# Worklog Dated sessions: what was built, what was run, and where each rule came from. The rules of the restart are docs/restart.md. ## 2026-11-19, session 1: milestone 1 (restart build) **Read first** (all permitted): docs/restart.md, handoff-brief.md, manual-registers.md, sockets.md, validation.md, mame-oracle.md, the READMEs; megadrive-python's installed `sockets.py`, `board.py`, `system.py`; m68000-python's `cpu.py` (its API); ares 9408cb4 `ares/md/mcd/*.cpp, mcd.hpp` (ISC; not `megald.cpp`); MAME f379cd0 `megacd.cpp` (BSD-3, first line checked; the interrupt and $A12000 parts); KRIKzz's `readme.txt`, `cd-log/readme.txt`, `notes/random notes.txt`, `cdd-cmd-info.txt`, `asic-render.txt` (prose and tables; no code fragments there); the BIOS manual's backup RAM chapter (text extracted with pdftotext). **Built**: `memory.py` (PRG RAM, word RAM 2M/1M, the dot image with PM1-0, the cell image, backup RAM), `gatearray.py` (both register blocks, the word-RAM hand-over, the timer, stopwatch, interrupt controller, communication), `graphics.py` (font converter and the stamp unit), `megacd.py` (the port device, its claims, the main- and sub-side buses, the scheduler and the sub CPU), placeholders `cdc.py`, `cdd.py`, `pcm.py`, `ramcart.py`, and `__init__.py`. **Sources by rule family**: register layout, power-on values, memory maps, write protect, the hand-over states, the dot image and its priority example, the cell image (formula derived from the p.16 table), timer and stopwatch periods, interrupt levels, the font converter, the HINT vector -- Sega's hardware manual (DOC). The 1M swap request written as DMNA=0 -- the manual's main-side table and KRIKzz's notes agree (DOC). Mirrors of both register blocks and of the 4 MB area, SRES forcing SBRQ, the "8-bit register" byte-lane rule, pending-only-if-enabled and acknowledge-clears, the stamp transform order, 5 clocks a dot for the graphics unit -- ares (OBSERVED). First word of a word-RAM DMA = the 68000's prefetch, unowned word-RAM accesses reading 0 and dropping writes, reset button doing nothing to the CD -- HYPOTHESIS. **Gate**: 18 unit tests pass. mcd-verificator as BIOS: docs/status.md (10 of 13 rows OK). Experiments that did not move IRQ TEST's "127 ERROR 06": latching requests while masked, a timer period of n instead of n+1, restarting the 30.72 us divider on a timer write. Experiment that did not move WORD RAM's 20: DMNA reading 1 after a 2M-to-1M switch (KRIKzz's note read literally). A trace of the board's own register traffic in the IRQ test shows the timer at 127 (the printed number) and 128 level-2 requests; both IRQ TEST and WORD RAM spend long stretches in loops, so sub-CPU speed (wait states on PRG RAM and word RAM, which KRIKzz's loop counts show exist) is the leading suspicion: milestone 2's question. Speed: about 0.12 s a frame on PyPy with the sub CPU running. ## 2026-11-19, session 1 (continued): milestone 4 **Read** (permitted): the LC8950/LC8951 design manual (text extracted from the scan with pdftotext: Table 7, §11.3-11.4, Appendix E), forum t=3166's prose (KRIKzz's 5-bit register address; Mike Pavone's hardware results; Eke's X'Eye note), KRIKzz's drive logs, ares `cdc.cpp`, `cdc-transfer.cpp`, `cdd.cpp` (to line 560), `cdd-dac.cpp`, `pcm.cpp`, `gpu.cpp`, MAME's `rf5c68.cpp` (BSD-3). One MiSTer capture (`dma_pcm.jpg`) was opened but is unreadable at the scale shown; not used. **Built**: `cdc.py` (registers, decoder, host and DMA transfers), `cdd.py` (exchange HLE, drive model, CD-DA source, subcode placeholder), `pcm.py` (RF5C164), `wiring.py`. **Rule families and sources**: CDC register map, IFSTAT polarity, DBC, DTACK/STAT3 clearing -- LC8951 manual (DOC). 5-bit AR and regs 16-31 reading $FF -- KRIKzz (DOC, hardware prose). Buffer layout per block, DMA every 6 clocks, $FFFF with no data -- ares (OBSERVED). INT5 on the CDC's leading edge and a new edge per decoded block -- FITTED to the CDC INIT row (TEST ROM), HYPOTHESIS for the per-block edge. CDD status codes, report types, flags, pause loop, play = seek + resume -- KRIKzz notes (DOC). Spin-up 70 and TOC 100 exchanges, one-shot reports 3-5 -- FITTED to his Sonic CD boot log. Seek length -- ares (OBSERVED). Subcode INT6 with an empty buffer -- HYPOTHESIS (p.30 for the interrupt). PCM -- MAME rf5c68 and ares (OBSERVED); Sega's PCM manual is a scan without a text layer and was not read in this session. **Findings**: the CDC INIT row stalled with INT5 as a level (the row's handler never clears the CDC's flag); as an edge it passes. Your own BIOS (US v2.00W) reaches its title screen with no disc. The machine did not pickle (lambdas as hooks); replaced by a module-level function. ## 2026-11-19, session 1 (continued): booting your own BIOS **Found by running**: your own BIOS (US v2.00W) sat on its title screen, its sub program resetting the periphery every 1.4 M sub clocks. Logged register traffic, then disassembled about forty of its sub-CPU instructions from PRG RAM at run time (an interoperability look at the user's own firmware, recorded in provenance.md): after HOCK it accepts a stopped drive only as "00.000000.0F". KRIKzz's real-drive log (`BI-mcd-tst/bios-start.txt`, line 1) begins with exactly that exchange, so the first exchange after HOCK now reads so. The BIOS then paused the drive at the data track's start and waited: data blocks now reach the decoder while the drive loops paused, and the pregap blocks a BIN lacks are built with sync and header (ECMA-130). With those, Sonic CD (USA) reaches its licence screen at frame 2100. **Settled by the test ROM**: REG 2006 ($70 reads $FFFF), CDC REGS (DBCH bits 7-4 read 0). Confirmed: PCM DMA writes the word's high byte first (swapping breaks CDC DMA1). **Overlap**: one Sonic run was left going while a second started (two heavy runs for about ten minutes); noted here because the machine is shared. ## 2026-11-19, session 2: wave 2 continued (rows, backup RAM, mode 1, repin) **Read** (permitted): the rewrite rules, docs/restart.md, status, worklog, provenance; KRIKzz's `readme.txt` and `notes/random notes.txt` (prose); forum t2981 (Ti_'s speed test, prose and hardware numbers); the MiSTer repository's SignalTap captures as images (`int2_ack`, `pr_refresh_when_halt`, `dma_wordram*`, `dma_prgram_continue`, `dma_pcm_continue`); ares 9408cb4 `cdc-transfer.cpp`, `mcd.cpp` (to line 200), `bus-internal.cpp`, `bus-external.cpp` (ISC); MAME's `megacd.cpp` first lines (BSD-3, grep only); the BIOS manual's chapter 7 (pdftotext); megadev's `lib/sub/bram.h` and `bram.def.h` (MIT); megadrive-python's installed `board.py` and `system.py` (our own, for the access clock); m68000-python's `cpu.py` and `docs/interrupt-lifecycle.md`. **Found by logging the test ROM's traffic** (method in build-status.md): IRQ TEST's 127 was the counter cleared by a mailbox command that the sub CPU had not finished when the first of 128 level-2 interrupts came; WORD RAM's 20 was the sub CPU answering a write to main-owned word RAM (the hardware hangs, p.24), and 21 the hang not ending when the RAM is handed over; CDC FLAGS 22 was INT5 coming one word late in a main-CPU transfer. **Built**: IFL2 latency (gatearray.py), the word-RAM hang and its release (megacd.py), transfer end on the last latched word and per-destination DMA periods (cdc.py), the HINT override in mode 1 (megacd.py), `__setstate__` defaults for old pickles, `scripts/format_backup_ram.py`, 4 unit tests. pyproject repinned (megadrive-python b84d978, m68000-python 38dbd0f); `.venv-pypy-pin2` built at those revisions. **Ran**: the gates in status.md, session 2; Sonic CD into Palmtree Panic zone 1; mode 1 with mcd-verificator; Night Trap with sega32x-python 5c66906 in the slot. **Later in session 2** (same method): CDC DMA2 passed and DMA3 went 28 -> 62, CDC FLAGS 26 -> 34, through whole-word transfers, byte-wise PCM DMA, the latched word seen from the other CPU, DMA holds on word RAM and PRG RAM, DTEI kept across DTTRG, inserted block syncs, and a write to $A12008 taking a word (provenance.md has each rule's source). The LC8951 design manual was read again (pdftotext; CTRL1 SYIEN, the sync modes). **Tried and kept out**: DMA periods of 5 and 20 clocks a word, 2 to 40 for word RAM (no row moved); the write protect stopping the DMA (56); no new INT5 edge for a block while DTEI holds the pin (CDC FLAGS then hangs). **Overlap**: up to three board runs at once for about an hour (Sonic, mode 1, 32X). ## 2026-11-21: the save-state report, and a permanent save-state check **Report** (affd58d's message): a state saved at frame 450 of mcd-verificator (as BIOS, `--ram-cart`, Sonic CD (USA)) and loaded in a fresh process "runs ahead": at frame 900 the loaded run shows CDC DMA1 OK and "Diagnostics complete", the straight run is still in CDC DMA1. **Finding: not a save-state bug.** `--frames` after `--load-state` counts frames after the saved one, so a load at 450 with `--frames 900` ends at frame 1,350, and frame 1,350 of the straight run shows exactly that screen (the rows finish near 1,180). Run as `--frames 450` after the load, the two frame-900 states are identical in every value a pickle holds (142,685 values; on the current pins in `.venv-pypy-pin3` and on the old ones in `.venv-pypy`), and plane A reads the same. Whether the reporter typed `--frames 900` is inferred from the screen they describe, not seen. Per-frame digests of the whole machine (scratch harness, then the new check) also matched for fresh-process loads at frames 30 (to 40), 450 (to 900), 560 (to 1,250, past "Diagnostics complete") and 1,000 (to 1,250), and for a same-process load at 450. **Changed**: `__main__.py` now says which frames a loaded run covers ("loaded ... at frame 450; running frames 451-900") and `--frames`'s help says how it counts. **Added**: `tests/test_save_state.py` (slow) with `tests/savestate_check.py`: the verificator from power-on, saved after frame 450, then frames 451-600 straight, from a copy loaded in the same process and from the file loaded in a fresh process; every value pickle reaches (walked through `__reduce_ex__`, as pickle walks it) digested per component after every frame. A first walker that followed `__getstate__` reported a false difference: `pathlib.Path` keeps lazily filled caches that pickle leaves out. **Seeded faults** (each in a separate worktree, on the fresh-process half; Sonic CD in the drive): the CDD's place in its 1/75 s exchange dropped on load -- caught, frame 451 (`device.gate.cdd`, the old walker's label); the CDC's block-sync timer dropped on load -- caught, frame 451, 28 components; the gate array's in-flight IFL2 requests dropped on load -- not caught: none is in flight at the end of frame 450, so at this save point it is an equivalent mutant (a save point inside a request's 14-clock latency would see it: a recorded blind spot of this one save point); m68000-python 38dbd0f (an unpickled CPU without its dispatch table, `.venv-pypy-pin2`) -- caught, the fresh process fails with `AttributeError: ... '_table'`. **Ran** (`.venv-pypy-pin3`, PyPy 3.11.15, `PYPY_GC_NURSERY=1M`): unit tests 29 pass; the save-state check passes with Sonic CD in the drive and with none (about 5 minutes alone, 13-22 under the shared machine's load of ~80); mcd-verificator 1,600 frames: 16 of 18 (CDC FLAGS 34, CDC DMA3 62), unchanged. ## 2026-11-23, session 3: repin, save states on state version 2, referee, sound, drive **Read first** (all permitted): the family charter, methodology and agents.md; this repository's README, status, build-status, worklog, restart, validation, handoff brief; megadrive-python's `docs/save-states.md`, `state.py`, the diffs of `vdp.py`, `render.py` and `frontend.py` from 3e2325f to efd80fc, and its git log; m68000-python's `capture_state`/`restore_state`; Sega's PCM Sound Source manual (page images of the 1999 transcription, and p.14 of the scan at 600 dpi); docs/manual-registers.md's fader entry (p.31); KRIKzz's drive logs (data). No emulator source was opened; ares and MAME were not reopened; emu-tools-gpl was not opened. **Environments**: `.venv-pypy-pin4` (megadrive-python efd80fc, m68000-python 4454d54, z80-python b59c80b from the local clones; the sound cores and this repository editable). A scratch venv at megadrive-python 3e2325f (the old pin) for the before gate; `.venv-pypy-pin3` actually held 6303613, not the pinned 3e2325f (pip freeze), so the before gate was run on both. **Before** (3e2325f and 6303613): unit tests 29; mcd-verificator 1,600 frames 16 of 18 (CDC FLAGS 34, CDC DMA3 62), identical text on both; save-state check (pickles, Sonic CD in the drive) passed; drive-log replay 2,503 of 11,256; Sonic CD recipe: Palmtree Panic zone 1, timer running at 6,900-7,500. **Repin** to efd80fc: the 33 PNGs of the verificator run (every 50 frames) byte-identical to 3e2325f's. **Built**: `state.py` and `docs/save-states.md` (the CD's states on megadrive-python's version 2: the format, the borrowed encoder, the disc as a medium, the sub CPU as `sub68k`); the command line on it, drawing only the frames it writes; `docs/sockets.md` §12 (no socket for a device's state; proposal); `scripts/referee.py` and `scripts/compare_audio.py`; `scripts/cdd_seek_times.py` and the fitted seek times; the fader's gain from p.31; the PCM's docstring re-sourced to Sega's PCM manual; SPDX headers on seven files; the README's lineage line. **Found in the logs, not built** (for the drive's next step; build-status.md): during a seek the drive reports busy ("F") for its first exchanges (12 from ready), then a position every second or third exchange as it jumps, lands 12-15 sectors before the target and plays in, and shows the new state about 3 sectors before the target; after a seek or play it reports the absolute time (report 0) without being asked; the pause loop shows one or two busy exchanges at each jump back. Tried in a scratch copy and kept out: a busy exchange at the loop's jump (replay 2,630 -> 2,611) and report 0 after a seek (-> 2,437): each alone makes the replay worse, because the seek's own reports differ; the seek's visible structure has to come first. **After** (454caf6's code, `.venv-pypy-pin4`): unit tests 36; verificator 16 of 18 (ade0f08 and 454caf6); save-state check passed with Sonic CD (3 h 18 min under load) and with the drive empty (1 h 46 min); replay 2,630; seek-time mean miss 7.3; Sonic CD recipe unchanged into zone 1; referee 11 of 12 frames, CD-DA correlation 0.971, BIOS intro 0.928; seeded state faults 8 of 12 caught, 4 equivalent. Numbers in status.md. **Overlap**: the machine's load stood at 80-135 all session (other agents); my runs were up to four at once. ## 2026-11-24, session 4: the drive's visible seek; CDC FLAGS and CDC DMA3 **Read first** (all permitted): the family charter, methodology; this repository's README, status, build-status, worklog; KRIKzz's drive logs (data) and `notes/cdd-cmd-info.txt` (prose); the forum thread t=3166 (prose); the LC8950/LC8951 design manual (pdftotext, and pages 63 and 108 as images). No emulator source was opened; mcd-verificator was run only (its `src/` unopened, its binary not disassembled). **Method for the drive**: `scripts/replay_cdd_log.py` (exchanges identical, of 11,256) and `scripts/cdd_seek_times.py --model` (mean |hardware - model| over the 32 moves both time) after each step; a scratch script cut every logged seek into its phases (start busy, jumps, play-in, arrival) and counted them. | Step | Replay | Seek miss (mean, 32) | Kept | | --- | --- | --- | --- | | before (454caf6) | 2,630 | 7.34 | | | 1. the seek as a state machine: start busy with flags 1, jumps (a position, then busy), play-in, the new state 3 sectors early; total kept at the fitted arrival | 2,908 | 7.47 | yes | | 2. report 0 shown after every seek (seek.txt) | 2,831 | 7.47 | no | | 3. the paused loop: 8 sectors to 3 before the target, a jump back showing busy once or twice alternately (9 exchanges a loop); a pause's loop ends one past the shown sector | 2,997 (without 2) / 2,895 (with 2) | 7.16 | yes, without 2 | | 4. report 0 only for a seek from rest (KRIKzz's notes: seek "ressets toc to 0 if runs from stop state") | 2,895 | 7.16 | no | | 5. landing 14 sectors short (the logs' median) instead of 15 | 3,004 | 7.16 | yes | | 6. the first loop jump after an arrival showing busy once instead of twice | 3,002 | 7.16 | no | Why report 0 loses although seek.txt shows it: the model's arrival for that seek is 47 exchanges against the hardware's 32 (the same seek took 53 in seek-resume.txt), so shown positions land on exchanges where the hardware is busy; without report 0 the model shows busy there and matches. It is the right rule for the hardware and the wrong one for this metric until arrivals agree; recorded in `cdd.py` where it would go. **Found in the logs, not built** (drive behaviour outside the seek, each measurable by the replay): a request for report 5 is answered 3 exchanges later in state 9 (112 cases), not 1, and while playing or paused it stops the drive to state 9 with about 20 busy exchanges first (boot-log.txt line 251; KRIKzz's notes: report 5 "results stop playing"); reports 3-5 are not "shown once": the busy exchanges after them are the next request's latency (seek.txt shows report 4 for 70 exchanges); report 1 in a pregap reads one less than the distance to the track (lba -14 reads 00:00:13, lba -1 reads 00:00:00); stop (command 1) shows "0F" for 13 exchanges and then state 0, not 9; resume from pause shows three busy exchanges with state 4 and the playing flag, then positions from 02:31 still as state 4, and "playing" from 02:38, five sectors before where it was paused (02:43; read-pause-resume.txt lines 349-360); the first 3 start-busy exchanges of Sonic CD's seeks show the data flag (59), the rest 1D; the start busy runs 9 to 18 exchanges there against 12 in KRIKzz's own logs; the pickup's place after the TOC read varies (the first position reported after a seek from rest ranges from 00:56 to 18:51), which is most of the arrival-time spread. Four of these were tried in a scratch worktree on 9f16fe2 and not committed (they change your BIOS's boot, which would need the recipe and the referee again): report 5 after 2 busy exchanges in state 9, 3,004 -> 3,038; plus stop to state 0, 3,054; reports 3-5 shown on, 2,911; report 1 in a pregap one less, 3,033. **CDC FLAGS 34 -> 40** (LC8951 design manual §12.6, p.63, and appendix E, p.108, read as images): the decoder interrupt is a pulse, the INT pin low "About 2750" us with none of WRRQ/PRQ/QRQ set (1800 or 1500 in the decoding modes) and inactive at once when STAT3 is read or DECEN goes to 0. Built as such, with INT a level and no forced edge per block (cdc.py). Step 34 passes: the row leaves DTEI unacknowledged and a later block's pulse no longer brings INT5. The row now stops at "25. ERROR: 40": traced, the row starts a host transfer about 1,400 sub clocks after a block's INT5 without reading STAT3, so the transfer's DTEI comes while the decoder's pulse still holds INT low, and no INT5 comes. Mike Pavone (forum t=3166, prose) reports exactly "CDC FLAGS test 40 with a value of 25" on a Wondermega M1 and a Sega CD 2 (LC89515), and his LaserActive PAC has an LC8951; KRIKzz's CDX, which passes, has an LC8913 ("only a very basic datasheet"). So the board, built from the LC8951's manual, now fails where the LC8951 units fail: a revision row (CDX/LC8913 against LC8951/LC89515), not a bug to fit away. Passing it would need the LC8913's interrupt timing, for which there is no source. **CDC DMA3 62 -> OK**: traced from a state at frame 580. The row has the main CPU drain a 1,176-word host transfer by writing $A12008 (session 2's rule, 60), then sets up the same transfer for the sub CPU (DD=3), has the sub CPU write $FF8008 588 times, and reads $FF8008 through its mailbox: the words came from the block's start. A write to $FF8008 now takes a word as $A12008's does (gatearray.py; TEST ROM, mechanism HYPOTHESIS), and the row passes. **Built**: `cdd.py` (the seek structure, the paused loop, constants FITTED with counts from the logs), `cdc.py` (the decoder interrupt as the manual's pulse), `gatearray.py` ($FF8008 writes), two unit tests (the seek from rest against seek.txt's shape; the decoder interrupt's pulse and the level INT). **Ran**: see status.md, session 4. **Overlap**: the machine's load stood at 95-105 (32 cores) all session; up to five board runs at once. **Later the same day (coordinator's follow-up)**: report 5's latency and stop to state 0 applied on main and gated: replay 3,054 (4,076 as shown), unit tests 38, verificator 17 of 18, referee 12 of 12 (53 frames behind at the title), but the Sonic CD recipe's fixed presses no longer reach the running timer by frame 7,500 (the Palmtree Panic card, 0'00"00): not kept, reverted, recorded in build-status.md. `scripts/replay_cdd_log.py --as-shown` added (2740185, a measuring aid): per-step numbers in build-status.md; under it report 0 after a seek still lowers the count (4,076 -> 3,977). The `.venv` and `.venv-pypy` environments hold older megadrive-python pins without `state` (kept for comparison, build-status.md "Environments"); not refreshed. ## 2026-11-25: decisions B1 and B2 Aubrey approved B1 and B2 as recommended. Branch `drive-rules`: the reverted drive rules committed as the patch held them (820a703); replay 3,054 of 11,256 (4,076 as shown; stop.txt 215/215, stop-play.txt 164/164), as measured on 2026-11-24. The recipe's presses re-derived from save states (one process, `nice`, PyPy, nursery 1M): the attract film takes Start only at some moments (a 6-frame press starting at 4,830, 4,831 or 4,838 is missed; 4,826-4,844 otherwise end the film), and 4,830 had become one of the misses. New presses 4,834, 5,504, 6,204: Palmtree Panic zone 1, timer 0'00"88 at 6,900 to 0'10"88 at 7,500; once from power-on, byte-identical to the run from the state. Referee 12 of 12, 53 frames behind at the title; verificator 17 of 18; unit tests 43. B2's paragraph in status.md. Scratch runs (states, PNGs, contact sheets) stayed in the session's scratchpad. The machine's load was about 15 on 32 cores.