256 byte pong

What is the minimum amount of information you need to describe a playable game? I had seen a bunch of 256 byte demos out there, but not many that were interactive. As an exercise, I tried to code the simplest game I could think of (pong) in that size.

pong256.zip 6/29/2008, ZIP File 32kB

This zip file contains the result of my efforts. After about a weekend of work I had produced a 255 byte version of "pong", and was satisfied. Included are all 11 versions of the program and their x86 assembly source code. These programs require at least a 16 bit x86 processor with VGA. If you have a Windows machine, you should be fine, but DOSBox will run it for you otherwise.

I'm sure there are many x86 assembly tricks I don't know about that could have applied; I was more interested in the exercise than creating a catalogue of tricks. I'm not planning to try to make this program any smaller, but if anyone else out there wants to continue the challenge, go for it, and let me know what you find. Otherwise, if you have any other comments or questions, please e-mail them to me. My address appears at the bottom of this webpage.


Version Highlights

In all versions you control the left paddle with the CTRL and ALT keys. Press any other key to quit. The right paddle is controlled by the computer.

A fairly detailed description of the version-to-version changes is included in comparisons.txt, but the broad strokes are described here.

Version 1.0: pong10.com (547 bytes)

This was written without too much concern for code size. I was really trying to get a complete set of "pong" features sketched out, and getting an idea of how much code that took. 547 bytes was bigger than I had hoped.

Version 1.4: pong14.com (450 bytes)

This was the last version before I started cutting features. I had managed to cut 97 bytes away without changing the functionality of the program at all. There was a lot more that could be trimmed here, but I decided to set my sights a little lower before proceeding. It might be possible to do the 1.0 feature set in 256 bytes, but at this point it was looking like it would take a very long time to figure that out.

Version 2.1: pong21.com (255 bytes)

After version 1.4, I immediately cut out any features I could that wouldn't turn this into some sort of mutant sub-Pong. I removed the score bar, coloured paddles, and took away the half-second delay after a goal, which after some minor rearangement cut me down to about 306 bytes, and my goal of 256 started to look really attainable.

After settling on this more minimal feature set, it was just a matter of time, slowly finding all the things that could be trimmed down. Replacing duplicate code with calls, rearranging the order of events and trying to maintain all my variables in the register and stack, using 8 bit immediate values wherever possible. Eventually I got it down to 255 bytes. I'm sure it could be smaller, but I won't be the one to figure out how.


Return to my main page.
brad @ rainwarrior.ca