weird problems with Svgalib's vga_setcolor()

This is a discussion on weird problems with Svgalib's vga_setcolor() within the Game Programming forums, part of the General Programming Boards category; Below is a program I have more-or-less finished coding. However, there's a weird error: instead of drawing each pixel in ...

weird problems with Svgalib's vga_setcolor()

Below is a program I have more-or-less finished coding. However, there's a weird error: instead of drawing each pixel in its correct color, the entire screen flashes different colors.

This program is meant to be a clone of the 'Demon' screensaver that comes default with most Linux distros. The program starts with a 320-by-200 matrix of numbers between 0 and 4. It then draws this to the screen, and steps three times, before repeating. In each step, it makes a copy of the map, except every 1 that's adjacent to a 2 gets replaced with a 2 in the new map, and likewise for 2 and 3, 3 and 4, 4 and 0, 0 and 1. Then the map is overwritten with the modified copy.

What this is supposed to look like: the map starts looking like noise, with lots of multicolored pixel. Then black regions 'eat' white regions, white regions 'eat' red regions, etc., so eventually the screen shows psychedelic patterns - spirals, large contiguous regions of colours, etc..

Your neighboring() function will break when passed an argument that is 0, since it will try to access an array element of -1. (mod'ing negative numbers is like moding the absolute value and then adding the sign back in.) This might cause random crashes and it will certainly introduce much more random values (with larger magnitude) than you were expecting.

The entire screen flashing different colours sounds strange. I guess it could be caused because you're not syncing with the vertical retrace, but all that should do is to show a frame that is half the previous frame and half the new one.

Other than that, do you have any way of viewing or setting the palette? It's possible that this is getting messed up somehow. How are you running this program? I didn't think modern versions of Windows would even let you switch into mode 13h anymore. (Certainly my old DOS programs don't work, but then those were compiled using DJGPP with a different library.)

By the way, unless you have an ancient laptop or some other reason for using DOS, consider using a modern (cross-platform) library like the SDL. Lazy Foo' Productions

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell