# Handoff: build `cps3-python`, the Capcom CP System III board ## Context you are inheriting The family's shape is **chips are cores, boards compose cores; never copy a chip file between repositories; CPUs always own a core; a non-CPU chip used by one machine stays in its board**. Each core is certified on its own and pinned by commit; each board is validated against the highest-tier oracle that exists, with MAME and other emulators as detectors only. Reference boards are correct, not fast. CPS-3 is a 32-bit arcade board (1996-1999, six games), outside the family's usual pre-32-bit line; Aubrey confirmed it is in scope. It embeds **one core**, already built for the 32X: - **`sh2-python`** (`/data/emu/sh2-python`, read-only here), the SH7604 with cache, BSC, INTC, DMAC, DIVU, FRT, WDT. **Pin `8755c3ae85ed9013a33f910019650475ccc69374`** (2026-11-05, the pin `sega32x-python` uses). Rungs 0-4 pass; it stopped for review before rung 5. It lacks one thing this board needs: a fetch filter for the cartridge's decryption ([sh2-core.md](sh2-core.md)). Read, in order, before writing code: 1. [README.md](../README.md): scope, what is fetched. 2. [start-here.md](start-here.md): the machine as data, clocks, the six games, module shape, speed. 3. [memory-map.md](memory-map.md): the CPU's view with the board's measured costs, interrupts. 4. [sh2-core.md](sh2-core.md): what the core must provide, the fetch filter specification. 5. [encryption.md](encryption.md), [boot.md](boot.md), [flash.md](flash.md): the cartridge, the BIOS, the SIMMs. 6. [video.md](video.md), [sound.md](sound.md), [eeprom.md](eeprom.md), [inputs.md](inputs.md), [scsi-cd.md](scsi-cd.md): the rest of the board. 7. [validation.md](validation.md): every oracle with tier and pin; what the one hardware-tier source can and cannot decide. 8. [mame-oracle.md](mame-oracle.md) and [census.md](census.md): the detector recipe; the sets. Then `python -I scripts/fetch_references.py --verify` (6 pinned files: Dunkley's paper, note and companion data, the WD33C93A data book, two operator's manuals; 6 repositories: MAME 0.285, FinalBurn Neo, jtcores with JTCPS3, the second FPGA core, the 3rd Strike decompilation, herzmx's dead-cart table). `reference/` is git-ignored; ROMs, CHDs and BIOS images are bring-your-own and read in place. ## Decided - **Aubrey:** CPS-3 is in scope (2026-11-11). - **The family's rules:** Python 3.11 floor, PyPy must work, ruff `py311`; modern over compat; never copy code from a sibling, pin it; nothing third-party committed; no hardware probes. - **This phase:** compare pictures at the 17-bit colour-index level (palette bank + pixel, before colour RAM), never at RGB; the board owns time; the six games are rows of data, not classes. ## Scope In: the main board 95682A-3/-4 (PPU, CCU, IOU, SSU, GLL1, GLL2 behaviour as far as it can be known), the security cartridge (BIOS flash, key pair, three decryption modes), flash SIMMs 1-7, the SCSI controller with a CD target, the 16-voice sample player, the score-screen layer, the EEPROM window, JAMMA and kick-harness inputs. The six games, all regions, CD and NO CD. Out (for now): the 24 kHz mode (unused by the games), the RS-232/SRAM/battery parts of early -2 boards, the FM1208S beyond a stub, bootleg multi-game CDs (open decision 8), the Darksoft kit. ## Names and module shape (open decision 1) Repository `cps3-python`; **package `cps3`** as the task named it (the family's other packages are `_python`: `sh2_python`, `pcengine_python`; decision 1). Classes: ``` cps3/ machine.py Machine (one frozen dataclass per game: key pair, mode, SIMM population, inputs profile) board.py CPS3: owns the timeline, address decode, IRL lines, save state; embeds sh2_python.SH7604 cartridge.py SecurityCart: BIOS bytes, key1/key2, mode (LIVE, DEAD, NONE), mask(), read_filter(), fetch_filter() simm.py Flash29F016A, Simm (4 or 8 chips, byte lanes), GraphicsFlash (the bank window + linear view) dma.py Gll1: character DMA (modes 0, 2, 3, table), palette DMA with fade, sprite-list latch, status, IRQ10 ppu.py Ppu: registers, CRTC, list walk, tilemap lines, zoom, alpha, the index buffer, full-screen zoom ssu.py Ssu: score-screen layer and registers; SampleVoices: the 16 voices io.py Iou: inputs, outputs, development switches, the EEPROM window (Eeprom93C46 behind it) scsi.py Wd33c93a (indirect mode), ScsiCdTarget disc.py BIN/CUE image reader (open decision 6) ``` ## Import boundary | Owned by `sh2-python` (pinned) | Owned by this board | | --- | --- | | SH7604: instruction set, pipeline, cache (incl. data array as RAM), BSC (widths, waits, write buffer, idle cycles), INTC (IRL, auto-vectors, priorities), FRT, DMAC, DIVU, WDT | everything outside the CPU package: address decode, per-device WAIT states, the cipher (data side in `read`, fetch side through the filter), IRL 12/10 sources and acknowledges, all ASIC behaviour, flash, SCSI, EEPROM, inputs, sound, video | | **New, requested:** `chip.fetch_filter(address, longword) -> longword` ([sh2-core.md](sh2-core.md)) | the filter's body (a `SecurityCart` method) | The board calls the core through its documented contract: `SH7604(read, write)`, one call per external bus cycle with `kind` bits (`FETCH`, `FILL`, `THROUGH`, `DMA`, ...), `chip.clock` and `chip.wait` inside the callback, `chip.irl` for the external level. DMAC cycles (`kind & DMA`) bypass decryption. GLL1's "DMA" is the board's, not the SH-2's. ## Sockets (internal interfaces, each with a test fake) The Sega pattern (base board + add-on boards) has no add-on to serve here; the sockets are the board's replaceable parts, defined in M0 so tests can fake them: | Socket | Protocol | Real implementation | Fake | | --- | --- | --- | --- | | Cartridge slot (CN5) | `bios: bytes`, `mode`, `mask(address)`, `read_filter`, `fetch_filter` | `SecurityCart` from a BIOS image and the machine row | plain BIOS, mode `NONE` | | SIMM slots 1-7 | `read(offset, width)`, `write`, `chips` | `Simm` of `Flash29F016A` | `bytes`-backed read-only SIMM | | SCSI port (CN6) | target: `select`, command phase, data phase, status | `ScsiCdTarget` over a disc image | "no device" (selection timeout) and "not ready" | | JAMMA + kick harness (CN1) | `inputs() -> (u32, u32)`, `outputs(value)` | host input | scripted per frame | | Video out | index buffer per frame + colour RAM | host window or PNG | hash per frame | | Audio out | stereo samples at 37,286.9 Hz | host audio or WAV | hash per frame | ## Chip rule | Chip | Other users in or near the family | Proposal | | --- | --- | --- | | SH7604 (SH-2) | 32X (`sega32x-python`), Saturn later | core, exists | | PPU, CCU, IOU, GLL1, GLL2 (DL-2729 ... DL-3529) | CPS-3 only | in the board | | SSU (DL-3329): sample voices + score-screen layer | CPS-3 only | in the board | | WD33C93A | many machines in MAME; no family board plans one | in the board; extract only if a second family board needs it | | Fujitsu 29F016A, 29F400TA | no other family board (`cps2-python` has none) | in the board | | 93C46 EEPROM | `cps2-python` (serial, 16-bit mode); here hidden behind the IOU's word window, serial protocol not visible | in the board; no split (open decision 12) | ## The milestones, with their judges A milestone closes when its exit holds and its undecidable items are written in the certification record as "provisional, tier N". | # | Milestone | Judge (tier) | Exit test | | --- | --- | --- | --- | | **M0** | **Skeleton**: `CPS3` with the address map, SH7604 embedded at the pin, the sockets and fakes, VBlank IRQ12 and its acknowledge, the `cps3boot` BIOS (mode `NONE`, no cipher) from reset | MAME instruction stream (5) | the first 200,000 instructions of `cps3boot` register-exact against `scripts/mame_trace.py cps3boot` (R0, R15, PR, SR per instruction), 0 unexplained (`cps3boot` was not run on MAME in Phase 0; if its BIOS stalls early, use `redearthnr1` with the M1 cipher instead) | | **M1** | **The cartridge**: the mask, three modes, `read_filter` and `fetch_filter`; the filter merged on sh2-python (open decision 3) and repinned | software fact: the BIOS images (the check already ran) | all six games' BIOS decrypt to PC `00000400`, SP `02080000`; 2nd Impact's SIMM 1 vector table reads plain; a unit test executes a routine from `C0000000` stored encrypted for its address, in LIVE and DEAD modes | | **M2** | **BIOS to the game, NO CD**: inputs (all released), development switches all ones, EEPROM window, DMA status bits idle, sprite-list latch status, SIMM 1 read | MAME (5) | `redearthnr1` from reset: register-exact against MAME until the first jump into `06000000` and for 1 M instructions after; then PC and SR equal at every VBlank entry for 8 emulated seconds | | **M3** | **Flash and EEPROM**: `Flash29F016A` read, autoselect, program, sector and chip erase, status; the 93C46 window | Fujitsu data sheet (2) if pinned, else MAME's `intelfsh.cpp` (5) | command-sequence unit tests from the data sheet (or MAME, marked provisional); with a blank EEPROM `redearthnr1` writes the same 64 words MAME writes | | **M4** | **Score-screen layer and the memory test**: SS RAM odd bytes, SS registers, tile bit 8 in the attribute, the text layer drawn on top | DP 8.1 (1, one board) for the width; the BIOS memory test (software fact); MAME for pixels (5) | the test menu's memory check reports every RAM OK; a longword read of SS RAM returns `00xx00xx`; the text layer's index image equals MAME's on the test menu | | **M5** | **Character DMA**: command list, modes 0, 2, 3, the table, the CPU window and bank, IRQ10 **once per completed batch** | DP 7.1 (1) for the interrupt rule; MAME (5) for the formats | character RAM byte-identical with MAME's after the attract of three games (Red Earth for mode 0; mode 3 by a unit test from a captured list); IRQ10 count per frame equals the batch count in every frame | | **M6** | **Palette**: colour RAM, palette DMA, fade modes | MAME (5) | colour RAM identical with MAME's at 20 frames across the six games; fade unit tests from MAME's arithmetic, provisional | | **M7** | **Tilemaps**: width-0 sub-entries, four maps, line scroll, flips | MAME (5) | index buffer equal to MAME's (before palette lookup) on 10 chosen frames with tilemaps | | **M8** | **Sprites**: list walk, sub-lists, global scrolls, zoom and its rounding, alpha, 6/8 bpp, list order as priority; the latch at VBlank N+1 shown in frame N+2 | MAME (5); DP 7.4 for the latch cost (1) | the six games' title and attract frames equal MAME's index buffer, or every differing pixel named (U4: MAME's own placement is "imperfect") | | **M9** | **Full-screen zoom, CRTC, wide mode** | MAME (5) | SFIII's zoomed intro frames and the wide mode equal MAME's; C2 (495 vs 496) decided by what the game programs | | **M10** | **Sound**: 16 voices, loop, volume, key on/off | MAME `cps3_a.cpp` (5) | the same register writes give MAME's stream sample for sample at 37,286.9 Hz over 30 s of three games, or differences named; provisional, tier 5 | | **M11** | **Board timing**: per-device WAIT states to DP tables 3 and 6, BIOS 8-bit bus, IRQ10 on completion only, no idle shortcut, the cache on (core) | DP P1/P2 loops (1, one board) | DP's device loops (P1 B03-B23, B33-B36) rebuilt from the companion's bodies run on the board within 2% of the board's ticks; the IRQ10 rule holds; in 3rd Strike's attract the IRQ10 service delays fall in two bands about 65 ticks apart (informational: the probe image is not available) | | **M12** | **CD boot and flashing**: WD33C93A, SCSI CD target, ISO reads, the BIOS flashing a blank board | WD data book (2); MAME with `wd33c9x` logging (5); the result (software fact) | `sfiii` from blank SIMMs to its game with the CD: the flashed SIMMs equal `sfiiin`'s chip images byte for byte (the CD check of [boot.md](boot.md)); one CD per BIOS family | | **M13** | **The six games to gameplay**: pre-flashed SIMMs for CD sets, save states, a play window | MAME (5) at VBlank boundaries | every NO CD set and one CD set per game reaches a fight with scripted inputs; PC/SR at VBlank equal to MAME's for 600 frames with board timing off (instruction-table mode), 0 unexplained | Build note: the bus-cost model of M11 is a table of per-device WAIT states consulted in the `read`/`write` callbacks. Put the hook in at M0 with zeros, so every earlier lockstep runs in "MAME timing" and M11 only fills the table. Lockstep against MAME stops being cycle-exact from M11 on; compare at VBlank entries. ## Unknowns (U) | # | Unknown | Best source / tier | Status | | --- | --- | --- | --- | | U1 | Character and palette DMA transfer rate; whether any game waits on it | DP: at least 8.5 decompressed bytes/µs (1, a bound); MAME: instant + 100 µs (5) | provisional: complete at the kick, IRQ10 at the rate bound or MAME's delay (M5, M11) | | U2 | Where the cipher sits relative to the cache; which partitions a dead cart decrypts (cached `06`, cache-through `26`) | MAME (5), JTCPS3 cache module (4), herzmx (3, second-hand) | the fetch filter, decode side; cache-through fetches open | | U3 | The region and NO CD bytes in the BIOS | MAME "two different bytes" (5) | find by diffing BIOS images (cheap; not done) | | U4 | Sprite zoom rounding and placement | MAME: "imperfect", gaps on hardware too (5) | follow MAME, provisional | | U5 | How the BIOS utility menu is entered on a production cartridge | BIOS strings (fact) | not needed | | U6 | Whether the other ten game discs follow the SFIII file pattern | sizes agree ([census.md](census.md)) | open one per game at M12 | | U7 | Whether a CD BIOS with correct SIMMs needs a drive or disc present | MAME notes (5) | M12; a "not ready" target fake | | U8 | Flash program/erase timing, status bits, whether the BIOS reads IDs at boot | no data sheet pinned | M3 | | U9 | The `400000` offset of linear graphics addresses | MAME `TODO` (5) | follow MAME | | U10 | WD33C93A clock source, INT and DRQ wiring | data book (2) for the part; board unknown | M12; read the BIOS's Own ID write | | U11 | CHD codecs actually used | `chdman info -v` (ran) | **answered**: FLAC in two game discs and all bootleg discs | | U12 | Whether colour RAM is read when drawing or at scan-out; where the picture buffer lives | none above tier 4 (C1, C15) | MAME's choice (scan-out), provisional | | U13 | Alpha: OR into the index or replace bits | MAME: "both produce same results in games" (5) | OR, provisional | | U14 | Tilemap line zoom | MAME: unused or untested (5) | implement as MAME; untested | | U15 | Fade arithmetic exactness | MAME "Is this 100% correct?" (5) | provisional | | U16 | Full-screen zoom range; registers `68`-`6C`, `78`-`7C` | MAME clamp at `80`, "don't know if accurate" (5) | provisional | | U17 | Which games use the wide mode; the pixel-clock bits of `80` | MAME (5) | check in M9 | | U18 | `05000A00-1F` development switches | MAME: must read all ones (5) | all ones | | U19 | What raises IRL levels 14 and 6; 3rd Strike installs a level-14 handler | decompilation (fact), MAME "unused" (5) | never raised; log any acknowledge | | U20 | `07FF0048` bit 0 during programming; `07FF0000-08` writes | MAME (5) | log only | | U21 | The FM1208S and `03000000-030003FF` | MAME: purpose unknown (5) | 1 KiB odd-byte RAM stub | | U22 | Writes nobody maps: `05000A20/24`, `05000C00-18`, `05150000`, `07FF000C` | MAME logs (ran) | log only | | U23 | Whether the games arm the on-chip WDT | not checked | check in M2 traces | | U24 | Sound longwords 5 and 6 (one is probably loop end) | MAME (5) | as MAME | | U25 | The sound write at `0x210` during boot | MAME (5) | ignore, log | | U26 | Mixing gain, clipping, interpolation, the true output rate | MAME (5) | as MAME | | U27 | EEPROM busy time, erase-before-write | MAME (5) | never busy | | U28 | Where the volume buttons are read | MAME (5) | not needed | | U29 | A bus cycle that never ends (read past work RAM) | DP 8.3 (1, inferred mechanism) | raise a board fault ("hung") rather than return a value; needs no core change | | U30 | Whether fetches from work RAM (or anywhere but BIOS, SIMMs, data array) are decrypted | none (MAME has no opcode view there) | plain | | U31 | PPU registers `84`, `8A`, `8E` (DMA interrupt enables?) and SS register `13` | MAME "??" (5) | store, ignore | ## Contradictions (C) | # | Sources disagree on | Sides | Decision | | --- | --- | --- | --- | | C1 | Frame buffer or line renderer | the task's premise and the second FPGA core: lines; DP 11, JTCPS3, MAME: a buffer. Evidence: one second-hand latency measurement (2.58 frames) that excludes only drawing the N+1-latched list during frame N+1 | **not decided**; model the observable (list latched at N+1, shown in N+2) as MAME does ([video.md](video.md)) | | C2 | Wide-mode width | MAME's register arithmetic 613 − 118 = 495; MAME's comment and common knowledge 496 | follow the registers; check what the game writes (M9) | | C3 | Refresh rate | 59.5995 nominal (crystals); 59.604 ± 0.011 measured on one cabinet; 59.583 often quoted; JTCPS3 59.637; second core 59.5637; Fightcade 60 | nominal from the crystals; the measured value is one cart in one board | | C4 | The CPU | "HD6417099 variant" (decap) and "SH7010-series (SH7014)" in the same MAME notes; emulated as SH7604; replaced in the field by HD6417604 or HD6417095 | SH7604 (the board's measurements fit its manual) | | C5 | When IRQ10 is raised | on completion only (DP, board); 100 µs after the request (MAME, second core); also periodically (FBNeo) | on completion (DP) | | C6 | Flashing time | 15-20 min (1997 BIOS text); 25-30 min (MAME notes); the 1999 BIOS computes an estimate | not needed; record both | | C7 | FRT period | OCRA + 1 (manual, DP, JTCPS3's model); OCRA (MAME, FBNeo) | OCRA + 1: a core matter (sh2-python rung 5) | | C8 | Dead cartridge | MAME's comment: 2nd Impact SIMMs plain "code&data"; MAME's code, JTCPS3, herzmx: fetches decrypted with key 0, data plain | the code's behaviour ([encryption.md](encryption.md)) | | C9 | SS RAM width | 8-bit, odd bytes (DP board, MAME's lane mask, both FPGA cores); 32-bit cells (FBNeo); MAME's comment "only even bytes" | odd bytes, 8 bits | | C10 | Where samples live | "on SIMM 3" (the task's premise); MAME: one linear space over SIMMs 3-7 | linear space | | C11 | FPGA implementations | "none exists" (common knowledge); JTCPS3 (jotego, 2026) and javi-ivaj's core exist | they exist; both tier 4, one derived from MAME | | C12 | A sound interrupt | the task's premise; no source describes one; 3rd Strike calls its sound driver from VBlank but handles an unexplained level 14 | no sound interrupt; level 14 is U19 | | C13 | The EEPROM | a serial 93C46 on the board; the CPU sees a word-wide window | model the window (MAME); the IOU's serial sequence is not visible | | C14 | Sprite-list latch time | MAME clears status after 4 µs; DP: under one tick (2.6 µs) | compatible; latch at once, status clear within one tick | | C15 | The PPU's four 1M×16 DRAMs | MAME's board notes and the test-mode memory check: "Character RAM" (8 MiB, the size the DMA fills); JTCPS3's schematics: "MEMORIES FRAME BUFFER" (a draft sheet adds "?") | character RAM (the memory test names it, and the DMA needs 8 MiB); the schematics' label is an interpretation | ## What was not verified in Phase 0 - Every register layout in [video.md](video.md), [sound.md](sound.md), [eeprom.md](eeprom.md), [inputs.md](inputs.md), [flash.md](flash.md) is MAME's, copied with its own doubts (tier 5). Spot-checked against the code: the SS RAM layout, the alpha rule, the character-DMA command word, the flash bank register, the input bits, the interrupt sources. - The board parts list is MAME's notes. - Dunkley's model is not available to run; its probe images are not distributed. - No CD other than `cap-sf3-3` was opened; no CD set was flashed to the end; no SCSI command list was captured. - No picture or sound was compared with anything. - DP's companion `verify.py` was not executed (fetched code). ## Open decisions for Aubrey **Decided by Aubrey on 2026-11-12** (recorded after a walk through all fourteen Phase 0 briefs): - The Python package is `cps3_python` (family rule set the same day: a repository `x-python` always imports as `x_python`); read any other package name in these documents as that. - Decision 3: the fetch filter on sh2-python is **approved** as an issue or PR on that core. Decision 9: the six key pairs stay in the repository as data, source cited; the board is private. - Decision 12 stands: this board does not use the shared 93Cxx EEPROM core, since its CPU never sees the serial protocol. - Referees built from die-derived material are built just before the rung that needs them, not up front. - Outside contacts proposed below are **deferred until the core or board exists**; Aubrey sends them himself, from a draft. - Remote: local through Phase 0; after the first passing rung or milestone, a private GitHub remote (going public later is a separate decision). Where a recommendation below names a different point, this replaces it. - Every other recommendation below is **accepted as written** unless a line here says otherwise. 1. **Package name.** The task named the package `cps3`; the family's packages are `_python` (`sh2_python`, `pcengine_python`). *Recommend `cps3_python`* for uniformity with the pins and imports of every other repository; keep `cps3` if the shorter name was meant. 2. **Pre-flashed SIMMs first, CD later.** *Recommend yes*: NO CD sets load chip images; CD sets get their SIMMs built from the CD's files by byte lane (checked for one disc); booting a blank board from the CD is M12, run once per BIOS family. Flashing in pure Python would take hours. 3. **The fetch filter's shape on sh2-python.** *Recommend* `chip.fetch_filter(address, longword) -> longword`, default `None`, applied in `_read_fetch` after the cache, bus or data array, with the full 32-bit address, fetches only ([sh2-core.md](sh2-core.md)). A `fetch_mask(address)` variant is acceptable if the core's owner prefers. Raised as a PR on sh2-python with its own tests (core quality of life), recertify, repin. 4. **The core's PyPy speed.** 252,000 instructions/s on PyPy, 160,000 on CPython, against 8-12 M needed: 30-75 times slower than real time. *Recommend* accepting it for the reference board (it is correct, not fast) and opening an issue on sh2-python for the PyPy attribute count (91 > 80) and the JIT drop after the scheduler; speed belongs to a later `-fast` sibling. 5. **First game.** *Recommend* `redearthnr1` (NO CD, smallest at 44 MiB of SIMMs, live key, mode 0 DMA on stage start, present in two libraries, runs in MAME here), then `sfiiin` (mode 3 DMA), then `sfiii2n` (dead-cart mode). 6. **Disc images.** *Recommend* BIN/CUE made once with `chdman extractcd` into a git-ignored directory, as segacd-python reads Redump BIN/CUE today. A native CHD reader needs FLAC as well as LZMA and Deflate (two game discs and every bootleg disc have FLAC hunks); if the family wants one, make it shared with `segacd-python` and `pcenginecd-python`, decided there. 7. **Board timing in the first build or later.** *Recommend* later (M11), with the per-device cost hook in place from M0 at zero, so M0-M10 lockstep with MAME cycle for cycle. 8. **Dead-cart and bootleg sets.** *Recommend* dead-cart mode in scope (2nd Impact needs it); the `cps3boot` BIOS image in scope as M0's cipher-free target; the multi-game bootleg CDs out. 9. **Keys in the repository.** The six key pairs are twelve published numbers (MAME, BSD-3-Clause, and in every CPS-3 emulator). *Recommend* keeping them in `machine.py` as data with their source, not asking the user for them. 10. **Remote.** *Recommend* a private GitHub remote when M2 passes (family rule: remotes as needed, private by default), public with the other boards' policy after M8. 11. **Asking Dunkley and XeD for the unrun probes** (DMA brackets, display-layer flashes, the probe on a dead cartridge, which would settle U1, C1 and U2). *Recommend* not now; after M11 the board can offer them a second implementation to test against. Any post names the Claude model (family rule). 12. **The 93C46.** `cps2-python` also has one, as a serial device. *Recommend* no shared chip: the CPS-3 CPU never sees the serial protocol, only the IOU's word window.