a 256b PC intro released at Revision 2021



This intro is a demonstration of a way to simulate buffer swaps using special color values, all within 256 bytes.

The naive way to render an effect like this would be to first clear the entire screen, then draw some lines and repeat. This works in theory but it creates a lot of flickering since you're very likely to see the image while it's in the middle of either clearing or rendering, meaning the lines are only partially visible.

My initial idea to get around this was to allocate a back buffer so I could first render the image off-screen and then copy the complete image onto the screen, but after some experimentation, I determined this was not going to fit into 256 bytes.

What I found out is that the default MS-Dos color palette has two different codes for both black and white, which conveniently differ by just 1 bit each. That bit can be used to encode what color each pixel should have in the next frame without visibly changing the image.


So when drawing the lines, it walks along each line and sets this bit for every pixel on the way. After that, it iterates over all pixels on the screen and replaces them with (the lower variation of) either black or white depending on whether or not the bit was set.

The result is a perfectly flicker-free animation since from the outside, it looks like it just sweep-transitions from one frame to the next with no intermediate stages in between.

I did realize after the compo that I could have implemented the same effect by clearing the screen, drawing the lines and waiting for a couple of milliseconds and it would have been 99.99% flicker-free because of how fast the first two steps are, but oh well...