# Build record 2026-10-11, one session, the day the last of the four Rust chip cores was finished and megadrive-python was frozen as `megadrive-rust-pin-1`. ## The transcription The reference's board is about 5,400 lines of Python in twelve modules, not counting the pygame frontend. Each became a Rust module in one pass, in the same order, with the same names and citations. Only Rust's ownership forced changes: both Rust cores own their buses, where the Python board hands callables to both CPUs and calls back into the system from inside them. The handoff brief ("The shape Rust forces") gives the resulting layout, and each module's header says what changed there. m68000-rust needed two additions, on its branch `board-hooks` (`e1b8000`), merged to its main as `ce3b489`, which this board now pins. The core's own tests and clippy pass with them: - `Cycle::irc`, for open bus; - `Bus::acknowledge_clock_credit`, for the E clock after a held push. The crate compiled on the first build. Its first lockstep run, Sonic the Hedgehog for 300 frames from power-on, was identical to the reference's on the first try. No case of the gate has differed since. ## The gate `scripts/lockstep.py`: 37 cases, 69,900 frames, all identical. The README has the table. Before the full run, the trace was widened to include the analogue mix (`audio.rs`), which it had left out. The mixed samples are identical too: the float arithmetic is the reference's, operation for operation. ## The seeded faults `scripts/seeded_faults.py`, 24 faults. The first run caught 20 of 24. The four misses were each traced to a cause, not waved away: | Fault | Why the gate missed it | What closed it | | --- | --- | --- | | FM write lag 21 -> 22 MCLK (die machine) | **An equivalent change.** A 68000 access is on the 7-MCLK grid, so 21 and 22 fall in the same FM cycle. No run can tell them apart. | The fault is now 21 -> 28, a 68000 clock later; the examples' 68000 FM writes catch it. | | The full-screen vertical scroll latch ignores late writes | In H40, plane A's latch is the line's last pixel and no slot follows it. Plane B's at $143 is followed only by idle-line slots, whose latch no visible line uses. In H32 the active slot at $105 follows plane B's at $103. | `h32-raster`: H32, full-screen scroll, plane B's word written at every phase. | | Colour 15 cancels the shadow | Only low-priority sprite pixels reach the rule. In 900 frames, only Overdrive 2 on the die machine, at frame 4,140. | `h32-sprites`' sprites are low priority, in palette 3 (colours 62 and 63). | | The EEPROM's page wrap | No game in the gate writes across a page. | `tests/eeprom.rs`: the reference's chip driven by bit-banged transactions in all three modes, update by update. | The final run caught 24 of 24. ## Pin 2, 2026-10-31 megadrive-python moved 31 commits to `megadrive-rust-pin-2` (`b2d47cb`): the mappers, Pier Solar, lock-on, the SVP, and the window bug kept to plane A. `ssp1601-rust` is the SVP's core, transcribed from ssp1601-python `c863a2c`. The expansion sockets were left out, with nothing here to attach to them. `scripts/lockstep.py`: 80 cases, 114,000 frames, all identical. No case ever differed; two lock-on cases had to be rerun for a quoting mistake in `cases.tsv`. `scripts/seeded_faults.py`, 42 faults. The first run of the 14 new ones caught 7: | Fault | Why the gate could not see it | What now catches it | | --- | --- | --- | | The window bug on both planes | No case has a left window with plane A at a fine scroll and plane B showing through in those frames. | `window-bug`, a cartridge of our own. | | Tekken's latch, Top Fighter's word writes, Pier Solar's write enable, the 2-in-1 at reset | The games do not reach these in the frames scripted. | `tests/boards.rs`: every board access by access against the reference. | | The S&K window not shifted | Equivalent with Sonic 3 or any 2 MB cartridge, which mirrors over the shift; the first version of the vectors had the same blind spot. | `tests/boards.rs` with a 4 MB cartridge locked on. | | The DSP's clock 3/8 | The trace held nothing of the SVP, and a DSP an eighth slower showed the 68000 nothing different in those frames. | The DSP's and memory controller's state in the trace. The SVP cases were rerun with it. | Four faults on slots with no local dump were added, which only `tests/boards.rs` catches. The final run caught 42 of 42. ## Speed The README has the table: 246-376 fps with the FM on, 4-6 times real time, before any optimization. ## Tooling notes - Build with `CARGO_TARGET_DIR=target/stable rustup run stable cargo build --release`. The default toolchain here is an old nightly. - For clippy, use the stable rustc and a target directory of its own: `CARGO_TARGET_DIR=target/lint RUSTC=$(rustup which --toolchain stable rustc) rustup run stable cargo clippy --release --all-targets -- -D warnings`. - `scripts/fetch_megadrivepython.sh` clones megadrive-python (private) over SSH. `MEGADRIVE_PYTHON_SOURCE` can name a local clone. The script checks that the tag is at the pinned commit. ## DMA trigger handshake, 2026-11-05 Transcribed the current Python specification's source-high latch and deferred DMA grant. A transfer-mode $97 write arms the 21-MCLK trigger hold; without a rewrite, one more CPU bus cycle completes before the grant. Read/write, byte/word callbacks all honor that ordering. Step traces include the armed/pending state. The DMA regression and four library tests pass. Eight cases match current Python and plain Rust exactly (436 frames, 6,000 step records). Fresh power-on runs also match throughout the 484-frame plasma window; the scene is one frame earlier than the old fresh baseline, with identical pictures after explicit alignment. The Python worklog records the oracle measurements and remaining H-scroll timing work. The older golden-example tests still fail; replaying the old DMA behavior proves those failures pre-existing. They were not regenerated. Both release headless binaries were rebuilt with `cargo +stable-x86_64-pc-windows-gnu build --release --offline --bin md-run --bin md-trace`. ## Active-H40 FIFO CPU acknowledgement Transcribed Python's separate CPU-ready timestamps: 29 MCLK after memory commit, or 34 at slow slot H $1CE. VRAM releases after its second byte. H32, idle slots, memory placement, status flags and DMA read pacing keep their existing behavior. Step traces include the new state; frame records keep their format. The four library tests, DMA regression and new FIFO regression pass. Both release headless binaries were rebuilt with the GNU toolchain above. Eleven cases match Python and plain Rust record-for-record (445 frames, 12,000 step records). Fresh power-on runs through frame 16950 agree across the 484-frame plasma window, with no image or alignment change from the DMA-fixed baseline: 7,849 disagreements remain. Python's same-arrival replays reproduce 25,753 exact acknowledgements across the independent destination probes and saved plasma arrivals. Python's targeted selection passes 115 tests. Its three Nemesis FIFO-ROM acceptance cases also pass after a hash-verified download from the pinned mirror. No golden baselines were regenerated. See Python's worklog for the measurements and remaining row-35 lead. ## Calibrated reset reference run The earlier frame harness used the die's button time rather than the board's calibrated pulse time. Reran from power-on with an exact reset at 26,601,719 MCLK: the preceding instruction boundary is 26,601,656, post-reset clock 26,602,909, and native cartridge-refresh phase 375 (die-clock phase 524). Python and both Rust cores agree over all 484 plasma frames with no picture change from the FIFO-fixed run; 7,849 disagreements remain. A separate calibrated Rust-fast capture pins the whole-frame advance to frame 7053. Picture alignment after that advance does not preserve refresh phase. No Rust core change was needed; Python's capture tool now has opt-in exact-reset scheduling. See its worklog and `flaws/plasma-reset-anchor.json` for the corrected attribution. ## VDP data-port bus ownership Ported Python's correction: byte/word VDP data-port waits extend the CPU /AS span used by the arbiter, not just instruction time. `Devices::vdp_hold` is shared by all four CPU access paths. Mirrors are included; disabled recording does not touch stale entries. Control-port DMA duration is not added to /AS. No timing constants changed. The data-port ownership tests, FIFO regression and DMA regression pass (four tests). Release binaries were rebuilt. Fresh exact-reset runs through frame 16,955 reproduce all 809 standard-Rust/control captures and all 506 Python plasma captures; no captured OD2 picture changes. The independent die replay predicts 1,193/1,193 grants with full FIFO hold spans, versus 354 without them. The same-start timing-cart control preserves all 681 records across 21 tests. See Python's worklog and `flaws/vdp-bus-ownership.json`; the logo/plasma defects remain separate. ## A Model 1's cartridge cycle; the FM's write timing on every machine (2026-11-10) Ported from the reference (its worklog, the section of the same name). `arbiter.rs`: `MODEL1_CARTRIDGE_EXTRA_MCLK` (3) and `MODEL1_CARTRIDGE_RELEASE_MCLK` (1), and `z80_access_wait` takes a fifth argument, `release`: the Z80's /WAIT let go that long after its cycle's end, the 68000 resuming from the cycle's own end. `machine.rs`: `Machine::z80_cartridge_extra` and `z80_cartridge_release`, 3 and 1 on the five Model 1s, 0 and 0 on the Model 2s, the Genesis 3 and nuked-md. `board.rs` and `system.rs` use them for a Z80 cycle on the cartridge. `board.rs`: the FM's write and read lags and the timer's control delay are on every machine, no longer on nuked-md only. Hardware-captured for the cartridge cycle (the probe cart's ZBS and ZRO counts on an NTSC Model 1, the PCM stream of a PAL console's capture of Overdrive 2); the FM lags stay die-derived, with the same capture as indirect evidence. On the probe cart's reference check (`genesis-tmss`), metrics outside the console's ranges go from 8 to 6 and none leaves its range: ZRO2's two counts come inside, ZRO1's two come from 885 and 86 counts out to about 100 and 36. Gates: the suite passes; of the five lockstep examples only `board-tour.trace` (the `genesis` machine) moves, regenerated from the reference; Overdrive 2's first 1,500 frames are identical, line for line, between the reference and both Rust boards on `genesis`, `megadrive` and `genesis2` (12,002 lines each). The 80-case gate has not been rerun: every case on a Model 1 machine whose Z80 reads the cartridge or writes the FM will move on both sides. ## The Model 1's release back to 0 (2026-11-11) Ported from the reference (its worklog, the section of the same date). `MODEL1_CARTRIDGE_RELEASE_MCLK` is 0: the frame each pose of Overdrive 2's console model appears on in a PAL console's capture bounds what the 68000 may lose, and (3, 0) shows all 30 on the console's frame where (3, 1) showed four. `board-tour.trace` regenerated from the reference; Overdrive 2, 1,500 frames, identical to it on genesis, megadrive and genesis2. ## The Z80 waits out a DMA (2026-11-11) Ported from the reference (its worklog, the section of the same name). `arbiter.rs`: `DMA_Z80_GRANT_MCLK`, `DMA_Z80_RESUME_MCLK` and `arbiter_grid`, which adds a 68000-to-VDP transfer's hold on the bus to the 68000's cycles as one long cycle for a Z80 access that falls in it. `vdp.rs` records the hold through `VdpHost::dma_bus`; `board.rs` `arbitrate` and the probe in `system.rs` use the grid, and the 68000 is charged only its stretched cycle. The example traces are unmoved; Overdrive 2, 1,500 frames, identical to the reference on genesis, megadrive, genesis2 and nuked-md. ## The unarmed trigger on the die's figures only (2026-11-11) Ported from the reference (its worklog, the section of the same name). `vdp.rs` `run_transfer` queues an unarmed transfer behind one more CPU cycle only with the die's DMA figures (`dma_die`): with Kabuto's start-up the queue left Overdrive 2's plasma in black bands on `megadrive`, which a console's capture does not show, and `nuked-md` draws it right either way. The example traces are unmoved. ## The Z80's refresh runs by itself; the Model 1's extra to 4 (2026-11-12) Ported from the reference (its worklog, the section of the same name). `arbiter.rs` `REFRESH_SELF_MCLK` (112): a refresh left alone on a free bus runs by itself, so a Z80 cycle beginning 112 MCLK or more after it fell due is not stretched by it (within its 14 MCLK run the cycle waits for its end, rounded up to 7), as on the die's ZBS3. With it the console's ZBS3 asks for a 4 MCLK cartridge extra, so `MODEL1_CARTRIDGE_EXTRA_MCLK` goes from 3 to 4. The board-tour example traces are regenerated from the reference (`board-tour`, `board-tour-nuked`); the others are unmoved. ## Provenance wave 2 (2026-11-19) The same port as megadrive-rust `477f6b7` (from megadrive-python `227de45`). `cargo test` passes. `scripts/lockstep.py --reference `, all 80 cases: **80 of 80 identical**; megadrive-rust is itself 80 of 80 identical to the reference at `227de45`. Seeded faults not rerun. ## `serial_line` removed (2026-11-19) The VRAM serial-port border pattern (`fe43425`, raster export only) removed unread: it was worked out from Nuked-MD's source and the reference tiers do not have it (docs/provenance.md). `cargo test --release` passes (26 tests); `scripts/lockstep.py --jobs 8 --reference` megadrive-rust `3b0cdf8` md-trace: **80 of 80 identical**. No speed claim, so no `scripts/ab.sh` run; the play path (`frame_rgb_into`) never called it. ## The cores' history resets (2026-11-21) m68000-rust-fast's history was reset on 2026-11-20 (`b6af29a` is gone); the board pins its reset `c896088`, wave 2's core. Upstream megadrive-rust moved to m68000-rust `8a5bbb7` and the reference megadrive-python `fcef88d` (reset: `6303613`), and was itself reset to `ecd3e71`, now the ladder's default upstream; `scripts/fetch_megadrivepython.sh` names the reference by commit (the pin tags named the removed history). Gates: `cargo test` 26 passed. `scripts/lockstep.py --reference ` (a5f6b98 has ecd3e71's code), all 80 cases: **80 of 80 identical**. The ladder itself stopped before rung 1 here: its upstream worktree (`external/upstream`) looks for the sound and SVP cores beside it (`external/ym2612-rust` and the others), which this machine does not have, so rung 2 was run by hand with upstream's own binary. ## A stopped 68000 wakes for VINT again (2026-11-21) Merged from megadrive-rust `1adc5b4` (reference megadrive-python `3e2325f`): the IPL synchronizer's deadline, for a STOPped 68000, is the idle step's own start less `IPL_SYNC_MCLK` (`IPL_SYNC_WHILE_STOPPED`); before, it stayed at the STOP's last bus cycle and a program waiting in `STOP #$2300` never woke (RICK ROLL MD and BAD APPLE MD showed one black frame from `fe43425` of the old history on). Nothing of this fork's own code touches that path, and the merge applied without conflict. The examples `h32-sprites` and `window-bug` came with it, regenerated upstream from the reference. Gates: `cargo test` 26 passed. `scripts/lockstep.py --jobs 8 --reference `, all 80 cases: **80 of 80 identical**. The ladder stopped before rung 1 for the same reason as above (`external/upstream` finds no `external/sn76489-rust`), so rung 2 was run by hand with upstream's own binary; the ladder's default upstream is now `1adc5b4`. RICK ROLL MD and BAD APPLE MD, 600 frames from power-on with `md-run --no-sound --png-dir`: 278 and 258 distinct pictures (frames 2-600), as at `9847aab` before the regression. No speed claim, so no `scripts/ab.sh` run. Then merged megadrive-rust `9222ba9` (documents and a 43rd seeded fault, `IPL_SYNC_WHILE_STOPPED = false`): here too `scripts/seeded_faults.py --only` catches it, by 5 of 86 checks (`cargo test` first). The other faults were not rerun. play-md built from this board (`92d2b84`'s code) runs both demo cartridges in headless Chromium: BAD APPLE MD at 60.05 fps (console 59.92), RICK ROLL MD at 49.68 (PAL, console 49.7), no lock-up, the video on screen. ## Save states (2026-11-23) Merged megadrive-rust `9d5629d` (`a95b0b3`) and `1bcf124`: save states (`src/state.rs`, the reference's `state.py` at megadrive-python `1e8dcd3` transcribed; upstream's docs/build-record.md, "Save states", has the design and its faults). One conflict, `Md`'s `z80_timings`: this fork's direct-mapped cache kept; like upstream's map it is a pure cache and not in a state. This fork's own structs serialize with upstream's: `Offsets` (the Z80's access offsets as a copied array) derives serde, and the probe's bus, which this fork keeps between steps, is saved with the board. Its states carry their own magic, `MDRFSTAT`, so a state of one board is never read as the other's. The ladder has a third rung, `scripts/state_rung.py`: every case straight through and through save states, identical line for line. At `a95b0b3` (upstream `9d5629d`): rung 1 cargo test 33 passed and the window 8; rung 2 80 of 80 identical; rung 3 80 of 80. `scripts/ab.sh` with the two `md-bench` binaries (one layout, load 12): x0.993 against `d660e6e` (Sonic x1.028, SoR2 x0.983, Gunstar x0.990, OD2 x0.973), noise: no hot path changed. play-md built on it: run-ahead 1 and 2 against a plain run give the same sound, the same end state and the picture that many frames later (its `check-run-ahead.mjs`). At the merge of `1bcf124` (upstream's tests for the idle fields; no change to `src/`): rung 1 cargo test 34 passed and the window 8; rung 2 80 of 80 against upstream `1bcf124`; rung 3 80 of 80. ## The drawing switch, undrawn frames and the SVP's ROM DMA (2026-11-23) Merged from megadrive-rust `d6972cd` and `4088297` (megadrive-python `5351daf`, `4872910`, `efd80fc`; that repository's build record has the changes). Nothing of this tier's own changed. Ladder at `1be71d8` against upstream `4088297`: rung 1 37 + 8 passed, rung 2 81 of 81, rung 3 81 of 81. What drawing off still saves, now that it gates only the pixels (`VdpState::rendering` off for a whole run, against on; ms a frame with the sound mixed, best of 5 runs of 600 frames, the two builds alternated on one core, both layouts): | | drawn | undrawn | saved | undrawn at `1636fff` (the old gate) | | --- | --- | --- | --- | --- | | Sonic the Hedgehog | 1.786 / 1.799 | 1.483 / 1.508 | 17 % / 16 % | 1.453 / 1.472 | | Streets of Rage 2 | 1.469 / 1.475 | 1.245 / 1.263 | 15 % / 14 % | 1.218 / 1.237 | | Overdrive 2 (PAL) | 2.395 / 2.555 | 2.039 / 2.112 | 15 % / 17 % | 2.068 / 2.070 | (default / `nf5` layout.) Keeping the sprite pipeline running costs about 2 % of an undrawn frame on Sonic and Streets of Rage 2 (0.03 ms), within the noise on Overdrive 2; the switch still saves 14-17 % of a frame. ## The expansion sockets merged (2026-11-25, branch `sockets`) megadrive-rust `d39b9bf` (the reference's `sockets.py` and its call sites, megadrive-python `efd80fc`) merged as `ad976bf`; conflicts were placement only. `frame_rgb_into` stays the console's own picture: a picture device's rows, which may be another width, come only through `frame_rgb` (documented on it). The ladder's upstream is now `d39b9bf`, and its case table has rung 6, six cases with the reference's test-only socket devices plugged in on both sides (`--fake`), which the save-state rung leaves out. **A/B, nothing attached**, against `pin-2-od2` (`a291363`), `scripts/ab.sh` with `BIN_A`/`BIN_B` (the base built in a worktree beside this repository, since one under `target/` cannot find `../sn76489-rust`), 7 rounds, load 75-100: | | default | nf5 | | --- | ---: | ---: | | the merge as it came (`ad976bf`) | x0.878 | x0.939 | | the sockets' paths out of line (`bf2c805`) | x0.986 | x1.003 | The merge's slowdown was in `Devices::z80_peek` (md-profile on Gunstar Heroes: 1.2 % to 2.6 % self; the scheduler peeks four bytes at every Z80 instruction) and the cartridge reads, whose device arms stopped them inlining. `bf2c805` keeps the cartridge on the bus and the plain peek inline and moves the boot ROM, a socket's claims and `with_device` out of line. Per workload at `bf2c805`: Sonic x0.966 / x1.020, Streets of Rage 2 x1.004 / x1.011, Gunstar Heroes x0.999 / x1.003, Overdrive 2 x0.981 / x0.984. **Not a clean no-slowdown result**: the default layout's total is 1.4 % behind (Sonic 3.4 %), within the spread this machine shows at that load but not shown to be noise; to be re-measured quiet. Ladder at `bf2c805`: rung 1 cargo test 56 passed (37 before: the 19 socket tests) and the window 8; rung 2 **87 of 87** against upstream `d39b9bf` (the 81 of before, and rung 6's 6); rung 3 **81 of 81** through a save state. ### Re-measured, and `z80_offsets`' RAM read (2026-11-26, merged to `pin-2-od2`) Decision M2 (emulator-lineage docs/proposals/2026-11-decisions.md). Every A/B below is `scripts/ab.sh` with `BIN_A`/`BIN_B`, `CPU=30` (an E-core nobody else used), `ROUNDS=9`, one run per layout; each binary built in its own worktree beside this repository. The window was meant to be quiet, but the machine sat at **load 15-29** throughout (other agents on other cores), so per-workload ratios move by up to 4 % even with the same binary on both sides. | A/B (MEASURED) | default | nf5 | load | | --- | ---: | ---: | --- | | A/A: the base against itself (the noise) | x0.998 | x0.985 | 15-18 | | `sockets` (`9995ffb`) against the base (`a291363`) | x0.970 | x1.004 | 17-20 | | the same, repeated | x0.986 | x1.014 | 15-16 | | `sockets` + the RAM read, against the base | x1.007 | x1.024 | 17-19 | | the same, repeated | x0.999 | x1.040 | 21-23 | | the base + the RAM read, against the base | x1.029 | x1.041 | 21-23 | | `sockets` + the RAM read, against the base + the RAM read | x0.991 | x0.999 | 20-26 | Per workload, `sockets` against the base: Sonic x0.920 / x0.954, then x0.988 / x0.991; Streets of Rage 2 x1.056 / x0.999, then x1.000 / x1.047; Gunstar Heroes x0.994 / x1.048, then x0.987 / x0.967; Overdrive 2 x0.933 / x1.017, then x0.973 / x1.057. With the RAM read on both sides: Sonic x0.972 / x0.997, Streets of Rage 2 x0.989 / x0.993, Gunstar Heroes x1.007 / x1.016, Overdrive 2 x0.993 / x0.989. So the sockets alone stay behind on the default layout (three runs, x0.970-x0.986, counting the load-75-100 one), level on nf5. **md-profile on Sonic** (1,800 frames, CPU 30, load ~20; 3,723 samples base, 3,960 sockets) put the extra in code inlined into `Md::catch_up_z80`: `z80_offsets` +71 samples (the four `z80_peek`s per Z80 instruction, each now with the `pages` test on its bank arm), the probe's read +16, `prearbitrate`'s closure +16, `z80_running` +18 (inlined; the symbol table has no out-of-line copy). `row_rgb` replacing `frame_rgb` is a wash (98 against 96). **One fix tried, kept (`684f0b1`):** `z80_offsets` reads the four bytes as one slice of the Z80's RAM when all four are there and do not cross the 8 KB mirror's end (the Z80's code nearly always runs from RAM), and goes through `z80_peek` otherwise. The bytes are the same: md-bench's checks identical on all four workloads at 1,800 frames, base, `sockets`, both with the fix. It is a speed change of its own: x1.029 / x1.041 on the base alone, which wins on both layouts natively (OBSERVED, one run each; **not measured on the WebAssembly target play-md runs**). With it on both sides the sockets cost x0.991 / x0.999, inside the A/A spread; the merged line is level with or ahead of the base on both layouts. In other words the fix pays for the sockets rather than the sockets costing nothing: about 1 % on the default layout is still theirs, as far as this noise lets one say (HYPOTHESIS beyond that). Gate at the merge (`sockets-fix`, `2b22eb1`: `684f0b1` plus `pin-2-od2`'s LICENSE commit), `JOBS=2` on CPUs 29-30, load 21-29: rung 1 cargo test 56 passed and the window 8; rung 2 **87 of 87** against upstream `d39b9bf`; rung 3 **81 of 81** through a save state; the ladder clean in 1,428 s. The save-state version is now 3 on `pin-2-od2`: play-md, which builds from this checkout, refuses its players' earlier F5 states at its next deploy (held until megadrive-python's device-state socket comes down, so they meet one refusal, not two).