# 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 Rust-fast 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 Rust-fast 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 Rust-fast/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) Ported from the reference's wave 2 (`5ad77f6`..`227de45`; its `docs/provenance.md`, "Wave 2"): the refresh tie and the dot-clock edge tables removed; the full-screen vertical scroll latch refitted on the picture at the referee's pins (plane B $13F in H40, $102 in H32; plane A $104 in H32); the plane addressing rewritten from CMD and a pin-level measurement (same values); 777 Casino's values dropped; labels, citations and `NOTICE`. Example traces (`board-tour`, `board-tour-nuked`, `h32-raster`) and `boards.txt` regenerated from the reference. Gates: `cargo test` passes. `scripts/lockstep.py --python `, all 80 cases (114,000 frames): **80 of 80 identical**, the first full 80-case run since pin 2 (the Model 1 and FM-timing ports of 2026-11-10 to 11-12 had been checked on Overdrive 2's first 1,500 frames only). Seeded faults not rerun. ## The cores' history resets (2026-11-21) m68000-rust's history was reset on 2026-11-20 (`ce3b489` is gone); the board now pins its reset `8a5bbb7`, wave 2's core (the divide clocks re-derived from the SST corpus, nothing resting on MAME's header-less files). The reference moves with it to megadrive-python `fcef88d` (main's PR #11 and #12 merged into pin-2-od2; m68000-python `4454d54`), whose own history reset is `6303613` (the same board code; the sound referees moved out as GPL tools), named in `scripts/fetch_megadrivepython.sh` by commit: the tags `megadrive-rust-pin-1` and `-pin-2` named the removed history, and no new tag is made while the clean-up settles. Gates: `cargo test` 23 passed. `scripts/lockstep.py --python `, all 80 cases (114,000 frames): **80 of 80 identical**. Every trace, both boards', is byte-identical to the 2026-11-19 run (reference `227de45` on m68000-python `38dbd0f`, this board on `ce3b489`): the rewritten divide clocks give the same counts (m68000-rust's own record: 0 of 633,847 inputs differ), so nothing a case reaches moved. Seeded faults not rerun. ## A stopped 68000 wakes for VINT again (2026-11-21) Found downstream: our demo cartridges RICK ROLL MD and BAD APPLE MD (play-md's included games) showed one black frame forever. Both wait in `STOP #$2300`. The IPL synchronizer (`IPL_SYNC_MCLK`) measured its deadline from the 68000's latest bus cycle, which a stopped 68000 never moves, so every VINT raised after the STOP was too late for good. Reported upstream and fixed there first: megadrive-python `b2259f3` (the rule) and `3e2325f` (its measurement against Nuked-MD: recorded, not adopted; undocumented-behavior item 22). While stopped, the deadline is the idle step's start less the lead (`IPL_SYNC_WHILE_STOPPED`), transcribed line for line. The reference pin moves to `3e2325f`. Gates, at `1adc5b4` (this note's commit changes only documents and the fault list): - `cargo test` 23 passed. The examples `h32-sprites` and `window-bug` wait in `stop #$2000` and were regenerated from the reference: their VINT handlers had run once and never again (d7, the frame counter, stuck at 1); now it counts every frame. `board-tour`, `board-tour-nuked` and `h32-raster` do not STOP and are unchanged. - `scripts/lockstep.py --python ` (a clone of the local repository at that commit, with the five cores its pyproject pins installed from their local clones: `fetch_megadrivepython.sh` cannot install the unpinned sound cores from an index), all 80 cases: **80 of 80 identical**. Against the previous run (reference `6303613`, `external/traces-waveB`) two cases' traces changed, both because they STOP: `rickroll-mapper` (the 5 MB Rickroll: 869 of 900 frames ended stopped before, 120 now; 6 distinct pictures before, 149 now) and `soft-checker` (Sega's MD Soft Checker: 768 ended stopped, 33 now; 22 distinct pictures, 47 now). Every other case is byte-identical. - `scripts/seeded_faults.py`: a 43rd fault, `IPL_SYNC_WHILE_STOPPED = false`, caught by 5 of 86 checks (`cargo test` first). The other 42 were not rerun. - RICK ROLL MD and BAD APPLE MD, `md-run --no-sound --png-dir`, 600 frames: 278 and 258 distinct pictures over frames 2-600, as megadrive-rust-fast `9847aab` gave before the regression. - Clippy from the stable toolchain flags two lints in `src/mappers.rs` (a collapsible `if` in a `match`, a manual range check) that this change does not touch: a newer clippy than the one CI last ran. ## Save states (2026-11-23) megadrive-python `1e8dcd3` specified save states (its docs/save-states.md) and built them (`state.py`): the whole console between two 68000 steps, a header refused up front, the body found by walking the object graph. Transcribed here as `src/state.rs` (`9d5629d`): the same boundary, the same header content (magic, version, the cartridge images' SHA-1, the machine, the wiring) checked before the body is read, the same inventory, the same configuration left out and taken from the system loaded into, all or nothing. What Rust forced: the body is serde-derived structs in bincode (famicom-rust's precedent), each skipped field named in `Config`; the line and frame tables written as which one; the CPUs' and the SSP1601's fields mirrored (no core changed; the sound cores' existing `serde` feature is used); the renderer's palettes written once each by content. The format is not shared with the reference's, so there is no cross-load; the cross-tier check is by trace instead (below). `save_snapshot`/`load_snapshot` are the body alone, for rewind and run-ahead. The save-state rung, `scripts/state_rung.py`: every case of `cases.tsv` run by `md-trace` straight through and interrupted -- saved a third of the way in 1,777 steps into the frame and loaded into a freshly built system, saved again at the half, and at two thirds a snapshot taken, three frames run and the snapshot put back into the same system -- and the two traces compared line for line. **80 of 80 identical** (with `EXTRA_ROMS` and `TITAN_DEMOS` set). `--reference` makes megadrive-python's run the interrupted one, through its own `state.py` (`scripts/md_trace.py --save-at`, `--rewind-at`): Sonic the Hedgehog, 300 frames, saved at 100+1,777 steps and 150 and rewound at 200, gives this board's uninterrupted trace byte for byte. Seeded faults of the rung (`state_rung.py --faults`, 14 changes to the state code, each against all 80 cases at most 900 frames, and `cargo test --test state` in the faulted copy, built with fresh timestamps): **13 of 14 caught**. The traces caught 8 (the HINT counter, the FIFO, the Z80's held instruction, the 68000's clock, the DSP's RAM, the analogue filter, the Sega mapper's banks, the sprite cache; 3 to 80 cases each). Five more held, at the rung's save points, values that made them equivalent there (the long and short H40 lines are in force only on an interlaced odd field's VSYNC lines; the frame table is latched again at VBlank, before the first line where V28 PAL and NTSC differ; the Z80's EI delay, a 6-button pad's TH count and a serial EEPROM's address are idle at a frame's start), so `tests/state.rs` holds them directly: every line and frame table comes back as itself, and those fields set to live values survive a load; all five are caught by it. The fourteenth, the stall credit not restored, is equivalent everywhere: `Md::step` clears it before reading it. The fault script's copy uses fresh timestamps (`copy_function=shutil.copy`); `seeded_faults.py`'s `copytree` keeps the originals', which the methodology's 2026-11-13 lesson says can let cargo reuse a stale build: not changed here, noted for whoever runs it next. `tests/state.rs`, 8 tests without a ROM: the example cartridges saved at seven step counts (198 inside a VRAM fill, 1,409 with a Z80 instruction held by a bus request) and continued 4,000 steps, every step's clocks and PCs and the memories, picture and sound equal, and the whole snapshot equal after the load and at the end; `--save-at` and `--rewind-at` against the reference's example traces; the refusals (garbage, another cartridge, machine, pad, a damaged body), each leaving the system as it was; the host's FM switch and sample rate kept; one snapshot loaded again and again; the tables; the idle fields. Gates, at this entry's commit: `cargo test` 31 passed; clippy (stable) clean; rustfmt clean; `scripts/lockstep.py` against megadrive-python `1e8dcd3` (its PyPy venv, the reference checkout moved from `3e2325f`: the state module, documents and scripts only), all 80 cases with `EXTRA_ROMS` and `TITAN_DEMOS` set: **80 of 80 identical** (the reference up to 705 s a case, 10 at a time); the save-state rung 80 of 80. ## The drawing switch, undrawn frames, and the SVP's ROM DMA (2026-11-23) Transcribed from megadrive-python `5351daf`, `4872910` and `efd80fc` (`d6972cd`, `4088297`): - **The drawing switch gates only the pixels.** `render_at` no longer depends on `rendering`; `begin_line` on an undrawn line runs phase 3 without pixels and the next line's scan, so line $1FF's scan, the X = 0 mask and the collision flag are what a drawn frame gives. `render::SEEN`, `Renderer::seen` and `state::machine_snapshot` (the reference's `machine_state`) compare consoles by everything but the picture. - **`VdpState::undrawn_frame`**: a host's undrawn frame, cleared by the VDP at V = 0 so the next frame is drawn from its first line even when the step that ends `run_frame` has run some of its lines. `md-play --skip` uses it. - **States, version 2**: `rendering` and `undrawn_frame` are host settings (`Config`). The SVP's ROM words were already left out here. The SVP's idle map is a `BTreeMap`: as a `HashMap` two equal consoles saved unequal bytes (the hasher's seed), which play-md's state comparison caught on Virtua Racing. - **The SVP's ROM DMA one word late**, as its DRAM's (svpdoc 4): Virtua Racing's speedometer needle was split. A new case, `board-svp-usa-race`, scripts the game into a race and holds accelerate for 600 frames. - `tests/drawing_switch.rs`: the examples drawn one frame in three against every frame (steps, machine snapshot, picture), and `rendering` off for a whole run. Gates: `cargo test` passes. `scripts/lockstep.py` against megadrive-python `4872910` (its PyPy venv), `EXTRA_ROMS` and `TITAN_DEMOS` set: **81 of 81 identical** (the reference up to 377 s a case, 14 at a time); `md-trace` was rebuilt part way through the run with `undrawn_frame` added, which no trace sets. The reference's `efd80fc` changes only what a host asks (`undrawn_frame`, the frontend), nothing a trace runs. The save-state rung at `4088297`: **81 of 81**. Clippy was not run: the `stable` toolchain's clippy and rustc here disagree on versions. ## The expansion sockets (2026-11-25, branch `sockets`) The reference pin `efd80fc` already held every line of the sockets (built there on 2026-10-21/22 as `00910ab`, `5f3bd13`, `6b2583d`, `ebd1771`, merged `44ab15d`, carried through its history reset `6303613`; megadrive-python's `pin-2-od2` after `efd80fc` changes documents and scripts only), so this was a transcription with no repin. `d39b9bf`: `src/sockets.rs` (the nine Protocols as traits, the two records) and the call sites in `board.rs`, `system.rs`, `vdp.rs`, `render.rs`, `audio.rs`, `cartridge.rs`, `state.rs`; what Rust forced is in `sockets.rs`'s header. Found on the way, kept as transcription: the reference's `_vdp_hold` goes through `hold`, so this one's does too (the same arithmetic). State version 3: the header's wiring names the sockets' devices. Tests: `tests/sockets.rs`, the reference's `tests/test_sockets.py` (19 of its 20; the pickle test has no counterpart), on its fakes (`tests/support/fake_devices.rs`). Lockstep rung 6 (`socket-*`, six cases): the same fakes plugged in on both sides by `md-trace --fake` / `scripts/md_trace.py --fake` (the reference's own `tests/fake_devices.py`), each frame's `D` line every access, clock and master the device was handed. The save-state rung leaves them out (a device's side is not in a state). Gates, at `d39b9bf`, nothing attached on the 81 old cases: `cargo test` 53 passed (34 before); `scripts/lockstep.py` against megadrive-python `efd80fc` (its PyPy venv, `EXTRA_ROMS` and `TITAN_DEMOS` set, 12 at a time, load about 90): **87 of 87 identical**, traces in `external/traces-sockets` (the old `external/traces` left as it was); the save-state rung **81 of 81**; rustfmt clean. Not run: clippy (the toolchain mismatch noted above), and `scripts/seeded_faults.py`: its fault "BUSREQ sampled 34 after" looks for `Z80_BUSREQ_LAG_MCLK: i64 = 33`, which is 32 since the reference's change, so the script stops at that fault before running any (on `pin-2-od2` as well); no socket faults are in it yet.