The Spectrum Dispatch News

technology

A Classic Game-Programming Speed Hack from the 8-bit Era

A programmer squeezed an arcade game into a slow 1980s PC, then used clever assembly tricks to make it playable.

A Classic Game-Programming Speed Hack from the 8-bit Era

In the 1980s, when gaming hardware was severely limited, programmers employed radical optimization techniques to achieve playable speeds. A blog post by Tom Moertel recounts one such hack from his college years.

A Classic Game-Programming Speed Hack from the 8-bit Era

Modertel’s friend had nearly completed a port of a graphically impressive arcade coin-op game to a 1980s-era PC, but the result was unplayable—too slow and choppy for a side-scroller. The programmer had already applied standard optimizations: unrolled loops, eliminated unnecessary draws, and removed all obvious waste. Yet the game still crawled.

The bottleneck was redrawing the background each frame. The system had no graphics hardware acceleration; programmers had to manually copy data byte by byte to the screen buffer. Background tiles were 28 by 28 pixels, represented as 28 rows of 14 bytes each (since each pixel took half a byte). The screen buffer was 320 by 240 pixels, or 160 bytes wide by 240 rows tall.

The game’s core tile-copying routine ran on a 6809 processor with 16-bit index registers and auto-increment addressing modes. A straightforward implementation looped through 28 rows and, within each row, looped 7 times to copy 4 pixels per iteration. With setup, cleanup, and loop overhead, this burned 157 cycles per row.

Modertel’s friend applied loop unrolling—writing out all 7 iterations explicitly instead of repeating in a loop—cutting the cycle count to 120. But he went further. He recognized that the auto-increment operators (++) cost 3 cycles each and, with the loop unrolled, he knew the exact offset of each memory location. He replaced the post-increments with explicit offsets, reducing their cost to 1 cycle (or free for offset zero). This additional optimization brought each row down to just 112 cycles.

Modertel notes that this was “crazy” programming—trading code size for speed in an era when both were precious resources. The post includes the full assembly code and cycle counts, demonstrating how careful arithmetic and deep knowledge of processor internals could squeeze performance from impossibly slow hardware. The optimization exemplifies the ingenuity required when hardware constraints left no room for inefficiency.

Key facts

  • A 1980s PC port of an arcade game was unplayable due to performance issues.
  • The main bottleneck was redrawing 28×28 pixel background tiles each frame with no graphics acceleration.
  • Standard optimizations (loop unrolling, eliminating unnecessary draws) had already been applied.
  • The programmer replaced auto-increment operators with explicit memory offsets in assembly code, reducing cycle counts by trading code size for speed.
  • This technique was necessary because the 6809 processor had severe performance constraints.

Sources

← All posts