The Story
Mars was written by Tim Clarke in 1993 while still at school. The demo gained legendary status in the demoscene for generating and rendering fractal voxel terrain in real-time — all in under 6KB. Running at full speed on a 486, it was remarkable enough that Tim was headhunted to work for space agency Lunacorp in Washington for several summers while studying at Cambridge University.
Down the Rabbit Hole March 9
Started with a 5,649-byte DOS executable from the Hornet demoscene archive. Parsed the MZ header, mapped segment layout, found entry point at file offset 0x200. The entire binary was annotated by hand in a hex dump format — every instruction, every data table, every constant. 800 lines that became the single source of truth.
Key algorithms fell into place: the PRNG (seed * 0xAB + 0x2BCD mod 0xCF85), diamond-square fractals with BX register walk, palette at 0x14CA. First web port worked but looked wrong — horizon at wrong height, perspective formula off, hex misreads (B9 40 00 is MOV CX,64 not 16384).
Getting the Axes Right March 10
Terrain was rendering 90° rotated. A +0x4000 angle offset had leaked into the voxel pass. Fixed axis swap, added height & color interpolation, sorted out the horizon buffer — 0x7D00 was two packed 16-bit words in a STOSD.
The One-Line Fix March 11
A single missing line caused dramatic vertical streak artifacts: the prevColor buffer wasn't being cleared between frames. The binary zeroes it at 0xC40 with REP STOSD. One line of code, hours of debugging.
The Annotation Audit March 17–18
196 lines of the annotated hex dump had accumulated address drift (7–16 bytes off). Every address from 0x420 to 0xC20 re-verified with xxd. Two architectural fixes emerged: viewAngle was fiction (camera always faces +Y), and float math was wrong — replaced with integer DDA (ADD BX,AX; ADC SI,BP).
Key discovery: byte F5 in pattern A4 03 D8 13 F5 is a ModRM byte (ADC SI,BP), not a standalone CMC instruction.
The Last Few Percent March 19
Height projection was truncating to 8 bits. Missing DEC BP compensation. Two voxel pass bugs: skip path must update prevColor, and dispatch table draw range is off-by-one due to DI wrap trick. Floor pass: pixel-perfect. Voxel pass: down to 0–81 pixel diffs.
The Emulator Marathon March 22
Four sessions, 17 hours. Built a custom 16-bit x86 emulator (1,800 lines of JS) to run mars.exe instruction-by-instruction. First comparison: 39.5% pixel differences. Fixed PRNG seed isolation, DIV/IDIV edge cases, dynamic camera height, FS:[BX+1] carry semantics.
seed 42: PIXEL PERFECT seed 100: PIXEL PERFECT seed 500: PIXEL PERFECT seed 1000: PIXEL PERFECT seed 5000: PIXEL PERFECT seed 8888: PIXEL PERFECT seed 12345: PIXEL PERFECT seed 32000: PIXEL PERFECT