RC RANDOM CHAOS

Extreme optimization: how 1980s game programmers squeezed every CPU cycle

· via Hacker News

Original source

A great old-timey game-programming hack (2013)

Hacker News →

In the 8-bit PC era, a programmer struggled to get a side-scroller arcade port running at playable speed despite already optimizing the code. The bottleneck was the graphics hardware, which required manual byte-by-byte drawing with no hardware assistance. The main task was repeatedly copying 28x28-pixel background tiles—each stored as 14 bytes across 28 rows—into a 160-byte-wide screen buffer.

The initial tile-copy routine used nested loops with the 6809 processor’s auto-increment addressing to load and store pixels four at a time. This approach took 157 cycles per row of tile data. The first major optimization unrolled the inner loop, eliminating the loop counter and conditional branch overhead and reducing the time to 120 cycles per row—a 30 percent improvement.

The programmer pushed further, replacing the 3-cycle auto-increment operations with explicit byte offsets that cost only 1 cycle each. By knowing the exact position of each word within the unrolled operations, he could eliminate address-calculation overhead entirely, squeezing still more performance from hardware already pushed to its limits.

Read the full article

Continue reading at Hacker News →

This is an AI-generated summary. Read the original for the full story.