NewsCrawler.org

An old game-optimization hack: replacing post-increments with fixed offsets

The author recalls his college years working on games for 8-bit PCs, when hardware was very slow by today's standards. A friend had adapted a 1980s arcade side-scroller for a PC of that era, but the game was too choppy to play. The code was already tightly optimized, with loops [1]unrolled and unneeded draws removed, so there was no easy fix.

Each frame redrawed nearly a full screen of 28 by 28 pixel background tiles, with 16 colors at half a byte per pixel. The screen was 320 by 240 pixels, so each screen row took 160 bytes. The graphics hardware did not help: the program copied every tile byte by byte on the [2]6809 processor, using [3]auto-increment addressing to copy 4 pixels at a time.

Counting [4]clock cycles, the author found that unrolling the loop cut the time per row from 157 to 120 cycles, a 30-percent speed-up. The friend went further by replacing the 3-cycle post-increments with fixed offsets, which cost only 1 cycle each, and a zero offset costs nothing.

Read the original blog.moertel.comDiscussion

Discussion

Commenters mostly share nostalgia and enthusiasm for low-level optimization on old machines, and they add similar stories about the Atari 2600, Game Boy, TRS-80 and Amiga. One commenter disputes the claim that graphics hardware did nothing, noting that frame-buffer hardware built the image from video memory.

Sources

Published: First seen: Читать по-русски

Open as a page