Saturday, August 17, 2013

How one hack for playing a TRON lightcycle game went on an Apple IIgs

Folks, I was there in those ancient days of computing yore, and reading pixels off the screen for collision detection was exactly how I did games, too. I even still have code that does that lying around somewhere for some silly screensaver modules I wrote. Anyway:
"The algorithm to determine which pixel to check next used some fast assembler math to calculate a memory address – either one pixel above, below, to the left, or to the right of the current pixel.  But since any given pixel on the screen was really just a memory address, the algorithm simply calculated a new memory location to read.  So when the light cycle left the screen, the game happily calculated the next location in system memory to check for a wall crash.  This meant that the cycle was now cruising through system RAM, wantonly turning on bits and “crashing” into memory.

Writing to random locations in system memory isn't generally a wise design practice. Unsurprisingly, the game would generate spectacular crashes as a result.  A human player would be driving blind and usually crash right away, limiting the scope of system casualties.  The AI opponents had no such weakness.  The computer would scan immediately in front, to the left, and to the right of its position to determine if it was about to hit a wall and change directions accordingly.  So as far as the computer was concerned, system memory looked no different than screen memory."
Real Life Tron on an Apple IIgs

You young'uns might recognize this game better as 'Snake' as played on your phone.