# Build status (for the next agent) Where the restarted board (docs/restart.md) stands, exactly, and what to do next. Read docs/restart.md (the rules), docs/status.md (the gates with numbers), docs/provenance.md (where each rule came from) and docs/worklog.md first. ## Environments - `.venv-pypy-pin4` (2026-11-23): **use this one.** The pins in `pyproject.toml` -- megadrive-python efd80fc (its main, pushed), m68000-python 4454d54, z80-python b59c80b, installed from the local clones (`pip install --no-deps git+file:///data/emu/@`); ym2612-python and sn76489-python editable from `../`; this repository editable; pytest. No 32X. - `.venv-pypy-pin3`: holds megadrive-python **6303613** (not the 3e2325f the old pyproject named; pip freeze says so). `.venv-pypy-pin2` (b84d978, with sega32x-python 5c66906: the only one with a 32X) and `.venv-pypy` (5c6d1b7): kept for comparison. ## Gates (2026-11-25, the drive rules of decision B1; numbers in docs/status.md) | Gate | Command | Value | | --- | --- | --- | | unit tests | `pytest` | 43 pass (29 + 6 save-state + 1 fader + 1 seek + 1 decoder pulse + 5 domains) | | mcd-verificator as BIOS, `--ram-cart`, Sonic CD in the drive, 1,600 frames | `python -m segacd_python --bios --ram-cart --disc SONIC.cue --frames 1600 --text` | 17 of 18 OK; CDC FLAGS "25. ERROR: 40" (as LC8951 units fail it; status.md) | | save states | `pytest -m slow tests/test_save_state.py` (with `SEGACD_DISC` and without) | passed with Sonic CD in the drive and with none (9f16fe2; not rerun on the B1 rules) | | drive-log replay | `scripts/replay_cdd_log.py SONIC.cue` (`--as-shown`: mid-session logs start as shown) | 3,054 of 11,256 (4,076 as shown) | | seek times against the logs | `scripts/cdd_seek_times.py --model SONIC.cue` | mean miss 7.16 exchanges over 32 | | picture referee | `scripts/referee.py --bios $SEGACD_BIOS --disc SONIC.cue --backup-ram FORMATTED --frames 300-3600:300` | 12 of 12 frames agree with Genesis Plus GX at 0 differing pixels (`--window 150`); the board 53 frames behind from the title (50 before the B1 rules, 35 before session 4); sound (session 3, not rerun): CD-DA 0.971, BIOS intro 0.928 | | Sonic CD (USA), your BIOS, formatted backup RAM | status.md's recipe | Palmtree Panic zone 1, timer running at 6,900-7,500 (Start at 4,834, 5,504, 6,204 since the B1 rules; 4,830, 5,500, 6,200 before) | | CD + 32X | `--with-32x DIR`, `.venv-pypy-pin2` only | Night Trap's title film (2026-11-19); not rerun | ## Next steps, in order 0. **The drive, after the seek's structure** (built in session 4; replay 3,004 of 11,256; **3,054 since report 5's latency and stop to state 0 were kept on 2026-11-25**, decision B1, with the recipe's presses re-derived: status.md, "Drive rules kept"; of the list below, those two are now built, report 5 while playing or paused and stop's 13 "0F" exchanges are not). Found in the logs and not built, each measurable by `scripts/replay_cdd_log.py` (worklog.md, session 4, has the line numbers): report 5 answered 3 exchanges after the request in state 9 (112 cases; the model answers in 1), and while playing or paused it stops the drive to state 9 after about 20 busy exchanges; reports 3-5 shown on, not once (the "F" after them is the next request's latency); report 1 in a pregap one less than the distance (lba -1 reads 0); stop shows "0F" for 13 exchanges then state 0; resume from pause plays in and shows "playing" before the paused sector; report 0 after a seek from rest (true, kept out while arrivals miss). Measured in a scratch worktree on 9f16fe2, not committed: report 5 answered after 2 busy exchanges in state 9, 3,004 -> 3,038; with stop going to state 0 (flags 1) as well, 3,054; reports 3-5 shown on instead of once, 2,911 (worse); report 1 in a pregap one less, 3,033 (worse). **Tried on main and not kept (2026-11-24, later in session 4): report 5's latency with stop to state 0.** Replay 3,004 -> 3,054 from power-on, 3,704 -> 4,076 with `--as-shown` (stop.txt and stop-play.txt become fully identical); unit tests 38; mcd-verificator 17 of 18 unchanged; the referee 12 of 12, the board 53 frames behind at the title (50 without), 28 at 1,200, 11 at 3,300, 31 at 3,600. It fails the recipe: the boot runs differently (frame 5,400 is in the attract film, frames 6,300-6,900 the title screen), so the fixed presses (4,830, 5,500, 6,200) leave Sonic at the Palmtree Panic card at frame 7,500 with the timer at 0'00"00. The rule looks right for the drive; to keep it, re-derive the recipe's presses (a recipe change, which the gate's definition does not allow on its own) and rerun. **Kept on 2026-11-25** (Aubrey approved decision B1): presses now 4,834, 5,504, 6,204, the same verdict; the referee 53 frames behind. The arrival times are the limit: the pickup's place after the TOC read varies (first reported position after a seek from rest: 00:56 to 18:51), so a seek from rest cannot be timed from the target alone. `scripts/replay_cdd_log.py --as-shown` (2740185) starts the five logs that begin playing or paused where their first lines show the drive (tray open still starts from power-on; the paused loop's phase is not recovered). Per step, power-on / as shown: before session 4, 2,630 / 3,468; the seek structure with the loop (step 3), 2,997 / 3,697; landing 14 (9f16fe2), 3,004 / 3,704; with report 5's latency and stop to state 0, 3,054 / 4,076; adding report 0 after a seek to that, 2,955 / 3,977 (still worse). The logs' spin-up runs 64 to 100 exchanges (SPIN_UP is 70) and the TOC read 48 to 100. 1. **CDC FLAGS 40: a revision row, not a bug.** Session 4 built the decoder interrupt as the LC8951 manual's pulse (step 34 passes) and the row now fails as Mike Pavone's LC8951 and LC89515 units do ("25. ERROR: 40", forum t=3166). Step 40 (frame ~477): a host transfer started about 1,400 sub clocks after a block's INT5, STAT3 not read, so DTEI arrives while the pulse holds INT low and brings no INT5. KRIKzz's CDX (LC8913) passes. A `cdx` row would need the LC8913's interrupt timing: no permitted source (KRIKzz's units, a probe ROM on a CDX, would settle it; Aubrey has no Sega CD). The rule kept: the LC8951 (DOC), provisional as the chip choice. Unchanged by the pulse: VALST is still cleared by reading STAT3 here, while the manual's p.63 says reading STAT3 does not reset it (the scan is damaged there; check the row and your BIOS if it is changed). 2. **Save states from before 322c662** still load (megadrive-python's loader applies a state onto a freshly built console, so the drive's new `seek_*` and `loop_*` fields keep their power-on values), but a drive saved while seeking arrives at once, and one saved paused loops at sector 0's place until its next seek or pause. **Decided 2026-11-25 (decision B2, approved as recommended): accepted and documented (status.md); proper versioning comes with megadrive-python's device-state socket (B3, step 5).** `--frames` after `--load-state` counts frames *after* the saved one (a state saved at 450 with `--frames 450` ends at 900). `--load-state` needs the same `--bios`, `--disc` and `--ram-cart` as the run that saved it. 3. **Milestone 2 (time)**: PRG-RAM and word-RAM refresh and wait states from the MiSTer captures (`pr_refresh_*.PNG`, `wr_refresh_when_wordram.PNG`, as images, never the HDL); Ti_'s speed test (sub CPU 12,162,088-12,222,928 cycles a second on hardware, forum t2981, prose) as the judge. The IFL2 latency (14, FITTED) should be revisited once the sub CPU's speed is right. 4. **Mode 1 titles and the CD + 32X discs** (milestones 6 and 8): only Night Trap tried. 5. **A socket for a device's state in megadrive-python** (docs/sockets.md ยง12): to propose there; then `state.py` stops borrowing private names. 6. **Referee smoke list**: more discs through `scripts/referee.py` (only Sonic CD so far); a disc directory needs a documented environment variable first. 7. The RAM cartridge's memory: no permitted source for its layout; keep the documented default (not modelled, reads "not present"), provisional. ## Method that worked: logging the test ROM's traffic mcd-verificator's source is GPL-3.0 and is never opened, nor its binary disassembled. What is allowed and worked: wrap `GateArray.sub_read/sub_write/main_read/main_write` and `acknowledge` to log every register access with the sub clock and the sub CPU's `_fault_pc`; decode the mailbox (main writes the address to $A12014-$A12016, data to $A12012, a command to $A12010: 1 byte read, 2 byte write, 3 word read, 4 word write; the sub CPU answers in $FF8020/$FF8022); find the clock at which the error text appears by stepping the system 20 instructions at a time and reading plane A (`__main__.screen_text`); the last traffic before it is the failing step. Save states (`--save-state`, `--save-every`; `segacd_python.state`) make this quick; a pickle of `(system, device)` still works for scratch use. The scratch tools used are not in the repository; they are a few dozen lines each.