# Work log What was run, when, with what command and result; every decision with its reason; every open question for the user, marked `QUESTION:`. Newest entries at the end of each section. The reviewing session reads this first. > **Redacted 2026-11-19 (provenance wave 2).** Earlier sessions read the GPL and > non-commercial emulators' and models' source and cited it here by file, line, > function and internal node, with fragments of code and quoted comments. The family's > rules no longer allow reading that source, so those citations and fragments are > replaced by "[GPL source cited, redacted]", "[source name redacted]", "[internal > node]" or "[a quoted source comment, redacted]"; the account of what was done and > measured is kept. Findings that rested on such reading are re-established or > withdrawn in `docs/provenance.md` (wave 2) and the code's comments. ## Session 1 (2026-09-22): milestones 1 and 2 ### How the brief was read Scope is milestones 1 and 2 only: the board with both CPUs checked in a two-CPU MAME lockstep (at least five games, at least 30 s each), then the VDP's ports, FIFO, DMA, counters and interrupts judged by Nemesis's HV/status captures and VDPFIFOTesting. No pixels, no sound. Stop after milestone 2 and write the summary. ### Environment - Repository at `9459975` when the session started; m68000-python pinned at `51ee1a5a1ac9be2a773476d264e859adb2fb6c94` (its HEAD, clean, "Add the claim boundary: docs/claims.md"); z80-python 0.4.0 from PyPI. - `.venv`: CPython 3.14.4. `.venv-pypy`: PyPy 7.3.23 (Python 3.11.15), from `~/.local/bin/pypy3.11`. Both made with `python -m venv`, then `pip install /data/emu/m68000-python "z80-python>=0.4.0" pytest ruff==0.16.8` and `pip install --no-deps -e .` (the local clone at the pinned revision stands in for the git URL pinned in `pyproject.toml`, which CI uses). - `python scripts/fetch_references.py --verify`: "all pins satisfied". - MAME 0.285 (`/usr/games/mame -version`: `0.285 (unknown)`). ### Proposed core change (m68000-python) The board places each 68000 bus access at its own clock inside the instruction. m68000-python adds 4 to `_cycles` before calling the host for each access (`_core.py`, `_read_word` and friends), so inside a bus callback `_cycles - 4` is the access's start, counted from the start of the step. The board reads that private attribute in exactly one place, `Board.m68k_access_clock`, labelled as a workaround. Proposed PR for m68000-python: a read-only property ```python @property def step_clocks(self) -> int: """Clocks spent so far in the step in progress; inside a bus callback, the clocks before this access plus its own 4 (the access is counted as it starts).""" return self._cycles ``` documented in the embedding contract, with a test that a host callback sees 4, 8, 12 for the three reads of `MOVE.L (A0),D0`'s prefetch-read-read pattern (or whatever order the corpus records). Not made from here: the brief forbids changing the core. Update (2026-09-22, from the coordinator): the change is proposed as **m68000-python PR #1** (branch `step-clocks`, CI green, not merged): a read-only property `M68000CPU.step_clocks` returning `_cycles`; inside a bus callable the access occupies `step_clocks - 4 .. step_clocks`; inside `acknowledge` the acknowledge cycle is not yet counted; after `step()` it equals the step's total; the core models no wait states, so the host adds its stalls to `step()`'s total (as `System.step` does). The board keeps its labelled workaround in `Board.m68k_access_clock` (one line to change to `cpu.step_clocks` when the PR merges); the pinned revision is unchanged and the branch is not installed. ### Milestone 1: the board and both CPUs #### Decisions - **Scheduler** (`src/megadrive_python/system.py`, docstring): master clocks; the 68000 leads; the VDP catches up lazily (when touched, and at the start of each 68000 step); each 68000 access is placed at its own clock (`Board.m68k_access_clock`); stalls are added to the step of the CPU that suffers them (`Board.stall`); the Z80 runs in the 68000's wake and is caught up before every 68000 access that changes what it can see (its RAM, bus request, reset, the YM2612, the bank). Reason: the 68000's accesses are the ones that must land on the right clock (FIFO and slots), and m68000-python can say where each falls; z80-python reports only instruction totals. - **The Z80 gives up its bus at the end of a machine cycle**, not of an instruction: "BUSREQ ... is sampled by the CPU with the rising edge of the last clock period of any machine cycle" (Zilog UM0080, specification tier). z80-python has no machine-cycle hook, so `System.z80_access_offsets` runs the next instruction once on a probe bus (side-effect free: RAM and ROM only, the CPU state restored) and estimates when each data access starts (4 T for M1 fetches, 3 for other fetches and data accesses, internal T-states unplaced, so each estimate is the earliest). An instruction under way at a bus request whose accesses are not all started is run after the bus comes back. An approximation, to be judged in milestone 3/5 by MoD's `gen_test_z80_bus` ("BUSACK delay", "Delay with 6T M-cycle"). - **The bus grant is immediate** in the board (the $A11100 bit reads "granted" as soon as the request is written), as in MAME. MoD measured 2 cycles from /BR to /BG with a logic analyser (forum t=1661); the board does not model that yet. Open until `gen_test_z80_bus` is run. - **Byte and word rules** follow CMD `gen-hw.txt` 1.2 (hardware-checked) where MAME differs: a word read of Z80 RAM duplicates the even byte (MAME returns both bytes); a word write to Z80 space writes the MSB; the Z80 area without the bus reads the next opcode's MSB with a zero LSB (MAME: `machine().rand()`); $A11100 reads the next opcode's MSB with bit 0 (byte) or bit 8 (word) the grant, LSB zero (MAME: rand in the other bits). A 68000 byte write drives the byte on both halves of the data bus (68000 UM 5.1.2), so $A11100/$A11200 see bit 0 of a byte written to either address. - **Open bus is IRC**: CMD's "next instruction to be fetched" is, at a data access in m68000-python, `irc` (the queue has moved past the extension words). - **The Z80 reading 68000 RAM through its bank returns $FF** (MoD's test, several machines: reads fail; CMD: "returns FFh"). MAME returns the RAM. - **Cartridge ROM** is padded with $FF to a power of two and mirrored through 4 MB, as MAME loads it (detector; no hardware source in reference/ says what a board decodes). - **The I/O chip's power-on values** are CMD 3.0's ($7F data, 0 control, $FF TxData). #### The lockstep and what it found `scripts/mame_trace.py` (recording) and `scripts/lockstep_mame.py` + `scripts/mame_log.py` (replay). Findings, in the order they were diagnosed: 1. **The Z80's `totalcycles` is not a master-clock time.** It stands still while the Z80 is held in reset and restarts from about 0 when MAME resets it (Sonic: the first Z80 instruction at count 0 although the 68000 released it at its cycle 984; after a later reset the count goes from 168,824 to 10). While the 68000 holds the bus it keeps counting, but by MAME's timeslices, not exactly the hold (a 347.2- cycle hold shows as a 348-354-cycle jump; a 389.2 one as 392). So `docs/mame-oracle.md` trap 2's "the 68000's totalcycles × 7 and the Z80's × 15 are both master clocks from power-on" is wrong for the Z80; fixed in its own commit. An attempt to merge by count with re-anchoring at each release drifted by tens of cycles a frame and, once a stall was attributed to the wrong request, stayed a whole frame out. 2. **MAME's Z80 honours BUSREQ only at an instruction boundary** (MAME 0.285 `src/devices/cpu/z80/z80.lst`, the `ffff` block before each opcode fetch), but an instruction under way when the 68000 writes the request finishes in the Z80's next timeslice, *after* the 68000's own: Sonic's 68000 reads $A01FFD and gets $FD while the Z80's `LD (HL),H` at $00A2 (writing $1F there) was logged before the request (MAME Z80 cycle 10,242,048, 68000 cycle 66,545,929). Hardware releases at the end of the machine cycle (UM0080), which gives the same result here. 3. **The fix for the merge: markers.** `scripts/mame_trace.py` now also watches, in the Z80's run, the 68000's accesses to $A00000-$A0FFFF, $A11100 and $A11200 (`wpset a00000:maincpu,...`), logged with the Z80's own count. Each marker places one 68000 access in the Z80's stream exactly where MAME interleaved it. The lockstep runs the Z80 up to the marker of each such 68000 access; a record the marker falls inside is run before it if the board's access-offset model has all its accesses started by the marker's count, after it otherwise. Between markers the Z80 runs by its count, anchored at the last marker. 4. MAME adds one 68000 clock to every access to $A00000-$A0FFFF (`before_delay(1)`, `megadriv.cpp`, "required by pacman2 intro", "TODO: unverified"), and stalls the 68000 for length / 3.5 ns on a 68000-to-VDP DMA ("a hack until real DMA timings are implemented", `315_5313.cpp`). Both are sorted as named classes of clock difference. 5. **MAME clears the Z80's R (and I) on reset; z80-python 0.4.0 does not.** Zilog UM0080: RESET "clears the Program Counter and registers I and R". Found when R was added to the trace (Sonic 3's driver does `LD A,R`). The board clears I and R itself after a reset (`System._z80_reset_line`, labelled). **Proposed change for z80-python** (not made from here): `_accept_reset` should set `self.i = 0` and `self.r = 0`, with a test citing UM0080's reset description. 6. **MAME's Z80 count need not restart at a reset** (Phantasy Star IV: 168,824 then 230,489), so a record the reset cut short is recognised by its markers (a reset written while the record is under way), not by the count alone; the order the Z80's next registers require (finished before the reset, or cut) is then checked. 7. The in-flight instruction around a 68000 access: the markers' Z80 count does not say how far into its instruction the Z80 was (MAME stops a slice mid-instruction), so the lockstep decides with the board's machine-cycle estimate and, if the Z80's next registers or the 68000's read of Z80 RAM show MAME ran it on the other side, replays it in that order and counts a named difference. Totals below. 8. Battery RAM starts at $FF (as MAME: Sonic 3 reads its FRAM with `MOVEP.W` before writing it). No hardware source says what an unwritten chip holds. #### Milestone 1 acceptance: result (2026-09-22) Command, per game: `python scripts/mame_trace.py genesis GAME.zip --seconds 30 --out tests/mame_traces/genesis-NAME` (MAME 0.285, `genesis` driver, 6-7 min each), then `.venv-pypy/bin/python scripts/lockstep_mame.py tests/mame_traces/genesis-NAME` (PyPy 7.3.23 / Python 3.11.15; the six in parallel under `nice`). Code at the commit that adds this entry; m68000-python 51ee1a5, z80-python 0.4.0. | Game (No-Intro, local romset) | image SHA-256 (first 16) | 68000 instr. | Z80 instr. | 68000 ints | Z80 ints | unexplained | wall | | --- | --- | ---: | ---: | ---: | ---: | ---: | ---: | | Sonic The Hedgehog (USA, Europe) | 46160baa06362c71 | 23,286,815 | 12,728,465 | 1,495 | 0 | 0 | 111 s | | Streets of Rage 2 (USA) | 4a314edbfee92282 | 21,274,844 | 11,269,553 | 1,647 | 0 | 0 | 106 s | | Gunstar Heroes (USA) | f177810ce614be21 | 20,854,523 | 15,425,681 | 48,152 | 0 | 0 | 112 s | | Castlevania - Bloodlines (USA) | 5bfe171f5c251600 | 11,343,385 | 8,460,818 | 3,233 | 0 | 0 | 75 s | | Sonic The Hedgehog 3 (USA) (FRAM board) | d6404843c5ba3248 | 21,741,798 | 11,837,738 | 1,787 | 1,688 | 0 | 109 s | | Phantasy Star IV (USA) (SRAM board) | 511f35cc11f88316 | 21,254,417 | 13,280,703 | 1,792 | 0 | 0 | 105 s | | **Total** | | **119,755,782** | **73,002,958** | | | **0** | | Every register of both CPUs identical before every logged instruction (the 68000's 19 values, the Z80's 13 including R), every 68000 access to the VDP, Z80 space, I/O and bus/reset registers and every Z80 access to $4000-$FFFF matched in kind, address and size, every write in value. Interrupts are taken where MAME took them (the VDP is a stub). Named differences (MAME's value given to the CPU), summed over the six: YM2612 status replayed (stub) 90,707; $A11100's non-grant bits (MAME `rand()`, board next opcode's MSB) 47,067 (per-game counts in `tests/mame_traces/results/`, not committed); VDP reads replayed (stub) 10,879; Z80-RAM reads inside a Z80 instruction, sorted to MAME's side by value 516; Z80 instructions replayed in the other order around a 68000 access 47; the I/O data latch's bit 7 before any write (MAME 1, CMD 0) 1. Every 68000 clock interval equals the core's, or differs by MAME's `before_delay(1)` per $A0xxxx access, or by MAME's DMA spin, or is an interrupt entry that agrees; every Z80 interval agrees or spans a bus-request hold. What is *not* claimed: the timing of the Z80's bus handover (MAME's is scheduler-shaped; the board's is an estimate), the arbiter's delays, the VDP, the YM2612, and anything the stubs replay. **End of milestone 1.** Carrying on with milestone 2. ### Milestone 2: the VDP's ports, FIFO, DMA, counters and interrupts #### Decisions - **The VDP is Exodus's model, written anew.** Exodus (MIT, by Nemesis, the author of both judges) is the documented source for the port, FIFO, read-cache, DMA and slot rules; `vdp.py` cites file and line for each (`S315-5313_Ports.cpp`, `S315-5313_General.cpp`, `S315-5313_Timing.cpp`). No code is copied (Exodus is MIT, but the rule is to write our own); GPL emulators were not read for this. - **The refresh stalls** (`board.py`). Kabuto describes the cartridge-side one ("every time 128 cycles have passed the next bus access is slowed down by 2 cycles") and says work RAM has its own. To place both to the MCLK I built Nuked-MD (die-derived, GPL-2.0, `reference/src/Nuked-MD` @ 594ca2a) headless in `reference/build-nuked-md/` (ignored: `headless.c` replaces its SDL audio/video, logs the 68000 bus, `-DTMSS_ENABLE=0`, and the capture ROMs patched with a `move.l #'SEGA',$A14000` stub at $1F000; `gcc -O2 -w -Wno-incompatible-pointer-types`), ran probe loops and the capture ROMs, and fitted the rules to its bus logs: a fixed 896-MCLK grid whose tick the next bus cycle absorbs, +14 MCLK only if that cycle is a cartridge access (670 of 670 ticks in four probe loops); the next work-RAM access once due +21 MCLK, due again ~805 MCLK after (the capture loop allows 743-826). On Nuked-MD's own run of the capture ROM the rules reproduce every one of its 76,800 bus cycles' stretches (log of one run, 2.2 M MCLK). Nuked-MD is a detector here; the judge is the captures, whose loop rate (143.588 MCLK an instruction) the rules give. Nuked-MD shows other RAM-stretch lengths (7/35 MCLK) in other loops, not modelled. - **What a capture fit may set, and nothing else**: where in its line the VDP is, the 9-bit V and ODD, a pending H mode, the two refresh phases. Everything else is the board's, the same for every dump. The fit first missed on some dumps with cartridge stalls every few ticks: running Nuked-MD on the capture ROM at 16 button times reproduced the misses, the board's rules matched Nuked-MD's bus to the cycle, and the fault was the fitter's coordinate descent; it is now a search over all phase pairs. - **HV sampling.** A read samples at the first pixel-clock edge at or after 3 MCLK into its bus cycle (`HV_SAMPLE_DELAY`); fitted, as no document gives it. The reads that disagreed then all fell at one phase each (the counter stepping as sampled) and showed ripple-counter values; the two consoles differ there, so the board carries both measured units (`HV_UNITS`) and picks one by region (`Machine.hv_unit`). Where the hardware's own reads at a phase vary, the majority is taken and the rest counted apart. This is fitting the judge's data to the judge; it is stated so wherever it appears. - **Later runs.** Nemesis's ROM runs the loop, sends RAM, waits for C and jumps back to the loop, so dumps 2-9 of a capture start from the first run's state: F set, V mode and interlace latched (`later_run`). Dump 1 is the only one after power-on: there F reads clear until the first VBlank, in 27 of the 28 SR-type captures. Nuked-MD probes showed why: in mode 4 (power-on) any register write clears F; in mode 5 none does. Modelled in `VDP._control_write`. - **VDPFIFOTesting is read from VRAM**, page by page with Start, each result byte's palette giving match or mismatch, as sms-python's `run_vdptest.py`. #### Runs and results (2026-09-22) - `.venv-pypy/bin/python scripts/run_hv_captures.py` (commit 4743f9f; 288 dumps, PyPy 7.3.23 / Python 3.11.15, 16 processes, 76-78 s): **8,762,415 of 8,847,360 words equal (99.04 %)**. The rest: 61,440 in two unplaced dumps ("HV noint intdub NTSCJ H40V28" 1, whose H low nibble reads 3 in every sample and whose status shows DMA busy; "HV noint intinv PAL H40V30" 1); 11,103 in "HV noint intinv PAL H40V28" 6 (H one step behind in every second read); 9,869 reads at a stepping phase; 1,288 the F flag in "HV noint intnorm PAL H32V30" 1 (set from the start: the one first run that is); 705 VBlank (668 in the first runs of "intnorm NTSCJ H32V28" and "H40V28", set before the first VBlank); 228 HBlank at its edges; 302 H/V reads, mostly interlaced NTSC V30 H32; 10 sprite overflow. Per capture in `tests/hv_captures_baseline.json`. - `.venv-pypy/bin/python scripts/run_vdpfifotesting.py --machine M` (commit 4743f9f; ROM `VDPFIFOTesting/VDPFIFOTesting.bin` SHA-256 8b0ed3944893d679…, 3-4 s): 122 of 122 on genesis, genesis-tmss, genesis2, megadrive, megadrive-tmss, megadrive2, megadrive-japan, megadrive2-japan; genesis3 114 of 122 (the eight DMA Fill to VSRAM tests). The four intermittent tests pass. On the way: 110 of 122 as first written; the VSRAM-past-the-end read (+8), the transfer's start address (+3), and the transfer holding the 68000's next bus cycle rather than the write that started it (+1, FIFO Wait States, which Exodus fails) fixed it. - Lockstep sanity with the new VDP (commit f2055a5): Sonic The Hedgehog (USA, Europe) and Gunstar Heroes (USA) re-recorded (MAME 0.285, 30 s) and replayed: 23,286,815 / 20,854,523 68000 and 12,728,465 / 15,425,681 Z80 instructions, 0 unexplained each, 44 s / 47 s. Traces deleted. - `pytest` (commit 8babd34): 14 passed on PyPy (84 s) and CPython 3.14.4 (178 s), the milestone-1 replay skipped (no logs kept). - A standalone check: Sonic The Hedgehog runs 300 frames with the Z80 driving the YM2612 (27,032 FM writes by frame 300), 686,617 68000 steps a second of emulated time; 60 NTSC frames in 0.36 s on PyPy. #### Milestone 2 acceptance: what passes and what does not - **VDPFIFOTesting: passes** as the brief states it: every test Nemesis reports passing on hardware passes; the intermittent ones are listed (they pass); the Genesis 3 variant fails VSRAM tests. Which VSRAM tests a Genesis 3 fails is not published, so only "some, and only VSRAM ones" is checked. - **The captures: does not pass as stated** ("equal the captures sample for sample in every mode captured"): 99.04 % of words. Most of the rest is not deterministic on the hardware (the same console reads differently at the same phase, between and within runs) or is in four anomalous dumps; about 2,500 differences remain unexplained, listed above and in docs/timing.md. The per-mode tables the brief asked for are in docs/timing.md, "What the captures say". QUESTION: The capture acceptance cannot be met literally; the board takes the majority reading at the phases where the hardware's own reads vary. Is 99.04 % with every remaining difference classified acceptable, or should the unexplained ~2,500 (HBlank edges, first-run VBlank, NTSC interlaced V30) be pursued before milestone 3? QUESTION: Two captured consoles read the counters differently where they step. The board picks the PAL unit's rules for PAL machines and the NTSC-J unit's for NTSC ones (`Machine.hv_unit`). Keep that, or make one the default for all? QUESTION: The work-RAM refresh interval (805 MCLK) and stretch (21 MCLK) come from Nuked-MD, judged only by the capture loop's rate. Accept Nuked-MD as the basis for the work-RAM refresh until a hardware measurement exists? QUESTION: CI needs read access to the private m68000-python repository: add a secret `M68000_PYTHON_TOKEN` (a fine-grained token with read access to it), or make m68000-python public, or vendor a wheel? QUESTION (from milestone 1, still open): the Z80's interrupt length and the Z80 bus-grant delay (MoD: 2 cycles /BR to /BG) are not modelled; they wait for MoD's `gen_test_z80_bus` in milestone 3. **End of milestone 2.** Stopping here, as the working agreement says. ## Decisions (the user, 2026-09-22), answering milestone 2's questions 1. **The captures' 99.04 % is accepted for milestone 2.** The claim is stated as what it is ("8,762,415 of 8,847,360 words, every difference classified"), never as "sample for sample". The four anomalous dumps are worth a cheap look later; the ~2,500 unexplained words do not block milestone 3. 2. **The per-console H/V stepping tables stay**, chosen by region (`Machine.hv_unit`), **labelled as an assumption**: two consoles were captured, so it is not known whether the difference follows the region or the individual chip. Say so where the tables are defined and in undocumented-behavior.md. 3. **Nuked-MD is accepted as the basis for the work-RAM refresh** until a hardware measurement exists, as the tier rule allows for a die-derived model where no hardware source covers the question; the capture loop's rate agrees with it independently. Keep it labelled. 4. **CI reaches m68000-python with a read-only deploy key** (an SSH key whose public half is a read-only deploy key on m68000-python, private half the `M68000_PYTHON_KEY` secret here): narrower than a personal token, since it reaches that one repository and nothing else. 5. **The Z80's interrupt length and bus-grant delay** stay for milestone 3, judged by MoD's `gen_test_z80_bus`. Also decided: z80-python's reset not clearing I and R is being proposed as a PR there by the reviewing session; keep the board's labelled workaround until it lands. ## Session 2 (2026-09-22): milestone 3, the VDP's picture ### How the brief was read Scope is milestone 3 only: planes A and B with every scroll mode, the window, sprites (the cache, the phases, the per-line and per-pixel limits, masking, the X = 0 rule), priority, shadow/highlight, H32/H40, V28/V30, both interlace modes, 128 KB mode; judged by Nemesis's sprite masking ROM against his MD1600 chart, r57shell's VDP tests against the MD2 report in forum t=1585, CMD's window and colour tests against his capture photos, MoD's `gen_test_z80_bus`, and MAME's exit frames as a detector. Render per line, and record frames per second on PyPy. Stop after that. Also inherited: the Z80's interrupt length and the Z80 bus-grant delay to settle; the core-side workarounds stay (docs/polish.md, the user's decision to batch them). ### Environment Same as session 1: `.venv` CPython 3.14.4, `.venv-pypy` PyPy 7.3.23 (Python 3.11.15), m68000-python pinned at 51ee1a5 (unchanged, as docs/polish.md says), z80-python 0.4.0, MAME 0.285, machine a 13th-generation Core i9-13900K with 32 threads. `python scripts/fetch_references.py --verify`: "all pins satisfied" (with the two new pins below). ### The renderer `src/megadrive_python/render.py` (560 lines), called by the VDP at each line's HBlank-clear point -- where its active display begins -- so that an H interrupt handler's writes, made in the horizontal blank just before, are already in the registers. Decisions and their sources: - **A line at a time, not a pixel at a time**, as the brief requires: the line's scroll values, both planes' names and patterns, the sprites and the mixing are done in one pass. What this loses is written in the module's docstring: a CRAM or register write part way *along* a line lands at that line's start (CRAM dots are milestone 5), and the sprite phases are evaluated together rather than spread over the two preceding lines. - **Sprites follow Kabuto's phases**, with his X = 0 rule carried from line to line: "Rendering of further sprite pixels is disabled whenever a sprite is read from a cache slot with X=0 when the previous sprite read (no matter whether that happened on the same line, previous line or even a previous frame) had X != 0", and "When there are less than 40 sprite tiles on a raster line then further dummy sprites act as if they had X=0". Nemesis's four masking rules (forum t=541 start=30) then fall out of that one mechanism instead of being coded one by one -- including the one he says "Nothing emulates", a mask in the first slot becoming effective when the previous line ended on a dot overflow. - **The sprite cache** is written through by VRAM writes that land in the sprite table, checked over the whole 128 KB range and never filled by moving the table (Kabuto). It is checked against the address as the program gives it, not the byte-swapped one the VDP stores at. - **Shadow/highlight is Kabuto's three steps** in order, which reproduce his table (colour 63 shadows, 62 highlights or returns a shadowed pixel to normal, colours 14/30/46 cancel a shadow) and Genesis Plus GX's `make_lut_bgobj_ste` case for case. - **The colour ramp** is TmEE's oscilloscope measurement (forum t=2188, "All MD models I tested ... seemed to have identical output"), which Plutiedev's page and MAME's palette both come from, so MAME's frames compare as they stand. - **The debug register's plane forcing** (bits 8-6) is Kabuto's mixer `(A|!a)&(B|!b)&(S|!s)&(G|!g)` with one plane held visible; the other bits are not modelled. - **Status bits 6 and 5** (sprite overflow, collision) are set by the renderer and cleared when the status register is read, as Genesis Plus GX does; CMD says only that both are "most likely cleared at the end of the frame", so this is emulator-derived and labelled as such in `vdp.status`. Found by running the test ROMs against MAME's frames (all of these are in the second commit's message with their numbers): 1. **Plane sizes.** The invalid width (HSZ = 10b) shows the name table's *first row* on every line (CMD), which a 32-cell wrap does not give; the vertical wrap is a mask (0x2FF for the invalid height), not a modulus. The row shift and masks are Genesis Plus GX's tables, the only statement of the invalid sizes' shape; CMD's sentence agrees where the two overlap. `wbug.bin` 91.73 % -> 99.84 % of MAME's pixels. 2. **The window bug** hits the *partial* column the fine scroll puts before plane A's first whole 2-cell column, so that column's two cells repeat in the column after it -- CMD's "1 column that has identical patterns as the next column". Genesis Plus GX reads it the same way ([source name redacted]); MAME reads it as a half-column rule with a `(hscroll & 0xf) < 8` test, which is the 112 pixels of `wbug.bin` still differing. 3. **Interlace mode 2 addresses patterns as (name & 0x3FF) * 64.** CMD says "Bit zero of the name is ignored in interlace mode 2", which would be (name & 0x7FE) * 32; Exodus (`CalculatePatternDataRowAddress`), Genesis Plus GX ([source name redacted]) and MAME (`get_nametable`, `m_imode == 3`) all take the low bits and multiply by 64. Three against one, one of them Nemesis: CMD is wrong here. `wtest_i2.bin` 74.78 % -> 96.25 %. 4. **Base address masks** as CMD gives them: plane A and B to 0xE000, the window to 0xF800 and to 0xF000 in H40 ("In 40-cell mode, A11 is always forced to zero" -- the board was clearing A10), the scroll table to 0xFC00. 5. **Each row keeps the palette it was drawn with**, so a game that rewrites CRAM part way down the frame keeps each band's colours, and a frame is as wide as its widest row, so a mid-frame H32/H40 switch is not cropped (CMD photographed one). ### 128 KB mode Writes only: one byte per word (the other goes to the chip that is not there), bit 0 of the address ignored, the address bits rearranged by Kabuto's formula, and one access slot instead of two, which is why "write/DMA speed to VRAM increases to that of CRAM and VSRAM". What the mode does to the *picture* is not modelled: with one VRAM chip fitted the hardware shows "garbled display contents", and no pinned test covers it. Overdrive 2 (milestone 5) is the judge. The board's address register is 16 bits, so bit 16 -- which 128 KB mode stops ignoring -- is carried only in the sprite cache's check. *(Corrected 2026-09-27, Session 13: that dropped bit 16 from every write, and the sprite cache compares all 17 bits in 64 KB mode too. The address register is now 17 bits; Overdrive 2's rain needed it. See "The rain".)* ### Milestone 3 acceptance: the runs and their results (2026-09-22) All at commit `4890f03` unless said; m68000-python 51ee1a5, z80-python 0.4.0, MAME 0.285. **Nemesis's sprite masking ROM against his MD1600** (hardware-captured; the judge). His two photographs are now pinned (`reference/images/MD1600SpriteMask{H32,H40}.png`, SHA-256 in `scripts/pinned_files.json`) and neither contains a single red pixel, so all nine tests pass on his machine in both modes. `python scripts/run_sprite_masking.py` (ROM SHA-256 in the pin file, 2 s): **0 of 18 result cells differ** -- nine tests, two cells each, H32 and H40. That covers the per-line sprite limit, both dot-overflow tests, masking in and out of the first slot, masking after a dot overflow, the non-existent masking mode 2, and the per-frame limits (64 entries in H32, 80 in H40). The mode switch: the ROM polls bit 5 of $A10003 without making TH an output, so on a 3-button pad it is reading C rather than Start, and the harness presses both. **MoD's `gen_test_z80_bus`** (hardware-corrected; `gen_test_z80_bus.md`). `python scripts/run_z80_bus_test.py` (2 s): the eight checks the ROM makes all print PASS -- RESET and not BUSREQ $00DE, RESET and BUSREQ $0000, BUSREQ and not RESET $0078, normal operation $0034, byte writes + word read $7878, word write + byte reads $BE89, unused BUSACK bits $00C0, unused RESET bits $00C0 -- and the two it only prints: **Z80 writes to work RAM $4243, Z80 reads to work RAM $FFFF**, which is what MoD reports from several machines ("writes always worked and reads always failed"). Its two delay counts print **0000 and 0000** (below). **CMD's window and colour tests, and TmEE's** (`md_test.zip`), each against MAME's own frame after the same 3 emulated seconds (`scripts/compare_mame_frames.py --record`; MAME is a detector, never a judge): | ROM | pixels equal | what the rest is | | --- | ---: | --- | | `wtest.bin` (window) | 100.00 % | | | `wtest_i1.bin` (interlace 1) | 100.00 % | | | `wtest_i2.bin` (interlace 2) | 96.25 % | the window's vertical range in interlace mode 2: the board covers V counter lines 0..WVP*8, as Genesis Plus GX does; MAME halves it | | `wbug.bin` (the window bug) | 99.84 % | the bug's 112 pixels, above | | `stetest.bin` (S/H) | 100.00 % | | | `STETEST2.bin` (S/H) | 41.97 % | two thirds shadow-versus-normal (below); the rest a palette index difference in a mid-frame raster test, not run down | | `SHLTEST.BIN` (TmEE) | 69.64 % | every one of the 21,760 differing pixels is the board's shadow of MAME's colour | | `vctest.bin` (V counter) | 96.93 % | every differing pixel likewise | | r57shell `vdp_tests.bin` | 100.00 % | | The shadow-versus-normal difference is deliberate: in shadow/highlight mode the board darkens the backdrop and every pixel where both planes are low priority, which is Kabuto's measured rule ("If both A+B are low prio, the visible color becomes shadowed"), CMD's `ste.htm` ("The changes in intensity due to a tile's priority setting will also affect any parts of the backdrop color that can be seen") and Genesis Plus GX (`make_lut_bg_ste`: "Half intensity when both pixels are low priority"). MAME's backdrop pixels carry its normal-intensity flag instead. Three sources against one detector: the board keeps its rule and the difference is named here. **r57shell's VDP tests** (hardware-corrected by the MD2 report in forum t=1585): the ROM runs and its first screen, "VDP Redraw Time Test 1", renders pixel for pixel as MAME renders it. It says "You MUST SEE right column of spheres" and neither the board nor MAME shows them: the test wants VRAM writes to land *within* the line being drawn, which a per-line renderer cannot do. **Not passed**, and not comparable either: the thread's hardware evidence is photographs of a CRT plus prose (MrTamk1s, an MD2 VA1.8 with a 315-5708-01: "VDP Redraw Test #4 acted differently on my smaller CRT and on the Big CRT"), and no pad button the board models moves the ROM off its first screen -- it polls the pad seven times a frame, which is the 6-button handshake (milestone 7). **MAME's exit frames on the lockstep games** (detector). `scripts/compare_mame_frames.py --record` at four lengths, six games, `genesis`: | Game | 2 s | 5 s | 10 s | 20 s | | --- | ---: | ---: | ---: | ---: | | Sonic The Hedgehog (USA, Europe) | 98.65 / 100.00 | 100.00 | 72.46 / 77.31 | 92.10 / 93.10 | | Streets of Rage 2 (USA) | 100.00 | 100.00 | 99.97 / 100.00 | 99.91 / 99.96 | | Gunstar Heroes (USA) | 100.00 | 100.00 | 100.00 | 82.75 / 86.71 | | Castlevania - Bloodlines (USA) | 100.00 | 100.00 | 98.90 / 99.31 | 91.10 / 92.90 | | Sonic The Hedgehog 3 (USA) | 100.00 | 28.87 | 99.87 | 99.90 / 99.95 | | Phantasy Star IV (USA) | 100.00 | 92.57 / 100.00 | 100.00 | 93.03 / 93.54 | (exact frame / best of the eight frames around it, where they differ). Every static screen is identical; every lower figure is a moving demo or animation a few frames out of phase -- Sonic 3 at 5 s is its transformation sequence, the same picture at a different phase. Nothing structural showed up in any of the 24 comparisons. **Milestone 1 and 2, unchanged by all of this**: Sonic The Hedgehog re-recorded from MAME 0.285 (30 emulated seconds) and replayed: 23,286,815 68000 and 12,728,465 Z80 instructions identical, 0 unexplained, 44 s (the named differences: 5,258 YM2612 status replayed, 3,165 $A11100 non-grant bits, 1,477 VDP reads replayed, 41,274 steps differing by MAME's `before_delay(1)`, 3,276 by its DMA stall). VDPFIFOTesting 122 of 122 on `genesis`; the HV captures 8,762,415 of 8,847,360 words, the same as the milestone-2 baseline to the word. `pytest`: 19 passed on PyPy (96 s). The trace was deleted (3.4 GB). ### Frames per second on PyPy (the brief's speed section) `.venv-pypy/bin/python`, 900 frames after 120 frames of warm-up, one process, NTSC (59.92 frames a second is real time): | Game | fps | fps with the renderer turned off | 68000 instructions a second | | --- | ---: | ---: | ---: | | Sonic The Hedgehog (USA, Europe) | 147.7 | 367.2 | 1,882,988 | | Streets of Rage 2 (USA) | 215.3 | 434.0 | 2,397,718 | | Gunstar Heroes (USA) | 163.0 | 294.1 | 1,741,528 | | Castlevania - Bloodlines (USA) | 293.6 | 705.0 | 1,304,430 | | Sonic The Hedgehog 3 (USA) | 181.5 | 411.0 | 2,046,804 | | Phantasy Star IV (USA) | 223.9 | 425.4 | 2,519,624 | So 2.5 to 4.9 times real time with the picture, and the picture costs between half and two thirds of the time. On CPython 3.14.4 the same Sonic run is 23.9 fps, as expected. The YM2612 (milestone 4) has yet to be paid for. ### The two open items from milestone 1 **The Z80's interrupt length: kept at one line.** No hardware measurement is pinned; CMD (`gen-hw.txt` 2.4) gives the line and says the interrupt is missed if the Z80 has interrupts disabled, and Genesis Plus GX holds it to the end of that line, which is what the board does (`VDP.z80_irq_at`, labelled). What can be said for it: in the milestone-1 lockstep Sonic The Hedgehog 3 takes 1,688 Z80 interrupts in 30 seconds, all of them at the instruction MAME took them at, which a much shorter or longer window would not give. It stays emulator-derived. **The Z80 bus-grant delay: measured, not modelled, and here is why.** The board grants the bus at once, as MAME does, so MoD's two counts print 0000. A delayed grant was written and tried: the Z80 samples BUSREQ "with the rising edge of the last clock period of any machine cycle" (Zilog UM0080), so the grant falls at the end of the machine cycle in progress, which the board can estimate from `System.z80_probe` (its machine-cycle ends, the last one being the step's own length so that trailing internal cycles belong to it). With that in place the $A11100 read reports "busy" until the grant, and a 68000 access to the Z80's space in between has to *wait* -- the arbiter holds it, it does not drop the access (Kabuto: the 68000 waits about 11 of its cycles when both want the bus). Holding the 68000 moves its later accesses in the same instruction to later clocks, which moves the points at which the Z80 is caught up, and Sonic's Z80 then runs one instruction ahead of MAME's (a write to the bank register that MAME had not made yet): the milestone-1 lockstep diverges after 912,165 instructions. MAME grants the bus at once and models no arbiter stall, so the two cannot both hold. Since no hardware value for either count is published in the pinned material -- MoD's thread reports the ROM but not its numbers, and his logic-analyser measurement (2 68000 cycles from /BR to /BG, forum t=1661) is of the *other* direction, the Z80 reaching the 68000's bus -- there is nothing to judge the model by, and the lockstep is a real detector today. The delay is therefore left to milestone 5, whose subject is exactly the arbiter's delays and which will have to teach the lockstep about board stalls anyway. Recorded in docs/undocumented-behavior.md. QUESTION: is that the right call? The alternative is to model the BUSACK wait now and accept that the milestone-1 lockstep can no longer be replayed instruction for instruction against MAME (it would need a "the board waits for BUSACK, MAME does not" class, and the Z80 interleaving would have to be compared some other way). QUESTION: r57shell's redraw-timing tests want VRAM writes to land inside the line being drawn. Rendering per line is what the brief asks for and what pays for the frame rate above; drawing per pixel-clock would cost a lot of it. Leave those tests failing, or plan a per-slot renderer for milestone 5 (it is the same machinery CRAM dots need)? QUESTION: the window's vertical range in interlace mode 2 differs between Genesis Plus GX (the board's choice: V counter lines, so twice as many field lines) and MAME. No hardware source covers it and CMD's `wtest_i2.bin` is a picture, not a self-check. Accept the current choice? QUESTION: 128 KB mode's writes are implemented from Kabuto's formulas with nothing to judge them until Overdrive 2 in milestone 5, and its effect on the picture is not modelled at all. Accept, or leave 128 KB mode out until there is a judge? ## Decisions (the user, 2026-09-22), answering milestone 3's questions 1. **The Z80 BUSACK delay waits for milestone 5** (the arbiter), where the bus timing is settled as a whole. Modelling it now would cost the instruction-exact milestone-1 replay, which is the regression net for everything else. The test ROM's own delay counts (0000/0000) stay recorded as a known difference from MoD's hardware report. 2. **The per-slot renderer is planned for milestone 5**, with the CRAM dots: the same machinery serves r57shell's redraw-timing tests, and its cost in frames per second is measured once, there. 3. **The IM2 window vertical range stays Genesis Plus GX's**, labelled as a detector-tier choice with MAME's alternative recorded beside it, until a hardware source settles it. 4. **128 KB mode stays**, judged by Overdrive 2 in milestone 5. ## Session 3 (2026-09-22): milestone 4, sound ### How the brief was read Scope is milestone 4 only: the PSG after sms-python's, judged by Nuked-PSG; the YM2612 with all six channels, channel 3's special mode, CSM, SSG-EG, the LFO, both timers, BUSY, the DAC and the ladder effect as a variant field, judged by Nuked-OPN2's YM2612 mode and YM2608-LLE's YM2612 path sample for sample at the chip's native rate for register streams from Nemesis's test ROMs and five games; Nemesis's SSG-EG test against his MD1600 recording by measurement; the MDFourier signal against the recordings as a detector of the analogue model. Record the FM's cost per emulated second on PyPy. Then stop. The tier rule for this milestone, as the brief states it: the recordings are hardware-captured and judge; the die-derived models judge where no capture covers the question; MAME and Genesis Plus GX are detectors. There is no YM2612 datasheet and no self-checking FM test ROM (docs/validation.md), so the chips' *arithmetic* is exactly the case where the die-derived models judge, and that is how the FM and PSG comparisons below are stated. ### Environment Same as the previous sessions: `.venv` CPython 3.14.4, `.venv-pypy` PyPy 7.3.23 (Python 3.11.15), m68000-python pinned at 51ee1a5 (unchanged: docs/polish.md), z80-python 0.4.0, MAME 0.285, the 13th-generation Core i9-13900K. gcc 15.2.0 (Ubuntu 15.2.0-16ubuntu1) for the referees. `unrar` 7.20 and `ffmpeg` for the recordings. The machine was shared with other work for part of the session, which the wall times below reflect. The large material was already fetched (`python scripts/fetch_references.py --large` in an earlier session): `tests/test_roms/nemesis/ssg-eg md1600*.rar`, `tests/test_roms/mdfourier/MDFourier-Genesis-SegaCD-Recordings-14062020.zip`, `tests/test_roms/aly-james/MD1_LADDER.wav`. Everything unpacked from them was deleted at the end of the session and none of it is committed. ### The three referees `sh validation/build_referees.sh` builds all three into `reference/build-referees/` (git-ignored, beside the previous session's `reference/build-nuked-md/`): ```sh gcc -O2 -w -I reference/src/Nuked-OPN2 -o reference/build-referees/opn2_ref \ validation/opn2_ref.c reference/src/Nuked-OPN2/ym3438.c gcc -O2 -w -I reference/src/Nuked-PSG -o reference/build-referees/psg_ref \ validation/psg_ref.c reference/src/Nuked-PSG/ympsg.c gcc -O2 -w -I reference/src/YM2608-LLE -o reference/build-referees/lle2612_ref \ validation/lle2612_ref.c reference/src/YM2608-LLE/fmopna_2612.c ``` Each takes a binary event file of `{u64 clock; u8 port; u8 data}` and writes a binary result; the clock unit is documented in each `validation/*.c`. Nothing of the referees' source is copied into this repository -- the three `.c` files here only drive them, and the licences (LGPL-2.1, GPL-2.0+, GPL-2.0) stay with the sources in `reference/`, which is ignored. `lle2612_ref` is a *pin-level* harness: /IC held for 4,096 chip clocks, then /CS and /WR driven low for 16 chip clocks per write, with A0 and A1 from the port. That matters below. ### The PSG #### Decisions - **It is sms-python's, adapted, not imported** (the brief's rule): same three tone channels, one noise channel, one write-only port, 16-bit LFSR. Cited in the module docstring by file. - **The generator runs the die's rotation, not a four-channels-at-once tick.** sms-python advances all four channels together once per 16 input clocks; that is right for its own judge. Here the judge is Nuked-PSG and matching it needs the shape the die has, which turned out to be four things sms-python does differently: two internal phases a quarter of the input clock apart with one counter stepped per phase pair; the *period* taken from a one-hot selector that runs one place behind the counter index (so counter 0 is the noise channel's and counter 1 tone 1's); an up-counter compared with the period rather than a down-counter reloaded at zero; and a left-shifting LFSR tapped at bits 15 and 12 with a zero-detect, its output bit 14 latched a phase behind. - **A write reaches the register on the next input clock -- or on the same one.** Nuked-PSG updates the registers at the head of every clock *and* again inside the second internal phase ([GPL source cited, redacted]), so a write landing on that phase is a clock earlier than one that does not. Found by measurement: without it, 19 of 102,569 input clocks differed on the first random stream, every one of them at a write. Modelled. - **Power-on is the /IC sequence, run, not asserted.** Nuked-PSG's [source name redacted] holds /IC over 16 clocks and releases it, which leaves the counters at 1, the overflow shift register full (0x0F) and the one-hot selector at bit 3 -- not a zeroed machine. `PSG.reset` runs the same 16 clocks and the state then matches Nuked's field for field (checked in `tests/test_milestone4.py`). - **The attenuation curve is the measured one** (`ympsg_vol`: 1.0, 0.772, 0.622, 0.485, ...), not the ideal 2 dB a step sms-python uses (1.0, 0.794, 0.631, ...). Recorded in docs/undocumented-behavior.md. - **The port decode is CMD's**: "Doing byte-wide writes to even PSG addresses has no effect", and a word write must carry the data in the LSB (CMD `gen-hw.txt` 1 note 3). Reading the port locks up, so there is no read. #### What is compared, exactly `scripts/run_psg_compare.py` compares **the four attenuations the chip is driving, at every input clock** (MCLK / 15, 3.58 MHz) -- sixteen times finer than the chip's own output rate. That is the whole digital state; nothing is averaged and nothing is rounded. Nuked's *analogue* level is not compared, because the board uses Nuked's own measured curve and comparing it would be circular; the curve itself is checked entry by entry in the tests. ### The YM2612 #### The one decision everything else follows from **The model is the chip's pipeline, not a per-sample FM loop.** The acceptance is sample-for-sample equality with two die-derived models, and a textbook OPN2 cannot meet that bar however carefully it is written. The real chip serves one operator per internal cycle, 24 cycles to an output sample, and every stage sits a fixed number of cycles behind the slot being served: the phase generator 19 and 20, the envelope 22 and 23, the modulation 6 and 18, the channel accumulator 18. A register written between two cycles therefore reaches one operator this sample and the next operator only next sample, and the envelope's total level and sustain level are each delayed a further cycle. Only the same pipeline gives the same samples. So `src/megadrive_python/ym2612.py` runs the chip's cycle: `cycles` counts 0-23, slots 0-5 are the six channels' operator 1, 6-11 operator 3, 12-17 operator 2, 18-23 operator 4. Its shape, its stage offsets and its constant tables are read from **Nuked-OPN2** ([GPL source cited, redacted], LGPL-2.1, the YM3438's die) and **YM2608-LLE** ([GPL source cited, redacted], GPL-2.0, the NMOS YM2612's die), cited by file and line in every method. No code is copied: the models were read and this was written from what they say, as the working agreement requires. The two ROM tables are **generated**, not transcribed: `round(-log2(sin((i + 0.5) * pi / 512)) * 256)` and `round((2 ** (i / 256) - 1) * 1024)`, the functions Gambrell and Niemitalo recovered from the OPL2's ROM and which Nuked-OPN2 credits for the same tables. `tests/test_milestone4.py` checks all 512 entries against the pinned model's own. The other constants (the detune increments, the envelope step table, the two LFO shift tables, the LFO reloads, the algorithm matrix) are measurements of the chip carried as data, each with the line they were read from. #### Decisions and their sources - **BUSY** is set only by a *data* write and lasts 32 internal cycles, which at 6 68000 clocks a cycle is Eke's "32 internal clocks (32 x 6 68000 cycles)" read the other way round (forum t=386 start=810, hardware-captured). The model is structural, not a timer: the die's own counter. - **BUSY reads from port 0 only on the discrete chip, from every port on the ASIC** (Eke, same measurement), which is `FMVariant.busy_on_all_ports`. What a discrete chip's other three ports read is not in any pinned source; the board returns 0, which is Genesis Plus GX's choice (`core/sound/sound.c` line 152), labelled emulator-derived and listed as an open item. - **Kabuto's "wait about 33.6 Z80 cycles between register writes"** is modelled by construction, not by a delay: the chip has no register RAM the CPU can reach, and a write waits in a latch until the cycle that serves the addressed slot comes round. - **The ladder effect is `FMVariant.ladder`**, as the brief asks. With it, the discrete chip's output stage drives the channel's value on one of the channel's four cycles and the bare sign (+1 or -1) on the other three, adds 1 to every non-negative sample and triples everything; without it, the ASIC drives the value on three of the four and zero on the fourth, unamplified. - **The DAC** is 9 bits: register $2A carries the top eight and the test register $2C bit 3 the ninth, which is where Kabuto's "9 bits" comes from. Its *sampling point* within a cycle, which he says differs between Model 1 and Model 2 and did not publish, is not modelled: the board sums a sample's 24 multiplexed values, the same on both. - **The /RESET line is shared with the Z80** (CMD 2.2), so the board holds the chip at power-on and a game that pulses it clears the chip -- but not the samples already made, which are the output queue and not chip state. #### What is compared, exactly `scripts/run_fm_streams.py` runs each register stream from power-on and compares **every value of both DAC pins, one per internal cycle** -- 24 to an output sample, so a stricter test than sample-for-sample at the chip's native rate -- plus the status byte (BUSY and both timer overflow flags) on the same cycles. Nothing is averaged, nothing is rounded, and a stream either matches on every cycle or the first differing cycle is printed with both values. Both chip variants are run against the matching Nuked-OPN2 mode. The streams are: two seeded random walks over the whole register space; six aimed streams (channel 3's special mode and CSM at three timer-A rates, all eight SSG-EG shapes keyed on and off, the LFO at all eight speeds against every PMS and AMS depth, both timers at four reloads, the DAC through every value and its ninth bit); Nemesis's six YM2612 test ROMs run on the board; and five cartridges run on the board. The ROM and game streams are *the board's own*: the writes its YM2612 received, at the internal cycle it received them on, captured with the generator turned off (the register stream does not depend on it). So a difference there would be the board's scheduling as much as the chip's. #### YM2608-LLE: what it agrees with and what it does not YM2608-LLE is a **pin-level** model at MCLK / 7 of the NMOS YM2612's own die, so it is the better authority for the discrete chip's output stage than Nuked-OPN2, whose YM2612 mode its own comment calls [a quoted source comment, redacted] ([GPL source cited, redacted]). Comparing the two showed one real difference and one artefact of the harnesses, and both are worth recording. **The real one.** The six channels are multiplexed onto MOL/MOR four cycles each. YM2608-LLE drives the channel's value on the *first* of its four cycles and the bare sign (+1 or -1) on the other three ([GPL source cited, redacted]). Nuked-OPN2 drives the sign on three and the value on the *last* ([GPL source cited, redacted], [source name redacted]). Measured on the channel-3 stream: YM2608-LLE puts -14 at the start of the group and -1 for the next three cycles; the board (following Nuked-OPN2) puts -1 for three cycles and -16 at the end. The 24 values of an output sample are the same multiset either way, so the sample at the chip's native rate is unaffected and nothing audible turns on it. The board keeps Nuked-OPN2's order, because that is what the cycle-exact comparison above is made against, and the difference is recorded in docs/undocumented-behavior.md ("The YM2612" item 6). **The artefact.** A write is driven differently in the two harnesses: `lle2612_ref` holds /CS and /WR low for 16 chip clocks, as a bus cycle does, while [source name redacted] latches an edge. A write can therefore land one internal cycle apart in the two. The comparison is then made at the chip's native rate (each model's DAC summed over a sample, one phase and one whole-sample lag fitted over the run), and what is left scales with how often the stream writes: | Stream (24 x 20,000 cycles each) | samples differing | | --- | --- | | SSG-EG, all eight shapes | **0** of 19,898 | | both timers | **0** | | the DAC | **0** | | channel 3 special mode and CSM | 1 of 19,898 (0.01 %) | | the LFO, 8 speeds x 8 PMS x 4 AMS (292 writes) | 325 of 19,898 (1.63 %) | | a random walk, one write per 36 cycles | 4,351-7,179 of ~20,900 (21-34 %) | | a random walk, one write per 4,000 cycles | 25 of 67,299 (0.04 %) | | a random walk, one write per 1,000 cycles | 12 of 17,424 (0.07 %) | and the differences are transient: on the dense stream, 1,200 writes produce 146 runs of differing samples, median length 1 sample and mean 4.4, after which the two models agree again. That is what a one-cycle difference in when a write lands looks like; it is not a difference in either chip's arithmetic. Shifting the LLE harness's write by a few chip clocks moves the count (642 -> 547 at -9 clocks) but does not remove it, which is expected: the landing cycle differs only for writes that fall near a boundary. **So, stated precisely:** at the chip's native rate the board and YM2608-LLE are identical over the SSG-EG, timer and DAC streams and differ on 1 sample in 19,898 on the CSM stream; on streams that write every few tens of cycles they differ in bursts around writes that the two harnesses place a cycle apart, and re-converge. This is *not* the literal "equal sample for sample" the brief asks for, and the reason is measured above rather than argued. ### The analogue path `src/megadrive_python/audio.py`. Three signals leave the board -- MOL, MOR and the PSG's one output -- and meet in an amplifier that differs by revision. What is modelled, and what is not: - **The PSG is box-filtered onto the FM's grid with an integer phase.** Five FM samples take exactly 21 PSG samples (1,008 x 5 = 240 x 21), so nothing drifts over a long run. - **A low-pass**: one pole for `model1`, two cascaded for `model2`, which is Kabuto's "instead of the MD1's 1st order filter there's a 2nd order filter". He gives no corner frequency and nothing pinned does, so the board's are **fitted** and labelled where they are defined. - **A DC blocker**, which the coupling capacitor at the jack is. This is not cosmetic: the discrete YM2612 drives +1 in every gap between channels, which is a standing 72 units of every sample even in silence, so without it a recording of the board sits far off zero and a silence is not silent. Found by measurement: the first MDFourier run could not find the signal's silences at all. - **No distortion model.** Kabuto measures the Model 2's amplifier as introducing "severe nonlinearities ... Distortion is quite high too, very well audible" and publishes no transfer curve. The board's Model 2 is therefore cleaner than the hardware's, and docs/undocumented-behavior.md says so. - **The PSG-to-FM mixing ratio** is the one number the MDFourier recordings measure directly (below). ### The ladder effect, against Aly James's MD1_LADDER.wav (hardware-captured) `MD1_LADDER.wav` is 3.1 seconds of a real Model 1 playing a tone whose level is walked down. Its envelope, measured in 50 ms blocks, falls smoothly for the first half and then **stops falling about 33 dB below its peak**, staying there for about 0.8 s before the note reaches absolute silence. That plateau is the ladder: the +1 the discrete chip adds to every non-negative sample, and the bare sign it drives between channels, do not shrink with the note. `python scripts/run_fm_streams.py --ladder tests/test_roms/aly-james/MD1_LADDER.wav` walks one operator's total level from 0 to 127 on the board and prints each machine's level profile in decibels below its own peak, at ten points along the ramp: | | peak | 0 | 1/10 | 2/10 | 3/10 | 4/10 | 5/10 | 6/10 | 7/10 | 8/10 | 9/10 | 10/10 | | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | | board, discrete YM2612 | 222.9 | 0.0 | -9.7 | -18.5 | -27.2 | -34.0 | **-36.1** | **-37.1** | **-37.0** | -40.4 | silence | silence | | board, ASIC YM3438 | 128.3 | 0.0 | -9.8 | -18.7 | -28.2 | -37.9 | -46.1 | -49.0 | -48.9 | -52.4 | silence | silence | | `MD1_LADDER.wav` (a Model 1) | 19,670 | 0.0 | -9.5 | -18.2 | -25.7 | -30.7 | **-32.8** | **-32.8** | **-33.0** | -42.6 | -61.1 | -61.2 | The board's discrete variant plateaus at -36 to -37 dB where the Model 1 plateaus at -33; its ASIC variant does not plateau at all, falling another 12 dB. So **the board's ladder has the hardware's shape, within 4 dB of its depth, and the variant field does what it is there for**. What this does *not* claim: the two ramps are not the same ramp (the recording's ROM is not published, its console's filter and the capture's gain are unknown), so the 4 dB is not an error figure -- it is the distance between two differently made measurements of the same effect. Nothing here is rounded into a pass. ### Nemesis's SSG-EG test against his MD1600 recording (hardware-captured, the judge) `tests/test_roms/nemesis/ssg-eg md1600.rar` unpacks to 83.3 s of mono 96 kHz audio of his MD1600 running `ym2612ssg-eg.bin`. It cannot be compared sample for sample -- it is an analogue recording of unknown gain, with an unknown start offset, through the console's filter -- so `scripts/run_ssg_eg.py` compares what can be measured on both: how many notes sound, how long each lasts, how far apart they start, and the repetition period of the envelope inside each note, by autocorrelating its amplitude envelope (20 Hz blocks, RMS about each block's own mean, so neither signal's standing level counts as sound). ```sh unrar x "tests/test_roms/nemesis/ssg-eg md1600.rar" / .venv-pypy/bin/python scripts/run_ssg_eg.py --wav "/ssg-eg md1600.wav" ``` | note | MD1600 start | board | MD1600 length | board | MD1600 period | board | | ---: | ---: | ---: | ---: | ---: | ---: | ---: | | 0 | 0.00 | 0.00 | 0.40 | 0.45 | none | none | | 1 | 9.50 | 9.20 | 4.10 | 4.10 | none | none | | 2 | 18.80 | 18.40 | 0.10 | 0.10 | none | none | | 3 | 28.10 | 27.60 | 3.80 | 3.80 | **150 ms** | **150 ms** | | 4 | 37.35 | 36.85 | 4.35 | 4.30 | **50 ms** | **50 ms** | | 5 | 46.70 | 46.04 | 3.80 | 3.80 | none | none | | 6 | 55.95 | 55.24 | 4.35 | 4.30 | **50 ms** | **50 ms** | | 7 | 65.25 | 64.44 | 4.10 | 4.10 | **150 ms** | **150 ms** | | 8 | 74.55 | 73.64 | 0.10 | 0.10 | none | none | | 9 | -- | 82.84 | -- | 0.40 | -- | none | (times in seconds, relative to each machine's first note; the board's note 9 is the ROM starting round again, which the recording, begun 4.9 s in, does not reach.) **Every one of the eight SSG-EG shapes behaves the same way on both machines**: the three that hold or run to silence sound for 0.10-0.45 s and show no repeating envelope; the five that repeat sound for 3.80-4.35 s; and the four that repeat *visibly* do so at the same rate, 150 ms or 50 ms, to the resolution of the measurement (50 ms blocks). Every length agrees within one block. **What does not agree: the rate.** The MD1600's notes start 9.25-9.50 s apart and the board's 9.19-9.25 s, a steady **1.0-1.2 % difference** that accumulates to 0.91 s over the eight gaps. That is a clock ratio, not a structural difference: the ROM's own timing is the same number of frames on both. Two candidates, neither checkable from here -- the recorder's sample clock (a capture nominally at 96,000 Hz running 1.2 % slow would give exactly this) and the console's crystal against the nominal 53,693,175 Hz. It is recorded as an open item rather than guessed at. ### Milestone 4 acceptance: the runs and their results (2026-09-22) All at commit `383992c` unless said; m68000-python 51ee1a5, z80-python 0.4.0, PyPy 7.3.23 (Python 3.11.15), referees built as above with gcc 15.2.0. The machine was shared, so the wall times vary by up to a factor of three between runs of the same comparison. The MDFourier numbers below are from `46528e7`, which is `383992c` plus the two changes that run itself produced (the DC blocker and the fitted `PSG_GAIN`); nothing else in the sound path differs between the two. #### The PSG against Nuked-PSG (die-derived, the judge): passes `.venv-pypy/bin/python scripts/run_psg_compare.py --games`, 47 s. Ten streams, the four attenuations compared at **every input clock**: | Stream | input clocks | differing | | --- | ---: | ---: | | random walk (seed 1, 4,829 writes) | 1,028,959 | **0** | | random walk (seed 2, 4,812 writes) | 1,031,380 | **0** | | every tone period (0-7 and 8-1023 in steps of 37, all three channels) | 179,016 | **0** | | every noise setting (8 settings x 3 tone-3 periods) | 492,264 | **0** | | every attenuation on every channel | 115,064 | **0** | | Sonic The Hedgehog (USA, Europe) `46160baa…`, 400 frames, 12 writes | 19,567,876 | **0** | | Streets of Rage 2 (USA) `4a314edb…`, 400 frames, 52 writes | 22,135,675 | **0** | | Gunstar Heroes (USA) `f177810c…`, 400 frames, 16 writes | 6,903,440 | **0** | | Castlevania - Bloodlines (USA) `5bfe171f…`, 400 frames, 8 writes | 5,044,491 | **0** | | Phantasy Star IV (USA) `511f35cc…`, 400 frames, 447 writes | 23,802,440 | **0** | | **Total** | **80,300,605** | **0** | The games use the PSG sparsely (8 to 447 writes in 6.7 s), so most of those clocks are the free-running generators agreeing, which is the part a long run tests. #### The YM2612 against Nuked-OPN2 (die-derived, the judge): passes `.venv-pypy/bin/python scripts/run_fm_streams.py --roms --games`, 21 min. **18 streams, 0 comparisons not identical**: every value of MOL, every value of MOR and every value of the status byte, on every internal cycle, in **both** chip variants against the matching Nuked-OPN2 mode. | Stream | internal cycles | MOL | MOR | status | | --- | ---: | --- | --- | --- | | random walk (seed 1, 4,000 writes) | 504,939 | equal | equal | equal | | random walk (seed 2, 4,000 writes) | 502,904 | equal | equal | equal | | channel 3 special mode and CSM (3 timer-A rates) | 397,172 | equal | equal | equal | | SSG-EG, all eight shapes keyed on and off | 1,884,812 | equal | equal | equal | | the LFO, 8 speeds x 8 PMS x 4 AMS | 2,467,004 | equal | equal | equal | | both timers, four reloads each | 336,476 | equal | equal | equal | | the DAC, every value and the ninth bit | 31,532 | equal | equal | equal | | `ym2612csmmode.bin` `3faaae39…` | 123,658 | equal | equal | equal | | `ym2612ssg-eg.bin` `03a73fd6…` | 8,446,814 | equal | equal | equal | | `ym2612attackandrelease.bin` `06b72d38…` | 8,447,837 | equal | equal | equal | | `ym2612detune.bin` `74306d73…` | 123,557 | equal | equal | equal | | `ym2612multiplexing.bin` `519d19a0…` | 126,636 | equal | equal | equal | | `ym2612FrequencyWriteOrder.bin` `e79459a7…` | 123,607 | equal | equal | equal | | Sonic The Hedgehog (USA, Europe), 720 frames, 66,944 register writes | 15,351,279 | equal | equal | equal | | Streets of Rage 2 (USA), 720 frames, 2,750 | 15,350,206 | equal | equal | equal | | Gunstar Heroes (USA), 720 frames, 96 | 2,466,058 | equal | equal | equal | | Castlevania - Bloodlines (USA), 720 frames, 3,101 | 15,341,712 | equal | equal | equal | | Phantasy Star IV (USA), 720 frames, 45,260 | 15,351,280 | equal | equal | equal | | **Total** | **87,377,483** | | | | 87,377,483 internal cycles per variant, 174,754,966 over the two, and three values compared on each: **524,264,898 values, none different**. That is 68 emulated seconds of the chip's whole output, sampled 24 times per output sample. Two notes on the streams, neither a result: - **Gunstar Heroes reaches only 96 register writes** in 720 frames with Start pressed once: its driver wants Start at the title *and* at the mode select. With presses at frames 200, 400 and 600 it writes 176,586 registers by frame 1,400. The GAMES table and `capture_streams` now take several press frames; the run above predates that, so the Gunstar stream in it is the title screen's. - **Four of the six test ROMs write all their registers in the first tenth of a second** and then play, so their streams end early and the comparison runs 0.1 s past the last write. `--tail` runs further on. #### The MDFourier signal against the hardware recordings (a detector, and one fit) The 240p Test Suite's MDFourier signal is 172 tone blocks of 20 frames between two sync blocks: 96 FM, 40 PSG, 20 PSG ramp and 16 noise (`reference/src/MDFourier/profiles/mdfblocksGEN.mfn`). `scripts/run_mdfourier.py` drives the suite to it from its menus (down, down, A; down, down, A; A), records the board's own output, decodes a recording with ffmpeg, aligns both on their two syncs and measures each block's level (RMS about its own mean). MDFourier's own analyser is not built here: it needs FFTW and libFLAC and neither header is installed (docs/polish.md). ```sh unzip -j tests/test_roms/mdfourier/MDFourier-Genesis-SegaCD-Recordings-14062020.zip \ "Recordings-2020-06-14/A-MD1UTVA3-M192.flac" -d .venv-pypy/bin/python scripts/run_mdfourier.py --recording /A-MD1UTVA3-M192.flac ``` **The signal's timing matches exactly.** Both machines show ten loud regions and **58.40 s between the two syncs** -- the board's at 5.00 s and 63.40 s, the Model 1 VA3's at 1.50 s and 59.90 s. The signal is 3,520 frames, 58.74 s at the nominal 59.92 Hz, so both run it at the same rate and the 0.34 s is the trimming of the syncs' attack, not drift. (Worth noting against the SSG-EG recording's 1.0-1.2 %: whatever that was, it is not the board's frame rate.) **The mixing ratio, measured.** On the Model 1 VA3 the 40 PSG tone blocks sit **6.70 dB below** the 96 FM blocks. That is the one number `audio.PSG_GAIN` sets, and it was fitted here: at the gain the board started with (1,400) its PSG sat 3.72 dB *above* its FM, 10.42 dB too loud; at **422** (commit `46528e7`) it sits 6.66 dB below, **0.04 dB** from the hardware. This is the only parameter of the analogue path that a pinned source measures, and it is now measured rather than guessed. | group | hardware, relative to its own FM | board | board minus hardware | | --- | ---: | ---: | ---: | | FM (96 blocks) | 0.00 dB | 0.00 dB | (the reference) | | PSG tones (40) | -6.70 dB | -6.66 dB | **+0.04 dB** | | PSG ramp (20) | -7.10 dB | -7.17 dB | **-0.07 dB** | | noise (16) | -5.03 dB | -6.75 dB | **-1.72 dB** | **The filter, as a detector.** Each group's blocks climb through the chips' range, so the per-block difference is a frequency response. Board minus hardware, at twelve points through each group, each normalised by its own group's mean: ```text FM blocks 0..95 -0.2 -0.1 0.3 -0.1 -0.4 -0.4 -0.4 -0.3 0.1 0.5 0.9 1.1 PSG blocks 0..39 -1.6 -0.9 0.1 0.8 1.1 1.1 0.9 0.6 0.4 -0.2 -0.2 -0.5 noise blocks 0..15 1.0 0.4 -0.2 -0.0 0.4 -0.3 -0.1 -0.1 -0.3 -0.5 -0.8 -0.6 ``` Everything is inside **±1.6 dB**, so the one-pole low-pass at 8 kHz is in the right region: a corner badly wrong would tilt the FM's 96 blocks by many decibels end to end. The residual is a slight brightness at the top of the FM's range (+1.1 dB on the last block), which says the corner could be a little lower; that is left as a fit to revisit with MDFourier's own analyser, which does per-frequency work this measurement does not. **Not explained: the noise channel is 1.72 dB quieter, relative to the FM, than the hardware's.** The PSG's *digital* output is identical to Nuked-PSG's at every input clock, including every noise setting, so this is in the level model -- the attenuation curve applied to a pseudo-random bit stream against what the console's analogue stage does with it -- and not in the generator. Left open. ### Open questions for the user QUESTION: **YM2608-LLE cannot be matched literally.** The measurements above attribute the remaining differences to the two harnesses placing a write one internal cycle apart, and they re-converge. Is that characterisation acceptable, or should the LLE harness drive /CS and /WR aligned to the chip's own /6 phase (which means finding that phase in its state) so the comparison can be made literal? QUESTION: **The two die-derived models disagree about the DAC's multiplexing order** (docs/undocumented-behavior.md, "The YM2612" item 6). The board follows Nuked-OPN2, because that is what the cycle-exact comparison is made against -- but YM2608-LLE is a transcription of the *YM2612's* die and Nuked-OPN2's YM2612 mode is self-described as unverified, which makes LLE the better authority for exactly this. The output sample is the same either way. Keep Nuked-OPN2's order, switch to LLE's (and lose the cycle-exact comparison), or carry both as a variant? QUESTION: **The analogue path is fitted to one recording.** `PSG_GAIN` and the filter corner come from `A-MD1UTVA3-M192.flac`, one Model 1 VA3. The archive holds 21 boards. Fit per revision -- a table on the machine, which is what `audio_path` is there for -- or keep one Model 1 figure and one Model 2 figure? QUESTION: **The SSG-EG recording's notes start 1.0-1.2 % further apart than the board's**, while the MDFourier recording's syncs are exactly 58.40 s apart on both. That points at the SSG-EG recording's own clock rather than at the board, but it is not proved. Accept it as the recorder's, or pursue it (Nemesis's second SSG-EG recording, `ssg-eg md1600 attack and release.rar`, is 180 MB and untouched)? QUESTION: **Nemesis's CSM recording was not used.** docs/validation.md says to confirm in forum t=386 that `ym2612csmmode.wav` is from hardware before judging with it, and that was not done this session. Confirm and use it, or leave CSM judged by the die-derived models alone (where it passes cycle for cycle)? QUESTION: **What a discrete YM2612's ports 1-3 read** is Genesis Plus GX's 0, the only source there is (docs/undocumented-behavior.md, "The YM2612" item 7). Accept, or leave the board driving open bus there until someone measures it? QUESTION: **The noise channel is 1.72 dB quiet relative to the FM** against the MDFourier recording, while the PSG's tones are 0.04 dB out and its digital output is identical to Nuked-PSG's at every clock. Worth running down, or accepted as part of the analogue model's known looseness? ### What the sound costs on PyPy (the brief's speed section) `.venv-pypy/bin/python`, 600 frames after 120 of warm-up (Start at frame 110), one process, NTSC, at commit `2b113e5`. Four runs per game: the board as it ships; with `YM2612.enabled` off (the bus, the register file, the timers, BUSY and the PSG, no generator); with the YM2612 not advanced at all; and with neither chip advanced, which is the milestone-3 board measured in the same run for comparison. The last three columns are seconds of wall time per **emulated** second. | Game | fps, all | fps, no FM | fps, PSG only | fps, silent | sound s/s | FM s/s | PSG s/s | | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | | Sonic The Hedgehog (USA, Europe) | 18.2 | 49.9 | 139.5 | 185.9 | 2.97 | **2.86** | 0.11 | | Streets of Rage 2 (USA) | 21.4 | 57.3 | 177.0 | 205.4 | 2.51 | **2.46** | 0.05 | | Gunstar Heroes (USA) | 17.7 | 53.9 | 160.1 | 192.0 | 3.08 | **3.01** | 0.06 | | Castlevania - Bloodlines (USA) | 18.3 | 35.6 | 87.1 | 138.2 | 2.84 | **2.59** | 0.25 | | Sonic The Hedgehog 3 (USA) | 17.1 | 49.2 | 122.8 | 180.0 | 3.17 | **3.01** | 0.16 | | Phantasy Star IV (USA) | 17.5 | 40.8 | 124.3 | 152.7 | 3.03 | **2.94** | 0.09 | **The FM dominates, as the brief said it might: 2.5 to 3.0 seconds of wall time per emulated second**, against the PSG's 0.05 to 0.25 and the whole rest of the board's 0.32 (Sonic: 600 frames in 3.23 s silent). The board goes from 3.1 times real time to 0.29 times: with sound it is **17 to 21 frames a second on PyPy**, about a third of real time. Why, and what was done about it: the chip's grid is 1,278,409 internal cycles a second and each one runs seventeen stages of the pipeline over 24 slots' worth of state, so about 22 million method calls and a few hundred million integer operations per emulated second. The number is what modelling the pipeline costs, and the pipeline is what the acceptance above needs. One thing was cheap and is done: `YM2612.enabled` used to skip only the four operator stages, leaving the phase generator, the envelope generator, the LFO and the register decode running -- Sonic at 23.6 frames a second. It now skips the whole generator and keeps only the bus, the register file, the timers and BUSY, which is all a run without sound needs: 49.9 frames a second, and it is what `--no-sound`, the register-stream captures and a later compatibility sweep will use. What was *not* done, deliberately: flattening the seventeen stages into one method would likely buy something on PyPy, and it would touch every line the cycle-exact comparison rests on. Since that comparison is the whole evidence for this milestone and the tests would be the only net, it is left for a session that can re-run all eighteen streams afterwards, and recorded here rather than attempted at the end of this one. The machine was shared through the session: the "silent" column here (138 to 205 frames a second) is not directly comparable with milestone 3's table (148 to 294), which is why all four columns are measured in the same run. ### Milestones 1 to 3, unchanged by all of this `.venv-pypy/bin/python -m pytest -q` at commit `23e10d0`: **32 passed, 1 deselected** in 146 s (the deselected one is milestone 1's replay, which needs MAME logs that are not kept). That covers milestone 2's 288 HV/status capture dumps against `tests/hv_captures_baseline.json` and VDPFIFOTesting, and milestone 3's sprite masking ROM against Nemesis's MD1600 photographs and MoD's `gen_test_z80_bus`, all with the two sound chips now on the board. Nothing moved. The same suite on CPython 3.14.4 with the capture dumps deselected: 29 passed. ### One test failure that did not reproduce `tests/test_milestone4.py::test_ym2612_matches_nuked_opn2` failed once, while another comparison was running, and passed on both interpreters every other time (three runs after it). The subprocess it runs writes the referee's event and output files into `--tmp`, which defaults to `/tmp`, so two of them at once overwrite each other's -- the only explanation that fits. Those names now carry the process id (`scripts/audio_refs.py`). Recorded rather than left as a shrug: it is a real race whether or not it was this one. **End of milestone 4.** Stopping here, as the working agreement says. ## Decisions (the user, 2026-09-22), answering milestone 4's questions 1. **The YM2608-LLE difference is accepted as characterised**, not chased: the differences are transient, measured, and the cycle-exact anchor is Nuked-OPN2. Aligning its harness's write strobe is optional work, not a requirement. 2. **The DAC's multiplexing order stays Nuked-OPN2's**, with YM2608-LLE's disagreement recorded beside it (the cycle-exact comparison anchors there). 3. **The analogue path is fitted to two consoles, one Model 1 and one Model 2**, matching the machine variants the board models, not to all 21 recordings. 4. **The SSG-EG recording's 1.0-1.2 % rate difference is accepted** as that recording's clock (the MDFourier recordings show no such drift). 5. **Confirm `ym2612csmmode.wav`'s provenance** in the forum snapshot we already have (`reference/forum/spritesmind-t386*.html`); if it is from hardware, use it as a judge for CSM, otherwise leave CSM to the die-derived models. 6. **A discrete YM2612's ports 1-3 read Genesis Plus GX's `0`**, labelled emulator-derived until something better exists. 7. **The noise channel's 1.72 dB is accepted** as the analogue model's looseness: the digital output matches Nuked-PSG exactly, so the difference is in the analogue path or in that console. Also decided: **the FM's speed is its own milestone after the board is complete**. This pipeline stays as the reference implementation; any faster path is measured against it, and the cycle-exact comparison is the gate it must pass. ## Session 4 (2026-09-22): milestone 5, bus timing ### How the brief was read Scope is milestone 5 only: the arbiter's delays for Z80 bank accesses (Kabuto; MoD's logic analyser), the refresh steal, VDP stalls and DMA speed by the slot table, judged by VDPFIFOTesting's timing tests, Kabuto's DMA-cost formulas "reproduced within their stated form", and Overdrive 2 as a stress case against Kabuto's notes rather than pass/fail. Plus the two items earlier milestones deferred here: the Z80 bus-grant (BUSACK) delay, and the per-slot renderer with the CRAM dots, the latter to be kept or dropped on measured frames per second. Then stop. ### Environment Same as the previous sessions: `.venv` CPython 3.14.4, `.venv-pypy` PyPy 7.3.23 (Python 3.11.15), m68000-python pinned at 51ee1a5 (unchanged: docs/polish.md), z80-python 0.4.0, MAME 0.285, the 13th-generation Core i9-13900K. The machine was shared throughout, which the frame-rate numbers below reflect and which is why the renderer's cost is also measured a second, deterministic way. ### The arbiter `src/megadrive_python/arbiter.py` (95 lines) carries the two formulas and the quotations behind them; `board.py` and `system.py` wire them in; `scripts/run_bus_arbiter.py` (189 lines) measures them. #### What a Z80 bank access costs, and how it is modelled Kabuto's "The bus system" gives the averages ("delayed by 2 to 5 cycles ... The average Z80 delay is around 3.3 Z80 cycles, whereas the average 68k delay is around 11 68k cycles") and his **footnote 1** gives the arithmetic behind them, measured on his Model 1: ```text readdelay = a + 3 + b + 2 Z80 delay = ((readdelay*7 + 4 - subcycle)/15 68k delay = ((Z80 delay) * 15 + subcycle + 46) / 7 - a ``` with `a` "time until 68k finishes its last access before releasing the bus (1 to 6; 1 to 4 if there are no refresh delays)", `b` "2 if the z80->ROM access is prolonged by a refresh delay, 0 if not", and `subcycle` (0 to 6) "how much ahead of the starting 68k cycle the z80's request was to begin with". That is `bank_access_delay`, verbatim. What the board has to supply is `a`, `b` and `subcycle`: - **`a`** needs to know where the 68000's bus cycles fall. `Board._bus_cycle` -- the hook the refresh already used for every 68000 access -- now records each access's master clock for the step in progress, and `_m68k_release` walks them: an access under way, or one starting within Kabuto's "2 cycles ahead or less", is finished first, so `a` is the clocks left of it (1 to 6). - **`b`** is the cartridge refresh grid ticking inside the Z80's own access. The tick is *read*, not consumed: the 68000's accesses walk the same grid in `_bus_cycle` and, running ahead of the Z80 in this scheduler, would otherwise always have taken it first. That makes it about 14 MCLK in 896, 1.6 % of accesses. - **`subcycle`** is the access's master clock against the 68000's 7-MCLK grid. The Z80's share is added to its current step; **the 68000's share is owed to its next step** (`Board.m68k_pending_stall`), because the Z80 runs in the 68000's wake, so the instruction the delay really fell inside has already been executed. That is an approximation and is labelled as one. The access itself is placed at the Z80 step's start plus whatever it has already been held, because z80-python reports only an instruction's total. That is the one thing the model gets visibly wrong, and it is measured below rather than argued (docs/polish.md has the core change that would fix it). #### The bus grant (BUSACK), settled Milestone 3 measured this, implemented it and backed it out because holding the 68000 broke the milestone-1 lockstep. It is now modelled, and here is the reasoning in full. **What the hardware evidence is.** There is no published hardware number for this direction. MoD's t=1661 logic-analyser counts are of the *other* direction (the Z80 reaching the 68000's bus: "!BG will go low 2 68K cycles later"), and Kabuto's averages likewise. MoD's `gen_test_z80_bus` counts the BUSACK delay twice, but its hardware values are not in the pinned material. What there *is* is the specification: BUSREQ "is sampled by the CPU with the rising edge of the last clock period of any machine cycle", and the bus is released after it (Zilog UM0080). So the grant falls at the end of the machine cycle in progress, and a 68000 access to the Z80's space before then is held by the arbiter rather than failing. **What it costs.** Nothing, in the end, and that is the finding. The lockstep is not the price: MAME models no arbiter at all -- it grants at once and charges nothing for a Z80 bank access -- so `Board.arbiter_enabled` turns the whole of milestone 5's arbiter off for the replay, exactly as `refresh_enabled` has been turned off since milestone 1 for the refresh MAME also does not model. With that, the milestone-1 lockstep replays Sonic The Hedgehog instruction for instruction as before (below). And on MoD's ROM the grant delays the model produces are **0 to 9 68000 cycles**, every one of them shorter than the 8-cycle `move.b (a2),dN` the ROM measures with, so **its two counters still print 0000** -- the same result as with the immediate grant. So the specification's behaviour is modelled, the regression net is intact, and the one test that could disagree cannot see the difference. What *would* cost the lockstep is leaving the arbiter on during it, and that was never the right comparison: MAME is a detector, and a detector that models none of this milestone's subject cannot judge it. #### The measurements, against MoD and Kabuto `scripts/run_bus_arbiter.py` builds a small cartridge for each of MoD's experiments (the 68000 program that copies a Z80 program into the Z80's RAM, starts it and then holds the 68000 in the state the experiment wants) and records every delay the board's own arbiter charges. `.venv-pypy/bin/python scripts/run_bus_arbiter.py --accesses 4000` at commit `21038dd`, seconds: | Experiment | board, Z80 wait states | hardware | board, 68000 delay | | --- | --- | --- | ---: | | 68000 in `stop #$2700` (off the bus), Z80 reading the bank window | **2-3**, mean 2.27 (2: 2,923; 3: 1,077) | MoD: "2-3" | 10-12, mean 10.54 | | 68000 in his `jmp (a0)` loop ("constantly on the bus"), Z80 reading | **3-4**, mean 3.36 (3: 2,547; 4: 1,453) | MoD: "range is 2-4 ... about 2.93"; Kabuto: 2-5, mean 3.3 | 10-13, mean 10.95 | | the same, Z80 `pop`ping (his sound drivers' case) | 2-4, mean 2.53 | MoD: "at least 4 wait states" on the second read, mean 3.5 over 10 | 10-13, mean 10.43 | The first experiment reproduces MoD's range exactly. The second sits between his mean (2.93) and Kabuto's (3.3) at 3.36, inside Kabuto's 2-5 and one step narrower than MoD's 2-4. The 68000's delay is 10.4 to 11.0 cycles against Kabuto's "around 11" in all three. **The `pop` case is the one that does not agree**, and the reason is the modelling limitation above, not the formula: MoD saw the 68000 "sneak in a bus operation in between the first and second Z80 read", which needs the two reads placed at their own T-states; the board places both at nearly the same clock and charges 2.53 where he measured 3.5. Recorded as open item 14. #### The 68000's own rate, an independent check Kabuto also measured the whole stall model's effect in one number: "After all these slowdowns the 68K seems to be running at roughly 480 cycles per raster line instead of the theoretical 488+4/7 ones." With every stall the board charges -- both refreshes, the arbiter, the VDP -- the 68000 in the `jmp (a0)` harness keeps **481.0** of a line's 488.6 clocks for its own instructions. The six lockstep games, which also pay VDP stalls, run at 467.9 to 475.3 (`--cartridge`, 240 frames each). ### The DMA, and one correction to the slot table `scripts/run_dma_cost.py` (136 lines) measures the hold the VDP puts on the 68000 beyond the bus cycle of the control write that starts a transfer -- which is exactly Kabuto's "on top of what the actual 68k instructions cost" -- for four targets and ten word counts, and fits a line to it. **The correction.** The first run was 25 % slow on every fast transfer and the Manual's per-line table was out by 3 %. The cause: an idle line's access slots. Exodus's `GetPixelClockTicksUntilNextAccessSlot` jumps from a refresh block's start to six pixels past it, losing **two** slots per refresh, which leaves 161 (H32) and 198 (H40). Two hardware-tier sources say one: Kabuto's access pattern has a single `r` per group, and the Manual's DMA transfer capacity table gives 167 and 205 bytes a line in blanking, which is 171 - 4 and 210 - 5. The board now loses one slot per refresh, at the H counter values Exodus's own tables name as the refresh slots (five in H32, six in H40, "one more than there is during an active line"), giving **166 and 204**. Also changed: a transfer fetches its first word once the control write that started it is over, which is what `_run_transfer`'s docstring already claimed and its code did not. **After that** (`.venv-pypy/bin/python scripts/run_dma_cost.py`, commit `21038dd`, 30 s), fitted over 64 to 512 words with the display off in H40: | Transfer | board, 68000 cycles a word | Kabuto | board intercept | Kabuto | | --- | ---: | ---: | ---: | ---: | | fast (CRAM, VSRAM, VRAM in 128 KB mode) | **2.38** | 2.4 | -3.5 | +5.6 | | slow (VRAM in 64 KB mode) | **4.78** | 4.7 | -14.3 | -6 | and the Manual's table for 68000 memory to VRAM, in bytes a raster line: | | H32, display | H32, blanking | H40, display | H40, blanking | | --- | ---: | ---: | ---: | ---: | | the board | **16.1** | **167.4** | **18.1** | **205.9** | | the Manual (PDF page 44) | 16 | 167 | 18 | 205 | So Kabuto's formulas are reproduced within their stated form: the right two slopes, within 2 % of both, with the `max()` shape falling out of the FIFO filling up, and the negative intercept he explains ("the DMA ends while there is still data in the FIFO to be processed, this is why there are seemingly negative costs"). **What is not reproduced is his fast-transfer intercept**: +5.6 against the board's -3.5, so a one-word transfer costs 8 cycles on his hardware and about 1 here. That is a fixed start-up the board has no mechanism for; adding 5.6 cycles to match a fitted constant would be fitting to a fit, so it is left as open item 15 instead. ### The per-slot renderer, and the CRAM dots Milestone 3 deferred this here, and the brief asks for the decision to be made with frames per second on PyPy before and after. **The design.** A line is still set up once, at the point its active display begins: its horizontal scroll entry (the hardware's own `H` access is the first of the line), its window columns, and its sprites, which the hardware fetched during the preceding horizontal blank. Its *pixels* are now drawn lazily. Before anything the rest of the line would be drawn from changes -- a FIFO write landing at an access slot, a DMA fill or copy, a register write -- the VDP calls `Renderer.catch_up` with that slot's master clock and the line is drawn up to the pixel it falls on. A line nothing is written into is drawn in one piece, exactly as before. That is what keeps it affordable: the split points are access slots, of which an active line has 16 or 18, not arbitrary pixels. A CRAM write that lands in the active display also leaves its dot -- the colour it wrote, for the pixel of its slot. Dots are kept per row and laid over the picture at the end, as are the palettes each part of a row was drawn with, so a CRAM change along a line no longer recolours the pixels before it. **Where the pixels are.** The active display is external H $00-$9F in H40 and $00-$7F in H32, internal H $000 onwards. That is what makes Kabuto's access-slot groups fall into place: his 15 "mid-tiles" slots are the ones inside $000-$13F, his two "between-tiles-and-sprites" ones are $140 and $142 just past it, and his single "mid-sprite" one is $1CE, in the blanking. His remark that the second mid-tiles slot lands "at the pixel with X=-3 (display area coordinates)" would put the output about 21 pixels behind the H counter; that pipeline delay is **not** modelled, and is recorded as item 20 rather than guessed at. **What it costs.** Two measurements, because this machine's frame rate varies by up to 10 % between identical runs. Deterministic first -- how many pieces a line is drawn in, 100 frames after 400 of warm-up, `--no-sound`: | Game | draws a frame | draws a line | | --- | ---: | ---: | | Sonic The Hedgehog (USA, Europe) | 529 | 2.36 | | Streets of Rage 2 (USA) | 130 | 0.58 | | Gunstar Heroes (USA) | 278 | 1.24 | | Castlevania - Bloodlines (USA) | 224 | 1.00 | | Sonic The Hedgehog 3 (USA) | 224 | 1.00 | | Phantasy Star IV (USA) | 361 | 1.61 | | Overdrive 2 (PAL) | 224 | 0.93 | So most lines are still drawn in one piece and the worst game adds 1.4 extra pieces a line. Then frames per second, 900 frames, `--no-sound`, measured by **user CPU time** rather than wall time and taking the better of two runs each, the two configurations run back to back: | Game | per line | per slot | change | | --- | ---: | ---: | ---: | | Sonic The Hedgehog (USA, Europe) | 51.3 | 52.3 | +2.0 % | | Streets of Rage 2 (USA) | 64.0 | 61.6 | -3.8 % | | Gunstar Heroes (USA) | 51.6 | 50.2 | -2.7 % | | Castlevania - Bloodlines (USA) | 52.0 | 50.3 | -3.3 % | | Sonic The Hedgehog 3 (USA) | 50.8 | 49.0 | -3.5 % | | Phantasy Star IV (USA) | 53.7 | 47.1 | -12.3 % | | Overdrive 2 (PAL) | 38.4 | 38.4 | 0.0 % | **Decision: the per-slot path stays.** A few percent, with the one outlier inside the spread two identical runs of the *same* build show on this machine, is not ruinous, and the deterministic count says why: the machinery only runs where a program actually writes to the VDP part way along a line. What it buys is mid-line writes landing where they land on the hardware and the CRAM dots, which Overdrive 2 produces (below) and the six games do not (they write CRAM in the vertical blank, where the hardware makes no dot either). **What it does not buy, yet: r57shell's redraw-timing tests.** They are still not judged, and not for a rendering reason: the ROM polls the pad seven times a frame -- the 6-button handshake -- so neither the board nor MAME leaves its first screen. Both render that screen identically (100.00 % of pixels). The test waits for milestone 7. ### Milestone 5 acceptance: the runs and their results (2026-09-22) All at commit `21038dd` unless said; m68000-python 51ee1a5, z80-python 0.4.0, PyPy 7.3.23 (Python 3.11.15), MAME 0.285. **VDPFIFOTesting's timing tests** (hardware-corrected; ROM SHA-256 `8b0ed394...`). `.venv-pypy/bin/python scripts/run_vdpfifotesting.py --machine M`, 7-8 s each: **122 of 122** on genesis, genesis-tmss, genesis2, megadrive, megadrive-tmss, megadrive2, megadrive-japan and megadrive2-japan; **114 of 122** on genesis3, the eight DMA Fill to VSRAM tests, as a Genesis 3 fails VSRAM tests on hardware. The timing tests among them all pass: FIFO Buffer Size, FIFO Wait States, DMA Transfer Bus Locking, FIFO Full Before DMA Transfer, DMA Transfer using FIFO and the seven DMA Busy Flag tests. Unchanged from milestone 2 through the slot-table correction and the first-fetch change, both of which move DMA timing. **Kabuto's DMA-cost formulas**: reproduced within their stated form -- the table above. **The arbiter's delays**: the three experiments above. **MoD's `gen_test_z80_bus`** (hardware-corrected): all eight checks PASS, the Z80's writes to 68000 work RAM read back $4243 and its reads give $FFFF, and the two BUSACK delay counters print **0000** with the grant now modelled (the reason is above). **Milestones 1 to 4, unchanged.** - The milestone-1 lockstep: Sonic The Hedgehog (USA, Europe) re-recorded from MAME 0.285 (30 emulated seconds, `scripts/mame_trace.py`) and replayed with the arbiter and the per-slot renderer in the tree: **23,286,815 68000 and 12,728,465 Z80 instructions identical, 0 unexplained**, 122 s. The trace (684 MB) was deleted. - `.venv-pypy/bin/python -m pytest -q`: **42 passed, 1 deselected** in 125 s -- the 288 HV/status capture dumps still at 8,762,415 of 8,847,360 words, VDPFIFOTesting, the sprite masking ROM at 0 of 18 cells differing, `gen_test_z80_bus`, milestone 4's FM and PSG referee comparisons, and milestone 5's ten new tests. - The nine milestone-3 test ROMs against MAME's own frames after 3 emulated seconds (`scripts/compare_mame_frames.py`): 100.00 % for `wtest`, `wtest_i1`, `stetest` and r57shell's `vdp_tests`, 99.84 % `wbug`, 96.93 % `vctest`, 96.25 % `wtest_i2`, 69.64 % `SHLTEST`, 41.97 % `STETEST2` -- every figure identical to milestone 3's. - MAME's exit frames for the six lockstep games at 20 emulated seconds (`--record`): 92.38, 99.91, 82.75, 91.10, 99.90 and 93.03 % of pixels, against milestone 3's 92.10, 99.91, 82.75, 91.10, 99.90 and 93.03. Only Sonic The Hedgehog moved, by a quarter of a percent, in the animation that was already a few frames out of phase. ### Overdrive 2, the stress case `.venv-pypy/bin/python`, `megadrive` (the demo prints "THIS DEMO REQUIRES PAL/50 HZ" on an NTSC machine and stops), 12,000 frames -- 240 emulated seconds, 1,075 s of wall time with sound -- writing a PNG every 600 frames and the whole soundtrack as a WAV. The demo needed one thing before it would run at all: its cartridge board. MAME's software list gives Overdrive 2 the slot `rom_titan`, a device whose own comment says "This is same as SSF2 mapper, merge at cart slot rewrite" and whose registers are the same words of $A130F0; the board now accepts that slot as the mapper it already had. Without it the demo prints "YOUR CARTRIDGE OR EMULATOR DOES NOT SUPPORT SSF2-STYLE BANK SWITCHING" and stops. `python -m megadrive_python` also had to identify the cartridge (`Cartridge.from_image`) rather than load every image as plain ROM. **It runs to its end.** 12,000 frames of PAL is 240.4 s, and the last sampled frame (11,400) is the credits. 139,236,731 68000 and 116,596,672 Z80 instructions; 6,519,808 Z80 bank accesses, costing the Z80 23,962,067 of its cycles and the 68000 70,597,738 of its own. **The music is at the right speed, measured against Kabuto's own note.** He wrote the demo's sound driver: "I developed it from scratch to support 26 kHz sample playback with nearly no jitter". Counting the driver's writes to the YM2612's DAC register ($2A) over 600 frames of the demo: | | DAC writes in 12.07 s | realised sample rate | | --- | ---: | ---: | | the board, arbiter on | 317,648 | **26,313 Hz** | | the board, arbiter off | 326,282 | 27,028 Hz | | Kabuto | | "26 kHz" | So the arbiter's bank-access delays are what bring the driver from 27.0 kHz to 26.3 kHz -- the number he designed for. That is the clearest single piece of evidence this milestone produced: the delays are not a decoration, they set the pitch of this demo's samples, and they set it where its author says it belongs. **CRAM dots: 33,733 of them** over the run, all after frame 9,000, which is the sphere scene -- the one that paints a full-colour background by writing CRAM during the display. The six lockstep games make none (they write CRAM in the vertical blank, where the hardware makes no dot either). **The picture.** Of the twenty sampled frames, most are the scene they should be: the arcade, the spaceship, the robot, the city flyby, the sunset, the Overdrive 2 logo over concentric rings, the Mega Drive console, the sphere, the robot's head, and the credits. Four (frames 7,200, 8,400, 9,000 and 10,800) show a plaid or blocky pattern where a scene belongs. Overdrive 2 never enters 128 KB mode, so that is not the cause; it uses the debug register's plane forcing in four windows (frames 6,528-7,064 forcing sprites, 7,064 on with it clear, 8,128-9,130 and 9,132-9,740 and 10,144-11,082 forcing plane B), and the bad frames are not confined to any one of them. For a detector, MAME 0.285 was run on the same demo from its software list (`mame megadriv -cart d_titov2`) at 144, 192 and 216 emulated seconds. **MAME gets those sections wrong too, and differently**: at 144 s it shows a blocky pattern of its own, at 216 s red horizontal stripes where the board shows a red plaid, and at 192 s it draws the sphere over concentric rings where the board draws it over a diagonal weave. So all three are cases where no emulator here is right and the two are wrong in different ways, which is what the demo's readme predicted ("At the moment, this demo will not run on ANY emulator") and what its dependence on the VDP revision means. As the brief says, this is a stress case compared with Kabuto's notes, not a pass or a fail; the sections are recorded here for a later session. ### Open questions for the user QUESTION: **An idle line's access slots were changed from Exodus's 2-per-refresh to 1**, on the strength of Kabuto's access pattern and the Manual's DMA transfer capacity table, both hardware-tier, against Exodus, which is emulator-derived but written by the author of the hardware captures. It puts the board's DMA rates on Kabuto's measured formulas and reproduces the Manual's whole table. Accept, or is Exodus's table the one to follow where he and Kabuto disagree? QUESTION: **Kabuto's DMA start-up cost is not modelled.** His fast-transfer formula has a +5.6-cycle intercept where the board charges -3.5, so a one-word transfer costs 8 68000 cycles on his hardware and about 1 here; the slopes agree within 2 %. Adding a fixed 5.6 cycles would be fitting to a fitted constant, so it is left open. Pursue it, or accept the slopes? QUESTION: **The bus grant is the specification's alone.** No hardware measurement of the Mega Drive's BUSACK delay is published in the pinned material, and MoD's ROM cannot see the one the board now produces (0 to 9 68000 cycles). Keep UM0080's rule unjudged, or take it back out until something can judge it? QUESTION: **The 68000's share of a Z80 bank access is charged to its next instruction**, because the Z80 runs in the 68000's wake in this scheduler. Accept, or is it worth running the Z80 ahead of the 68000 (or rolling the 68000 back, as MoD describes wanting to do in BlastEm) so the delay lands inside the instruction it really fell in? QUESTION: **Kabuto's "X = -3" is not modelled.** He places the second of a line's mid-tiles access slots at display X = -3, which would put the VDP's output about 21 pixels behind its H counter; the board lands a mid-line write at the pixel its slot's own H counter names. Nothing pinned measures the offset, and r57shell's redraw tests cannot be reached until the 6-button pad exists. Leave it, or fit the 21 pixels from Overdrive 2's sphere scene (where it would move the colour bands)? QUESTION: **Four of Overdrive 2's twenty sampled frames are wrong**, in sections MAME also gets wrong differently. Run them down in a session of their own, or leave them until milestone 8's sweep gives more cases of the same kind? **End of milestone 5.** Stopping here, as the working agreement says. ## Decisions (the user, 2026-09-23), answering milestone 5's questions 1. **The one-slot-per-refresh change is accepted**: Kabuto's measured access pattern and Sega's own DMA table agree on one, against Exodus's two, and the change is what puts the DMA on Kabuto's slopes and reproduces the Manual's bytes-a-line table. Two sources over an emulator, as the tier rule says. 2. **Kabuto's DMA start-up cost (+5.6) is left open** and revisited in milestone 8, where a real game difference in the sweep would point at it. 3. **The bus grant stays.** It is Zilog UM0080's rule (specification tier), labelled as having no hardware judge, and it costs the lockstep nothing. 4. **Charging the 68000's share of a bank access to its next instruction is accepted**, documented as a consequence of stepping instruction by instruction rather than bus cycle by bus cycle. 5. **Kabuto's "X = -3" output pipeline is left unmodelled.** Fitting 21 pixels from Overdrive 2's sphere would be fitting to a demo whose correct output depends on the VDP revision. 6. **Overdrive 2's four wrong frames get their own session after milestone 8's sweep**, so that it is known first whether the same cause shows in ordinary games. Nuked-MD (milestone 6) is the referee for it. ## Session 5 (2026-09-23): milestone 6, Nuked-MD as a referee ### How the brief was read Scope is milestone 6 only: build Nuked-MD headless from `reference/src/Nuked-MD` (GPL-2.0 -- run it, read it, cite it, never copy it), teach it to write a bus-level trace, and for the test ROMs of milestones 2-5 show that the board's bus and device timing agrees with it or sort every difference into a named cause. Keep the build script in the repository, as milestone 4's `validation/build_referees.sh` does. Nuked-MD's tier is the one `docs/validation.md` gives a die-derived model -- it judges only where no hardware source covers the question -- with one caveat of its own: its README says it models "NMOS 68k, NMOS Z80 and FC1004. No real mega drive used such combination, but Model 1 VA7 would be closest", so anything that follows from its chip combination, from its unimplemented parts or from this build's `-DTMSS_ENABLE=0` is a named cause and not a board bug. Overdrive 2's four wrong frames are explicitly *not* in scope (the user deferred them to their own session after milestone 8); nothing here touched them. ### Environment Same as the previous sessions: `.venv` CPython 3.14.4, `.venv-pypy` PyPy 7.3.23 (Python 3.11.15), m68000-python pinned at 51ee1a5 (unchanged: docs/polish.md), z80-python 0.4.0, MAME 0.285, the 13th-generation Core i9-13900K. gcc 15.2.0 (Ubuntu 15.2.0-16ubuntu1) for the referee. Nuked-MD at `594ca2a` ("FJ3002 FM wip"), the revision `scripts/pinned_repos.json` pins. ### What was built | File | Lines | What it is | | --- | ---: | --- | | `validation/nuked_md_headless.c` | 342 | the three back ends Nuked-MD's [GPL source cited, redacted] calls (`Audio_*`, `Video_*`), plus the bus tracer: one sample per half-MCLK of /AS, /UDS, /LDS, R/W, the address and data buses, the Z80's /MREQ, /IORQ, /RD, /WR and ZCLK, and eight board signals (/ZBR, /BUSAK, /ZRES, /BGACK, the arbiter's refresh strobe, /WAIT, /SOUND, the VDP's reset) | | `validation/nuked_md_sdl.h` | 56 | a stand-in for the SDL2 declarations [GPL source cited, redacted] and [GPL source cited, redacted] use, so no SDL is needed and the run is single-threaded and deterministic | | `validation/build_nuked_md.sh` | 64 | the build, with both switches explained | | `scripts/nuked_md.py` | 495 | drive the referee, parse its trace, take the *board's* own bus log in the same shape, align the two and compare them | | `scripts/run_nuked_md.py` | 886 | the six comparisons below | Both C files are this repository's own (MIT) and are compiled *against* Nuked-MD's headers, exactly as `validation/opn2_ref.c` and the other two are compiled against theirs. Nothing of Nuked-MD is copied here. The binary lands in `reference/build-nuked-md/` (git-ignored) and is not distributed. The build: `sh validation/build_nuked_md.sh`, 12 s. Two switches, both deliberate and both recorded in the script: - `-DTMSS_ENABLE=0`. Nuked-MD's FC1004 carries TMSS, and with it enabled the bank register ([GPL source cited, redacted], [source name redacted]) powers up *clear*, so the cartridge is not decoded until "SEGA" reaches $A14000 -- which no pre-TMSS test ROM writes. With it 0 the same flip-flop powers up set (`SDFFS` instead of `SDFFR`), which is the pre-TMSS board. The referee's I/O chip still reports hardware version 1, so the combination is TMSS hardware with TMSS off: one more of the referee's departures from any retail console. - `-w`, as upstream builds it. **The trace.** 24-byte packed records: half-MCLK, the ZCLK edge count, the byte address, the data, the cycle's length, a type (68000 bus cycle, Z80 bus cycle, signal change) and flags. A 68000 bus cycle is /AS low to /AS high; its **length** is what makes the comparison sharp, because 18 MCLK is a cycle nothing is stretching and anything longer is a stall the referee charged -- which is exactly what the board's `Board.stall` counts. So each access is compared on four things: its byte address, its direction and size, *the stall charged to it*, and the data on the bus. The board's side needs no change to `src/`: `scripts/nuked_md.py` wraps the four bus callables the 68000 core holds through m68000-python's public `attach_bus`, and `board.dma_read_word` and the Z80's two callables by assignment. ### What was chosen to compare, and why Nuked-MD runs at about **0.33 emulated frames a second** here (2,000,000 half-MCLK in 3.4 s: 294,000 MCLK a second, against the machine's 53,693,182). One emulated second costs three minutes. That rules out running a test ROM to its verdict and rules in three things: 1. **Small purpose-built cartridges** where the question is one timing rule: eight probe loops, the three arbiter experiments, the bus grant, the DMA against its word count, the FM's BUSY. Each is 20,000-60,000 MCLK of trace after the referee's 68000 comes out of reset, 2-11 s of wall time. 2. **The first 900,000 MCLK (about one NTSC frame) of each test ROM of milestones 2-5**, from its reset vector on, which is its whole initialisation -- the VDP set-up, the RAM clear, the first DMAs -- and 25,000-29,000 bus cycles. 6-8 s each, run five at a time. 3. **Nothing by picture or by verdict**: what the referee is uniquely good for is the bus, and the picture already has hardware judges (milestone 3). **The referee's own clock.** Its 68000 fetches its reset vector at **693,230 MCLK** (/SRES is released at half-MCLK 10,000 and the FC1004 then holds the CPU); the board's does at 0. Every comparison therefore puts the board's clock at 693,230 before the first step, so both machines' VDPs are the same distance into a frame when the program starts, and aligns the two streams on 24 consecutive matching (address, kind) pairs. **The two refresh phases are read out of the referee, not fitted.** Both refreshes are free-running counters whose phase at power-on nothing models. Because the referee reports each cycle's length, its ticks are *observed*: a +14 on a cartridge access is the cartridge refresh, a +21 on a work-RAM access is the work RAM's. A grid is fitted to those observations and the board's counters are set to match. That is the only thing taken from the referee; the periods and the stretches are the board's own. ### The cartridge refresh: the board's rule is exactly right Fitting the board's rule -- a fixed 896-MCLK grid, the next bus cycle absorbs the tick, and it costs 14 MCLK only if that cycle is a cartridge access -- to the referee's own observed stretches: | ROM (300,000 MCLK from the referee's reset) | cartridge stretches | phases that reproduce all of them | | --- | ---: | --- | | Nemesis's `sr logic analyser noint - H40V28` | 269 | 518-523 | | CMD's `wtest.bin` | 250 | 518-523 | The same phase window for two unrelated programs, because both start from the same power-on. The obvious variant -- "only a cartridge access absorbs the tick", so that a work-RAM access leaves it standing -- reproduces neither ROM at any phase. Over the ten test ROMs below the board's rule misplaces **0 of the referee's cartridge ticks** in every one. ### The work-RAM refresh: the period is narrowed, the *rule* does not generalise The board's rule is "once due, the next work-RAM access waits 21 MCLK, and the next falls due 805 MCLK after that access started" (milestone 2, from Nuked-MD; the user accepted it as the basis until a hardware measurement exists). - **The stretch is confirmed**: 21 MCLK, on every work-RAM stretch seen in four probe loops (59, 59, 56 and 20 of them) and on all 100 and 344 in the two test ROMs above. - **In a dense work-RAM loop the rule is exact**, and the period is narrowed from milestone 2's 743-826 to **806-819** (`move.w (a0),d0` x16 with a0 = $FF0000, and the same with writes: 799 work-RAM accesses, 59 stretched, every period in 806..819 reproduces all 59 at some phase and 805 reproduces none). So the board's 805 is one MCLK below the window that fits. - **It does not generalise.** With work-RAM accesses every 112 MCLK instead of every 62, no period in 600..1400 reproduces the referee at any phase. On CMD's `wtest.bin` the exact periods are **694-699**, not 806-819. On Nemesis's capture ROM no period in 600..1400 fits at all (the best leaves 269 misplaced). The referee's stretches are not raster-locked either (their times are spread evenly modulo a 3,420-MCLK line). So the re-arm timer is a fit to one access pattern, not the machine's rule, and **805 was left unchanged**: no single value fits, moving it would re-open milestones 2-5's acceptance runs for no gain, and the question is now sharper than a constant. This is the single largest source of difference in the ROM comparison below, and every cartridge-stretch difference that goes with it is a knock-on: each misplaced work-RAM tick shifts the board's whole timeline by 21 MCLK, after which the (correct) cartridge grid lands on different accesses. ### The probe loops `.venv-pypy/bin/python scripts/run_nuked_md.py probes --cycles 400`, 20,000 MCLK of trace from the referee's reset, 2-3 s each: | Probe | bus cycles equal | what the rest is | | --- | ---: | --- | | NOP loop (ROM fetches only) | **394 / 394** | | | ROM reads (`move.w (a0),d0`, a0 in ROM) | **394 / 394** | | | VDP data writes (a control write then eight data writes) | **394 / 394** | | | work RAM reads | 312 / 394 | the work-RAM refresh (27 ticks misplaced) and its knock-on | | work RAM writes | 311 / 394 | likewise | | work RAM read-modify-write (`addq.w #1,(a0)`) | 325 / 394 | likewise | | VDP status reads | 336 / 394 | 58 reads differ in bit 2 (HBlank) only: the referee's VDP comes out of reset at its own point in the frame (below) | | VDP HV counter reads, Mode 5 | 232 / 394 | the same, and the counter itself (below) | | VDP HV counter reads, still in Mode 4 | 223 / 394 | the referee's Mode 4 HV port reads a constant $9F00; the board reads the Mode 5 counter whatever the mode | | **total** | **2,921 / 3,546** | | Three named causes come out of this and hold for everything below: 1. **The referee's VDP has its own power-on phase.** At the same master clock the board's V counter reads $CA (line 202, which is 693,230 mod 3,420 x 262) and the referee's $9F (line 159): its VDP starts about 43 lines and 1,040 MCLK after the board's. Shifting the board's clock to make the *first* HV read agree leaves only 1 of 162 later reads agreeing, so the two also step differently. **The HV counter and the status register are not the referee's to judge**: Nemesis's logic-analyser captures are hardware and cover exactly this question (milestone 2, 8,762,415 of 8,847,360 words), and the tier rule puts hardware above a die-derived model. Recorded and not pursued. 2. **Mode 4's HV port is not modelled.** At power-on the VDP is in Mode 4 and the referee's $C00008 reads a constant; the board reads its Mode 5 counter. No test ROM of milestones 2-5 reads HV before setting Mode 5, so nothing here depends on it. 3. **Work RAM powers up with the referee's DRAM contents** ($5E in the even bytes of the first words, in these runs) and the board's with zero, so a probe that reads work RAM before writing it differs in data. The probes now clear what they read. ### The test ROMs of milestones 2-5 `.venv-pypy/bin/python scripts/run_nuked_md.py roms --window 900000 --cycles 40000 --parallel 5`, 6-8 s each. Every 68000 bus cycle from the reset vector on: byte address, direction, size, the stall charged to it, and the data on a read. The comparison stops at the first *stream* difference, because after that the two machines are running different code. | ROM (SHA-256, first 16) | bus cycles equal | in the window | what the rest is | | --- | ---: | ---: | --- | | `wtest.bin` `160927b5a9f23efc` | **28,921 / 28,921** | 28,927 | | | `vctest.bin` `085115ec3e82ed4c` | **28,921 / 28,921** | 28,927 | | | `ym2612csmmode.bin` `3faaae394f6eba5e` | **25,307 / 25,307** | 25,313 | | | `ym2612detune.bin` `74306d736f99541c` | **25,307 / 25,307** | 25,313 | | | `ym2612multiplexing.bin` `519d19a023edf623` | **25,307 / 25,307** | 25,313 | | | `gen_test_z80_bus.md` `ed344fed9de5c985` | 21,828 / 21,832 | 28,096 | one work-RAM refresh tick, then the bus grant (below) | | `stetest.bin` `0c7729d63bc193ce` | 230 / 233 | 28,135 | one VDP status bit, then the bus grant | | `vdp_tests.bin` `207cd17db44a2142` | 22,125 / 28,122 | 28,128 | the work-RAM refresh (1,841 ticks) and its knock-on | | `sr logic analyser noint - H40V28` `fd25dd3094734b6b` | 23,258 / 28,621 | 28,627 | likewise (1,305 ticks) | | `VDPFIFOTesting.bin` `8b0ed3944893d679` | 23,259 / 28,622 | 28,628 | likewise (1,303 ticks) | | `SpriteMaskingTestRom.bin` `1331819ef3ed07c6` | -- | 11 | the referee's 68000 makes eleven bus cycles and stops: not compared | In every one of the ten the board's cartridge-refresh rule misplaces **0** of the referee's ticks. Every difference is one of four named causes: - **the work-RAM refresh rule** (above), and the cartridge stretches that move with it; - **the Z80's bus grant** (below), which ends `gen_test_z80_bus` and `stetest`; - **the VDP's power-on phase** (a single status read each in `stetest` and `vdp_tests`); - **the I/O chip's hardware version**: the referee reads $A1 at $A10001 (overseas, NTSC, no Mega CD, version 1) where the board's `genesis` machine reads $A0 (version 0). The comparisons give the board the referee's value; without it `stetest` and `vdp_tests` branch away after 34 and 36 cycles, which is what version detection is for. Nuked-MD is an FC1004, so version 1 is right for it. `SpriteMaskingTestRom.bin` is recorded rather than explained: the referee's 68000 makes eleven bus cycles from its reset vector and then nothing at all for the rest of the window. No other ROM behaves that way, and chasing it was out of proportion to the comparison it would buy. ### Milestone 5's open items, answered #### Kabuto's DMA start-up cost: the referee says it is real (open item 15) `.venv-pypy/bin/python scripts/run_nuked_md.py dma --words 1,2,3,4,8,16,32,64,128,256,512 --targets CRAM,VSRAM,VRAM`. Each ROM sets the VDP up (Mode 5, DMA enabled, display off, H40), starts one 68000-memory DMA from $FF0000, and the cost measured is the gap the transfer leaves in the 68000's own bus stream beyond the write that starts it -- which is Kabuto's "on top of what the actual 68k instructions cost", verbatim. | words | referee, CRAM/VSRAM | board | referee, VRAM | board | | ---: | ---: | ---: | ---: | ---: | | 1 | **11.0** | **1.1** | **11.0** | **1.1** | | 2 | 13.0 | 4.0 | 13.0 | 4.0 | | 4 | 18.0 | 6.9 | 18.0 | 6.9 | | 16 | 45.0 | 35.4 | 73.0 | 69.7 | | 64 | 168.0 | 175.4 | 305.0 | 326.6 | | 256 | 641.0 | 642.6 | 1227.0 | 1245.4 | | 512 | 1273.0 | 1254.6 | 2449.0 | 2475.7 | Fitted over all eleven word counts, in 68000 cycles: | | slope | intercept | | --- | ---: | ---: | | referee, fast (CRAM, VSRAM) | 2.47 | **+8.0** | | board, fast | 2.46 | +3.2 | | Kabuto, fast | 2.4 | **+5.6** | | referee, slow (VRAM) | 4.78 | -0.3 | | board, slow | 4.86 | -2.6 | | Kabuto, slow | 4.7 | -6 | **The start-up cost is real.** A one-word fast transfer costs the referee 11.0 68000 cycles and the board 1.1; Kabuto's formula gives 8.0. The board reproduces both slopes (within 1 % of the referee, within 3 % of Kabuto) and neither intercept, and the referee sits on Kabuto's side of the question rather than the board's. That is what milestone 5's open item 15 asked for: the +5.6 is not an artefact of his fit. #### The `pop` wait states: the board has the two reads the wrong way round (open item 14) `scripts/run_nuked_md.py arbiter`, MoD's three experiments run on the referee and on the board from the *same* image. One change from `scripts/run_bus_arbiter.py`: each Z80 loop jumps back to $0000 rather than into the middle of itself. With MoD's `jp $0003` the referee's Z80 never executes the `ld sp,$8002` -- found by tracing: its `pop` read Z80 RAM at three T-states and /WAIT never moved -- so the experiment measured nothing. Jumping to $0000 makes the loop self-correcting on both machines. The referee's wait states are counted exactly, from ZCLK edges: a Z80 memory cycle is three T-states and the next machine cycle begins the moment it ends, so `(next cycle's first ZCLK) - (this one's) - 3` is the count. | Experiment (2,000 board accesses, 134-218 referee accesses) | referee | board | hardware | | --- | --- | --- | --- | | 68000 in `stop #$2700`, Z80 reading the bank window | **2-3, mean 2.25** | 2-3, mean 2.19 | MoD: "2-3" | | 68000 in his `jmp (a0)` loop, Z80 reading | **2-4, mean 2.74** | 2-5, mean 3.55 | MoD: 2-4, "seemed about 2.93"; Kabuto: 2-5, mean 3.3 | | the same, Z80 `pop`ping | 2-5, mean 3.28 | 2-5, mean 3.19 | MoD: the second read "at least 4 wait states", mean 3.5 over 10 | | -- the `pop`'s **first** read | mean **2.95** (2-4) | mean **4.08** (2-5) | | | -- the `pop`'s **second** read | mean **3.61** (2-5) | mean **2.30** (2-3) | MoD: 3.5 | The first experiment agrees with the referee and with MoD. The second is the board's worst: it charges 3.55 where the referee charges 2.74 and MoD measured 2.93, and it produces 5s the referee never does -- Kabuto's `a` (how long the 68000 still needs the bus) comes out systematically larger on the board than on the die. **The `pop` is the interesting one, and the referee names the cause.** The two reads of one `pop` cost the referee 2.95 then 3.61 -- the second is the expensive one, which is exactly what MoD measured on hardware ("the second read from the POP seems to always have at least 4 wait states", mean 3.5). The board has it **the wrong way round**: 4.08 then 2.30. The totals happen to be close (3.19 against 3.28), which is why milestone 5's averages looked reasonable; the split shows what is really happening. The cause is the one docs/polish.md already records: z80-python reports only a step's total, so the board places both of a `pop`'s reads at the step's start, the first one absorbs the whole bus hold and the second finds it already paid. This is a measured confirmation of that entry, not a new problem, and it is the strongest argument yet for proposing the Z80 equivalent of m68000-python's `step_clocks`. #### The bus grant: the board grants about 7 68000 cycles too early `scripts/run_nuked_md.py busack`: the 68000 asks for the Z80's bus, holds it for 20 NOPs, gives it back, waits 20 NOPs and asks again, for ever, while the Z80 runs its bank-reading loop. 37 grants in 60,000 MCLK. | | delay from the $A11100 write to /BUSAK | in 68000 cycles | | --- | ---: | ---: | | referee, /ZBR to /BUSAK | 50-100 MCLK | 7.14-14.29, mean 9.64 | | referee, the $A11100 write to /BUSAK | 68-118 MCLK | **9.71-16.86, mean 12.22** | | board (`System.z80_busack`) | 10-44 MCLK | **1.43-6.29, mean 4.86** | | hardware | nothing in the pinned material measures this direction | | The board models only Zilog UM0080's rule -- BUSREQ "is sampled by the CPU with the rising edge of the last clock period of any machine cycle" -- and nothing of the arbiter's own propagation, so it grants about 7.4 68000 cycles early. Milestone 5 accepted the rule as unjudged because nothing could judge it; **this is the judge the tier rule allows**, and it says the rule is right in shape and short by a constant. It is not academic. In the ROM comparison above, both `gen_test_z80_bus` and `stetest` end at a read of $A11100 where the referee returns $0067 and the board $0066: bit 0 is the grant, the programs are polling for it, and the board answers one poll sooner. Those are the only two ROMs that poll it, and it ends both comparisons. ### The sound chips' wiring, which milestone 4's referees could not see `scripts/run_nuked_md.py sound`. A cartridge releases the Z80's reset (the FM shares that line), takes the Z80's bus, writes an FM register eight times and after each write polls $A04000 until BUSY clears, counting the polls; then it reads all four ports. The whole thing is on the 68000's bus, so the trace answers it. - **BUSY: the same 6 polls on both machines, all eight times.** The board's program takes the same path as the referee's through every poll loop (there is no *stream* difference anywhere in the run), so the board's BUSY window and the referee's are the same to the poll. That is the board's wiring of the chip, not the chip's arithmetic, and it is the part Nuked-OPN2 and YM2608-LLE could not check. - **Ports 1-3 read $00 on the referee**, as they do on the board (milestone 4's decision 6 took Genesis Plus GX's 0 for want of anything better). One more source, and a die-derived one. - **One real difference, and it is the board's: every 68000 access to $A0xxxx costs one 68000 clock more on the referee.** 68 of the run's accesses to the Z80's space are held 7 MCLK by the referee and 0 by the board (and 93 later cartridge fetches move with them): 434 of 636 bus cycles agree, and every difference is that one clock or a knock-on of it. This is **MAME's `before_delay(1)`** -- `megadriv.cpp`, "required by pacman2 intro", "TODO: unverified" -- which milestone 1 recorded as a named class of difference between the board and MAME, 41,274 steps of Sonic alone. Nuked-MD verifies it. Nothing hardware covers the question, so the tier rule lets the die-derived model judge, and it agrees with MAME against the board. It was **not** changed this session: adding a clock to every $A0xxxx access moves milestone 1's lockstep (it would remove a whole named-difference class, which is an improvement, but the lockstep has to be re-recorded from MAME to show it), and it moves the arbiter's `subcycle` and the Overdrive 2 sample rate. It is the one actionable board fix this milestone found, and it is left as a question for the user with the numbers above. Run as `genesis2` (the ASIC FM the referee actually carries) the figures are identical to `genesis`: nothing in this probe distinguishes the two FM variants. ### What is *not* claimed - Nothing about the **picture**: the referee's video output was not compared. - Nothing about the **HV counter or the status register's** values: Nemesis's hardware captures cover them and outrank the referee (above). - Nothing about **Overdrive 2's four wrong frames**: out of scope this session, and nothing here happened to localise them. - The referee's own FM is the **CMOS YM3438**; milestone 4's sample-for-sample work against Nuked-OPN2 and YM2608-LLE is unaffected and was not re-run. - **Mode 4** (the Power Base Converter) is not modelled by the board at all and the referee's Mode 4 HV port differs; milestone 10 is where that belongs. ### Milestones 1 to 5, unchanged **Nothing in `src/` was modified this session.** Every difference the referee found is a decision that re-opens an earlier milestone's acceptance run -- the lockstep needs re-recording from MAME, the arbiter's numbers move, Overdrive 2's realised sample rate moves -- so each is a `QUESTION:` below and a row in docs/polish.md's new "waiting on a decision the user has to make" table, not a change made at the end of a session that could not re-run what it moved. `.venv-pypy/bin/python -m pytest -q` at commit `10255f9`: **46 passed, 1 deselected** in 139 s, against milestone 5's 42 passed, 1 deselected -- the four new ones are milestone 6's (three probe loops reproduced cycle for cycle, and the cartridge refresh grid). `ruff check` and `ruff format --check` clean over the whole tree. ### Open questions for the user QUESTION: **Should the board charge one 68000 clock for every access to $A00000-$A0FFFF?** The referee does (68 of 68 such accesses in the sound probe, 7 MCLK each) and so does MAME, whose own comment calls it unverified; nothing hardware covers it. Doing it would delete a named-difference class from milestone 1's lockstep but needs that lockstep re-recorded from MAME, and it moves the arbiter's `subcycle` and Overdrive 2's realised sample rate. Change it, or leave it named? QUESTION: **The bus grant is 7.4 68000 cycles too early.** The referee measures the $A11100 write to /BUSAK at 9.71-16.86 68000 cycles (mean 12.22) against the board's 1.43-6.29 (mean 4.86), and two test ROMs poll $A11100 and see the difference. Milestone 5 kept UM0080's rule because nothing could judge it; now something can. Add the arbiter's propagation (a constant, fitted to the referee), or leave the specification's rule alone and name the difference? QUESTION: **The work-RAM refresh rule does not generalise.** The stretch is confirmed at 21 MCLK, and the re-arm period is exact at 806-819 in a dense work-RAM loop -- but 694-699 in `wtest.bin` and nothing at all in Nemesis's capture ROM. It is the largest remaining source of difference (1,300-1,900 misplaced ticks per test ROM). Leave 805 and the named difference, spend a session finding the referee's real mechanism, or drop the work-RAM refresh until there is a rule that holds? QUESTION: **Kabuto's DMA start-up cost is confirmed by the referee** (+8.0 cycles fitted, 11.0 for a one-word transfer, against the board's +3.2 and 1.1). Milestone 5's decision 2 left it open until milestone 8. Model it now from the referee -- which would be fitting the board to a die-derived model where Kabuto's hardware figure agrees in sign and size -- or keep it for milestone 8 as decided? QUESTION: **The board charges 3.55 Z80 wait states where the referee charges 2.74 and MoD measured 2.93** for a bank read with the 68000 constantly on the bus, and it produces 5s neither sees. Kabuto's `a` is too large on the board. Worth running down against the referee's own bus log (which shows exactly where each 68000 cycle was when the request arrived), or accept a 0.6-wait-state bias? QUESTION: **`SpriteMaskingTestRom.bin` makes eleven bus cycles on the referee and then stops.** Worth a look (it may be a referee limitation, in which case it is a named cause, or a real difference in what the ROM does on an FC1004), or leave it? ### Commits | | | | --- | --- | | `b95f0d5` | Nuked-MD headless, with a bus-level trace (`validation/nuked_md_headless.c`, `validation/nuked_md_sdl.h`, `validation/build_nuked_md.sh`) | | `10255f9` | Six comparisons against the referee (`scripts/nuked_md.py`, `scripts/run_nuked_md.py`, `tests/test_milestone6.py`) | | `0ae7a6a` | Milestone 6's record: the worklog, the certification record, and the open items in `undocumented-behavior.md`, `timing.md`, `polish.md` and `README.md` | **End of milestone 6.** Stopping here, as the working agreement says. ## Decisions (the user, 2026-09-23), answering milestone 6's questions A focused **timing session** takes these together, before milestone 7 and before milestone 8's sweep: the sweep compares thousands of frames against MAME, and every timing change moves its results, so the sweep runs once, on corrected timing. 1. **Adopt the one extra 68000 clock on $A00000-$A0FFFF accesses.** Nuked-MD (die-derived) and MAME agree, which is as close to a judge as this has; it also deletes a named lockstep difference class. Re-record the MAME traces and re-run the milestone-1 replay. 2. **Adopt the arbiter's propagation on the bus grant** (the referee's ~7.4 68000 cycles), keeping UM0080's machine-cycle rule underneath it: the specification says *when* the Z80 lets go, the referee says how long the arbiter takes to say so. Label it die-derived. 3. **The work-RAM refresh rule is investigated, with a limit.** It is fitted machinery that does not generalise (806-819 in a dense loop, 694-699 in `wtest`, nothing in 600-1400 for the capture ROM). Try to find the real mechanism from the referee; if a rule cannot be found that fits the referee *and* keeps milestone 2's capture agreement, keep 805 with the difference named, and say what was tried. Do not spend the session on it. 4. **Adopt the DMA start-up cost** from the referee, checked against Kabuto's +5.6 and re-run against VDPFIFOTesting and `run_dma_cost.py`. 5. **Chase the Z80 wait-state bias** (board 3.55, referee 2.74, MoD's hardware 2.93) in the same pass: it is the same arbiter arithmetic as 2. 6. **Leave `SpriteMaskingTestRom.bin` stalling the referee**: it looks like the referee's own limitation, and the ROM is judged by Nemesis's photographs. ## Session 6 (2026-09-23): the timing session ### How the brief was read Not a milestone: the user's six decisions on milestone 6's questions, taken in one pass before milestone 7 and before milestone 8's sweep, because the sweep compares thousands of frames against MAME and every timing change moves its results. Four things to adopt (the extra clock on $A00000-$A0FFFF, the arbiter's propagation on the bus grant, the DMA's start-up cost, the Z80 wait-state bias), one to investigate with a limit (the work-RAM refresh) and one to leave alone (`SpriteMaskingTestRom.bin`). Then re-run every acceptance run they touch and record the before and after, explaining anything that moves. The judging rule the user set for this session, which decided two of the four: **where the referee and a hardware-measured source disagree in size, the hardware source is the judge and the referee is the corroboration**; and do not fit a constant to make one test pass at the cost of another. ### Environment Same as the previous sessions: `.venv` CPython 3.14.4, `.venv-pypy` PyPy 7.3.23 (Python 3.11.15), m68000-python pinned at 51ee1a5 (unchanged: docs/polish.md), z80-python 0.4.0, MAME 0.285, Nuked-MD at `594ca2a`, gcc 15.2.0, the 13th-generation Core i9-13900K. The machine was shared throughout, which is why the frame-rate measurement below is a paired run of the two trees rather than a table of absolutes. ### 1. One extra 68000 clock on every $A00000-$A0FFFF access Milestone 6 found the referee holding all 68 of the FM probe's accesses to the Z80's space 7 MCLK where the board held none, which is MAME's `before_delay(1)` (`megadriv.cpp`, "required by pacman2 intro", "TODO: unverified"). Two independent models against the board and nothing hardware on the question, so the tier rule lets them judge. `Board._z80_space_cost` charges it in the four bus entry points, **after** the access, so the access itself still lands at the clock its bus cycle began at (the referee stretches the cycle; it does not delay its start). It is also counted apart in `Board.z80_space_stall`, because the milestone-1 lockstep compares the board's step with MAME's own clock count and MAME charges the same clock: `scripts/lockstep_mame.py` adds that counter to the core's clocks, and the line that used to add MAME's own `before_delay` to the E-clock phase of an interrupt entry is gone with it. **The milestone-1 replay, re-recorded and re-run.** `python scripts/mame_trace.py genesis GAME.zip --seconds 30` for the six games (MAME 0.285, two runs each, six in parallel), then `.venv-pypy/bin/python scripts/lockstep_mame.py tests/mame_traces/genesis-NAME`. The traces (3.5 GB) were deleted afterwards. | Game | 68000 instr. | Z80 instr. | unexplained | `before_delay(1)` steps | wall | | --- | ---: | ---: | ---: | ---: | ---: | | Sonic The Hedgehog (USA, Europe) | 23,286,815 | 12,728,465 | 0 | **0** (was 41,274) | 397 s | | Streets of Rage 2 (USA) | 21,274,844 | 11,269,553 | 0 | **0** | 372 s | | Gunstar Heroes (USA) | 20,854,523 | 15,425,681 | 0 | **0** | 397 s | | Castlevania - Bloodlines (USA) | 11,343,385 | 8,460,818 | 0 | **0** | 355 s | | Sonic The Hedgehog 3 (USA) | 21,741,798 | 11,837,738 | 0 | **0** | 403 s | | Phantasy Star IV (USA) | 21,254,417 | 13,280,703 | 0 | **0** | 400 s | | **Total** | **119,755,782** | **73,002,958** | **0** | | | Every instruction count is milestone 1's to the instruction. To be sure that nothing *else* moved, the same Sonic trace was also replayed against a worktree at the session's starting commit `86fa7e1`: its 41,274 `before_delay(1)` steps move into "agree" exactly (23,240,769 → 23,282,043) and every other class is identical to the count -- 3,165 $A11100 non-grant bits, 1,477 VDP reads replayed, 463 YM2612 status replayed, 48 Z80 RAM reads sorted to MAME's side, 26 Z80 instructions replayed in the other order, 3,276 MAME DMA stalls, 1,495 interrupt entries. Summed over the six: 107,762 YM2612 status replayed, 47,067 $A11100 non-grant bits, 10,879 VDP reads, 516 Z80 RAM reads, 47 Z80 instructions, 1 I/O latch bit -- the last five identical to milestone 1's totals. (The YM2612 status count is the one number that differs from milestone 1's 90,707, and it did not move this session: the comparison at `86fa7e1` gives Sonic's 463 too. It moved when milestone 4 put a real FM on the board and was never re-measured across all six games.) ### 2. The arbiter's propagation on the bus grant The board modelled Zilog UM0080's rule -- the Z80 lets go at the end of the machine cycle in progress -- and nothing of the board around it. `run_nuked_md.py busack --window 200000` over **122 grants**: the referee takes 68-118 MCLK (9.71-16.86 68000 cycles, mean **12.34**) from the 68000's write to $A11100 to /BUSAK where the specification's rule alone takes 10-37 MCLK (mean 4.15). `BUSACK_PROPAGATION_MCLK` is the difference of the two means, 8.19 cycles, rounded to **57 MCLK** and labelled die-derived and fitted; `busack_grant` now returns the machine-cycle end plus it. (The constant was fitted twice: once at 50 MCLK against the release rule of the time, and again at 57 after section 5 corrected that rule and moved the board's unaided figure from 5.19 cycles to 4.15. 57 is the one in the tree.) After: the board's grants are 67-94 MCLK, **mean 12.29 68000 cycles against the referee's 12.34**. The board's spread is narrower (9.57-13.43 against 9.71-16.86) because `System.z80_probe`'s machine-cycle estimate is coarse; the constant fixes the mean, not the shape, and that is said rather than hidden. MoD's `gen_test_z80_bus`: all eight checks still PASS, the Z80's writes to 68000 work RAM still read back $4243 and its reads $FFFF, and its two delay counters now print **0001** instead of 0000. MoD's own hardware values for those two counters are still not in the pinned material, so this is a change, not a pass. **What it did not fix, and the measurement that says why.** `run_nuked_md.py roms` is unchanged in every figure, including the two ROMs that poll $A11100 -- `gen_test_z80_bus` (21,828 / 21,832) and `stetest` (230 / 233) -- which still end where the referee reads $67 and the board $66. Tracing that poll on both machines: ```text referee: $A11100 write at 1,382,688; /BUSAK at 1,382,923 (235 MCLK, 33.6 cycles) referee: polls at 1,382,884 -> $6700 (busy), 1,383,038 -> $6600 (granted) board: $A11100 write at ~1,382,807; grant at 1,382,864 (57 MCLK) board: poll at 1,383,003 -> $6600 (granted) ``` The Z80 is **held in reset** there, and the referee's arbiter takes 235 MCLK in that state against the 68-118 it takes with the Z80 running (the board takes 57). The propagation was made to apply with the Z80 held as well (it is the arbiter's, not the Z80's), but a second constant fitted to a single observation is exactly what the user's rule forbids, so the board keeps 57 and the remaining ~178 MCLK is a named, measured difference rather than an unmodelled one. QUESTION below. ### 3. The work-RAM refresh: what was tried, and why 805 stayed Time-boxed, as the decision said. The referee reports every bus cycle's /AS-low length, so its work-RAM stretches are *observed*; eight traces were taken (three dense probe loops of 300,000 MCLK and five test ROMs of 900,000) and candidate rules replayed over the referee's own cycle times. **Three new facts.** 1. **The stretch is not always 21 MCLK.** It is 7, 21 or 35 -- one, three or five 68000 clocks. Nemesis's capture ROM: 301 of its 401 stretches are 21 and 100 are 7. r57shell's `vdp_tests`: 820 of 1,020 are 21, 18 are 7 and 182 are 35. The board models only the 21. 2. **The rate varies by two and a half between programs, and rises as work-RAM traffic thins.** In 900,000 MCLK `wtest.bin` shows 1,032 stretches (one per 872 MCLK) and the capture ROM 401 (one per 2,244). The apparent period is 845 MCLK where 44 % of bus cycles are work RAM, 871 at 29 %, 880 at 40 %, 896 at 20 %. 3. **No free-running grid fits.** For a fixed grid of period *G*, every stretch's time must fall in one narrow band of residues mod *G*. Over *G* = 200..2,000 the tightest band any *G* gives is 70-165 MCLK, 8-18 % of the period, and no *G* is shared by two programs. The 4,546 stretches of all eight runs together -- which share one power-on phase, since the referee always starts from the same reset -- band no better at any period (best arc 196 of 203). **Five candidate rules, each free to choose its own period and phase**, scored by how many of the referee's stretches it misplaces (fewest misses @ the period that gave them): | rule | dense probe (354) | `wtest` (1,032) | capture ROM (401) | `vdp_tests` (1,020) | | --- | ---: | ---: | ---: | ---: | | **A** re-arm *P* after the stretched RAM access (the board's) | 556 @ 946 | **0** @ 760 | 1,055 @ 946 | 1,664 @ 834 | | **B** fixed grid, any bus cycle absorbs the tick, only RAM pays | 233 @ 845 | 863 @ 871 | 300 @ 896 | 638 @ 880 | | **C** fixed grid, the tick waits for a RAM access | 175 @ 845 | **0** @ 871 | 604 @ 896 | 183 @ 880 | | **D** every *N*th work-RAM access (a row counter, not a timer) | 353 @ 44 | **0** @ 8 | 300 @ 57 | **0** @ 11 | | **E** any bus cycle absorbs the tick and re-arms the timer | 361 @ 785 | 1,032 @ 834 | 401 @ 876 | 1,072 @ 778 | Rules C and D are each exact on two programs and hopeless on the other two, and the period or count each needs differs by a factor of five between programs (C: 845 to 896; D: 8 to 57 accesses). At the board's own 805 MCLK, C is no better than A overall (663 against 709 on the dense probe, but 1,656 against **0** on `wtest`), so even the shape change does not pay. **Decision: 805 MCLK and rule A stay, the difference stays named.** No rule was found that fits the referee, and changing the constant or the shape would move milestone 2's capture agreement for no gain. What the session did buy is a sharper question: the interval depends on the access pattern, the stretch has three sizes, and the mechanism is not a grid, not a re-armed timer and not an access counter. Written up as open item 5 of docs/undocumented-behavior.md, with the table above. Not tried, and the obvious next step: reading the referee's refresh counter out of its own state instead of inferring it from stretches. That needs a change to `validation/nuked_md_headless.c` to expose FC1004 internals, which is more than a time-boxed investigation. ### 4. The DMA's start-up cost Kabuto (hardware-measured research) gives a fast transfer as `words * 2.4 + 5.6` 68000 cycles, so a one-word transfer costs eight; milestone 5 reproduced his slope within 2 % and had no mechanism for the +5.6, charging about one cycle; milestone 6 measured the referee at 11.0 cycles for one word and +8.0 fitted over 1 to 512. The two judges agree the start-up is real and differ by 2.4 cycles in its size, so **the hardware source judges**: `VDP.DMA_STARTUP_MCLK` is Kabuto's own 5.6 cycles, 39 MCLK (5.571, the rounding to whole master clocks), charged before the transfer's first word is read. Taking his constant as the mechanism it is named as, rather than a delta fitted to make some measurement land, is the whole reason for the choice -- and it matters, because the board's own two harnesses fit intercepts seven cycles apart on the same board (`run_dma_cost.py` fits over 1..512 by the VDP's own `hold`, `run_nuked_md.py dma` over 1..512 by the gap in a real 68000 bus stream). `.venv-pypy/bin/python scripts/run_dma_cost.py`, H40, display off, fast transfer: | words | 1 | 2 | 4 | 8 | 16 | 64 | 512 | | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | | board, before | 0.6 | 4.0 | 7.4 | 16.0 | 36.0 | 145.7 | 1216.0 | | board, after | **7.4** | **8.6** | **12.7** | **22.1** | **40.6** | 150.3 | 1217.4 | | Kabuto | 8.0 | 10.4 | 15.2 | 24.8 | 44.0 | 159.2 | 1234.4 | Fitted: 2.37 x words + **1.7** (was −3.5) fast, 4.78 x words − 9.7 (was −14.3) slow, against Kabuto's 2.4 + 5.6 and 4.7 − 6. In the referee's own harness the board is now 2.46 x words + **9.0** with one word at **6.9**, against the referee's 2.47 + 8.0 and 11.0. So the board sits between Kabuto and the referee on the one-word figure and just past the referee on the fit: the residual 3.6 cycles to the die are named, not fitted away. The Manual's DMA transfer capacity table still comes out: **16.1, 167.1, 18.1, 205.1** bytes a raster line against its 16, 167, 18, 205. VDPFIFOTesting is **122 of 122** on every machine but genesis3 (114 of 122, its VSRAM tests), its seven DMA Busy Flag tests, DMA Transfer Bus Locking, FIFO Full Before DMA Transfer and DMA Transfer using FIFO included. ### 5. The Z80 wait-state bias: one number, found in the referee's bus log The board charged **3.55** wait states for a bank read with the 68000 in Kabuto's `jmp (a0)` loop where the referee charges 2.74 and MoD's logic analyser measured 2.93, and it produced 5s neither of them sees. The user's hint was to run it down against the referee's own bus log, which shows where each 68000 cycle was when the request arrived. That is exactly what it shows. **A 68000 bus cycle is four clocks, but the 68000 holds the bus for only 18 of its 28 MCLK.** The bus is a requester's once /AS and /DTACK are negated (68000 UM, "Bus Arbitration"). In the referee's trace of that loop, **1,706 of its 1,766 68000 bus cycles hold /AS low for exactly 18 MCLK**, with a 10-MCLK gap to the next; the other 60 hold it 32, which is 18 plus the cartridge refresh's 14 and is Kabuto's "up to 6 cycles if the last access is delayed by the refresh logic". The board charged the whole 28 MCLK, which made the 68000 look continuously on the bus in a tight loop, and then also looked two cycles ahead to the next access, so Kabuto's `a` came out 5 and 6 where the die never goes past 4. Replaying his formula over the referee's own 134 held Z80 reads with three candidate `a`s: | how ``a`` is taken | wait-state distribution | mean | the referee's own | | --- | --- | ---: | --- | | the /AS-low remainder (18 MCLK) | 2: 52, 3: 65, 4: 17 | **2.74** | 2: 51, 3: 67, 4: 16, mean **2.74** | | the whole four-clock cycle | 2: 1, 3: 67, 4: 66 | 3.49 | | | the whole cycle plus the 2-cycle look-ahead (the board's) | 3: 16, 4: 66, 5: 52 | 4.27 | | So `Board.m68k_accesses` now holds `[start, span]` -- where /AS fell and how long it stays down, lengthened by whatever stretches that cycle -- and `_m68k_release` counts only a cycle actually under way. Kabuto's sentence is not contradicted: a cycle is four clocks and the next does begin within two; the bus is simply free for the 10 MCLK in between, which his own footnote could not have distinguished. On the board (`run_nuked_md.py arbiter`, 2,000 accesses; `run_bus_arbiter.py`, 4,000): | experiment | before | after | referee | hardware | | --- | --- | --- | --- | --- | | 68000 in `stop #$2700`, Z80 reading | 2-3, 2.19 | 2-3, 2.19 | 2-3, 2.25 | MoD: "2-3" | | 68000 in `jmp (a0)`, Z80 reading | 2-5, **3.55** | 2-4, **2.86** | 2-4, 2.74 | MoD: 2-4, 2.93 | | the same, `run_bus_arbiter.py` | 3-4, **3.36** | 2-4, **2.91** | | MoD: 2.93 | | the same, Z80 `pop`ping | 2-5, 3.19 | 2-4, 2.50 | 2-5, 3.27 | MoD: 3.5 | | -- the `pop`'s **first** read | 2-5, 4.07 | 2-4, **2.97** | 2-4, 2.95 | | | -- the `pop`'s **second** read | 2-3, 2.30 | 2-4, 2.04 | 2-5, 3.60 | MoD: 3.5 | The board's `jmp (a0)` figure is now 2.91 against MoD's hardware 2.93 and 2.86 against the referee's 2.74, in his range 2-4, with the 5s gone. **One thing got worse, and it is the right kind of worse.** The `pop` pair's mean falls from 3.19 to 2.50 against the referee's 3.27. The inflated `a` had been compensating for the board's inability to place the *second* of a `pop`'s two reads at its own T-state: the first read now lands on the referee's own figure (2.97 against 2.95) and the second is plainly short (2.04 against 3.60). That is the z80-python limitation docs/polish.md records, unmasked instead of cancelled out, and it is the strongest argument yet for the Z80 equivalent of `step_clocks`. Kabuto's whole-model check is unmoved: **481.0** of a raster line's 488.6 clocks left for the 68000's own instructions, against his "roughly 480". ### 6. `SpriteMaskingTestRom.bin`: left alone, as decided The referee's 68000 makes eleven bus cycles from its reset vector and stops. Nothing was done, and Nemesis's MD1600 photographs go on judging that ROM: `0 of 18 result cells differ`. ### Everything else these changes touch, re-run Every figure is in docs/validation.md's certification record, "The timing session". The short version: the HV/status captures are **8,762,415 of 8,847,360 words**, unchanged to the word; VDPFIFOTesting is unchanged on all nine machines; the sprite masking ROM is unchanged; the PSG is identical to Nuked-PSG on **121,279,196 input clocks** over ten streams and the YM2612 identical to Nuked-OPN2 on **110,549,790 internal cycles** in each of two variants over eighteen streams, so **sound is still cycle-exact**; `run_nuked_md.py probes` is 2,921 of 3,546 and `roms` is unchanged in every one of its ten figures. The one referee comparison that improved is the FM probe: **568 of 636 bus cycles** against milestone 6's 434, the 68 $A0xxxx stall differences gone. ### Frames per second: the changes make the board slightly faster Timing changes can cost speed, so this was measured -- and it does the opposite, for a reason worth stating: a frame is a fixed number of master clocks, so charging the 68000 more stall clocks means it executes *fewer* instructions per emulated frame. The machine was shared all session and identical runs of the same build vary by up to 10 %, so this is a **paired** measurement: the session's starting commit `86fa7e1` in a git worktree and the current tree, 900 frames each, `--no-sound`, alternating, two runs each, the better of the two, by **user CPU time**. | Game | before (s) | after (s) | before fps | after fps | change | | --- | ---: | ---: | ---: | ---: | ---: | | Sonic The Hedgehog (USA, Europe) | 19.00 | 18.26 | 47.4 | 49.3 | +4.1 % | | Streets of Rage 2 (USA) | 20.32 | 19.58 | 44.3 | 46.0 | +3.8 % | | Gunstar Heroes (USA) | 24.33 | 21.58 | 37.0 | 41.7 | +12.7 % | | Castlevania - Bloodlines (USA) | 18.54 | 17.58 | 48.5 | 51.2 | +5.5 % | | Sonic The Hedgehog 3 (USA) | 22.16 | 21.39 | 40.6 | 42.1 | +3.6 % | | Phantasy Star IV (USA) | 20.96 | 20.84 | 42.9 | 43.2 | +0.6 % | (The absolute figures are well below milestone 5's 50-64 because of the load; only the paired difference means anything here.) ### Overdrive 2's realised DAC rate, which these changes do move Milestone 5's clearest single piece of evidence was that the arbiter's delays bring Kabuto's own sound driver from 27.0 kHz to 26.3 kHz -- "26 kHz sample playback", the number he designed for. 600 PAL frames, counting the driver's writes to the YM2612's register $2A: | | milestone 5 | now | | --- | ---: | ---: | | arbiter on | 26,313 Hz | **25,858 Hz** | | arbiter off | 27,028 Hz | 26,318 Hz | | Kabuto | "26 kHz" | "26 kHz" | Both figures moved and the two halves say which change did what. With the arbiter off the only changes in play are the $A0 clock and the DMA start-up, and they cost 2.6 % (27,028 → 26,318). The arbiter itself now costs 1.8 % rather than 2.6 %, which is the corrected wait states (2.86 rather than 3.55 per bank access). The result is 0.6 % *below* 26 kHz where it was 1.2 % above; both round to his figure, and the demo is still being driven at the rate its author says it should be. ### The picture, unmoved The nine milestone-3 test ROMs against MAME's own frame after 3 emulated seconds (`scripts/compare_mame_frames.py`, a detector): 100.00 % for `wtest`, `wtest_i1`, `stetest` and r57shell's `vdp_tests`, 99.84 % `wbug`, 96.93 % `vctest`, 96.25 % `wtest_i2`, 69.64 % `SHLTEST`, 41.97 % `STETEST2` -- **every figure identical** to milestones 3 and 5. ### The suite `.venv-pypy/bin/python -m pytest -q`: **49 passed, 1 deselected** in 163 s; `.venv/bin/python -m pytest -q` (CPython 3.14.4): 49 passed in 395 s. (While the MAME trace directories were still present six were deselected instead of one: the extra five are `slow` replays that are only collected when their logs exist.) Three tests are new (the Z80-space clock, the /AS-low release rule, the DMA start-up) and one was rewritten for the grant's propagation. The six deselected are the `slow` marker's MAME-log replays, collected this time because the trace directories were present; they were run directly instead, above, and the logs (3.5 GB) were deleted afterwards. `ruff check` and `ruff format --check` clean. ### Open questions for the user QUESTION: **The bus grant with the Z80 held in reset.** The propagation constant (50 MCLK) is fitted to 122 grants with the Z80 *running*, and the board now matches the referee's mean there to 0.01 of a cycle. With the Z80 held in reset the referee takes **235 MCLK**, and that is one observation, on one ROM, so nothing was fitted to it -- which leaves `gen_test_z80_bus` and `stetest` ending their referee comparison at the same $A11100 poll as before. Is it worth a purpose-built probe (request the bus repeatedly with the Z80 held, over many grants) to see whether 235 is a constant, or does the named difference do? QUESTION: **Which DMA start-up figure.** The board took Kabuto's 5.6 cycles because the session's rule makes the hardware source the judge; that leaves a one-word fast transfer at 7.4 cycles against his 8.0 and the referee's 11.0, and the fit +1.7 in one harness and +9.0 in the other against the referee's +8.0. Keep the hardware number, or is the referee's 8.0 the better choice now that both agree the effect is real? QUESTION: **The work-RAM refresh, next step.** 805 stayed and the question is sharper (three stretch sizes, a rate that varies two and a half times between programs, no grid that fits). The obvious next move is to stop inferring the refresh from stretches and read the FC1004's refresh counter out of the referee's own state, which means adding to `validation/nuked_md_headless.c`. Worth a session of its own, or leave it named until milestone 8's sweep says whether it costs anything visible? QUESTION: **The `pop` split is now the board's largest arbiter difference** (2.50 against the referee's 3.27, entirely because both of a `pop`'s reads land at the Z80 step's start). The fix is the Z80 equivalent of m68000-python's `step_clocks`, which docs/polish.md has been carrying since milestone 6. Is it time to propose that PR to z80-python, given that it is now the only thing between the board and the referee on this experiment? QUESTION: **The referee stretches a work-RAM access by 7 or 35 MCLK as well as 21** (100 of 401 stretches in Nemesis's capture ROM are 7; 182 of 1,020 in `vdp_tests` are 35). The board models only the 21. Since the rule that places them is not known, the sizes cannot be modelled either -- but should the *observation* be part of what milestone 8's triage looks for? ### Commits | | | | --- | --- | | `8085361` | Two clocks the referee found: the Z80's space, and the grant | | `9ca2ec6` | The DMA's start-up cost, taken from the hardware source | | `7558425` | How long the 68000 really holds the bus | | `3ae1498` | The grant's propagation applies with the Z80 held too | | `647c283` | The timing session's record (worklog, certification record, open items, polish, timing, README) | | `23837e5` | The rest of the record: speed, Overdrive 2, the picture, and the questions | | `ccdb63b` | Re-fit the grant's propagation on the corrected release rule | The last of those is worth reading as a lesson rather than a change: the propagation constant had been fitted while the board still charged the whole four-clock bus cycle for Kabuto's `a`, and correcting that moved the quantity it was fitted to. It was caught by re-running every acceptance script **at the final commit** rather than trusting the number each change was measured with, which is worth doing whenever a session changes two things that touch the same clock. Re-run there: the 288 HV/status capture dumps (8,762,415 of 8,847,360 words, to the word), the sprite masking ROM (0 of 18), VDPFIFOTesting on all nine machines (122/122, 114/122 on genesis3), `gen_test_z80_bus`, `run_bus_arbiter.py`, `run_nuked_md.py` `arbiter`, `busack` and `roms`, Overdrive 2's DAC rate and the suite. **End of the timing session.** Milestone 7 next, then milestone 8's sweep on this timing. ## Decisions (the user, 2026-09-23), answering the timing session's questions 1. **The grant with the Z80 held in reset stays a named difference** (referee 235 MCLK against the board's 57, one observation on one ROM). The post-sweep debugging session can probe it; it is measured now, which was the point. 2. **Kabuto's 5.6-cycle DMA start-up stays**, as the session chose: the hardware-measured source judges, the die-derived referee corroborates. 3. **The work-RAM refresh keeps 805 MCLK with the difference named.** Five rules were scored and none fits more than two programs; milestone 8's sweep says whether it costs anything visible before anyone spends a session on the FC1004's refresh counter. Unneeded machinery is latency. 4. **The z80-python accessor is proposed as a PR there** by the reviewing session (the same shape as m68000-python's `step_clocks`), so the `pop` pair's second read can land at its own T-state. The board adopts it in the polish pass, not before: `docs/polish.md` carries the row. 5. **Milestone 8's triage watches for the 7- and 35-MCLK work-RAM stretches**, which the board does not model, as a possible cause of a frame difference. ## Session 7 (2026-09-23): milestone 7, cartridges and peripherals ### How the brief was read Scope is milestone 7 only: battery SRAM, the EEPROM games, the SSF2 mapper, the 3- and 6-button pads with Terakawa's timing, TMSS with the local No-Intro boot ROM, and the region and version register. Each is judged by its research document **and by a game that uses it doing the right thing** -- saving and reloading, a mapper's banks appearing, a region check passing or failing as the hardware would -- with MAME as a detector where nothing better exists. Plus the two things the brief hands over explicitly: run r57shell's VDP tests once the 6-button pad works and judge them against the MD2 report in forum t=1585, and give the SSF2 mapper (which milestone 5 already had as `rom_titan`) its own judge, Super Street Fighter II. MD Soft Checker v0.30 is not available (a dangling symlink in the local romset) and was not used. ### Environment Same as the previous sessions: `.venv` CPython 3.14.4, `.venv-pypy` PyPy 7.3.23 (Python 3.11.15), m68000-python pinned at 51ee1a5 (unchanged: docs/polish.md), z80-python 0.4.0, MAME 0.285, the 13th-generation Core i9-13900K, shared throughout. ### What was built | File | Lines | What it is | | --- | ---: | --- | | `src/megadrive_python/eeprom.py` | 241 | the serial (I2C) EEPROM, modes 1, 2 and 3, from Eke-Eke's `gen_eeprom.pdf` | | `src/megadrive_python/io.py` | +212 | `Pad6`, and TH edges timed: every access that can move TH now tells the port when | | `src/megadrive_python/cartridge.py` | +392 | the EEPROM boards, the J-Cart ports, the battery's save and load, `BootROM`, the SSF2 mapper's documentation | | `src/megadrive_python/board.py` | +72 | the TMSS boot ROM and $A14101, and the I/O chip's clock | | `src/megadrive_python/render.py` | +13 | register $00 bit 0: no display generation | | `src/megadrive_python/{system,__main__}.py` | +37 | `pads=`, `tmss_rom=`, `--pad`, `--pad2`, `--save`, `--tmss-rom` | | `scripts/run_pads.py` | 299 | the pads against CMD's table, r57shell's `joy_speed`, and which games handshake | | `scripts/run_battery.py` | 168 | battery SRAM and EEPROM against the games and against MAME's own nvram | | `scripts/run_mapper.py` | 130 | the SSF2 mapper against `ssf2tnc.txt` and the game | | `scripts/run_tmss.py` | 197 | the boot ROM, the hand-off, the header check and the VDP lock | | `scripts/run_region.py` | 211 | the version register against the Manual, and three games that check it | | `scripts/run_r57shell_tests.py` | 154 | the eight VDP-test screens, now that they can be walked | | `tests/test_milestone7.py` | 379 | 24 tests that need nothing fetched | ### The pads #### Decisions and their sources - **Two sources describe the 6-button pad and they agree on every value it returns.** Terakawa's page (`reference/web/terakawa-6button.html`, hardware-corrected: he timed real pads) gives the sequence as rows of Sel and the six pins; CMD's `gen-hw.txt` 3.2 ("checked on the real thing") gives the same rows as `?1CBRLDU` / `?0SA00DU` / `?1CBRLDU` / `?0SA0000` / `?1CBMXYZ` / `?0SA1111`. Reading the two together settles two things Terakawa's table alone does not: **D4 and D5 still carry B and C in the extra-buttons phase** (his "HI HI" is those two released), and **the counter stops** after the fourth rising edge -- "From this point on, the standard 3-button pad values will be returned if any further TH transitions are done" -- rather than starting round again, which is what MAME does (it wraps modulo 4, `bus/sms_ctrl/md6bt.cpp`). - **The timeout is a field, not a constant, and nothing is claimed for it.** The brief said not to fit one number and call it hardware, and the sources make that easy to obey: they do not measure the same quantity. CMD times out "about 8192 (probably less than that) 68000 CPU cycles" after TH was last *modified*; Terakawa gives 1.1 ms for the second up-edge, 1.6 ms for the data to stay readable and 1.8 ms before the sequence may restart, all from the *first* up-edge; MAME uses 1.5 ms from the last rising edge. `Pad6.timeout_mclk` takes CMD's shape and figure (57,344 MCLK) because his is the only one that says what the clock runs from, and the class docstring carries all four. Nothing observable turns on the choice: a poll takes a few microseconds and a game polls once a frame, so every one of the four resets the pad between frames and none of them resets it inside one. - **TH's edges now have a time.** A 6-button pad counts edges, not levels, so `IOChip.read` and `IOChip.write` take a master clock and `Port.set_th` tells the device whenever a write to the data *or* the control register could have moved TH (a control write can make TH an output or let it float back up, which is an edge too). The board passes `m68k_access_clock()` for a 68000 access and `step_start` for a Z80 one. A 3-button pad ignores all of it and behaves exactly as before. - **The pad's own MODE switch** is `Pad6.mode_switch`: "the MODE button can be held down when powering-up the console, and the 6-button gamepad will respond like a 3-button one" (CMD 3.2). Held False the pad never advances its counter. #### What the pads were judged by (2026-09-23) **CMD's table, every button combination** (`scripts/run_pads.py`, 21 s). A small 68000 program makes TH an output and walks it high, low, high, ... eight times, reading $A10003 after each change into work RAM, so every access goes through the board's own bus. The eight bytes are compared with CMD's rows written out as bytes, for **all 4,096 combinations of the twelve buttons on the 6-button pad and all 256 on the 3-button one**: **34,816 of 34,816 bytes match**. **r57shell's `joy_speed_v1.02.bin`** (hardware-corrected; his own tool, forum t=2308; SHA-256 `3c49a278f737…`). The ROM's own reads of $A10003 were watched on the port and grouped into bursts, 400 frames each: | pad | reads in 400 frames | the commonest burst | | --- | ---: | --- | | 3-button | 972 in 198 bursts | `$7F $33 $7F $33 $7F $33 $7F $33` (56 x) | | 6-button | 1,552 in 197 bursts | `$7F $33 $7F $30 $7F $3F $7F $33` (56 x) | which is CMD's table read off a real test ROM: `?1CBRLDU` = $7F, `?0SA00DU` = $33, then `?0SA0000` = $30 and `?1CBMXYZ` = $3F where the 6-button pad's counter has reached two and three. The ROM's own screen shows the same eight bytes. **What `joy_speed` does *not* do is name the pad**: its heading reads "Port 1: 3 Buttons Pad No Reset" for both pads. MAME 0.285 with `-ctrl1 md6button` prints exactly the same heading, and its own code says why -- its pad reads its MODE switch in `device_reset` with the comment "TODO: doesn't work - reset happens before host inputs are read for the first time", so MAME's 6-button pad is stuck in 3-button mode. So MAME cannot detect the difference here and the board agrees with it; the evidence for the pad is the byte sequence above, not that heading. **The games** (`scripts/run_pads.py --games`). A 6-button game drives TH high three or more times in a burst; a 3-button game never does: | game | frames | the counter reached 2 | 3 | 4 | | --- | ---: | ---: | ---: | ---: | | Super Street Fighter II (USA) | 2,600 | 2,368 | 2,368 | 2,368 | | Comix Zone (USA) | 600 | 399 | 399 | 399 | | Sonic The Hedgehog (USA, Europe) | 600 | **0** | **0** | **0** | | Streets of Rage 2 (USA) | 600 | **0** | **0** | **0** | So the two games sold with the 6-button pad in mind ask for the extra buttons about once a frame and the two 3-button games never do, which is the pad working in a game rather than in a harness. ### The battery: SRAM, FRAM and the serial EEPROMs #### Decisions and their sources - **The EEPROM is written from Eke-Eke's `gen_eeprom.pdf`** (in `reference/docs/md_tech.zip`), the research document the brief names: `src/megadrive_python/eeprom.py` is the two-wire protocol -- START and STOP, eight clocks and an acknowledge, one, two or three address words by mode, a write wrapping inside the page and a read wrapping at the end of the chip. His game table gives which game is on which board and MAME's software list gives which board each image is, so `cartridge.EEPROM_BOARDS` is keyed by MAME's slot name with Eke's numbers in it. CMD's `gen-eeprom.txt` names the actual chips found on several boards (a Xicor X24C01 in Monster World 3 and Mega Man - The Wily Wars, an X24C02 in NBA Jam), which agrees with Eke's modes. - **Eke's NBA Jam entry is wrong and the game says so.** His table gives the Acclaim type 1 board `SDA_IN` bit 0, `SDA_OUT` bit 1 and `SCL` bit 1 of $200001 -- the data out and the clock on one bit, which cannot be a board. MAME's NBA Jam device reads /SDA at bit 1 and writes /SDA at bit 0 and /SCL at bit 1. **Measured, with the game as the judge**: with bit 1 the board writes NBA Jam's "Snake 1993" header once and, restarted with that EEPROM loaded, reads it back and writes *nothing*; with bit 0 the game cannot read its own save and rewrites all 256 bytes on every boot. The board takes bit 1 (docs/undocumented-behavior.md, "Cartridges" item 1). - **MAME's `sram` data area is an address range, not a chip size.** `md_slot.cpp` sets `m_nvram_end = m_nvram_start + length - 1` and allocates that many bytes as 16-bit words, one per address the chip answers at. The chip is eight bits wide on the odd byte (CMD 4.3, of Phantasy Star 4: "16k of battery backed RAM mapped to $200001-$203FFF. (odd addresses used)"), so it holds half as many bytes as the range is wide, and the board now halves the list's figure. Before this the board mapped twice the address range MAME does; no game in the lockstep ever read the extra half, which is why milestone 1 never saw it. - **A battery is saved and loaded as the chip's own bytes**, packed, which is half MAME's file; `Cartridge.save_bytes` and `load_bytes`, and `--save FILE` on the command line, which reads the file at power-on if it exists and writes it at the end. #### The runs (2026-09-23) `.venv-pypy/bin/python scripts/run_battery.py`. Each game runs 40 emulated seconds from a blank battery, the battery is saved, a fresh machine is built with it loaded and the game runs again; MAME 0.285 runs the same image for the same time with `-nvram_directory`. 90-125 s a game. | game | board's battery | after a reload | MAME's file | equal | | --- | --- | --- | --- | --- | | Sonic The Hedgehog 3 (USA), `rom_fram` | 512 bytes, **272 written** | unchanged | 1,024 bytes, both halves of every word equal | **512 of 512** | | NBA Jam (USA, Europe) (Rev 1), `rom_nbajam_alt` | 256 bytes, **48 written** ("Snake 1993") | unchanged, **0 EEPROM bytes written on the warm start** | 256 bytes | **256 of 256** | | Phantasy Star IV (USA), `rom_sram` | 8,192 bytes, none written in 40 s | unchanged | 16,384 bytes, halves equal | **8,192 of 8,192** | | Wonder Boy in Monster World (USA, Europe), `rom_eeprom_mode1` | 128 bytes, none written | unchanged, 0 written | 128 bytes | **128 of 128** | | Evander Holyfield's 'Real Deal' Boxing (World), `rom_eeprom_mode1` | 128 bytes, none written | unchanged, 0 written | 128 bytes | **128 of 128** | The two games that write during their own start-up are the evidence: **Sonic The Hedgehog 3 lays out its FRAM and the board's 512 bytes are MAME's 512 bytes exactly**, and **NBA Jam writes its EEPROM header and the board's 256 bytes are MAME's exactly**, then reads it back on the next boot and leaves it alone. The other three write nothing without being played, so for them the comparison says only that both machines leave a blank chip blank; that is stated rather than counted as a pass. ### The Sega (SSF2) mapper The mapper itself is milestone 5's: `rom_titan` was added then so that Overdrive 2 would run. What milestone 7 adds is its documentation, its own slot name, and the judge the brief names -- **Super Street Fighter II**. Bart Trzynadlowski's `ssf2tnc.txt` (second edition, 2000, in `md_tech.zip`) gives the mechanism ("views the addressable 4 megabytes of ROM as 8 512KB regions. The first area, 0x000000-0x07FFFF is fixed and cannot be remapped because that is where the vector table resides"), the seven registers and their windows, the 6-bit page number ("bits 7 and 6 are always 0"), and -- which is what makes it a judge -- the game's own code, quoted from the US dump: ```text 0x003BEC: move.b #$08, ($A130FD) 0x003BF4: move.b #$09, ($A130FF) 0x003BFC: lea ($300000), a0 ``` "The bankswitching hardware must be properly emulated before the game starts working. If it is not, the checksum will fail and the game will hang with a red screen." `.venv-pypy/bin/python scripts/run_mapper.py --titan`, 2,400 frames each: | | | | --- | --- | | Super Street Fighter II (USA), 5,242,880 bytes, `rom_ssf2` | **267 writes to $A130xx**, the first two of them `$A130FD = $08` and `$A130FF = $09` -- the checksum pair, at the value `ssf2tnc.txt` quotes -- then `$A130F1 = $02` and the seven windows set back to 1..7 | | the picture | the intro artwork at frame 1,200 and the **"SUPER STREET FIGHTER II - The New Challengers" title screen** at frame 2,400; no red screen | | Overdrive 2 (World) (Revision 2017), 8,386,056 bytes, `rom_titan` | the same registers, ending with pages 10 and 11 in the two top windows (`banks [0, 1, 2, 3, 4, 5, 10, 11]`), which is the demo reaching past the 4 MB the 68000 can see | So the game pages in its top megabyte at the address the document says, checksums it, and goes on to its title screen: the mapper is judged by the cartridge it was made for. ### TMSS #### Decisions and their sources - **The boot ROM is something a caller fits.** `System(..., tmss_rom=...)` (and `--tmss-rom` on the command line) puts a `cartridge.BootROM` on the bus in the cartridge's place and makes bit 0 of $A14101 choose between them; without one the cartridge is on the bus from power-on and $A14101 does nothing. That is exactly what every run of milestones 1 to 6 did -- VDPFIFOTesting is scored on `genesis-tmss` among nine machines -- and making the boot ROM automatic would move all of them for no gain. The VDP lock is *not* optional: every TMSS machine has it. - **The two are swapped, not tested for.** `Board.install_tmss_rom` puts the boot ROM where `self.cartridge` was and `_tmss_select` swaps them back, so a board with no boot ROM pays nothing on the hottest path in the emulator. - **The behaviour is read out of the boot ROM's own disassembly** (`reference/src/TMSS-Disassembly`, which rebuilds bit for bit): `bset #0,(a3)` with a3 = $A14101 to look at the cartridge, `cmp.l (ROM_Header).w,d7` against 'SEGA' and then ' SEG' with 'A' after it, the licence message for 60 iterations of a delay loop, `move.l #0,(a2)` with a2 = $A14000 to lock the VDP again, and `bset #0,(a3)` for good before jumping to the cartridge's start vector. CMD's 4.4 says the same in three sentences. - **The ROM is 16 KB.** The No-Intro dump is the chip's 2,048 bytes; MAME's is those same bytes and 14 KB of zeros, which the disassembly's README calls "hardware padding", and the board pads the same way. Above 16 KB it reads $FFFF, as MAME does. #### The runs (2026-09-23) `.venv-pypy/bin/python scripts/run_tmss.py --png ...`, 14 s, with the local No-Intro boot ROM (2,048 bytes, SHA-1 `3f50b76b0529db7f79c396b5e808cc0786ffc311`): 1. **Sonic The Hedgehog (USA, Europe) on `genesis-tmss`**: the licence message "PRODUCED BY OR UNDER LICENSE FROM SEGA ENTERPRISES LTD." is on screen by frame 2, the cartridge takes the bus at **frame 189 (3.15 s)**, and by frame 420 the picture is Sonic's own SEGA screen. That is the brief's acceptance: **TMSS boots the local No-Intro boot ROM to a licensed cartridge.** 2. **MAME 0.285 `genesis_tmss` on the same cartridge at 7 emulated seconds** (a detector): **71,680 of 71,680 pixels equal, 100.00 %**. 3. **A cartridge whose header is not 'SEGA'**: the licence message never appears, the cartridge never takes the bus, and $A14000 reads $00000000 -- the boot ROM switched itself back in, locked the VDP and stopped in `FailLoop`, which is what the disassembly's `.fail` path does. 4. **The VDP lock, with no boot ROM fitted**: a cartridge that writes to $C00004 without having written "SEGA" raises the board's `Lockup` at that access. ### The region and version register `.venv-pypy/bin/python scripts/run_region.py`, 126 s. The Manual's own page 72 (PDF page 84) gives $A10001 as MODE, VMOD, DISK, RSV, VER3-0, and all nine machines decode to what their fields say: | machine | $A10001 | | machine | $A10001 | | --- | --- | --- | --- | --- | | genesis | $A0 overseas NTSC ver 0 | | megadrive | $E0 overseas PAL ver 0 | | genesis-tmss | $A1 | | megadrive-tmss | $E1 | | genesis2 | $A1 | | megadrive2 | $E1 | | genesis3 | $A1 | | megadrive-japan | $20 domestic NTSC ver 0 | | | | | megadrive2-japan | $21 | A 68000 reading $A10001, $A10000 and $A10000 as a word gets the byte, the same byte and the byte in both halves on every machine, which is CMD's 3.0 rule. **The games.** Three that check it, each run on all nine machines for 6 emulated seconds; every one splits the nine into exactly the four overseas NTSC machines and the five that are PAL or domestic: | game | boots on | refuses on | | --- | --- | --- | | Mortal Kombat 3 (USA) | genesis, genesis-tmss, genesis2, genesis3 | megadrive, megadrive-tmss, megadrive2, megadrive-japan, megadrive2-japan | | Comix Zone (USA) | the same four | the same five | | Streets of Rage 3 (USA) | the same four | the same five | The refusal is the screen "DEVELOPED FOR USE ONLY WITH NTSC GENESIS SYSTEMS". Against MAME's three drivers as a detector: `megadriv` and `megadrij` **100.00 %** of pixels for all three games, and `genesis` 100.00 % for Mortal Kombat 3, 97.28 % for Streets of Rage 3 and 91.23 % for Comix Zone -- the three machines where the game is actually running and its animation is a frame or two out of phase, the same kind of difference milestone 3 recorded for the lockstep games. ### r57shell's VDP tests, which the pad was supposed to unblock Milestones 3 and 5 recorded that "the ROM polls the pad seven times a frame -- the 6-button handshake -- so neither the board nor MAME leaves its first screen". The observation was right and the conclusion was wrong: the polling *is* the handshake, but the ROM is navigated with the **D-pad**, and r57shell says so in the thread ("even if you don't see screen, you can change tests by arrows keys on pad", forum t=1585). RIGHT walks its eight screens with a 3-button pad just as well as with a 6-button one. So the blocker was a misreading, and it is recorded here as one. **What can judge them, and it is very little.** r57shell never ran the ROM on hardware ("I didn't because I can't do that") and asked for results. The one report in the thread is MrTamk1s's, on an MD2 VA1.8 with a Sega 315-5708-01 (he photographed the chip: `reference/images/t1585-18.jpg`) plus a 32X, captured to a VCR and watched on two CRTs, and it is one sentence about one test: "VDP Redraw Test #4 acted differently on my smaller CRT and on the Big CRT. On the smaller, the screen completely rolled over, while on the larger, only the first few rows were flickering/rolling." His video is on YouTube and is not pinned; of his three pinned photographs two are of the console and the VCR and one is a CRT too dark and too small to read a test off. So **the MD2 report judges test 4 and nothing else**, and what it says is about a display losing and regaining sync. For the rest the only statement is the ROM's own printed expectation, which its author wrote from what he believed and wanted confirmed. `.venv-pypy/bin/python scripts/run_r57shell_tests.py`, 10 s, 12 frames measured per screen: | screen | the ROM says | the board | | --- | --- | --- | | 1 VDP Redraw Time Test 1 | MUST SEE right column of spheres | the display alternates 256x224 and 320x224 frame by frame; the right 40 columns carry **1,446 lit pixels on the wide frames and 0 on the narrow ones**, so the column is drawn, flickering at half the frame rate | | 2 VDP Redraw Time Test 2 | MUST NOT SEE right column of spheres | 256x224 throughout, **0 lit pixels** in the right 40 columns, nothing changing | | 3 VDP Redraw Time Test 3 | MUST NOT SEE glitches | 256x448 (interlace mode 2), a regular field of spheres, **identical on all 12 frames** | | 4 VDP Redraw Time Test 4 | MUST NOT SEE blinking of whole screen, only first rows | 320x224, **nothing changes at all**: neither the whole screen nor the first rows. The MD2 report's "only the first few rows were flickering/rolling" is a CRT losing sync, which a frame buffer cannot show. **Not reproduced**, and recorded as an open item | | 5 VDP Blink Test (Reg 0 bit 0) | MUST SEE blinking of whole screen | **every one of the 11 frame pairs differs**: the whole screen alternates between the text and black | | 6 VDP Colors Test 1 | MUST SEE only same colors within solid block | a static screen with the shadow and highlight blocks | | 7-8 VDP Colors Test 2 and 3 | (interactive) | static screens of the shadow/highlight priority matrix | **Test 5 needed a change to the VDP, and it is the one thing this milestone found that was a real gap.** Register $00 bit 0 "actually turns off all display generation, as opposed to the screen blanking feature which simply shows the backdrop color" (CMD `genvdp.txt` 17); the board did not model it, so the blink test showed a still picture. It now draws such a line black whatever CRAM holds (`render.py`, per row, because there is no CRAM entry that means "nothing"). r57shell's own note from 2013 -- "blink test works only in MESS" -- says how few emulators did it then. Tests 6 to 8 are the shadow/highlight priority matrix by eye, which milestone 3 already judged against Kabuto, CMD and Genesis Plus GX; nothing here adds to that. ### Everything these changes touch, re-run (2026-09-23) Five things in `src/` moved: the pads and the I/O chip's clock, the cartridge's EEPROM and battery handling and the halved battery size, TMSS's bank register, the renderer's register $00 bit 0, and the two new constructor arguments. The battery size is the one that could move an earlier run -- Sonic The Hedgehog 3 and Phantasy Star IV are the battery games in the milestone-1 lockstep -- so their MAME traces were re-recorded and replayed; the rest are checked because they are cheap and because the working agreement says to. | Run | Result | | --- | --- | | milestone 1's replay, **Sonic The Hedgehog 3 (USA)**, trace re-recorded from MAME 0.285, 30 emulated seconds | **21,741,798 68000 and 11,837,738 Z80 instructions identical, 0 unexplained**, 251 s -- milestone 1's counts to the instruction | | milestone 1's replay, **Phantasy Star IV (USA)**, likewise | **21,254,417 and 13,280,703, 0 unexplained**, 251 s -- likewise | | Nemesis's HV/status captures, 288 dumps | **8,762,415 of 8,847,360 words**, unchanged to the word, 96 s | | VDPFIFOTesting, all nine machines | **122/122** on eight and **114/122** on genesis3 (its eight VSRAM tests), unchanged | | Nemesis's sprite masking ROM against his MD1600 | **0 of 18 result cells differ**, unchanged | | MoD's `gen_test_z80_bus` | 8 checks PASS, $4243 and $FFFF, delay counters 0001/0001, unchanged | | `scripts/run_bus_arbiter.py`, 4,000 accesses | 2.27 / **2.91** / 2.44 wait states and 481.0 clocks a raster line, unchanged | | `scripts/run_dma_cost.py` | one word 7.4, fit 2.37 x words + 1.7, the Manual's table 16.1/167.1/18.1/205.1, unchanged | | the nine milestone-3 test ROMs against MAME's frames, 3 emulated seconds each | 100.00 (`wtest`), 100.00 (`wtest_i1`), 100.00 (`stetest`), 100.00 (`vdp_tests`), 99.84 (`wbug`), 96.93 (`vctest`), 96.25 (`wtest_i2`), 69.64 (`SHLTEST`), 41.97 % (`STETEST2`) -- **every figure identical** | | the PSG against Nuked-PSG, ten streams | **0 of 121,279,139 input clocks differ** | | the YM2612 against Nuked-OPN2, eighteen streams, both variants | **0 of 110,502,778 internal cycles x 3 values x 2 variants not identical** -- 663,016,668 values, none different, so **sound is still cycle-exact** | | `scripts/run_nuked_md.py roms`, ten test ROMs against the die-derived referee | **every one of its ten figures unchanged** (28,921/28,921 twice, 25,307/25,307 three times, 21,828/21,832, 230/233, 22,125/28,122, 23,258/28,621, 23,259/28,622) | | `pytest -q`, PyPy 7.3.23 | **73 passed, 1 deselected** in 154 s, against the timing session's 49 passed: the 24 new ones are milestone 7's | **Two numbers needed running down, and both are the records' and not the board's.** The PSG total is 121,279,139 where the timing session recorded 121,279,196, and the YM2612's 110,502,778 where it recorded 110,549,790. Both were checked against a git worktree at this session's starting commit `fa22dcc`, run with the same interpreter and the same referee binaries: the PSG's ten streams come out **stream for stream identical** to this tree's, and `run_fm_streams.py --games`'s twelve streams are **identical line for line before and after**, register writes and cycle counts alike ("BEFORE AND AFTER IDENTICAL", 12 streams, 0 comparisons not identical). So nothing this session changed moved either stream; the earlier figures were recorded from a slightly different state and are superseded by the ones here. ### Open questions for the user QUESTION: **The 6-button pad's timeout is a field with CMD's figure in it.** Four published numbers measure three different quantities and their author says the parameter varies from pad to pad. The board takes CMD's "about 8192 68000 cycles from the last change of TH"; nothing observable turns on it, because a poll is microseconds and a frame is 16 ms. Keep that, or carry Terakawa's three figures as the default and CMD's as the alternative? (The brief said not to fit one number and call it hardware, which is why neither is called one.) QUESTION: **After the fourth rising edge the board's pad stops** ("From this point on, the standard 3-button pad values will be returned if any further TH transitions are done", CMD 3.2), where MAME's wraps its counter modulo 4 and starts the sequence again. Nothing pinned settles it and no game seen here does more than four edges in a burst. Accept CMD's, or is this worth a probe? QUESTION: **Eke's NBA Jam bits are corrected from MAME's code, with the game as the judge.** With his /SDA in on bit 0 the game rewrites its whole EEPROM on every boot; with MAME's bit 1 it reads its save back and writes nothing. That is as good a judge as exists here, but it is one game on one board. Accept, or should the other Acclaim boards (NBA Jam TE, NFL Quarterback Club, College Slam) be driven far enough into a game to save, which needs a scripted input sequence? QUESTION: **Three EEPROM boards are modelled from sources that disagree and no game was run on them**: the Ninja Burai Densetsu prototype (Eke's mode 1 against MAME's mode-2 chip) and Brian Lara Cricket and Cricket 96 (Eke's Codemasters addresses against MAME's $380000 pair, and his X24C01 against MAME's 24C65). All three are in the local romset but none writes its battery without being played. Leave them as they are with the disagreement named, or drop the two Brian Lara boards until something can judge them? QUESTION: **r57shell's VDP Redraw Time Test 4 is not reproduced and probably cannot be.** The only hardware statement is that a CRT rolled -- completely on a small one, only the first rows on a big one -- which is a display losing sync, not a picture. The board's frame does not change at all there. Accept that as out of reach, or is a "the VDP's sync went away for N lines" flag on the frame worth having for a frontend? QUESTION: **Register $00 bit 0 draws a black line.** CMD says it "turns off all display generation, as opposed to the screen blanking feature which simply shows the backdrop color", which says what it is *not* and not what a console puts out. Black is the obvious reading of "no display generation" and it makes r57shell's blink test behave as he says; nothing pinned confirms the colour. Accept? QUESTION: **The J-Cart's two extra ports answer as empty sockets.** The four J-Cart boards in the local romset are modelled far enough to run (the port reads all pins high); putting pads on them is a frontend's job, and milestone 9 is the frontend. Leave it, or wire them to `System(pads=...)` now? QUESTION: **MD Soft Checker v0.30 is still not available** (the local romset's symlink is dangling and the only link is a mega.nz page), so Sega's own diagnostic has never been run against the board. Worth fetching by hand before milestone 8's sweep? ### What is *not* claimed - **The 6-button pad's timeout.** The four published figures do not agree and their author says the parameter varies from pad to pad; the board carries one of them as a field and nothing here measures it. - **Test 4 of r57shell's VDP tests**, which is the only one the MD2 report covers, and which is a CRT losing sync rather than a picture. - **The three EEPROM boards no game was run on** (the Ninja Burai prototype and the two Brian Lara boards): they are modelled from sources that disagree and the disagreements are named, not settled. - **What a console puts out with register $00 bit 0 set**: the board draws black because "no display generation" is not the backdrop, which is all CMD says. - **The J-Cart's extra ports** answer as empty sockets; no pad can be put on them yet. - **Nothing about the picture of Overdrive 2's four wrong frames**, which are still the user's post-sweep session, and nothing about the sound path, which this milestone does not touch. ### Frames a second, paired against the session's starting commit Two things were added to the cartridge's read path -- the battery and the EEPROM's lines -- and a 68000 fetch is the hottest thing in the emulator, so it was measured rather than assumed. Measured first, it cost about 2 %; the two checks were then folded into one attribute (`Cartridge.special`, true only when there is a battery or something decoded), which puts a plain cartridge back where it was. 900 frames after 120 of warm-up, `--no-sound`, by **user CPU time**, the session's starting commit `fa22dcc` in a git worktree and the current tree run alternately, twice each, on a machine shared throughout: | Game | before (s) | after (s) | | --- | --- | --- | | Sonic The Hedgehog (USA, Europe), before the fold | 20.87, 21.39 | 21.25, 21.41 | | Phantasy Star IV (USA), before the fold | 19.53, 19.03 | 19.93, 19.50 | | Sonic The Hedgehog (USA, Europe), after the fold | 19.19, 17.63 | 17.48, 18.06 | and an EEPROM cartridge costs nothing measurable against a plain one: NBA Jam 46.2 frames a second against Sonic's 46.4 in the same conditions. ### What is left for milestone 8 The compatibility sweep is next and it inherits three things from here: cartridges now identify themselves (`Cartridge.unsupported` names a board the sweep cannot run), the pads can be either kind, and `--save` means a sweep can be run twice over a game that saves. The boards still not modelled are the unlicensed mappers, the SVP, the Game Genie and the Sega Pico family; the sweep will say how many images they are. ### Commits | | | | --- | --- | | `851b9e7` | The cartridges: serial EEPROMs, the J-Cart's ports, and a battery that saves (`eeprom.py`, `cartridge.py`) | | `e94a4f3` | The 3- and 6-button pads, with TH's edges in time (`io.py`) | | `0229a70` | TMSS: the boot ROM on the bus, and the clock the I/O chip now needs (`board.py`) | | `efb7b45` | Register $00 bit 0: no display generation at all (`render.py`) | | `e16e3d7` | The system and the command line: a pad, a battery file and a boot ROM | | `9a9643a` | Six runs that judge milestone 7 (`scripts/run_{pads,battery,mapper,tmss,region,r57shell_tests}.py`) | | `69d836c` | Milestone 7's tests: 24 that need nothing fetched | | `a0d299e` | `run_mapper.py`: do not try to write a PNG of a frame not yet drawn | | `d6a8659` | Say exactly what a read of an EEPROM board's register gives | | `ef04b86` | `start-here.md`: two things it got wrong about the pads and TMSS | | `e755a3b` | Milestone 7's record: the worklog, the certification record, the open items, the findings and the README, and the fold in `cartridge.py` that keeps a plain cartridge as fast as it was | | `58cbc47` | the final line counts | **End of milestone 7.** Stopping here, as the working agreement says; milestone 8's sweep is next. ## Decisions (the user, 2026-09-23), answering milestone 7's questions 1. **The 6-button pad keeps CMD's timeout** (8192 68000 cycles since TH last changed) as the field's default. Terakawa's three figures measure different quantities and he says they vary per pad, so no single number is claimed as hardware; the field stays a field. 2. **The pad stops after the fourth rising edge** (CMD's rule), not MAME's modulo-4 wrap: a research document plus `joy_speed`'s byte sequence beat a detector. 3. **The NBA Jam correction is accepted.** One game is thin, but a game behaving correctly beats a document that cannot be right (Eke's `gen_eeprom.pdf` puts /SDA-out and /SCL on one bit). Do not script the other Acclaim boards for now. 4. **The three unrun EEPROM boards stay, named**: dropping them would stop those games booting at all, and their disagreements are already recorded. 5. **Redraw Test 4 is out of reach** and stays that way: a frame buffer cannot show a CRT losing sync. No "sync went away" flag; unneeded machinery. 6. **Register $00 bit 0 draws black**, labelled: nothing pinned says the colour. 7. **Wire the J-Cart's two extra ports to `System(pads=...)` now**, while the cartridge code is fresh, rather than leaving them to the frontend. 8. **MD Soft Checker v0.30 is available after all** (the user asked the right question): the local mirror has it as `No-Intro/Sega - Mega Drive - Genesis/MD Soft Checker (USA) (Proto) (Unl).zip` (zip SHA-256 `688debcf0635e48ef501c84fd8348cdd40d18b2a5efa1e4391be1fd5cbf2996a`, inner `.md` 262,144 bytes). No-Intro dropped the `(v0.30)` from the name, which is why the romset's symlink dangles. It runs on the board: at 600 frames it shows its pad screen with both ports reading a 3-button pad. It is Sega's own factory diagnostic, so it is a hardware-corrected oracle: use it. ## Session 8 (2026-09-23): milestone 8, the compatibility sweep and its triage ### How the brief was read Scope is milestone 8 only: boot every cartridge in `/data/emu/roms/megadrive` for N emulated seconds against MAME's frame at the same time, then triage every difference into a named cause, as sms-python did. Nothing is changed to match MAME without a higher-tier source; MAME is a detector here and never a judge, and a difference that is MAME's own -- its `insta_68k_to_*_dma` hack, its `rand()` on $A11100, its interrupt acceptance, its lack of an arbiter, its 6-button pad that its own source says does not work -- is counted apart from the board's. Three things the user asked for by name: run Sega's own MD Soft Checker, now that the local mirror is known to have it, and record what it reports as its own acceptance (a judge, not a detector); watch for the 7- and 35-MCLK work-RAM refresh stretches the board does not model as a possible cause of a frame difference (the timing session's decision 5); and say whether a real game's difference points at Kabuto's DMA start-up cost (milestone 5's open item, left for here). Overdrive 2's four wrong frames are the user's own next session and were not touched. ### Environment Same as the previous sessions: `.venv` CPython 3.14.4, `.venv-pypy` PyPy 7.3.23 (Python 3.11.15), m68000-python pinned at 51ee1a5 (unchanged: docs/polish.md), z80-python 0.4.0, MAME 0.285, the 13th-generation Core i9-13900K, shared throughout (load average 25-30 of 32 threads for most of the session, which the wall times below reflect). ### What was built | File | Lines | What it is | | --- | ---: | --- | | `scripts/mame_media.py` | 207 | which board MAME puts an image on, and how to hand it one so that both machines run the same cartridge | | `scripts/compat_sweep.py` | 290 | the sweep: every cartridge on the board and on MAME, the frame compared | | `scripts/triage_diffs.py` | 210 | the triage: the lockstep's verdict for each difference, and which of the board's own timing models moves it | | `scripts/run_soft_checker.py` | 123 | Sega's MD Soft Checker, its verdicts read off the screen | | `tests/test_milestone8.py` | 90 | 7 tests that need nothing fetched | ### Sega's MD Soft Checker, which is a judge `MD Soft Checker (USA) (Proto) (Unl)` from the local No-Intro mirror (zip SHA-256 `688debcf0635e48ef501c84fd8348cdd40d18b2a5efa1e4391be1fd5cbf2996a`, the image 262,144 bytes, SHA-1 `bd716dbbbe3fd50169fa5bad7e203ce9356fdfc0`, header "MD Soft Checker Version 0.30"), pinned in `scripts/pinned_files.json` by a `file://` URL that names exactly where it came from, fetched into `tests/test_roms/sega/` and not committed. It is not in MAME's software list. It is Sega's own factory diagnostic, so under the tier rule it is a **judge**, not a detector: it was written by the people who made the machine, and what it reports is about hardware. `scripts/run_soft_checker.py` runs it and reads its verdicts off the rendered picture -- each result line's last two glyphs as a block of pixels, because the ROM is proprietary and publishes no result table -- and the glyphs themselves were read once by eye from the PNG. `.venv-pypy/bin/python scripts/run_soft_checker.py` (96 s for all nine machines): **17 result lines on every machine, all seventeen with the same verdict, and that verdict reads OK.** The report, read off the picture at frame 240: ```text OVERSEA mode NTSC VER.0 68K Register R/W OK DMA ROM ==> VRAM OK 68K All Instruction Set OK DMA ROM ==> Color RAM OK WORK RAM R/W OK DMA ROM ==> VSRAM OK Z80 BUS Request OK DMA WRAM ==> VRAM OK Z80 RAM R/W OK DMA WRAM ==> Color RAM OK VRAM R/W OK DMA WRAM ==> VSRAM OK Color RAM R/W OK DMA VRAM FILL OK VSRAM R/W OK DMA VRAM COPY OK I/O Port Register R/W OK ``` and its header is the version register read back, which is milestone 7's work judged by Sega's own program: `OVERSEA mode NTSC VER.0` on `genesis`, `OVERSEA mode PAL VER.1` on `megadrive2`, `JAPAN mode NTSC VER.0` on `megadrive-japan`. The Genesis 3, whose VSRAM is 0x80 bytes and which fails Nemesis's VSRAM tests, passes the checker's VSRAM test -- the checker writes and reads back, which a larger VSRAM does not break. At 600 frames it has moved on to its pad screen, which reads `JOY1 PAD3 1P` and `JOY2 PAD3 1P` with `U L R D ST A B C` -- a 3-button pad found on both ports, which is what the board presents. **What this does not cover**: the checker tests that each memory answers reads and writes and that each kind of DMA moves bytes; it says nothing about timing, about the picture, or about sound. It is a floor, and the board is over it. ### The sweep: what was chosen, and why Four choices had to be made before running anything, and each is a number. **Sound off.** `YM2612.enabled = False` keeps the chip's bus, register file, timers and BUSY and skips only the generator, so nothing a game can observe changes (milestone 4). It is the difference between 2.9 seconds of wall time per emulated second and 0.3: with the FM running, the whole sweep would be ten times the cost for a picture that does not depend on it. **Ten emulated seconds**, as sms-python's sweep used. Measured on this machine, a cartridge costs about 100 s of CPU at that length -- 600 frames of a board that runs 38 to 51 frames a second without sound, plus MAME (0.8 s), the snapshot and the comparisons -- so the whole romset is about four hours on 16 processes. Five seconds would halve it; twenty would double it and lose comparisons rather than gain them (below). Ten is also the length milestone 3's own MAME frame table used. **Sixteen processes**, the cap the working agreement sets on this shared machine, under `nice`. The machine was carrying other work throughout. **MAME's `genesis` for every image**, not a driver chosen per region. Both machines then run the same console, which is what makes the comparison a comparison: a Japanese or European cartridge that refuses to run on an overseas NTSC machine refuses on both and shows the same screen (milestone 7 measured exactly that against MAME's three drivers). ### Two traps of this board's own, both measured **MAME's file loader gives almost every cartridge battery RAM it does not have.** sms-python's trap 8 -- MAME guesses a board from the image -- has a worse form here. `md_slot.cpp`'s `get_cart_type` matches a table of code signatures by exact file length and, when nothing matches, returns `SEGA_SRAM_FALLBACK`: 64 KB of battery RAM at $200000, "in case this is a broken header", where the board mirrors its ROM (Eke's mirroring rule). Counted over the local romset: of the 1,799 present images MAME's `megadriv` software list names, **1,523 would run on a different board in MAME if handed to it as a file** -- 1,347 of them exactly this way, and the rest as `rom_sram`, `rom_eeprom`, `rom_codemast` and so on. So `scripts/mame_media.py` hands MAME a **software-list name** for every listed image, from a scratch rompath holding that one image under the name the list expects, which is the same board `Cartridge.from_image` reads from the same list. The 874 unlisted images have to go as files, and `mame_guess` -- a port of `get_cart_type`'s table -- says which board MAME then puts each on, so that a differing frame can be attributed to that rather than to the board. (Checked against the list itself: for every listed image the board's own slot equals the list's, 1,799 of 1,799.) **The board's picture is a few frames behind MAME's at the same emulated time.** MAME's exit snapshot is the frame it completes after `-seconds_to_run`; the board's is the first frame it completes at or after the same master clock. Those are not the same field of an animation. Fitted over the 35 cartridges of a 207-cartridge sample whose picture is identical at *some* offset and not at all of them, at three lengths: | length | the offset at which most of the 35 are identical | how many | | --- | --- | --- | | 5 emulated seconds | **+4** | 29 of 35 (0: 22) | | 10 | **+3** | 24 of 35 (0: 10) | | 20 | +4, +5 | 19 of 35 (0: 11) | The offset does **not** grow with the length of the run, which is what says it is a one-off shift and not a rate difference: the two machines run the frame at the same rate, and the board's game simply starts its animation two to five frames later. Why it would: the board charges the 68000 stalls MAME does not model at all -- both refreshes, the arbiter's bank-access delays, the DMA's start-up -- so a game's CPU-bound initialisation (a checksum over a 2 MB ROM is a second of 68000 time) ends a little later on it. That is measured below rather than argued. `compat_sweep.FRAME_OFFSET` is therefore **3**, one figure for the whole sweep, and the frames within `--window` of it are scored as well, so that a cartridge whose picture is identical a frame or two away is reported as `phase` rather than as a difference in what the machine drew. A search per cartridge was not used: it picks a wrong frame on a mostly uniform picture, which is the trap sms-python's sweep found. ### What a row of the sweep means `tests/compat/megadrive.csv` (git-ignored, as sms-python's is) has a row per entry: the cartridge, the board `Cartridge.from_image` puts it on, the board MAME runs it on when that differs, the status, the differing pixels, and every offset in the window at which the two pictures are identical. | status | what it means | | --- | --- | | `same` | the frame compared is identical to MAME's, pixel for pixel | | `phase` | it is not, but a frame within 12 either side of it is: the same picture, a different field of an animation | | `differs` | no frame in that window is identical | | `size` | the two pictures are not even the same size (H32 against H40, or interlace) | | `unsupported` | `Cartridge.unsupported`: a board the emulator does not model (the unlicensed mappers, the SVP, the Game Genie) | | `mame-board` | the frame differs *and* MAME ran the image on another board (an unlisted image) | | `lockup` | the board raised `Lockup` -- CMD's rule that some accesses stop the machine -- where MAME went on | | `missing` | a broken symlink in the local romset | | `error: …` | MAME would not run it, or the board raised something else | ### The triage, and why it is two passes sms-python's triage was one pass: run the MAME lockstep on every differing cartridge and read the verdict off it. That still works here and is pass 1 (`--lockstep`): MAME's two traces recorded for the sweep's own emulated time, the board stepped against them instruction for instruction, and the verdict taken from its report -- `cpu` for a divergence or an unexplained read, else the first non-empty class of *differing device read* (`vdp-reads`, `fm-status`, `z80-order`, `mame-rand`), and `identical` when nothing differed at all, which says the difference is in the picture and not in what either program did. But the lockstep has a blind spot on this board that it did not have on the Master System, and it is the one the user's decision 5 points at. `lockstep_mame.py` turns the refresh and the arbiter **off**, because MAME models neither and with them on the two machines interleave the CPUs differently and the replay is no longer instruction-exact. So the lockstep cannot see a difference the board's own bus timing causes -- which is exactly where the work-RAM refresh's unmodelled 7- and 35-MCLK stretches would show. Pass 2 (`--sensitivity`) is for that, and it needs no MAME trace: run the sweep's own comparison again with one model turned off at a time -- the work-RAM refresh, the cartridge refresh, the arbiter, and the cartridge put on MAME's fallback SRAM board -- and see which of them moves the frame. A cartridge whose picture is the same whether the work-RAM refresh runs or not is one where that model cannot be the cause; one whose picture moves is a candidate, and it is named as one. None of it needs a change in `src/`: both refreshes are due at a master clock the board keeps in a field, so a clock they never reach turns them off. ### What is *not* claimed by this milestone - **Nothing about sound.** The sweep runs with the generator off; the FM and PSG are judged cycle for cycle by milestone 4's die-derived referees and nothing here touches them. - **Nothing about timing** beyond what the sensitivity pass measures: MAME models no refresh, no arbiter and no DMA start-up, so it cannot judge any of them, and the lockstep turns them off to compare at all. - **Nothing about a cartridge whose board the emulator does not model**: those are counted and named, not run. - **Nothing about Overdrive 2's four wrong frames**, which are the user's own next session. - **Nothing hardware.** MAME is a detector throughout. The only judge in this session is Sega's MD Soft Checker, and it judges that the memories and the DMA work, not how they are timed. ### Why the board's picture is behind MAME's, measured The alignment above is a fitted constant, so what it is fitting matters. The claim is that the board charges the 68000 stalls MAME models nothing of -- both refreshes and the arbiter -- so a game's CPU-bound initialisation ends later on it and its whole animation starts a few frames later. That is testable with the board's own knobs: run the same comparison with all three turned off. `/tmp/.../lag.py` (`compat_sweep.run_one` with a `disable` that clears both refresh timers and `arbiter_enabled`), 10 emulated seconds, `--window 12`, the offsets given relative to the frame the sweep compares (so `FRAME_OFFSET` = 3 is already in them): | cartridge | as the board ships | with both refreshes and the arbiter off | | --- | --- | --- | | Sonic The Hedgehog (USA, Europe) | identical at **+9** | identical at **+1** | | Phelios (USA) | identical at **0** | identical at **-1** | | Zero Wing (Japan) | identical at 0, 1, 2, 3 | the same four | | JuJu Densetsu (Japan) (En) | identical at 0 to 7 | the same eight | **Sonic's picture moves eight frames closer to MAME's when the stalls the board charges and MAME does not are taken away**, which is the claim, measured. Phelios moves one frame. The two whose animation is locked to the vertical blank from the first frame do not move at all, which is the other half of it: the lag is in how long a game's *initialisation* takes, not in how fast the frames come. So `FRAME_OFFSET` is not a fudge of unknown origin: it is the accumulated cost of milestone 5's and the timing session's own work, which MAME cannot see. It is also why it cannot be one exact number -- how much CPU-bound work a game does before its first drawn frame differs from game to game. ### The sweep: the run, and what it found (2026-09-23) `.venv-pypy/bin/python scripts/compat_sweep.py --seconds 10 --jobs 16 --window 12 --frames --offsets`, 14,423 s (4 h 0 m) on 16 processes under `nice`. | status | count | what it means | | --- | ---: | --- | | `same` | 1,609 | identical to MAME's frame, pixel for pixel | | `phase` | 461 | identical at another frame within 12 either side | | `missing` | 841 | a broken symlink in the local romset | | `differs` | 261 | no frame in the window is identical | | `mame-board` | 229 | the frame differs *and* MAME ran the image on another board | | `unsupported` | 65 | a board the emulator does not model, across 40 distinct slots | | `size` | 32 | the two pictures are not the same size | | `error:` | 11 | MAME would not run it, or the board raised | | `lockup` | 5 | the board raised `Lockup` where MAME went on | **2,070 of the 2,673 present cartridges -- 77.4% -- are identical to MAME's picture or identical a frame or two away.** That figure is a detector's, not a judge's, and it is deliberately not called a pass rate: the sections below say what the remainder is, and a good part of it is MAME's. ### The triage, pass 1: which of the board's own models moves the picture `scripts/triage_diffs.py --sensitivity --jobs 16 --seconds 10 --window 12 --sample 60`, 4,057 s. Each of 60 differing cartridges was run again with one model turned off at a time. | what moves the picture | cartridges of 60 | | --- | ---: | | MAME's fallback SRAM board | 31 | | the work-RAM refresh | 26 | | the cartridge refresh | 26 | | the arbiter | 15 | | the DMA's start-up cost | 8 | | **nothing: unmoved by every model** | **14** | The largest single cause is **MAME's**, not the board's: 31 of 60 move when the cartridge is put on the `SEGA_SRAM_FALLBACK` board MAME's file loader would have chosen. Fourteen move for none of the five, which says the board's timing models are not implicated in those at all. A model "moving" a picture implicates it; it does not convict it, and nothing here was changed on the strength of it. ### The triage, pass 2: the lockstep's verdict `scripts/triage_diffs.py --lockstep --jobs 16 --seconds 10 --status differs,size,lockup`, 9,902 s (2 h 45 m) over 298 cartridges. | verdict | count | what it means | | --- | ---: | --- | | `vdp-reads` | 181 | the two programs read different values from the VDP | | `cpu` | 112 | the two programs diverged, or made an unexplained read | | `identical` | 4 | the programs ran identically and no read differed | | `fm-status` | 1 | the FM's status register read differently | `vdp-reads` dominating is expected and is not a finding about the board: the lockstep runs with the refreshes and the arbiter **off** (MAME models none of them), so the two machines reach the VDP's counters and status at different times by construction. ### The four cartridges that ran identically, which are the cleanest result here `Breach (USA) (Proto)`, `Joshua & the Battle of Jericho (USA) (Unl)`, `Zany Golf (USA) (Unl)` and `Exodus - Journey to the Promised Land (USA)` each ran **5.9 to 6.8 million 68000 instructions with not one read differing from MAME's**, and their pictures are still not the same: the board draws 256x224 where MAME draws 320x224. Identical execution and identical device reads leave nothing for the difference to be except the picture itself, so this is the sharpest thing the sweep produced: it is about the width the renderer settles on, not about timing, the bus or the CPUs. `Renderer.frame` takes `width = max(self.widths[:height], ...)`, so the two machines disagree about H32 against H40 for a frame whose program neither disputes. Ten more cartridges show the same 256-against-320 shape without an identical lockstep behind them. Not chased in this milestone; it is a QUESTION below. ### The `size` rows are three different things, and should never be one number Of the 32: - **17 are the partial-frame capture** (320x1, 320x4, 320x13, 320x48, 320x55, 320x56, 320x101, 320x223, 256x4): `System.run_frame` returned part way into the *next* frame. Diagnosed in full under "The partial-frame capture" above; it is a limitation of the harness and of `Renderer`, not a rendering difference. - **15 are a width or mode difference** (256x224 against 320x224 and four the other way round), the four identical ones among them. - **Overdrive 2 is neither**: 320x240 against 320x224, because the board runs it on a PAL machine, as the demo demands, and MAME's snapshot is 224 lines. ### Two things MAME could not do, both attributable to MAME **MAME 0.285 cannot run the Demons of Asteborg family.** All nine `error: MAME` rows are one family -- `Astebros (World) (PixelHeart)` and eight `Demons of Asteborg` releases -- and every one exits with glibc's `corrupted size vs. prev_size`, a heap error inside MAME rather than a refusal to load. Deterministic: every member fails and nothing else does. MAME's own software list marks the entry `supported="no"`. The detector is unavailable for those nine; they say nothing about the board. **`Phantasy Star Fukkokuban (Japan)` is a bad dump.** Its initial PC is `00CB187F`, which is odd, and the header at $100 is not a console string. It is not an interleaved dump: neither a whole-file de-interleave nor an SMD 16 KB-block de-interleave yields a valid header or an even PC. MAME runs it for ten seconds and snapshots 256x224 with every pixel 0 (the PNG was decoded here: one distinct byte value). The board raises `GroupZero (3, 13310079, False, True)` out of `System.__init__`, at the initial PC's prefetch. Both machines agree that nothing runs; a real 68000 takes an address error *during* reset processing, which is a double bus fault, so it halts with a black screen -- MAME's behaviour. The board's verdict is right and its presentation is not. A `src/` change, so it is in [polish.md](polish.md), not made here. ### An image larger than the cartridge window is silently truncated Found while triaging the `error:` rows and larger than the rows that led to it. `Cartridge.from_image`'s fallback returns `cls(image)` with no size check, so an image larger than `ROM_WINDOW` ($000000-$3FFFFF) loads with the rest unreachable. **36 romset images exceed the window; 29 of them are unlisted and get `rom` or `rom_sram` with `unsupported = None`.** The mapper machinery is not at fault: the *listed* Super Street Fighter II gets `rom_ssf2` and runs, while its unlisted Virtual Console re-release of the same 5 MB game gets plain `rom`. It distorts this sweep's own numbers: all nine `Earthion` images score `differs`, counted against the board where the cause is ours. These carts are **not on the SSF2 mapper**. They are on Krikzz's Extended SSF, a different device, and its designer documents it: `extended_ssf-v2.txt`, krikzz.com, 22.09.2014, now pinned in `scripts/pinned_files.json` (specification tier). | | the Sega/SSF2 mapper the board implements | Krikzz Extended SSF v2 | | --- | --- | --- | | bank field | 6 bits (`ssf2tnc.txt`) | **5 bits**, 32 x 512 KB = 16 MB | | bank registers | odd $A130F3-$A130FF, windows 1-7 | even $A130F2-$A130FE, windows 1-7 | | $A130F0/F1 | SRAM enable and write protect | **mapper control**: protect, 32x, ROM write-enable, LED, and **the first bank** | | first bank | fixed | **switchable** | | extras | none | hardware multiply and divide at $A130D0-$A130DA, SD and USB IO | | activation | MAME's software list | the header at $100 reads `"SEGA SSF"` | The documented header rule covers 14 romset images -- 3 Demons of Asteborg, all 9 Earthion, 2 Kunio no Nekketsu -- **and Overdrive 2**, which declares `"SEGA SSF"` and currently runs on `rom_titan`. It does not cover the other 6 Demons of Asteborg, which use a game-specific `"SEGA DOA"`, nor `Astebros`, which is 14.75 MB under a plain `"SEGA MEGA DRIVE"` header, so a size check is still needed behind it. One conflict is left open rather than guessed: MAME's `megadrive_hb_ssf_device::time_f0_w` implements $A130F0 as the Sega mapper's SRAM control with the comment "same as Sega mapper (Demons of Asteborg wants it this way)", which contradicts krikzz's own document. The document is specification tier and MAME is emulator-derived, so the document judges -- but MAME's comment claims a real game disagrees, and that is evidence about its own cartridge. It is in [polish.md](polish.md) to be resolved by observation before any of this is implemented. ### Two fixes taken from the triage, and the numbers they correct (2026-09-24) The user took the recommendation to make the oversize guard first, "because it is cheap and makes the 77.4% honest". It was, and it did -- and validating it turned up a second bug that was not on any list. **1. An image larger than the window is no longer silently truncated.** `Cartridge.__init__` sets `unsupported` when the image exceeds `ROM_WINDOW` and no mapper slot was chosen. Checked against the romset: **29 images are flagged, and the seven that must not change did not** -- Overdrive 2 (`rom_titan`) and the three listed Super Street Fighter IIs (`rom_ssf2`) keep their mappers, and the three Pier Solars keep their own, more specific `rom_stm95`. The guard does not guess a mapper from a size. That is precisely what MAME's `SEGA_SRAM_FALLBACK` does and what this milestone counted against it; the Krikzz Extended SSF work stays queued in [polish.md](polish.md). **It costs more `same` rows than it gains, which is the point**: eight cartridges lose a `same` they had not earned, because they matched MAME on their first 4 MB and nothing else. Nine `Earthion` images stop being counted as the board's failures. **2. `Sonic & Knuckles (World)` was being loaded as its lock-on adapter.** Chasing the last `error:` rows left two `GroupZero`s: the known-bad Phantasy Star dump, and a flagship retail cartridge, which is not a thing to leave as "a bad dump". The archive holds two image members: ```text 262144 Sonic & Knuckles (World) (Lock-on).bin 2097152 Sonic & Knuckles (World).md ``` `load_image` took the zip's first image member and both suffixes are image suffixes, so the board was handed the **256 KB lock-on adapter ROM** instead of the 2 MB game. Its initial PC is odd, so `m68k.reset()`'s prefetch raised out of `System.__init__` -- the same signature as the genuinely bad dump, from an entirely different cause. `_pick_image` now takes the member named after the archive, falling back to the largest. The blast radius was measured before the change: **exactly one archive in the romset's 3,514 entries holds more than one image member.** Sonic & Knuckles now loads the real image (`SEGA GENESIS` header, even PC) and scores `same`, 0 of 71,680 pixels differing, at offset 0. ### The sweep's numbers, corrected | status | as first run | after the two fixes | | --- | ---: | ---: | | `same` | 1,609 | **1,602** | | `phase` | 461 | 461 | | `differs` | 261 | **252** | | `mame-board` | 229 | **226** | | `unsupported` | 65 | **94** | | `size` | 32 | 32 | | `lockup` | 5 | 5 | | `error:` | 11 | **1** | | `missing` | 841 | 841 | **2,063 of the 2,673 present cartridges: 77.2%**, against 77.4% before. The figure goes *down* because eight cartridges stopped passing on a truncated image, which is the fix working. Counted against the cartridges whose board the emulator actually models, it goes up: **2,063 of 2,579, 80.0%**, from 79.4%. The single remaining `error:` row is `Phantasy Star Fukkokuban (Japan)`, the bad dump, whose presentation is still queued in [polish.md](polish.md). Six tests were added (`tests/test_milestone8.py`): the guard fires, a mapper board may exceed the window, an unmodelled board keeps its own reason, and the three `load_image` cases. `pytest`: **86 passed, 1 deselected** on both interpreters. ### The renderer's two buffers, and the full re-sweep that checked them (2026-09-24) The partial-frame capture diagnosed in milestone 8 is fixed. `Renderer.start_frame` now hands the finished frame over by **swapping** five row arrays -- pixels, widths, blanked, palettes and dots -- with a second set, so the next frame is drawn into what the *previous* finished picture used and cannot overwrite the one a caller is about to read. It costs five reference exchanges a frame and about 150 KB; nothing is copied. `frame()` and `frame_rgb()` both take their source from one `_finished()` helper, so they can never disagree about which picture they are showing. Before any frame has finished -- only at power-on -- `_finished` still returns what has been drawn, so a caller always gets a picture. **The whole romset was re-swept rather than the `size` rows the polish list asked for.** The change can move any cartridge whose `run_frame` overshoots a frame boundary, and which those are is exactly what was not known; 3 h 37 m of machine time is cheaper than a number nobody can defend. **17 rows moved, and all 17 are the partial-frame captures. Nothing else in the 3,514 changed.** | what the 17 became | count | | --- | ---: | | `same` -- the picture was right all along | 6 | | `phase` | 1 | | `differs` -- a full frame, and a real difference the truncated one hid | 10 | Seven were being scored wrong purely because the wrong frame was handed out. Ten had a genuine difference that a 320x1 picture could not show. One of the 17 was not a `size` row at all: `Pac-Man (World) (Aftermarket) (Unl)` was `mame-board` with a `320x3` picture -- the same bug wearing a different label -- and it now matches exactly. **No partial-frame row is left.** All 16 surviving `size` rows are genuine width or mode differences (256x224 against 320x224 and four the other way), plus Overdrive 2's PAL 240-line picture against MAME's 224. | status | before | after | | --- | ---: | ---: | | `same` | 1,602 | **1,608** | | `phase` | 461 | **462** | | `differs` | 252 | 262 | | `size` | 32 | **16** | | `mame-board` | 226 | 225 | **2,070 of the 2,673 present cartridges: 77.4%**, and 2,070 of the 2,579 whose board the emulator models: **80.3%**. ### Krikzz's Extended SSF, implemented (2026-09-24) With the $A130F0 conflict settled by observation the day before, the mapper itself was small. The board already had a Sega-mapper-shaped implementation; what these cartridges lacked was a **board**, because almost none of them is in MAME's software list and an unlisted image fell through to plain ROM. **Detection is the cartridge's own statement, not a guess.** krikzz: "Mapper will be activated in case if ROM header contains "SEGA SSF" string". Twenty-two of the romset's images say so at $100 -- seventeen `SEGA SSF` and five `SEGA DOA`, Demons of Asteborg's own variant of the same announcement, which item 20 showed behaves identically. That is the difference between this and MAME's `SEGA_SRAM_FALLBACK`, which invents a board from a file's length. **The backup-RAM header picks which of the two boards it is.** Twenty declare `RA` over $200000-$20FFFF, which is exactly the range MAME's `ssf_sram` device answers with a 32 KB chip on the odd byte -- and exactly the 32 KB krikzz reserves ("First 32Kbyte of this bank will be copied to SD card"). Overdrive 2 and the Joyzz test program declare none and are the plain `ssf` board. **Two of the twenty-two are under the 4 MB window**, so the oversize guard had never touched them and nothing else would have found them: `Castle Cat 3 - The Vegas Connection` (3.88 MB) and `Joyzz Controller Test Program` (64 KB). A size rule would have missed both. The bank field is five bits on these boards (`BANK_MASK`) and stays six on the Sega mapper, and $A130F0/$A130F1 stays SRAM control, both on the evidence of item 20. Overdrive 2 is listed, so `identify` still puts it on `rom_titan` and nothing about it moved. #### The board is now more right than the detector | cartridge | the board draws | MAME draws | | --- | --- | --- | | Demons of Asteborg | its language-select screen, six flags, "Press A to confirm" | nothing: MAME 0.285 exits with a glibc heap error on this family | | Earthion | its title screen: the logo, "PRESS BUTTON", the credits line | **noise** -- MAME puts it on `rom_sram`, a flat 7 MB ROM with no mapper | | Kunio no Nekketsu | its disclaimer screen, legible | the same, and the two agree pixel for pixel | MAME's file loader has no rule for the `SEGA SSF` header; only its software list names the board, and these images are not in it. So for Earthion and Castle Cat 3 it runs the very bug this change fixed, and its picture is garbage while the board's is the game. The 70,000-odd differing pixels on those rows are the detector's, and the rows are counted `mame-board` for exactly that reason. #### What it moved | status | before | after | | --- | ---: | ---: | | `same` | 1,608 | **1,610** | | `unsupported` | 94 | **75** | | `mame-board` | 225 | 243 | | `differs` | 262 | 261 | **2,072 of 2,673 present cartridges, 77.5%.** Counted against the boards the emulator models the figure *falls*, 80.3% to 79.8%, and that is not a regression: nineteen cartridges left `unsupported`, so the denominator grew by nineteen while two became `same`. The other seventeen are cartridges the board now runs and MAME cannot, which no comparison against MAME can score. ### BlastEm's event log, read (2026-09-24) The user asked for BlastEm as a second detector, which matters more since the mapper landed: seventeen cartridges sit in `mame-board` not because the board is wrong but because **MAME cannot run them**. It crashes on the whole Demons of Asteborg family and puts Earthion on `rom_sram` with no mapper, where it draws noise. Getting a *picture* out of BlastEm headless turned out to be closed on every route: - its **debugger** spawns a terminal emulator (`terminal.c`: `execlp(term, term, "-title", "BlastEm Debugger", "-e", termhelper)`), so piped stdin drives nothing; - **`-g`** does not avoid OpenGL and SDL's dummy video driver cannot supply it; - **`USE_FBDEV=1` does not build** at the pinned revision: [GPL source cited, redacted] types `render_thread` as `SDL_Thread *` and only `render_sdl.c` implements `render_create_thread`, so the 2013 framebuffer backend no longer compiles. It is about twenty lines of pthread shim to fix, and was **not** fixed: patching a pinned oracle to build would make it "our BlastEm" rather than an independent one. Its **event log** needs no display at all. `scripts/blastem_events.py` reads it, and `tests/test_blastem_events.py` checks the decode on logs built in the test. **What it settles.** BlastEm runs Earthion properly -- 380,043 VRAM byte writes, 13,840 CRAM and VSRAM writes, 9,062 register writes, PSG and YM activity, sane registers -- where MAME draws noise. Two independent emulators run this cartridge and the one that cannot is the one without the mapper, which is as close to corroboration of milestone 8's mapper work as a detector can give. **What it opens.** The board and BlastEm do *not* agree on Earthion. The board runs the game's whole VDP initialisation **twice**: frames 25 and 26 repeat frames 10 and 11 byte for byte, the full register set `0:04 1:74 2:38 3:34 ...` and then the same DMA burst. BlastEm runs it once. Best alignment over 600 frames matches only 118 of them, so this is a structural difference and not a phase one. Whether the board is re-initialising wrongly or the game reaches that path at a different moment is **not settled here**, and needs the divergence traced to its first differing write rather than its first differing frame. **Two traps, both of which produced wrong readings before they were found**, and both now recorded in the module's own docstring so the next reader does not repeat them: 1. **`EVENT_FLUSH` is not a frame marker.** It is an output-buffer flush. Its count lands near the frame count -- 599 for a 600-frame run -- which is exactly what makes it look like one. Its gaps cluster: over that run the mean gap is one frame and the **median is two**. Grouping by it produced an apparent "BlastEm runs at half the rate" that does not exist. Frames come from the cycle instead, and a cycle is **half a master clock** (~26.85 MHz), not a 68000 clock. 2. **Comparing instantaneous VDP registers says nothing here.** The board's and BlastEm's differ at registers 0, 10, 12 and 13 after 600 frames -- which are exactly the ones Earthion rewrites per raster band. That is sampling phase, not disagreement. The stream is the instrument; a snapshot is not. The parser's own correctness check is that it consumes the body exactly: 887,746 of 887,746 bytes on Overdrive 2's log and 1,226,184 of 1,226,184 on Earthion's. One wrong payload width desynchronises and either raises or stops short, so landing on the last byte is the proof. ### Item 21 chased, and closed the other way (2026-09-24) The user asked for the Earthion difference to be chased. It turned out there was no divergence to chase, and then the rate difference that was left resolved against the detector rather than against the board. **There is no divergence.** The first 9,062 VDP register writes are identical, in order, between the board and BlastEm; the board's stream is a strict superset. The "the board runs the initialisation twice" reading was an artefact of comparing by frame number: BlastEm reaches the same code later. That claim is withdrawn. **What the loop actually is.** Between two DMA triggers the game reads $C00004 three or four times and nothing else -- `0A0A`, `0A0A`, `0A0A`, `0A08`. Bit 1 is the DMA-busy bit. The game triggers a 31-word 68000-to-VRAM transfer, polls until busy clears, and triggers the next, so the loop's rate *is* the transfer's duration. **The board's duration is the Manual's, to the digit.** `scripts/run_dma_cost.py` still reproduces the whole DMA transfer capacity table -- 16.1, 167.1, 18.1, 205.1 against the Manual's 16, 167, 18, 205 -- and Earthion's own transfers take a median of **1,036 MCLK where the table predicts 1,034**, a ratio of 1.00. The blanking column is the right one: the display is disabled on all 34 of the board's triggers, and with the display disabled the blanking figure applies on every line. BlastEm takes about 2.6 times longer for the same transfers. The Manual is specification tier and outranks both emulators, so the board is right here and nothing was changed. **The contradiction with MAME was never one.** Running *behind* MAME is the accumulated cost of stalls MAME models nothing of; running *ahead* of BlastEm is one DMA rate the Manual settles. Two different measurements that were only ever in tension because both were described as "speed". **What this cost, and what it bought.** Two readings had to be thrown away -- the double initialisation, and `EVENT_FLUSH` as a frame marker -- both from comparing before checking the instrument. What survived is: an independent emulator corroborating the Extended SSF mapper, a second detector for the cartridges MAME cannot run, and one more of the board's timing rules confirmed against the specification rather than against an emulator. ### The event reader's 32-bit counter, and a heuristic thrown away (2026-09-24) Redoing Overdrive 2 on the double-buffered renderer needed a way to find a broken frame among 12,000. Two instruments were tried and one of them was already committed and wrong. **The distinct-row count does not work, and is inverted.** It was right about the *old* symptom -- a torn frame collapses to 37 rows of 224 -- and carrying it over to corruption was a mistake. Scored by how far a frame's self-difference falls at some small shift, the four frames confirmed broken by eye score 0.226, 0.395, 0.552 and 0.620, scattered across the whole range, while frame 10,100 -- a correct grey cube on black -- scores the highest of all at 0.892. A mostly-black correct scene is hugely self-similar; a dense plaid has every row distinct. Pixel statistics do not separate these two, and the approach was dropped rather than tuned. **`scripts/blastem_events.py` silently corrupted any log longer than about eighty seconds.** BlastEm's cycle counter is 32 bits, and `EVENT_ADJUST` deducts a large amount from every component at once to keep it from overflowing. Its own reader does that subtraction in `uint32` arithmetic; the parser did it in Python's unbounded integers, so the counter ran off. The 12,000-frame Overdrive 2 log carries exactly one adjust -- 4,278,391,830, taken when the raw counter had reached 4,286,955,510 -- and read without the mask the log **appears to stop at frame 4,008** instead of the 12,002 it holds. The fix separates the two clocks, which is what the format actually has: - `Reader.raw` is the counter as BlastEm holds it: 32 bits, wrapping, deducted from by an adjust. - `Event.cycle` is absolute time, which only ever advances by an event's delta. An adjust is bookkeeping against an overflow, not a moment when time moved, so it does not touch it. Three tests cover it, including a wrap that accumulates past 2^32 with real 24-bit deltas. The reader still consumes the whole body: 76,821,806 of 76,821,806 bytes on the Overdrive 2 log, now over 12,002 frames. Milestone 8's Earthion work is unaffected -- 600 frames is about twelve seconds, well before the first adjust -- so item 21 stands as measured. **The reconstruction was validated before anything was built on it.** The risk was that BlastEm logs the register writes that *trigger* a DMA but not the bytes the transfer moves, in which case a VRAM rebuilt from the log would quietly drift from the real one. Earthion settles it, because its loading is almost entirely DMA: the board's **380,340 VRAM byte writes are identical to BlastEm's, address and value, in order**, with no address transform (`^ 1` mismatches at the very first write; straight matches throughout). So the log carries the transferred bytes, the address convention is the one `_vram_write_byte` takes, and a replay of the log reconstructs VRAM faithfully. It is also a much deeper corroboration than the register streams gave. 9,062 matching register writes was suggestive; 380,340 matching VRAM writes between two independent emulators is another kind of evidence. ## Session 9 (2026-09-24): the Overdrive 2 diff, and the instrument corrected first ### How the handoff was read The handoff put the Overdrive 2 diff first and said to validate every instrument before drawing a conclusion from it. Doing that turned up three faults in the BlastEm instrument, one of which had hidden the whole target: the reference log the diff was to be built on **never reached a broken frame**. Environment: PyPy 3.11.15 (`.venv-pypy`), BlastEm at `reference/src/blastem` @ 542164d, `Overdrive 2 (World) (Revision 2017) (Aftermarket) (Unl).md` (SHA-256 `f722fc34...5611`, unpacked alone into a scratch directory), `MACHINES["megadrive"]`. ### The BlastEm clock is one master clock, and `-b N` runs N/2 frames `scripts/blastem_events.py` took a logged cycle for half a master clock. It is one: BlastEm's VDP clock, which stamps every VDP event, advances `MCLKS_LINE` = 3,420 a line ([GPL source cited, redacted]) and 16 an H40 slot. The data says the same without the source: Overdrive 2's once-a-line VSRAM writes land 3,420 apart in the log, one line, where the old reading put them two lines apart. The half-clock reading had been fitted to a second fault: **`blastem -b N` runs N/2 frames**, at least headless at this revision. The frame counter `-b` reads is bumped in two places ([GPL source cited, redacted] when a threaded renderer exists, and a second place). So the handoff's reference log, `-b 12000`, holds 6,423,581,234 master clocks, **6,001 PAL frames**, and its last register write and its last VRAM write are both the board's in frame 6,001. Frames 7,200, 8,400, 9,000 and 10,800 were never in it. `-b 24000` gives the whole demo: 65,160,157 events over **12,001 frames** (by the clock, not the argument), decoding to byte 211,063,218 of 211,063,218. The old log regenerated byte-identical first (20,545,852 events, 76,821,806 bytes), so BlastEm is deterministic here -- though not hermetic: it loads and saves a battery file under `~/.local/share/blastem//save.sram`, which is why an Earthion log regenerated this session came out 1,227,750 bytes against the 1,226,184 recorded. ### Item 21 withdrawn: the factor of two was the unit Item 21's table -- the board 300 frames and a 1,710 MCLK gap between DMA set-ups, BlastEm 599 frames and 3,608 -- is exactly this error: 599 half-frames are 300 frames and 3,608 is 1,804 doubled. Re-measured on `Earthion (World) (En) (Aftermarket) (Unl)`, `genesis`, 300 frames: both emulators run the same 31-transfer burst every other frame, one frame apart, and the median gap between set-ups (register 23 writes, below 20,000 MCLK) is **1,712 MCLK on the board and 1,804 on BlastEm**, a ratio of 1.05. The board's transfers being the Manual's (ratio 1.00) stands; it never rested on BlastEm. "BlastEm takes 2.6 times longer" and "BlastEm is the outlier" are withdrawn, in `docs/undocumented-behavior.md` item 21 and in the handoff. ### The third fault: `VRAM_BYTE_AUTO` steps by register 15 The reader stepped `VRAM_BYTE_AUTO` by a fixed 2 ("the value every log seen here uses"). BlastEm's writer and reader both step by the live [source name redacted] ([GPL source cited, redacted]), from the zero `calloc` gives. The reader now tracks register 15 from the log's own writes, with a test. Overdrive 2's log has no `VRAM_BYTE_AUTO` event at all, so nothing measured moved; it would have mattered on the next game that does. ### Two things the log cannot carry, found by reading before building - **A VRAM copy DMA is not logged** ([source name redacted], [GPL source cited, redacted]: [source name redacted] with no [source name redacted]). The board's copy bytes are flagged and left out of the comparison. Overdrive 2 copies 131,072 bytes, all in frames 11,086-11,149, after every frame examined here. - **In 128 KB mode BlastEm stores a write to an odd address**, where the board, after Kabuto, stores nothing. The instrument flags it on both sides so it is counted, not hidden. None occurred. ### The instrument: `scripts/vdp_streams.py` Records the board's four VDP write streams (register, VRAM byte, CRAM, VSRAM) in one canonical form, rebuilds the same four from a BlastEm log, and reports where each pair first parts; `replay` rebuilds the state a stream leaves at the end of any frame. The board and BlastEm store VRAM in the same byte-swapped layout (byte address `a` at index `a ^ 1`, and Kabuto's 128 KB rearrangement, which is also BlastEm's `write_vram_word`), so one index serves both. Validated before use: - **The board side rebuilds exactly.** A 7,201-frame run saved the VDP's real final state; VRAM, CRAM and VSRAM rebuilt from its streams equal it. The only registers that differ are 19 and 21, the DMA length and source counters `_dma_step` updates directly -- which BlastEm's log does not carry either, so the comparison is like for like. - **The board run is deterministic**: the 7,201-frame run's streams are an identical prefix of the 12,000-frame run's, values and positions. - **`fm.enabled = False` changes nothing the VDP sees**: 1,499 frames with the FM generator on and off give identical streams in all four kinds, values and positions. - **Alignment holds** once the clock is right: every divergence below sits at the same line within a frame or two on both sides. Commands (scratch directory `S` holding only the image): ```text blastem -b 24000 -e $S/od2-24k.bel "$S/Overdrive 2 ... .md" # 45 s .venv-pypy/bin/python scripts/vdp_streams.py blastem $S/od2-24k.bel --out $S/blastem # 10 s .venv-pypy/bin/python scripts/vdp_streams.py board "$S/Overdrive 2 ... .md" --frames 12000 --out $S/board # 344 s .venv-pypy/bin/python scripts/vdp_streams.py diff $S/board $S/blastem ``` ### What the streams say | stream | board | BlastEm | agree from the start | then | | --- | ---: | ---: | ---: | --- | | registers | 1,033,488 | 1,033,780 | 395,312 | **one episode**: the board makes two extra writes at frame 7,047 (`r15=04, r15=02`), reaching a transition a frame late; every later write matches to the end | | VSRAM | 761,855 | 761,857 | 107,740 | two small episodes at frames 5,660-5,661 (a raster effect starting one line later on the board); identical to the end after them | | VRAM | 52,642,830 | 52,665,188 | 15,165,203 | from frame 6,032, one FIFO entry at each 128 KB-mode boundary (below), then the frame-7,047 lag | | CRAM | 351,858 | 351,857 | 1,971 | from frame 548, 271,414 of the values differ while count and slots start out the same (below) | **The 128 KB-mode boundary.** Each time the demo leaves 128 KB mode the board commits the last FIFO entry as a normal-mode word where BlastEm commits it in 128 KB mode (frames 6,032-6,256); each time it enters, the board commits the second byte of the last normal-mode word in 128 KB mode where BlastEm commits both in normal mode (from 6,270). Both emulators apply a register write at once, not through the FIFO (BlastEm [GPL source cited, redacted] runs the VDP to the 68000's cycle, then applies it), so this is a slot or so of 68000-against-VDP phase, one entry per boundary. Two detectors cannot say which is right. **The CRAM values.** From frame 548 to 11,083 the two write the same number of CRAM words but mostly different values -- green levels in steps of `0x20`, which looks like a random-number effect seeded or fed differently on the two. The register and VRAM streams stay identical for thousands of frames after 548, so these values do not feed back into anything else the VDP holds. Their source is **not settled**. **Overdrive 2 does use 128 KB mode**, contrary to milestone 5's note above: the board writes register 1 with bit 7 set 12,460 times over frames 4,123-6,520, 11,124 of them as `$F4`, **with the display enabled**. What 128 KB mode does to the picture is not modelled (`vdp.py`, `_vram_write_128k`), so that section is suspect too. It is not one of the four sampled frames. ### The four broken frames: the data is right Rebuilt at the end of each broken frame and set against BlastEm's frames a few either side: | board frame | VRAM bytes differing | CRAM | VSRAM | registers | BlastEm frame | | --- | ---: | ---: | ---: | ---: | --- | | 7,200 | **0** | 0 | 0 | 0 | 7,198 | | 8,400 | **0** | 0 | 0 | 0 | 8,398 | | 9,000 | **0** | 0 | 0 | 0 | 8,998 | | 10,800 | **0** | 0 | 0 | 0 | 10,797 | At every broken frame the VDP holds, byte for byte, what BlastEm's VDP holds. The plaid is **not** wrong data in VRAM, CRAM or VSRAM. What is left, in the order to look: 1. **The debug register ($C0001C)**, which neither stream carries: milestone 5 found Overdrive 2 forcing planes through it in windows around all four frames. 2. **Mid-frame timing**: raster writes landing on other lines than on BlastEm. 3. **The renderer**, drawing the right data wrongly. ### The debug register was not it: three of the four frames were never broken The debug register was the first suspect for the four frames, since BlastEm's log cannot carry it. Recording every write Overdrive 2 makes to it on the board (25 over 11,200 frames) settled that quickly: **frame 7,200 is drawn with it at 0** -- cleared at frame 7,064 and not set again until 8,128 -- while 8,400, 9,000 and 10,800 are in the demo's "B-masked" windows (bits 8-7-6 = 110). Every write lands in the vertical blank or at the frame's edge, 56-84 MCLK behind the 68000, so the missing sync on `$C0001C` does not matter here. "Broken by eye" had no reference behind it, so one was made. BlastEm's framebuffer backend does not build and its debugger will not run headless, but the pinned tree builds unchanged as a **libretro core with its own `Makefile.libretro`**, and a libretro core hands every finished frame to its frontend. A frontend of our own (ctypes, about 100 lines: environment calls answered, SRAM kept in a scratch directory rather than `~/.local`) drew BlastEm's picture of the same 31 frames the board was asked for, aligned to within a frame or two (the Mega Drive console scene appears at 7,598-7,700 on both). - **8,400, 9,000 and 10,800 are not broken.** Their "plaid" is the B-masked effect the demo means, and the board draws it as BlastEm does. Three of the four "wrong frames" carried since milestone 5 were a judgement made without a reference. - **7,200 was broken, and it is not alone**: frames 7,066-7,598 are one scene, a fractal zoom into nested squares that changes colour as it goes. BlastEm draws it clean; the board drew the same squares chopped vertically, with bands of vertical bars at a few lines. ### The vertical scroll latch The zoom sets full-screen vertical scroll on every line (two VSRAM words a line from an H interrupt handler, values that nearly cancel the line number, so each plane row is repeated for several lines -- a vertical magnification), and on the board those writes commit 2-66 pixels into the visible line (448 commits in frame 7,200: 177 at pixel 2, 215 at 18, 47 at 34, 9 at 66). The board read VSRAM as it stood whenever it drew, so each such line was drawn half from one value and half from the next. When the chip takes the value is not in any hardware-captured source. BlastEm latches once a line at H40 slot 165 and says it is untested ([GPL source cited, redacted]); Nemesis "believe[d]" it is re-read at every mapping slot and had not tested it (forum t=1291); Eke was "pretty sure it is fetched close to HSCROLL". By the tier rule the die-derived referee judges, so it was measured on Nuked-MD: - `validation/nuked_md_headless.c` gained two instruments of our own: `NMD_PLOT`, the VDP's RGB pins sampled on every clock edge and framed by its own `/HSYNC` and `/VSYNC` (with the V counter of each row), and `NMD_VDPSIG`, a log of every change of the two VSRAM-to-scroll latches [source name redacted] (plane A) and [source name redacted] (plane B), of VSRAM words 0 and 1, and of `/HSYNC`, each with the die's H and V counters ([source name redacted], [source name redacted]). - A test cartridge (`scripts/run_vscroll_latch.py`, hand-assembled, each encoding in its comment): plane red over its top 128 rows and green below, full-screen scroll; on each line the 68000 waits (V & 63) `dbra` loops, sweeping its write across the whole line over 64 lines, then writes `(V & 1) << 7`. The value is fixed by V: a first version toggled once a line, and the board's H40 result came out almost exactly inverted because its set-up ended a line from the referee's -- a phase artefact of the instrument, caught and removed before anything was concluded. Result, planes A and B, H40 and H32: | | plane A latch | plane B latch | split lines | line v shows the latch of v - 1 | | --- | --- | --- | ---: | ---: | | H40 | $149 (640 of 640) | $143 (640 of 640) | 0 | 224 / 224 | | H32 | $109 (640 of 640) | $103 (640 of 640) | 0 | 224 / 224 | (against 37-39 of 224 for "the latch of line v"). So the scroll is latched **once a line, in the last pixels before the V counter increments**, and a VSRAM write made during a line -- including in the horizontal blank before its display, where an H interrupt handler writes -- reaches the picture only on the line after. The board now does that: `VDP.vscroll_latch` holds each plane's value, set at `_next_line` from VSRAM as it stood at the plane's latch point (`_vsram_store` keeps the old word when a write lands after it), and the renderer draws full-screen scroll from it. The 2-cell column mode, interlace mode 2 and display-off lines are **not** measured and not changed. The rule is `docs/undocumented-behavior.md` VDP item 23. Against the referee on the same cartridges, the board now splits no line and matches **222/224 (plane A, H40), 221/224 (A, H32), 206/224 (B, H40) and 201/224 (B, H32)** lines. The rest is item 20, already open: the board commits a slot's write about 4 pixels (H40) or 1 pixel (H32) before the die does (measured here per line, board H minus referee H: -4 on 135 of 187 H40 lines, -1 on 125 of 188 H32), and plane B's latch at $143 sits just after the slots at $140/$142, so a write the die places after it the board places before. **Overdrive 2's fractal zoom now matches BlastEm's picture**: the chopped rows and the bands are gone, frames 7,150-7,500 show the same squares, and the other scenes did not move. Frame 10,000 still differs from BlastEm in one blue shape at the top: open. ### What it moved, and why Checks at the latch commit: both suites (109 passed on each interpreter, before the four new tests), the sprite masking ROM (0 of 18 cells differ from the MD1600), and r57shell's eight VDP tests (identical output before and after). The whole romset was re-swept (`scripts/compat_sweep.py --seconds 10 --jobs 16 --window 12 --offsets --out tests/compat/megadrive-latch.csv`, 13,478 s, PyPy 3.11.15) and diffed row by row against the sweep before it. **10 of 3,514 rows moved**: | cartridge | before | after | | --- | --- | --- | | Batman (Europe), (Japan) (En), - The Video Game (USA) | differs 7,041 | **phase** | | Mega Turrican (USA) | differs 5,487 | **phase** | | Panorama Cotton (Japan) | differs 64,351 | **phase** | | ZPF (World) (Demo) (Aftermarket) (Unl) | differs 6,903 | **phase** | | Vectorman (USA, Europe), (Beta 1), (Beta 2) | phase 2,159 | differs 2,836 | | McDonald's Treasure Land Adventure (USA) | differs 10,647 | differs 10,682 | **Every move is the latch and nothing else**: a new sensitivity knob, `disable="vscroll_latch"` (`scripts/compat_sweep.py`, also in `triage_diffs.py`'s pass 2), hands the renderer live VSRAM again, and with it all ten rows return to their old status and pixel count exactly. The four that moved away from MAME are the pattern the referee measured. Both games write plane B's full-screen word once a line during the display -- Vectorman at H $12 (about pixel 18) on 209 of 224 lines, McDonald's at H $62/$82 (pixels 98-130, the middle of the line) -- so the board used to split those lines, and now draws each from the latch of the line before, as the die does. MAME draws a line at one moment of its own choosing and agrees with neither. MAME is a detector; nothing is changed to match it. **One of them was put to the judge directly.** Nuked-MD ran `Vectorman (USA, Europe)` for 600 frames (38 minutes; the picture taken with `NMD_PLOT`), and the board's frames 594-605 were compared with it line by line, at the best horizontal offset and colour mapping. With the latch, board frame 601 equals the referee's frame **on 224 of 224 lines**; with the live read (`disable="vscroll_latch"`), the best is 75 of 224, on the same frame and offset. So the row the sweep counts as having moved away from MAME moved onto the die: Vectorman's `differs` is MAME's. Checks after the latch: both suites **113 passed, 1 deselected** (PyPy 172 s, CPython 449 s); ruff check and format clean. | status | before | after | | --- | ---: | ---: | | `same` | 1,610 | 1,610 | | `phase` | 462 | **465** | | `differs` | 261 | **258** | **2,075 of 2,673 present cartridges, 77.6%** (from 77.5%), and **2,075 of the 2,598 on boards the emulator models, 79.9%** (from 79.8%). ## Session 10 (2026-09-25): where a mid-line write shows (item 20) ### The question Item 20 had been open since milestone 3: the board lets a mid-line change take effect from the pixel the H counter names when it lands, and Kabuto places H40's second mid-tiles slot "at the pixel with X=-3 (display area coordinates)" for palette writes, where the board put it at 18 -- a colour output running about 21 pixels behind the counter. It was also the one residual of the vertical scroll latch measurement. The referee instruments of Session 9 made it measurable. ### The measurement `scripts/run_output_delay.py`: two cartridges with both planes transparent, so the display is the backdrop; on each line the 68000 waits (V & 63) `dbra` loops, sweeping across the line, then changes the backdrop's colour by V's parity -- by writing CRAM entry 0 (`cram`), or register 7, the backdrop's index (`reg7`). The referee's picture (`NMD_PLOT`; display pixel 0 is sample 154 in H40 and 130 in H32, two samples a pixel, read off the latch test's plots) gives the pixel where each line's colour changes, and `NMD_VDPSIG` now also logs CRAM entry 0 (`C0`) with the die's H counter. - **A CRAM write committed at die H counter h shows from output pixel h - 24**, on 153 of 154 lines in H40 and 155 of 158 in H32. - The die numbers H40's slots three above the board (the board's $042 is its $045, the same "-4" seen in the latch work, which was therefore mostly labelling: the two commit within about a pixel of each other). So in the board's terms the output runs **21 pixels** behind the counter in H40 and **24** in H32, which puts H40's slot $012 at X = -3 and $002 at -19, in the blank -- exactly Kabuto's two statements. - **Register 7 behaves the same way**, shown by timing the write on the board (whose 68000 milestone 6 matched to the referee's): the change sits 21-25 pixels left of the write's pixel in H40, spread a few pixels by the 68000's polling phase. And the board had a second gap here: it read the backdrop index once, at `begin_line`, so a mid-line write never showed on its own line; the referee changes colour part way along 166 of 224. ### The change `render.OUTPUT_DELAY = {"H40": 21, "H32": 24}`. `Renderer.catch_up` takes `output=`: a change acting where the colour is looked up is drawn from that many pixels further left. `VDP._write_register` passes it for register 7, and `VDP._slot` when the slot commits to CRAM (a FIFO write or a fill). The renderer now reads register 7 as it stands when it draws. Changes that act where tiles are fetched -- VRAM, the plane and scroll registers -- are **not** delayed: the fetch runs ahead of the output by an amount not measured here, and they stay at the H counter's pixel. The rule is `docs/undocumented-behavior.md` VDP item 20, rewritten. After it, referee minus board per line (`scripts/run_output_delay.py`): | | CRAM | register 7 | | --- | --- | --- | | H40 | 0 on 102 of 151 lines, the rest whole slots (+-16, +-32) | centred on 0 (mode -2), spread -7..+7 by polling phase | | H32 | 0 on 114 of 152, the rest whole slots | spread -7..+16, centred near 0 | The whole-slot spread is the 68000 reaching the write a slot earlier or later on some lines in one run than in the other (the board's frame 12 against the referee's 11th); before the change the CRAM mode was -21 and -24. One test pinned the old rule: `test_a_cram_write_in_the_display_leaves_a_dot` expected the dot at its slot's pixel (118-135 for a write at pixel 120); it now expects it 21 further left (97-114). ### What it moved Checks: the sprite masking ROM (0 of 18 cells differ), r57shell's eight tests (identical output), both suites (below). Re-swept (`--seconds 10 --jobs 16 --window 12 --offsets --out tests/compat/megadrive-delay.csv`, 14,444 s) and diffed against the post-latch sweep: **2 of 3,514 rows moved, and no status changed** -- `George Foreman's KO Boxing (Europe)` differs 44 -> 48 pixels, `Satyr in Hell, A (World) (Digital) (Aftermarket) (Unl)` 302 -> 320. Both are the delay and nothing else: a new knob, `disable="output_delay"` (`compat_sweep.py`, and in `triage_diffs.py`'s pass 2), puts the delay back to 0, and both return to 44 and 302. Their extra pixels are CRAM changes now shown where the die shows them; MAME is a detector and nothing is changed to match it. The totals are the post-latch sweep's: 2,075 of 2,673, 77.6%; 79.9% on the boards modelled. Overdrive 2: frames 9,000 and 10,000 are unchanged pixel for pixel (so 10,000's one blue shape against BlastEm is something else, still open); frame 9,500, the sphere, changes in 180 pixels, all in its left quarter, where its mid-line CRAM dots now land. Both suites after it: **113 passed, 1 deselected** (PyPy 183 s, CPython 450 s); ruff check and format clean. ### The 2-cell column latch Item 23 had left 2-cell column scroll unmeasured, and the board still read each column's word as it stood whenever it drew -- so it split columns the way it had split full-screen lines. It is also where tile fetching's lead over the output (the half of item 20 left open) shows first. `scripts/run_vscroll_columns.py`: a cartridge like the latch one, with 2-cell column scroll, every VSRAM word 0, and each line's write aimed at **one** column's word. Because only that word ever changes, the die's column-scroll latch [source name redacted] takes 128 exactly when it latches that column, so the log names the moment, and the picture says which value each line used. `NMD_VSRAM_WATCH` makes the log watch any one VSRAM word. | plane, mode | die H of column k's latch | columns measured | line v shows counter line v's latch | | --- | --- | --- | ---: | | A, H40 | 16k + 1 | 0, 10, 19 | 224 / 224 each | | B, H40 | 16k + 9 | 0, 10 | 224 / 224 each | | A, H32 | 16k + 1 | 0, 8, 15 | 224 / 224 each | | B, H32 | 16k + 9 | 8 | 224 / 224 | So each column is latched during its own line, 16 pixels after the one before, and the referee never splits a column. A first check of the rule from write positions missed the same lines for every column; it was the check that was wrong (the most common write position over three frames, and H values compared without the counter's wrap), and reading the latched value straight from [source name redacted] line by line gave 224/224. The board now keeps, word by word, what a column's word held when a write landed after that column's latch in the current line (`VDP._column_before`, cleared at `_next_line`), and draws 2-cell columns from `VDP.column_scroll`. The latch points, in the board's counter (the die's H40 counts three above it), are `VSCROLL_COLUMN_H`: plane A 16k - 2 and plane B 16k + 6 in H40, 16k + 1 and 16k + 9 in H32. That alone left plane B splitting (7 lines in H40, 20 in H32): its latch falls 6 or 9 pixels *into* the column, after the board has begun drawing it, while the die outputs the column about 21 pixels later (item 20), after the latch. So a slot committing a 2-cell VSRAM write before its column's latch now holds the drawing at that column's first pixel (`VDP._column_limit`, `catch_up(limit=)`), and the whole column takes the value the latch will. | board against referee, lines matching / split | before | after | | --- | --- | --- | | A H40 column 0 | 207 / 0 | 222 / 0 | | A H40 column 10 | 216 / 7 | 223 / 0 | | A H40 column 19 | 219 / 0 | 219 / 0 | | B H40 column 10 | 216 / 7 | 223 / 0 | | A H32 column 8 | 202 / 20 | 222 / 0 | | B H32 column 8 | 201 / 20 | 220 / 0 | (The remaining lines are the 68000's polling phase, a slot either way, as before.) Checks: sprite masking 0 of 18, r57shell identical, `scripts/run_vscroll_columns.py` passing on all nine cases (board 218-224 of 224 lines, no split), both suites **116 passed, 1 deselected** (the three new column tests; PyPy 178 s, CPython 460 s). **The re-sweep moved nothing**: `--seconds 10 --jobs 16 --window 12 --offsets --out tests/compat/megadrive-2cell.csv`, 14,719 s, 0 of 3,514 rows different from the sweep before it, in status or in pixel count. The romset's 2-cell games do not, at the frame the sweep compares, write a column's word in the window the two rules disagree on. The triage knob is there for when one does: `disable="column_latch"` reads each column's word as it stands again and never holds the drawing back. ### Frame 10,000, and where a tile write shows Overdrive 2's frame 10,000 still differs from BlastEm in one place: the darker region at the top right of the upper shape. The VDP data is not it -- VRAM, CRAM, VSRAM and the registers at the end of board frames 9,998-10,004 equal BlastEm's two frames earlier (`vdp_streams.py` replay) -- and nor is frame phase: BlastEm's 10,000 is the board's 10,003-10,004 in geometry, and none of the board's frames 9,996-10,004 has the region. (Pixel counts against BlastEm are no guide here: its libretro frame is 320x240 with borders, five lines above the board's, and its colour levels are not the board's.) Two leads, one ruled out: - The scene rewrites tile 0's first row about 870 times a frame **during the display** (bytes $02-$05, every line), so which columns see which row depends on where each column's tiles are fetched relative to the write -- the half of item 20 left open. `scripts/run_output_delay.py` now measures it (`vram`: plane A one tile everywhere, each line rewriting the row it shows): in **H40 the board already lands on the referee's pixel** (60 of 79 lines, the rest a slot either way) and in **H32 it is 8 pixels late** (53 of 77). The scene is H40, so this is not the cause. The H32 offset is recorded in item 20, open; name-table writes are not measured. - The scene has **shadow/highlight on** (register 12 = $89). The missing region is darker, as a shadow would be. That is the lead left: how the board decides shadow there, not what it is given. BlastEm is a detector; the judge would be Nuked-MD running the demo to frame 10,000, about eight hours at 0.33 frames a second. Open. ## Session 11 (2026-09-26): where tiles are fetched -- measured as far as slots allow ### The die run Overdrive 2 is running on Nuked-MD to frame 10,006 (PAL, about eight and a half hours), to judge the region frame 10,000 lacks against BlastEm. Nuked-MD handles the Sega mapper up to 8 MB ([GPL source cited, redacted]), which the demo's 8,386,056 bytes fit. `NMD_PLOT_FRAMES` now plots that many consecutive frames from `NMD_PLOT_FRAME`, one file each (`.`), so a frame or two of phase between the board and the referee costs nothing; it is plotting 9,995-10,006. Checked first on the latch cartridge (frames 11 and 12, full line structure in both). ### Name-table writes Session 10 left the H32 pattern-row offset (-8) open because names are fetched at a different point from patterns. The name test: plane A tile 1 everywhere; each line rewrites **one cell's name** (column c of the cell row the line shows) to tile 1 or 2 by V's parity, at the sweeping delay; per line, did the cell show the name written on that line. Writes land only in access slots, so the result is a switch point between two slots, per column; columns 16-23 in H40 and 12-19 in H32 were run to move the column across fixed slots. **In every column, in both modes, the die stops taking the new name one slot earlier than the board does** -- names are fetched well before the board draws them, even in H40, where pattern writes land on the board's pixel. So no single offset per mode is right for all VRAM writes: names lead, patterns lead by nothing in H40 and trail by 8 pixels in H32. What slots cannot give is the exact fetch point: the windows they leave (up to 32 pixels wide across the refresh gap between $0A2 and $0C2) do not line up into one fetch time per 2-cell group, which means the inference is too coarse, not that the hardware is irregular. **Not modelled, and not fitted**: a lead read off these windows would be a fit. The way to an exact answer is to log the die's VRAM reads -- address and H counter -- which `vram.c` does not expose; our driver would rebuild them from the VDP's VRAM pins (`o_vram_ras`, `_cas`, `_oe1`, `_ad`, and the serial port's `_sc`/`_se0`), and the fix it points to is a renderer that fetches a column's tiles at their fetch time and outputs them 21 (or 24) pixels behind the counter, instead of doing both at the one moment it draws. ### Where tiles are fetched (the user chose to do both steps) **Step 1: the die's own VRAM accesses.** `NMD_VRAMSIG` (our driver) rebuilds every VRAM access from the VDP's DRAM pins by the ordinary protocol -- the row on /RAS falling, the column on /CAS falling, a random read where /OE is low outside a transfer, a transfer cycle where /OE is low as /RAS falls (its start column arrives with /CAS), serial shifts on SC rising, and each write's bank (/WE0 or /WE1) and data -- and logs the raw chip address with the die's H and V. The plane fetches go through the **serial port**: one transfer cycle, then four shifts, per pattern row and per name pair. The chip address maps to VRAM as `(a & 3) | ((a >> 6) & 0x3FC) | ((a & 0xFC) << 8)`, and that was checked, not assumed: on the name cartridge every access of line 100 lands where its layout says -- plane A's name row 12 at $C600 and on, plane B's at $E600, tile 1's row 4 at $0030, tile 0's at $0010, the sprite table at $F000, the scroll table at $FC00, and plane A's and B's column -1 at $C67C and $E67C. The schedule, identical in H40 and H32 in the die's counter (group g, 16 pixels): | fetch | die H | | --- | --- | | plane A name pair | 16g + 3 | | plane A pattern rows | 16g + 7, 16g + 9 | | plane B name pair | 16g + 11 | | plane B pattern rows | 16g + 15, 16g + 17 | | group -1 (fine scroll) | in the blank: $1F3, $1F7/$1F9, $1FB, $1FF/$001 | | horizontal scroll entry | $1E9 | **Two wrong turns on the way, both caught by the instrument:** - **Byte order.** The name test had left a slot's disagreement in some columns, and a word's two bytes going in over two slots looked like the cause; the die's writes (`$CDA0` then `$CDA1`) seemed to say the board wrote them in the wrong order, and the board was changed. That made the other columns wrong. Logging each write's bank and data showed the die writes the tile index (1 or 2) **first**: its chip index is the board's store index with bit 0 flipped, and the board's order was right. The change was reverted. - **Pattern writes read as name writes.** After the renderer change, the tile-row test got worse (-16 in both modes). A trace of one line showed pattern writes flagged `names=True`: the name-table check counted the window's table, and the cartridge never sets register 3, so a window base of $0000 made the patterns at the bottom of VRAM look like names. The window's table now counts only on a line that shows the window. **Step 2: a renderer in two stages.** `render.FETCH_AT` holds the schedule in the board's pixel time (the die's less three in H40): plane A (0, 4, 6) and plane B (8, 12, 14) from each group's start in H40, three later in H32. Each line keeps a fetch pointer per plane; `catch_up(names=)` first fetches every cell whose fetch time has come (with `names`, every cell whose name has), then mixes to the H counter's pixel less `OUTPUT_DELAY`, for *every* change -- so the special `output` flag is gone, and with it a latent gap: an earlier catch-up could mix past where a CRAM change should still have shown. Group g sits at screen pixel 16g plus the plane's fine scroll. `VDP._in_name_table` decides `names` for a VRAM write; register writes pass it for the plane registers (2, 3, 4, 11, 12, 16, 17, 18). **What it measures now**, against the die: - Name writes, eight columns across both modes: the board's picture differs from the die's on 3-8 lines a column, and **every such line is one where the 68000's write reached a different access slot** on the two (the same slot on 116-145 lines a column, with no disagreement among them). What is left is the 68000 and FIFO's timing, not the fetch. - A tile-pattern row written mid-line: the board lands on the die's pixel on 60 of 79 lines in H40 and **53 of 77 in H32, which was 8 pixels late**; the rest whole slots, as above. - CRAM, register 7, both latch measurements and the column latches: unchanged. A first attempt to check the die against itself -- predicting its picture from its own log -- agreed on only 150-158 of 198 lines, because the log and the picture are framed by different counters and cannot be matched line for line; it is not a result either way, and the board-against-die comparison does not depend on it. Checks: sprite masking 0 of 18, r57shell identical, both suites **120 passed, 1 deselected** (the four new fetch-schedule tests; PyPy 165 s, CPython 461 s), ruff clean. `scripts/run_fetch_schedule.py` passes: no access of line 100 off the layout in either mode, the schedule above, and in all eight columns every board-die difference a commit-slot difference. Its first run failed its own layout check on three accesses, which were transfers of tile 2's row for the one cell the cartridge renames -- the check, not the log, was wrong, and was widened to tile 2. Also seen and not explained: once a group the die reads a plane A name through the **random** port, three counts after that name's serial transfer (16g + 6). It is not the fetch the picture is drawn from: were it, writes committed at the board's slot 16g + 2 would show the new name on the die and the old on the board, and none of the disagreements above is of that kind. **The re-sweep moved nothing**: `--seconds 10 --jobs 15 --window 12 --offsets --out tests/compat/megadrive-fetch.csv` (15 jobs, the die run holding the 16th process), 13,357 s, 0 of 3,514 rows different from the sweep before it. The knob for when one does: `disable="fetch_schedule"` fetches every cell as the screen reaches it again. ### The Overdrive 2 die run: the demo does not get past its first frame on Nuked-MD The run to frame 10,006 (PAL, 11 h 8 m) finished, and every sample of all twelve captured frames is black. The capture is not at fault: the latch cartridge under `-pal` draws its red and green through the same code. A boot check (frames 298-300) is black too, where the board shows the demo's opening Pong scene. Nuked-MD's own 68000 bus trace says why: from frame 2 to at least frame 10 the demo sits in $2F021C btst #3,$C00005 ; the VDP status's VBlank flag $2F0224 bne.s $2F021C ; loop while it is set and the flag never clears there. The board reaches the same loop in frame 1, in the vertical blank (V 230) with the display on (register 1 = $54), and leaves it when the blank ends (V 511). The die's picture also has an odd V count (293 rows under 224), so its VDP is not in the state the demo set up: something earlier in the demo's start-up went another way on the die -- something it detects, a register write that did not take, or a gap in the model or in this build's configuration (`-DTMSS_ENABLE=0`, a pre-TMSS board the README says no retail console was). **Not chased**: that is debugging the referee's run of the demo, not the board, and it was stopped here to ask. Two unit traps met on the way, the second new: the driver's `frame N` progress line counts 1,789,772 half-master-clocks ([GPL source cited, redacted]) -- an NTSC-sized unit even under `-pal` -- so "frame 10,478" was PAL frame 8,759, and the run's real pace was 0.24 PAL frames a second, not the 0.33 first estimated. So frame 10,000's missing region (the scene has shadow/highlight on) stays open, with the die unable to judge it until the demo runs on it. ## Session 12 (2026-09-27): milestone 9, the desktop frontend ### What the brief asks, and how it was read "A desktop frontend, after sms-python's (audio-paced, vsync, pads)", with pygame-ce as an optional extra and sms-python's design copied, not imported. There is no acceptance number; full speed on PyPy "is a goal to measure, not a promise". ### What was built `src/megadrive_python/frontend.py`, from sms-python's `frontend.py` (same author, MIT): pure conversions tested without pygame; a SCALED window presented at the display's refresh; SDL's audio thread draining a queue that paces the console a frame at a time; keyboard and game controllers through SDL; Tab fast-forward, F3 pause, F5 power cycle, F11 fullscreen, F12 screenshot. What is the Mega Drive's own: - **Pads**: the 3- and 6-button pads' bit masks, the keyboard's Z X C / A S D rows for A B C / X Y Z and Q for Mode, and a controller's face buttons laid out as the Mega Drive's own row (A B C as X A B, X Y Z on the shoulders and Y). - **The machine** from the header's "Country in which the product can be released" at $1F0, "Japan: J, USA: U, Europe: E" (the Manual, PDF page 130): the NTSC Genesis if it names the USA, the PAL Mega Drive if Europe only, the Japanese one if Japan only, the Genesis otherwise; `--machine` overrides it. - **Sound** is the board's own mix (`System.take_audio`, FM and PSG through the audio path at 44,100 Hz), so the frontend only packs it for SDL. - **Battery RAM** (`--save`) read at power-on and written at exit and at F5, and **TMSS** (`--tmss-rom`), as the command line has them. - The first frame after power-on can be empty -- the renderer hands out finished frames only -- so a black one stands in until one has finished. Not built: the console's reset button. The Mega Drive's resets the 68000 without a power cycle, and the board has no path for it yet; F5 power-cycles. ### Speed, measured PyPy 3.11.15, a shared machine (load average 4-8 of 32 cores during these), so lower bounds: | cartridge | FM on | FM off | FM off, one frame in 3 drawn | | --- | ---: | ---: | ---: | | Sonic The Hedgehog (USA, Europe) | 16.7-17.3 | 39.8-41.4 | 56.4 | | Streets of Rage 2 (USA) | 21.3 | 55.5 | -- | | Gunstar Heroes (USA) | 16.4-19.3 | 37.3-39.8 | 53.6 | The YM2612 is about two-thirds of a frame's time with it on; skipping frames does nothing for that (17-21 frames a second whatever is drawn). So the frontend degrades rather than pretends: paced by the audio queue while the board keeps up, flat out when it does not, with the console's speed as a percentage in the title bar; `--no-fm` turns the FM generator off (its registers, timers and BUSY still run, so a game behaves the same) and `--skip N` draws one frame in N + 1. Real time with sound needs the FM generator faster -- milestone 4 left flattening its seventeen stages for a session that can re-run all eighteen of its referee streams afterwards. The README had said the board runs "138 to 205 [frames a second] without" sound; that was milestone 4's "silent" column, a board with no sound chips at all, before the per-slot renderer and the timing work. It now gives today's measurement and its basis. ### Checks `tests/test_frontend.py`: the conversions, the sound buffer, the header's country codes, a key for every pad button, and the real window loop run headless under SDL's dummy drivers on a cartridge that loops (skipped where pygame-ce is not installed, as in CI). A run on Sonic under the dummy drivers, three ways: 90 frames drawn in 4.5 s with the FM, 2.1 s without, and 180 console frames in 4.4 s drawing one in two; screenshots written. Both suites **126 passed, 1 deselected** (PyPy 189 s, CPython 456 s), ruff clean. Two warnings in the headless test: SDL's dummy driver has "no fast renderer", and pygame-ce 2.5 deprecates `Window.from_display_module`, which sizes the window here as it does in sms-python; its replacement is the whole `Window` API, which asks for vsync differently, and that move is left for both frontends together. ### The reset button Asked after milestone 9: is the 68000 core missing a lifecycle event? No. m68000-python's `reset()` is the reset exception (UM 6.3.1), callable between any two steps, and since `1f43e0b` (after this board's pin, `51ee1a5`) a fault during it halts the processor as a double bus fault -- which is also the answer to `polish.md`'s last decision row, the odd initial PC, when the pin moves. The missing piece was the board's. What the button does, from hardware (forum t=1262, pinned): Charles MacDonald measured the reset signals -- VRES# "to 68000 and cartridge connector", SRES# (the VDP, the I/O chip, the 315-5364) "only asserted on a cold boot" -- and Eke, against the 68000's clock, that "when RESET button is pressed, !ZRES is held low at the same time as !VRES and !HALT on 68k side... but remains low after that until software enables it again. 68k RESET pulse is asserted for 128 VCLK". `System.press_reset()`: ZRES asserted at once through the same path an $A11200 write takes (now `Board.set_z80_reset`), and at the 68000's next step 128 of its clocks held in reset with the rest of the machine running, then the reset exception; the VDP, the I/O chip and the cartridge are left alone. The frontend's Backspace presses it. `tests/test_reset_button.py`: the 68000 boots again and work RAM keeps its count; ZRES is held from the press until the game's own $A11200 write; the VDP keeps its registers; the pulse costs 128 + 42 clocks; a halted 68000 comes back. On Sonic, a press at frame 400 goes back to the SEGA logo, and the game releases the Z80 itself. Both suites **131 passed, 1 deselected** (PyPy 186 s, CPython 456 s), ruff clean. ## Session 13 (2026-09-27): the rain Aubrey, watching Overdrive 2 through the new frontend: the first rain scene draws its city and mountains correctly and **no rain at all**, and older emulators showed it the same way. ### What the rain is BlastEm's libretro core (the Session 9 reference, unmodified) draws the scene at frames 4,150-5,100 with rain; the board does not. A colour census of frame 4,600 says what kind of thing is missing: BlastEm's frame has 70 colours, the board's 26, and mapped level by level onto the board's picture BlastEm's extra pixels are the board's own colours **shadowed and highlighted** -- 1,223 and 1,359 of a sample of 8,025, streaked diagonally over the whole screen. Highlight needs a sprite, so the rain is sprites. The table (base $0000, H40, shadow/highlight on) holds exactly that: a 10 x 7 grid of 32x32 sprites in palette 3 (colours 14 and 15 of palette 3 are the highlight and shadow operators), 70 of them, 40 tiles a line -- H40's whole budget. The board's sprite cache ended its chain at sprite 0 (Y 0, link 0), so no sprite was ever examined. ### The first guess was wrong, and was tested before anything was built on it The scene uses 128 KB mode in the vertical blank for byte-wide uploads of the rain's pattern columns, and Kabuto warns about 128 KB mode and the sprite cache ("even though the high byte is discarded it'll still get written to the cache"). The board's 128 KB path fed the cache only the low byte at the rearranged address, where BlastEm checks the address as written and stores both bytes. Patched in BlastEm's way, from a snapshot and then from power-on: **still no rain**. Kept as a question, not a fix. ### What the demo does Logging every write to the table's first 2 KB from frame 4,000: at 4,117 the demo writes the chain properly (sprite 0 at Y 128 linking to 1, and so on); from 4,123, every frame, in the vertical blank and in **64 KB mode**, it writes zeros over the Y and size/link words of sprites 0, 4, 8, ... 76. On the board that broke the cache's chain at sprite 0. BlastEm's cache rebuilt from its event log broke the same way -- yet BlastEm draws the rain. The instrument was the suspect, so BlastEm's real cache was read instead: its libretro core's `retro_serialize` writes `sat_cache` right after VRAM, CRAM and VSRAM ([source name redacted], [GPL source cited, redacted]), and the 320 bytes were found by their contents and cross-checked against the registers that follow them. Frame by frame, 4,110-4,130: VRAM's sprite 0 goes to zeros at 4,124 and **the cache keeps Y 128, link 1 throughout**. A throwaway instrumented copy of the libretro core, in the scratch directory and never used as a reference, printed every cache check and every VRAM byte write to the first 16 bytes: after 4,117 BlastEm never checks the cache for those writes, because they are addressed to **$10000-$10003**. The log had shown them at $0000 because [source name redacted] takes a `uint16_t` address ([GPL source cited, redacted]) -- a third thing the log cannot carry, now in `scripts/vdp_streams.py`'s docstring. ### The rule Kabuto, "Precise details of sprite rendering": the cache check "is sensitive to the entire 128 KB address range even in 64 KB mode, so when setting bit 16 for the sprite table address but not for the Write/DMA target address (or the other way round) the sprite table in memory will get updated but the cache won't". The demo is his; the rain is that sentence used on purpose. Nuked-MD has the register the sentence needs: [source name redacted] takes the second control word's [source name redacted] into bits 16-14 in mode 5 ([GPL source cited, redacted]) and increments [source name redacted]; the first word leaves bits 16-14 alone. BlastEm keeps the same three bits. Exodus keeps 16, and the board's port logic came from Exodus, so the board kept 16: bit 2 of the second word was dropped and the increment wrapped at 64 KB. `vdp.py`: `ADDRESS_MASK = 0x1FFFF` for the command address, its increments, the FIFO entries and fills; the second control word takes bits 2-0 in mode 5 (still 1-0 in mode 4, which the die clears and the board does not model further); VRAM is still indexed modulo 64 KB, and `sprite_cache_write` already compared 17 bits. Nothing else changed. `tests/test_sprite_cache.py`: a write through $10000 changes VRAM and not the cache, and the increment carries into bit 16 and wraps at 128 KB -- both fail on the code before. ### Result Against BlastEm, best of its frames n-4..n+4, its levels mapped onto the board's ramp (its 27/49/71/103/119/146/157/174/190 are the board's 29/52/70/101/116/144/158/172/187): | frames (every 25th) | before | after | | --- | --- | --- | | 4,150-5,075, the rain | 25,057-67,095 of 71,680 pixels | **71,680 of 71,680, every frame** (BlastEm frame n - 1) | | 4,100-4,125 and 5,100-6,500 | not scored | identical except 1-4 pixels in 5,675, 5,825, 5,950, 6,525 | | 6,550-6,600, the logo over rings | not scored | 53,033-53,226: the board has no blue rings | The last two rows are unchanged from the code before (same seven frames rendered from `HEAD`, identical pixel for pixel) and are not this fault. The 128 KB question makes no difference to the demo: the two cache rules give identical pictures in all 101 sampled frames, 4,100-6,600, so the board keeps its rule and the question is written up as unsettled (docs/undocumented-behavior.md, VDP item 24). ### Checks Triage knob `disable="address_16"` (`scripts/compat_sweep.py`, and in `triage_diffs.py`'s list): bit 16 dropped as the command word is taken and the increments wrapped at 64 KB. Checked faithful before use: under it both new tests fail as they did on the code before, and Overdrive 2's frame 4,600 is identical pixel for pixel to the old code's (no rain). Both suites **133 passed, 1 deselected** (PyPy 197 s, CPython 461 s), ruff clean. The romset re-sweep is running at this commit and is reported below when it finishes. ### The re-sweep for the address `scripts/compat_sweep.py --seconds 10 --jobs 16 --window 12 --offsets`, 17,115 s: **0 of 3,514 rows moved** against the sweep before it. The 17-bit address changes no other cartridge's picture at ten seconds. ### The whole demo against BlastEm Every 25th frame of 12,000, each against the best of BlastEm's frames n-4..n+4 (`score.py`, its levels mapped onto the board's ramp), then a frame at a time where a scene was off. What was found, in the order it was found; each fix is a rule of its own with a triage knob, checked to put the old pictures back exactly. **The rings (6,540-7,060).** The scene forces the sprite plane on through the debug register (bits 8-7 = 01), and the board drew black where BlastEm drew blue and magenta rings: palette entry 0 of palettes 1 and 2. Both emulators' CRAM and debug register were the same (BlastEm's read from a save state), so the difference was the sprite line buffer: Kabuto's holds colour, palette and priority and lets a transparent pixel leave its palette, the board's kept opaque pixels only. That took the scene from 73-75% to 99.7%; the rest was one line, the last. The demo points register 5 at another table in the blank before line 223, after the hardware has read that line's sprites (phase 2, "1 raster line before"); the board read them as the line began, from the moved table (X 383, garbage names), and drew none. Phases 1 and 2 now run when the line before begins. VDP item 25; knobs `sprite_transparent`, `sprite_scan`. **The shadow scene (9,750-10,125; Aubrey's "gray box missing a kind of gray").** Wherever the two differed, the board had a colour at its shadow level and BlastEm at normal: plane B showing through transparent pixels of high-priority plane A tiles, and the board dropped a transparent pixel's priority, so both planes looked low. Kabuto: shadow "depends on plane tile priority, even when all plane tile pixels are transparent". `_tile_row` now keeps palette and priority on every pixel; all 16 sampled frames went from 0-95% to identical. VDP item 26; knob `plane_transparent`. **Left alone: 9,225-9,725, 150-190 pixels a frame.** One CRAM write every fourth line (3, 7, 11, ...), exactly the rows that differ, about 3 pixels a row: where a mid-line colour change starts. The board's place for that was measured on Nuked-MD (item 20); by the tier rule the die outranks BlastEm, so the board keeps it. **The arcade (12,154-12,960; Aubrey saw it stop advancing).** Not a hang: the board fell behind from 12,200, by 330 frames at 13,300, and drew black bands and missing monitors. A profile of one frame put 87% of the 68000's time in `tst.w $FF079A / beq` at $39FBE4: the main loop waits for a flag the last of a chain of H interrupt handlers (vector $FF069A, each loading the next and the next register 10 value) sets. The board's own register log gave the reason: $7C (V30) at line 207 and $74 (V28) at 225, every frame, which is Kabuto's border trick. The board latched V28/V30 at the blanking line, so the border started anyway and the H interrupt counter was reloaded through it; the chain fell out of step and the loop ran every 1.4 frames. The border is now tested against the live mode (VDP item 27). The demo keeps pace (2-6 frames of BlastEm, as everywhere else) and all 32 sampled frames of the scene, 240 lines each, equal BlastEm's (rows 0-231 against its 8-239: its libretro frame keeps an 8-line top border even with the border open). Two wrong turns. Making V28/V30 live everywhere, the counter's jump included, and the HV captures test failed in 26 dumps -- but the cause was `run_hv_captures.py`, which places the VDP at a fitted line and did not set the new `border`; with that set, they are unchanged to the word. The counter's sequence was put back on the latched mode anyway, since only the border has a source, and a sentence claiming the captures ruled the live jump out was caught before it was committed: the live jump was never run with the harness fixed. And `pkill -f` / a `grep` over process command lines killed their own shell twice (the trap memory already names): kill by the process's own PID. ### Aubrey's other questions - **"Crashed around 4:11"**: the board runs to 13,500 without an exception, FM off, and FM on gives the same frames through the arcade intro (11,500-12,400). What was seen was the arcade's lag. - **The very first second**: frames 3-14 flash grey and black, six times, on both emulators -- the demo's own. The board's run is one frame behind BlastEm's there (grey on 4, 6, ... 14 against 3, 5, ... 13), the same frame of offset as through the whole demo; every frame from 15 on is identical after that offset. - **The pong screen's static**: seeded from memory nothing initialised. Filling work RAM and Z80 RAM with $FF or random bytes changes exactly the static frames (550-575, 785-810, 1,135-1,160) and nothing else in the first 1,200. Both emulators zero RAM and still differ, so something else nothing initialised feeds it too (the CPU registers at reset are one candidate); on a console it differs at every power-on, so there is no picture to match. Session 9's "CRAM values differ from frame 548" (to 11,083) is probably the same source, but only the first 1,200 frames were tested here; the pictures after them match, so those values do not show. ### The frontend's frame counter The title bar now carries `frame N (m:ss)`: the VDP's count since power-on (a reset leaves it), which is the number every tool here calls a frame, and the emulated time at the machine's rate. `tests/test_frontend.py` checks the format. ### Checks `tests/test_sprite_line_buffer.py`: five tests, four of which fail on the code before (the fifth, V28's border at line 224, holds on both). Both suites **140 passed, 1 deselected** (PyPy 211 s, CPython 481 s), ruff clean; the HV captures equal their baseline in every dump. ### The tools, for anyone chasing the rest The method of this session is now in the repository, each checked to reproduce the scratch work it came from (same pictures to the pixel, same scores): ```text sh validation/build_blastem_libretro.sh # the pinned BlastEm, unchanged, as a libretro core python scripts/blastem_frames.py reference/build-blastem-libretro/blastem_libretro.so ROM OUT_B --range 7600:9200:25 [--states] python scripts/board_frames.py ROM OUT_M --range 7600:9200:25 python scripts/compare_frames.py OUT_M OUT_B --pairs # best of BlastEm's n-6..n+6, levels and border put right ``` `--pairs` says what kind of fault a frame has: k against 2k is a shade fault (shadow against normal), matched pairs both ways a picture partly a frame out of step. For BlastEm's frames around each board frame, ask for n-6..n+6 (`--frames`). BlastEm's own VDP state at a frame comes from `--states` ([source name redacted]: VRAM, CRAM, VSRAM, sprite cache, registers); its event log cannot carry bit 16 of a VRAM address or a copy DMA (`scripts/vdp_streams.py`). What is open in Overdrive 2 at the end of this session, every 25th frame to 13,500 (477 of 540 identical): | frames | what | where it stands | | --- | --- | --- | | 550-1,150 (4) | the pong screen's static | uninitialised memory; nothing to match | | 5,675-6,525 (4) | 1-4 pixels each | not looked at | | 7,700-8,075 (7) | parts of the picture a frame out of step (grid scroll against objects) | pacing, not drawing (below) | | 8,150-9,125 (25) | 16-517 pixels, the B-masked debug-register scenes | not started | | 9,175-9,725 (23) | where a mid-line CRAM change starts | kept: die-measured (item 20) | ### 7,650-7,760: the 3D console is paced differently, not drawn differently Every frame of 7,650-8,100 was scored on both (`compare_frames.py`): the frames that differ come about every fourth frame (7,666, 7,670, 7,674, ...), about 6,500 pixels each, with the frames between identical. In a differing frame the rows above and below the rotating 3D Mega Drive are BlastEm's frame n - 2, as everywhere in this stretch, and the object's rows match none of BlastEm's frames: the grid comes from one frame and the object from another. The object is rendered in software by the 68000 and swapped in when an image is done, a new image every 3-5 frames. Labelling each frame by the object's own pixels (the grey ones) on both: | images | 1-3 | 4-10 | 11-20 | 21-25 | 26-27 | | --- | --- | --- | --- | --- | --- | | board's first frame after BlastEm's | 2 | 3 | 4 | 3 | 2 | against a constant 2 for the grid, and both emulators take 106 frames for images 0 to 26. So the board renders the object at BlastEm's average rate and only the phase of the image swaps drifts, by up to two frames and back: an image that finishes close to a frame's end lands on the other side of it. That is a sub-frame difference in how much 68000 time a frame gives (bus stalls: the work-RAM refresh rule is the open item most likely to move it), and there is no judge for it here -- BlastEm's 68000 timing is an approximation, and Nuked-MD cannot run Overdrive 2 to frame 7,650 (it does not get past its first frame, and at 0.24 fps would take nine hours). Left open; not worth changing the board to follow a detector. **7,930-8,090, the same, bigger.** Labelled the same way (the grey pixels of the console and the TITAN sign), 50 of the board's 51 object images are BlastEm's images exactly (the 51st is one transitional frame at 8,088), but the board falls behind BlastEm by 4, 3, 5, 8 and 4 frames at images 1, 10, 20, 30 and 40: images 19-30 take it 48 frames against BlastEm's 45, some 6% less 68000 work a frame in this stretch, and it catches up at the scene's end. Still pacing, not drawing, but a throughput difference rather than a phase: what takes the 68000's time here (refresh stalls, DMA contention) is modelled differently on the two, and BlastEm is not a judge of it. Open, with the same lack of a judge; a cycle profile of one image on each side would be the next step if it is taken up. ### Overdrive 2 on Nuked-MD: a reset after the first run Session 11 found the demo stops on the referee after its first frame. Nuked-MD's own notes say why: "The Overdrive 2 demo has an issue loading Z80 microcode and requires pressing Reset after the first run (behavior is similar on real hardware)". The driver gained `NMD_RESET=:`, which holds the console's reset button as Nuked-MD's frontend does ([source name redacted] and the arbiter's [source name redacted] low, [GPL source cited, redacted] F12). Traced (68000 bus cycles, PAL): with no reset the 68000 waits at $2F0240 until about frame 15, moves on, and by frame 15-19 makes no bus cycle at all (the last are reads of a table at $398A34 and the VDP status) -- the first run's freeze. A press at frames 4-9, before it, changes nothing. A press at frames 25-30, after it, is a real reset (the reset vector is read at frame 25), and the demo then starts again and keeps running: the 68000 is still busy at frame 100, and the captured pictures from frame 60 show the opening -- the ship fading in through its green, cyan, yellow and grey tints -- as BlastEm draws it at frames 30-67. So Overdrive 2 is now a referee run, at about 25 frames of offset for the reboot. Measured speed on the shared machine: 100 frames in 13 minutes (0.13 frames a second, with the romset sweep running beside it). The board does not freeze on the first run, and the note says real hardware does; what the board does differently in the Z80 start-up is a question for later. ### One referee run for everything Runs of the die model are expensive (0.27 frames a second with the machine free), so the whole demo is being run once, recording what any later question could need. The driver gained, each checked on a 60-frame run: - `NMD_PICS=`: every frame's raw capture, zlib-compressed and indexed (frame, offset, bytes, half-MCLK); about 11 KB a frame. - `NMD_AUDIO=`: FM left, FM right and PSG summed over each FM sample period. - `NMD_SAVE_EVERY=`: a save state every n frames, taken where [GPL source] takes its own, with the driver's counters and part-drawn frame beside it; `NMD_LOAD=` starts from one. Nuked-MD's save holds six pointers FC1004_Init aims into the chip, stale in another process, so the build renames [GPL source]'s [source name redacted] and the driver's wrapper re-aims them. A run loaded from frame 40 draws frames 40-59 bit for bit as the run that saved it did, at the same half-MCLK. (Its sound could not be checked there: the demo is silent until later.) - `NMD_PLOT_LIST=`: plot a list of frames. The run (`reference/nuked-od2/launch.sh`): to die frame 20,400, reset held at frames 25-30 (after the first run's freeze), every frame's picture, the sound, a save every 250 frames, and a 68000 bus trace over die frames 12,230-12,260 (the arcade's V interrupt). Die frames are the board's frames plus about 25 for the reboot; the board can press its own reset at frame 25 to line the two up. **The board lined up with the referee.** `scripts/board_frames.py --reset-mclk 26761500` presses the board's reset button at the master clock the referee's was pressed at (PAL frame 25). After it, board frame n is the referee's frame n - 1, pixel for pixel: 62/61, 70/69, 78/77, 86/85 all 71,680 of 71,680 through the opening fade, where each frame differs from its neighbours (the one frame is where the two count their first). The aligned board run (`reference/od2-board-aligned`, every frame to 20,400, FM on, the chips' own samples in `fm.bin` and `psg.bin`, a snapshot every 1,000 frames) is the board half of the whole-demo comparison. ### The one-frame slip at 7,047, and the Z80 from the reset Against the referee (frames 1-9,897 compared, `scripts/compare_referee.py`), 7,155 frames are identical at the aligned offset and 8,686 within two frames. From frame 7,051 the board is one frame late. Traced cycle by cycle from the referee's save at frame 7,000: 1. Both write the same VDP stream until a pass at frame 7,051 where the demo waits for the V counter to read $DF. The board enters the wait at line $DD; the die after $DF has passed, so it waits through the blank for line $1DF, 57 lines late. 2. The die's 68000 is late because over ~33 lines before it the board ran the same decryption loop (move/eor/move, ROM to RAM) ~17% faster: the die's Z80 made 332 bank reads in the stretch (each costing the 68000 ~11 cycles, which the board's arbiter charges too: 10.57), the board's Z80 only 54, from another place in the ROM. The two Z80 sound drivers were at different points of their playback; the FM recordings of the whole demo correlate at only 0.4. 3. From the reset, the two Z80s load the same 7,440-byte program at the same times and then run identically for 187 reads, until a loop that polls the YM2612 for timer A's overflow. The board's flag rose 617 MCLK before the die's. 4. The cause: the FM's sample phase after a reset. Nuked-MD's FM resets its prescaler and slot counter only for 12 FM clocks after /IC is asserted ([source name redacted]'s [source name redacted]) and then runs on under /IC; its slot-23 marker keeps its 1,008-MCLK period through a reset and moves by 2 cycles when /IC is pulsed. The board froze its counter under /IC and restarted it at release. It now restarts it at the assertion, holds it 2 cycles, and lets it run (`ym2612.IC_FSM_HOLD`); release resets nothing. Timer A's first flag after the reset is now 113 MCLK from the die's (was 617), and the Z80s run identically for 398 reads (was 187). What looked left there -- the board's timer-A flag "jittering" by up to 3 cycles -- was the probe's own artifact, not the board's: `YM2612.run` advances its clock to the catch-up target before running the cycles, so a probe reading `mclk` inside `cycle` stamps every cycle of a catch-up with the same time. Timed cycle by cycle the board's flag keeps the die's 4,032-MCLK period. The next section is what the difference was. Tools: the driver's `NMD_FMSIG` logs the FM's BUSY latch, timer flags, slot-23 marker, timer clock and /IC; `tests/test_sprite_line_buffer.py` holds the counter rule. Both suites pass (140 before this test). ### The access-timing table, and what the slip turned into Aubrey's decision: adopt z80-python's access-timing table. What that and the chase behind it found, in order. 1. **The table.** z80-python `b62891b` (PR #19, merged, not yet released; pinned by revision in `pyproject.toml`) gives, for an instruction's bytes, each memory access with its T-state (`z80_python.timing.instruction_timing`). The system looks the Z80's next instruction up before stepping it (`System._z80_offsets`, cached by its first four bytes, read with `Board.z80_peek`, which has no side effects), and the board places each FM, VDP and bank-window device access at the step's start plus that offset plus what the Z80 has already been held (`Board._z80_access_time`). Where the Z80 takes an interrupt that step the table does not apply and the access stays at the step's start; an interrupt merely requested, with IFF1 clear or in EI's shadow, does not count (z80-python's own acceptance test, `iff1` and `_ei_delay`). Identical Z80 reads against the die from the reset: 398 to 1,150. 2. **Not the arbiter.** The bank-access delay (`Board._bank_delay`) still places the access at the step's start. The arbiter reads the 68000's bus cycles only as far as the Z80 has been caught up to; an access later in the instruction lands past them on a bus that looks idle, and MoD's spinning-68000 experiment then costs the Z80 exactly what a stopped 68000 does (682 wait states in 300 tries both ways; `tests/test_milestone5.py` caught it). Placing the arbiter's accesses too needs the Z80's catch-up to stop short of an instruction whose accesses would cross the 68000's clock; that, and with it undocumented-behavior open item 14, is next. 3. **The 1,150 rested on two errors cancelling.** Before the Z80 starts, the 68000 copies its sound driver into Z80 RAM a byte at a time (7,357 writes over 1.2M MCLK), and on the board it released the bus 252 MCLK before the die did. The die's write-to-write spacings are 161, 168 or 175 MCLK where the board's are 161 or 175: the cartridge refresh falling on a write to Z80 space holds it one 68000 clock, not the cartridge's two and not the board's none. Of the 519 refreshes that fell on those writes, 392 due a clock or more before /AS held it 7 MCLK and 127 due within the last clock held it not at all, though they were used up (the next refresh came 1,785 MCLK later) -- every one. `board.Z80_REFRESH_STALL`, `Z80_REFRESH_LATE`; undocumented-behavior "The bus" item 7. The bus is now released 7 MCLK from the die's. 4. **The FM's /IC: a reset or a pause, by where in its slot it lands.** With the Z80 now on time, the timer flag was early by 239 MCLK. Nuked-MD's [GPL source], clocked the way [GPL source cited, redacted] clocks it (scratch harness, not kept: the die's own code driven through every position), resets the slot counter only if the assertion is sampled 1-3 FM clocks into a slot; at 0, 4 or 5 clocks the counter keeps its count and resumes, after the 12-clock stop, at the slot under way two clocks after the assertion. The Overdrive 2 run's three assertions agree: the console reset (2.6 clocks in) reset it, the first run's release-and-reassert (5.1 clocks in) paused it 11 clocks, the final one (0.1 clocks in, sampled at the next) paused it 12. `ym2612. IC_PAUSE_POSITIONS`; the rule the board had, always a reset, is item 4 of the section above. 5. **Why the reads still part.** The FM's phase at the Z80's final /IC depends on the last resetting assertion, the console reset, and on everything the 68000 does between them. The die's reset button reaches VRES and ZRES 80,496 MCLK after the driver presses it (the board's `press_reset` is immediate), and before the reset the two runs differ outright (the die freezes on its first run), so the board cannot be lined up with the die to 7 MCLK from outside. Forcing the board's slot counter at the final /IC through all 24 slots and seven grid offsets finds the die's phase between two of the board's cycles: slot 18 with the grid 12-17 MCLK late gives 3,507 identical reads, where the best whole-cycle phase gives 1,150. 6. **And what stops those at 3,507**: the 68000's boot runs out of step with the VDP. From its precise vblank polls after the Z80 starts (every 210 MCLK), the die's VDP runs 240,277 MCLK after the board's; the Z80 release, 235,880. The difference comes from a start-up loop that reads CRAM back 64 words at a time in H40 with the display on, re-checking vblank every ~20,500 MCLK: the board runs each pass 300-900 MCLK fast, so it leaves on a different pass. Per line the die stalls two reads, one served at the hblank slot near $1CE and one near $002; the board stalls the same pair in most lines, but after a read at 3,316 MCLK into a line it still catches an end-of-line slot ($140/$142), where the die, from any read at 3,300-3,334, never does (about 50 lines, three exceptions). That is a read-prefetch slot rule in H40 active lines, not yet settled: whether the die's end-of-line slots sit earlier, or its prefetch needs more lead time, the data here does not say. The next thing to settle. Also seen: after a reset release with a bus request already pending, the die's Z80 fetches its first opcode before granting the bus; the board's grants first. Checks: both suites pass with z80-python `b62891b` installed (142 each, CPython 3.14 and PyPy 3.11). The milestone-1 replay, re-recorded (`scripts/mame_trace.py genesis GAME.zip --seconds 30`, MAME 0.285) and re-run on PyPy: all six games 0 unexplained, with the same instruction counts as before (Sonic 12,728,465 Z80 instructions, Streets of Rage 2 11,269,553, Gunstar Heroes 15,425,681, Castlevania 8,460,818, Sonic 3 11,837,738 with 1,688 interrupts, Phantasy Star IV 13,280,703). New tests: the Z80-space refresh stretch (`tests/test_board.py`), the /IC reset and pause (`tests/test_sprite_line_buffer.py`). ### The Z80 after a hold, and a read-ahead rule that the hardware test refused Chasing the reads further, with the FM phase still forced (item 5 above) so that each change is judged on the Z80 reads it matches, from 3,507: 1. **When the Z80 takes up its bus again** (Nuked-MD, all 83 bus releases and both reset releases after the power-on reset). Its clock runs on through a hold: every access falls on one phase of the 15-MCLK clock, 6 MCLK past a multiple of 105 on both machines. After the write that releases the bus, its next access comes on the first such edge 42 MCLK or more after the write began (42-56 measured); after a reset release, 57 or more. A reset released with the bus already requested still makes its first opcode fetch before letting go. And an instruction the request falls inside keeps the machine cycle under way and resumes with its later accesses moved, where the board used to rerun the whole instruction from the start. `system.Z80_CLOCK_PHASE`, `Z80_RESUME_MCLK`, `Z80_RESET_RESUME_MCLK`, `System._z80_resume`, `Board.z80_hold`. 3,507 to 6,305. 2. **The Z80's VDP accesses are arbitrated.** Its 3,095 reads of the VDP ($7F08, the V counter) in the run are held 60, 75 or 90 MCLK, the bank window's three lengths; its RAM and FM reads take 30. They go over the 68000's bus, so they take the bank window's delay (`board.Z80_VDP_ARBITRATED`). 6,305 to 6,970. 3. **The arbiter sees the access where it falls.** With the delay at the access's own time (item 2 of the section above undone), the Z80 is no longer stepped into an instruction whose accesses would fall past the 68000's clock: it waits for the next catch-up (`System.catch_up_z80`). MoD's experiment is back to its shape (stopped 2-3 wait states, spinning mostly 3 with 2-4, the 68000's share 10-12), and the reads against the die reach 7,435. **The read-ahead.** `scripts/run_read_slots.py` (new) sweeps bursts and pairs of CRAM reads across H40 active lines on Nuked-MD and the board. What the die showed: a read that waits for the buffer ends 42-48 MCLK later than the board's, at every slot; a fill needs the read that emptied the buffer to have begun about 21 MCLK before the slot; and the slot at H $142 fills no read at all. VSRAM reads behave the same; VRAM reads miss $140 too. Modelled as three rules, they reproduced the die's map exactly -- and failed **VDPFIFOTesting's "FIFO Wait States"**, which passes on hardware (Nemesis) and, run here on Nuked-MD from the same ROM, on the die too. Each rule removed alone still failed; the test passes only with the release delay and the $142 rule both gone. A hardware-verified test outranks a model fitted to die traces, and the die's own pass says the three rules are not how it works, only what it looks like from outside. **Not adopted**; the measurements and the script stay. What the die's read-ahead really is, is the next thing to find there: its VDP's read path, read from [GPL source cited, redacted] itself rather than fitted from bus traces. Also tried, not adopted: the die's longer DMA start-up (item 15 of the open items); with 100 MCLK the best forced phase reached 7,835 reads, but the hardware source (Kabuto's 5.6 cycles) still judges that question. Checks: both suites pass (143, a test for the resume rule added); the six-game MAME lockstep still 0 unexplained. The mini sweep against `megadrive-branch.csv`: 3 better (Arkagis Revolution - Input Diagnostics from a lock-up to `same`, Dynamite Headdy and Ristar from `phase` to `same`), 3 worse (After Burner II 2,531 to 2,841 differing pixels, Ultraman 4,673 to 4,801, Windjammers 2,243 to 2,244), all still to triage. ### Triage of the three worse carts Each of this round's three rules taken out in turn (scratch copies of `src/`, the sweep run against each): | cart | all rules | no VDP arbitration | no arbiter horizon | no resume | none of them | branch sweep | | --- | ---: | ---: | ---: | ---: | ---: | ---: | | After Burner II (USA, Europe) | 2,841 | 2,527 | 2,841 | 2,841 | 2,527 | 2,531 | | Ultraman (Japan) | 4,801 | 4,801 | 4,733 | 4,770 | 4,814 | 4,673 | | Windjammers (Proto) | 2,244 | 2,243 | 2,243 | 2,243 | 2,243 | 2,243 | After Burner II moves with the Z80's VDP arbitration alone. Its title screen scatters star balls at random positions over a fixed logo, and blinks "PUSH START BUTTON": the logo and text match MAME's in every variant, the balls and the blink phase do not. Ultraman's title draws its logo with a random pixel dissolve; every differing pixel is inside the logo, and the count moves under every variant, the old rules included. Both are random effects whose seed follows timing, so a count moving is not a fault in the picture; Windjammers moves by one pixel. None is a regression. MAME can't judge them and a die run of 600 frames from power-on (about 40 minutes) would not start in step with the board either (the first-run freeze, Session 13). `tests/mini_sweep.txt` notes them so a later move is read the same way. ### What "FIFO Wait States" can and cannot judge The read-ahead rules above were set aside because they failed VDPFIFOTesting's "FIFO Wait States". Traced on both machines from the ROM itself (die: Nuked-MD, frames 56-170 with Start pressed at 55, as the harness does), sub-test 8 -- six data writes fill the FIFO, the long write `$00008F01` then sets up a VRAM read, and 16 status reads look for a full FIFO -- loops until it has seen full or 2,048 times: | machine | iterations | iterations with a full sample | | --- | ---: | ---: | | Nuked-MD | 812 | 1 (the last; the sixth write held 74 MCLK) | | board, no read-ahead rules | 1 | 1 | | board, with the rules | 2,049 (the limit) | 0 | Both machines spread the iterations over the whole line (34-35 bins of 100 MCLK), so neither is phase-locked. At the commonest timing (413 MCLK from the sixth write's end to the first status read) the die reads full in 0 of 281 iterations and the board without the rules read full at once. So the board's pass of this test was partly luck, and on the die the test passes about once per 800 iterations: it cannot discriminate between read-ahead models, and Nemesis's own note that data-port tests during transfers "fail occasionally" on hardware fits. The rules stay out anyway, on the other count: they did not move the Overdrive 2 comparison (3,507 identical reads with and without them). Scripts for this: the scratch `fifo8.py`/`vft8.py` harnesses were not kept; `scripts/run_read_slots.py` holds the measurement that matters. ### The arbiter, measured The per-read Z80 wait mismatches (15 MCLK, now and then, on its reads of the VDP) came from Kabuto's footnote-1 arithmetic, which the board had used since milestone 5. Tested straight against the die -- every one of the 24,343 bank-window and VDP accesses in the Overdrive 2 trace, predicted from the die's own 68000 bus cycles around it -- it gives the die's wait for 76.8 % of them. What the die does, read off its bus (the Z80's own cycle on the 68000's bus is in the trace, marked as not driven by the 68000): 1. A 68000 cycle that begins up to 21 MCLK after the Z80's /MREQ still goes first; none that begins later does (every access in the run). 2. The Z80's own cycle begins 17 MCLK after the last of those ends, and no sooner than 29 MCLK after /MREQ, on a 68000 clock edge. The grants 7 or 14 MCLK later than 17, which had looked unexplained, are this floor and edge. 3. It ends on the first Z80 clock edge at /MREQ + 37 + 15w that leaves it at least 30 MCLK: 67, 82 or 97 MCLK after /MREQ for 2, 3 or 4 wait states, every access. 4. The 68000's next cycle waits for its first clock edge 25 MCLK after that. 5. A ROM read through the bank window that meets the cartridge refresh takes it: its own cycle is 14 MCLK longer (Kabuto's ``b``). With the 68000 stopped a quarter of the Z80's reads do, one per refresh period (882-889 MCLK apart). Rules 1-4 give the die's wait for 94.3 % of the accesses; in 97.8 % the grant is right and the rest are rule 5, which the board takes from its own refresh grid (the window in which a refresh lands on the Z80's read rather than passing on an idle bus is not pinned: the board takes every owed tick, and in MoD's stopped case gives 3 wait states to half the reads where the die gives it to a quarter). `arbiter.z80_access_wait`; Kabuto's arithmetic (`bank_access_delay`) and `Board._m68k_release` are gone. The board also moves the 68000's later cycles in its step by the delay each access costs it, so the cycle the 68000 resumes with is on the bus when the Z80's next access comes. Against MoD (`scripts/run_nuked_md.py arbiter`, hardware-captured, with the die beside it): the 68000 stopped, 2-3 wait states ("2-3"; the die 2.25, the board 2.49); in `jmp (a0)`, 2-3 with mean 2.86 (MoD 2-4, "about 2.93"; die 2.74); the `pop`'s second read, mean about 2.2 where MoD and the die have 3.5-3.6 -- no better than Kabuto's arithmetic was (2.04), and still open. On Overdrive 2, every Z80 read of the VDP now waits what the die's does, through the whole comparison window. The best forced-phase run stops at 4,738 reads rather than 7,435, and the reason is not the arbiter: after the Z80 starts, the board's 68000 makes its periodic bus request about 4,800 MCLK earlier than the die's (the boot offset between the two CPUs, Session 13), so the request lands on another Z80 instruction; with the old arbiter the two holds cancelled exactly (-150/+150), with this one they miss by 15 MCLK and the timer-A poll flips. That offset is the next thing. Checks: both suites pass (142; Kabuto's formula test and `_m68k_release`'s test replaced by one for `z80_access_wait`); the six-game MAME lockstep 0 unexplained (it runs with the arbiter off); the mini sweep against the previous one: one move, Sansan (Japan) 2,370 to 3,134 pixels at the exact frame, still `phase` -- an identical frame remains within the window. ## Session 14 (2026-09-29): the boot offset Merged into main (d8fdf1c); the 7,435-read state is tagged `od2-z80-7435` (6b07497) as the regression baseline, reproducible with the forced FM phase. Aubrey's brief: find the first point where the board's 68000 gets ahead of the referee's, reporting for each experiment the boot offset, the first divergence, the matching Z80 reads and whether the visible frame slip moves; no new forced alignment. **The measure.** The boot offset is the Z80's start (the 68000's second release of the bus after the final sound reset) measured against the start of the next vblank line on each machine: 183,964 MCLK on the referee (its line starts taken from `NMD_VDPSIG`'s /HSYNC log, `reference/boot-frame`, and the H counter it logs), 179,782 on the board. **Board minus referee: +4,182 MCLK**, the board's 68000 late against its own VDP. **Where it comes from.** `scripts/od2_boot_drift.py` (new) lines up the two 68000s' bus cycles by address and kind and prints where the time difference steps. From the last vblank edge before the Z80's start through the start itself the two stay within about 100 MCLK -- but that edge is found by a loop that polls vblank only once per pass of a CRAM readback (every ~20,500 MCLK), so where each machine leaves it depends on how long its passes take, and the board's run 300-900 MCLK short (the read-ahead, Session 13's "The access-timing table" item 6). After the Z80's start the next vblank wait then ends 4,074 MCLK early on the board: that is the offset, surfacing. | experiment | boot offset | matching Z80 reads, unforced | first divergence | frames 6,981-7,100 at the aligned offset | | --- | ---: | ---: | --- | ---: | | main (d8fdf1c) | +4,154 | 197 | timer-A poll (FM phase) | 22 / 120; late from 6,981 | | + the three read-ahead rules | **-57** | **4,738** | 15-30 MCLK per bus hold | **111 / 120; late from 7,095** | | + cartridge refresh restarted at the reset button | -130 | 1,150 (best of 25 reset clocks) | -- | not run | All unforced, the reset button pressed with ZRES at the die-aligned clock (26,601,687, found by stepping 7 MCLK at a time; 26,601,680 follows from the VDP offset 240,316). With the read-ahead rules the unforced run reaches what the forced one reached with the same arbiter: the boot no longer needs the FM phase forced. What remains at 4,738: at each of the 68000's bus requests the board holds the Z80 15-30 MCLK longer, and the drift tool shows why: the board takes work-RAM and cartridge refreshes on cycles where the die takes none, so the two refresh schedules are out of phase after the reset. The third row tried the one explanation the die suggested -- its refresh ticks sit where its reset pulse began, modulo 896 -- and it made every clock worse; not adopted. **The read-ahead rules and the hardware gate.** They are the same three rules set aside in Session 13 (the read waits 45 MCLK after the slot that fills it, a fill needs the read that emptied the buffer begun 21 MCLK before the slot, H40's $142 fills no read), and with them VDPFIFOTesting's "FIFO Wait States" fails on the board every time. On the die that test passes about once per 800 iterations ("What FIFO Wait States can and cannot judge"). Adopting them means moving that test to the intermittent list the harness already keeps for Nemesis's "fail occasionally" tests, which is Aubrey's call. **Aubrey adopted them.** `vdp.READ_RELEASE_MCLK`, `READ_FILL_LEAD_MCLK` and the $142 rule are in `src/`; "FIFO Wait States" is in `run_vdpfifotesting.INTERMITTENT` with the die evidence, and the test exempts the intermittent ones; a new test holds the board's read slots to the die's measured windows (`tests/test_milestone5.py`); VDP item 28. Checks: both suites pass (143); MAME lockstep six games 0 unexplained; the mini sweep against the previous one: Gauntlet IV (USA, Europe) (En,Ja) from `differs` to `phase`, nothing worse. ### The refresh after the reset (not adopted) With the read-ahead in, the Z80 comparison stops where the board holds the Z80 15-30 MCLK longer at each bus request, and the drift tool shows refresh stalls one machine takes and the other does not. What the die says, from the whole power-on trace (`reference/z80-reset/t.bin`): - **Work RAM**: the next access falls due for its refresh 812 MCLK after the last one that took it, not the board's 805 (gaps of 805 or less: never refreshed; 812: 9 of 14; 819 and more: all but two). It settles the 791-819 window of `RAM_REFRESH_AFTER_MCLK`. - **The cartridge refresh** is a rigid 896-MCLK grid, as the board has it, and a tick is taken by the first 68000 access after it -- stretched only if that access is a cartridge read (12,753 ticks; a VDP or work-RAM access after a tick takes it with no stretch, 1,627 times). But on the die the grid **starts at the console reset**: no cartridge read is stretched before the reset, and afterwards every stretched one lies 0-28 MCLK after a multiple of 896 from the reset pulse's start. The board keeps its power-on grid through the reset, and its cartridge stalls coincide with the die's for 1 of ~13,400 refreshes after it. Restarting the board's grid at the reset button, the phase swept in 7-MCLK steps, the coincident stalls rise to 8,048 (at +21 MCLK, from 1). The metrics, against main (69b9e86), reset pressed at 26,601,687: | | boot offset | matching Z80 reads (best of 11 reset clocks) | frames 6,981-7,200 aligned | first frame late | | --- | ---: | ---: | ---: | ---: | | main | -57 | 4,738 | 111 / 220 | 7,094 | | work RAM at 812 | -- | 4,738 | not run | -- | | cartridge grid restarted at the reset (+21) | -46 | 1,150 | 94 / 220 | 7,075, then two late | So the change that makes the board's refresh agree with the die's makes the picture worse; neither is adopted, the work-RAM threshold because it moves nothing. The likely reason the Z80 reads and the slip resist: they also carry the YM2612's phase from before the reset, where the die froze on its first run and the board did not (Session 13), and the slip itself is the two sound drivers drifting apart (Session 13, "the one-frame slip"). A 68000-side change that is right on the die can still land the sound driver on a worse phase. `scripts/od2_boot_drift.py` gains `--from-reset`, to compare the 68000s from the reset vector on. ### Removing the sound phase as a variable (Aubrey: ROM-specific, not ideal, worth it) Aubrey agreed to align the YM2612 to the referee's measured state in the comparison harness only, knowing it ties the comparison to this ROM. What the measurements said about *where*: - **Not at the console reset.** Both machines' slot counters are *reset* there (the referee's next marker comes 1,077 MCLK after /IC, the reset case; the board's goes from cycle 9 to 0), so the phase after it depends only on when the button is pressed, which is aligned. The history before the reset -- the die's first-run freeze -- does not reach the sound chip. (This corrects the previous section's guess.) - **At the Z80's start.** From the final sound reset to the Z80's start the 68000 runs 1,208,224 MCLK on the referee, 1,208,242 on main and 1,208,251 with the refresh restart. The Z80 reads flip from 4,738 to 1,150 on that 9-MCLK difference: the timer-A poll after the start crosses its threshold at 10-15 MCLK. The count is a threshold detector, not a measure of distance. `scripts/od2_compare.py` (new) is the harness for Session 14's numbers: the reset button pressed with ZRES at the exact clock, the boot offset and the matching Z80 reads reported, `--src` to run another board, and `--align-fm`, labelled ROM-specific, which sets the board's slot counter at the Z80's start to the referee's phase there (its slot-23 marker 41 MCLK after the start; the board's cycle 0 85 MCLK after the marker, calibrated on main, whose reads match). Results: | board | aligned | boot offset | matching Z80 reads | | --- | --- | ---: | ---: | | main | no | -57 | 4,738 | | main | yes | -57 | 4,738 (by construction) | | work RAM at 812 | yes | -57 | 4,738 | | cartridge grid restarted at the reset (+21) | yes | -46 | 1,150 | With the sound phase removed, the refresh restart still loses, and the per-read drift says why: it matches the referee better at the first bus hold (15 MCLK short where main is 30), but its Z80 starts 15 MCLK later against the 68000's release, and the sum of such 15-MCLK steps puts the timer-A poll on the other side. Each of those steps -- the Z80's resume after a bus hold, the 68000's cycles in the hold, the refresh within it -- is a separate question at the 7-15 MCLK level, and the Z80 count cannot tell them apart. ### BlastEm with the same reset (Aubrey's suggestion) Aubrey: reset BlastEm at frame 25 too, for a second view from the accurate camp -- the differences might not all be the board's. `scripts/blastem_frames.py` gains `--reset-frame` and `--seed`: BlastEm's soft reset lands at a random point of the next frame ([GPL source cited, redacted] [source name redacted], `rand()`), so the process's generator is seeded first and a run repeats exactly; the reset is placed to the frame, not to the clock. Its frames, cropped of its 8-line top border and mapped to the board's DAC levels, are scored against the referee's with `scripts/compare_referee.py` like the board's. Frames 6,981-7,200: every BlastEm frame is identical to one of the referee's, and BlastEm **slips one frame against the referee at 7,051** -- where the board slipped before the read-ahead (7,047-7,051; Session 13), and for all seven seeds tried, i.e. wherever in the frame its reset lands. The board, with the read-ahead, slips at 7,094. So two independent emulators part from the die model at 7,051 the same way. Session 13 traced that slip to the die's 68000 being late into a V-counter wait because its Z80 made 332 bank reads in the stretch before, against the board's 54: the two sound drivers were at different points of their playback. BlastEm is a detector and cannot overrule the die; but the die's Z80 is the part of Nuked-MD with a known fault (its README's Notes put Overdrive 2's first-run freeze down to a Z80 microcode issue), and its chip combination (NMOS 68000 and Z80 with the FC1004) matches no console Sega sold. Where the die and both emulators disagree about the Z80, the die is not an obviously better judge. ### Three ways at the sound driver (A2) To use BlastEm as a tie-breaker at a finer grain than frames, `blastem_frames.py` gains `--event-log`: BlastEm's hardware event log ([GPL source cited, redacted], the standalone's `-e`), started through the libretro core before the cartridge loads, so it records every YM2612 register write with its clock. The same stream comes from the referee's bus trace (the Z80's writes to $4000-$4003) and from the board's YM2612. Two cautions from doing it: the referee's trace shows the driver's data-port writes but not all its address-port writes, so the streams are compared on the data-port values alone (the DAC samples and the timer-control $35s, in order); and BlastEm's timestamps swing by about 270 MCLK from write to write where the board's stay within the FM clock's 42 of the referee's, so BlastEm cannot referee questions at the 15-MCLK level. Identical data-port writes from the driver's first ($FF, $02, $15, ...) after the reset: | streams | identical writes | | --- | ---: | | referee vs board | 470 | | referee vs BlastEm | 435 | | board vs BlastEm | 435 | The referee and the board run together longest; BlastEm leaves both at the same write, the same way. Each departure is where the timer-control write falls among the DAC samples -- when timer A overflows against the Z80 -- the sensitivity every Z80 comparison here has met. So at the driver's level BlastEm does not side with the referee against the board; its frame-level slip at 7,051 is its own driver's path, not evidence about the die's. The bus-hold steps (option A) are left to the referee alone, with the Z80 caution noted above. ### The bus holds (option A, against the referee alone) Each of the 68000's bus requests after the Z80's start, step by step on both machines (the request, the Z80's last access, the release, the Z80's first access after it): - **The 68000's side is exact.** With the request lined up, its bus cycles through the hold are the same cycles at the same clocks on both machines, the release 161 MCLK after the request every time. (A scratch log had stamped the 68000's writes one bus cycle early, which looked like a 28-MCLK longer hold on the board; the board's own resume path gets the true clock.) - **The Z80's resume matches** where the two Z80s are still in step: 56 and 53 MCLK after the release at the first two holds on the board, 56 and 52 on the referee; the third, 55 against 46, differs because the 68000's release falls at another phase of the Z80's clock -- the board's 68000 is 21 MCLK late by the first hold, from a work-RAM refresh the referee does not take (Session 14's refresh section). - **One rule corrected.** At a later hold the referee's Z80 fetches an opcode after the request, lets go at the end of that fetch, and after the release runs the instruction's internal T-states before its next read (122 MCLK after the release). The board put the next *access* at the resume edge, folding those internal T-states into the hold; it now moves the rest of the instruction as a whole, so whatever follows the cut comes at the edge (`System._z80_resume`; `tests/test_board.py`). It does not move Overdrive 2's numbers (the holds where it matters come after the two Z80 streams part); the mini sweep: MUSHA 30,077 to 28,736 differing pixels, Ultraman (the timing-seeded dissolve) +16. - **The clocks agree.** Lined up by their VDPs, the referee's 68000 and Z80 edges fall 1 MCLK earlier than the board's, both -- within what the line-start derivation can resolve. (A first reading of 29 MCLK matched the wrong lines of the 105-MCLK pattern.) So the hold mechanics are right, and what is left in the Z80 comparison comes back to the 68000's refresh schedule after the reset: the die restarts it there, the board does not, and adopting the die's restart moved the Overdrive 2 slip earlier (Session 14). That contradiction is the open question. Checks: both suites pass (144); MAME lockstep 0 unexplained. ### The reset exception, the console model, and the refresh contradiction Following the 68000's bus cycles from the reset button on (`od2_boot_drift.py --from-reset`) found three things before any refresh question: - **The reset exception ran before the pulse.** The board fetched the reset vectors at the start of the 128-clock pulse and added the pulse afterwards, with the fetches stamped at a stale clock. On the die the 68000 is held for the pulse (896 MCLK) and fetches its vectors after it, the first taking the cartridge refresh then due. The board now holds it first (`System.step`), and `System.press_reset(at=...)` presses at an exact clock (the 68000 held from its next clock edge) for the referee comparisons. - **The console model.** At +364 MCLK Overdrive 2 reads $A10001: the die answers $E1 (version 1, a TMSS Model 1, the VA7 its README names) and the board's `megadrive` $E0 (version 0), so the program writes "SEGA" to $A14000 on one and skips it on the other -- 210 MCLK in the first instructions. Every referee comparison so far ran the board as the pre-TMSS model; `od2_compare.py` and `od2_boot_drift.py` now default to `megadrive-tmss`, which matches the die cycle for cycle through that check. - **The core's reset is 42 clocks.** m68000-python's `reset` returns 42 clocks where its docstring and the 68000 UM (Table 8-14) say 40; its bus cycles match the die's except the first vector fetch, 16 clocks after the pulse where the die's is at 14. A core question, to raise on m68000-python, not to work around here. The refresh, with those settled. The die's cartridge refresh grid restarts at the reset pulse's start; its work-RAM refresh is not the board's rule (after the reset the die's next refreshed RAM access is 2,700 MCLK after the first, with unrefreshed ones between) but no simple rule fits it -- a line-based grid, an 896 grid taken by RAM accesses, a count since the last all do worse than predicting "never" (492 of 544). What the reset does show is that the pending RAM refresh is cleared there. | board (megadrive-tmss) | 68000 timing steps (7+ MCLK) from the reset through the boot | after the Z80's start (290k MCLK) | matching Z80 reads, best press | frames 6,981-7,200 aligned | | --- | ---: | ---: | ---: | ---: | | reset fixed (A) | 30,924 | 527 | 4,738 | 111 / 220; late from 7,094 | | + cartridge grid restarted and RAM refresh cleared at the reset pulse (B) | 24,532 | 116 | 1,150 | 22 / 220; late from 6,981 | On the 68000's own bus cycles, which is what the refresh changes, B is the closer board by a factor of four to five after the Z80's start. On the measures further downstream -- the Z80-read threshold and the picture 7,000 frames on -- it is worse. Which the board should follow is Aubrey's call; B is not adopted yet. The reset-order fix and the exact-clock press are adopted (neither moves A's numbers). Checks: both suites pass (144; the reset test now checks the vector fetch comes after the pulse and counts the refresh it takes). **Aubrey's decision: B.** "Go with B as the current implementation, but record the refresh behavior as a supported finding rather than a fully proven model. The deciding evidence is the direct 68000 bus-cycle comparison, since that is the subsystem the refresh change actually affects." So `system.RESET_RESTARTS_REFRESH` is on, documented as a supported finding (undocumented-behavior, the bus, item 11), and A stays reproducible: `od2_compare.py` and `od2_boot_drift.py --no-refresh-restart`, which give the table's numbers exactly. B is not to be tuned further to recover the late-frame picture unless the discrepancy that causes it is found. The core's 40-clock reset is raised on m68000-python as issue #3 (a reproducer, the die's clocks beside the core's, and a proposed test), not compensated here; it arrives with the next pin bump. ### Open: Aubrey's Overdrive 2 playthrough notes (2026-09-30) From watching a full run on the frontend, recorded to investigate later. Frame numbers are the frontend's title-bar counter: frames since power-on, **no reset pressed**, so they are not the die-aligned numbering of the referee comparisons (those press reset at frame 25; the two differ by a constant to be measured before comparing). | frames | what Aubrey saw | confidence | related, already on record | | --- | --- | --- | --- | | ~5,673 | the scene transition from the ship crash to the 3D ninja view: garbage on screen | seen | -- | | ~5,700-5,900 (from ~5,787) | the ninja's arm colours change to the wrong colour, wrong through the scene, right again by 5,900 | seen | a palette (CRAM) timing or a palette-index question; mid-line CRAM placement is die-measured (item 20) but only checked 9,175-9,725 | | ~7,000; 7,065-7,066 | a black flash just before 7,065 shows junk (white lines and dots) in the centre of the frame | unsure | the one-frame slip lies here (7,047-7,095; Sessions 13-14) -- a frame shown a frame early or late may be the cause, not the drawing | | ~10,100 | vertical-line garbage as the scene transition is set up | seen | -- | | ~12,500 | the robot "breaks the frame" and the picture should get wider: a width change (H32 to H40), or start at the widest | seen | the frontend reopening its window on a size change (the arcade section, Session 13) and letterboxing (the other agent's area); the board draws what the mode says, so first check whether the width is the board's or the window's | Also still open from before: the rotating boxes' black scanlines (~14,400-14,850), the B-masked debug-register scenes (8,150-9,125), and the arcade V-interrupt question (die bus trace over die frames 12,230-12,260). ### m68000-python pinned at 38dbd0f (its #3 fixed) Issue #3 went to m68000-python and came back as its PR #4 (merged 38dbd0f): `reset()` reads the SSP vector after 14 clocks, 40 in all, as UM Table 8-14 and Nuked-MD have it. The pin moves there from 51ee1a5, which also brings the core's polish round (the halt on a double bus fault during the reset sequence, 1f43e0b) and lets the board read the public `step_clocks` instead of the private `_cycles` (docs/polish.md's item, done). Checks: both suites pass (145; the reset test now expects 40 clocks and the vector read 14 clocks after the pulse); the MAME lockstep, six games, 0 unexplained; the mini sweep: one better, none worse -- Phantasy Star Fukkokuban (Japan) from an `error:` (a fault in its reset sequence) to `same`, the double-bus-fault halt; Overdrive 2's harness numbers unchanged (B 1,150 and A 4,738 at their best presses: the vblank waits resynchronise the 68000 before the Z80 starts, so two clocks at the reset do not reach it). ### The ninja's arm colours (Aubrey's playthrough, ~5,775-5,900) - **What goes wrong.** In the aligned run (reset at frame 25, `megadrive-tmss`) the board's pictures are identical to the referee's through frame 5,800 and part at 5,801: about 56,000 pixels for ten frames (the transition garbage Aubrey saw), then about 8,500 from 5,811 (the arms). The frontend's numbering, with no reset, is about 26 lower. BlastEm and the die both draw the arms grey; the board draws them orange and green. `scripts/vdp_streams.py` against BlastEm: the first VRAM write the two disagree on is the sprite table's $F010 at the board's frame 5,775 (no-reset numbering) -- the board writes $4545 (palette line 2, and a byte write's replicated value) where BlastEm writes $0160 (the next Y). The board's 68000 writes the sprite table late, from line 3 of the picture instead of in the blank, and the demo's code takes another path when it is late. - **Why the 68000 is late.** The die from its save at frame 5,750 (`reference/arms-die`, `NMD_LOAD`), its 68000 traced over frames 5,790-5,804, against the board's aligned run over the same frames: once lined up, the board falls behind steadily, 43,197 MCLK over 4.17 frames. Of that, about 20,800 is the work-RAM refresh (the board refreshes on RAM writes the die does not refresh, +57,540, and the reverse, -36,708: the board refreshes work RAM more often), about 3,400 comes after `MULS.W` (the core charges 2 clocks more than the die's 68000 for some operands), 2 clocks at a `MOVEM.W` to memory (the core's first write 2 idle clocks late), and about +17,500 in steps the alignment could not name. The biggest of those, 1,100-1,600 MCLK each, are only the level-4 interrupt (the per-line palette writes) arriving at other instructions: both sides take 225 per frame, one a line, and the board's entry is no slower (217 MCLK on average against the die's 228). - **What it really was: the Z80's bank reads.** That breakdown named steps by where the alignment put them, and the arbiter's charge lands at the start of the 68000's next instruction (`m68k_pending_stall`), so it was filed under whatever came next. Two measures without an alignment found it. Ranked by each address's mean cost (board minus die, times the die's count), the main loop's fetches ($3BAC6E-$3BACE0) cost 7-14 MCLK more on the board, in gaps of 70-130 MCLK with no stall logged. Across the whole window the board's 68000 has 9,234 such gaps against the die's 7,381, and longer ones. The die's trace logs the Z80's bank reads on the 68000's bus (cycles the 68000 did not drive): 8,597, 540-810 a frame, against the board's 9,710. What each cost the 68000, in its clocks: | | 9 | 10 | 11 | 12 | 13 | |---|---:|---:|---:|---:|---:| | die (68000 interval round the read) | 431 | 2,804 | 3,719 | 476 | 565 | | board | 103 | 3,569 | 2,345 | 778 | 2,681 | On the die 12-13 come with the cartridge refresh (a read 0-84 MCLK after a tick); on the board 13 comes at every refresh phase. It is the arbiter's arithmetic at 3 wait states when the 68000 is taken to want the bus four clocks after its last cycle (`_bank_delay`'s `wanted`) -- and in this code it often does not: the loop is multiplies and long register operations, and a Z80 read granted inside one costs the 68000 only what runs past it. `Z80_GRANT_OVERLAPS_IDLE` charges from the 68000's next bus cycle in the instruction, or where its next instruction starts: | | board, before | board, after | die | |---|---:|---:|---:| | 13-clock reads | 2,681 | 241 | 565 | | 10 / 11-clock reads | 3,569 / 2,345 | 2,903 / 3,469 | 2,804 / 3,719 | | lag behind the die, per frame (vblank milestones) | ~10,000 | 3,000-7,000 | | | aligned frames 5,741-5,840 identical | 57 of 100 | **100 of 100** | | | frames 6,981-7,200 at the expected offset | 22 of 220 | 110 of 220 | | | first of those only at another offset | 6,981 | 7,053 | | | boot, 68000 bus cycles 1.4M MCLK after reset: steps / end | 1,402 / +18 | 1,355 / +12 | | | boot offset; matching Z80 reads | -67; 187 | -61; 1,150 | | MoD's `jmp (a0)` loop, always on the bus, costs the 68000 10.86 cycles a read before and 10.78 after (Kabuto's "around 11"); a `mulu.w d0,d0` / `bra.s` loop 11.01 before, 3.09 after (`test_a_z80_access_costs_a_busy_68000_only_what_it_overlaps`). Die-derived; no hardware source measures the 68000's side with it off the bus. Suites 146 pass on both interpreters; the mini sweep against `mini-pin.csv`: 2 better (Sansan 3,134 -> 2,370 pixels, Windjammers 2,244 -> 2,243), 1 worse (Sonic 3, 831 -> 862 against MAME, a detector that has no arbiter), 112 unchanged. - **Tooling.** The measure that found it, without an alignment: for each (address, kind), the mean time to the next cycle on each side, the difference times the die's count. A running `System` pickles: a snapshot at frame 5,789 of the aligned run replays the window in seconds instead of 10 minutes (a fresh process must build one `System` first, which builds the core's dispatch table). - **Left.** The lag still grew 3-7k MCLK a frame: the work-RAM refresh, next. The "+2 clocks after `MULS`" was the same misattribution as the rest -- the arbiter's charge landing after a long instruction: m68000-python times `MULS` by the manual (38 + 2n, n the 01/10 transitions; SST-certified), and the die's `muls.w d2,d0` with d2 = $0AAA (read on the bus just before) takes 62 clocks, the manual's figure. No core issue. ### The work-RAM refresh The boot's 544 RAM accesses never settled it; the arms window's die trace has 135,937 (Nuked-MD, frames 5,790-5,804; IACK cycles, which it logs as reads of $FFFFF8, set aside). 11,203 are stretched by exactly 21 MCLK, a few by 7, 14, 28 or 35. - **The board's rule fails outright.** It had the next work-RAM access always take a refresh due 805 MCLK after the last; on the die, RAM accesses go unstretched 50,000 MCLK after the last stretched one. The refresh is hidden when the RAM is idle. - **The rule that fits.** It falls due 819 MCLK after the last one began. A work-RAM access starting within 98 MCLK of that takes it and waits 21. If none does, it runs by itself from +112 to +133, and an access starting from +98 waits for its end -- on the 68000's next clock edge, which is why the partial waits are 35 (+98), 28 (+105), 14 (+119) and 7 (+126). The next falls due 819 after whichever began. Replayed over the 135,937 accesses (resynchronised on the die's own refreshes), it predicts every stall exactly but 172; 153 of those are a refresh one 68000 clock early, mostly where the due time falls on an odd master clock (121 of 153, against 834 of 2,284 on time) -- a clock-domain crossing the trace's half-MCLK resolution cannot settle. Only P + window = 931 is fixed by the data for the run-by-itself case; 819 (not 812-818) is what the triggered case needs. - **On the board** (`RAM_REFRESH_HIDDEN`, False keeping the old rule): the arms window's RAM stalls become 11,898 of 21, 402 of 35, 172 of 28, 129 of 14, 197 of 7 over 15 frames against the die's 11,203 / 338 / 169 / 116 / 179 over 14 (the old rule: 16,027 of 21). The steady lag behind the die is gone: the vblank milestones wander -9k to +16k instead of climbing to +69k. `RESET_RAM_REFRESH_MCLK` re-swept under the rule: 2,359-2,408 all give the best boot comparison, 2,380 stays. | | arbiter fix only | + refresh rule | |---|---:|---:| | boot, 68000 bus cycles 1.4M MCLK after reset: steps of 7+ / end | 1,355 / +12 | 931 / +17 | | same over 3.5M MCLK: steps of 60+ / end | 22 / +18 | 16 / +23 | | aligned frames 5,741-5,840 identical | 100 of 100 | 100 of 100 | | frames 6,981-7,200 identical (window 3) | 218 of 220 | 220 of 220 | | ... at the expected offset; first not | 110; 7,053 | 75; 7,053 | | boot offset; matching Z80 reads | -61; 1,150 | -217; 192 | The judge, the direct bus-cycle comparison, improves: over the first 850,000 MCLK after the reset the old rule drifted to +818 and the new one has no step at all. The boot offset is read at the Z80's start, inside a polling loop ($2EFAD2-$2F0246) where both runs take 60+ MCLK steps either way, so it moves with where a wait loop exits; the late-frame offset count is downstream of the same. Neither is tuned for. **Against the hardware.** Nemesis's HV/status captures (288 dumps from real consoles; the sampling loop writes work RAM twice every 20 clocks, with a 112-MCLK gap that the 98-MCLK trigger window can miss) are the one hardware source that sees this. They do not tell the two rules apart, and they found a weakness in their harness instead: - `run_hv_captures.py` fits each dump's refresh phases with a fast model of the loop, which now follows the board's rule (its RAM phase searched over 0-938, the new rule's whole 931-MCLK cycle). It took the first way of anchoring that left any survivor, and with the new rule a tolerant first-sample anchoring let a poor fit through (NTSC-J intnorm H32V28 dumps 2 and 4, PAL intinv H32V30 dump 7 -- each a third wrong) where the strict second-sample one had the right placement: run on the board, the old placement (its RAM phase moved 14, the same phase under the new rule) matches as well as before -- 39 differences, 13 on another dump. Both anchorings are now tried strictly before either tolerates, and up to 32 placements within 20 long-score samples of the best (duplicates dropped) are run on the board, where only exact ties, at most 8, were. 143 s for all 288 (91 before). - Same harness, both rules: 8,763,223 words equal under the old, 8,762,828 under the new, of 8,847,360. Every capture is within 34 words but PAL intinv H40V28 (-445), all in its dump 6, which no placement fits under either rule (its best long score 698 of ~2,400 even under the old; about 11,000 differences either way). That capture's floors in `tests/hv_captures_baseline.json` are lowered to what the new rule gives (264,783 equal, 6,876 away from a step), the only baseline change. The mini sweep against the arbiter fix's run: 6 better (Ultraman 4,817 -> 4,648, Sansan 2,370 -> 1,868, Sunset Riders, Castlevania, Sonic 3, After Burner II), 3 worse (MUSHA 28,736 -> 30,077, Gauntlet IV phase -> 1,091 differing, Fantasy Zone +42) -- against MAME, which has no refresh model; MUSHA and Gauntlet IV are worth a look. ### The test cartridges, before and after (Aubrey: "how are we doing on all of the other test carts?") Every quick harness run on main (82ddf49) and on this branch, side by side: | | main | this branch | |---|---|---| | VDPFIFOTesting, nine machines | 122/122 on five, **121/122** on megadrive, megadrive-tmss, megadrive2 (an intermittent-on-hardware test); genesis3 114 (as a Genesis 3) | **122/122 on eight**; genesis3 114 | | Nemesis's sprite masking ROM vs his MD1600 | 0 of 18 cells differ | 0 of 18 | | MoD's `gen_test_z80_bus` | 12 results, 0 FAIL | the same | | MD Soft Checker, five machines | 17 of 17 verdicts each | the same | | r57shell's VDP tests, the pads, `joy_speed`, TMSS | as certified | the same | | MoD's experiments: Z80 waits stopped / `jmp (a0)` / `pop` (hardware 2-3 / 2.93 / 3.5) | 2.32 / 2.92 / 2.80 | 2.32 / 2.97 / **3.37** | | the 68000's delay a Z80 read (Kabuto "around 11") | 10.97-11.05 | 10.71-10.82 | | Nuked-MD probe loops, 68000 bus cycles agreeing | 2,921 of 3,546 | **3,155** (the three work-RAM loops 312/311/325 -> **394/394/394**) | | Nuked-MD, the test ROMs' first 394 cycles | HV capture 315, r57shell 328, VDPFIFOTesting 317, the other seven unchanged | **382, 393, 382**, the other seven unchanged | | Nuked-MD, the `pop`'s second read (referee 3.60) | 3.34 | 3.47 | | Nuked-MD, the FM probe's first difference | cycle 197 | cycle 337 | | Nemesis's HV/status captures | 8,762,415 words (old harness) | 8,762,828 (old rule, same harness: 8,763,223) | The probe loops needed `run_nuked_md.py` to seed the board's work-RAM phase by the board's rule: it fitted the old one, with its own copy of 805. The rule is now one function, `board.ram_refresh`, that the board and both harnesses call. Under the old rule no phase made the work-RAM loops agree; under the new one the first phase does. Not rerun here, being untouched by bus timing or slow: the MAME frame comparisons of the milestone-3 test ROMs, MDFourier, the SSG-EG recording, the battery, the mapper, the region register. ### The DMA trigger (Aubrey's option A), and the slip at 7,053 **The whole demo against the die.** The board rendered every frame from 26 to 24,400 of the aligned run (the die's own pictures cover the whole demo): frames 27-7,052 match it at the expected frame, 6,821 of 7,025 (the others are TV static, whose noise differs, and the frames just after the reset). At 7,053 the board goes a frame ahead, at about 10,304 a second: Aubrey's "junk between scenes", growing towards the end. **Why 7,053.** The logo scene's main loop does a frame's work, then syncs (reads the HV counter to line ~215, writes register 5, waits for VBlank to end and begin, at $31C826). In frame 7,050 the die's work ends at line 224.2, just after VBlank began, and it waits a whole frame; the board's at line 220.3, in time. Its 68000 is 4 lines faster that frame because the Z80's sample reads (150 of them in one stretch on the die, none on the board) fall elsewhere in the frame: the sound driver is out of phase. It parts from the die at its very first timer wait ($011C: `or (hl)` / `jp po`, polling the YM2612 at $4080), the board's timer A overflowing one poll sooner -- and the FM's phase is set at the console reset, so it follows the boot's length. The boot's 68000 is early by up to 275 MCLK at the Z80's start, built up DMA by DMA: every 68000-to-VDP transfer froze it 70-115 MCLK shorter than the die's, whatever its length (32 to 7,952 words). **What was adopted (branch `dma-trigger-hold`):** - `vdp.DMA_TRIGGER_HOLD_MCLK` = 21: the write that starts a transfer is held 3 clocks longer -- 39 MCLK on the die for every one of 119 trigger writes (boot and logo traces), and /BGACK falls 40 MCLK after the write began, just as it ends. Fitted over 4-128 words, the board's start-up moves from 4.9 cycles (below Kabuto's 5.6 and the die's 8.0) to 7.2, between them, its slope 2.355 (Kabuto 2.4). `test_a_dma_transfer_pays_kabutos_start_up` now checks that fit instead of one word alone (one and two words fall on the same slot and cost 12.0). - `vdp.DMA_TAKES_REFRESH`: the transfer's own bus cycles take the cartridge refresh ticks due while it runs; the die's first 68000 cycle after a transfer is unstretched 114 times of 118, where the board stretched it every time. | | main | + option A | + both | |---|---:|---:|---:| | boot DMAs, board minus die (MCLK, typical) | -73 to -136 | -33 to -107 | -41 to -86 | | Nuked-MD DMA probe, display off, 1-16 words (cycles) | -5.0 to -3.4 | -2.1 to -0.6 | | | 68000 bus cycles to the Z80's start, 60+ MCLK steps / end | 48 / -37 | | 52 / -5 | | boot offset; matching Z80 reads | -217; 192 | -217; 192 | -215; 192 | | aligned frames 5,741-5,840 identical | 100 | 100 | 100 | | frames 6,981-7,200 identical (window 3); at the expected frame | 220; 75 | 220; 75 | 219; **182** | | first frame off the expected | 7,053 | 7,053 | 7,053 | **What was tried and taken out.** On the die /BGACK rises 26-54 MCLK after the board's last read, and the 68000's next cycle comes 19-25 MCLK after it (three logo DMAs). A fixed 35-MCLK release and 19-MCLK resume brought the boot's display-on DMAs within a clock of the die and the boot offset to -81, but put the display-off probe 6-8 cycles over the die, Kabuto's fit over 8.0, and the arms window from 100 to 63 frames: not a rule. Releasing when the FIFO drains overshot by 90-112 MCLK. What differs between the display-on boot DMAs and the display-off probe is the open question. **The Z80, separately.** Shifting the FM's phase at the Z80's start (the harness's `--align-fm`, its lag swept over the 24 internal cycles of a sample) gets the driver past its first timer wait at one phase only (lag 126: 1,150 reads match), and it parts from the die again after that -- the Z80's own timing, the long-open caveat. ### The Z80's phase, and DMA with the display on **The Z80 is not the cause.** With the FM's phase set to the die's at the Z80's start (`--align-fm`, lag 112-133), the board's and the die's Z80 accesses agree in time for all 1,148 reads that match, with no drift; every FM timer wait has the same load-to- flag time and polls until the 15th, which neither a fixed FM phase nor the Z80 explains. What sets it is earlier: in `ld iy,$0000` at $00E4 the 68000 takes the Z80's bus to write $05A2. On the die the Z80 lets go after the instruction's third read ($00E6), on the board one machine cycle sooner, because the board's 68000 asks 80-215 MCLK earlier: its boot runs early. From there the board's Z80 is 4 T-states (60 MCLK) behind, which the FM alignment had been hiding. (A logging slip first put the board's `or (hl)` status read 1 T after its fetch; read after the access, as the board does, it is 4 T, as on the die.) **DMA with the display on** (`run_nuked_md.py dma --display-on --when vblank|active --delay N`, new; the transfer started just after VBlank begins or ends): | 68000 cycles beyond the write | die | board before | board now | |---|---|---|---| | active display, 1 / 2 / 4 words | 11 / 14 / 19 | 56 / 56 / 56 | 8.6 / 10.9 / 15.4 | | active display, 8 / 16 / 64 words (VRAM) | 219 / 653 / 3,242 | | 220.6 / 654.3 / 3,243.4 | | VBlank, VRAM, slope / 512 words | 4.78 / 2,448 | 4.79 / 2,440 | the same | | VBlank, CRAM, slope / 512 words | 2.47 / 1,270 | 2.39 / 1,224.6 | the same | | display off (200 NOPs later), CRAM 512 | 1,267 | 1,225.1 | the same | - **Fixed:** the board read the 68000's memory for a transfer only at an access slot, so in the active display a short transfer waited for slots the die does not wait for. `vdp.DMA_READS_BETWEEN_SLOTS`: the reads are events of their own, into the FIFO while it has room. Die-derived. - **The display-off case is the same as VBlank** on the die and now on the board too, once the transfer starts a few lines after the probe's register writes; started at once, the board pays ~240 MCLK more, from the H40 switch written just before, which the board latches at the next line. A mid-line mode change; left. - **What remains is the hardware-versus-die pair already on record:** every transfer 2.4-3.6 cycles short (the die's start-up 8.0 against Kabuto's 5.6, which the board charges) and the fast pace 2.40 (Kabuto's 2.4) against the die's 2.47 -- 12 cycles over a 64-word CRAM transfer, the boot's commonest. Those, not the board's own mechanism, are what keeps its 68000 early at the Z80's start. Changing either is a tier decision (Aubrey's). Overdrive 2: aligned frames 5,741-5,840 100 of 100; 6,981-7,200 219 identical, 182 at the expected frame (unchanged); matching Z80 reads 192 -> 331; boot offset -217. VDPFIFOTesting 122/122 on eight machines, 114 on genesis3; suites 147 pass; Overdrive 2 runs at the same speed (9.3 frames a second from the frame-7,036 snapshot). ### Kabuto's figures or the die's (Aubrey's option 3) Where the two disagree -- a transfer's start-up (Kabuto 5.6 cycles, the die 8.0) and the fast pace (2.4 against 2.47 a word) -- the board keeps Kabuto's by default, as the tier rule says, and `Machine.dma_figures = "die"` takes the die's: a start-up of 56 MCLK and a read every 190/11 MCLK (3,420/198: an H40 line's worth of reads, the fraction carried so none drifts). The `nuked-md` machine is `megadrive-tmss` with the die's figures, for the comparisons against Nuked-MD; `run_nuked_md.py dma --dma-figures die` gives the probe's own machine the same. With the die's figures, against the die (cycles beyond the write, NTSC as the probe's referee runs): every regime within 2 cycles -- active display 1 to 512 words, VBlank and display off for CRAM -- but VRAM in a blank line, 4-8 short from 16 words on. | Overdrive 2 | `megadrive-tmss` | `nuked-md` | |---|---:|---:| | boot offset; matching Z80 reads | -217; 331 | -86; 192 | | 68000 bus cycles to the Z80's start, 60+ MCLK steps | 52 | 33 | | frames 6,981-7,200 identical (window 3); at the expected frame | 219; 182 | 219; 182 | | first frame off the expected | 7,053 | 7,053 | The slip does not move. Before the Z80's start one step is left, -60 MCLK after the 64-word CRAM transfer at $39889E; and the die's cost for such a transfer depends on where along the line it starts -- 161 to 173 cycles over 16 starts 3 NOPs apart (a blank line), where the board's averaged pace gives 166.4 every time. Matching it transfer by transfer needs the die's own read times, which its bus trace does not show: the VDP's DMA reads do not appear among the cycles the harness logs. ### The DMA's reads on the die, and the Z80's bus request **The harness sees the DMA now.** `validation/nuked_md_headless.c` gains `NMD_TRACE_MASK` bit 3: the work-RAM (/RAS0) and cartridge (/CE0) selects as type-4 records, one per new address while a select is held (the cartridge's stays low across a transfer), flagged with /BGACK and whether the 68000 drove /AS. The VDP's DMA reads drive neither /AS nor the 68000's strobes, which is why no trace had shown them; `nuked_md.memory_cycles` reads them. **What they show** (a 512-word CRAM transfer from work RAM in VBlank; the Overdrive 2 boot's 64 transfers, almost all from the cartridge): - The reads fall on the VDP's slot clock, 16 MCLK apart (18-20 across the H40 sync's slower pixels), with a 48-MCLK gap at six places a line -- 512 MCLK apart, 860 across the blank: each refresh costs the reads **two** ticks, as Exodus has it, where the VRAM write slots lose one (the Manual's 205 bytes a line). That is the die's fast pace, 2.47 cycles a word, against Kabuto's 2.4. - First read 74 MCLK after the trigger write's start from work RAM, 50-59 from the cartridge; the 68000's next cycle 32 MCLK after the last read from work RAM, 35-55 from the cartridge. `Machine.dma_figures = "die"` now uses that, not an averaged pace: reads on `_dma_ticks` (the refresh positions 8 H earlier than Exodus's against the board's own counter, fitted: 1.66 cycles RMS over 16 starting points), the first read on the first tick 25 (work RAM) or 4 (cartridge) MCLK after the write is over, the 68000 back 21 (fitted) or 45 MCLK after the last read. Against the probe, 3 cycles RMS over its 16 transfers -- active-display transfers of 16 words or more stay 4-5 long. Kabuto's figures (the default) are untouched. **The Z80's bus request.** As `nuked-md` the boot lined up (boot offset -4 MCLK), and the Z80 still parted at its first timer wait. On the die the 68000's request ($A11100 = $0100) lands in the M1 of `ld iy,$0000`'s second byte, and the Z80 still reads $00E6 before letting go: /BUSREQ falls 18 MCLK after the write begins (all six writes in the logo trace), and the Z80 samples it on the last clock of a machine cycle, 15 before its end. The board let go at the first machine-cycle end after the write itself. `system.Z80_BUSREQ_LAG_MCLK` = 33: the first end 33 or more after the write. The pause now falls where the die's does; the board's Z80 then resumes one T-state late, its 68000 14 MCLK late at the release. | | `megadrive-tmss` before | after | `nuked-md` before | after | |---|---:|---:|---:|---:| | boot offset | -217 | -211 | -86 | +14 | | matching Z80 reads | 331 | 264 | 192 | 192 | | Z80 timing from the driver's start | +60 after the pause | | +60 | **+15** | | frames 6,981-7,200 identical (window); at the expected frame | 219; 182 | 218; 111 | 219; 182 | 219; 182 | The default machine's late-frame count falls with the lag; it is the downstream measure, and the lag is what the die does. Unchanged: suites (148), VDPFIFOTesting on every machine, MoD's Z80 bus test and arbiter experiments, the arms window (100 of 100). Still open: the board's /BUSACK grant averages 18.2 68000 cycles from the write where the die's averages 12.1 (`run_nuked_md.py busack`) -- already so before this work, and the likely home of the last 14 MCLK. ### The Z80's bus grant **What the die does.** `run_nuked_md.py busack`'s loop (the Z80 reading the bank window, the 68000 asking for its bus, holding it, giving it back): /BUSREQ falls 18 MCLK after the $A11100 write, and /BUSAK falls **7 MCLK after the Z80's last memory cycle releases /MREQ**, in all 29 grants of one window -- that cycle a bank read, wait states and all (60-90 MCLK long). Over 142 grants the write to /BUSAK is 69-75 or 97-104 MCLK (a few 117), never under 69: mean 12.55 68000 cycles. **What the board did.** /BUSAK at the probe's estimate of the machine cycle's end plus a fixed 57 MCLK (`arbiter.BUSACK_PROPAGATION_MCLK`, fitted to this probe's means in the timing session). The probe gives every memory cycle 3 T-states, so the 57 stood in for the bank reads' wait states as much as for the propagation: 50 MCLK late for a Z80 running from its own RAM, as Overdrive 2's driver does. And where the Z80 had already run the instruction the request fell in to its end, it added the 57 to that end. **Now** (`Z80_BUSACK_AT_CYCLE_END`): /BUSAK falls `Z80_BUSACK_AFTER_MCLK` (3) after the end of the machine cycle that takes the request -- the instruction's end if the Z80 has run it, the deferred instruction's let-go if not, else the next instruction's cycle ends with each bank or VDP access's wait states (from the arbiter) added. The lag before the Z80 takes a request, 33 from /BUSREQ and the last-clock sampling, is refitted to the grants as 48: the board's grants mean 12.5 cycles (12.55 on the die; 17.9 before), the shape still not the die's two clean clusters (the largest gap between the two cumulative distributions 0.30). Overdrive 2's driver: the first pause is now exact, the second (at +1,647) one Z80 clock late, and the driver still parts at its first timer wait. | | before | now | |---|---:|---:| | `busack`: write to /BUSAK, mean (die 12.55) | 17.9 | 12.5 | | `nuked-md` boot offset; matching Z80 reads | +14; 192 | -4; 187 | | frames 6,981-7,200 identical (window), `nuked-md` / `megadrive-tmss` | 219 / 218 | 220 / 220 | | ... at the expected frame | 182 / 111 | 75 / 75 | The boot offset and the late frames move by whole wait-loop passes with a few MCLK of change anywhere (an after of 2 gives -88, of 3 gives -4): threshold quantities, not measures of how close the model is. Unchanged: suites (148), VDPFIFOTesting, MoD's Z80 bus test, the arbiter's experiments and the die's (the board's waits 2.49 against the die's 2.25). ### Handover by handover A comparison of every Z80 bus handover after the driver's start, board against die (the request, the Z80's last access before it stops, the 68000's first access to Z80 space, the release, the Z80's first access after it), found the first difference at the first handover: every 68000 event 8 MCLK late against the Z80's. Not a whole 68000 clock, so not a timing rule: the two CPUs' clock phases. - **The 68000's phase drifted.** On the die its edges keep one phase from power-on; on the board every VDP hold that was not a multiple of 7 MCLK moved them -- 4,000 times in Overdrive 2's first 12 frames. A held cycle ends on the first edge after the device lets go (/DTACK is sampled on an edge): `board.HOLD_ON_68K_EDGE` rounds the VDP's holds and the wait for the Z80's bus up to the 68000's clock. The phase now never moves. - **The two clocks' relation.** The die's 68000 edges fall at 6 mod 7 MCLK and its Z80's at 6 mod 15, in its own time; lined up with the board as the Overdrive 2 comparisons line them (240,323 MCLK), that is 0 and 13 in the board's. The board had 0 (from power-on) and 6, and its arbiter assumed 6. `system.Z80_CLOCK_PHASE` = 13 and `arbiter.M68K_EDGE_PHASE` = 0: the first handover then matches the die exactly, and the second's release and resume. - **The YM2612's /IC.** Its phase is set by the 68000's last write to $A11200 (the reset line it shares with the Z80), not the reset button: on the die /IC moves 18 MCLK after each such write. `board.ZRES_PIN_MCLK` = 18 for the FM's view of it. Its slot counter then sits within 3.5 MCLK of the die's after the final release (taking the model's note that the die's slots begin 24 MCLK after its cycles; the 85 MCLK `od2_compare` calibrated with in Session 14 had absorbed errors since fixed). - **The reset press.** With the 68000's holds whole clocks, the first interrupt after the reset button fell one instruction early, the miss shrinking by 7 MCLK for each 7 MCLK later the button: at 26,601,694 it is gone, and the first difference in the 68000's bus stream moves from 390,859 MCLK after the reset to 850,199. The harnesses default to it. **What is left there.** At 850,199 the board comes out of the boot's first transfer -- 272 words from the cartridge, the display on, during the active display -- 252 MCLK early: the die's 68000 gets the bus back 389 MCLK after the transfer's last read where in the blank it is 35-55, presumably as the FIFO drains through the active display's few slots. That decides the 68000's timing to the Z80's start, and so whether the driver's first timer poll sees the flag (board 2,640 MCLK after the load, die 2,895; one poll). | | before | after | |---|---:|---:| | first difference in the 68000's bus stream after the reset | 390,859 | 850,199 | | handovers 0 and 1 against the die | +8 MCLK each | exact (the second's request 14 early) | | the driver's first timer wait, load to flag (die 2,670) | 2,535 | 2,640 | | frames 6,981-7,200 at the expected frame, `nuked-md` | 75 | 182 | | aligned frames 5,741-5,840 identical | 100 | 100 | Unchanged: Nemesis's HV captures (8,762,828 words), VDPFIFOTesting on every machine, MoD's tests, Nuked-MD's probes (3,155 of 3,546). `test_a_z80_access_waits_as_the_die_times_it` now names its clock edge by the constant. The comparison is `scripts/od2_handovers.py`. **Not settled: the press time.** At 26,601,687 the first two handovers match the die (the 68000 against the Z80) and the first interrupt after the reset comes one instruction early (the 68000 against the VDP); at 26,601,694 the interrupt matches and the handovers are 5 MCLK off (`scripts/od2_handovers.py`). No one press time lines up all three clocks, so their relation is still not the die's somewhere -- the next thing to find, with the active-display DMA's end. The harnesses default to 26,601,694 (the 68000's own bus stream agrees with the die further: to 850,199 MCLK, not 390,859); it is a harness setting, not board behaviour. ### The FIFO's delay (the end of DMA during the picture) **The die's VRAM writes.** `NMD_TRACE_MASK` bit 4 now logs Nuked-MD's VRAM write strobes (/RAS, /CAS and /WE low together; type-5 records, `nuked_md.EV_VRAM`). With them and the DMA reads, the boot's four transfers around 850,000 MCLK after the reset: - The end is not where the board differed. After the last read the die's 68000 has the bus back in 40-55 MCLK, in the active display as in the blank (the "389" of the last section was a read misselected). - The die writes a transfer's first word to VRAM **57 MCLK after reading it**; its reads then stall after six, the FIFO full. The board wrote at the next slot, the same clock it read, and ran on for nine. `vdp.FIFO_COMMIT_DELAY_MCLK` = 32 (fitted over the four: the last reads and returns to within 7-21 MCLK, where they were 35-189 out): a transfer's entry for VRAM is committed no sooner than that after it is pushed. CRAM and VSRAM, inside the VDP, take none (a 64-word CRAM transfer matches without one), nor do the 68000's own data-port writes (no evidence either way; the transfers are what was measured). **A latent reset bug it exposed.** With the delay the first difference in the 68000's bus stream jumped to 196 MCLK after the reset: the board added 70 MCLK after `move #$2700,SR`. Not the FIFO: the delay moved the boot's timing so that the Z80 made a bank read just before the button, and the arbiter's charge for it (`m68k_pending_stall`) survived the reset and was added to the 68000's first step after it. The 68000 is held through the pulse; the reset now clears it. | | before | after | |---|---:|---:| | the boot's first transfer (280 words, from line 202): 68000 back, board minus die | +189 | **-14** | | the two 32-word VRAM transfers after it | -42, -35 | +7, -7 | | first difference in the 68000's bus stream after the reset | 850,199 (-252) | 850,199 (-14) | VDPFIFOTesting's "FIFO Wait States" (intermittent on hardware, passing once in 812 on the die) now fails on the plain machines as the die mostly does; every other test of the 122 unchanged on all ten machines. Unchanged: the suites (148, both interpreters), Nemesis's HV captures and sprite masking, MoD's Z80 bus test, Nuked-MD's probes, the arms window (100 of 100), frames 6,981-7,200 (219 identical, 182 at the expected frame). ### The VDPs' offset (the press-time conflict) The comparisons had lined the board up with the die by 240,323 MCLK, "the two VDPs' offset", and from it the CPUs' phases and the reset press. Fitted directly instead: Overdrive 2's boot polls the VDP's status 186,758 times on the die; the HBlank flag of every poll the board's line structure covers (16,427) comes out as the die read it at an offset of **240,277** MCLK and at no other (240,323 gets 15,995). With it: - **The clocks' relation.** The die's 68000 edges (6 mod 7) and Z80 edges (6 mod 15) are at 4 and 14 in the board's time. The board's 68000 now starts 4 MCLK into power-on (`system.M68K_POWER_ON_PHASE`, kept through everything: its holds are whole clocks), the arbiter's edge is at 4, the Z80's at 14 (`Z80_CLOCK_PHASE`). - **The E clock.** The first interrupt's autovectored acknowledge (VPA, waiting for the E clock) ended a 68000 clock early: the E clock's phase at power-on, `M68K_E_CLOCK_POWER_ON` = 9, puts it where the die's is. - **One press time does both.** At 26,601,705 the first interrupt and the first two handovers match the die exactly; the 68000's bus stream agrees to 850,199 MCLK after the reset (-21, the boot's first transfer). The harnesses default to it. (The die's pulse less the offset is 26,601,719; the 14 is the board's pulse start against the die's.) - **The YM2612.** Its sample phase after /IC was off by 455 MCLK: its reset-or-pause rule (`ym2612.IC_PAUSE_POSITIONS`, `IC_SLOT_LAG`) had been fitted under the wrong relation, and the 18-MCLK pin delay added last session counted the model's own sampling delay twice -- with it at 0 the phase after the boot's later two assertions is one FM cycle early, with 9 or more 175-440 MCLK out (`board.ZRES_PIN_MCLK` = 0 now). Timer A's flag rises 168 MCLK after the die's slot-23 marker and 126 after the board's cycle 0, so the board's cycle 0 is the die's marker + 42 (not + 18, the note the earlier calibration leant on); against that the FM was one cycle early, and holding it 3 cycles after /IC (`IC_FSM_HOLD`, from 2) puts timer A's first flag where the die's is. 3 is fitted against two assertions, not read off the netlist (its [source name redacted] gives 12 FM clocks, 2 cycles); no sampling point recovers it with 2. - **The status read.** The Z80 takes the YM2612's status at the end of its read cycle: `board.Z80_FM_SAMPLE_MCLK` = 42 (40-45 all give the same; outside, 1,150 or fewer). | | before | after | |---|---:|---:| | matching Z80 reads | 192 | **3,301** | | the driver's first timer wait, load to flag (die 2,895) | 2,640 | 2,895 | | handovers 0 and 1 / the first interrupt at one press time | no | **yes** | | frames 6,981-7,200 identical (window); at the expected frame | 219; 182 | 220; 75 | The Z80 now parts from the die at read 3,301 (`$011C`/`$0120`), a later timer wait: the waits from the fourth on alternate one poll early and late against the die's, a phase finer than these constants. Unchanged: the suites (148), VDPFIFOTesting, Nemesis's HV captures and sprite masking, MoD's tests, Nuked-MD's probes, the arms window (100). ### The FM's restart (the timer, wait by wait) The last section left a compensating pair: the YM2612 held 3 cycles after /IC (`IC_FSM_HOLD`, against the 2 its [source name redacted] gives) and the Z80 taking the chip's status 42 MCLK into its read (`board.Z80_FM_SAMPLE_MCLK`). Compared wait by wait, every one of the Overdrive 2 driver's timer A waits had the board's flag 42.5 MCLK late after the load, and the sampling offset hid it. - **The die's FM alone.** Nuked-MD's prescaler and slot counter ([GPL source cited, redacted] [source name redacted], [source name redacted]/[source name redacted]), clocked by a small harness the way [GPL source cited, redacted] drives them ([source name redacted] from [source name redacted], phi1/phi2 from the prescaler), with /IC asserted at each of the six FM clocks of a slot: the counter's next slot comes **15 FM clocks after the clock that first samples /IC, at every phase**. Sampled 1-3 clocks after the last slot began, the count is kept and the next slot is entered at that point, 10-12 clocks late. Sampled 4-6 clocks after, the slot under way is finished and the count restarts at 0. The harness's marker and timer clock land 150.5 and 24.5 FM clocks after the sampling clock. The die's own run puts them 1,077 and 195 MCLK after its console reset's /IC, so the sampling clock is 23.5 MCLK after /IC moves, and /IC moves about 16 MCLK after the write that drives it. - **In the board's terms** the restart is 15 + ~3 FM clocks, about 126 MCLK after the write: 3 cycles, the hold the board already had. That fits for **both** kinds of assertion, so the hold was never the error. The error was the pause's count: it went on from the slot under way, not the one after it (`ym2612.IC_PAUSE_CARRY` = 1). With the old hold of 2 the two mistakes cancelled. Moving the hold to 3 for the console reset left the boot's final /IC pulse, a pause, one cycle late. - **Against the die's slot-23 markers** (board cycle 0 = marker + 42), after the console reset the board is +0.5 MCLK before and after the change. After the final pulse it was +42.5 and is now **+0.5**. (The pulse at 14.6M, before the press, is 637.5 off. The console reset restarts the count, so it reaches nothing; the 68000s are not aligned that early.) - **The status read** needs no offset now: `Z80_FM_SAMPLE_MCLK` is gone and the Z80 takes the status when its read begins. At 0, 22 of the driver's first 24 waits have the flag rise within 0.5 MCLK of the die's after the load, and the Z80's last poll before the flag is the die's to 0.5 MCLK (82 against 81.5, 154 against 153.5, ...). At 14 or more, waits 1 and 9 miss a poll and run 255 MCLK late. - **Waits 0 and 8** are the two that differ: the die's flag shows 20 and 26 MCLK after the board's. On the board both rises fall inside a Z80 status read, 10 and 4 MCLK into it. The die shows both exactly 30 MCLK after that read began, at the read's end, as if its status were held while /RD is low. Either way the Z80 reads the flag clear and the next loads agree on both machines. | | before | after | |---|---:|---:| | board cycle 0 against the die's marker, after the final /IC pulse | +42.5 | **+0.5** | | timer A waits, flag after load within 0.5 MCLK of the die's (of 24) | 0 | **22** | | Z80 sampling offset (fitted) | 42 | **none** | | matching Z80 reads | 3,301 | 3,301 | | the 68000 judge (`od2_boot_drift --from-reset`) | | identical | **Where read 3,301 comes from.** Not a timer wait: handover 2 (185,313 MCLK after the driver starts). The board's 68000 asks for the bus 14 MCLK early, so the Z80 stops one access sooner (`$012A` against `$012B`) and resumes 45 MCLK late. 190 reads later, at `$011C`/`$0120`, a poll lands on the other side of the flag. The lead is on the 68000 side: its bus stream parts from the die's at +850,199 after the reset (-21, the boot's first transfer) and is 14 MCLK early by handover 2. Unchanged: the suites (148, CPython and PyPy), VDPFIFOTesting on every machine, Nemesis's sprite masking, MoD's Z80 bus test, the soft checker, r57shell's tests, the pads, TMSS and Nuked-MD's probes (the whole battery's output is identical), and frames 6,981-7,200 (220 identical in the window, 75 at the expected frame, the slip still at 7,053). In the arms window (5,741-5,840) one pixel moved: frame 5,783 at (0, 32) is white where the die and main have grey, a colour-RAM write's dot at the line's start. The Z80 has parted from the die's 190 reads after handover 2, long before this frame, so its handovers there are not the die's on either board; the dot rides on that. ### The DMA's read into room (the 68000's drift) The judge (`od2_boot_drift --from-reset`) parted from the die at +850,199 MCLK after the reset, 21 early: the end of the boot's first long transfer, 280 words from the cartridge into VRAM across the end of the picture. Compared read by read (the die's memory selects, `NMD_TRACE_MASK` bit 3, against the board's reads), the board read each word about 405 MCLK before the die, all but the first four, and let the 68000 go 401 MCLK after its last read where the die lets it go 33 after. The two errors nearly cancelled. - **No read ahead.** With the FIFO full the board read the next word into a latch and pushed it when an entry emptied. The die does not: its next select comes 2 MCLK after the VRAM write strobe (`NMD_TRACE_MASK` bit 4) of the second byte that empties an entry, in the picture and in the blank alike. On a blank line that strobe is 1 MCLK after the board's slot. On an active line it is 49 MCLK after, so the transfer's read waits for it there (`vdp.DMA_ACTIVE_WRITE_LAG_MCLK` = 48). Moving the active slots themselves instead shifts a VDPFIFOTesting result and breaks the boot, so only the transfer waits; the 68000's own FIFO is left as it was. Every read of the board's now comes 3 MCLK before the die's select (its tick against the select). - **The first line of the border.** A transfer running from the picture into vblank writes nothing on the die until H $152, four slots into the line, where lines inside the border show no such gap (`vdp.FIRST_IDLE_SLOT_H`). - **The refresh.** On a blank line the die's writes lose the slot at $1F8, $038, $078 and its reads the ticks at $1F6 and $1F8: Exodus's $1F2, $032, $072 plus 6 and plus 4. The board had the reads 8 *before* Exodus's, fitted to the display-off probe, and the writes at Exodus's own. That probe is not lined up: its two 68000s meet their VDPs only through a status-poll loop, and the board's VDP sat 20 MCLK into a slow-pixel run when the die's did not. The vblank and active probes, which wait on the VDP first, are good to about a poll loop, ±20 MCLK. The boot, lined up by the VDPs' offset, is the judge (`DMA_REFRESH_SHIFT_H` = +4, `IDLE_REFRESH_SLOT_SHIFT_H` = +6). - **The resume.** The die's 68000 takes the bus back on its first clock edge 30-33 MCLK after the last select (33 and 36 to the edge in the boot, 33 in the work-RAM probe), whatever the source. One figure for both, `DMA_RESUME_DIE_MCLK` = 34 from the board's read: 33-36 fit the first two transfers, 33-34 all four. The 21 (RAM) and 45 (ROM) were fitted while the board read ahead. - **The FIFO's delay.** The die passes up a write slot 30 MCLK after its read and takes the one 46 after, so a DMA entry needs more than 32 MCLK from the board's read; 33-48 give the same boot (`FIFO_COMMIT_DELAY_MCLK` = 40, from 32). At 32 the board wrote the third transfer's first byte one slot early, and from there its bytes paired one slot ahead of the die's. - **The first read from the cartridge**, on the first tick 8 MCLK after the write is over (from 4): 5-12 put every blank-line transfer's first read where the die's is. The first transfer's first read, on an active line, wants 16 or more, which makes the blank ones late; it does not reach the 68000, the FIFO being full by then. - **The press time.** With these, no single resume fits both of the first two transfers at the press the harnesses used (26,601,705), and 31-36 fit both at the die's own (26,601,719, its pulse less the VDPs' offset): the 14 MCLK the earlier calibration called the board's pulse start against the die's was a 68000-against-VDP error, absorbed. At 719 one more thing moved, the first interrupt's autovectored acknowledge, 14 MCLK short: the E clock runs from power-on, so moving the press two clocks moves the program against it, and `system.M68K_E_CLOCK_POWER_ON` = 7 (from 9) puts it back. The harnesses default to 719 now. | | main | after | |---|---:|---:| | the judge's first difference | +850,199 (-21) | **+933,737** (-21) | | the boot's transfers in the strobe window (27.69-28.19M) exact at the 68000's resume | | **4 of 4** | | die DMA probe, active line, 8+ words, mean \|board-die\| (68000 cycles) | 8.80 | **0.13** | | die DMA probe, active line, all rows | 6.50 | **1.08** | | die DMA probe, vblank / display off, all rows | 1.83 / 15.08 | 2.79 / 16.42 | | matching Z80 reads | 3,301 | 187 | | handovers 0 and 1 | exact | +22, +8 | The Z80's numbers fall because by the Z80's start, 15.7M MCLK after the reset, the board's 68000 is about 100 MCLK out, where main's happened to be in step there (threshold measures, as before). What moves it on the way is the next item: the judge's first difference now is a work-RAM write the die holds 21 MCLK and the board does not, after the longest stretch of the boot without a work-RAM access (+747,628 to +931,469, all four transfers from the cartridge). The refresh rule (`board.ram_refresh`) fitted on the 3D scene, where the RAM is never left alone long, mispredicts 313 of the boot's 3,935 work-RAM accesses, both ways, after long idle stretches and in some dense ones; its self-run (`RAM_REFRESH_SELF_MCLK`) is the suspect. The die's refresh does not show on /RAS0 when nothing accesses the RAM (four work-RAM selects in 500,000 MCLK), and its holds fall nowhere in particular in the line. Unchanged: the suites (148, CPython and PyPy), Nemesis's HV captures (8,762,828 words), VDPFIFOTesting on every machine, sprite masking, MoD's tests, the soft checker, r57shell's tests, the pads, TMSS and Nuked-MD's probes; `run_dma_cost`'s VRAM 128 KB blanking figure moves 406.5 to 405.7 bytes a line (the refresh slot's place). The arms window is identical (100 of 100). Frames 6,981-7,200: 183 at the expected frame (main 75). The board is back on the die's frame from 7,090, where main stayed one behind from the slip at 7,053 to the window's end, but it catches up through one junk frame: 7,089 is black with a pale block and a patch of tiles, between the die's fading pattern and its white flash, the one frame of the window not found within three of the die's. ### The work-RAM refresh after a transfer The judge's first difference, +933,737, was a work-RAM write the die holds 21 MCLK and the board does not, after the boot's longest stretch without a work-RAM access, almost all of it spent in transfers from the cartridge. The rule (`board.ram_refresh`, fitted on the 3D scene) gets 313 of the boot's 3,935 work-RAM accesses wrong. Two test cartridges on the die (`scripts/run_ram_refresh.py --idle` / `--dma`), each with dense work-RAM reads (one every 56 MCLK, so each refresh is taken by a read and the timer's phase is known), something in between, and dense reads again: - **Idle in ROM** (a `dbra` spin, 700 to 280,000 MCLK): the rule's self-run chain is right. 65 of 68 idle lengths put the first held read exactly where it predicts. The other three are the known refresh one 68000 clock early, on an odd master clock. Period 931 (112 + 819) and only 931 fits. - **A transfer in between** (10 to 6,000 words from the cartridge, display off): the rule misses 15 of 16. The first held read is always the fourth after the transfer, whatever its length. Moving the reads in steps of 14 MCLK (NOPs and an `exg`), the first read held is the first at least 238-251 MCLK after the transfer's last memory select, to VRAM and to CRAM, 100 and 1,000 words alike. Measured from the 68000's resume instead, the boot's own hold (210 after it) contradicts the cartridges by 1 MCLK; measured from the last select, the boot agrees (218 free, 246 held) and narrows it to 238-246. So the transfer restarts the timer from its end: `vdp.RAM_REFRESH_AFTER_DMA_MCLK` = 245 from the board's last read (3 MCLK before the die's select). The judge now agrees to **+1,227,275** (from +933,737). The difference there is a VRAM read through the data port on line $1FF, the line before the display, which the board counts as active: the board fills the buffer at the slot at H $002 and lets the read go 45 MCLK later (`READ_RELEASE_MCLK`), and the die lets it go 50-56 after that slot, one 68000 clock later. The 45 was fitted to a sweep where the die ended waiting reads 42-48 MCLK after the board. That is the next lead, with the cartridge refresh holds that land on different cycles after it. Unchanged: the suites (148, CPython and PyPy), Nemesis's HV captures, the battery's whole output, the arms window (100 of 100). Frames 6,981-7,200: 218 identical in the window, 109 at the expected frame (the last round's branch 219 and 183, main 220 and 75): the slip that began at 7,053 is gone (7,054-7,088 now at the expected frame) and a slip begins at 7,094 instead. Threshold measures downstream of the Z80, as before. **The "junk" frame is the die's own.** The board's frames 7,052 and 7,089 are a black screen with a pale block and a patch of tiles, Aubrey's "junk between scenes". Nuked-MD shows the same picture once in this window, at its frame 7,052 (71,087 of 71,680 pixels alike), between the logo and the next scene; it is the only mostly black frame the die shows here. The board shows it one frame late at 7,052 and then again at 7,089, where the die has gone to its white flash. So the picture is not the board's invention; the repeat is. Whether a real console shows that frame at all is a question for hardware or BlastEm (Aubrey sees BlastEm's transitions clean). ### The active-line slots The judge's difference at +1,227,275 is the boot's first data-port read, a CRAM read on line $1FF (which the board counts as an active line). The board fills the buffer at the table's slot at H $002 and lets the read go 45 MCLK later; the die lets it go 50-56 after that slot, one 68000 clock later. The read sweep (`run_read_slots.py`), to which the 45 was fitted, puts the board's and the die's waiting reads in the same places on active lines; so the question was which frame to believe. - **The two frames disagree.** The sweep lines the die up by its /HSYNC fall, taking the die's H counter as the board's plus 3. In the boot, lined up by the VDPs' offset, the die's /HSYNC fall (at its H $1CD) comes 39 MCLK after where the board puts H $1CA. The boot's frame is the one the die's own VRAM strobes confirm (1 MCLK after the board's blank-line slots, all of them). - **Stall lengths need no frame.** Back-to-back CRAM reads with the display off: the die stalls 2,717 of 14,656, nearly all by one 68000 clock; the board stalled 13,185, by three or four. A blank-line release of 25-26 MCLK after the slot brackets the die's count (`READ_RELEASE_IDLE_MCLK` = 26; the active-line figure was the only one). - **After a new address.** The same sweep with the read address set before each burst: the die's first read stalls one clock more often than the board's (display off: 618 unstalled and 299 by a clock, against the board's 966 and 2). A slot fills the buffer only 21 MCLK after the control write, as after a read (`READ_FILL_LEAD_MCLK`, now for both); the histogram distance falls from 696 to 122. It does not reach the boot's read, whose command was written long before the slot. - **Six H, tried and rejected.** Several corrections have come out at about 48 MCLK on active lines (the transfer's VRAM strobes 49 after the table's slots, the die's /HSYNC 39 after) and the refresh gaps on blank lines 4-6 H after Exodus's. Moving the H40 active slots 6 H later, dropping the transfer's separate lag and letting a waiting read go 5 MCLK after the moved slot looked better on every measure at hand (the judge to +1,230,229, 7,408 steps of 7+ MCLK over the first 16M where there are 13,675, the read sweep's stalls closer, VDPFIFOTesting 122/0), but moved the CRAM dot and the read windows (two tests). The frames were the question, so three tests that need none, on each machine against its own HV counter as the 68000 reads it (`scripts/run_slot_hv.py write|status|read`): - VRAM writes with the FIFO full, the HV counter read after each: the die's stalled writes end at H $06, $16, $2E, $46, $56, $6E, $86, $96, $A6 (about 770 each), the board's at the same or one HV step (16 MCLK) earlier. The board's slots are where the die's are, to within one step, not 48 MCLK out. - Status and HV counter read in turn: HBlank sets at H $E4-$EA and clears at $09-$0F on both. - CRAM reads with the display on, the HV counter after each: the waiting reads end at the same H on both ($08, $10, $18, $28 ... $A7, $ED), so the active release of 45 is right. The board alone shows about 6 % at $20, $40, $60 and $80; those are reads of the HV counter made just as it steps from $x7 to $x8, which the board answers with mixed bits as Nemesis's captures show the hardware doing (`run_hv_captures`, "reads at a phase where a counter steps") and the die answers cleanly -- the reads before them were let go after the ordinary slots. The board also splits $08/$09 and $EC/$ED where the die does not, one step either way. So the slot table is right and the 6-H move was wrong: the 48 MCLK is the die's VRAM write pipeline on an active line (the word leaves the FIFO at the slot, which is what the 68000 sees, and reaches VRAM about 48 later, which is what a transfer's next read waits for: `DMA_ACTIVE_WRITE_LAG_MCLK` models exactly that), and the sweep's /HSYNC frame, anchored in the slow pixels around the sync, is what is out. The boot's read on line $1FF is a one-step difference at one slot, of the kind the HV test shows the board making at $08/$09. (The move's `vdp.py` is not kept.) **The release, placed.** The die's waiting reads put the next HV read on $08 22 times in 24, the board's spread over $07, $08 and $09: its release sat near the edge of an HV step, the die's inside one, and the 68000's clock, which drifts against the slots by 4 MCLK a line, carried the board's across. Swept against the die's HV histogram (28,214 stalled reads), the board's release after the slot scores 48,060 at 38, 13,352 at 45, 4,768 at 48, **4,193 at 52** and 4,454 at 55: `READ_RELEASE_MCLK` = 52, which is also what the boot's read wants (49-56). The test that held the board to the sweep's windows now holds it to the die's HV values (`test_data_port_reads_end_where_the_die_lets_them_go`: 87 % of the board's waiting reads land on them, 71 % with 45). The judge now agrees to **+1,230,229** (from +1,227,275), with 12,128 steps of 7 MCLK or more over the first 16M where there were 13,675; handovers 0-2 come within 1-15 MCLK (main: +22 and +8 for the first two). The next difference is a cartridge refresh: the die holds a ROM read 7 MCLK where the board holds 14. Unchanged by the blank-line release and the lead: the suites (148, CPython and PyPy), Nemesis's HV captures, the die's DMA probes, the arms window (100 of 100), frames 6,981-7,200 (218 identical, 109 at the expected frame), the Z80 reads (187). VDPFIFOTesting's "FIFO Wait States", intermittent on hardware and passing on the die about once in 800, now fails on `megadrive`, `megadrive-tmss` and `megadrive2` as on the die (the blank-line release); "0 fail that pass on hardware" on every machine. With the release at 52: the suites (148, CPython and PyPy), Nemesis's HV captures, the battery's output, the arms window and frames 6,981-7,200 are as above; the Z80 reads 187. ### The cartridge refresh when the bus is free The judge's difference at +1,230,229: in the boot's CRAM readback loop, a data-port read the die holds 126 MCLK, then a ROM read the die holds 7 for the cartridge refresh where the board held 14. Kabuto's rule already has the refresh swallowed by a VDP write; this one was half swallowed by the long held read before it. - **The boot.** Over the 1,000 refreshes that fall due during a held data-port read in the boot's first 16M MCLK, against how long before the next cartridge read the board's refresh fell due: up to 105 MCLK the die holds that read 14, at 112-119 it holds 7, from 126 not at all. The board held all of them 14. - **A test cartridge** (`scripts/run_cart_refresh.py`): dense cartridge reads, which place the die's own refresh grid, between `mulu.w #$FFFF` gaps of 70 clocks with no bus cycle. The read after a gap is held 14 when the refresh fell due up to 112 MCLK before it and not at all from 126 (184 reads). So it is any free bus, not the VDP's hold. - So the refresh runs by itself once the bus has been free 112 MCLK after it fell due, and takes 14: `board.CART_REFRESH_SELF_MCLK` = 112, half the stretch for an access that comes while it runs. The same shape as the work-RAM refresh's self-run. With it the read at +1,230,229 is held 7 on both, handovers 0 and 1 are exact, and the mean difference over most of the boot's first 16M falls from about 15 MCLK to 9-10 (steps of 7+ MCLK 12,128 to 11,173). The read before it, at the slot at H $1CE, was let go a step early: that slot is in the slow pixels around the sync (10 MCLK each), and counted in pixel clocks the release stretches there. `vdp.READ_RELEASE_PIXELS` = 6 (plus 4 MCLK, the same 52 on ordinary pixels): against the die's HV histogram 1,172 where the flat 52 now scores 1,552, and the boot's steps of 7+ MCLK fall to 7,241. The judge now parts at **+1,230,698** (-7), another data-port read. Unchanged: the suites (148, CPython and PyPy), Nemesis's HV captures, the arms window (100 of 100). VDPFIFOTesting passes all 122 on every machine again ("FIFO Wait States", which the blank-line read release had made fail on three). Frames 6,981-7,200: all 220 found within three frames of the die's (the repeated "junk" frame at 7,089 is gone), 75 at the expected frame (the slip at 7,053 is back). The bus-arbiter test against the die: the pop's second read 2.45 to 2.55 wait states (die 3.60, MoD's hardware 3.5), its first 2.92 to 2.82 (die 2.95); against MoD's average for the whole loop 3.27 to 3.24 (3.5). Handovers 0 and 1 exact; the Z80 reads 187. ### The read release in half pixels The judge's difference at +1,230,698 is a data-port read filled at the slot at H $002 that the board let go a clock early (52 MCLK after the slot). A flat 53 or more fixes it and makes the read before, at H $1CE in the slow pixels, a clock late. Reading the limits off the boot's reads at those two slots, sweeping the release with the scratch variant helper (new trees, nothing deleted): - At H $002 (8-MCLK pixels): one read needs at least 53, another at most 53. - At H $1CE (10-MCLK pixels): one read needs at least 64, another at most 64. So the die lets the read go 53 MCLK after the one slot and 64 after the other, 11 apart. Whole pixel clocks from the slot give 10 apart (5 pixels) or 12 (6); 5 pixels + 13 and 5 pixels + 14 each leave one of the four reads a clock out (the judge parts at +1,237,075 and +1,247,792). Eleven half pixels are 44 MCLK on ordinary pixels and 55 on slow ones, 11 apart: `vdp.READ_RELEASE_HALF_PIXELS` = 11 plus 9 MCLK (`READ_RELEASE_MCLK` = 53 on ordinary pixels). The judge now agrees to **+1,373,449** (from +1,230,698), with 5,469 steps of 7+ MCLK over the first 16M where there were 7,241; against the die's HV histogram 1,302 (1,172 with 6 whole pixels), and the board's waiting reads land on the die's HV values 91 % of the time (87 % before). Unchanged: the suites (148, CPython and PyPy), Nemesis's HV captures, the arms window, frames 6,981-7,200 (220 within three frames of the die's, 75 at the expected one), handovers 0 and 1 exact, the Z80 reads (187). VDPFIFOTesting's "FIFO Wait States" (intermittent on hardware, passing on the die about once in 800) fails again on three machines; it has flipped with each of these read-timing changes. The next difference, +1,373,449, is a read filled at the slot at H $140 that the die lets go at most about 46 MCLK after it, where the board's 11 half pixels + 9 give 53: the release differs by slot beyond the pixels' speed, and $140/$142 are already special (no read is filled at $142). ### The slot at $140 The judge's difference at +1,373,449 is a data-port read filled at the end-of-line slot at H $140 that the die does not hold and the board holds 7. A new tool, `scripts/od2_read_slots.py`, takes every data-port read of the boot's first 16M MCLK whose bus cycle starts in step on both machines and waited for the read-ahead, and compares when the next cycle starts, by the slot the board filled the buffer at. Every slot agrees on every read (tens of thousands; $002, $012 ... $122 and $1CE on active lines, and the blank-line slots) but $140: 2,184 agree, 20 end 7 MCLK earlier on the die, 30 end 14 earlier. With `--slot 0x140`, by when the read began after the fill: | read starts after the fill (MCLK) | the die's read | the board's | |---|---:|---:| | 43-47 | 28 (no wait) | 35-42 | | 48-51 | 35 (one clock) | 35 | | 55-63 | 28 | 28 | So the data the $140 slot fetches is ready on the die by the time a read 43 MCLK after it needs it (the board's 53 is too late there), and yet a read starting 48-51 after it waits a clock: not a release time but a short window, about 32 MCLK after the $142 slot (which never fills a read), in which the VDP does not answer the data port. Neither a 68000 sample point nor its phase changes the boot (tried: a flat sample point breaks the read on line $1FF; with the release moved to match, every phase gives the same 5,469 steps). The boot's offsets do not reach the window's edges; a die test sweeping a read's start across $140-$142 in single master clocks is the next step. No model change in this round. ### The die sweep at $140/$142, and the refresh waiting for its end A die-only sweep (`scripts/run_read_window.py`): the read sweep cartridge's back-to-back CRAM reads, placed in the board's line by the die's /HSYNC fall (board offset 327, as the boot measures it), the die's wait tabulated by the read's start against a slot. Against the slot at H $140 (board offset 3340), with F the slot: - reads already waiting when the slot fills are let go at about F+53 (they end at 3393-3397 whatever their start), the board's release; - reads starting F+35 to F+39 wait not at all; F+43-44 wait; F+45-47 mostly not; F+48-51 a clock; from F+53 not at all. So a read can find the word before a pending one is let go. Against the slot at H $002 there is no such island: the wait shrinks steadily to nothing at F+53. The boot's offsets (the last section) put the island at 43-47, the sweep a clock or two later, within its placement; the boot's reads are lined up directly, so `vdp.READ_EARLY_MCLK` = (43, 47) for reads filled at `READ_EARLY_SLOT_H` = $140. With it every slot agrees on every in-step read of the boot (`od2_read_slots.py`), and the judge agrees to +1,446,200. There the difference was the cartridge refresh again: a ROM read after a long data-port read, due 112 MCLK before it, held 14 on the die where the last round's rule gave 7. With the reads now right, the boot's 1,020 refreshes that fall due during a held data-port read read, by how long before the next cartridge read they fell due: up to 112, 14; 119, 7; from 126, nothing (none out of line). That is a refresh running by itself from 112 to 126 and an access that starts while it runs waiting for its end, on the 68000's clock, not a flat half. With that (`board.CART_REFRESH_SELF_MCLK` unchanged at 112, the wait now to its end) the judge agrees to **+3,076,143** (from +1,446,200). Unchanged: the suites (148, CPython and PyPy), Nemesis's HV captures, the battery (but the bus-arbiter loop's figures, by a hundredth), the arms window (100 of 100), the Z80 reads (187). Frames 6,981-7,200: **199 at the expected frame** (75 before); the slip now runs 7,053-7,073 and ends on a repeat of the die's transition frame (the board's 7,073 is the picture the die shows once, at 7,052), the one frame of the window not found within three of the die's. Handovers 0 and 1 are now -1 and -15 MCLK (exact before): they come 15.7M MCLK after the reset, past the judge's first difference. ### The refresh half a period out The judge's difference at +3,076,143: a work-RAM write at +3,076,094 that the die holds 21 MCLK for the work-RAM refresh and the board does not. It ends the boot's longest stretch without a work-RAM access, +2,007,761 to +3,075,982 (just over a PAL frame), spent in the CRAM readback loop: cartridge fetches, 2,432 data-port reads (most held 98-189 MCLK) and 38 CRAM read commands ($0000, $0020), no transfers, no interrupts. The stretch begins right after a 64-word CRAM transfer from the cartridge, whose 68000 resume agrees on both machines; the board restarts its refresh 245 after the transfer's last read (+2,007,772) and runs its chain from there to a due time of +3,076,560. The die's hold puts its due time in +3,075,997-3,076,094: about half a period (450-550 MCLK) away. The die test (`scripts/run_ram_refresh.py`) reproduces every ingredient and none moves it: - **Idle** in ROM, 285,000 to 1,423,000 MCLK, NTSC and PAL: the first held read is on the 931-MCLK chain every time (+0, +28, +49, +7, +42 into the window). - **Held data-port reads** (`--vdp`, 3 to 400 CRAM reads with the display on): no restart; the chain runs on through them (out to 98 periods). - **A 64-word CRAM transfer with the display on, then idle** (`--dma 64 --cram --display-on --idle-after N`, up to 1,067,000 MCLK after it, NTSC and PAL, V28 and V30): the chain restarts 238 after the last select and runs on exactly (1,146 periods + 55 at the longest). So the rule holds in every case built so far, and something in the boot not yet reproduced resets or delays the die's refresh timer during that frame. Open. On how close the board's read timing is to the die's (Aubrey's question), three measures: in the boot, every in-step data-port read agrees with the die at every slot (`od2_read_slots.py`); against each machine's own HV counter, 91 % of the board's waiting reads land where the die's do (`run_slot_hv.py read`; the die itself puts 92 % on its commonest values); and on the read sweep cartridge run on both, line by line, 67 % of the reads wait exactly as long as the die's, nearly all the rest one 68000 clock longer or shorter in about equal numbers (1,233 and 1,163) -- the two machines' clocks meeting the VDP at different phases in that cartridge, which nothing lines up, rather than a rule. ### The refresh timer stops for a transfer Reading Nuked-MD's VDP for the work-RAM refresh, rather than inferring it from held accesses, settles the last section. In [GPL source cited, redacted] a seven-bit counter ([source name redacted]-[source name redacted]) counts 68000 clocks; at 112 ([source name redacted]) the next work-RAM access takes a refresh ([source name redacted]), at 126 ([source name redacted]) one runs by itself ([source name redacted], then the sequence [source name redacted]-[source name redacted]); a refresh resets it ([source name redacted]; its other input, [source name redacted], is the Mega Drive mode pin). It counts only while [source name redacted] is set, and [source name redacted] is not [source name redacted], the VDP holding the bus for a transfer. So a transfer **stops** the timer and it goes on from where it was; it does not restart it. The "restarts 238 after the last select" of two sections back was the test cartridge starting every transfer at the same count. - `vdp.RAM_REFRESH_PAUSES`: the board stops its refresh timer from the end of the write that starts a transfer to `RAM_REFRESH_PAUSE_TAIL_MCLK` = 14 after its last read (`board.ram_refresh_paused`). With 17 or 20 the refresh after the boot's run of four transfers (+933,688) comes too late; with 14 the boot's 68000 stream agrees with the die's to **+5,229,301** (from +3,076,143). - **Recorded, not inferred.** The harness traces the counter now (`NMD_TRACE_MASK` bit 5, type 6: the counter going back to 0, the count it reached, and whether an access took the refresh or it ran by itself; `validation/build_nuked_md.sh` builds to `NMD_BUILD_DIR` for experiments). `scripts/od2_refresh_events.py` puts every die refresh of the boot's first 5.2M MCLK beside the board's: 5,376 on the die, 5,375 on the board, each kind at a fixed offset (taken: -18/-19 MCLK; by itself: +7, -3, -47 or -61, the counter's reset coming a different time into each), and three whose kind differs: one at the reset itself and two refreshes the die runs by itself one 68000 clock before the access the board lets take it (the known clock-early refresh). Unchanged: the suites (148, CPython and PyPy), Nemesis's HV captures, the arms window, the battery but VDPFIFOTesting's intermittent "FIFO Wait States" (passing on every machine again). Frames 6,981-7,200: all 220 within three frames of the die's (no repeated transition frame), 75 at the expected one (199 last round): the slip from 7,053 now runs on to the window's end. Handovers 0, 1 and 3 within 1 MCLK of the die, 2 at -15, 4 and 5 at -120 and -43; the Z80 reads 192. ### The first read in the slow pixels The judge's difference at +5,229,301: a 32-word VRAM transfer from the cartridge on a blank line whose 68000 resume came 14 MCLK early. Its trigger write ends in the slow pixels around the sync (10 MCLK each, the DMA ticks 18-20 apart), and the board's first read came a tick early: the die skips the tick 11 MCLK after the write and reads at the one 29 after. Placing the boot's transfers by where their trigger writes end (scratchpad `firstread.py`), the die's first-read ticks want, after the write is over: at most 12 and 9, more than 1 and 7 (four transfers in ordinary pixels) and more than 11 (this one). A flat delay cannot be both at most 9 and more than 11; one pixel's length plus a constant cannot either (8 + c <= 9, 10 + c > 11). Two pixels' lengths less 8 MCLK can: 8 in ordinary pixels, 12 in the slow ones (`vdp.DMA_FIRST_READ_DIE_PIXELS`, with `DMA_FIRST_READ_DIE_MCLK` = -8 for the cartridge). Then the transfer's later reads came a tick early: its bytes paired one slot ahead of the die's, as at the boot's third transfer (the die passes up the slot 40 MCLK after its first read and takes the next), so the FIFO's delay is 41-48, not 33-48 (`FIFO_COMMIT_DELAY_MCLK` = 44). Every transfer of that stretch now ends and resumes as on the die. The judge: the streams agree to +5,233,109, part there for one cycle (a work-RAM refresh the die takes at the access after the one the board's lets take it, after three transfers in a row; the pause's tail of 14 is a few MCLK short there, and 17 or more breaks the run of four at +933,688 -- a single tail does not fit both; counting the pause in whole 68000 clocks, tried, fits neither), agree again to +7,649,439, part for one read (-210), and agree again to +9,512,769. Unchanged: the suites (148, CPython and PyPy), Nemesis's HV captures, the Z80 reads (192). Frames 6,981-7,200: 219 within three frames of the die's, **183 at the expected one** (75 last round). The arms window: 99 of 100, frame 5,805 a single pixel at (0, 40), a CRAM write's dot at a line's start, downstream of the Z80, which parts from the die long before. VDPFIFOTesting: "0 fail that pass on hardware" on every machine; the intermittent "FIFO Wait States" now fails on the Mega Drive machines and passes on the Genesis ones, and the Genesis 3 fails 8 (its VSRAM tests, as the hardware does) where it failed 9. `run_dma_cost`'s VRAM 128 KB blanking figure 405.7 to 405.0 bytes a line. Handovers 0-3 within 12 MCLK of the die's. ### The VBLANK flag a pixel late The judge's step at +7,649,439: the boot's poll for the end of vblank left its loop one pass (210 MCLK) earlier on the board. Frame by frame (scratchpad `vblank_polls.py`), the status reads bracketing each VBLANK flip agree on both machines for the boot's first six frames; at the seventh the die's read at +7,649,145 still sees VBLANK and the board's sees it clear. The board's line $1FF begins at +7,649,155, and its status read samples at the first pixel edge at or after the read plus 3 MCLK (`HV_SAMPLE_DELAY`, fitted to hardware), which is exactly that line's first edge. So the die's flag clears later than the line begins: at least a pixel, by this read, and at most about a pixel, by the frames before. Placed against each machine's own HV counter (`scripts/run_slot_hv.py status --pal`, now with `--v30` and `--frames`, and VBLANK changes listed), the two clear and set VBLANK at the same H to within one step, the die's never earlier, in PAL V28 and V30 alike. Nemesis's hardware captures lean the other way: in two PAL H40 samples the hardware reads VBLANK clear where the board still has it set. So the die-figures machine only (`nuked-md`; Aubrey's call to match the die there) keeps VBLANK set for the first pixel of line $1FF (`vdp.VBLANK_CLEAR_DIE_PIXELS` = 1). The boot's 68000 stream agrees with the die's to +9,512,769 but for the one-cycle refresh at +5,233,109. Unchanged: the suites (148, CPython and PyPy), Nemesis's HV captures, the battery's output, the arms window (99 of 100) and frames 6,981-7,200 (183 at the expected frame). ### The refresh timer's pause, edge by edge The judge's step at +9,512,769: the board's work-RAM write took a refresh the die's did not. Matching every die refresh to the board's nearest (`scripts/od2_refresh_events.py`, and a scratchpad `offsteps.py` that prints where the offset between the two chains changes) showed the board's chain moving against the die's once a frame from +2.0M on, at each frame's transfers: +7, -3, -47, -61, -21, -35, -34, -43 MCLK, until at +9.51M a refresh fell on the wrong side of a write. The transfers themselves agree (first read, last read and the 68000's resume). Only the length of the timer's pause did not. The die says exactly how long. Its refresh trace gives the count the counter reached at each reset, so a refresh-to-refresh interval less 7 per clock counted is the time it stood still. Its /BGACK (traced already, `NMD_TRACE_MASK` bit 2, signal 3) is the counter's own gate: [GPL source]'s [source name redacted]-[source name redacted] count while [source name redacted] = not [source name redacted], and [source name redacted] is [source name redacted] too. Over the boot's 25 transfers to +9.5M /BGACK falls 40 MCLK after the /AS of the write that starts the transfer, every time (41 once), and rises 15-16 after the board's last read; the board paused from 49 to 14, counting master clocks. Three changes, each needed: - **Whole clocks.** The pause is the 68000 clock edges between its ends, not the master clocks (`board.ram_refresh_paused`). Without it the judge stops at +9,512,797. - **A self-run under way goes ahead.** At +928,786 the die's counter had reached its self-run count as /BGACK fell; the refresh ran 30 MCLK into the transfer and the counter started again from it. The board held that refresh until after the transfer and lost the run of four transfers there. Now a self-run that began up to 14 MCLK into the pause runs, and only the pause in the 112 clocks after it delays the next (`RAM_REFRESH_COUNT_MCLK`). Without it the judge stops at +933,737. - **The ends, on the edges.** Which edges the die skips depends on where /BGACK falls against the clock, so the ends were fitted over every edge phase: 147 pairs, start 34-40 by tail 9-15, three margins. Start 35 and tail 9 alone keep the board's refreshes within one 68000 clock of the die's from the reset to +9.54M (self/self offsets 7, 0, -7 only, where they had wandered to -61). Both are 5 short of the /BGACK edges on the trace's clock, consistent with the board's anchor putting its edges a master clock from the die's. The judge: the boot's 68000 bus stream agrees with the die's to **+12,712,161**, and the one-cycle refresh at +5,233,109 is gone. The refresh tool to +9.51M: die 9,969, board 9,968, kinds differing at 3 (all before +0.72M). Unchanged: the suites (148, CPython and PyPy), Nemesis's HV captures. The arms window: **100 of 100** (99). VDPFIFOTesting: 0 fail that pass on hardware on every machine; the intermittent "FIFO Wait States" passes on the Mega Drive machines again. Frames 6,981-7,200: all 220 within three frames of the die's (219), but **75 at the expected one** (183): the step at 7,053 is the same, and where the board came back at 7,090 it now parts again three frames later -- far downstream of where the Z80 parts from the die. ### The tick 8 after The judge's step at +12,712,161: the boot's 68000 resumed 14 MCLK early after the line-227 transfer from the cartridge to CRAM (64 words) that every frame makes, all of whose reads came 16 MCLK (one tick) early on the board. The same transfer had been exact in the frames before. Placed in its line (a scratchpad listing of each transfer's start, the board's earliest first-read point and the tick it reads at), the trigger write began at 167 MCLK into the line; at 165 and 166 in earlier frames the earliest point fell 1-2 MCLK short of the tick at 224, and this time on it. The board read there; the die passed it up and read at the next. In the terms of "The first read in the slow pixels" this is a tick 8 MCLK after the write is over that the die skips -- more than 8, with at most 9 from before: exactly 9 in ordinary pixels. So the cartridge's first read waits two pixel lengths less 7, not 8 (`vdp.DMA_FIRST_READ_DIE_MCLK`); in the slow pixels that is 13, still more than the 11 the +5,228,195 transfer wants. No other transfer of the boot moves. The judge: the boot's 68000 bus stream agrees with the die's to **+14,245,189**. Unchanged: the suites (148, CPython and PyPy), Nemesis's HV captures, the battery's output, frames 6,981-7,200 (all 220 within three frames, 75 at the expected one). The arms window: 98 of 100 (100): frames 5,769 and 5,800 each one pixel off, the kind of single dot frame 5,805 had two rounds ago -- far past the judge's reach and where the Z80 parts from the die. ### The E clock after a held push The judge's step at +14,245,189: the boot's level-6 interrupt entered 21 MCLK late on the board. On the die the PC push at +14,245,042 is held 21 MCLK (a work-RAM refresh), then the acknowledge cycle at $FFFFFC is held 42 for the E clock, and the SR push follows at +14,245,189; the board's SR push came at +14,245,210. The core times an autovectored acknowledge from its own clock count (`M68000CPU.clock` plus the instruction's clocks so far, mod 10), and the board, which holds bus cycles out of band (`board.stall`), adds those clocks to `clock` only when the instruction ends -- so an acknowledge after a held push saw the E clock 3 clocks behind. The boot's one earlier interrupt entry (+390,635) had no hold before it and agreed. `System._acknowledge` now credits the instruction's holds so far before the core reads the clock (and the step adds only the rest). The judge: the boot's 68000 bus stream agrees with the die's to **+15,263,346**. Unchanged: the suites (148, CPython and PyPy), Nemesis's HV captures, the battery's output. Frames 6,981-7,200: **182 at the expected frame** (75); 219 within three frames (220): frame 7,090, where the board comes back in step after the step at 7,053, now changes part way down, matching none. The arms window: 99 of 100 (98), frame 5,806 a single pixel. ### Under the /REF pulse The judge's step at +15,263,346: the boot copies bytes into Z80 RAM in a loop (a cartridge read, then a write to $A0xxxx), every write held 7 MCLK on both machines, but at +15,263,304 the die held the write 14. The cartridge read before it, at +15,263,262, took a refresh on both (held 14; on the board it fell due exactly at the read's /AS). With the die's cartridge refresh pin traced (`NMD_TRACE_MASK` bit 2, signal 4, the arbiter's `ext_ref`), the /REF pulse of a refresh that stretches a cartridge access runs from 39 to 46 MCLK after the refresh fell due; the stretched access lasts 42 when the refresh fell due at its /AS, so the next access starts under the pulse. In the boot to +15.26M that happened before thousands of cartridge accesses, never held, and once before a write to the Z80's space -- this one, held a clock more. After a refresh due a clock before /AS the pulse ends 3 MCLK before the next access, and the one such write in the boot is held 7. So a Z80-space access starting under the pulse waits a 68000 clock, as one the refresh falls on does (`board.CART_REFRESH_PULSE_END_MCLK`). One instance in the boot: the rule is the pin's timing, not a fit to it. The judge: the boot's 68000 bus stream agrees with the die's to **+15,729,329**; 5 steps in the 16M MCLK span. Unchanged: the suites (148, CPython and PyPy), Nemesis's HV captures, the battery's output. The arms window: 99 of 100 (frame 5,830 a single pixel). Frames 6,981-7,200: all 220 within three frames (219), **75 at the expected one** (182) -- the window has swung between 75 and 183 on four of the last five rounds, each fix far upstream of it: the board comes back in step after the step at 7,053, or does not, on a knife edge. ### The tie at 112 The judge's step at +15,729,329: the die's read of $FFFFEE took a work-RAM refresh the board's took one access later. The board's refresh chain holds within ±7 MCLK of the die's through +15.74M, so the chain was not it; nor was the interval after a taken refresh, or an allowance for a late take: each fixed this step and broke +391,419. The harness now says where the take is decided (`NMD_TRACE_MASK` bit 6: at each work-RAM /AS the refresh counter, the count a half-MCLK step before, the VDP's H and V counters, how long H has held its value, the half-MCLK since the dot clock last changed, and [source name redacted]; and [source name redacted] setting). In the boot every access that sees 111 misses the refresh and every one that sees 113 takes it; at 112 two take it and two do not, and in all four the counter steps from 111 to 112 in the very half-MCLK the /AS falls in. [source name redacted] latches "count >= 112" on the /AS, and Nuked-MD evaluates the VDP's logic -- the counter and [source name redacted] with it -- only on the edges of the dot clock the FC1004 feeds it ([GPL source cited, redacted] calls `VDP_ClockDCLK2` with phi1/phi2 only when [source name redacted] changes). So which of the two it sees first is the dot clock's business. `scripts/run_refresh_tie.py` runs a loop of NOPs (and an `exg`) from work RAM, every bus cycle a work-RAM access, with a Z80-RAM write for an odd clock (bus cycles are an even number of clocks apart, so without one the count at every /AS keeps one parity and never meets the step), over 48 loop shapes, display on and off. Of 37,840 ties, every one is taken when the dot clock changed in the /AS's half-MCLK (20,797) and none when it last changed 1 or 2 MCLK before (17,043). Mapped back, the dot clock changes every 2 MCLK but in each run of long pixels runs at MCLK/5: two windows of 30 edges 3 and 2 MCLK apart, 4 and 87 MCLK into each run (1,680 edges on an H40 line, the die's every one). Those are on the VDP's internal H counter, 15 MCLK behind the H the board's line follows (the HV counter as read): at the boot's tie at +391,391 the die's counter reads $106 5 MCLK in where the board is at $108 4 MCLK in. The nuked-md machine now takes a refresh due 7 MCLK after an access's /AS (the tie, in the board's terms) when the dot clock changes at the /AS (`board.RAM_REFRESH_TIE_MCLK`, `vdp.dot_clock_edge`, `DOT_CLOCK_SLOW_WINDOWS`, `DOT_CLOCK_LINE_LAG_MCLK`); the other machines keep the board's rule, a tie being an artifact of the die-derived model's evaluation order. In H32 the dot clock is not mapped; there a tie is not taken. The judge: the boot's 68000 bus stream agrees with the die's to **+15,912,792**; all four ties of the boot go the die's way. Unchanged: the suites (150 with the two new checks, CPython and PyPy), Nemesis's HV captures, the battery's output, frames 6,981-7,200 (all 220 within three frames, 75 at the expected one). The arms window: **100 of 100** (99). ### The bus request, sampled The judge's step at +15,912,792: the 68000 asks for the Z80's bus at +15,912,659 and writes Z80 RAM at +15,912,757; the die holds the write 7 MCLK (the Z80-space clock), the board 14 -- it had not yet let the 68000 have the bus. On the die (`NMD_TRACE_MASK` 7: signals and Z80 bus cycles) /BUSREQ falls at +15,912,677, the Z80's write cycle at +15,912,686 ends at +15,912,701 and /BUSAK changes at +15,912,708: 49 MCLK from the write, under the 69 the `busack` probe's 142 grants never went below. The board's Z80 had run that instruction to +15,912,701, 42 MCLK after the request, and with `Z80_BUSREQ_LAG_MCLK` = 48 waited for the next instruction's first cycle end (+15,912,761). 33 is the figure the die's /BUSREQ (18 after the write) and the Z80's last-clock sampling (15 before a cycle's end) give; 48 was a refit to the mean of the `busack` probe's grants, a Z80 reading the bank window, whose cycle ends the board's probe places only roughly ("The Z80's bus grant": the shape was never the die's). Back to 33: the boot's 68000 bus stream agrees with the die's over the whole 16M MCLK the judge looks at -- no step at all. `busack`'s board mean goes from 12.5 68000 cycles to 9.4 (the die's 12.55): the bank reads' cycle ends in the probe are the open question there. Unchanged: the suites (150, CPython and PyPy), Nemesis's HV captures, VDPFIFOTesting on every machine, frames 6,981-7,200 (all 220 within three frames, 75 at the expected one), the arms window (100 of 100). Changed: MoD's `gen_test_z80_bus` prints its "Delay with 6T M-cycle" counter 0000 (0001; "BUSACK delay" stays 0001) -- no hardware value is published for either (docs/undocumented-behavior.md, item 8). ### The first read from work RAM The judge now looks past 16M: `reference/z80-reset/t.bin` (the die from the reset, every 68000 cycle) runs to +58,793,791 after the anchor, so `--span 58700000` (7 minutes on PyPy). Its first step was at +16,094,512: the boot's first transfer from work RAM, 16 words to CRAM on blank line $1DC, after which the board's 68000 resumed 14 MCLK late, its reads all one DMA tick late. The work RAM's first read had a flat 25 MCLK after the trigger write is over, from one probe at 74 MCLK from the write's /AS -- a memory select, which on the die comes 5 MCLK after the board's DMA tick for the same read. `scripts/run_dma_first_read.py` starts a 16-word transfer from $FF0000 to CRAM again and again, the delay before each one pass longer, so the trigger walks every phase: the die's first select comes 63-110 MCLK after the trigger's /AS, the board's first read with the cartridge's rule (two pixel lengths less 7 after the write is over) 58-105, the same 5 MCLK apart over the whole range, display off and on. One rule for both sources now (`vdp.DMA_FIRST_READ_DIE_MCLK` = -7, `DMA_FIRST_READ_DIE_PIXELS` = 2). The judge: the boot's 68000 bus stream agrees with the die's to **+16,099,013** (the old 16M window clean, as before). Unchanged: the suites (150, CPython and PyPy), Nemesis's HV captures, the battery's output, the arms window (100 of 100), frames 6,981-7,200 (all 220 within three frames, 75 at the expected one). ### The timer flag on the die The judge's step at +16,099,013 was the Z80's: the board's Z80, in step with the die's read for read and MCLK for MCLK from the driver's start (+15.73M), left its Timer A wait one poll (255 MCLK) early at read 190 (+15,740,246), went another way, and at +16,099,031 read the 68000's bus where the die's did not -- 70 MCLK the board charged its 68000. The board's status showed the flag where the die's did not yet. `scripts/run_fm_timer.py` takes the Z80's bus and, over and over, sets Timer A to $3FF (or `--timer`), loads it ($27 = $15), polls the status, resets the flag with $27 again and polls again, a delay growing each pass so the writes walk the FM's sample; and a scratchpad comparison took the exact times on both (the die's `NMD_FMSIG` latch, the board's flag), each against its own FM slot. The load raises the flag in the same slot and MCLK on both, at every slot but one: a load written in slot 1 rises a whole sample later on the die. That is the die's register write taking effect later than the board's (the YM3438 core's write path is not the ASIC's): with $27's timer bits two cycles later on the die-figures machine (`ym2612.TIMER_CONTROL_DELAY_CYCLES`) all 325 loads match, where nine came a sample early; the resets now show 133-147 MCLK after the write against the die's 126-196 (they were 70-147). Timer A at $3FE, Overdrive 2's, matches the same. None of it moved Overdrive 2's read 190: the timer was right, the FM's sample clock was not -- see the next section. ### The FM's restart, swept Against the die's slot-23 markers the board's FM is in step all through the console reset and five slots (209 MCLK) ahead after the boot's last, short /IC pulse (+14,519,124-726, a write to $A11200 each way): the board restarted its slot counter where the die's only paused. `scripts/run_fm_ic.py` asserts /IC by a write to $A11200, holds it 0.2, 0.6, 2.3 or 8.8k MCLK, releases it and lets the FM settle, the walk putting the assertion at every phase; the FM's phase is taken before and after, on the die from its markers, on the board from its slot counter. The answer does not depend on the pulse's length. By where the write's bus cycle begins in the FM's slot: at 0-6 MCLK a pause (the sample shifts 84), 7-27 a restart (slot 0 125 MCLK after the write), 28-41 a pause (70 and 77). The board had the restart one FM clock late, 14-34: its sampling lag (`IC_SLOT_LAG` = 3) is the console button's, and a write's is 0 (`ym2612.IC_WRITE_SLOT_LAG`, the pause's look-ahead taken from the same sampling point). Every cell of the sweep now agrees. Overdrive 2: the board's FM is in step after the pulse, and the two Z80s agree for **6,968 reads** (190 before), to +16,141,646. The judge's first step is +16,099,363: the die's arbiter takes the 68000's bus for a Z80 access to it (/BGACK low 49 MCLK), and the board charges the same 70 MCLK one instruction later (its rule of charging the Z80's bank accesses at the 68000's next step) -- the streams are back in step at +16,099,461. Unchanged: the suites (151 with the new check, CPython and PyPy), Nemesis's HV captures, the battery's output, the arms window (100 of 100). Frames 6,981-7,200: **110 at the expected frame** (75), 218 within three frames (frames 7,054 and 7,091 change part way). ### The Z80's grant inside an instruction The judge's step at +16,099,363: the die's Z80 asks for the 68000's bus at +16,099,241 (a read of the VDP's HV counter through $7F08); the 68000's cycle at +16,099,251 starts within the arbiter's cut-off and goes first; /BGACK is low from +16,099,290 to 339; the 68000's next cycle, in the same instruction, waits 70 MCLK. The board ran the Z80 only after each 68000 instruction and owed the 70 to the next instruction. `board.Z80_CATCH_UP_EACH_CYCLE`: before each 68000 bus cycle at t the cycle goes into the arbiter's grid and the Z80 is brought up to t less the cut-off (21 MCLK), so a Z80 access asked for before then wins the bus and moves this cycle back as the arbiter moves any 68000 cycle past a grant (a second Z80 access then waits behind it), and one asked for within the cut-off loses to this cycle and is settled at the next. The end-of-step catch-up stops at the cut-off too (+16,123,466: the die's 68000 cycle 12 MCLK after the Z80's request goes first). The 68000 drives /AS only once it has the bus back, so the judge stamps such a cycle at its new start (`board.grant_wait`). The judge: the boot's 68000 bus stream agrees with the die's to **+16,143,617**; 116 steps over the 58.7M MCLK window (187). The two Z80s agree for **7,833 reads** (6,968), to +16,194,026. The cost, on `run_nuked_md.py arbiter`'s die figures: the 68000 stopped, unchanged (2.49, the die's 2.25); the `jmp (a0)` loop with the Z80 reading, mean unchanged (2.86, the die's 2.74) but 2/3/4 waits 27/63/7 % against the die's 38/49/12 (39/40/18 before); the pop's first read 2.59 (2.82; the die's 2.95), its second 2.56 (2.55; 3.60). The reason: a Z80 instruction still runs only once its last access is past the cut-off, so an early bank access in an instruction of several (the pop's first read) is still settled late. Arbitrating each access by the access-timing table's offsets before the instruction runs is what remains. **And a correction.** `run_bus_arbiter.py`'s 68000 rate summed each step's `stall + owed after - owed before`, which over a run is the stalls alone: the Z80's holds, all owed until now, were never counted, and the 481.0 "with every stall the board charges" quoted against Kabuto's "roughly 480" (docs/timing.md, validation.md) was the refreshes alone. Counting each step's own stalls and the owed it begins with: 481.0 with the Z80 in its own RAM -- the comparison Kabuto's figure supports -- and 357.8 with it reading the bank window, the same before this change (360.5) and after. The script now gives both. Unchanged: the suites (151, CPython and PyPy), Nemesis's HV captures, VDPFIFOTesting, the arms window (100 of 100), frames 6,981-7,200 (all 220 within three frames, 75 at the expected one). `busack`'s board mean 9.71 (9.39). ### Each access arbitrated at its own time The last round left the arbiter experiments' `pop` a little further from the die's: a Z80 instruction runs only once every access of it is before the 68000's clock less the cut-off, so the first of a `pop`'s two bank reads was settled when the second's time had come, the 68000 cycles in between already run without it. z80-python steps whole instructions, so the instruction itself cannot be split. `system.Z80_ARBITRATE_PER_ACCESS`: where the catch-up leaves an instruction for later, its accesses over the 68000's bus that begin before the horizon are arbitrated now, at their own time (`System._prearbitrate`, the instruction probed once for where they fall -- the probe's machine-cycle start plus a T-state, the access-timing table's place), and the instruction takes their recorded waits when it runs (`Board._bank_delay`, the arbitration itself now `Board._arbitrate`). The probe is skipped when no access past the opcode's own fetches comes before the horizon, so the judge's run is no slower. `run_nuked_md.py arbiter`, the board against the die: the 68000 stopped, unchanged (2.49; 2.25); the `jmp (a0)` loop with the Z80 reading, unchanged to the count (2.86; 2.74); the Z80 popping, **3.17** (2.57; the die's 3.27), the first read **2.96** (2.59; 2.95), the second **3.37** (2.56; 3.60, and MoD's hardware "at least 4", mean 3.5). `run_bus_arbiter.py`'s pop: the 68000's delay 10.94 cycles a read (9.80). Unchanged: the judge (+16,143,617, 116 steps over 58.7M), the Z80s' 7,833 reads, the suites (151, CPython and PyPy), Nemesis's HV captures, VDPFIFOTesting. Frames 6,981-7,200: **217 at the expected frame** (75), 219 within three frames (frame 7,055 changes part way). The arms window: 99 of 100 (frame 5,771 a single pixel). ### The grant over the 68000's own clocks The judge's step at +16,143,617: the die's Z80 asks for the bus at +16,143,521 (a read of $7F08), just after the 68000's last cycle of a taken branch began; that cycle goes first, the Z80 has the bus from +16,143,544 to 593, and the 68000's next fetch comes at +16,143,617. The board settled the access at the end of the 68000's instruction and owed the 70 MCLK from the next one's start -- where the 68000 first spends two clocks inside itself, so its fetch came 14 MCLK late. `system.OWED_AT_FIRST_CYCLE`: a hold owed from a Z80 access settled after an instruction is now a time the bus is the Z80's until (`board.m68k_resume_at`), which the 68000's next bus cycle waits for; its own clocks before that overlap the wait. Not bringing the Z80 up at the end of an instruction at all, settling it at the next instruction's first cycle instead, was tried: the same judge, but the `pop` back to 2.92 (first read 2.80, second 3.04) where this keeps 3.17 (2.96, 3.37) -- so the end-of-instruction catch-up stays. The judge: the boot's 68000 bus stream agrees with the die's to **+16,155,720**; **52 steps** over the 58.7M MCLK window (116). The two Z80s still agree for 7,833 reads. `run_bus_arbiter.py`'s rate now counts the 68000's own clocks (each step's time less its stalls) and takes the rest of the run as lost, whichever way a hold was paid: 480.9 a line with the Z80 in its own RAM, 357.3 with it reading the bank window (481.0 and 357.8 as counted before). Unchanged: the arbiter experiments' figures (`run_nuked_md.py arbiter`, to the count), the suites (151, CPython and PyPy), Nemesis's HV captures, VDPFIFOTesting, the arms window (100 of 100). Frames 6,981-7,200: all 220 within three frames, 75 at the expected one (217) -- the same knife edge downstream, the other way again. ### The Z80's cycle a master clock shorter The judge's step at +16,155,720: the die's Z80 reads the VDP's HV counter through $7F08 at +16,155,626; the 68000's cycle 3 MCLK later goes first; /BGACK is low from 654 to 696, the Z80's cycle on the 68000's bus +16,155,664-693, and the 68000's next read comes at 720, held 14 by the cartridge refresh. The board's came at 734 -- two things: - **The refresh.** One fell due inside the Z80's cycle (+16,155,678), and the board let that cycle take it, 14 MCLK longer, and then the 68000's read took it again. On the die a Z80 access to the VDP is not held by the refresh and the 68000's next cycle takes it, as the 68000's own VDP accesses go unheld. `board.Z80_REFRESH_CARTRIDGE_ONLY`: only a Z80 access that lands on the cartridge (the bank window below $800000) takes it; the probe now records each bus access's target for the per-access arbitration. Without it the judge parts at +16,179,933 on just such a double hold. - **The Z80's own cycle.** The arbiter lets the 68000 have the bus back 25 MCLK after the Z80's wait runs out, at the first of its clocks at or past the end of its own cycle (start plus `arbiter.OWN_CYCLE_MCLK`). With 30 that end fell at 694, one master clock past the die's 693, and cost a whole Z80 clock (resume 733). 29 fits both this grant and the 38-MCLK one at +16,099,290 (24-29 do), and leaves the arbiter experiments as they were (27 and below move them). Taking the resume from the Z80's own cycle instead, tried, breaks the earlier grants (223 steps). The judge: the boot's 68000 bus stream agrees with the die's to **+16,179,975**; **22 steps** over the 58.7M MCLK window (52). The two Z80s agree for **8,033 reads** (7,833), to +16,206,146. `run_nuked_md.py arbiter`: the 68000 stopped 2.49, the `jmp (a0)` loop 2.86 (the same counts), the pop 3.16 (3.17), its reads 2.96 and 3.36. `run_bus_arbiter.py`: the 68000's rate with the Z80 on the bank window 360.3 (357.3). Unchanged: the suites (151, CPython and PyPy), Nemesis's HV captures, VDPFIFOTesting, the arms window (100 of 100), frames 6,981-7,200 (all 220 within three frames, 75 at the expected one). ### The refresh a Z80 cycle uses up The judge's step at +16,179,975: the die's Z80 reads the HV counter through $7F08 at +16,179,836; /BGACK is low from 860 to 909, the Z80's cycle on the 68000's bus begins at 870, and the 68000's next read, of the cartridge at 933, is not held. A cartridge refresh fell due at 870 -- the die's grid, placed from the 68000's held cartridge reads over the whole window, puts its ticks in a 7-MCLK bracket ending there. The board's Z80 cycle let it pass (a VDP access is not stretched by it, `Z80_REFRESH_CARTRIDGE_ONLY`), and the 68000's read took it: held 14, its next 14 late. `scripts/od2_z80_refresh.py` counts, for every Z80 cycle on the 68000's bus over the +58.7M window with a tick from 28 MCLK before to 35 after its start, the 68000's next access and its hold. Of the 1,809 with a cartridge access next, every one goes the same way, whether the Z80's cycle is a cartridge read (1,528) or an HV read (281): a tick due by the Z80 cycle's start is used up by it, and the 68000's next cartridge access is not held; one due after it began falls on the 68000's next cartridge access, held 14. That is the +16,155,720 case (due 14 after the Z80's start, the 68000 held) and this one (due at its start, not held) in one rule, and the same "next bus cycle" rule Kabuto gives for the 68000's own accesses. `board.Z80_REFRESH_USED_UP`: a Z80 cycle that begins at or after a tick still owed now moves the refresh on (`cart_refresh_due`), so the 68000 does not take it again; a cartridge access is stretched by it as before, a VDP access is not. The board had, besides this case, let the 68000 take again a tick a Z80 cartridge cycle had already been stretched by. The judge: the boot's 68000 bus stream agrees with the die's over the whole +58.7M MCLK window the referee trace covers -- **no step** (22), the 476,359 aligned cycles every one at the die's time. (Wrong: the board's stream ended at +16.2M; the judge agrees to +16,244,508 -- "The judge's reach, corrected" below.) The two Z80s agree for **9,521 reads** (8,033), to +16,308,956, where the die's Z80 reads the FM's status as $01 and the board's, 45 MCLK ahead by then, $00. `run_nuked_md.py arbiter`: the 68000 stopped 2.49 (the same counts); the `jmp (a0)` loop 2.74 (2.86), the die's 2.74; the pop 2.93 (3.16) where the die has 3.27, its reads 2.77 and 3.09 (2.96 and 3.36; the die's 2.95 and 3.60). The double hold had stood in for some of the pop's second-read wait; what the die's second read waits on beyond this is open. `run_bus_arbiter.py`: 480.9 and 360.3 a line, unchanged. Unchanged: the suites (151, CPython and PyPy), Nemesis's HV captures, the rest of the test-ROM battery, the arms window (100 of 100), frames 6,981-7,200 (all 220 within three frames, 75 at the expected one). ### The judge's reach, corrected The judge has not looked past +16.2M since it was "extended to +58.7M". `--span` was raised, but the board's run length, `--until`, kept its default of 42.8M MCLK from power-on -- about +16.2M after the reset anchor -- so the board's stream ended there, and difflib aligned what it had against the die's whole window and reported nothing past it. Every figure "over the 58.7M window" from "The first read from work RAM" on (187, 116, 52, 22 steps, and "no step") counted steps over about +16.2M; the rules those sections found stand on their own die evidence, the window does not. The 476,359 "aligned" cycles, the same in every run, were about the board's stream's length. - `--until` now follows the span (past the reset and the span, 1M MCLK to spare), and the judge says when a stream ends short of it. - difflib's alignment is gone. Over the real window it ran for hours: once the two streams take different paths, its search goes quadratic. `scripts/drift_walk.py` walks the two streams together from their anchors, prints every step as before, and stops at the first cycle where they part in address or kind -- the place a path difference is named, and the last place the two can be compared one to one. It steps over the die's interrupt acknowledges (a read with A23-A4 high), which the board does not log as bus cycles. It also counts the cycles whose data differ, which no judge looked at before. `--save` keeps both streams for another look without a rerun. The judge over the real window: the boot's 68000 bus stream agrees with the die's to **+16,244,508**, where the board's 68000 resumes 14 MCLK late after the die's Z80 reads the HV counter through $7F08 (/BGACK low +16,244,442-484, the die's next read at 508, the board's at 522; no refresh in it). 2,105 steps follow, and the paths part at +16,982,364: a status poll for vblank, the board 147 MCLK behind by then, leaves its loop a pass before the die's. The data the walk compares: the board's status reads have zeros in bits 15-10 where the die's carry the open bus ($6609 against $0009), and on a byte access the die logs the byte on both halves of the data bus where the board's log has it on one -- the second a logging difference, the first not yet looked at. ### A second title Everything since the narrowing (2026-10-03) was judged on one boot. To see whether it is the machine that has been learnt or Overdrive 2, three other cartridges from the local No-Intro set run from power-on on both, judged the same way: `scripts/cold_boot_drift.py ROM --span N` (Nuked-MD from power-on, PAL; the board's nuked-md machine; the streams walked from the cycle after the vectors and the first prefetch). Two things the board cannot know are set from the die, as `run_nuked_md.py`'s probe comparisons have always set them, and nothing else is: - **The clock.** The die holds its 68000 in reset for about 693,000 MCLK after power-on and the board's starts at once. The board's clock is moved on so that the first walked cycle falls 240,277 MCLK before the die's (453,149 against 693,426): the relation at which the two VDPs, each running from power-on, line up ("The VDPs' offset", every one of the Overdrive 2 boot's 16,427 HBlank flags), and the 68000's and Z80's clock edges fall where the die's do against its VDP. Put equal at first, the two clocks left the VDPs 70 lines and 877 MCLK apart, which nothing before each game's first interrupt showed but the status reads' HBlank bit and Sonic's first refresh tie. - **The refresh phases.** The cartridge refresh runs free, so every held cartridge access brackets its phase: due after the access before, by the held one's /AS. `run_nuked_md.referee_refresh` takes the first phase with no miss -- the bracket's start, 518 for Sonic -- and the die's /REF pulse at +51,141,633 (39 MCLK after the tick) puts it at 524, the bracket's end, on a held read's /AS; with 518 the board missed the pulse's extra 68000 clock on the Z80-RAM write after it. The tick is now placed at the bracket's end. The work RAM's refresh, which transfers pause, is fitted over the first 5M MCLK only; fitted over the whole run it misplaced 39,438 of Gunstar Heroes' ticks and put the start out. One rule was missing, and the first of them found it at once. **A bus request made while the Z80 is held in reset** is granted only after the reset is released and the Z80's first M1 cycle has run: Sonic asks for the bus at +6,850, releases the reset at +6,906, the die's Z80 fetches at +6,945 and /BUSAK falls at +6,997, so the 68000's first poll of $A11100 reads "busy" and it goes round once more. The board already ran that M1 cycle (`System._z80_resume`) but kept the grant the request made in reset (57 MCLK on), and its poll read "granted". `system.Z80_BUSACK_AFTER_RESET`: the grant moves to that M1 cycle's end, 3 MCLK on, as at any other. Overdrive 2 does not do this inside the judged window. Test: `test_a_request_made_in_reset_is_granted_after_the_first_m1`. With it, from power-on: | Cartridge | agrees with the die to | 68000 cycles walked | the paths part | | --- | ---: | ---: | --- | | Streets of Rage 2 (USA) | +139,046,873 | 4,359,546 | +139,528,893: the board's 68000 takes a level-6 interrupt 112 MCLK before the die's | | Gunstar Heroes (USA) | +96,496,519, no step | 2,839,693 | +96,496,561: the FM's busy flag, read at the same MCLK, busy on the die, not on the board | | Sonic The Hedgehog (USA, Europe) | +51,931,635 | 1,621,466 | +55,396,404: the same FM read | Sonic and Gunstar run a ROM checksum first (a four-word loop over the ROM, both still in it at +30M), and none of the three takes an interrupt before +55M (Sonic), +96.7M (Gunstar): it is past those that the rules are being tested -- the start-up of each game's sound driver, its first frames, Gunstar's first DMA-heavy scenes. Nothing found on Overdrive 2 had to change for them. The Streets of Rage 2 HBlank bits a first version of this section left open (the board's flag 931 MCLK from the die's with the display off) were the VDPs set 877 MCLK apart in the line, not a question for hardware: with the 240,277 relation Streets of Rage 2's status words with a different HBlank bit fall from 374 to 33, and Sonic's from 2,079 to 181 (most of those now bit 9, the FIFO's empty flag: $088B on the die, $0A8B here). Both are left for a later look; no judge sees them. Unchanged: the judge over Overdrive 2 (+16,244,508, 2,105 steps, the paths part at +16,982,364), the suites (153 with the new test, CPython and PyPy), Nemesis's HV captures, VDPFIFOTesting on every machine, the arbiter experiments, the arms window (100 of 100), frames 6,981-7,200 (all 220 within three frames, 75 at the expected one). Changed: MoD's `gen_test_z80_bus` prints its "Delay with 6T M-cycle" counter 0001 again (0000), on every machine -- the rule is the Z80's, not the nuked-md machine's. No hardware value is published for it, and the die cannot give one: on Nuked-MD the ROM's 68000 makes no bus cycle at all from about +2.5M MCLK, once its Z80 tests begin, and nothing is printed. ### The tie after the self-runs Sonic's step at +51,931,635: the die's work-RAM read at +51,931,586 is held 21 and the board's is not. The die's refresh counter, at that /AS (the harness's mask bit 6), steps from 111 to 112 as the dot clock changes: a tie, and taken (the rule of "The tie at 112"). The board's due there, +51,931,593, was the die's to the MCLK -- 7 after the /AS -- but only once the refreshes that had run by themselves since its last access were counted in (the RAM had been left alone for 7,800 MCLK, eight self-runs). The tie was judged before that, against the due as last stored (+51,924,145), so it was never even tried. `board.RAM_REFRESH_TIE_AFTER_SELF_RUNS`: the self-runs are counted first (`board.ram_refresh_self_runs`, which `ram_refresh` now uses too), then the tie. Test: `test_the_tie_is_judged_after_the_self_runs`. Overdrive 2's work RAM is never idle that long before a tie, so its judge did not see it. On the way, Sonic's run tabulated the die's counter at every work-RAM /AS from +45M to +60M (61,826 accesses) against what each one waited: 113-126 taken, 21; 127, 35 (the self-run about to start); 0, 1, 2, 3 after it began, 28, 21, 14, 7; 112 either way, the tie. The board's windows give every one of those, reading its due as the step to 113. After a take the counter starts again so that 113 falls 819 MCLK after the taking /AS, as `RAM_REFRESH_AFTER_MCLK` has it. Sonic now agrees with the die to +55,151,173, its first interrupt. There the board's autovectored acknowledge was 49 MCLK shorter: `cold_boot_drift` moved the board's clock on without the 68000's own count of clocks, from which the core keeps its E clock. A 68000 clocked from power-on through the die's reset hold has run those 64,695 clocks too, and with them counted the acknowledge's wait comes out 14 MCLK shorter instead: the board's SR push 14 early, its vector fetch at the die's MCLK. Where those two clocks go inside the exception is the next question. The paths still part at +55,387,710, on a read of the FM's busy flag at the same MCLK on both, "not busy" on the die and "busy" on the board. Unchanged: the judge over Overdrive 2 (+16,244,508), the suites (154, CPython and PyPy), Nemesis's HV captures, the test-ROM battery, the arms window (100 of 100), frames 6,981-7,200 (all 220 within three frames, 75 at the expected one). ### The busy flag Sonic's and Gunstar Heroes' paths parted on the same kind of read: the 68000 writes an FM register and polls the status for BUSY to clear, and the last poll reads differently -- Sonic's 1,407 MCLK after the data write, ready on the die and busy on the board; Gunstar's 1,421 after, busy on the die and ready on the board. `scripts/run_fm_busy.py` takes the Z80's bus and, over and over, writes an address and a data byte to the FM and polls the status 40 times, two delays walking the write through every phase of the chip's 42-MCLK cycle and the polls through every 7 MCLK. Each machine measured against its own FM's cycle, 1,408 writes: | the write's /AS in the cycle | BUSY clear, die | BUSY clear, board (before) | | ---: | ---: | ---: | | 0 | 1,407 | 1,435 | | 7 | 1,400 | 1,428 | | 14 | 1,393 | 1,421 | | 21 | 1,428 | 1,414 | | 28 | 1,421 | 1,407 | | 35 | 1,414 | 1,400 | The die's BUSY clears at a fixed point of the cycle grid, and a write in the cycle's first half counts from that cycle, one in its second half from the next; the board took every write and read the status at the access's /AS. `board.M68K_FM_WRITE_MCLK` and `M68K_FM_READ_MCLK` (the nuked-md machine only): the FM takes a 68000 write 21 MCLK after /AS and drives its status for a read as it stands 27 after. The sweep allows 15-21 and 22-28; Gunstar's own write and poll at +96,495,063 settle both (below). Two more things were in the way before that showed in the games. - **A short /IC pulse.** Asserting /IC stops the chip for three cycles (`ym2612.IC_FSM_HOLD`); the board ended that hold at the release. Gunstar's start-up pulses /IC for 112 MCLK (+13,454), and the die's chip stays where a longer pulse leaves it. `run_fm_ic.py --short` (pulses of 56-224 MCLK from two register writes): from 140 MCLK the board's shifts and restarts were the die's, at 84-139 a cycle short. `ym2612.IC_HOLD_PAST_RELEASE`: the hold runs out whatever /IC does. Open: a 56-MCLK pulse leaves the die's chip 28 MCLK earlier than the board's, at every position -- one length, no mechanism yet. - **The FM's power-on phase in the cold-boot judge.** Like the refresh phases it is nothing either machine models; before the first /IC the two FMs were 357.5 MCLK apart, so Gunstar's short pulse paused the die's chip and restarted the board's. `cold_boot_drift.align_fm` puts the board's slot 23 a master clock before the die's marker (`nuked_md.run(..., fm_markers=True)`), and the two stay within 0.5-2 MCLK through every /IC Gunstar gives them, out to +96.5M. With all of that, the sweep's cartridge run through `cold_boot_drift` (every phase on the die's, each poll against the die's at the same MCLK) agrees in every one of its polls. Gunstar's parting write lands at phase 21 of both FMs' cycles, the board's half an MCLK after the die's; the die takes it a cycle late, which needs the write at 21 (no earlier), and its poll 1,421 MCLK on reads busy with the die's BUSY falling at +1,448.5, which needs the read before 28: from a snapshot just before it, 27 and 22 read busy, 28 ready. From power-on now: Gunstar agrees with the die to +96,673,913 (+96,496,519), Sonic to +55,151,173, Streets of Rage 2 to +139,046,873 -- each its first interrupt, where the board's 68000 comes out of the acknowledge 56 MCLK late (Gunstar, Streets of Rage 2) or 14 early for a cycle (Sonic). That is the next question. The timer flag's sweep (`run_fm_timer.py`) is no nearer the die's resets than before (133-147 against 126-196); its sets now begin where the die's do, 1,148 MCLK after the load (1,141), and end at 2,030 against the die's 2,009. Unchanged: the judge over Overdrive 2 (+16,244,508), the suites (155, CPython and PyPy), Nemesis's HV captures, the test-ROM battery, the arms window (100 of 100), frames 6,981-7,200 (all 220 within three frames, 75 at the expected one). ### The first interrupt Each title's first step was its first interrupt: the 68000 pushes its PC, makes the autovectored acknowledge, pushes SR -- and between the two pushes the board took 56 MCLK longer than the die in Gunstar Heroes and Streets of Rage 2 (8 68000 clocks), 14 shorter in Sonic. The acknowledge waits for the E clock, ten clocks a period: +8 and -2 are the same phase two clocks out. The board keeps its E clock in step with time over the run (every hold is credited to the core's clock count after each instruction), so this is where it starts, and that is `cold_boot_drift`'s to set, not the board's: it moved the count on by the clocks of the die's reset hold, which leaves it two ahead of the die's. `cold_boot_drift.E_CLOCK_SHIFT` = -2, read from Gunstar's first acknowledge (from a snapshot just before it, -2 puts its SR push and vector fetch at the die's MCLK; -1 and -3 are 63 and 7 out) and right for the other two as they stand: | Cartridge | agrees with the die to | the paths part | | --- | ---: | --- | | Streets of Rage 2 (USA) | +139,354,306 | +139,528,893 | | Gunstar Heroes (USA) | +97,726,153, no step | +97,726,181 | | Sonic The Hedgehog (USA, Europe) | +55,297,851 | +55,978,328 | In all three the paths now part on an interrupt the board's 68000 takes an instruction before the die's does -- the next question, and one the Overdrive 2 judge does not reach before +16.98M. `scripts/run_vint_sweep.py` asks where the 68000 takes a VINT: a cartridge loops on `nop; nop; bra.s` with VINT unmasked, its handler a different length each frame, run from power-on on both through `cold_boot_drift` (whose setup is now `referee()` and `board()`, for other harnesses). In 62 of 62 VINTs the die takes it at a later instruction boundary than the board, whichever of the 0-69 MCLK the board saw it before its boundary by: the die begins stacking 152-234 MCLK after the board's VDP raises it. No one delay fits all 62 (the die's boundaries bracket it at 137 and more for some, 115 and less for others), so it is not just VINT being raised later on the die: where the 68000 samples its interrupt lines inside the instruction comes into it. That needs the die's IPL lines and its 68000's interrupt decision in the trace, which the harness does not record yet. ## Session 15 (2026-10-21/22): the expansion sockets, built Branch `expansion-sockets`, from `d7882e1` plus the design commits; the design and what was built are in [expansion-sockets.md](expansion-sockets.md) ("What is built"). `src/megadrive_python/sockets.py` holds the nine sockets as `typing.Protocol`s; the call sites are in `board.py` (sockets 1-4: claims by 256-byte page, `_LowDecode` for `$000000-$3FFFFF`, `hold`, `dma_started`, the Z80's bank window and peek), `system.py` (5, 9, the probe through `Board.z80_peek`, `attach_*`), `vdp.py` (6 and the DMA start notice), `render.py` (7) and `audio.py` (8). Test-only fakes for every socket are in `tests/fake_devices.py` and `tests/test_sockets.py` (19 tests). ### The gate, with nothing attached Run at `ebd1771` (the last code commit; the commit after it changes only docs). PyPy 7.3.23 throughout; `d7882e1` in a scratch worktree wherever a comparison needs one. | gate | result | | --- | --- | | `pytest`, PyPy | 177 passed, 6 deselected (1,465 s, machine loaded) | | `pytest -m slow`, PyPy | 6 passed (the six MAME lockstep replays) | | `scripts/lockstep_mame.py`, six traces | 0 unexplained each; e.g. Sonic 23,286,815 68000 and 12,728,465 Z80 instructions identical, as in milestone 1 | | VDPFIFOTesting, nine machines | 122/122 on eight, 114/122 on genesis3; every row identical to `d7882e1`'s | | Nemesis's HV captures | 8,762,828 of 8,847,360 words equal; all 288 dumps' JSON identical to `d7882e1`'s, field for field | | `run_psg_compare.py --games` | 10 streams, 0 not identical | | `run_fm_streams.py --roms --games` | 18 streams, 0 comparisons not identical | | mini sweep (`tests/mini_sweep.txt`, window 12), against the same sweep run at `d7882e1` | 115 unchanged, 0 better, 0 worse: every row's status, differing pixels and offset | | `ruff check`, `ruff format --check` (0.16.8) | clean | The mini sweep was run, not the full one (about four hours on this machine when it is quiet, and it was not). The CPython suite did not collect: `.venv` had no `sn76489_python` (the PSG's extraction postdates it), at `d7882e1` as on the branch. *(Corrected 2026-10-24: sn76489-python installed into `.venv` from the local clone at the pinned `b0acbc8`; CPython 3.14.4 then gives 177 passed, 6 deselected, on main at `44ab15d`, the sockets merged.)* Speed, PyPy, 900 frames `--no-sound`, revisions interleaved three rounds, best user CPU time, run alone (no other megadrive-python process; load average 8.3 at the start, 10.3 at the end, from other users). Both revisions ran the same instruction counts and wrote byte-identical final frames in every run. | Game | `d7882e1` (s) | branch (s) | change | | --- | ---: | ---: | ---: | | Sonic The Hedgehog (USA, Europe) | 34.01 | 34.17 | -0.5 % | | Streets of Rage 2 (USA) | 24.57 | 24.56 | +0.1 % | | Gunstar Heroes (USA) | 31.40 | 32.36 | -3.0 % | | Castlevania - Bloodlines (USA) | 24.93 | 23.77 | +4.9 % | Within noise: one revision's own three runs spread by up to 15 % (Gunstar 31.4-36.6 s on `d7882e1`). ### Open - Sockets 6 and 7 are the minimum (lines, not pixels; no HSYNC edges or VSYNC pulse length; YS ignores the debug register); see expansion-sockets.md. - The FM and the PSG stay outside the sources list, to keep their exact merge. - Needed outside this board, unchanged: m68000-python's /DTACK wait; sh2-python's FTOA. ### The invalid width, and phase 1's cache Aubrey compared 20,000 frames of megadrive-rust-fast (lockstep-identical to this board at 15441fe over 20,001 frames on `nuked-md`) against BlastEm and flagged five spots. VRAM was compared through `retro_serialize` at each one. - **Frames 10,143-10,146 and the vertical lines from 15,634.** VRAM matches BlastEm's (0 bytes differ), and register 16 is $22: both sizes invalid. The board's row shift of 0, from Genesis Plus GX, puts a plane on the name table's second row once the vertical scroll passes $200 (VSRAM $22B here); CMD's sentence says the first row on every line, and BlastEm reads the first. `PLANE_ROW_SHIFT[2]` now clears the row. 10,143-10,146: 21,056 and 3,584 pixels from BlastEm's picture to 0. From 15,635: about 10,000 to about 3,500. - **The rotating boxes' notches (14,400-14,850).** About 25 pixels missing from the left of one row every 30 or so (rows 42, 73, 106, 131, 160, 180, 205 of frame 14,810). The demo rewrites the Y of sprites 48-55 in the cache through each line, starting at 796 MCLK; `begin_line` runs phases 1 and 2 at 868, so phase 1 saw sprite 48's new Y and not its neighbours', and dropped it from that row. Kabuto puts phase 1 "2 H-borders before the raster line to be rendered", and BlastEm runs it in the blank from slot 168. `Renderer.latch_scan_cache` takes the cache as the V counter steps, and phase 1 walks that copy. Sampled frames 10,100-24,975 against BlastEm: 61 closer, 0 further. - **The boxes' streaks.** Aubrey found wrong-colour lines left on rows 56, 84 and 112 of frame 14,810. The tables wrap every 28 lines, and there the demo writes sprite 0's link at 3,356 MCLK into a line, into a second group whose Y it writes through the next line. Phase 2 had read as that line began, at 868, with one Y written, so seven of eight sprites took the wrong pattern line. Phase 2's reads now come at the V step that ends the line before (`latch_scan_cache`). Phase 1 stays as above. Those rows are clean by eye, and 55 sampled frames came closer to BlastEm, 0 further. - **Tried and refused:** phase 2 as the next line begins, 868 MCLK past the V step: it takes that line's register 5 and made the notches more frequent (55 sampled frames further). Phase 1's cache taken 100 MCLK before the V step, to miss the link write: the streaks ran the full width of the line (54 further). Neither rule has been run on Nuked-MD: BlastEm is a detector, and CMD's sentence and Kabuto's are what they rest on. Open: from 15,635 the ring of sprites' Y values, which the demo computes, differ from BlastEm's at every frame offset tried; and the rotating boxes' pictures differ from BlastEm's by tens of thousands of pixels at any offset in n-40..n+40, so the two are not at the same point of the animation. ### Overdrive's two hangs Aubrey asked for the first Overdrive next (`Overdrive (World) (v1.1)`, region E, so `nuked-md`). It went black at frame 1,809 on every machine, in both revisions, where BlastEm goes on to Titan's logo. The 68000 was in a loop at $31D1B0 with interrupts masked: bus request, read Z80 RAM $1200, clear it, release, until the byte is set. Two faults stood between that loop and the byte. - **The PSG on the VDP's clock.** The Z80 was waiting for timer A at $0893, and the timer's flag was off from frame 1,574: `Vdp.z80_write` takes `max(mclk, self.mclk)`, right for the VDP's own state, but the PSG goes through it too, so a Z80 write to $7F11 ran the sound chips to the VDP's clock, 4,200 MCLK past the Z80's. The eight FM writes the Z80 made next fell in one FM cycle, the last of them a DAC byte, `$59`, which landed on register $27, and the timer's enable went. The PSG now keeps the Z80's clock. - **The instruction neither run nor cut.** Then the Z80 stopped at $0549, a CALL, for good. The loop leaves it 209 MCLK a pass. `catch_up_z80` cuts an instruction with an access at or past `mclk + 33`, where the request is sampled, but held one with an access at or past `mclk` for the next catch-up, and there is none once the bus has gone: the CALL's last access lay between the two, so it was restarted every pass. The hold now goes by the same `sampled`. This is the one the die has not seen; the figures in "The bus request, sampled" are unchanged, but the instruction between them is new. Overdrive runs to its end screen at frame 16,987 with its music, BlastEm's at 16,995. The scenes match by eye; the pace does not, by -4 frames to +8 across the demo, and only 262 of 14,022 changing frames match any BlastEm frame exactly. Which of the two is right about the pace is open. Overdrive 2 moved in 1,114 of 25,000 frames, 66 runs, median 68 pixels, the largest in its TV static: 350 closer to BlastEm, 329 further, the total distance unchanged. The rust fork's `board-tour` traces were rewritten from this board. Lockstep against the fork on `nuked-md`: Overdrive, 18,000 frames; Overdrive 2, 25,001 frames. ### The hardware capture, the border scene, and the display at the right edge Aubrey found Oerg866's upload of Overdrive 2 (`TiTAN - Overdrive 2 (RGB 50fps)`, 720p50), a capture from a real console. All 25,178 of its frames were aligned to the demo, median correlation 0.993. It repeats a frame every 167 frames from its own 50 Hz clock, so anything off that rhythm is a real change of pace. A compressed capture of one console and one run: it settles hundreds of frames, not one pixel. - **Frame 7,052 is not the die's junk.** The capture shows the same black frame with two small marks, about 25 frames later (board 7,077), a frame neither the board nor BlastEm draws. Nudging only the Z80 at frame 7,000 by 26,600-27,300 T-states makes the board take the extra frame and draw a similar one; one nudge held the die's pace through 7,140 (139 of 139 frames). The slip is sound phase, as Session 13 said. The nudge is an instrument, not a fit. At 10,228 the capture appears to side with BlastEm against the board and the die; that scene hardly moves, so this is weaker. No nudge moved it. - **Whose picture.** Scored on the pixels in dispute, frames where BlastEm alone differs go to the die and the board 475 to 31, and frames where the board alone differs go to the die and BlastEm 288 to 15. **The display switched off at the right edge.** The plasma (16,465-16,948) writes VSRAM through each line, turns the display on near its start and off with `$8114` near its end, 3,366-3,433 MCLK in. The board stopped the picture where a colour write would show, up to 16 pixels short. `render.DISPLAY_OFF_DELAY` lets the output run to 5 pixels behind the H counter in H40. Any delay from 16 pixels past `OUTPUT_DELAY` gives the same frames, because the line ends first, so 5 is a bound, not a measured figure. H32 is not measured. 452 frames of 19,997 moved, all in this scene; exact against the die, 0 to 274 of 451, and 212 of 216 from 16,700. 16,465-16,699 keeps about 50 pixels a frame, slivers 16-32 wide on single lines, not explained. **The whole raster.** The arcade (die frames 12,455-13,021) draws into every border, which no picture here had shown: our PNGs, the die's included, were cropped to 320x240. Kabuto describes all of it. V30 at line $DD and V28 at $E1 keep the border from starting, and the display goes off from $101 to $1CE, which gives about 294 lines. The debug register is $1C0, "B only", so plane B shows everywhere, and in the side borders the plane renders the VRAM bus: sprite tile fetches 4 and 5 on the right, 36 and 37 on the left, in the palettes of plane B's last two tiles ("Horizontal border for plane A/B"). The top reads like "NO BORDERS ALLOWED" in the die's raw frames. `Renderer.enable_raster` keeps it all for `frame_raster`, off by default; sprites above line 0 needed the 9-bit line counter. Against the die's raw frames, 980 frames: main picture 0 of 73,907,200 wrong; lower lines 4,791 of 3,660,800; top lines 97,348 of 10,997,760; left border 5,379 of 3,597,984; right border 10,863 of 3,874,752. Raster on changed 0 of 100 frames and the end state. Not explained: seven lines near $1D0 the die leaves black late in the scene, line 255's last 13 pixels, line 511's right border. Plane A's left border is not done. The method (a separate seed lab, not in this repository): board snapshots every 250 frames and each disputed window run from its own, 24 sound phases each. Most disputed frames never matched in any phase, so they are not sound phase: 456 at 16,465-16,948 and 982 at 8,042-9,761. **The repeat at 10,227.** The board and the die repeat one frame at 10,227 where the capture and BlastEm move seven frames straight: a frame's deadline missed. It is not sound phase (8 nudges from 9,500), the reset (the run with no press has it), the refresh's phase, or the die's DMA figures. One constant at a time from the frame-10,000 snapshot, 33 tried: setting the cartridge or work-RAM refresh stall to 0 removes it, and so do `RAM_REFRESH_AFTER_MCLK` 1,600, `Z80_VDP_ARBITRATED` off, and zeroing any of the arbiter's `RELEASE`, `RESUME`, `GRANT_GAP`, `OWN_CYCLE`, `CUTOFF` or `REFRESH` times. Halving a refresh stall does not, so the overrun is a real slice of a frame, not a few clocks. No constant changed: one capture of one console does not justify it. **8,042-9,761** differs from the die by 16-170 pixels a frame. Frames 9,250-9,262, 107 wrong pixels a frame at `OUTPUT_DELAY` 21, 140 or more at any other value tried, 122 with a CRAM dot showing the previous colour, 101 with no dots. Left alone. ### The read pace Overdrive 2's plasma, and the classroom just before it, drew black lines on every machine but `nuked-md`: frames 16,438-16,902, 464 of 700 frames on `megadrive`, 4,161 lines. Everything fixed there had been checked on `nuked-md`, which is why it went unseen; the browser's `megadrive` showed it. The capture and the die have no lines: the capture scores 3.2 on a row-against-its-neighbours measure, `nuked-md` 5.0, `megadrive` 16.6. The die's figures one at a time on `megadrive`, lines left: read pace 0, resume 0, first read 24, DMA into FIFO room 4,178, dot clock 4,172, VBlank flag 4,161, FM control delay 4,186, FM lags 4,161. So the writes sit on an edge, and more than one figure tips them. This was the tier decision the section on DMA with the display on left open. Every machine now reads on the DMA ticks: the fast pace is 2.47 cycles a word, 3 % above Kabuto's 2.4, and his 5.6-cycle start-up stays the default. The two are nearer than the numbers look: his own account of the limit is one word per internal cycle less the ticks around each refresh, which is the die's rule, and a flat pace gives a 64-word transfer 166.4 cycles wherever it starts, where the die takes 161 to 173. `dma_figures` keeps the start-up, resume, FIFO room, dot clock and FM figures. Against the die's 23,849 frames, the comparison ROM on `megadrive`: 21,804 pictures reached before, 22,305 after; 16,438-16,915 went from 451 missing to 177, 7,052-10,227 from 1,000 to 1,002. `nuked-md` is unchanged at 22,439. Frames where the two defaults really differ, against the capture: 1,613 video frames, nearer the new pace on 685, the old on 357, 571 too close to call; 16,438-16,915 alone 312 to 156. A 512-word CRAM transfer is now 1,274 cycles (die 1,270, flat pace 1,225, Kabuto's formula 1,234). The gate's 80 cases stay identical across the three boards; 57 traces moved, the rest being `nuked-md`, the VDP FIFO ROMs, the FM ROMs and a few boards, with no new lock-up. ### The capture as a fourth witness `flaws/make_tri.py` lines the board, BlastEm and the die up on the die's frame, and `seedlab/video/pxvote.py` asks Oerg866's 720p capture to settle each patch where they differ. Each machine's frame goes through the capture's own damage: scale 2.7375 by 2.502, origin 170.375, -13, nearest then a blur of 0.6 by 0.5 (`px-geo.json`, correlation 0.98 on quiet frames). The vote is a matched filter in units of the noise around the patch. Flaws planted in quiet frames were called right 94% of the time at 1-3 pixels, 99% at z >= 4. Three rules keep it honest. The video frame is chosen on undisputed pixels only. When several video frames tie, each machine takes its best, because a picture that updates every third frame cannot pin the moment. And the winner must fit by itself (fit under 17.7), which gives a third answer, none fits. Without those, 8,086 was a clear win for the board, and wrong. Of 61,286 patches, 49% got a verdict, 48% can't tell, 3% none fits. A machine alone against the other two lost 77% (board), 72% (BlastEm) and 66% (die). The die is not the top of the ladder: on patches only it disputes, the capture sides against it two times in three. 2:42 is two clocks, not a drawing fault. The grid moves on the vertical beat, one pixel a frame, on every machine and on the capture. The console is 3D and flips every 3-5 frames. With the grid as a clock (`flip242.py`), BlastEm's flips drift up to 4 frames ahead of the die, the capture's run from 1 ahead to 2 behind, and the board's match the die except for eight flips, 8,082-8,104, a frame behind. Those eight were the board's largest repeating flaw and they lean toward the capture, so they are not to be tuned to the die. Thin moving lines count double on a flaw map, which is why this looks large and nobody sees it. Likely cause: 3D code that finishes when it finishes, on slightly different CPU time per frame. Not proven. The families left, from `off.py`. The first two are ours to chase. - Cube, top row (73 frames, 14,348-14,840): row 0 mostly holds what the die draws on row 1, so a per-line change lands a line early at the top. The capture agrees with the die: 108 patches at row 0. Rows 222-223 may be the same thing. Unconfirmed. - Plasma slivers, 16,465-16,948: runs of about 25 pixels on single lines where a colour change lands at a different place. Verdicts split among all three, so no machine has this timing right yet. - CRAM writes in the picture, 9,177-9,761: bursts about 9 pixels apart near the left edge, every 32-36 lines, displaced 1-3 pixels between machines. Most too small to judge. - Left 16 or 32 pixels, 8,152-9,152: lines where the first tiles keep the previous colour, a write landing just after the line starts. Mostly BlastEm. - BlastEm draws the line above the picture where the board and die are black, 9,178-11,108. - 19,206-19,396, single pixels on a star field: BlastEm disagrees, the capture is mixed. The comparison ROM removes the random source and the capture does not, so don't read this as a verdict on anyone. Disagreement frames are twice as likely within 60 frames after a scene start (30% against 17%), but most are mid-scene. ### Line $1FF never scanned the first line's sprites The fix for the cube's top row. `begin_line` has always said line $1FF's sprite scan is the first line's (Kabuto, "Topmost and bottommost raster line"), but line $1FF is a border line and `render_at` skipped border lines, so that branch never ran and line 0 always fell through to "scanned as it begins". That took phase 1 from the cache one line late. Most software can't tell. The cube can: it moves register 5 and rewrites sprite Y on every line, on line 511 too. `render_at` now also fires on $1FF, and `begin_line` stops there without drawing on a border line. Against the die, comparison ROM on `megadrive`: 80 frames from 208,642 wrong picture pixels to 199,085 in total (1,551 wrong frames to 1,471), 80 better, 0 worse, nothing else moved; 14,348 went from 212 pixels to 0. Border score unchanged. The gate, Windows, with the fix in all three boards: `cargo test` passes on both Rust boards; new against old `md-trace` identical on all 78 cases that ran, so no game on the list changed; fast against plain the same; plain against Python identical on 75, and on Overdrive 2 to frame 14,900, past the cube. Not run: `soft-checker` (access denied) and `titan-mdniccc` (a hard-coded path). The three SVP cases differ from Python on this box, whose PyPy venv shows no `ssp1601` package; the Python board with and without the fix gives identical traces there. Row 223 of the cube scenes is still open: 44 frames, 571 pixels, the largest a full-width line at 14,852 and otherwise blocks of 22-32 pixels, one sprite wide. The capture sides with the die. At die 14,498 the board draws sprite 7 of the last table at X 230 and the die doesn't. Ruled out: reading the sprite list later in the line (`link` 0 is written into sprite 0 at the end of line 222). Latching phase 1 at 2,000, 2,600 or 3,420 cycles fixed none of the 44 frames at 2,000 or 2,600 and 5 at 3,420, and raised the frames wrong elsewhere, so phase 1 at the V step stands. The X = 0 mask as coded doesn't explain it either: row 222 uses 32 tiles, so the carry is clear, and sprites 3-6 sit at X 383 before sprite 7. ### The first console run: VRAM reads at $142, and the YM2612's ports 1-3 alewman-probe (its own repository) ran on a borrowed NTSC Genesis, Model 1601 with TMSS (version register $A1), from an EverDrive-MD V3 clone. Two runs, both saved to the cart. Against the die, the board and BlastEm it settles two of the board's open rules. **$142 fills VRAM reads.** The probe's VRAM read loops count 900 reads in 100 picture lines (RDLN) and 40,703 in a frame with the display on (RDV1), on the console and on the die alike. The board counted 851 and 38,896: the $142 rule (undocumented-behavior VDP item 28) was shutting VRAM reads too. It now holds for CRAM and VSRAM reads only, and the board counts 900 and 40,696-40,699. The CRAM sweep that found the rule is untouched. Overdrive 2 on `megadrive`, 25,200 frames, old board against new: every frame identical. **Ports 1-3 keep port 0's status, then fade.** All 13 YMP2 reads and the YMPT reads: with the flag set and a second without a status read, ports 1-3 read 0 while port 0 reads 1; the flag cleared straight after port 0 read 1, port 1 still reads 1; 20 and 60 frames on, 0; after port 0 read busy, ports 1-3 read $80. The board returned 0 (Genesis Plus GX) and the die gives a live copy of port 0; neither fits. The board now keeps port 0's last value and gives it on ports 1-3 for `FM_PORT_FADE_MCLK`. Run 1 only bounds the fade (0-20 frames), so the figure is provisional, and the cart has a new test, YMDK, that reads port 1 from 0 lines to 18 frames after. With both changes the board matches the console on RDLN, YMPT and YMP2 exactly. Checks: both Rust boards' tests pass, with the board-tour example traces rewritten from the Python board (the Z80 reads port 2 there and now gets $80); the Python suite passes (208, 20 skipped for missing references); plain, fast and Python give byte-identical probe saves. The lockstep gate did not run: the ROM share was unreachable. What else the run showed, for later: the WEDG sequence (an ordinary command in two control writes straight after DMA registers) hangs the console as it hangs the die, and RESET does not free it; the board and BlastEm pass it. Sprite phase edges sit near the die's, the board's 10-20 steps late; VINT and F land about 2-4 H steps later than the board's; the bus grant read straight after a request is there 16-26 times in 32, the board's 9-20. CPU, Z80-in-RAM, DMA pace and the idle loops match the board. **The port fade, timed.** alewman-probe's runs 4 and 6 on the same Model 1601, saved to the flash cart's card, read YMDK identically: port 1 still gives port 0's 1 after 3 frames' wait and 0 after 5 (the wait is d6+1 frame edges from an unsynced start, so 3-4 and 5-6 frames). `FM_PORT_FADE_MCLK` goes from the provisional 1,000,000, which lost it within a frame, to 4,000,000, about 4.5 NTSC frames, in all three boards. The cart's YMDK now reads port 0 at a frame edge and waits 1-7, 9, 13 and 18 whole frames, so the next run narrows it to one frame. Both Rust boards' tests pass; the Python suite passes (211, 17 skipped). The synced YMDK ran twice (runs 7 and 8, both from power-on): port 1 kept the status through 6 frames and lost it by 7, then kept it through 4 and lost it by 5. The fade varies run to run, 4-7 frames over the four runs; the board keeps 4,000,000, inside that range. Runs 9-11 kept the status 6, 4 and 2 frames; the console had been left on a long while before runs 10 and 11. Runs 7-9, soon after power-on: 6, 4, 6. So warmth likely shortens the fade, from five runs. Every other test agreed across runs 4-11 within a count or two: only the fade, a charge held on the bus, moves. The board keeps 4,000,000 MCLK. ### Hardware-vote attribution, and the plasma's missed horizontal-scroll fetches The fourth-corner maps in `od2-20k/flaws` attributed a whole connected patch to its winning group. That overcounted a machine's disagreements wherever its pixels already matched the winning candidate. Both generators now classify agreement per pixel, retaining the original patch-level capture confidence, thresholds and votes. Border patches remain two-way; no BlastEm border is invented. Six regression tests pass, and both full-raster and cropped composition were exercised on saved votes. `stats-full-serial-pixels.json` is the recomputed full-run result. In die frames 9177-9761, the pixels attributed to our disagreement fall from 40,218 to 17,822; 22,396 of the formerly blamed pixels already matched the winning candidate. In the plasma/wipe window 16465-16948 the corresponding count falls from 8,202 to 7,921. These are agreements with a patch's hardware-selected candidate, not independent hardware judgments of every pixel. Corrected stills were generated; existing movies have not been re-encoded. **The plasma slivers have a concrete horizontal-scroll cause.** At frame 16555, the 72 picture disagreements are on rows 35, 102 and 184 (24, 18 and 30 pixels). An isolated replay from Nuked-MD's frame-16500 save reproduces the archived die picture exactly. Its VRAM-pin trace has the normal H-scroll transfer at die H=$1E9 on rows 34, 101 and 183, but no such transfer on rows 35, 102 and 184. An additional driver-only probe of the actual H-scroll latches confirms: | Row | Current table, both planes | Die retains, both planes | Display re-enabled at die H | | --- | --- | --- | --- | | 35 | 208 | 192 | $1E7 | | 102 | 224 | 208 | $1E7 | | 184 | 240 | 224 | $1E9 | The successful request is visible at die H=$1E7, the transfer at $1E9, and the two low-byte latches at $1EB/$1EC. A display enable at $1E6 can still make the request; the sampled $1E7 enables miss it. On the following lines the latches take the new table values. This is not a two-cell VSRAM latch delay: all sampled per-column scroll values on the three faulty lines match the die. The renderer's `_plane_setup` instead reads both H-scroll words directly when it sets up a line; it has no retained H-scroll latch for a missed fetch. Reconstructing only those three lines with the retained horizontal values, keeping their existing vertical scroll, VRAM, sprites and palette, removes all 72 disagreements, without changing any other picture pixels. This is a diagnostic reconstruction, **not an emulator fix**. The initial board replay explicitly migrated six missing fields of an older Python checkpoint and matched the saved serial Rust picture exactly. A fresh run from power-on confirms this is not a stale renderer build or just old checkpoint state. After explicitly aligning frame numbers (the fresh runner's frame is the archived reference frame plus one), all 484 pictures in 16465-16948 match the archived serial Rust output pixel for pixel. Fresh Python frame 16556, reference frame 16555, repeats the same 72-to-zero diagnostic reconstruction. `flaws/plasma-current/comparison.json` records both frame numbers and every comparison; `flaws/plasma-hscroll-diagnosis.json` records the reconstruction. A production fix needs a display-gated H-scroll fetch and retained values, with Python as the specification and matching Rust transcriptions. Do not substitute "always use the previous row": only missed fetches retain the old values. Nor is it safe to fit one display-enable cutoff to these three rows: the exploratory board and die's per-line enable phases differ on other rows. The fetch gate and its CPU/VDP timing need an isolated boundary test before changing all three boards. The fresh run preserves that caveat: row 184 re-enables at board line offset 526 MCLK, earlier than rows 35 and 102 at 541 and 546, while on the die it re-enables later than both. A new latch alone is therefore not yet a demonstrated complete fix for these slivers. #### Isolating the fetch boundary, and rejecting a gate-only fix `scripts/run_hscroll_latch.py` now generates a small H32/H40 ROM with alternating 0/16 horizontal-scroll table entries and a swept display-enable phase. The headless driver's existing `NMD_VDPSIG` stream now includes both H-scroll words (`HA`, `HB`), `DISPLAY` and `HREQUEST`. The checker verifies actual requests and retained values, and requires the measured enable boundary to be exercised. This tests the oracle's behavior independently of our renderer. With the standard driver rebuilt in a separate directory, both modes pass: | Mode | Successful fetches | Retained previous words | Requests at die H | | --- | --- | --- | --- | | H32 | 14 | 1,105 | $1E7 | | H40 | 77 | 1,042 | $1E7 | These are complete visible lines inside half-MCLK 16,128,720-25,089,120, excluding partial first/last lines. In both modes, display enables at $1E6 fetch and those at $1E7 miss; both words retain their old values after a missed request. Generate with `python scripts/run_hscroll_latch.py rom probe.bin` (add `--h32` for H32), run Nuked-MD without `-pal` using the timing/environment options in the script's docstring, then run `python scripts/run_hscroll_latch.py check probe.txt`. A runtime-only candidate added the display gate and retained values to the Python renderer. It was **rejected**, not committed or transcribed to Rust: across reference frames 16465-16948, raw picture disagreements with the die rose from 7,849 to 22,878. Only 24 frames improved, 206 worsened and 254 were unchanged. Frame 16555 improved from 72 to 30, but even a previously exact frame (16665) acquired 305 wrong pixels. These raw die comparisons are not the hardware-selected attribution counts above. The prototype also does not model every request/address/data stage or a VRAM write during the fetch. CPU bus tracing exposes a separate timing discrepancy worth resolving before landing the latch. All 384 sampled plasma DMA-trigger writes have ordinary 18-MCLK `/AS` pulses. Generic synthetic transfers instead produce 39 MCLK, the behavior behind the board's unconditional 21-MCLK trigger hold. On the die, the plasma CPU completes an instruction prefetch after the trigger and before granting the DMA bus; our board stalls synchronously at the trigger, putting that prefetch after the stall. This is a measured ordering difference, not yet an established explanation of every display-enable phase error. Controlled probes varied DMA target, instruction form, PAL/NTSC, FIFO prefill, mixed data/control long writes and CPU phase, without reproducing the short plasma trigger. The distinguishing condition remains unresolved. In particular, there is no evidence for removing the 21-MCLK hold globally. No production VDP/renderer changes were made in this investigation; Python remains the spec for a future tested fix and both Rust transcriptions. Validation: the new probe/checker tests and existing vertical-scroll latch tests pass together (15 tests); Ruff check/format and `git diff --check` pass. The rebuilt driver and both generated ROMs were also exercised end-to-end, producing the counts above. Existing signal consumers filter by tag and ignore the added records. #### Resolving the short DMA trigger The distinguishing state is Nuked-MD's [source name redacted], not the DMA destination, autoincrement or the CPU clock phase. A mode-5 write to register $97 with bit 7 clear sets [source name redacted] low; CPU bus grant sets it high. The second command word's acknowledgement depends on this latch. The old synthetic probes rewrote $97 for every transfer, whereas the plasma reuses it and writes the transfer length again. `scripts/run_dma_trigger.py` isolates that difference with three sixteen-transfer ROMs. All three are byte-identical to the ROMs used for the measurement: | Source-high writes | Trigger /AS lengths (MCLK) | | --- | --- | | Before every transfer | 39, sixteen times | | Only at setup | 39, then fifteen 18s | | Before alternate transfers | 39, 18, eight times | The short trigger allows one more CPU read before /BGACK; the held trigger does not. A normal extra read puts /BGACK 47 MCLK after the trigger rather than 40; when that read is refresh-stretched, the grant waits for it too. The checker requires the lengths, number of transfers, intervening read and completed-cycle ordering, and rejects incomplete evidence. **Implemented in Python and transcribed to both Rust boards.** The source-high write arms the held trigger; the grant consumes it. An unarmed trigger queues the transfer instead of immediately running it. All four 68000 byte/word read/write callbacks finish the extra access before granting it. The established first-read, resume and refresh-pause calibration is retained relative to the granted cycle; the 21-MCLK hold is not removed globally. Step traces now include `dma_trigger=` in both languages. This covers the measured DMA-to-DMA sequence. The die's [source name redacted] also responds to CPU bus grant for other bus masters; the effect of an intervening Z80 grant between the source-high write and trigger has not been measured or newly modeled here. Validation: - 81 targeted Python tests pass: DMA handshake, bus timing, board, sockets, and both scroll-probe suites. The new tests exercise all four callback surfaces and verify that reads return the pre-DMA value and writes land before DMA. - Both Rust boards pass their new DMA regression and four library tests. Their release `md-run` and `md-trace` binaries were rebuilt using the installed `stable-x86_64-pc-windows-gnu` toolchain. - All eight probe/example cases match current Python line for line in both Rust versions: 436 frames and 6,000 step records, including the new handshake state. - All three implementations ran from power-on through frame 16950, pressing reset at the first instruction boundary at or after 26,761,500 MCLK. Every one of the 484 plasma pictures agrees across the three implementations. - **The scene is now one frame earlier than the previous fresh baseline.** The updated files' frame number equals the die reference number; the previous fresh Python file has number reference + 1. With that explicit alignment, all 484 pictures are unchanged and the raw die disagreement remains 7,849. `flaws/plasma-dma-fixed/comparison.json` records both frame numbers and the checks. The existing Rust golden-example tests still fail. Replaying all five examples with the old unconditional hold gives exactly the same output as the new behavior, so those failures predate this change (the saved IRQ pulse, for example, is still 3,420 MCLK rather than the worktree's 2,578). The old goldens were not regenerated. New probe lint, targeted Rust formatting, and `git diff --check` pass; whole-tree lint/format checks also report unrelated existing formatting. The H-scroll gate is still not landed. With the corrected DMA handoff, the runtime-only combined candidate gives 8,917 disagreements instead of the earlier gate-only 22,878, but still exceeds the 7,849 baseline (5 frames better, 47 worse, 432 equal). Another concrete missing timing component is now measured: for all 384 matched plasma display-on writes, Nuked-MD changes `reg_disp` 24-34 MCLK after the CPU's /AS starts, whereas our register update is immediate. Its pixel-clock pipeline and the board/die clock anchors must be resolved together, not replaced by an arbitrary constant or a gate fitted to the three originally sampled rows. #### Measuring the display pipeline and physical clock anchors The register delay is now measured independently of the plasma pictures. The existing H-scroll ROMs were run in H32 and H40, recording CPU bus cycles and pixel-clock edges. A separately built diagnostic wrapper also exposed the register request stages. The resulting rule for ordinary 18-MCLK register writes: 1. Capture on the first half-pixel edge at least 20 MCLK after /AS falls. 2. Commit on the following HCLK1 edge, strictly after the capture edge. This predicts all 524 H32 and 524 H40 display transitions, then all 768 transitions in the two-frame saved plasma run, exactly. A fixed delay followed by rounding to HCLK1 cannot explain all H40 phases. H32 needs half-MCLK precision: its measured delays are 26.5, 28.5, 30.5, 32.5 and 34.5 MCLK, not rounded integers. The standard headless driver now has opt-in `NMD_VDPCLK=1` records (`HC`, `HCLK1`, `HCLK2`) in its existing signal window. The permanent `scripts/check_register_latch.py` checks both values and exact commit times, rejecting missing state, clock evidence, unsupported cycles and extra transitions. The separately rebuilt standard driver reproduces the diagnostic measurements; its CPU bus traces are byte-identical. All 31 tests in the register, H-scroll and DMA probe selection pass, and the new files pass Ruff. **The clock anchor is not an H-counter-number subtraction.** Directly observed V increments occur at internal H $10A in H32 and $14A in H40, the board's own counter labels. On visible H40 lines the die's /HSYNC falls 312 MCLK after that origin, at H $1CD. H $1E7 and its H-scroll request occur at +565, not the board table's +566; the table differs by one MCLK through parts of the slow-clock region. The last preceding HCLK1 is at +561. Under the established 240,277-MCLK board/die relation, the updated plasma snapshot's physical counter origin is 15 MCLK before the die's: board line starts are phase 568 modulo 3420, the die's are phase 1460, and the offset is phase 877. This accounts for the earlier observation that /HSYNC was 39 MCLK after board H $1CA: 24 MCLK of counter-label difference plus 15 MCLK of physical phase. It is not a reason to shift the existing HV/status sampling calibration globally. **Two runtime-only candidates, neither landed.** Starting from the updated power-on snapshot at frame 16450, the first gives H-scroll its own delayed display state, using the independently measured clock edges and physical origin. The second schedules all register writes through the VDP event loop, so FIFO, DMA and the renderer also see them at the delayed time. Both produce the same score over all 484 plasma frames: | Baseline disagreements | Candidate | Better frames | Worse | Equal | | --- | --- | --- | --- | --- | | 7,849 | 7,904 | 7 | 10 | 467 | Frame 16555 still has its original 72 disagreements. The diagnostics and comparisons are in `flaws/plasma-clocked-gate` and `flaws/plasma-clocked-registers`; neither modifies a production core. **The remaining discrepancy is already present in the CPU arrival times.** On the three diagnosed rows, aligning pictures as before and expressing die times relative to the board's physical-clock reference: | Row | Board display-on /AS offset | Die offset | Board earlier by | | --- | --- | --- | --- | | 35 | 512 | 555 | 43 MCLK | | 102 | 496 | 553 | 57 MCLK | | 184 | 497 | 575 | 78 MCLK | The corresponding display-off writes are already 29, 36 and 50 MCLK early. The remaining difference grows during DMA, but different entry phases cross different parts of the slow pixel-clock region; this does not by itself prove a second DMA bug. The preceding VSRAM writes also stall differently: in row 35's matched instruction sequence, one die data-port /AS lasts 109 MCLK while the corresponding board write is unstalled. The next bounded investigation is the FIFO occupancy/commit sequence before those display-off writes, with transfers compared at equal arrival phases before changing their calibration. Python and both Rust production cores remain at the previously validated DMA implementation. No register-delay or H-scroll threshold change was applied. #### Separating FIFO memory commit from CPU acknowledgement The plasma sequence writes **VSRAM**, not VRAM: its earlier `$40000090` command selects VSRAM and the subsequent single `$4002` control word preserves that destination. All 3,821 logged CPU pushes in the investigated frame have code 5. Optional `NMD_FIFOSIG=1` records now expose the die's write/read pointers, half-word state and full/empty flags through the standard driver's signal window. The read pointer releases 39 MCLK after ordinary active-H40 commit slots, but 44 after the slow H $1CE slot. /AS releases 8-14 MCLK after full falls. In the board's existing bus-clock convention, this means CPU reuse is ready 29 MCLK after commit, or 34 at H $1CE, with the usual 7-MCLK rounding at the CPU callback. The correction is in Python and both Rust transcriptions. It keeps four separate CPU-ready timestamps, including the case where a CPU write arrives after the memory commit but before acknowledgement is ready. VRAM releases only when its second byte consumes the entry. Memory placement, DMA read pacing and status flags retain their existing behavior; H32 and idle slots receive no new delay. Step traces include this state; frame trace records retain their format. **Same-arrival evidence, not a picture-fit threshold:** | Probe | Writes checked | Exact acknowledgements | | --- | ---: | ---: | | Plasma VSRAM groups, each starting with a confirmed empty FIFO | 3,820 | 3,820 | | Independent H40 VSRAM loop | 8,479 | 8,479 | | Independent H40 CRAM loop | 8,479 | 8,479 | | Independent H40 VRAM loop | 4,975 | 4,975 | The old plasma replay matched 3,499 writes, underestimating all 321 held writes. Row 34's last burst now gives the measured 91- and 7-MCLK holds instead of 63 and zero. A constant 29-MCLK correction initially missed 278 synthetic CRAM/VSRAM writes by one CPU clock; measuring the slow H $1CE slot explains all of them. Blank-line writes also match, without a timing change there. The permanent `scripts/run_fifo_release.py` generates and checks the three independent probes. A separately rebuilt standard oracle reproduces the original diagnostic ROMs and bus traces byte-for-byte and all the results above. Replay uses the existing +15-MCLK physical-origin relation. The separate HV-only samples and coarse HBlank/status samples do not establish a replacement clock anchor. The rejected runtime FIFO-plus-clocked-H-scroll candidate gives 14,467 disagreements rather than 7,849 over the 484-frame plasma window. No H-scroll gate or register-delay change is included in this correction. **Validation of the production correction.** The targeted Python selection passes 115 tests. The three Nemesis FIFO-ROM acceptance cases initially skipped because the archive was absent. A subsequent fetch succeeded through the pinned archive mirror (the original URL returned HTTP 502), with its SHA-256 verified. All three acceptance cases now pass: Genesis, Mega Drive and Genesis 3, each running the 122-test ROM with the existing hardware-intermittency and Genesis 3 exceptions. Each Rust core passes its four library tests, DMA regression and new FIFO regression, and both release headless binaries were rebuilt. Eleven cases match Python, Rust and Rust-fast record-for-record: 445 frames and 12,000 step records. The new files pass Ruff and targeted Rust formatting; `git diff --check` passes. Fresh runs from power-on through frame 16950 agree across all 484 plasma frames. They also agree with the DMA-fixed baseline, without an additional frame shift: the total remains 7,849 disagreements. The result is persisted in `flaws/plasma-fifo-fixed/comparison.json`, with corresponding Rust and Rust-fast captures in `plasma-fifo-rust` and `plasma-fifo-fast`. This corrects CPU timing, not the remaining visible slivers. A fresh snapshot's bus trace substantially narrows the remaining arrival error: | Row | Old display-on offset | FIFO-corrected offset | Die offset | Still early | | --- | ---: | ---: | ---: | ---: | | 35 | 512 | 533 | 555 | 22 MCLK | | 102 | 496 | 552 | 553 | 1 MCLK | | 184 | 497 | 574 | 575 | 1 MCLK | These use the same physical-origin convention and picture alignment as the preceding investigation. Two of the three large arrival discrepancies have collapsed to one MCLK; row 35 still has a distinct residual. Its preceding bus sequence is the next bounded lead, not a justification to shift clocks globally or enable the rejected H-scroll gate. #### Row 35: cartridge-refresh phase, not another DMA trigger hold The corrected board and die execute the same instruction/data-access sequence. Immediately before the ROM prefetch at `$3FB6FC` (word `$C140`), the board is only one MCLK early. That fetch's /AS lasts 18 MCLK on the board but 32 on the die. The board then remains 15 MCLK early through display-off, the ordinary DMA trigger and its extra CPU read. The following DMA increases the display-on gap to 22: | Event | Board offset | Die offset | | --- | ---: | ---: | | ROM prefetch `$3FB6FC` | -174 | -173 | | Following RAM read | -146 | -131 | | Display off | 8 | 23 | | DMA command, second word | 92 | 107 | | Extra CPU read before grant | 120 | 135 | | Display on | 533 | 555 | This is not evidence for another 21-MCLK trigger penalty. In a **diagnostic only** replay from the fresh snapshot, adding just the die's 14-MCLK stretch to that one ROM fetch moves the first modeled DMA read from +160 to +176 and the twentieth from +498 to +518. The CPU's ordinary rounding then moves display-on from +533 to **+554**, one MCLK before the die's +555. The extra seven MCLK follows from entering the existing DMA clock schedule later, not from an independently missing hold. Neither this per-address injection nor any clock shift is in production. **The refresh rule itself passes a same-arrival check.** There are 382 complete plasma display-on/off bursts shorter than a line in the saved trace. Of their 16,044 cartridge accesses, 507 are stretched by 14 MCLK and 15,537 are unstretched. The existing production `Board._bus_cycle`, driven at those exact CPU arrivals, predicts **all 16,044 exactly** at refresh phase 523 modulo 896. An exhaustive phase check admits 518-524; 523 also lies in the independently established 518-523 interval from the earlier unrelated refresh probes. The board's native grid is phase 690. After this picture/physical-origin alignment it is phase 579 in die-clock coordinates, not 518-524. Applying that aligned phase to the die's input arrivals produces 1,075 disagreements. On row 35, the board's next tick is at -118, so its -174 ROM fetch legitimately precedes its own refresh; the tick is instead consumed by a RAM access. Matching pictures and VDP line origins does not establish matching refresh phases. This investigation locates the local discrepancy but does **not** establish the origin of the global offset. Reset/clock alignment and any whole-frame shift must be audited before changing the refresh model or judging an H-scroll gate against these picture-aligned runs. The broad blanking workload was excluded from the closed-burst proof, not claimed as passing. No production Python or Rust timing changed. The 54 board, DMA-trigger and FIFO regressions pass. The bus alignment, production replay and single-stretch counterfactual are summarized in `flaws/plasma-row35-timing.json`; the previous fresh 484-frame comparison remains the production baseline. #### Resolving the reset anchor and the remaining whole-frame advance The previous FIFO and row-35 frame captures used the stale `board_frames.py` example: reset at the first instruction boundary at or after 26,761,500 MCLK. That is the **die's button-press time**, not the corresponding board reset pulse. This was an error in those comparison runs, not evidence for a new refresh delay. The existing boot-drift tools already use the correct calibrated time. A fresh standard-oracle run from power-on, with `NMD_RESET=53523000:64227600` in half-MCLK, independently reconfirms: | Event | Die MCLK | | --- | ---: | | Button pressed | 26,761,500 | | VRES and ZRES asserted | 26,841,996 | | VRES released | 26,842,892 | | First reset-vector fetch | 26,842,990 | The switch-to-pulse delay is 80,496 MCLK and the pulse lasts 896 MCLK. The board models the pulse, not that switch delay. Subtracting the independently measured 240,277-MCLK VDP offset gives **26,601,719** for the board pulse. This agrees with the earlier "The VDPs' offset" and "The press time" investigations; no new constant was fitted to the plasma. The old capture actually reset at 26,761,522, giving native cartridge-refresh phase 690 modulo 896. An exact calibrated reset uses the preceding instruction boundary 26,601,656, asserts at 26,601,719 and gives phase 375. Adding the global VDP offset yields **524**, exactly the die pulse's phase and inside the measured 518-524 interval. Both Rust cores reproduce the same boundary, post-reset clock 26,602,909 and phase. The actual Python capture CLI's saved snapshot confirms the same phase. The legacy CLI is a separate case: its 1,000,000-MCLK lookahead can cross the reset time during a PAL frame. It resets at 26,762,166 here (phase 438), whereas the earlier session harness used a 1,100,000-MCLK lookahead and reset at 26,761,522. Neither is the calibrated pulse. Exact mode avoids both overshoots; the legacy CLI behavior is retained explicitly. `scripts/board_frames.py` now offers opt-in `--reset-exact`. It probes the preceding instruction boundary, then schedules `System.press_reset(at=...)` without skipping instructions or stepping beyond the requested pulse. While the reset is pending, it checks each instruction rather than relying on a frame-length estimate. The default legacy mode is preserved for reproducibility. The reset-boundary helper is shared with `od2_boot_drift.py`, and the stale example is corrected: ```sh python scripts/board_frames.py ROM OUT --machine nuked-md --range 16465:16948:1 \ --reset-mclk 26601719 --reset-exact ``` **A second, real alignment change remains.** A calibrated Rust-fast run sampled the whole demo, then captured every frame from 6980 through 7120. Board frames 6980-7052 match reference frame N-1 exactly; from **7053**, changing pictures match reference frame N exactly. Static pictures later in the window are explicitly ambiguous. This reproduces the previously documented logo-scene one-frame advance under the current core and the correct reset; it is not repaired by reset calibration. The earlier attribution to Z80/sample bus contention has not been remeasured in this round. A PAL frame is 1,070,460 MCLK, or **636 modulo 896**. Consequently, after the one-frame picture realignment the calibrated refresh phase becomes 264 rather than 524. The old run's incorrect reset phase instead became 579, producing the misleading near-55-MCLK offset investigated on row 35. Neither can be corrected by globally shifting refresh clocks to fit that row. The next causal investigation is the main-loop/VBlank boundary around frame 7053 in this calibrated run, including the Z80's bus use. Until the whole-frame advance is accounted for, picture-aligned plasma traces are not phase-aligned bus traces. No Python or Rust emulation timing was changed by this reset-anchor correction. The 61 capture, board, DMA-trigger and FIFO tests pass; the new capture tests cover off-grid times, an exact instruction boundary, a multi-frame wait, invalid times and a divergent probe. Ruff and the actual exact/legacy capture CLI runs pass. Fresh Python, Rust and Rust-fast runs through frame 16955 also agree on all 484 plasma pictures. The calibrated reset changes neither their image alignment nor their pixels relative to the preceding FIFO-fixed run: the die disagreement total remains 7,849. The default CLI's picture is byte-identical to the original committed capture script run against the same current core. The new evidence is in `flaws/plasma-reset-anchor.json`, with the calibrated full-window comparison in `flaws/plasma-calibrated/comparison.json` and every-frame slip comparison in `flaws/calibrated-slip/alignment.json`. The reset mistake does not invalidate the independent equal-arrival FIFO/handshake measurements, but the old captures must not be described as reset/refresh-phase-aligned to the die. ### NEW10 and the calibrated logo wait The new cartridge saves are in `alewman-probe/hardware/card3`, not in the emulator repositories. NEW10 identifies version A1 (NTSC), build `2433831+`, run 601. All 70 last-run tests completed with valid record CRCs; the long-run header reports 300/300 cycles, first run 302, and no interrupted merge. The existing 32X handoff already covers the sprite flags, Z80 IRQ width, and YM status fade; those changes and the raw saves were left alone. A fresh run of the existing cartridge ROM on the rebuilt Rust-fast `genesis-tmss` board also completes all 70 tests with valid record CRCs. CPU1, CPU3, both Z80-local-RAM controls, and ZINC fall within NEW10's ranges. Cartridge contention does not: | Measurement | NEW10, 900 observations | Current board repeats | | --- | ---: | ---: | | ZRO1, 68000 in ROM | 68,385-68,530 | 69,041-69,117 | | ZRO1, Z80 count | 21,175-21,194 | 21,251-21,261 | | ZRO2, 68000 in RAM | 69,613-69,620 | 69,850-69,852 | | ZRO2, Z80 count | 21,145-21,147 | 21,221-21,222 | | ZINC | 83-87 | 85-86 | Both processors run too fast when sharing the cartridge. The ZRO1 means of the older warm-start NEW8 run and NEW10 are 68,470.079 and 68,470.100; ZRO2 means are 69,616.578 and 69,616.580. Their different YM status-retention histories do not explain this repeatable bus-count difference. A matching dirty build label does not establish the flashed binary's hash; the exact emulator-run ROM hash is kept in the report. **The logo boundary, remeasured rather than inherited.** A fresh Python snapshot at frame 7048 uses reset 26,601,719, with post-reset clock 26,602,909 and native refresh phase 375. Python and fresh Rust-fast traces agree on all 62,581 steps from frames 7048 through 7054. A fresh die replay from its frame-7000 state covers the same boundary. The loop at `$31C812` is `cmpi.b #$DF,$C00008` / `bne`: it waits for V counter 223 **exactly**, not merely for VBlank or for V to pass a threshold. It changes register 5, then at `$31C826/$31C830` waits for VBlank to end and begin. Between matching CPU bus-fetch endpoints `$31C842` and `$31C812`, the critical work interval is 1,067,794 MCLK on the board and 1,070,300 on the die: the board is 2,506 MCLK faster. It reaches the poll on line 223; the die's first HV read is `$E0B5`, already line 224. The die misses the intended sync, eventually sees the repeated PAL counter value, and waits an extra frame. The visible advance still starts at picture 7053. The earlier claim of 150 die sample reads versus none on the board does **not** describe this calibrated run. Both perform 1,024 cartridge reads in the critical interval. Their separate Z80 VDP-read counts are 14 and 15. `bank_accesses` counts both kinds: comparing its 1,038 total with the die's 1,024 cartridge reads would be another attribution error. The preceding work interval has 512 cartridge reads on each, 82 versus 76 VDP reads, and a duration difference of only +126 MCLK. **The next discrepancy is after grant.** Replay the arbiter at the die's actual Z80 request times and 68000 bus cycles. All 4,096 cartridge grant onsets match the observed Z80-owned /AS onsets after their fixed half-MCLK signal offset. With the *observed* Z80 waits, the modeled earliest CPU resumption matches 4,045 next accesses; 51 are later and none earlier. A later access alone does not prove extra arbiter delay, since the CPU can be doing internal work. The current 29-MCLK own-cycle threshold underpredicts 443-451 of those waits across the independently admitted refresh phases 518-524. A diagnostic 31-MCLK cartridge threshold, preserving 29 for non-cartridge accesses, gives: | Die refresh phase, replay only | Exact waits, current 29 | Exact waits, candidate 31 | | --- | ---: | ---: | | 518 | 3,653 / 4,096 | 4,095 / 4,096 | | 523 | 3,648 / 4,096 | 4,088 / 4,096 | | 524 | 3,645 / 4,096 | 4,085 / 4,096 | No reset or refresh phase was changed to get these results. These are isolated equal-arrival replays, not alternative globally calibrated demo runs. **Why the candidate was not adopted.** Enabled only at the frame-7048 snapshot, the 31-MCLK trial pushes work completion onto line 224 and restores the wait frame. Its pictures 7054 and 7055 match die N-1 exactly, but 7053 still differs by 83 pixels. A separate fresh run of the entire cartridge ROM completes correctly but does not settle the hardware gap: ZRO1 stays at 69,108-69,110 and ZRO2 only improves to 69,799-69,800. Of 86 ZSW1/ZSW2 scalar ranges, 36 contain all candidate repeats versus 32 for the current board; several other results worsen. This is not a complete arbiter correction, and the local OD2 intervention is not a fresh power-on/full-demo validation. No production timing changed in this investigation. Keep the cartridge-cycle completion/WAIT and refresh interaction as the next lead, rather than changing the grant constants or inserting a scene-specific stall. The persistent report is `od2-20k/flaws/logo-vblank-new10.json`; it includes the hardware ranges, ROM fingerprint, bus endpoints, grant/resume measurements, candidate sweeps, and actual picture comparisons. `alewman-probe/HANDOFF-OD2-TIMING.md` requests focused paired-count/phase trials and a FIFO reuse-phase probe for the next console run, with explicit capture provenance and lossless outlier handling. ## Independent Z80 refresh probes Fourteen small ROMs separate stopped/spinning 68000 execution, ROM/RAM CPU loops, single and paired Z80 reads, writes, and H32/H40 VDP reads. Steady-state measurements begin at 750,000 MCLK, after bank initialization. The actual shared bus addresses and Z80 read/write flags are checked, not inferred from ROM names. Every measured grant onset still matches the helper plus the same half-MCLK signal offset. Several cartridge workloads uniquely identify a 31-MCLK completion threshold; paired VDP reads uniquely identify 24. Those are not production changes. **An isolated improvement that did not pass the full run.** The Z80 helper can charge an old cartridge refresh indefinitely. Applying the CPU path's existing self-refresh rule at *grant time* (full 14 through age 112, seven at 119, none from 126) improves the stopped-CPU replay from 1,277 to **1,710/1,710**, at the independently calibrated die phase 524. It leaves the other thirteen equal-arrival replays unchanged. The candidate was implemented and tested in Python and both Rust cores, then run from power-on through frame 16955 with the exact calibrated reset. All 484 plasma pictures agree across the three cores. Nevertheless, it retains the logo slip at 7053 and introduces another frame lead by plasma. After shifting the reference to account for that lead, the same 7,849 plasma disagreements remain. NEW10's ZRO1 CPU counts worsen to 69,319-69,325 and ZRO2 to 70,219-70,221; ZSW range coverage falls from 32/86 to 29/86. CPU-only, local-Z80-RAM, and ZINC controls remain inside hardware ranges. An isolated old-rule control reproduces **506 baseline pictures pixel for pixel** and all 70 previous cartridge-test results, ruling out a stale build or unrelated source change. A separate fresh diagnostic combining expiration with cartridge 31 removes the additional lead but **does not fix the original logo slip**. It still has 7,849 plasma disagreements and worsened shared-ROM counts. The earlier local frame-7048 intervention was therefore not a fresh-boot fix. The expiry-only production changes and their tests were removed from all three cores; the candidate sources, tests, traces, and captures remain in the session evidence. Both Rust release binaries were rebuilt after restoration. Seventy focused Python tests and two DMA/FIFO tests per Rust core pass. A fresh restored 7000-frame cartridge run reproduces all 70 baseline test results. **The stronger RAM lead.** New die traces expose the actual RAM-refresh latches: - All **422 isolated reads and 422 isolated writes** latch an access refresh. A 52-MCLK own-cycle threshold uniquely fits both, consistent with a 31-MCLK base plus the existing 21-MCLK RAM-refresh cost. - Of **808 paired reads**, 690 fit a 31-MCLK base and 59 latch an access refresh. Another 59 need additional timing: 58 have the automatic-refresh latch set at /AS, and one needs further edge tracing. - The automatic-refresh latch can remain set on accesses that need no extra wait. Its value alone is not a remaining-delay model. A constant 52 for RAM would therefore be wrong. The bank-access path currently does not apply the CPU path's RAM-refresh timing. The next change needs shared refresh history and destination-aware completion, including accesses landing during automatic refresh, rather than another global grant constant. The scheduler's supplied bus-cycle history remains a separate item to verify. The headless tracer now optionally exposes [internal node] in type-7 flags bit 7 when trace-mask bit 7 is set: use **239**, not 95, for bus, RAM-refresh, and extended RAM-access records. Mask 111 retains the old fields. A rebuilt isolated oracle produces byte-identical legacy traces; extended traces differ only in the new flag. No shared oracle binary or cartridge source was replaced. The persistent report is `od2-20k/flaws/arbiter-refresh-expiry.json`. It contains the independent replays, fresh three-core picture comparisons, hardware ranges, rejected combined candidate, restoration checks, and measured RAM-refresh classifications. No new emulator timing change was retained. ## The Z80 acknowledgement pipeline Direct /DTACK tracing resolves the apparent destination-dependent completion thresholds into one measured handshake. In **half-MCLK** units, for a Z80 request at `r`, acknowledgement at `a`, and wait count `w`: ``` release = r + 75 + 30*w w = max(2, ceil((a + 47 - r - 75) / 30)) ``` The release is the first allowed sample at least **23.5 MCLK after /DTACK**. Half-clock precision matters: rounding acknowledgements to whole MCLK incorrectly adds or removes waits. Sweeping half-MCLK offsets across the independent cases leaves 47 half-MCLK as their unique common fit: | Case | Exact waits from observed /DTACK | | --- | ---: | | Paired cartridge reads | 2,734 / 2,734 | | Paired VDP HV reads, H40 | 2,846 / 2,846 | | Paired work-RAM reads | 808 / 808 | | Cartridge reads, stopped 68000 | 1,710 / 1,710 | | VDP HV reads, H32 | 1,681 / 1,681 | | Actual OD2 logo window | 4,362 / 4,362 | | **Total** | **14,141 / 14,141** | The logo row contains **4,096 cartridge and 266 VDP accesses**. Its new oracle replay starts from the same frame-7000 state; all **813,408 legacy records** in the common interior window match the earlier trace exactly. The diagnostic did not alter execution or retune reset/refresh phase. Incomplete final requests in the independent cartridge traces are explicitly excluded, not silently passed. This explains why a cartridge threshold near 31 and a VDP threshold near 24 worked in the earlier sweeps: cartridge /DTACK normally arrives 7 MCLK after Z80-owned /AS, while the VDP HV port acknowledges after half a MCLK. RAM adds its own readiness and refresh delays. The release rule is common; device readiness is not. **RAM history is close, but not yet complete.** Replaying the existing CPU `ram_refresh` helper at the measured RAM accesses predicts **804/808** waits. The other four cross a sampling boundary because the actual acknowledgement is slightly later. The previously unexplained non-refresh-latch case is now resolved: its ordinary /DTACK arrives after 8 MCLK instead of the nominal 7, adding a wait. The other three are near automatic refresh. Observed /DTACK plus the common pipeline explains all four; simply rounding the idealized RAM delay to the next dot-clock edge does not predict every acknowledgement edge. The automatic-refresh latch rises exactly 35 MCLK before its completion signal in all 1,012 observed intervals. That is a latch-to-completion interval, not a constant delay to add to every access: an access may arrive partway through. Do not replace the existing 21-MCLK access-refresh cost with 35. **Scheduler check.** Instrumenting both synthetic counter loops and OD2 frames 7048-7054 checks 12,891 reservations against 257,751 recorded CPU bus cycles. There are no recorded CPU cycles retimed after their bus callback, no recorded /AS overlaps with a Z80 reservation, and no CPU starts before modeled resumption. This establishes those grid invariants in these workloads; it does not prove that every device hold is represented with the correct span. **Permanent checker and instrumentation.** `scripts/check_z80_ack.py` accepts raw 24-byte traces and explicit half-MCLK request windows. It checks request length, the next Z80 machine cycle, grant/release pairing, acknowledgement address, and the release equation. Missing evidence, malformed records, empty windows, and half-clock timing errors fail explicitly. New opt-in tracer fields are: - Mask 527: existing bus records plus type-10 /DTACK assertions. - Mask 1007: also RAM latch and completion transitions (type 9). - Mask 2031: also VDP dot-clock edges (type 11). Existing trace fields remain identical when the new records are removed. `nuked_md.read_trace` retains its legacy whole-MCLK conversion; the new checker uses raw `EVENT` records instead. The checker and existing register-latch tests pass **31 tests**; Ruff passes for the changed Python tools. The report is `od2-20k/flaws/arbiter-ack-pipeline.json`, including trace fingerprints, explicit boundaries, the offset sweep, logo replay identity, scheduler checks, and the remaining RAM prediction errors. No new emulator timing change was adopted. The next implementation should predict /DTACK from shared device/refresh state, then apply this handshake consistently in Python, Rust, and Rust-fast and validate fresh runs against hardware. ## OD2T1: hardware constraints and measurement traps The new A1 NTSC console capture has 21 completed tests, 681 records and valid CRCs. All 681 records also agree across the cart agent's saved Python/Rust/fast captures; those identify as A0, not A1. These are existing full-run captures, not new emulator runs after the commits. The cartridge ROM still hashes to `473ee6f6995bbb63403b2ba0d495ca4050fa041be5481ac4376e89196a42abd2`. The local-Z80-RAM controls agree, but cartridge sharing differs on hardware from both the board and Nuked-MD. Four-read ROM bursts already give essentially the same CPU count deficit on board and hardware (15.8051% versus 15.8107%), while the board's Z80 completes too many turns. The die's 23.5-MCLK pipeline is therefore **not hardware-confirmed**; do not adopt it solely on the trace fit. Two measurement traps were checked before deriving new arbiter constants: - The paired counters share a repeat number, not an identical window. `run_zcount` starts the Z80 almost one frame before the CPU's 16-frame loop, then stops it after recording the CPU count. Even the no-wait Z80 control requires 15,220,380 MCLK, more than the 14,336,640 MCLK in 16 frames. - A fresh isolated H32 FIFO trace produces an HV-derived duration of 3,960 MCLK for reads actually 609 MCLK apart (600 between sample edges). The configured HV unit returns `$4184` while the internal counter is `$4187`, crossing the converter's `$85` line origin. All 48 real burst durations are 476-812 MCLK, identical on the A0 and A1 board variants. This demonstrates an alias, not a timestamped replay of the saved full-run 3,920-MCLK outlier. The cart comparison tool now flags suspect durations without changing the raw statistics; its seven focused tests pass. No emulator timing was changed. The [cart handoff](../../../md-probe-cart/HANDOFF-OD2-TIMING.md) explains the unequal windows, matching-control estimates and the next common-window test. The [hardware report](../../../od2-20k/flaws/hardware-od2t1.json) retains input fingerprints, all 41 programs, raw outlier pairs and fresh trace evidence. ## VDP data-port bus ownership The CPU resumption constant is not the next missing delay: 26,722 observed resumptions, including an independent long-DIVU workload and the real logo window, satisfy the existing lower bound. The concrete error is in the bus history supplied to the arbiter. VDP data-port waits were added to CPU instruction time but omitted from that CPU access's /AS span. A synthetic active-display VRAM FIFO writer, with concurrent Z80 cartridge reads, makes this visible without scene-specific timing changes. In the steady window, the old board gives 1,696 Z80 grants, **1,169 inside a held CPU /AS**. Recording the data-port holds gives 1,198 grants and **zero overlaps**. An equal-arrival replay of the die's own CPU cycles verifies the mechanism: **1,193/1,193 grant onsets** match with complete spans, versus **354/1,193** when the data-port holds are omitted. The established half-MCLK signal offset is unchanged. The die and corrected board can charge 49 Z80 wait states when the FIFO keeps the CPU waiting; the old board incorrectly stayed at 2-5. Retained in Python, Rust and Rust-fast: byte and word data-port reads/writes, including mirrors, extend the current CPU bus span by the rounded wait. Python reuses `Board.hold`; both Rust ports use the same rule in `Devices::vdp_hold`. Disabled arbitration/recording cannot extend a stale entry. Control-port DMA holds remain separate: the whole DMA duration is not a CPU /AS assertion. No grant, release, refresh, FIFO commit or FIFO acknowledgement constants changed. Validation: - 46 targeted Python tests and four tests in each Rust core pass. Both release libraries and the standalone capture binaries were rebuilt. - Fresh power-on runs through frame 16,955 use the exact calibrated reset. The boundary remains 26,601,656, post-reset clock 26,602,909, refresh phase 375. - All 809 Rust captures agree across both ports and an isolated same-source stall-only control. All 506 Python plasma captures agree with both Rust ports and the prior baseline. **No captured OD2 picture improved or regressed**; the logo frame slip and plasma defects remain. - The original OD2 timing cartridge completes 21 tests and 681 CRC-valid records, all identical to the same-start isolated control. Stop on first completion (frame index 3,158), not a fixed 4,000/7,000-frame endpoint that captures a later partial run. Older stored captures have a different startup phase and are not an exact per-repeat control for this harness. - New Python tests pass Ruff and all worktree whitespace checks pass. The existing `board.py:180` E501 is also present in HEAD and was left untouched. Evidence and input fingerprints are in [the ownership report](../../../od2-20k/flaws/vdp-bus-ownership.json). The [cart handoff](../../../md-probe-cart/HANDOFF-OD2-TIMING.md) now requests concurrent Z80-bank/CPU-FIFO traffic; the existing cart tests exercise those loads separately. ## Bounded plasma request investigation The observed missed requests result from display gating, not a later VRAM-slot loss. `scripts/check_register_latch.py --hscroll` now checks that causal chain from CPU writes and independent HCLK1/HCLK2 edges, without using observed DISPLAY changes as the prediction. It first verifies the predicted register commits against DISPLAY, then checks requests at HCLK2 rising with H=$1E7. All **896 visible opportunities** match: 224 H32, 224 H40 and 448 in the saved two-frame plasma trace. The existing 1,816 display transitions remain exact. The checker covers stable mode-5 V=0..223, not later scroll-data fetches. Its 28 focused tests, including half-clock precision, missing/incorrect requests and a one-MCLK boundary, pass; Ruff passes. The runtime-only gate was rerun from the latest fresh calibrated Python snapshot. Across the same 484 pictures, disagreements increase from **7,849 to 15,788** (33 pictures improve, 176 worsen, 275 are equal). This is not a production change. In picture 16555 (Python activity frame 16554), rows 35 and 184 recover, but rows 36 and 37 gain 45 wrong pixels and row 102 still has 18: 72 disagreements become 63. Matching the preceding 140 CPU accesses for each selected row introduces no sequence gaps. Two local causes are now isolated: - **Row 36:** ROM read `$3FB73C` takes an extra 14-MCLK cartridge-refresh hold in the board but not the picture-aligned die trace. Removing only that hold in a diagnostic replay moves display-on from offset 557 to 536, and its predicted register commit from 585 to 567, before the request at 580. Both rows 36 and 37 recover; row 37 had inherited the wrong retained scroll. All 90 compared preceding pictures remain identical to the gate control. This is a causal intervention, **not a refresh correction**: the arrival still differs by 6 MCLK from the die's 530. - **Row 102:** the board writes display-on at offset 552 and the die at 553. Independent H40 clocks predict commits at 576 and 585 respectively, with the request at 580. The observed die commit is exactly 585. One MCLK of CPU arrival difference is enough to reverse this request, without any extra VDP contention. Offsets above use the board line origin; the physical die counter origin is 15 MCLK later. The picture-aligned origins differ by 240,277 + 1,070,460 + 15. The extra PAL frame is 6 mod 7 and 636 mod 896: it changes both the CPU phase and the cartridge-refresh phase. Thus the original frame advance is relevant even when the images have been aligned correctly. The row-36 intervention leaves only row 102's 18 pixel disagreements in the selected picture; it is not adopted. No emulator-core files or timing constants changed in this pass. Stop tuning the local deadline: resolve the upstream frame advance, then implement the persistent request/fetch/latch path and recheck the full window. The measurements remain die-derived, not hardware-confirmed. Input hashes, all comparison counts and the counterfactual limitations are retained in [the causal report](../../../od2-20k/flaws/plasma-request-cause.json). ## Logo gap attribution and coupled readiness The current Python core exactly reproduces all 23,732 logged CPU cycles between the critical matching `$31C842` and `$31C812` fetches. Recording grant waits separately from device holds, then using the die's observed Z80 releases, explains **23,655/23,655 matched ordinary CPU intervals with zero residual**. The board-minus-die duration remains -2,506 MCLK: | Contribution | MCLK | |---|---:| | Z80 blocking in the matched ordinary intervals | -2,450 | | CPU access holds in those intervals | +210 | | Three DMA return intervals | -7 | | Remaining unmatched interrupt-relocation boundaries | -259 | The last term is a bookkeeping remainder around differently placed interrupt entry/return, not evidence that the interrupt itself is wrong. The matched ordinary intervals need no new CPU internal-cycle or resumption constant. The remaining cartridge-readiness errors expose a second refresh interaction. The old request+50-MCLK look-ahead can select the previous refresh tick even though a new tick arrives before the actual grant. All eleven remaining logo refresh mismatches have this form (ten grant exactly one refresh period after the selected tick, one 14 MCLK later). Extending the horizon alone is incomplete: an independent FIFO writer can hold the CPU long enough for an old refresh to expire before the Z80 gets the bus. With the actual grant covered, the existing expiration rule (14 MCLK through age 112, seven at 119, none at 126 or later) predicts cartridge /DTACK at observed grant+7 MCLK plus the remaining refresh time. The measured 23.5-MCLK ACK-to-release pipeline then predicts: - All 4,096 cartridge ACKs and waits in the logo trace. - All 1,171 ACKs and waits in a new independent long-held FIFO trace, including seven partial-refresh acknowledgements. Existing records in the common trace interior remain identical when ACK records are removed. - All 14,516 cartridge waits in eight earlier independent workloads. That is **19,783 exact cartridge waits**, including **5,267 exact ACK predictions**. The isolated compiled Rust-fast implementation reproduces those 5,267 oracle waits, plus the 266 VDP predictions of the unchanged non-cartridge model. The latter are deliberately not claimed as exact against the die. No general work-RAM or VDP-readiness implementation was added. ### Fresh-run rejection and the next divergence An isolated copy of the current Rust-fast source combines the measured cartridge completion, expiration and extended horizon. Production sources and binaries were not swapped or modified. A power-on run reaches frame 16,955: - The exact reset pulse remains 26,601,719, the post-reset clock 26,602,909 and cartridge phase 375. The preceding instruction boundary is now 26,601,621, rather than the baseline's 26,601,656. - Only nine of 809 captured images change. All captured logo images and all 506 plasma images are identical to the baseline. The original slip remains at 7053 and the 484-frame plasma comparison still totals 7,849 disagreements. - The same-start timing cartridge completes all 21 tests and 681 CRC-valid records at frame 3158. Of those records, 305 change. The ROM CPU-count deficit moves from 15.8090% to 15.4342%, away from hardware's 15.8107%; its estimated whole-run extra Z80 time moves from 2.6163 to 2.5565 T/read, also away from hardware's 2.8286. These are paired-count observations, not simultaneous-window per-access hold measurements. The fresh-run failure is not the same workload with a slightly different delay. The candidate's critical instruction-bounded interval contains **768 cartridge accesses and 65 non-cartridge accesses**, versus baseline 1,024 and 14, and die 1,024 and 15. Its first 256-byte cartridge burst starts about 94,000 MCLK later; only three such bursts fall in the work interval, rather than four. The changed polling path is visible at `$7F08`: the candidate reads V-counter zero near offset 307,324, while the corresponding die poll at offset 307,623 returns one. The candidate then takes additional polls before its first ROM burst. These offsets have different anchors: the candidate sample time is relative to the baseline's board start, while the die's is its request time relative to the die start. They identify the differing observation, not an exact sampling-delay fit. VDP time clamping is **zero** on all recorded reads in both runs. Diagnostic tracing leaves every candidate instruction record byte-identical. **Do not adopt the candidate.** Equal-arrival cartridge correctness does not yet give the correct closed-loop driver path or hardware counts. The next bounded question is the Z80 polling phase and branch around V=0 versus V=1, including the still-unmodelled VDP-specific completion timing. Evidence, exact partition, source hashes and the fresh-run rejection are in [the readiness report](../../../od2-20k/flaws/logo-readiness-cause.json). ### Counter-poll branch follow-up The zero-versus-one observation above is not sufficient to explain the missing ROM burst. A controlled replay changes only the baseline's `$7F08` return from one to zero at 7,546,747,709 MCLK, preserving its sampling time. All 1,316 CPU steps and all 1,016 Z80 instruction paths/timestamps/lengths/waits in the checked window remain identical. Only 26 instructions have differences in the recorded register fields, which reconverge. Both values take the same carry branch at `$061C` after subtracting `$7B`. The observed candidate divergence is later: sampled PC proceeds from `$0697` to `$0684`, while baseline and die proceed to `$0699`. In the baseline code this branch follows `EX AF,AF'` and `CP $35`; baseline A is `$BE`. Passing the gate subtracts `$32` before ROM-transfer setup. Candidate registers and bytes at this gate still need direct capture, particularly because the driver has self-modifying instructions elsewhere. The next question is the earlier alternate-A state evolution, not a special zero/one V-counter behavior. No production change was made. Assertions and input hashes are in [the branch report](../../../od2-20k/flaws/logo-poll-branch.json). The standalone continuation guide is [the Fable handoff](../../../od2-20k/flaws/FABLE-HANDOFF.md). ### The candidate's sample-page countdown Direct isolated-candidate tracing now confirms the bytes and state at the gate: both runs execute `CP $35; JR C,$0684`, but the candidate has A=$1D (29) versus baseline $BE (190). The candidate therefore rejects the opportunity. The complete instrumented fresh CPU CSV is byte-identical to its prior control. A wider baseline replay reproduces all 26,583 CPU steps. The accumulator is initialized by `XOR A; SUB C` in the sample-register bank. At 139 checked wait-loop boundaries, A is exactly `-C_alt mod256`; BC_alt is the sample-read address. The last initializations and all subsequent updates account for the gate values without a fitted timing constant: - Baseline: initialized238, then24 subtractions of2, yielding190. - Candidate: initialized255, then113 subtractions of2, yielding29. The next transfer setup is 93,915 MCLK later in the candidate, matching the first-ROM-burst displacement. At the poll, sample pointers are baseline $1342 and candidate $12E3; the die's corresponding local read is $1441. The baseline and die low bytes are close, but full addresses differ: this does not prove matching audio data or an absolute sample lag. The next question is the earlier sample-pointer/driver phase that establishes this countdown difference. The individual counter byte and the countdown must not be patched. Production remains unchanged. Assertions, trace-neutrality checks and source hashes are in [the countdown report](../../../od2-20k/flaws/logo-sample-countdown.json); [the Fable handoff](../../../od2-20k/flaws/FABLE-HANDOFF.md) is updated. ### The Z80 sample stream's drift (2026-11-06, diagnostic only) The die's Z80 sample pointer leads the board's by 255 samples throughout the logo window (frames 7046-7049, ~1,540 compared reads, twelve ROM bursts, +-1 jitter); both run at one sample per 2016 MCLK, YM2612 timer A polled at $4080. The lead is not one event. The 68000 reloads the driver at board frames 15, 40, 241, 1488 and 2006, and after the 2006 reload both machines resume within about one sample of each other. From there the die-minus-board DAC-write count (at equal absolute time) wanders: +60 at 2000, +315 at 3000, +345 at 3500, +215 at 5000, +365 at 5750, +246 at 7046, against 255 read directly in the logo window. Per code site over frames 1500-6413 the die emitted 1,057 fewer timer-polled samples and 1,349 more unpolled ones (the V-counter poll path at $0618, $05D9, and the unrolled burst code), net +258. So the slip's "sound phase" is the sum of per-iteration races in the driver's wait loop, decided by the Z80's loop timing (its arbitrated $7F08 read, its bank-read waits, the 68000's bus activity); the integrated count is a judge for any Z80 timing model, alongside same-arrival waits and the cart. Nothing in production changed. Scripts, data and the full write-up: `od2-20k/flaws/sample-phase/` and [the Fable handoff](../../../od2-20k/flaws/FABLE-HANDOFF.md), section "Z80 sample phase". ### The first lost sample: V-int against BUSREQ (2026-11-06, diagnostic only) Following the sample-phase drift above, the die's and the board's Z80 instruction streams were aligned over frames 1500-1510 (`od2-20k/flaws/sample-phase/divergence/`). The driver's loop is not on a knife edge: a polled pass costs one timer-A period and a polled-plus-unpolled pair two, so the stream runs at one sample per 2016 MCLK and the Z80's phase is re-synchronised at every pass. A sample moves only when the driver's reg $27 reset crosses a timer overflow. The first such event (board time 1606458000, frame 1501) is decided by the 68000. Once per frame it writes the driver's mode byte at Z80 RAM $05A2 under BUSREQ, about 700 MCLK after leaving a 210-MCLK VDP status-poll loop, and V-int lands within tens of MCLK of the `move.w #$100,$A11100`. Taken after it (die, frame 1501) the handler runs with BUSREQ held and the Z80 stalls ~1170 MCLK; taken before it (board) the Z80 is held ~150. The two machines resolve that race differently in 6 of 11 frames because their 68000s enter the poll loop up to ~1000 MCLK apart (board 1043 early in 1501, 406 late in 1508), which sets the poll phase at exit. Both VDPs raise V-int and the VBLANK flag at the same phase of the frame within the reads' resolution. So the Z80 sample drift measures the 68000's per-frame timing error; the Z80's own arbiter waits (bank LDI die 48.4 vs board 45.5 MCLK mean, $7F08 die 39.1 vs board 43.7) never cross an overflow in this window. Write-up and per-frame table: `flaws/FABLE-HANDOFF.md`, "The first lost sample". No core code changed. ### The 68000's frame work partitioned: the Z80's own cycle per target (2026-11-07, diagnostic only) Die 68000-bus trace (Nuked-MD, frames 1500-1501) against a board log of every 68000 bus cycle over frame 1501's work window: 29,345 identical cycles, the board 889 MCLK faster, all of it in the Z80's accesses on the 68000's bus. The Z80's own cycle on the bus is never shorter than 31 MCLK for a cartridge read on the die (31-45, then the refresh tail) and never shorter than 24 for a VDP read (24-38); `arbiter.OWN_CYCLE_MCLK` = 29 gives 29-43 for both. So the board ends 64 of the driver's 508 LDI reads per frame a wait state early (the 68000 held 2.5 MCLK less per read, -1085 per frame) and its ~105 $7F08 reads a wait state late more often (+4 per read). With 31 for the bank window and 24 for the VDP, set in diagnostic copies of the logging scripts, the board reproduces the die's wait-state and 68000-hold distributions for both targets (cartridge: waits mean 3.23 vs 3.22, hold 74.3 vs 74.2; VDP: 2.50 vs 2.59, 65.9 vs 66.4) and the frame's 68000 work closes to -392 (the rest is which Z80 accesses fall inside the span). The sample drift at frame 7046 nevertheless gets worse (+872 vs +246 samples): the V-int/BUSREQ race is decided by tens of MCLK, below the remaining per-frame difference, so the drift cannot judge the constant and must not be used to. Before any production change the per-target own cycle wants `scripts/run_nuked_md.py arbiter` and the first-80-frames arbiter comparison rerun with it (the referee builds natively; not possible on the Windows box). Write-up: `flaws/FABLE-HANDOFF.md`, "The 68000's frame work partitioned". No core code changed. ### The Z80's own cycle per target, on the repo's own experiments (2026-11-07, diagnostic only) The referee builds in WSL (`wsl sh validation/build_nuked_md.sh`) and runs from the Windows venv through a WSL-routed copy of `nuked_md.run` (`od2-20k/flaws/sample-phase/divergence/ nmd_wsl.py`). `scripts/run_nuked_md.py arbiter` with the own cycle at 29 and at 31 for the bank window: the 68000-stopped and `jmp (a0)` reading experiments are unmoved (2.49 and 2.74, the same counts, the referee 2.25 and 2.74); the `pop` moves to the referee -- 3.37 (was 2.93, referee 3.27), its second read 3.74 with 708 of 1000 at four wait states (was 3.09, referee 3.60, MoD on hardware "at least 4", mean 3.5). The case "The arbiter, measured" left open is the own cycle being two master clocks short for a cartridge read. The boot judge (`od2_boot_drift.py`) could not be reproduced here (a fresh referee boot trace against the worktree walks 2,105 refresh-hold steps in its first 1.25M MCLK at the shipped constant, so it judges nothing); it needs the original `reference/z80-reset` trace. `arbiter.OWN_CYCLE_MCLK` is unchanged; the production change would be per target (31 cartridge, 24 VDP), gated on that judge. Write-up: `flaws/FABLE-HANDOFF.md`, "Validation on the repo's own evidence". ### The boot walk: five mechanisms (2026-11-07, diagnostic only) `scripts/od2_boot_drift.py` against a fresh referee boot trace (od2-noh.bin, `-pal`, `NMD_RESET=53523000:64227600`, machine `nuked-md`, reset 26,601,719), each first step dissected on both sides of the bus and patched as a diagnostic (od2-20k `flaws/sample-phase/divergence/`: `arb_diag.py`, `busack_diag.py`, `fm_diag.py`). The step-free span after the Z80's start: 516,558 MCLK as shipped; 543,466 with the Z80's own cycle per target (cartridge 31, VDP 24); 1,113,252 with a refresh tick owed to the Z80's cycle only while pending (`Board._arbitrate` rebuilds the last tick as due - 896 after a 68000 cycle has passed it and stretches the Z80's cycle for a refresh that ran by itself); 1,255,331 with the grant as the refresh horizon; 1,379,490 with the Z80 letting go at the end of the machine cycle BUSREQ is sampled in even when the rest of the instruction is internal (`catch_up_z80` deferred only on an access past the sampling point); 1,710,800 with the instruction that starts at the 68000's clock recorded as partial in `z80_busack` (else re-run whole after the release, 45 MCLK late); 8,872,836 with the YM2612's timer-A flag not set by the overflow produced in the cycle of a flag reset (the die loses the overflow and waits a period; the [GPL source] order sets it in the next cycle; delaying the reset instead breaks earlier windows). The Z80 streams agree per instruction through every dissected window (`z80_walk.py` on the referee's dual-CPU traces). Residual: the board's overflow 42 MCLK after the die's. Nothing in production; write-up and what landing needs: `flaws/FABLE-HANDOFF.md`, "The boot walk". Later the same day: a sixth, the bus request sampled on a machine cycle ending 32 MCLK after the 68000's write rather than 33 (`Z80_BUSREQ_LAG_MCLK`; the die at boot +8,748,369 takes the cycle whose last-T edge sits exactly at the /BUSREQ fall), takes the step-free span to 9,941,344 MCLK, and the Z80 instruction streams agree with the die's through every window walked, +1.2M to +8.95M. A one-cycle-earlier timer flag was tried and rejected (it breaks the early windows). Diagnostics only; handoff "A sixth, and the Z80 streams in lockstep". ### Five of the six rules landed in the spec (2026-11-07, evening) In production now, each with its event from the boot walk as a test (`tests/test_z80_bus_rules.py`, six tests): `arbiter.OWN_CYCLE_CARTRIDGE_MCLK` 31 and `OWN_CYCLE_VDP_MCLK` 24, `z80_access_wait` taking the own cycle as a parameter and `Board._arbitrate` passing it by target; the refresh tick owed to the Z80's cycle only while pending (`tick >= cart_refresh_due`) and found on the horizon `max(request + 50, grant)`; `System.catch_up_z80` deferring an instruction whenever its last machine cycle ends past the sampling point; `System.z80_busack` recording as partial the instruction that starts at or before the 68000's clock; `Z80_BUSREQ_LAG_MCLK` 32. The sixth, the YM2612's flag reset in an overflow's cycle losing the overflow, is ym2612-python's (pinned at 2c2ab23 here; no clone on this box): `flaws/sample-phase/divergence/fm_diag.py` "coincidence" is the rule, boot +1,709,651 the event, and its own `run_fm_timer.py` loads must stay exact. Checks: the suite 318 passed, 13 skipped (PyPy; `test_milestone6`'s four referee-stream cases deselected: the referee at `reference/build-nuked-md/` is now a Linux build made in WSL for the walk, which the test tries to execute natively and cannot -- it used to skip when the binary was absent); the boot judge on the production path with the FM rule as a diagnostic: first step +9,941,344, exactly the all-diagnostics figure; without it +1,710,800, as expected. `run_nuked_md.py arbiter` on production: the 68000-stopped and `jmp (a0)` cases unchanged (2.49, 2.74), MoD's `pop` 3.29 against the referee's 3.27 (was 2.93), its second read 3.61 against 3.60 (was 3.09; hardware "at least 4"). Not committed or staged; the worktree's other changes (board.py's VDP hold and DMA pending, vdp.py) untouched. Night: the sixth rule in ym2612-python (`chip.py` `_timer_a`, `timer_a_overflow_masked`; `tests/test_timer_reset_race.py`; a local clone of ym2612-python installed editable here), and in ym2612-rust-fast and ym2612-rust; the five board rules ported to megadrive-rust-fast and megadrive-rust (`od2-20k/flaws/sample-phase/divergence/rust-rules.patch`), the lockstep examples regenerated from this spec at HEAD and exact in a clean checkout of the fast board. The boot judge on this spec with no diagnostics: first step +9,941,344. The detectors do not move: the fast board's flaw map 192,858 wrong pixels against HEAD's 192,513, the 7052 slip as it was, the per-frame sample drift +814 at 7046 against +246 and now monotone. Six rules right at their own level, two with hardware figures behind them, and nine clean frames of 7,052: the walk's yield per cause is frames, so the next step is the race's distribution over thousands of frames, not more walking (handoff, "All six landed in every core"). The referee stream tests skip on Windows now (`tests/test_milestone6.py`). 2026-11-08 (Fable). The investigation protocol's Experiments 6-12 (od2-20k `flaws/FABLE-HANDOFF.md`) land two rules and withdraw one. On matched time axes (the pass log now stamps Z80 events at `board._z80_access_time()` and FM edges at the cycle's start) the board took the Z80's FM write at the access's start where the die takes it 23 MCLK later: `Z80_FM_WRITE_MCLK` in `board.py`, `z80_fm_write_lag` with die figures, applied in `z80_write`'s FM branch; test in `tests/test_z80_bus_rules.py` (a cycle ending 22 after the access runs before the write, one ending 24 does not; die: +9,150,686 rejected a 22.5, frames 2500-2700 take 24.5). With the landing right, the YM2612's "masked overflow" rule of 2026-11-07 proved to be compensation: the die's coincidence window is one cycle wide (11.7k free-phase passes: loss exactly for the reset's phase > 1865.5 of 2016 after the last overflow; every lost pass 2,205 MCLK), which is [GPL source]'s own order -- withdrawn in ym2612-python and both Rust FM cores, tests rewritten. Gates: production boot judge first step +13,150,942 (was +9,941,344); lockstep examples exact between a clean Python HEAD with only the rules (a `python-head` worktree) and the clean fast board; suite 319 passed. Detectors: the per-frame sample drift loses its monotone bias (+154 at 5500 against +631), the 7052 slip does not move, frames 8042-8108 get worse on the map. Experiment 3's "two-valued board phase" was a stamp artefact (batch-end flag times) and is withdrawn. ### A Model 1's cartridge cycle, and the FM's write timing on every machine (2026-11-10) Two changes to the consoles, none to the `nuked-md` machine (its example trace is unmoved). **The Z80's cycle on the cartridge is longer on a Model 1 than on the die.** `arbiter.py` `MODEL1_CARTRIDGE_EXTRA_MCLK` (3: the cycle itself, both CPUs) and `MODEL1_CARTRIDGE_RELEASE_MCLK` (1: the Z80's /WAIT let go that long after the cycle's end, the Z80 only; `z80_access_wait`'s new `release`), carried by `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`. Hardware-captured, three judges over a 6 x 5 grid of the two figures: - the probe cart's ZBS counts on an NTSC Model 1 with TMSS: summed relative error of 14 group means 12.67 % with the die's figures (the die itself: 13.13 %), 4.03 % at (3, 1); a valley along sum = 4, minimum 3.75 % at (2, 2), 5.00 % at (4, 0); - its ZRO1/ZRO2 counts, outside the console's ranges by 885/86/535/164 (68000/Z80, twice) with the die's figures, 100/36/0/0 at (3, 1), 0/10/0/3 at (4, 0); - the PCM stream of a PAL console's capture of Overdrive 2 against the board's WAV (the lag of the sample-playback layer is the console's sample position less the board's): the console behind the `megadrive` board by 74 ms in the opening track and 343 ms by the end with the die's figures, 6 and 151 ms at (3, 1). The split is the least certain part: the three agree on about 4 MCLK (~75 ns) and differ on how it divides. Against it, and the reason the Model 2 keeps the die's figures: MoD's logic analyser on a Genesis 2 sees "2-3" wait states with the 68000 stopped, which the die's figures give (2: 68 %, 3: 32 %) and these do not (2: 33 %, 3: 50 %, 4: 17 %); his `jmp (a0)` and `pop` cases do not move with either. So either the Model 2's arbiter is the faster, or the extra is not all in the cycle's length. A stopped-68000 count on the probe cart (the Z80 reading the bank window with the 68000 in `stop`) would say which; `scripts/run_bus_arbiter.py` now runs MoD's experiments on `genesis2`, his console, and takes a machine. **Every machine takes FM writes as the die does.** `Z80_FM_WRITE_MCLK` (23), the 68000's `M68K_FM_WRITE_MCLK`/`M68K_FM_READ_MCLK` (21/27) and the timer's control delay were on `nuked-md` only, the consoles taking a write at its access's start. Still die-derived: no hardware measurement of the lags exists (the probe cart's race build, YMLW, is the test, and its board predictions were run without them: on a die-tier NTSC machine the board loses the die's passes at every delay step, 5,065 of 16,320 against 5,062 of 16,291). The hardware evidence is indirect, the same capture: with the cartridge cycle as above, the console behind the board by 1 to 24 ms to frame 16,400 and 80 ms at the end with the lags, 6 to 72 and 151 without. What neither does: against the die's pictures only pace moves (Overdrive 2's flaw map: 1,484 frames differ against 1,480), and the frame the console and the die draw at 7,052 is no longer drawn, the board's PCM being 8 to 11 ms ahead of the console's there, where before it was 100 ms ahead and drew it. Open: a creep of about 2.4 ms per 1,000 frames from 4,100 to 13,000, steps at the stream's restarts near 16,400 and 19,300. Gates: suite 333 passed (`tests/test_model1_cartridge_cycle.py` new); of the five lockstep examples only `board-tour.trace` (the `genesis` machine) moves, and both Rust boards match it; Overdrive 2's first 1,500 frames on `genesis`, `megadrive` and `genesis2`, spec against both Rust boards: see the Rust boards' build records. ### The Model 1's release back to 0: a picture judge for the 68000's side (2026-11-11) `MODEL1_CARTRIDGE_RELEASE_MCLK` 1 -> 0 (`Machine.z80_cartridge_release` on the five Model 1s); the cycle's extra stays 3 and `z80_access_wait` keeps its `release` argument. The fourth hardware judge is the console-model scene of Overdrive 2 in the PAL console's capture: the background grid scrolls a pixel a frame, so its phase dates the frame each of the model's 30 pose changes (die frames 7,952-8,076) appears on, with no alignment of capture to board. The console shows them on the die's frame to 7,965, a frame early to 7,984, on it to 8,038 and a frame late from 8,043. Poses on the console's frame, of 30: (3, 1) and (4, 0) 4 (a frame late from 7,968 on); (3, 0) 30; the die's figures 30; (2, 2) 25. With (3, 0): ZRO 0/36/2/0 counts outside the console's ranges, ZBS 5.68 %, the PCM lag 13 ms in the opening track and 86 ms at the end (1 and 80 at (3, 1)). The redraw ends at the vertical blank's deadline, so the judge bounds what the 68000 loses and does not measure it. Against the die's pictures the frames 7,968-7,984 and 8,042-8,108 of that scene remain different, as the console's are. Gates: suite 333 passed; `board-tour.trace` regenerated (the `nuked-md` one unmoved); Overdrive 2, 1,500 frames, identical between the spec and both Rust boards on `genesis`, `megadrive` and `genesis2`. Not rerun: the 80-case gate. ### The Z80 waits out a DMA (2026-11-11) A 68000-to-VDP transfer owns the 68000's bus from its trigger write to its last read, and a Z80 access over that bus (the bank window, the VDP through $7F00) asked for in that time now waits for all of it. The board had let such an access through at its ordinary cost, 60 to 105 MCLK. Found from sound, not pictures. The die's own audio (`NMD_AUDIO`, 250-frame windows from its saves) holds its place against a PAL console's capture from frame 10,000 to the end (15 to 18 ms; before that it gains on the console, about 13 ms over frames 1,750 to 4,000 and 15 over 4,500 to 10,000, as the die's cartridge figures make the board do), while the board's music ran ahead of the die's: by 9 ms at frame 13,000, and by 40 ms more over frames 15,360 to 15,600 alone, 0.65 % fast for five seconds. In that scene the die's Z80 trace has cartridge reads 645 to 1,395 MCLK long behind 40-word transfers and one of 97,000 to 126,000 (the trace's 16-bit length wraps: taken from the next record) behind a 3,376-word one, 27 short and one long in each frame where the sample player's 256-byte block read meets the transfers, five frames in sixty: 1.16 % of the Z80's time. `arbiter.py`: `DMA_Z80_GRANT_MCLK` (16: the Z80's own cycle begins that long after the transfer's last read; the die's reads end 23 to 47 MCLK after its last memory select ends, 34 reads) and `DMA_Z80_RESUME_MCLK` (-11: the 68000's cycle after such a read is already under way and only stretched, ending 7 MCLK after the Z80's read, all 28 hand-overs; charging it the ordinary `RESUME_MCLK` cost the 68000 36 MCLK a transfer and put the console model's poses a frame late again). `VDP._transfer` records the hold (`Board.dma_bus`), `Board.arbiter_grid` gives it to `z80_access_wait` as one long bus cycle, `_arbitrate` and the probe in `system.py` use it. Die-derived, on every machine. With it the `nuked-md` board's holds have the die's shape (27 of median 1,290 MCLK and one of 72,000 to 110,000 a frame, six frames in a hundred). On `megadrive` the console's music is behind the board's by 12, 2, 8, 12, 19, 21, 28, 32 and 36 ms over the nine sections of the demo, where it was 13, 3, 10, 14, 24, 26, 63, 83 and 86; the console model's 30 poses stay on the console's frame; against the die's pictures 1,451 frames and 306,566 pixels (1,481 and 311,789); those are from a build of the fast Rust board without its other pending work, and the fast board proper, in lockstep with this one, gives 12, 2, 9, 14, 20, 20, 25, 27 and 32 ms. The scene's rate of holds turns on where the block reads fall in the frame, so what is left there (the die-tier board 15 ms behind the die after it, where it was 40 ahead) is a realisation and not a figure to fit. Outside that scene the `nuked-md` board's music now keeps within 5 ms of the die's from frame 250 to 15,250 (30 windows of the die's audio). Gates: suite 338 passed (5 new, `tests/test_dma_bus_hold.py`); the five example traces unmoved; Overdrive 2, 1,500 frames, identical between the spec and both Rust boards on `genesis`, `megadrive`, `genesis2` and `nuked-md`. Not rerun: the 80-case gate. ### The unarmed trigger on the die's figures only (2026-11-11) Scoring the fast Rust board proper (in lockstep with this one) against the die's pictures of Overdrive 2 on `megadrive` found the plasma (die frames 16,470 to 16,955) in black bands: about 28,000 wrong pixels a frame, 14,825,188 over the demo, where a build without the pending VDP work has 20 to 60 a frame. A PAL console's capture shows no bands. One piece of that work off at a time, on `megadrive`: the FIFO's CPU release off, worse; the /AS extension of a VDP hold off, no change; the unarmed trigger's queue off ("Resolving the short DMA trigger": a transfer whose source-high register was not rewritten lets the 68000 run one more cycle before the grant), the plasma right again. On `nuked-md` the plasma is right with the queue and without it. Moving an unarmed transfer's start-up on `megadrive` by -28 to +21 MCLK does not mend it, so it is not a start-up figure. The other candidate was to give every machine the die's DMA figures. The probe cart's DMA measurements on an NTSC Model 1 partly ask for it (`genesis-tmss`: the VSRAM and VRAM-write start-ups and the VRAM pace come inside or next to the console's ranges, the CRAM start-up stays 83 MCLK out, and three Z80 counts leave their ranges by 4 to 30), and it draws the plasma right, but it puts 26 of the console model's 30 poses a frame later than the console shows them. Not taken. `VDP._run_transfer`: the queue is taken with the die's figures only (`_dma_die`). Kabuto's start-up is a lump measured on consoles; what the unarmed trigger does to it there is not measured. On `megadrive`, fast board: the plasma 304 wrong pixels over seven sampled frames (as `nuked-md`); the demo against the die's pictures 1,449 frames and 316,835 pixels; the console model 30 poses of 30; the console's music behind the board's by 14, 3, 8, 12, 19, 19, -2, 2 and 5 ms over the nine sections (40 to 6,000 Hz), where the broken plasma's pace had left 25, 27 and 32 at the end. The probe check is unmoved (its transfers all rewrite the register). ### The Z80's refresh runs by itself; the Model 1's extra to 4 (2026-11-12) The die (Nuked-MD) on alewman-probe's single-test ROMs, the Z80's cartridge reads against the 68000's cycles: on ZBS3 (the 68000 in DIVU, mostly off the bus) the board stretched 1,293 of 4,404 Z80 reads for a refresh where the die stretched 624. On the die a refresh left alone on a free bus runs by itself: a read whose own cycle begins 0 to 112 MCLK after the refresh fell due is stretched 14, one at 119 by 7, none from 126. The 68000's side has had this rule since 2026-11-07 (`CART_REFRESH_SELF_MCLK`); the Z80's side now has it too (`REFRESH_SELF_MCLK`, `z80_access_wait`: within the 14 MCLK of the refresh's own run the cycle waits for its end, rounded up to the 7 MCLK grain). With the die's figures (`genesis-tmss` with extra and release 0): ZBS3 Z80 9,440 and 68000 11,837 against the die's 9,439 and 11,838 (9,413 and 11,813 before); ZBS1, ZBS2 and ZBS5 within 0.1 % of the die. The RAM-loop gap noted earlier was the experimental tree's, not this board's. The old rule over-charged the Z80's refreshes, and the Model 1's 3 MCLK extra had been partly paying for that. With the new rule the console's ZBS3 (Z80 9,338 to 9,339, 68000 11,726 to 11,729) is met by (4, 0) at 9,338 and 11,724, where (3, 0) gives 9,383 and 11,781 and (3, 1) 9,339 and 11,726. Over all of ZBS (14 groups) the summed relative error is 4.27 % at (4, 0), 3.53 % at (3, 1) and 6.54 % at (3, 0); ZRO1's Z80 count is 10 outside the console's range at (4, 0) against 36 at (3, 0), ZRO2's 2 to 3 against 0, and hwref's OUT count is 5 against 4. (3, 1) puts 26 of the console model's 30 poses a frame late; (4, 0) and (3, 0) show all 30 on the console's frame with the new rule (before it (4, 0) showed four). The plasma is right at both (304 wrong pixels over seven frames). `MODEL1_CARTRIDGE_EXTRA_MCLK` 3 to 4. The console's PCM against the board's on `megadrive` (fast board), nine sections: 2.7, 2.4, 7.4, 12.8, 20.8, 21.2, -47.8, -46.8 and -43.8 ms (with 3: 14.3, 2.0, 9.5, 14.5, 19.4, 19.2, -1.8, 1.8, 6.6). The step at the seventh section is the ramp scene (die frames 15,380 to 15,600): its transfers of about 5,000 words run into the picture and hold the bus for 460,000 to 750,000 MCLK each. The board and the die have the same 132 transfers there (the board's frame one less) with holds within 1 to 5 %; the die's 485,190 MCLK hold at 15,414 is the board's 462,194 (the die's trigger 2,256 MCLK later). Which of them catches a sound read is phase luck: the die's Z80 is caught by one the board's misses, and the board's by others. Any change to the Z80's timing reshuffles it and the music after the scene swings by about 50 ms, so the scene does not judge the cartridge figure. Video pace is identical at 3 and 4. The 80-case lockstep gate: both Rust boards identical to this one on all 80. od2-20k `flaws/FABLE-HANDOFF.md`, 2026-11-11 (night). ## Session 16 (2026-11-13): the restarted sound cores The FM and PSG cores this board used were found to be translations of GPL/LGPL die models and were withdrawn (/data/emu/sound-cores-restart-HANDOFF.md, step 4). The board now uses the restarted ym2612-python and sn76489-python, installed editable from local checkouts in both venvs. Glue: the FM runs in whole MCLK/7 clocks from `Board.fm_mclk` (it was handed absolute master clocks); /IC is driven with ZRES's level (`reset_line(0)` holds); the undriven status ports come from `read` returning None, the board's fade kept; the FM's frames are multiplied by `audio.FM_UNITS_PER_STEP` = 3 (the withdrawn core idled at 72 a sample, the new one at 24). Dropped: `IC_SLOT_LAG`, `IC_WRITE_SLOT_LAG`, `TIMER_CONTROL_DELAY_CYCLES`, `fm.control_delay`, `fm.mclk`, `busy_on_all_ports`. Tests: `test_milestone4.py` rewritten to the board's use of the chips (the old one judged the withdrawn cores against the die models, two tests by reading tables out of their source); one Nuked-MD slot-counter test dropped from `test_sprite_line_buffer.py`. 223 pass. Sonic: both chips sound, 21.4 frames/s. MDFourier against the Model 1 VA3: PSG -6.42 dB below FM against the console's -6.70, `PSG_GAIN` not refitted. Left for the board's own audit: `M68K_FM_WRITE_MCLK` / `M68K_FM_READ_MCLK` (fitted on Nuked-MD), the scripts that drive the withdrawn cores' internals, and the passages of undocumented-behavior.md and timing.md that cite the models' source lines. The E501 in `board.py`'s `FM_PORT_FADE_MCLK` comment came with the console-fix commit dcd5b2b and is left for whoever next touches it.