# Build record What happened when the plan in [build-approach.md](build-approach.md) ran, 2026-09-11, in the shape of the earlier projects' records. ## Stage 0: documents and oracle Eleven documents written from MAME master (every file BSD-3-Clause), with eight agents in parallel, then a proven MAME 0.285 Lua oracle: headless with `-video none`, deterministic across runs, per-frame RAM dumps and device write taps. Three reference runs defined and generated (2.6 s of MAME for all three). ## Stage 1: three Z80s boot and play First run: RAM identical for 720, 1,200 and 900 frames respectively, then single bytes off. The cause was the frame origin: MAME's frame runs from vblank start to vblank start, so its vblank IRQ lands ~400 T-states into the frame it labels and the sub2 NMIs at 19,968 and 44,544, not at 43,008 and 12,288/36,864. With the timeline re-based, two runs were identical over their whole length and the third through 2,034 frames, where the sound CPU starts a note one NMI period early. Instrumenting both sides showed the sub CPU writing the trigger byte in frame 2034 here and 2035 in MAME: a read of a main-CPU variable ordered differently by the two schedulers. Slicing exactly as MAME does (512 T-state quanta cut at every timer) and adding MAME's other timers as cuts changed nothing; the difference is pinned as known. (2026-10-02, in galaga-remix: what was missing was MAME's two MCUs, which sit in its scheduler's device list and pull every slice back to their own cycle grid, and the 51xx's O-port syncs. With those reproduced the pin is gone; docs/mame-oracle.md.) Two power-on facts came from probing MAME rather than reading it: the sub CPUs are held in reset until the main program writes the latch (the LS259 code fires no callbacks at reset, yet the CPUs sit at PC 0 for 699 frames), and the Z80 starts with F = 0x40 and IX = IY = 0xffff. ## Stage 2: video Every screenshot MAME took, twelve across the three runs, pixel-identical on the second attempt; the first differed only in blue, because MAME scales all three resistor networks by one factor and blue's two legs top out at 222. The starfield matched at once. ## Stage 3: inputs Done inside stage 1: the 51xx's reply pipeline (levels one frame late, edges two, the in-game bits one later still, 0xff in switch mode) was fitted from the game run's polls, and the scripted game reproduces. Free play was fitted later, when the page's first start press did nothing: with the free-play DIP the game sends a coinage of zero and the chip reports 0xa0, dipping to 0x99 for the one poll after a start. ## Stage 4: sound The WSG was right first time (correlation 0.969 with MAME's mix, equal RMS). The 54xx took the day's longest detour. Its output was captured by making the MCU the debugger's visible CPU and logging registers per instruction (the debugger's `trace` action works headless; `tracelog` does not, and a breakpoint set through the Lua device API segfaults). The nibble stream is a random bit times a stepped envelope, and Galaga only ever fires it at boot and at a death. Then the analog path: by MAME's source the nibble feeds the 450 Hz band-pass, and simulating exactly that chain on the captured stream reproduces neither the level nor the spectrum of MAME's recording, two thirds of which is low-frequency energy with no linear relation to the bits. Several hours went into candidate explanations (rail clipping, the DAC interpolation, timeslice quantisation, the other channels, the summing resistance) and none held. The model was fitted to the recording instead, which is what the plan said the ear test would settle, and the docs say so. ## Stage 5: the page Written against the Galaxian page's parts (zip reader, audio worklet, gamepad and touch handling, the 120 Hz pacing fix) and the site plan. Headless Chromium runs it end to end. Two bugs found there: the `hidden` attribute lost to the panels' `display: flex` (one CSS rule), and the stored-ROM check could race the file picker and start two boards. ## Numbers - Native: 2,400 frames in 0.23 s (the three-CPU board with tracing), about 170x real time. - `.wasm`: 301,148 bytes built, 256,612 after `wasm-opt -Oz`, once the bindings moved to their own crate (the board crate as cdylib+rlib collided with itself under `cargo test`). - The page in headless Chromium: 60.6 frames/s emulated, keeping up. ## Left open - The 54xx path's analog behaviour in MAME, above. - A and B explosions were never observed apart; the model plays one schedule for either. - Command 2 ending the 51xx's game-running state is assumed; no reference run reaches game over. - The cocktail (flipped) screen is implemented but unchecked.