← Wed, Nov 11 digest

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

read article ↗ hn thread ↗

Two programmers accelerated a sluggish 1980s 8-bit arcade port by 70% by commandeering CPU stack registers and registers for an unconventional memory-copy hack.

read it A delightful retro assembly deep-dive into wringing maximum performance out of a constrained 8-bit CPU.

summary

Tom Moertel recounts how he and a friend accelerated a sluggish 1980s side-scrolling game on a 6809 processor by 70 percent. By repurposing the stack registers and every available CPU register for a custom block-copy loop, they bypassed standard throughput bottlenecks. When hardware interrupts threatened to corrupt tile data via the hijacked stack pointer, they solved it by letting the corruption occur safely in a scratchpad area.

key points

  1. The 6809 processor's fast push and pull stack instructions allowed moving multiple bytes at a time, drastically cutting cycle counts compared to naive loops.
  2. Pre-processing tile data with a reversed byte-order canceled out the inversion side-effects caused by stack-based pushing and pulling.
  3. Interrupts caused memory corruption because the system stack pointer was commandeered, which was fixed by safely relocating the stack target during the copy routine.

who should read it

Retro-game developers, low-level systems programmers, and computer history enthusiasts.

discussion warm

consensus

Commenters universally praise the ingenuity of the optimization, sharing fond memories of low-level programming constraints and similar hardware hacks from the 8-bit era.

best comment by mrandish ↗

The clever 6809 PSHU/PULS memory copy trick was probably independently discovered several times before Tom Moertel discovered it. The game Tom worked on was for the Coco 3, which was released in 1986.

My first computer was the original 4K Color Computer (1981). I learned 6809 assembler on it and worked full time programming it for several years, while also running one of the largest users groups for it. Traveling to Coco trade shows around the country, I met many of the devs writing the most popular Coco games and the trick was definitely known by around Summer 1983 as that's when the first …

It adds historical context showing that this clever 6809 memory-copy trick was independently discovered and used by arcade developers like Eugene Jarvis.

Generated by an LLM from the article and thread. Check the sources before relying on it.