A great old-timey game-programming hack (2013) blog.moertel.com · 256 points · 5...
HN Best 30 @best30
A great old-timey game-programming hack (2013) blog.moertel.com · 256 points · 58 comments · HN thread
TL;DR Tom Moertel recounts a college-era optimization on a Tandy Color Computer 3 (6809 CPU) where he and a friend sped up tile drawing for a side-scrolling arcade port by about 70 percent using PULS/PSHU stack-based copying, the direct page register as an extra byte register, and pre-reversed tile data. Interrupts then corrupted memory, which they solved by drawing into the screen buffer instead and reversing the tile order. The post is a 2013 essay about the joy of hard-won low-level tricks.
- A side-scroller's background redraw was too slow on a 1980s PC with a Motorola 6809; the friend's hand-optimized loop already ran about 98 cycles per row.
- Using PSHS/PULS and PSHU/PULS, the author copied bytes while borrowing the S and U stack pointers, reducing a row copy to about 56 cycles using the DP register as an extra go-between.
- Stack reversal flipped tile rows and swapped septets, so the tiles were pre-processed by reversing their septet order, which undid the mangling when drawn.
- The full copy routine measured about 1689 cycles versus roughly 5,000 for the earlier version, a reported 70 percent speed-up; in practice the game felt one-third to one-half faster.
- Sound interrupts corrupted memory where S pointed, so they swapped S and U so corruption hit the screen buffer, then changed draw order so each corrupted area was repaired before display.
Discussion The thread mostly shares nostalgia and admiration for 6809 and 8-bit-era tricks, with many commenters adding their own stories of clever hacks on the TRS-80, Coco, Atari 2600, Game Boy, and MS-DOS. Several threads drift into whether such optimizations still matter on modern hardware, and a few commenters note that the technique was likely discovered independently many times. The mood is warm and appreciative, with some wistfulness about the era and a few tangents, including an off-topic mention of TempleOS.
- Admiration and nostalgia for old-school clever hacks (most): Many commenters enjoyed the story and said it brought back memories of early programming and the thrill of understanding hardware. Several described similar feelings from their own early work.
- Such tricks are still valued in specialized fields (many): Game graphics, GPU shaders, embedded and low-level work still reward clever hand-tuned code. Commenters point to SIMD-like thinking and performance-critical niches as living descendants of these tricks.
- Modern compilers and hardware make these tricks irrelevant (some): A few argue that out-of-order CPUs and compiler optimizations have made such micro-tricks mostly pointless, with memory access now the bottleneck. Others replied that compilers do not handle these non-standard patterns well.
- The technique was discovered independently by many programmers (some): A commenter who worked on Coco games says PSHU/PULS block copying was widely known in the 1980s, citing Williams arcade games and the nickname 'PUSH-U / PUL-Me'. They note the direct page refinement seemed new to them.
- Early knowledge sharing was hard without the internet (some): Commenters observe that tricks spread through magazines, books, user groups and BBSes, and that many were lost. This connects to the author's call to record such stories.
- Off-topic tangents about other figures and systems (a few): Some comments drift to Terry Davis and TempleOS, Video Seven and Paradise VGA chips, and the Story of Mel. These are mostly side discussions rather than the main thread.
Links from the comments
- Excerpt from Michael Abrash's book about the Video Seven and Paradise VGA FIFO story.
- Wikipedia page on the Amiga custom chips, including the blitter that handled memory moves.
- A commenter's article on texture memory layouts, linked as a related piece on graphics performance.
- The Story of Mel, a classic piece of programmer folklore cited as a related read.
- Shadertoy, a site with many examples of GPU shader programming, suggested as a modern outlet for low-level tricks.
#retrocomputing #assembly #optimization #gameDevelopment #history