# Worklog One section per build session, newest last: what was done, what was measured, what was decided and why, and what is left. The milestones and their acceptance tests are in [handoff-brief.md](handoff-brief.md); the oracle tiers in [validation.md](validation.md). ## Environment Two virtual environments, both git-ignored: `.venv-pypy` (PyPy 7.3.23, Python 3.11: the platform and the floor) and `.venv` (CPython). The pins in `pyproject.toml` name GitHub URLs; for local work install the local clones at the same revisions without touching their checkouts, with `--no-deps` (megadrive-python's own GitHub pins would otherwise conflict with the `file://` ones), from a requirements file: ```text m68000-python @ git+file:///data/emu/m68000-python@c827cca6617ddcfb82e2735f3f30fe14971335f0 z80-python @ git+file:///data/emu/z80-python@b62891b9bac68da196ccb47c77e1e579f207dc1c ym2612-python @ git+file:///data/emu/ym2612-python@2c2ab235aed619b395ba152111cd79a6193390b3 sn76489-python @ git+file:///data/emu/sn76489-python@b0acbc863c87259b3bb120df1a5886980462e25c megadrive-python @ git+file:///data/emu/megadrive-python@5c6d1b752970e49c7e3626925551087c3dd3d687 sh2-python @ git+file:///data/emu/sh2-python@d4665d536947d004b0f3969bb5cd143114944d1e ``` then `pip install -e . --no-deps` and `pip install pytest ruff==0.16.8`. The PyPy venv's pip 24.0 rejects a `git+file://` requirement; upgrade pip first. ## Session 1 (2026-10-23): milestones 0 and 1 ### Milestone 0: referee tables - Boot ROMs: the user's three in `/data/emu/images/x55/bios/` hash to the SHA-1s in start-here.md (validation.md, "Boot ROMs verified"). Copies made for the referee runs live in the session's scratch directory only. - testpico and the Mars Check Program rerun on PicoDrive 1008a98 and MAME 0.285; BlastEm from 36bb09a. jgenesis and ares are not built (sources only), so they have no column. - testpico prints only failures, so its table is per test (57 rows). PicoDrive hw 54/57 (fails 42 `irq ack h-v`, 54 `32x irq vint`), `PICO=1` 55/57 (fails 54); MAME fails 19 Mega Drive tests and takes an illegal-instruction exception after test 37; BlastEm fails 26, 27, 31, 41 and hangs in 46 `32x init`. Test 0 skips itself on a cold boot everywhere. - The Mars Check Program keeps no list, so its table is per group (ten groups, test ranges read off PicoDrive frames). PicoDrive and BlastEm: 0 errors throughout; MAME: 2 errors and a stall at 39/161, in "MD & SH2 SYSTEM REGISTER R/W CHECK". - PicoDrive's libretro core looks up only Sega CD boot ROMs (`find_bios` in `platform/libretro/libretro.c`), so it cannot be run with the user's 32X ROMs. ### Milestone 1: the slot device without the SH-2s `src/sega32x_python`: - `slot.Sega32X`: a megadrive-python `SlotDevice` holding a `Cartridge`. Claims (256-byte pages): always `$A13000-$A130FF` and `$A15100-$A153FF`; with ADEN = 1 also `$000000-$0000FF` and `$840000-$9FFFFF`; with ADEN = 1 and RV = 0 also `$000100-$3FFFFF`. ADEN and RV writes call `Board.update_claims`. With ADEN = 0 nothing below `$400000` is claimed, so `Board.cartridge` stays the cartridge object and the 68000's ROM path is untouched. - `"MARS"` at `$A130EC-$A130EF` for any master; the rest of the `$A130xx` page reproduces the board's own /TIME decode (the cartridge's `read_time` on both halves or the open bus's MSB; `write_time` with D7-D0; a Z80 read gives `$FF`), since a claim takes the whole page. - `$A15100-$A1513F` registers with testpico's writable bits and power-on values; the vector ROM with the `$70` HINT vector register; the frame buffer and overwrite image (zero-byte rules); the windows and bank register; FM; RV. The VDP registers and palette, PWM, and everything on the SH-2 side raise `NotModelled`; hangs the hardware shows (testpico) raise megadrive-python's `Lockup`. - `machine`: two models, every quirk a `Quirk(value, source, tier, milestone)`; `bootrom`: the user's three ROMs read and checked by SHA-1; `harness`: runs a megadrive-python script with every `System` given a passive 32X holding its cartridge, and counts the Systems so built and any claims read with ADEN set. - Not added: the 68000's wait states on 32X accesses (`Board.hold`). Manual 4.1's ranges depend on SH-2 and VDP activity; they come with milestone 2. Tests: 32 (PyPy and CPython), including testpico's 68000-only checks run as 68000 programs: `t_32x_md_rom` (all, with a stand-in vector ROM and with the user's), `t_32x_reg_w` (the 68000 half), `t_32x_md_fb`, `t_32x_md_bios` (the user's ROM's `$C0` routine), `t_32x_init`'s power-on values and "writable bits without ADEN" block. #### The gate, 32X inserted and passive At `26dd029` (the last code commit), PyPy 7.3.23, megadrive-python's scripts at its checkout `44ab15d` through `python -m sega32x_python.harness`; outputs kept in `reference/m1-gate/` (git-ignored). Every harness run reported one System built with a 32X and 0 claims read with ADEN set. | Gate | Result | | --- | --- | | `lockstep_mame.py`, six traces | 0 unexplained each; Castlevania 11,343,385 68000 / 8,460,818 Z80 instructions identical, Gunstar 20,854,523 / 15,425,681, Phantasy Star IV 21,254,417 / 13,280,703, Sonic 23,286,815 / 12,728,465 (the counts of megadrive-python's Session 15), Sonic 3 21,741,798 / 11,837,738, Streets of Rage 2 21,274,844 / 11,269,553 | | VDPFIFOTesting, ten machines (the nine of Session 15 and `nuked-md`) | 122/122 on nine, 114/122 on genesis3 ("8 VSRAM tests fail, as on a Genesis 3"); every page's line identical to the same machine's run without the 32X | | mini sweep (`tests/mini_sweep.txt`, `--window 12`), with against without, both through the harness at `44ab15d` | 115 rows, **0 moved**: status, differing pixels and offsets equal on every row (differs 13, lockup 4, mame-board 8, phase 30, same 45, size 15) | | testpico's 68000-only 32X checks | pass (`tests/test_testpico.py`) | | `pytest` PyPy / CPython; `ruff check`, `ruff format --check` (0.16.8) | 32 passed each; clean | The full sweep (about four hours) was not run; the mini sweep was. The "with" sweep's own CSV was lost: `/tmp` hit its quota (other users' files) as it was written, after all 115 rows had been logged, so the comparison was made from the two runs' logs, row by row (`reference/m1-gate/compare.txt`). The four `lockup` rows carry the same message in both runs: two VDP-pattern lock-ups, and Devi to Pii (`$9FFFFE`) and The Killing Game Show (`$800000`), whose reads of the 32X area stay the board's own lock-up because with ADEN = 0 the 32X does not decode `$800000-$9FFFFF` (the board's message still says "without a 32X"). #### Speed, passive 32X against none PyPy, megadrive-python's CLI (`python -m megadrive_python CART --frames 900 --no-sound`, run through `runpy` with and without the harness's patch), four titles, without/with interleaved per title, three rounds, best user CPU time; nothing else of this session running. Load average 27.7 at the start (20:53), 13.3 at the end (22:16), from other users; this machine ran these titles in 24-34 s in megadrive-python's Session 15 and took 82-332 s here, so the numbers are noisy (one title's own runs spread by 2x). | Game | without (s) | with 32X (s) | change | | --- | ---: | ---: | ---: | | Sonic The Hedgehog (USA, Europe) | 171.52 | 125.12 | -27 % | | Streets of Rage 2 (USA) | 122.83 | 112.70 | -8 % | | Gunstar Heroes (USA) | 163.60 | 152.37 | -7 % | | Castlevania - Bloodlines (USA) | 86.30 | 81.92 | -5 % | No cost is visible: "with" ran second in every pair while the load was falling, which favours it, so the table says only that a passive 32X costs less than the noise. That is what the shape predicts: with ADEN = 0 the 68000's ROM, RAM and VDP paths are untouched and the only added work is one `catch_up(mclk)` call per 68000 instruction (socket 5), a comparison and a store. Every pair wrote byte-identical final frames. #### The sockets, as milestone 1 found them None was short for milestone 1. One convenience would remove duplicated decode: since a claim is a whole 256-byte page, the device must answer every address of `$A130xx` and of the `$A151xx` page, and so reproduces the board's own /TIME and undecoded-`$A1` answers (`Sega32X._time_read_word`, `Quirks.unused_registers`). A `Board` entry a device could hand an access back to ("as if unclaimed") would keep those answers in one place; it is written up as an optional PR description in the session report, not needed now. #### Open after milestone 1 - What hardware does on a 68000 read of `$800000-$9FFFFF` with a 32X attached and ADEN = 0 (the board locks up, as with no 32X; two mini-sweep cartridges do it). - Where the reset button lands with ADEN = 1 and RV = 1 (docs/undocumented-behavior.md, open item 10). - `$000100-$3FFFFF` with RV = 0: open bus is an assumption (open item 2). - The 68000's wait states on 32X accesses (milestone 2). ## Session 2 (2026-10-24): Aubrey's answers to the five questions Aubrey answered the five open questions from Session 1 (after outside advice). The standing rule now in validation.md, "Three records, kept apart": what the documents say, what hardware testing shows and what the board implements are recorded separately, and a disagreement stays visible instead of being resolved toward the easiest implementation. `Quirk` gained `documents`, `hardware` and `unresolved` fields for it. 1. **`$000100-$3FFFFF` with ADEN = 1, RV = 0**: open bus kept, recorded as known (no cartridge mapped, Manual 3.1) / chosen (CMD note 1's open bus as megadrive-python defines it) / unresolved (what hardware drives; ares vs PicoDrive kept as a disagreement). 2. **FM = 1 (changed)**: a 68000 access to the frame buffer, VDP registers or palette follows the Manual -- reads return the board's open bus (labelled chosen), writes are dropped -- for all three; no hang. testpico's "FM=0 (hangs without)" (main.c:2185) is kept as an unexplained observation: the reads after it are system registers, not the frame buffer. Quirk `framebuffer_with_fm` became `vdp_side_with_fm`. 3. **`$800000-$9FFFFF`**: still a lock-up, now recorded as two states -- no 32X (megadrive-python's, CMD note 2, research) and 32X with ADEN = 0 (inherited, unverified) -- in the new quirk `area_without_aden`, with the two mini-sweep cartridges that reach it. 4. **Reset button with ADEN = 1 and RV = 1**: the stop is now an explicit placeholder, `ResetLanding`, raised from one method (`Sega32X._reset_landing`) so a finding replaces it without touching the reset path; testpico's `$2C8-$304` landing area recorded as the only evidence. Plan: run testpico's reset test on the board and the emulators once milestone 2 allows. 5. **Mars Check per test**: `scripts/libretro_frames.py --on-change` keeps a frame each time the program's counter moves; PicoDrive, BlastEm (the user's boot ROMs) and MAME (a snapshot every second frame) were rerun, each test's counter read by digit matching and its message compared after thresholding. PicoDrive and BlastEm agree on all 161; MAME fails 38 and 39 and stalls in 40 (validation.md, "Mars Check Program, per test"). The Session 1 group summary had test 38 in the wrong group; corrected. Reruns at `6c75f60` (the last code commit): pytest 34 passed on PyPy and on CPython; ruff check and format clean; testpico's 68000-only checks pass (in pytest). The passive gate cannot move from changes 2-4 (all need ADEN = 1, or are the same lock-up), and confirms: VDPFIFOTesting on genesis through the harness 122/122, every line identical to the no-32X run of Session 1; the Castlevania lockstep is below. | Rerun at `6c75f60` | Result | | --- | --- | | `pytest`, PyPy and CPython | 34 passed each | | `ruff check`, `ruff format --check` (0.16.8) | clean | | testpico 68000-only checks | pass | | `lockstep_mame.py` Castlevania, through the harness | 0 unexplained; 11,343,385 68000 and 8,460,818 Z80 instructions identical, as in Session 1 | | VDPFIFOTesting genesis, through the harness | 122/122; every line identical to the no-32X run | ## Session 3 (2026-10-24/25): milestone 2, the SH-2s on the bus ### What was built - `sh2side.py`: two sh2-python SH7604s (pin d55bbb0), `mode="master"`/`"slave"`, owned by the slot device when the user's boot ROMs are given (`Sega32X(..., boot_roms=...)`, `console.build`). The bus callbacks decode boot ROM (per CPU), the registers at $4000-$43FF, the cartridge ($02xxxxxx), the frame buffer ($04xxxxxx), SDRAM ($06xxxxxx, 256 KB). Clock: the board's time in SH-2 states is `mclk * 3 // 7`; each chip's place is `chip.clock + skew`; `catch_up` steps the chip furthest behind until both pass the target, from every 68000/Z80 access to 32X space and after every 68000 instruction. Interrupts per CPU with FTOA on /IRL0; VINT/HINT from socket 6's lines; VRES from socket 9's BUTTON; CMD from INTM/INTS; PWM from the PWM timer. DREQ0 to both chips while the FIFO holds a word. The SCIs crossed. Waits: `chip.wait` (Manual 4.1 low ends) and `Board.hold` for the 68000 on the VDP side; a first-come shared bus. - `vdpregs.py`: the 32X VDP's registers and palette, **no picture**. Stubbed: the auto fill (at once, FEN 0), PEN (no palette wait), FS swapping at the next VBlank, the bitmap mode bits at the emulators' positions. PWM: registers, FIFOs that drain, the timer interrupt; no sound, no DREQ1. - `console.build(machine, cartridge, boot_roms)`: System + slot + socket 6 in one place. - `scripts/run_32x.py` (acceptance runs, `--on-change`, `--press-reset-at`), `scripts/sh2_lockstep.py` (the board's SH-2 against MAME's trace), `scripts/libretro_frames.py --reset-at`; `tests/stubs.py`; 13 new tests (one slow). - Fixed on the way, each from a judge: INTM/INTS read/write (Mars Check test 3), the PWM FIFOs draining (tests 13-15), bit 1 of the SH-2 view of $20004006 (tests 43-44), VINT for VBlank (testpico `t_32x_irq_vint`). ### Acceptance, at f3aab74 (the last code commit) | Gate | Result | | --- | --- | | testpico, cold (110 frames) then the reset button, warm (to 260) | cold 50/57, 1 skipped; warm 52/57, 0 skipped; **all twelve 32X tests pass** (0 on the warm run, 46-56 on both) | | testpico's Mega Drive tests | the same six fail cold as on megadrive-python alone at 44ab15d (26, 27, 41, 42, 43, 45), with the same diagnostic lines | | Mars Check Program, per test (1,600 frames) | tests 1-64 OK, **all system tests (1-58) pass**; 65 (PALETTE ENABLE BIT, the VDP group) fails: milestone 3; reached 67 | | boot with the user's ROMs (`pytest -m slow`) | M_OK and S_OK, no unmapped access | | SH-2 lockstep against MAME 0.285 (Mars Check, master) | **14,228,130 instructions identical from reset** (the boot ROM's SDRAM test, checksum, load and jump), then the first divergence in the program's own wait loop at $06000172: the board's master reads comm0 after the 68000 cleared "M_", MAME's before -- a timing difference between the 68000 and the SH-2, which MAME (no SH-2 cache, about a cycle an instruction) does not claim | | passive gate: MAME lockstep, Castlevania | 0 unexplained; 11,343,385 / 8,460,818 identical, as before | | passive gate: VDPFIFOTesting genesis | 122/122, every line identical to the no-32X run | | passive gate: mini sweep (115), with against Session 1's without | 0 moved (status, pixels, offset): 0 better, 0 worse | | pytest PyPy / CPython; ruff | 47 passed each (+1 slow); clean | The referees for the same 32X tests (validation.md): PicoDrive passes 11 of 12 (fails `irq vint`) and needs a warm start for test 0; BlastEm, reset after its hang in `32x init`, fails 0, 46 (SEGA TV reads 1, $8C/$8E keep what is written), 48 ($20004006 lacks EMPTY), 50 ($000070 is not a register reading 0) and 54. The board passes `irq vint` with a VINT rule it inferred from that test, so the pass is not independent evidence for the rule (the quirk says so). ### The reset-landing experiment (open item 10) The board, button pressed during testpico's 32X tests with ADEN = 1 and RV = 1: the placeholder `ResetLanding` at $880200. PicoDrive does not model RV, so its 68000 always reaches the cartridge. BlastEm, reset while hung in `32x init`, restarts testpico (and passes on to 48/57), but nothing shows RV was 1 at its press. No evidence for a specific landing: the placeholder stays. ### Open - The 32X VDP (milestone 3): Mars Check test 65 fails on PEN; nothing is drawn. - `sh2_clock_needs_aden`, the VINT rule, the DREQ FIFO, the SH-2 FM = 0 rule and the waits are first models, each recorded with its disagreement. - PWM sound and DREQ1 (milestone 5). ### Speed (PyPy, alone, at f3aab74) Nothing else of this session running; load average 31.7 at the start (03:50), 33.0 between the runs, 36.4 at the end (04:10), all from other users. No sound (the FM generator off, its timers kept). | Run | Frames | Wall (user CPU) | Frames/s | SH-2 instructions/s (both) | | --- | ---: | ---: | ---: | ---: | | testpico, frames 1-49 (SH-2s held: Mega Drive tests) | 49 | 14.3 s | 3.4 | - | | testpico, frames 50-110 (SH-2s running: the 32X tests) | 61 | 226.3 s | 0.27 | 106,000 | | testpico cold, whole (to its result screen) | 110 | 244 s (241 s) | 0.45 | - | | Mars Check Program, boot to its first test (frame 297) and on to 320 | 320 | 915 s (903 s) | 0.35 | 101,000 | Real time is 60 frames/s: the board runs testpico's 32X tests at about 0.5 % of it and the SH-2s at about 0.2 % of their 23 MHz. How long each acceptance run takes here: the testpico cold + warm run (260 frames) about 16 minutes alone (32 under the gate's other jobs); the Mars Check Program to test 58 about 975 frames, a little over an hour (it boots through Sega's ROMs, whose checksum of the 4 MB cartridge takes ~12 M master instructions); to test 67 1,600 frames, about two hours. The whole program (161 tests and the VDP pictures, about 8,000 frames on the referees) would take nine hours or more: the milestone-2 acceptance is its system tests (1-58), and the VDP groups belong to milestone 3's run. ## Session 4 (2026-10-29): milestone 3, the 32X VDP ### What was built - `vdp.py` (replacing milestone 2's `vdpregs.py` stub): the 32X VDP's registers and palette, its line timing, its events and its own picture. From each socket-6 line record it places, in the Mega Drive's dots, HBLANK's rise, PEN, the 40-Sclk refresh FEN pulse, the register latch, HBLANK's fall (the row's display) and VBLANK's edges. Status bits (VBLK, HBLK, PEN, FEN) are computed at the clock they are read; what changes state is an event at its master clock, run in order with the SH-2s' instructions (`SH2Side.catch_up`) or up to a 68000 access (`Sega32X.catch_up`): HINT at HBLANK and the counter's reload at its fall, the latch, a row drawn at its display, VINT and the FS swap at VBLANK. - Rows: packed pixel, direct colour, run length from the displayed buffer's line table, the word address wrapping through the DRAM, the screen shift (all three modes) with Bulletin #14's `$FF` exception; a blank-mode row is None (transparent). The finished frame (`vdp.picture`, 224 or 240 rows of 320 BGR555 + through-bit words) is taken at VBLANK; `frame_rgb()` gives RGB888 for a PNG. 320 wide whatever the Mega Drive's mode. - Auto fill writes at once and holds FEN for 7 + 3 x words Sclk; a palette access while PEN = 0 holds the 68000 (`Board.hold`) or the SH-2 (WAIT states) until PEN. - `SH2Side` lost its own VINT/HINT line logic; the VDP raises them (`raise_hint`, `raise_vint`). With ADEN = 0 nothing runs: the line records are kept, no event is queued, so the passive path is cheaper than before. - Quirks: `hblank_phase`, `hblank_timing`, `fen_refresh`, `auto_fill` (was `fill_at_once`), `palette_wait`, `fs_swap`, `screen_shift_modes`, `blank_row`, `rgb_levels` new; `vint_at`, `hint_counter`, `vblank_after_hblank`, `screen_shift_ff_exception`, `hcount_read`, `bitmap_bits` given their three records. `bitmap_bits` is now specification tier: PRI at bit 7 and 240 at bit 6 read off the Manual's scan (PDF page 36). Open item 9 (the blank-period table) settled from the scan (PDF page 56): 38, 89, 73 lines. - Scripts: `run_32x.py` saves the 32X-only frame (`fNNNNN-32x.png`) and holds pad buttons (`--press`); `libretro_frames.py --press` does the same on the referees, mapped per core; `compare_frames.py` finds a detector's closest frame and counts differing pixels. - Tests: `tests/test_vdp.py`, 12 (the modes, the line table and its wrap, the shift and `$FF`, blank rows, FS, auto fill and FEN, the line's spans in MCLK, PEN and the palette wait, the latch, HINT's counts, the three records of every milestone-3 quirk). ### Where HBLANK sits The Manual gives no place for HBLANK in the Mega Drive's line, but gives four spans from it in dots and MCLK (figures 3.15, 3.17: PEN 3 dots = 24 MCLK, VBLANK 27 = 224, latch 76 = 668, blank 100 = 860). The Mega Drive's H40 dots are not all 8 MCLK (EDCLK slows around HSYNC; socket 6 hands over every pixel's start), so the MCLK figures pin the place. Scanning the phase over a measured H40 line (`LineTiming` with `hblank_phase` from -30 to 24 dots before the Mega Drive's HBlank flag): | dots before the HBlank flag | PEN | VBLANK | latch | blank | | ---: | ---: | ---: | ---: | ---: | | -11 | 30 | 264 | 668 | 860 | | 0 | 24 | 246 | 668 | 860 | | 4 (PicoDrive's FEN note) | 24 | 238 | 668 | 860 | | 11 | 24 | 226 | 668 | 860 | | **12** | **24** | **224** | **668** | **860** | | 13 | 24 | 222 | 668 | 860 | | 17-24 | 24 | 216 | 668 | 860 | Only 12 gives all four (the Manual's own numbers): HBLANK at H $15A, the display H $01A-$159. The first build used 4 (H $162, from notaz's note in PicoDrive that FEN pulses "most often at 0xb1-0xb5" on hardware); the scan moved it before any acceptance run, and the note stays recorded as an 8-dot disagreement (`Quirks.hblank_phase`). ### Acceptance, at 3ad5c20 (the last code commit) All runs on PyPy, the user's boot ROMs, started together at 09:51 (load 5.9 at the start, 4.8 when the last ended at 12:51, otherwise up to about 22, from other users; 16 processes of this session at most), outputs in `reference/m3/final/` (git-ignored). | Run | Result | Took | | --- | --- | --- | | Mars Check Program, the whole program (9,000 frames) | **every test passes**: tests 65-161 OK (65, PALETTE ENABLE BIT, failed at milestone 2), ERROR COUNT 0 on all 328 kept frames that show it, "すべて正常に終了しました" ("all finished normally") between frames 6,750 and 7,000; its VDP-mode pictures against the detectors in validation.md, "Milestone 3" | to the verdict about 2 h 35 min (frame 7,000 at 9,318 s); all 9,000 frames 10,815 s (3 h 0 min) | | testpico, cold (110 frames) then the reset button, warm (to 260) | cold 50/57, 1 skipped; warm 51/57; **all twelve 32X tests pass**, `32x irq vint` included; the Mega Drive tests as before but 45 also fails warm (the reset lands elsewhere in the frame: validation.md) | 453 s | | Runlength sample, 600 frames, 12 frames compared | **0 pixels differ** from PicoDrive's and from BlastEm's closest frame, all 12 | 1,120 s | | Texture sample, 600 frames, 12 frames compared | **0** against both, all 12; the board's frame N is PicoDrive's N - 7 and BlastEm's N + 1 | 1,352 s | | 240p suite 1.0, 600 frames with presses: main menu, Test Patterns menu, Color Bars | **0** against both on all three screens | 1,393 s | | passive gate: MAME lockstep, Castlevania, through the harness | 0 unexplained; 11,343,385 68000 and 8,460,818 Z80 instructions identical, as in Sessions 1-3 | 817 s | | passive gate: VDPFIFOTesting genesis | 122/122; every page line identical to Session 3's run (`--verbose`) | 36 s (66 s verbose) | | passive gate: mini sweep (115), against Session 1's without | **0 moved** (0 better, 0 worse, 115 unchanged): status, differing pixels and offsets as Session 1's without | 1,703 s | | pytest PyPy / CPython; ruff check, ruff format --check (0.16.8) | 59 passed each (+1 slow deselected); clean | - | Every frame difference is explained in validation.md, "Milestone 3": only colour levels (at most 8 of 255 per channel: each emulator expands 5 bits its own way) and which frame shows which picture -- the run-length demo draws as fast as its SH-2s allow, and the board takes about 1.95 of PicoDrive's frames per picture (BlastEm 1.45): SH-2 speed in emulated time (milestone 2's waits), not the VDP; with the palette wait switched off the mapping is the same. The Mars Check Program's own pictures match too, but for the Mega Drive's title text (the detectors give the composite) and two things worth keeping: on the three-modes screen (the 68000 changing the bitmap mode at four Mega Drive H interrupts) the board switches at rows 16, 80, 144 and 208, where the program's line table puts the bands, and BlastEm a row earlier (PicoDrive draws nothing on that screen); on the colour-bar screen PicoDrive and BlastEm disagree on the composite (the Mega Drive's bars over the 32X's black with the through bit clear, or not) -- a datum for milestone 4 (corrected in Session 5: a BlastEm frame from before its bars appeared; they agree). ### Open after milestone 3 - HBLANK's place: the Manual's MCLK figures (the board) against PicoDrive's FEN note, 8 dots apart; no capture (decision 6). The three-modes screen's boundary rows depend on it, and BlastEm puts them a row earlier. - PEN's fall, the 1-us window before it, the narrow FEN pulses, what a CPU access during an auto fill does: modelled as the Manual's simplest reading or not at all, labelled. - HINT's counter in VBLANK without HEN (reloaded here; jgenesis keeps it). - VBLANK 27 dots (the Manual) against jgenesis's 22: testpico passes with 27. - The screen shift in direct-colour and run-length modes (emulators disagree). - H32 and PAL 240-line operation: built, not exercised by any acceptance program. - testpico 45 (a Mega Drive H32 test) now fails on the warm run as well: the reset lands at another point of the frame since the SH-2s' interrupt timing moved; not a 32X test. ### Speed (PyPy, alone, at 3ad5c20) Nothing else of this session running (`reference/m3/final/speed/`); load average 19.4 at the start (09:41), 18.3 and 10.3 between the runs, 6.3 at the end (09:51), all from other users. | Run | Frames | Wall (user CPU) | Frames/s | SH-2 instructions/s (both) | | --- | ---: | ---: | ---: | ---: | | testpico cold, whole | 110 | 152 s (151 s) | 0.72 | - | | testpico, frames 50-110 (the 32X tests) | 61 | 140 s | 0.44 | 168,000 | | Mars Check Program, boot to frame 320 | 320 | 316 s (315 s) | 1.01 | 293,000 | | 240p suite to its menu, 200 frames | 200 | 97 s (96 s) | 2.1 | 708,000 | Session 3 measured 0.27 and 0.35 frames/s for the first two at a load of 31-36; the VDP's cost is small against the SH-2s (its per-line work is a few events and one row), so most of the difference is the machine's load. The SH-2s in an idle loop with cache hits (the 240p suite's menu) run fastest. ## Session 5 (2026-10-30): milestone 4, the composite ### What was built - `composite.py`: socket 7's device. Per pixel, the 32X's where its row is not blank and (through bit XOR PRI, or YS), else the Mega Drive's (Manual 3.3 figure 3.9, the scan, PDF page 48; service manual `A406a`, "switches between input via 'YS' signal to produce one output"). Every choice a `Quirk` with its three records: `composite_rule`, `composite_md_transparent`, `composite_ys_shadow`, `composite_alignment`, `composite_dot`, `composite_border`, `composite_levels`. - **The two sides meet by the line's start clock.** Socket 7 hands a line over when the lazy VDP finishes it, before or after the 32X VDP's event for the same line has run, and the 32X cannot catch up from inside the VDP's own sync (`Sega32X.catch_up` calls `vdp.sync`). Whichever arrives second composes; a line handed over first is returned as a copy of the Mega Drive's and filled in place when the row is drawn, which the board reads only when the frame is read (socket note below). - **Alignment** in master clocks: the line runs on the 32X's dot from the Mega Drive's output pixel 0, to the end of the 32X's last pixel: 320 wide in H40, 323 in H32. - The harness attaches socket 7, so the passive gate covers it: with ADEN = 0 every line is handed back None. - `console.cartridge_for`, `AcclaimEEPROMCartridge`, `Quirks.cartridge_boards`: NFL Quarterback Club stopped at $05AF06 with stripes on the screen. MAME's list names no board for a 32X title, so the EEPROM was missing; then its check needed the line, not the chip's drive, read back (undocumented-behavior.md, "The cartridge"). - Scripts: `run_32x.py` saves the composite, the 32X's and the Mega Drive's frames and logs PRI and the H mode; `compare_composite.py`. - Tests: `tests/test_composite.py`, 15, one computing from socket 7's fields and `LineTiming` the 40 MCLK the board's own line model would put the 32X to the right in H40. ### What was found - All four emulators now have one form of rule (Manual figure 3.9) and differ on what "transparent" is; nothing here separates them (validation.md, "Milestone 4"). - **Spider-Man runs with PRI = 0 on the board**, not the PRI = 1 of Near's post, and the Manual's rule draws both of his titles as both detectors do. - **H32:** the 32X keeps 320 pixels over the Mega Drive's 256. The EDCLK-as-dot-clock reading in undocumented-behavior.md fails on arithmetic (a 420-dot line at 10 MCLK does not fit 3,420 MCLK). The first build started the line at the 32X's pixel 0, losing the Mega Drive's left 3 pixels and sitting 3 pixels left of every detector's frame; NFL's menu showed it, and the line now starts at the Mega Drive's left edge. - BlastEm's source has no H32 offset, but its frames show one (validation.md). - The Mars Check Program's manual menu (Start held through its start-up) reaches the VDP screens in about 500 frames instead of 5,000, and its DIRECT COLOR screen toggles PRI (A) and the through bit (C): Sega's own composite test, all four states agreeing on all three programs. Presses: `reference/m4/mars-manual-presses.txt`; PicoDrive, which starts sooner, needs Start from frame 1. ### Socket 7 Not short, with one thing unstated. The composite relies on the board reading a returned list only when the frame is read (`Renderer.frame_rgb`), so a device can fill it in place until then. That holds at the pin, and is what a lazy VDP needs of a device with its own CPUs to run first, but `sockets.py` does not say it. The change for megadrive-python is one docstring (the session report has the description). Border lines and pixels are not handed over: for H32's right edge the board assumes YS (`Quirks.composite_border`) and needs no Mega Drive colour there. HSYNC is still not in socket 6, so alignment cannot be derived from what the 32X actually times itself from; the detectors' figures are used instead. The Acclaim cartridge's two changes also belong in megadrive-python (`console.AcclaimEEPROMCartridge`); the same report has them. ### Acceptance Detectors only. Comparisons in validation.md, "Milestone 4"; outputs in `reference/m4/` (git-ignored). The last code commit is **3cd3bb6**. It changed only the H32 line (the H40 map is the same, by `test_h40_is_one_on_one`), so the H40 runs below that started before it stand. Those runs loaded the code of e225439, but for the 240p suite's and the first Spider-Man run, which loaded e3fb538's (no cartridge table, the same composite). | Run | Result | Took | | --- | --- | --- | | NFL Quarterback Club, 3,060 frames, Start every 300 from 300 (3cd3bb6) | reaches its menu in H32 (the Mega Drive H32 from about frame 2,800); the 32X's logo in place on both detectors, the Mega Drive's buttons on PicoDrive, 1 pixel off on BlastEm | 11,557 s | | Knuckles' Chaotix, 1,810 frames, the same presses | 1,750: 0 pixels from BlastEm but row 223; 33 from PicoDrive | 5,171 s | | Spider-Man, 2,300 frames, the same presses | title, menu; PRI = 0 throughout | 6,695 s | | Spider-Man, the first run, stopped at 2,700 | newspaper screen, 0 pixels from both | 23,441 s to 2,700 under load 60-85 | | Mars Check Program, automatic, 7,100 frames | "all finished normally" by frame 7,000; every composite screen 0 from both detectors but the three-modes screen's boundary rows (Milestone 3's) | 21,453 s | | Mars Check Program, manual, 2,200 frames | DIRECT COLOR, four PRI/through states, and COLOR BAR: 0 from both; a shorter acceptance found while the automatic run was held up by a load of 60-85 | 4,070 s | | 240p suite, 600 frames | main menu, Test Patterns, Color Bars: 0 from both | 3,977 s | Milestones 1-3 and the passive gate, at 3cd3bb6, with socket 7 attached (the harness now attaches it). Load average 15.4 at the start (08:46), 31.4 at the end (09:28), from other users. The composite is output only: nothing the CPUs read depends on it, so the verdicts could not move, and what it could move is the pictures above and the passive path. | Gate | Result | Took | | --- | --- | --- | | testpico, cold (110 frames) then the reset button, warm (to 260) | cold 50/57, 1 skipped; warm 51/57, 0 skipped; all twelve 32X tests pass; the Mega Drive tests as Session 4 | 650 s | | Mars Check Program | as above; tests 1-161, "all finished normally" | above | | passive gate: MAME lockstep, Castlevania, through the harness | 0 unexplained; 11,343,385 68000 and 8,460,818 Z80 instructions identical | 1,084 s | | passive gate: VDPFIFOTesting genesis | 122/122; every page line identical to Session 4's run (`--verbose`) | 114 s | | passive gate: mini sweep (115), against Session 1's without | **0 moved** (0 better, 0 worse, 115 unchanged): differs 13, lockup 4, mame-board 8, phase 30, same 45, size 15 | 2,530 s | | pytest PyPy / CPython; ruff check, ruff format --check (0.16.8) | 74 passed each (+1 slow deselected); clean | - | ### Speed (PyPy, at 3cd3bb6, nothing else of this session running) Load average 10.0 at the start (13:43), then 30.4, 30.3, 25.3 between the runs and 20.4 at the end (14:43), all from other users: far higher than Session 4's 6-19, which is most of the difference from its table. | Run | Frames | Wall (user CPU) | Frames/s | SH-2 instructions/s (both) | | --- | ---: | ---: | ---: | ---: | | testpico cold, whole | 110 | 194 s (192 s) | 0.57 | - | | testpico, frames 50-110 (the 32X tests) | 61 | 172 s | 0.35 | 139,000 | | Mars Check Program, boot to frame 320 | 320 | 693 s (689 s) | 0.46 | 133,000 | | 240p suite to its menu, 200 frames | 200 | 489 s (488 s) | 0.41 | 138,000 | Socket 7's cost, the 240p suite's 200 frames with it attached against without: 568 s and 484 s, one pair back to back at load about 25, a second pair's figures lost to the script (and the 568 s is a rerun of the 489 s above: the machine's noise is of that size). So a few hundred ms a frame at most: the YS loop and RGB per line in megadrive-python's renderer, and the composite's loop per line. ### Open after milestone 4 - What "transparent" means: nothing here separates YS from colour 0 or the backdrop's index. A purpose-built ROM could: a backdrop on a non-zero colour under a 32X pixel with through = PRI. It would separate the emulators, not settle the hardware, without a capture. - `vdp.py`'s line timing still counts the Mega Drive's H32 dots (10 MCLK), against `Quirks.composite_dot`'s 8; the status bits and interrupts in H32 follow it. - H40 alignment against the line model's 40 MCLK. - `hblank_phase` (Milestone 3) and the composite's one-on-one together imply the 32X's picture leaves 5 dots before its own display window opens: one of the two is not as modelled. ## Session 6 (2026-11-04): milestone 5, PWM ### What was built - `pwm.py`: PWM out of `slot.py` and making sound. The counter in SH-2 states, lazily, run to every register access, to each period's end from `SH2Side.catch_up`'s loop (`PWM.next`, beside the 32X VDP's `next_state`) and to each socket-8 take. Periods of `cycle - 1` states; both FIFOs pop at a period's end, the word playing through the next, the last word held when a FIFO is empty; routing as the output each field drives; the timer interrupt every TM periods and, with RTP, DREQ1. Every choice a `Quirk` with its three records: `pwm_registers` (rewritten), `pwm_period`, `pwm_fifo`, `pwm_routing`, `pwm_byte_writes`, `pwm_timer_restart`, `pwm_cycle_write`, `pwm_dreq1`, `pwm_needs_aden`, `pwm_output_level`, `pwm_gain`; `tests/test_pwm.py`, 15 tests, one driving SH-2 DMA channel 1 as the Mars Check Program's test 152 sets it up (8 longwords, one per timer event, TE at the end). - **DREQ1.** sh2-python exposes `chip.dreq1`, a level its DMAC samples at the start of each step (`_core.py` `step`, `dmac.py` `run`). The Manual fixes channel 1 as edge-triggered (CHCR1 bits 7-4 `1110`), and the core does not model CHCR.DS, so the board gives it the edge's effect: raised on both SH-2s at the timer event, dropped after the chip's next step, so each DMAC sees it once. The hook is there and sufficient for every setting the Manual allows; what the core lacks is noted below for sh2-python, not worked around. - **Output.** The duty cycle, min(width, period) / period, unipolar (0 when off), kept as runs of (states, left, right) and read on a grid of the current period: one sample per period, socket 8's `rate` = MCLK x 3/7 / period (21,999.4 Hz for cycle 1047). Gain 6,100 FM units per full swing. Both labelled assumptions. - `console.build` and the harness append the PWM to `System.audio_sources`; a passive 32X never starts the counter (`pwm_needs_aden`) and so hands over nothing. - Scripts: `run_32x.py --wav/--wav-from/--rate/--no-fm/--pwm-log` (the PWM's own samples before the mix); `libretro_frames.py --wav/--wav-from` for the detectors; `compare_audio.py` (numpy; the system Python's). ### What was found - **The Z80 writes a width as two bytes.** Queuing on each byte put two partial entries in the FIFO. PicoDrive and ares queue on the odd byte (`pwm_byte_writes`); the MiSTer core queues on either, so two entries per sample. - **Socket 8's first samples.** megadrive-python's mixer lines a source's first samples up with the start of the stretch it mixes. The counter started part way through a frame, the first list was short, and the mixer's position for the PWM stayed about 105 samples ahead for good: each frame skipped that many and held the last for the rest (the sample demo's mix correlated 0.77 with the PWM's own stream, with tones at 79 Hz and 5 kHz). The first take now leads with silence back to the previous take (`tests/test_pwm.py` `test_first_samples_start_at_the_previous_take`). - **BlastEm's period is cycle - 2**: its Mars Check tones are 1,007.7 Hz and 502.9 Hz for cycles 521 and 1042, which is 23,011,360 / 519 / 44 and / 1,040 / 44; its source counts down to 2 and reloads at 1. PicoDrive's libretro core gives 735 samples a frame at 59.92 frames a second and calls it 44,100 Hz, so its pitch is 0.13 % high and wanders with its per-frame resampler: it cannot settle a 0.2 % question. - **Mars Check's sound tests are function only**: the SH-2 tests' verdict is a 10-second timeout on "OK" in a communication port, the DMA tests count no error whether a transfer happens (they wait 60 frames on the V counter), and the 68000 tests wait for EMPTY. The board's verdicts there say the registers, FIFOs, interrupt and DMA move. - The comparison needs a common high-pass (100 Hz, two poles): each emulator filters the sub-audio band its own way, and the demo's PWM carries most of its energy there. ### Core note for sh2-python (not a blocker) For the core's own fidelity, written as a PR description; nothing here waits on it. > **DMAC: edge-detected DREQ (CHCR.DS/DL) and its acknowledge.** `dmac.py` samples > `chip.dreq0`/`dreq1` as a level at each step boundary and documents DS edge detection as > not modelled. The 32X's Manual fixes channel 1 as `DS = 1, DL = 1` (rising edge) and > channel 0 as `0100 0100 1110 0XXX` (edge too). Proposal: latch a rising edge of each DREQ > input (or a falling one with DL = 0) into a per-channel request flag that a transfer > clears, so a board can drive the pin as the hardware does (a pulse; the MiSTer core holds > the 32X's for one SH-2 clock) without holding it until the next step. With DS = 0, keep > sampling the level. Tests: an edge between two steps gives one transfer; a level held > for several steps gives one transfer with DS = 1 and one per step with DS = 0 > (cycle-steal). sega32x-python's board would then raise and drop DREQ1 at the timer > event and stop clearing it in its catch-up loop (`Quirks.pwm_dreq1`). ### Socket 8 (not short; one thing unstated) `AudioSource.take_samples` says "the stereo samples finished since the last call", and `AudioPath._add_sources` takes a source's first non-empty list to start where the call's stretch starts. A source that starts part way through a stretch therefore has to lead with silence back to the previous call, which this board now does. The change for megadrive-python is one sentence in `sockets.AudioSource`'s docstring: "the list covers the whole stretch since the last call; a source that starts within it leads with silence". `rate` describes the list just returned: one rate per call, so a source whose rate changes within a call converts (this board reads a changed period on the new grid, zero-order hold). ### Gate (at 3226df1, the passive gate with sockets 7 and 8 attached) Run together by `reference/m5/gate.sh` (git-ignored, with the outputs), PyPy, beside this session's acceptance runs; load average 20.8 at the start (04:39), 35-44 throughout, mostly other users'. The last code commit, 5f2067c, changes only a cycle write that shortens a period already past, which none of these programs makes (they write the cycle with the counter stopped; the demo's rate never changes in its `--pwm-log`). | Gate | Result | Took | | --- | --- | --- | | VDPFIFOTesting genesis, through the harness | 122/122; every page line identical to Session 5's (`--verbose`) | 134 s | | mini sweep (115), against Session 1's without | **0 moved** (0 better, 0 worse, 115 unchanged): differs 13, lockup 4, mame-board 8, phase 30, same 45, size 15 | 3,288 s | | MAME lockstep, Castlevania, through the harness | identical to Session 5's log: 0 unexplained | 1,456 s | | testpico, cold (110 frames) then the reset button, warm (to 260) | frames 110 and 260 (composite and 32X) byte-identical to Session 5's, and every frame's line, SH-2 instruction counts included | 870 s | | pytest PyPy / CPython; ruff check, ruff format --check (0.16.8) | 89 passed each (+1 slow deselected); clean | - | The Mars Check Program's automatic run (7,100 frames) was started with the gate and stopped: at this load it would have taken about seven hours, past the session's bound. It was rerun afterwards to frame 760 (test 51, past every PWM register test; Acceptance, below), and the sound tests were run through its manual menu. ### Speed (PyPy) Side by side, 3f8acfd (milestone 4) and this session's code, each pair started together so both see the same load (34 at the start, 05:34; 29 between; 44 at the end): | Run | 3f8acfd | this session | SH-2 instructions | | --- | ---: | ---: | --- | | Mars Check Program, boot to frame 320 | 888 s | 867 s | identical | | 240p suite to its menu, 200 frames | 724 s | 732 s | identical | No measurable cost: the catch-up loop gains two comparisons a step. At low load (3.5-6, 04:24) the first sample-demo run, FM on, took 248 s for 480 frames (1.9 frames/s) and the first Mars Check sound run reached frame 1,150 in 423 s (2.7 frames/s, FM off); at load 35 the same runs went at 0.2-0.3 frames/s. ### Acceptance (detectors only for the sound; [claims.md](claims.md)) Comparisons in validation.md, "Milestone 5"; outputs in `reference/m5/` (git-ignored). Both runs at 3226df1, PyPy, the user's boot ROMs. | Run | Result | Took | | --- | --- | --- | | Mars Check Program, manual menu, SOUND CHECK: 68000, SH2, Z80 (tests 137-156), 2,800 frames, FM off | every test named, no error message, each group to its "press any key"; tones 502.39 Hz (68000, Z80) and 1,005.74 Hz (SH-2 polling, interrupt, DMA), exactly cycle - 1's, on the named sides, pans moving; shapes 0.999-1.000 against PicoDrive and BlastEm but BlastEm's Z80 tests (its byte writes) | 12,699 s, load 30-68 | | Sega's PWM sample, 480 frames, FM on | plays from 2.0 s at 21,999.4 Hz; against PicoDrive 0.986 and BlastEm 0.988 (median of 50 ms windows over 2.5-7.5 s; they reach 0.985 with each other); levels x2.38 and x1.31 of the board's | 2,414 s, load about 35 | | Mars Check Program, automatic, 760 frames (at 5f2067c) | tests 1-51, the PWM register tests 11-15 and 24-35 among them, ERROR COUNT 0; every frame on which the counter moved (106 of them) byte-identical to Session 5's run | 3,957 s, load 40-63 | ### Open questions (Aubrey's) - **PWM gain** (`pwm_gain`, 6,100 FM units per full swing) and whether to keep the unipolar level with its start-up pops: the detectors play it 1.3 to 2.4 times louder against their own FM, and centre it so a stopped PWM is silent. Default kept: the board's assumption, labelled, until a recording exists (decision 6 says none will be made; an MDFourier-style capture through a 32X would settle it). - **The period**: cycle - 1 (three software detectors) against the Manual's and the MiSTer core's cycle and BlastEm's cycle - 2. A recording of the Mars Check Program's 1 kHz tone at a known MCLK would separate all three (0.1-0.2 %). Default kept: cycle - 1. - **Raise the two notes** (sh2-python's DREQ edge, megadrive-python's socket 8 docstring) as PRs, or leave them in this worklog? Default: left here. - **The Mars Check Program's automatic run** was rerun only to test 51 at this load (the whole 7,100 frames would take about seven hours); the sound groups were run through the manual menu. Rerun whole at a quieter time before milestone 6? ### Probe-cart test requests None found this session: PWM is the 32X's alone, and nothing in it waits on a base Mega Drive timing (the mix point is the 32X's own, and the A/V-cable path is outside a probe cart's reach). ## Session 7 (2026-11-04): milestone 5b, the SH-2 bus's timing ### What was built (a5a606c) - `sh2side.py`: every bus callback is placed by arbitration first and closed with its end (start + the BSC's states + `chip.wait`). New and rewritten quirks, each with its three records and a test in `tests/test_bus.py` (8 tests): `sh2_waits` (Manual 4.1's low ends, palette split out), `sh2_wait_overlap` (HM 7.4.2: the board drives only what WCR's one programmed wait does not cover; before, every 32X-space cycle had one state too many), `sh2_area0_width` (16, the MiSTer core's mode pins), `sh2_framebuffer_fifo` (4 words, one leaving per 5 clocks; FULL/EMPTY at $20004006 through `sh2_dreq_view`), `sh2_sdram` (the core's cycle: WAIT does not reach SDRAM, HM 7.2.3), `cartridge_contention` (Manual 3.4, both ways; the 68000 through `Board.hold`, the VDP's DMA not held), `sh2_bus_arbitration` (HM 7.10: slave request 2, master return 1, fills and port pairs unsplit). - `docs/sh2-python-sdram-pr.md`: the core change (SDRAM cycle shapes, refresh) written as a PR description, not worked around. - `scripts/run_32xspd.py`: bakemono's 32xspd benchmark against its hardware photograph. - Boot ROMs' BSC, read off the chips: BCR1 $0001, BCR2 $00A8, WCR $0055, MCR $0AB8, RTCSR $08, RTCOR $59. ### Results In [validation.md](validation.md), "Milestone 5b": 32xspd cartridge loops 83.7/300.0/80.7 -> 75.5/267.9/72.6 clocks against the photograph's 76.5/271.1/75.0; frame-buffer writes 32.8 -> 40.9 against 41.1; SDRAM loops unchanged (the core's). Rickroll player: before reproduces the reference run.log exactly; after 142 frames in order, 0 unknown, mean fields per frame 4.37 -> 3.98, decode 2.38 -> 2.02, convert 1.33 -> 1.30, slave wait 0.215 -> 0.263. ### Gate (a5a606c, `reference/m5b/gate.sh`, load 55-105) - testpico cold + warm: frames 110 and 260 (composite and 32X) byte-identical to Sessions 5-6 (all twelve 32X tests as before). - VDPFIFOTesting genesis through the harness: 122/122, every line identical to Session 6. - pytest PyPy 97 passed; CPython 97 passed; ruff 0.16.8 check and format clean. - Mini sweep (115), against Session 1's without: **0 moved** (0 better, 0 worse, 115 unchanged): differs 13, lockup 4, mame-board 8, phase 30, same 45, size 15; 7,778 s. - MAME lockstep, Castlevania, through the harness: 0 unexplained; 11,343,385 68000 and 8,460,818 Z80 instructions identical; 4,764 s. - Mars Check Program, automatic, to frame 760: 51/161 (SH2 MASTER V INTERRUPT OK), ERROR COUNT 0; 7,432 s. Outputs in `reference/m5b/gate/`. ### Speed (PyPy, side by side) Rickroll player, 200 frames, 69c2c19 and a5a606c started together (17:44, load 87-100): 1,256.5 s against 1,379.4 s, SH-2 instructions 71.10 M against 70.00 M: about 11 % slower per instruction, the cost of placing every bus cycle (arbitration and its end) in Python. ### Open questions (Aubrey's) - **Raise the SDRAM PR on sh2-python?** Default: left as docs/sh2-python-sdram-pr.md. - **CS0 width** rests on a detector's pins. Default: 16. - **Arbitration costs** (2/1) and the FIFO read rule are readings, not measurements. Default: kept, labelled. - **ROM-VRAM copy**: the board is 9 clocks an iteration faster than the photograph. Default: listed, not tuned. ### Probe-cart test requests None: every cost here is the 32X's own bus; nothing waits on a base Mega Drive timing. ## Session 8 (2026-11-05): the ROM-VRAM copy against the 32xspd photograph Session 7's open question: the board's ROM-VRAM copy runs 92.60 SH-2 clocks an iteration against the photograph's 101.36. Investigated from the documents; **no model change**. ### What was done - Disassembled 32xspd's SH-2 program (sh2-python `disasm`): the copy loop at `$02001428` makes, per iteration, one cartridge line fill (8 word cycles) and 8 frame-buffer word writes to the draw buffer; the 68000 runs from work RAM and the slave spins in cached SDRAM, so nothing else is on the cartridge or the SH-2 bus. - Traced the board's master on a copy of the ROM patched to start at that test (one PyPy run, about 4 minutes to the loop): 4,186 of 4,204 iterations are exactly 91 states (writes 8 x 3 + 2 waiting for room, fill 64, 1); the photograph's figure is about 100 steady, so about 9 states an iteration are missing. - A steady-state toy of the loop (the FIFO's rule against the fill) tried on both copy loops with the photograph's own read loops' fill times. The SDRAM-VRAM copy has the same kind of shortfall (about 5) once the core's SDRAM fill is the documents' 10-12 states. Every serialising rule overshoots both by about 5; only a fitted constant (7-8 an iteration) lands on both: **not taken**. - Hypotheses and verdicts in [validation.md](validation.md), "The ROM-VRAM copy, investigated": display fetches ruled out (separate draw and display DRAMs, Manual 1.1, and the pure write loop fits); cartridge waiting for the FIFO not documented and overshoots; the core's write buffer already modelled; HM 7.9's idle cycle hidden by the loop's own gap; the core's missing SDRAM refresh about 1 state here and the right size for the other cartridge loops' 1-3 %. - New source: Sega's *32X H/W Information* (MAR-25-R5/R6-060694, the 32XDK transcription), whose "32X I/F Implementation Time" table gives frame-buffer writes 3, 3, 3, 3, then 5 on Target Ver. 2.0: the board's FIFO. Cited in `sh2_framebuffer_fifo`. - Docs: validation.md (the row, the investigation, the source table), timing.md, undocumented-behavior.md (open item 12, the FIFO and SDRAM entries), `Quirks.sh2_framebuffer_fifo`'s records (text only; value unchanged). ### Open questions (Aubrey's) - **The copy loops' missing time** stays open, labelled. A second photograph or anyone's measurement of a write-then-read pattern (e.g. 4 frame-buffer words then one cartridge word, uncached) would tell a per-switch cost from a FIFO rule; nothing in hand does. - **Refresh**: worth adding to the SDRAM PR's case that it would also close most of the cartridge loops' 1-3 %? Default: noted in the docs only. ## Session 9 (2026-11-05): horizontal timing, the 32X against the Mega Drive Branch `htiming` from fb81893. The three open items of Session 5 ("Open after milestone 4"): H40 alignment against the line model's 40 MCLK, `hblank_phase` with the one-on-one composite ("5 dots before its own window"), and `vdp.py` counting H32's 10-MCLK dots against `composite_dot`'s 8. ### What decided it - **Sega's *32X H/W Information*** (MAR-25-R5/R6-060694, the 32XDK transcription, item 4, "Display dot distortion with MD"): "Left 2/3 dot for Ver. 1.0; 1/2 dot left or right for Ver. 2.0. Between 1/2 dot left to 1/2 dot right for mass production goods". In H40 the two pictures lie one on one within half a dot: a document, not only the detectors. - **The Manual's figure 3.15, read again** (scan, PDF page 55): A (100 dots, 860 MCLK) and B (320 dots) are drawn between XHDISP's edges, and XHDISP rises and falls D = 3 dots after HBLANK. The phase scan is unaffected (the 860 holds from either edge); only VBLANK's 224 fixes the phase. Recorded in `hblank_phase`; XHDISP not modelled. - **Nuked-MD as the die-derived referee for the Mega Drive side of the slot.** Its FC1004 makes EDCLK in the arbiter (`arbiter.c` `ARB_ClockEDCLK`) from MCLK, HSYNC and reset only; the H mode never reaches it. A probe of our own (`scripts/nmd_edclk_probe.c`, built in a scratch copy of megadrive-python's pinned Nuked-MD @ 594ca2a with one call added to `md.c`; the build recipe is in its header) logged EDCLK, /HSYNC, the V and H counters and the RGB pins on megadrive-python's measurement carts (`output-delay-cram-h40/h32` and `vscroll-latch-planeA-h40/h32`, frames 11-12, each run about a minute); `scripts/nmd_edclk_report.py` gives, in MCLK from /HSYNC's fall: | | H40 | H32 | | --- | ---: | ---: | | V counter increment to /HSYNC fall | 312 | 370 | | die H counter at /HSYNC fall | $1CD | $1D9 | | EDCLK cycles a line | 840 | 840 | | slow runs (15 cycles of 5 MCLK each) start at | 1.5, 84.5, 167.5, 250.5 | 4, 87, 170, 253 | | backdrop (left border) on | 572 | 510 | | display pixel 0 (plane A) on | 676 | 650 | | picture off | 3,236 | 3,210 | The slow runs paired two cycles to a dot are exactly megadrive-python's H40 table (7 x 10, 9, 9, 7 x 10, 8, ...), and its line puts the first slow pixel 312 MCLK after the V increment, where the die's /HSYNC falls: the two frames agree at HSYNC. ### The verdicts 1. **`hblank_phase` and the one-on-one are both right; the "5 dots" was a mixed frame.** HBLANK 184 MCLK before EDCLK's first slow cycle (the phase, now restated in EDCLK terms) + 860 opens the 32X's display 676 MCLK after the slow run starts, 677.5 after /HSYNC; the die's Mega Drive shows pixel 0 at 676. 1.5 MCLK: one on one, as the H/W Information says. Milestone 4's 40 MCLK came from socket 7's `display_at + output_delay x pixel_mclk`, which in megadrive-python is where a CRAM write shows (its item 20, measured from the die's CRAM-dot offset), not where pixel 0 leaves the RGB pins: that is 26 board pixels behind the counter in H40 (40 MCLK later), 26 in H32 (20 MCLK later). Kabuto's oscilloscope note ("24 pixels after the right edge (or 10 after the last rendered pixel)") gives 76 dots from the slow run to pixel 0, the die 77. No behaviour change in H40. 2. **`vdp.py`'s H32 timing was wrong; changed.** EDCLK keeps its H40 dots in H32, and the 32X counts EDCLK. New `Quirks.edclk_h32` (374: the slow run's start in the H32 line, 370 + 4); `LineTiming` builds EDCLK's dots for an H32 record (`vdp.edclk_dots`, cached) and places HBLANK 23 of them before it: HBLANK 190 MCLK into the record, PEN 214, VBLANK's edges 414, the latch 858, the display 1,050 -- the Manual's 24/224/668/860 spans, where the old count gave 30/270/760/1,000. H40 unchanged (the same code path as before). 3. **H32 alignment: 26 -> 30 MCLK.** From the same figures, the 32X's display opens 4 + 676 = 680 MCLK after /HSYNC, the Mega Drive's pixel 0 at 650: 30 MCLK, 3.75 of the 32X's pixels, where PicoDrive, ares and jgenesis put 26 and BlastEm's frames about 3.75. Under the board's centre sampling, output pixel x now takes the 32X's x - 4 (was x - 3) and the line is 324 wide. Any value in (28, 36] gives the same picture, so the residual uncertainty (the 32X's dot phase on EDCLK, a few MCLK) does not move a pixel. Tier: specification (the Manual's line) on die-derived Mega Drive figures; it rests on the 32X timing its line from HSYNC in H32 as in H40. `composite_dot` and `composite_alignment` are now specification tier with the H/W Information and the die in their documents; the detectors' 26 stays in `unresolved`. ### Tests - `test_the_32x_display_opens_over_the_mega_drives_pixel_0` (replacing `test_the_line_model_alone_would_put_the_32x_five_pixels_right`): on the board's H40 lines the 32X's display opens 676 MCLK after socket 6's first slow pixel (the die's pixel 0), and still 40 MCLK after socket 7's `display_at + output_delay` (kept, so the meaning of that field stays pinned). - `test_h32_counts_edclk_dots_from_hsync` (`tests/test_vdp.py`): an H32 line's HBLANK at 190 MCLK and the Manual's four spans in MCLK. - The H32 composite tests at 30 MCLK and 324 wide. - pytest PyPy and CPython: 98 passed each (+1 slow deselected); ruff check and format --check (0.16.8): clean. ### What moved - **The passive path**: not touched. With ADEN = 0 `VDP32X.video_line` builds the line's `LineTiming` (H32 now from the cached EDCLK dots) and returns before queuing any event; no status or register is reachable and the composite hands every line back None. Run anyway: VDPFIFOTesting through the harness, 122/122, every line identical to Session 7's gate (`reference/m5b/gate/vdpfifo-genesis.log`), 112 s. - **testpico** (cold 110 frames, the reset button, warm to 260; PyPy, 683 s): frames 110 and 260 (composite, 32X and Mega Drive PNGs) byte-identical to Session 7's gate (`reference/m5b/gate/testpico`), and every report line, SH-2 instruction counts included, the same: it never shows the 32X in H32. (Run on the tree before `edclk_dots` was cached, a change of speed only.) - **Milestone 4 titles**: Chaotix, Spider-Man, the 240p suite and Mars Check run in H40: nothing moves (the H40 map and line timing are as before). NFL Quarterback Club's H32 menu: the 32X's layer one output column right, the line 324 wide; recomposed from the saved frame 3,060, about 4,726 of 72,352 pixels change, all at the layer's edges (validation.md, Milestone 4). Its H32 status bits and interrupts also move (HBLANK 30 MCLK later, the latch 62 earlier, the row 110 earlier); not rerun. ### Open questions (Aubrey's) - **XHDISP.** The figure counts the 100 and 320 dots between XHDISP's edges, 3 dots after HBLANK's. Taken as the 32X's picture window it would put the 32X 24 MCLK right of the Mega Drive in H40, outside the H/W Information's half dot, so the board keeps HBLANK's fall. - **A capture that would settle all three** (none exists): on a 32X in H40 and in H32, a scope on the 32X's video out with the Mega Drive showing a one-pixel vertical line at display x = 0 and the 32X a one-pixel line at its x = 0 (through bit set over a transparent backdrop), or the two pictures' left edges against the slot's /HSYNC; plus HBLK read against the Mega Drive's HV counter in H32. A probe-cart ROM that draws both lines is small; Aubrey's Genesis has no 32X. - **megadrive-python's socket 7.** `display_at + output_delay x pixel_mclk` is not the RGB pins' time (40 MCLK early in H40, 20 in H32 against Nuked-MD). Nothing in sega32x-python relies on it now; a docstring note in `sockets.py` (or a separate `pins_at`) would stop the next reader making Milestone 4's mistake. Not changed here (megadrive-python untouched). ## Session 10 (2026-11-05): save states and the package CLI The brief's tooling bar ("whole-machine save/restore including both SH-2s ... a debugger hook, `python -m sega32x_python CART --bios-dir DIR --frames N --png out.png --wav out.wav`"), driven by boot times: the rickroll player spends 137 frames and the Mars Check Program about 300 before anything worth testing, at 0.3-2 frames/s. ### What was done - `savestate.py`: the machine pickled (the System, the 32X, both SH7604s), zlib level 1, behind a magic line and a JSON header: format 1, the frame, the board's git revision (with `-dirty-` and a digest of the package's source when it has uncommitted changes), the six cores' commits (megadrive-python, sh2-python, m68000-python, z80-python, ym2612-python, sn76489-python, from pip's `direct_url.json`), the interpreter, the cartridge's and the three boot ROMs' SHA-1s. The header is checked before unpickling; another board revision needs `--any-board`. - Not written: the cartridge's `bytes` attributes and the boot ROMs (persistent IDs by role, re-attached from the cartridge and boot ROMs handed to `load`; any other immutable `bytes` of 4 KB or more stops the save); the packages' module-level objects (by reference, so `H32`/`H40` and their lambdas, the machines tables and the cores' decode tables keep their identity); the SH-2 side's four closures per chip, made again by the new `SH2Side.rewire` (the constructor's wiring, moved there). - Found on the way, worked around without touching the cores (PR notes in [megadrive-python-state-pr.md](megadrive-python-state-pr.md)): megadrive-python's `AudioPath` keys socket 8's leftover samples by `id(source)` (the keys are moved to the new ids after loading); m68000-python builds its dispatch table on the class in the first `M68000CPU()`, which an unpickling process never calls (a throwaway console is built first); PyPy 3.11's `_pickle` takes a Pickler subclass's extra constructor arguments as its own (the tables are set after construction). - `runner.py`: `Session` (build or load, the FM and rate, a frame, a save, the three pictures), shared by `scripts/run_32x.py` (now `--save-state FILE --save-at N`, `--load-state FILE`, `--any-board`; frames numbered on from the saved one; a final `[run]` line with the 68000, Z80 and SH-2 instruction counts and MCLK) and the new `python -m sega32x_python` (`__main__.py`: `--frames`, `--png`, `--wav`, the same state options). `--pwm-log` refuses a state (its wrapper is a local class). - The debugger hook: `SH2Side.on_step(index, chip)` before each step of either chip, one check a step when unset; per access, sh2-python's own `chip.observe` and wrapped `read`/`write`. Device events (the 32X VDP's, PWM's, register writes) have no hook yet. - Tests: `tests/test_savestate.py` (round trip on a synthetic machine, no ROM bytes in the pickle, refusals), the hook in `tests/test_sh2side.py`. ### Results Determinism, straight against save + fresh process + load, byte for byte (validation.md, "Save states"): | Program | N + M | Frames, counts, sound | State | Save / load | | --- | --- | --- | --- | --- | | testpico cold | 60 + 50 | 150 PNGs, 50 status lines, final counts identical | 82,330 bytes | 1.74 s / 1.58 s | | Sega's PWM sample, FM on | 125 + 45 | 135 PNGs, 45 lines, counts, WAV (33,118 samples) identical | 55,944 bytes | 0.26 s / 0.42 s | | rickroll player | 140 + 60 | 180 PNGs, 60 lines, counts identical; `verify_run.py` 16 frames in order, 0 unknown, as straight | 183,520 bytes | 1.14 s / 1.00 s | Counts: testpico 68000 1,132,967, Z80 69,796, SH-2 11,837,712 / 11,875,672; PWM sample 68000 3,049,341, SH-2 19,200,871 / 19,807,889; rickroll 68000 1,998,207, SH-2 29,596,022 / 40,405,404 -- each the same straight and loaded. The PyPy-written rickroll state loads on CPython 3.14 and runs frames 141-144 identically. `python -m sega32x_python` checked by hand: a load to frame 145 gives the straight run's `f00145.png` byte for byte; a save at 8 and a load to 10 give the same last picture; a refused state is a one-line error. A state saved with the FM off and loaded with `--wav` warns that the sound will not match (that run, FM on from frame 141, went at 0.07 frames/s beside another job; not looked into). ### Open questions (Aubrey's) - **Board revision on load**: a state is refused by another board revision (a pickle holds the objects' attributes, so a changed class can load into nonsense) unless `--any-board`; an uncommitted tree's states carry a digest of the package's source, so an edit between save and load is refused too (a state saved before `on_step` existed, loaded after under the old plain `-dirty` mark, failed on the missing attribute: why the digest is there). Default: strict. A looser rule (refuse only when `src/` differs) is possible. - **Device events for the debugger** (VDP line events, PWM periods, register writes, CMD and FIFO): one optional callback like `on_step`, or sh2-python's trace schema extended with board records? Not built; next if wanted. - **Traces in sh2-python's schema plus 32X events** (the brief's other tooling item): not started; `on_step` plus `sh2_python.debug.StepRecord` is the likely route. ## Aubrey's decisions (2026-11-05) Aubrey accepted every default standing in Sessions 3-8: the PWM gain stays the board's labelled assumption, start-up pops included; the PWM period stays `cycle - 1`; the sh2-python DREQ-edge and megadrive-python socket-8 notes stay in this worklog; the whole Mars Check Program (161 tests) is rerun at a quiet time before milestone 6; CS0 stays 16 bits; the arbitration costs (2/1) and the FIFO read rule stay, labelled; the copy loops' missing time stays unexplained, not tuned; HBLANK stays at the Manual's position; VBLANK stays 27 dots; testpico's Mega Drive test 45 failing warm is accepted for now (megadrive-python #10). Aubrey asked for the SDRAM PR on sh2-python (docs/sh2-python-sdram-pr.md), now being built there. No 32X hardware is available, so each of these stays labelled as resting on documents and detectors. ## Session 11 (2026-11-05): repin to sh2-python 8755c3a (the SDRAM BSC) sh2-python PR #1 (synchronous DRAM cycles and refresh, from [sh2-python-sdram-pr.md](sh2-python-sdram-pr.md)) merged as 8755c3a; pinned in df3df1f. Reruns at df3df1f, PyPy, the two side by side: - **32xspd** (380 frames, 2,345 s), SH-2 clocks per iteration, board against the photograph: SDRAM read 20.91 / 22.08 (was 35.21), sparse SDRAM 49.34 / 51.49 (105.64), sparse SDRAM uncached 49.02 / 51.37 (32.01), SDRAM write 13.53 / 13.53 (25.63), SDRAM-VRAM copy 41.44 / 46.59 (52.82), ROM-VRAM copy 93.75 / 101.36 (92.60; the refresh adds about 1), cached read 11.31 / 11.31, ROM read 75.00 / 76.53, VRAM write 40.62 / 41.14. - **Rickroll player** (reference/rickroll/c1v_0, 200 frames): first picture at frame 141, 19 video frames in order, 0 unknown; fields per video frame {2: 3, 3: 10, 4: 3, 5: 1, 6: 1}, mean 3.28 (Session 7's after-run: 4.0 over the same 200 frames). - pytest 101 on CPython and PyPy; ruff 0.16.8 clean. ## Session 12 (2026-11-05): milestone 6, the first smoke sweep The 27 titles of `tests/smoke_sweep.txt` on the board at 0d985b8 (PyPy, the user's boot ROMs) and on PicoDrive (detector, the same boot ROMs), 1,200 frames each, pad 1 Start at frames 700 and 1,000 (6 frames). The board saved its composite every 100 frames; PicoDrive every second frame. Each board frame was compared with the closest PicoDrive frame within 300 frames (tolerance 12 per channel). Scripts and output are in `reference/m6/` (git-ignored): `smoke.sh`, `triage.py`, `triage-w300.txt`, `triage-pal.txt`. ### Results - **All 27 ran 1,200 frames: no exception, no Lockup.** The full run took 2.3-5.2 h a title with all 27 at once (load about 39 on 32 cores); alone a title runs at about 0.3 frames/s. - **No wrong picture.** Every frame differing by more than 5 % from its closest PicoDrive frame was looked at: Doom, Knuckles' Chaotix (its PUSH START palette cycle, 9-10 %), Space Harrier and Star Wars Arcade (logo animation), Mortal Kombat II, Virtua Racing Deluxe (attract race, camera), Tempo (walk cycle), the run-length demo (the model's turn). Each is the same screen at another animation phase, or another screen because the Start press landed elsewhere (Doom stays on its title: its 700 press fell in the intro). - **Harness fault, fixed:** the first run put every title on the `genesis` machine, so the two Europe-only titles (Virtua Racing Deluxe (Europe), Darxide) showed the PAL lockout screen. Rerun on `megadrive` (PAL): both play, Darxide 0 % at every frame, VRD as its USA version. `smoke.sh` now picks the machine from the title's region. - **Pacing (open).** The board falls behind PicoDrive as a run goes on: the closest detector frame is 60-120 frames earlier by frame 300 and up to 300 earlier by frame 700 (the Mars Check auto demo and Soulstar X stay about 10 behind). The games advance more slowly per field on the board. That agrees with the rickroll player's 3.28 fields per video frame (it needs 2), and the board's SH-2 bus is within about 5 % of the 32xspd photograph while PicoDrive's SH-2 timing is loose, so PicoDrive cannot say which is nearer the console. A second detector with cycle-counted SH-2s (BlastEm, libretro build 542164d) would; the copy loops' unexplained 8-11 % (Session 11) is the board's known shortfall in the other direction, so it does not explain this. - **Known broken:** none. The smoke list's section stays empty. ### Next - Pace the comparison: press Start on a picture rather than a frame number (or from a save state after boot), so both sides get the press in the same state. - Run BlastEm on the same titles as a second detector for the pacing question. ## Session 13 (2026-11-06): BlastEm on the smoke list; pacing answered Aubrey asked for BlastEm (libretro 542164d, `megadrive-python/reference/build-blastem-libretro`, the user's boot ROMs under the lowercase names it wants, `reference/m6/bios-blastem`) on the 27 titles, same presses and frames as PicoDrive. All 27 ran (`reference/m6/blastem/`, `triage-blastem.txt`; `detlag.txt` sets BlastEm against PicoDrive). - **Session 12's "pacing" was mostly PicoDrive running ahead.** On a static screen the closest-frame search returns the earliest identical frame, so its lag means nothing; on animated stretches the lags are constant. Board behind PicoDrive / board behind BlastEm / BlastEm behind PicoDrive, in frames: After Burner 62 / 16 / 46, Space Harrier 64 / 16-22 / 48, Star Wars Arcade 78 / 20 / 58, NFL Quarterback Club 90 / 24 / 66, Mars Check auto demo 10 / 2 / 8. The board reaches each game about 20 frames after BlastEm and plays at the same rate. - **The exception is SH-2-bound rendering.** The run-length demo's lag grows on both: the board falls 16 -> 202 frames behind BlastEm over frames 100-1,200, BlastEm 34 -> 294 behind PicoDrive. - **32xspd on both detectors** (the results screen at frame 700, KB/s), against the photograph: PicoDrive shows 31,104-31,360 for every loop, no memory timing at all. BlastEm: cached 31,712 (hardware 31,840), SDRAM read 16,560 (16,304), ROM read 6,000 (4,704, +28 %), sparse SDRAM 6,880 (6,992), sparse ROM 1,744 (1,328, +31 %), sparse SDRAM uncached 6,880 (7,008), sparse ROM uncached 5,984 (4,800), SDRAM write 23,456 (26,608, -12 %), **VRAM write 31,984 (8,752, x3.65: no FIFO stall)**, SDRAM-VRAM copy 12,880 (7,728, +67 %), ROM-VRAM copy 5,440 (3,552, +53 %). The board (Session 11) is within 1-6 % of the photograph on every simple loop and 8-12 % fast on the copies. So BlastEm runs renderers ahead of the console, and neither detector can judge the board's pace; the photograph says the board is the nearest of the three, and if anything slightly fast. **Closed:** no board change. - **Pictures against BlastEm.** No new board fault. Where BlastEm alone differs: Soulstar X (6 % at every frame: BlastEm draws no HUD, the shield/energy gauges and score; the board and PicoDrive agree at 0.1-0.4 %), Virtua Racing Deluxe (Europe) and Darxide (the PAL picture placed about 8 lines lower by BlastEm; the board and PicoDrive agree), the Chaotix title's palette cycle (each emulator its own phase). Doom's later frames agree with BlastEm (title screen) where PicoDrive had reached the skill menu: the Start press landing, as said. - For the rickroll player: the board's 3.28 fields per video frame is not an emulator slowness that hardware would hide; a 32X is, by 32xspd, at least as slow. ## Session 14 (2026-11-06): the boot's 16-24 frames behind BlastEm Session 13's constant lag sits wholly before the first picture: After Burner's first non-blank frame is 104 on the board, 82 on BlastEm, 40 on PicoDrive; Space Harrier's 86, 70, 22. It grows with the cartridge's size, not the header's copy size (64 KB: 2 frames; 2 MB: 16-22; 2.5 MB: 20; 3 MB: 24; Star Wars Arcade copies 21 KB, Space Harrier 128 KB). - **The master boot ROM checksums the whole cartridge.** Sampling the master's PC (every 1,000 steps, `reference/m6/lag/bootprobe.py`): frames 15-68 of Space Harrier are in $278-$282, `MOV.W @R8+,R2 / AND / ADD / AND / DT / BF`, one cache-through cartridge word a pass from $22000200 to the end, the sum stored at GBR+$28 (COMM8). The cache is on (CCR $01). The slave waits at $1C0 (a 40-pass delay, then one COMM read): no bus load. The 68000 waits in the cartridge's start code at $8807C2, fetching from the cartridge. - **The board's pass: 19.78 SH-2 clocks** (R7 falls 19,417 a frame, 6.0 instructions a pass, frames 25-35). With `SH2Side.m68k_cartridge` stubbed to 0 for the measurement (`reference/m6/lag/sumrate2.py`), 16.43: the 68000's fetches hold the SH-2's cartridge cycles (`Quirks.cartridge_contention`, Manual 3.4 "ROM Access Competition") for 3.35 clocks a pass, about 9 frames of a 2 MB cartridge's 54. 16.43 is the six instructions' 8 states plus about 8.5 for the cartridge word, as 32xspd's uncached ROM loop (within 3 % of the photograph) gives. - **So the 16-24 frames are BlastEm's:** it has no contention (about 9 frames) and its cartridge reads are 28-31 % fast against the photograph (Session 13; about 7 more). **Closed:** no board change. A hardware boot time (power-on to first picture for a 2 MB title) would test the contention's size; no 32X is available, so it stays labelled. ## Session 15 (2026-11-06): presses counted from the first picture The boots differ most between emulators (Session 14), so `scripts/run_32x.py` and `scripts/libretro_frames.py` gain `--press-from-picture N:BUTTONS[:HOLD]`: the press comes N frames after the first frame that is not one colour. Doom (one board run, 760 frames, Start at first picture + 500): the first picture (the SEGA logo on all three) is frame 113 on the board, 95 on BlastEm, 17 on PicoDrive (no SH-2 memory timing, so its checksum is nearly free). Counted from there, the board matches BlastEm at 0-0.4 % within 6 frames from k = 387 to 647, one demo-phase frame apart (18 % at k = 607); all three are on the same screen after the press (the menu over the demo), PicoDrive's demo at another phase. Session 12's Doom difference (the skill menu on PicoDrive only) is gone. `reference/m6/smoke.sh` now presses Start at first picture + 550 and + 850. Item 2 of the plan (the copy loops' 8-12 %) was not reopened: Session 8 traced the loop, tried every documented serialising rule (each overshoots both copies by about 5) and measured refresh (about 1); nothing new is in hand but a fitted constant, which stays refused. ## Session 16 (2026-11-07): the save-state workarounds go megadrive-python #11 (socket 8's leftovers by source, docstring notes) and m68000-python #6 (the dispatch table built on first read) merged as d75b6a4 and c827cca; megadrive-python #12 moves its m68000-python pin to c827cca. `savestate.py` drops the id remapping and `_prime`, and the state's format goes to 2 (the pickle no longer carries the sources' ids). - **`_prime` was covering a third case.** With it gone the PWM sample's load in a fresh process stopped at its first SH-2 step: `'SH7604' object has no attribute '_table'`. sh2-python built its table in `__init__` as m68000-python had; sh2-python PR #2 is the same descriptor (593 passed, 1 skipped on PyPy and CPython; its two tests fail on main). - **The test that would have caught it:** `tests/test_savestate.py` now loads a state in a child process that has built no console, runs on and compares the fingerprint (the sound sources by class name). It fails on sh2-python 8755c3a, passes on PR #2's head. - **Determinism, PWM sample, FM on, 125 + 45, fresh process:** 135 PNGs, 45 status lines, the WAV (33,118 samples) and the final counts identical (68000 3,023,049, Z80 4,967, SH-2 18,816,298 / 19,803,045, MCLK 151,431,333); 57,420 bytes, 0.26 s / 0.70 s. - **The counts moved from Session 10's** (68000 3,049,341, MCLK 151,431,382): the repin brings megadrive-python's commits since 44ab15d, among them the first VINT's E clock two clocks back (037d2da) and plane A's window fix (491c584). The board's suite passes (101 plus the new test). Three of the milestone 5 gate's runs on the new pins, against reference/m5/gate (3226df1): testpico's six PNGs (frames 110 and 260, before and after the reset) byte for byte; VDPFIFOTesting on `genesis` 122/0/122; the Castlevania lockstep replay's report identical but for the revision line; the mini sweep 0 better, 0 worse, 115 unchanged against the passive baseline, and every row's status, difference and offset as at the gate; Mars Check's automatic run (7,100 frames, 9,020 s) ends on "all finished normally" by frame 7,000, its last picture byte for byte milestone 4's final run's (reference/m4/final, 3cd3bb6). Its other captures fall on other frames, as any timing change moves them; the program's own count is the judge. - Pinned at the merge commits, megadrive-python 5c6d1b7 and sh2-python d4665d5, whose trees are the PR heads these runs used. ## Session 17 (2026-11-19): the wave-2 provenance rewrite, in place What changed and why is in [provenance.md](provenance.md), "Wave-2 rewrite". The gates, each run on e3bdf84 (before) and e483e65 (after), PyPy, the user's boot ROMs: | Gate | Before | After | | --- | --- | --- | | pytest / `-m slow` | 102 / 1 | 102 / 1 (and 102 on sh2-python b327ae0) | | testpico, 260 frames, cold + warm | frames 110, 260 as milestone 5b | byte-identical to before | | Mars Check automatic, 760 frames | 51/161, ERROR COUNT 0 | all 118 kept frames byte-identical | | PWM demo, 480 frames, FM off | 352,520 samples | same count; correlation 0.994 (0-3 s), 0.997 (1-7 s) | | NFL Quarterback Club, 900 frames, Start at 300 and 600 | reaches its 32X mode-2 screen | all 18 PNGs byte-identical (the Acclaim board without the ROM/EEPROM switch passes the game's own /SDA check) | **A note on the earlier sessions.** These dated entries are history and are not rewritten, but parts of them rest on reading closed sources and are superseded: lines 43-44 (PicoDrive's libretro BIOS lookup), 239-240, 323-332 and 367-369 (PicoDrive's FEN note), 372-373 (jgenesis's HINT and VBLANK), 437, 554-556, 563-565, 584, 656-657, 680 (the MiSTer core's pins), 790-842 (the Nuked-MD probe and the verdicts built on it) and 887. Possibly also 1025, 1095 and 1106 (statements about other emulators' SH-2 timing that may be inferences from 32xspd runs). Nothing in them is evidence for the board any more.