# Handoff: build `cps1-python`, the Capcom CP System board ## Context you are inheriting The family's shape: **chips are cores, boards compose cores; never copy a file between repositories; a non-CPU chip gets its own repository only when a second emulator uses it**. Python is the readable reference; correct, not fast; PyPy must work (floor 3.11). This board embeds two CPU cores and three chip cores: - `m68000-python` (`/data/emu/m68000-python`), **pin `3029f56`** (v0.1.0): has `set_ipl`, an `acknowledge(level)` callback returning `AUTOVECTOR`, the E-clock wait of autovectored acknowledges, `function_codes=True`, and `step_clocks` for placing host stalls. It models no wait states and no bus arbitration; the board adds both ([interrupts.md](interrupts.md)). - `z80-python` (`/data/emu/z80-python`), **pin `b62891b`** (origin/main, the pin megadrive-python uses; the local `main` branch has diverged and is not a descendant). Needs one addition for Kabuki: a `read_opcode` hook ([sound.md](sound.md), open decision 8). - `ym2151-python`, `msm6295-python`, `dsp16-python`: Phase 0s in parallel (read-only). The msm6295 Phase 0 is complete (its `docs/handoff-brief.md`, `docs/bus.md`, `docs/census.md`). - `megadrive-python` is the model of a 68000 + Z80 board: one scheduler in master clocks, the 68000 drives, the Z80 catches up; `docs/expansion-sockets.md` is the socket pattern. Read, in order: [start-here.md](start-here.md), [memory-map.md](memory-map.md), [interrupts.md](interrupts.md), [cps-a.md](cps-a.md), [cps-b.md](cps-b.md), [gfx-mapping.md](gfx-mapping.md), [sound.md](sound.md), [inputs.md](inputs.md), [sockets.md](sockets.md), [quirks.md](quirks.md), [cps2-sharing.md](cps2-sharing.md), [census.md](census.md), [validation.md](validation.md), [mame-oracle.md](mame-oracle.md). Then `python -I scripts/fetch_references.py --verify` (11 repositories by commit). ## Decided - **Aubrey: QSound is the real DSP program (`dl-1425.bin`) run on `dsp16-python`, low-level.** An HLE is at most a later speed option, proven sample-equal first. - From the task: the CPS-1 family is **one board with each game's configuration as data**; bootlegs and Mitchell boards out of scope; the CPS Changer is a machine row; Forgotten Worlds' dial and the 3/4-player boards are in. - Family rules: reference boards are correct, not fast; never copy code; BYO ROMs, read in place. ## Scope, package, classes Repository `cps1-python`, package **`cps1`**. Proposed classes: `CPS1` (the board and scheduler), `Machine` (a row: sockets' choices, [sockets.md](sockets.md)), `CPSA` and `CPSB` with `CPSBConfig` rows in the subpackage **`cps1.video`** (importing nothing else from `cps1`: the future shared package, [cps2-sharing.md](cps2-sharing.md)), `ObjectFrameBuffer` (CPS-1's sprite path), `Mapper` (from fuse maps: `cps1.pal` evaluates GAL16V8 images; `scripts/decode_gal16v8.py` and `scripts/check_pal_mapper.py` are the prototypes), `StandardSound`, `QSoundSound`, `kabuki` (a pure decode module), `uPD4701`, `M48T35`, and the 93C46 (where: open decision 3). **The import boundary**: the cores own instruction execution and their own chip state; the board owns every address decode, the wait states, the CPS-A bus requests (as 68000 stall time), the interrupt lines and acknowledge, the latches and banks, the clocks and their ratios, mixing, the mapper, Kabuki's decode (the core only offers the opcode-read hook). ## Facts this Phase 0 established (and where common knowledge was wrong) 1. **The mapper PALs can be executed from the dumps.** The ROM sets' 279-byte GAL16V8 images decode to MAME's quoted A-board equations exactly, and with the pin wiring read from Capcom's 89624B-3 schematic, ten B-board mapper PALs reproduce MAME's tile ranges boundary for boundary. The wiring is per B-board type; only one type's schematic is in hand (U15). 2. **Every CPS-B-21 row has an independent witness** (Cruz's keys decoded with the die's key layout); **no DL-0411 row does** besides the games' own use of it. 3. **MAME's multi-bit layer-enable masks are not what the chip does**: the B-21 selects one LAYER-CTRL bit per layer (C2). 4. **MAME's three "unknown" B-21 registers are MULT-TC, CHECK1 and CHECK2**; the published keys are synthesised with CHECK disabled, so no genuine CHECK data exists outside game code. 5. **MAME's 68000 runs faster than the board**: one wait state per bus cycle (PAL) plus about 10% of each frame taken by the CPS-A's bus requests (15% with a palette copy). 6. **The palette DMA**: the die text's "`0x1800` strobes" (1.5 ms) against a board measurement of 780.4 us; `0xC00` words at 4 MHz is 768 us (C4). 7. **Kabuki is on all five QSound parents and `wofch`** (four keys), not "four games". 8. **The OKI rate is the data sheet's clock/132 or clock/165**; a "/164" (6,097.5 Hz) figure circulates from a comment in jt6295. 9. **The only measured CPS-1 frame rate is 59.61 Hz** (one 2008 report); 59.637 is arithmetic (C10). 10. The die trace is detailed enough (about 2,500 + 2,200 placed standard cells, with a cell library) that a **gate-level simulation could become a tier-1 referee**; nobody has built one (open decision 6). ## Milestones | # | Milestone | Judge | Exit test | | --- | --- | --- | --- | | **M0** | **Scaffold and data**: `pyproject.toml` (3.11, PyPy), pins, the per-set data generated from `-listxml` (load layouts, SHA-1s, CPS-B row, mapper, clock), the GAL16V8 evaluator as `cps1.pal`, the sockets with fakes | `mame -verifyroms` (hashes); the fuse maps | all 168 local sets load and verify by SHA-1; `cps1.pal` reproduces PRG1/IOA1 and the ten 89624B-3 mappers ([gfx-mapping.md](gfx-mapping.md)) as tests | | **M1** | **68000 side**: memory map with PAL decode and mirrors, `/ONE WAIT`, IPL1/IPL2 + acknowledge, inputs and DIPs, latches (Z80 stubbed), CPS-A/CPS-B registers as storage, raster counters' line/frame timing | PAL equations (1); MAME traces (5) | MAME lockstep on `ffight` and `pnickj` for 5 seconds: instruction stream and every I/O value equal, cycle counts excluded, 0 unexplained divergences; **every one of the 37 parents passes its own CPS-B ID check** (G evidence) | | **M2** | **Tilemaps and palette**: CPS-A SRAM refill schedule, scroll 1/2/3, row scroll, stars, palette copy on base write with the page quirk and bit 0, CPS-B mixing, priority masks, layer enables as single-bit selects | die documents (1) | 10 parents' attract frames equal to MAME at the 16-bit palette word except where a Q-entry explains it (written per frame); Magic Sword's video-control values (Q10) behave as the board tests say | | **M3** | **Objects and bus timing**: object job one tile per line, frame buffer double-buffering, 256-tile limit, bus requests as 68000 stall time, mapper from fuse maps for every set whose B-board wiring is known (MAME table otherwise, flagged) | die (1); jtcps measurements (1) | all 37 parents' attract mode compared with MAME frame by frame, every difference explained; the palette DMA and per-line request durations within 2% of jtcps's figures in a synthetic test; mapper-from-PAL equals MAME for every set where both exist | | **M4** | **Standard sound**: Z80 map, bank, latches, pin 7, YM2151 and MSM6295 cores, mixing | sibling cores' certifications; MAME `YW` traces | Z80 lockstep and YM/OKI register streams equal to MAME's for 5 games over 10 s | | **M5** | **Security and odd boards**: CPS-ID read counter, CHECK lock-out (data per row: open decision 11), raster IRQ (Ganbare, Puchi Monster), M48T35, Pang! 3 decryption + 93C46 + Mach215, Forgotten Worlds dial, 3/4-player and 6-button ports | die (1); MAME | all 166 "good" sets reach attract mode; 3 Wonders runs its CHECK with no lock-out; a deliberately wrong CHECK blanks the palette 64 frames later | | **M6** | **QSound**: `read_opcode` in z80-python (merged upstream), Kabuki decode, D-board map, 250 Hz IRQ, the QSound device on `dsp16-python` | the DSP program (Capcom's); MAME LLE (`vgmplay`) as detector | Kabuki: the decoded opcode/data images equal MAME's for all four keys; Z80 lockstep with MAME on `wof` 10 s; DSP output sample-equal to the dsp16 referee on a recorded host-write list | | **M7** | **Changer rows, timing gate, sweep, extraction** | jtcps loop count (1, if the test ROM is found: U22) | Changer sets boot; full sweep of 168 sets triaged; `cps1.video` extracted to the shared package at the cps2 trigger ([cps2-sharing.md](cps2-sharing.md)) | A milestone is closed when its exit holds and each undecidable item is written as "provisional, tier N". Smoke sets (curated, before any full sweep): ffight, pnickj, sf2, 3wonders, msword, strider (stars), forgottn (dial, stars), captcomm (4 players), ganbare (raster), pang3, wof. **Speed**: not measured (nothing exists). megadrive-python runs a 7.67 MHz 68000 well under real time on PyPy; this board's 68000 is 10-12 MHz with a 384 x 224 picture and per-line CPS-A work, so expect several times slower than real time; QSound games far slower (a DSP16A executing about 30 M instructions a second). Reference boards are allowed to be slow; `-fast` is a later project. ## Unknowns (U) | # | Unknown | Best source / tier | Status | | --- | --- | --- | --- | | U1 | Mirrors: I/O every 512 bytes through `800000-8FFFFF`, work RAM through `FC0000`; does any game depend on them | PAL (1) says they exist | implement the PAL's decode; MAME has none, FBNeo some | | U2 | What a read of a write-only CPS-A register returns (Pnickies does it) | none | open bus = last value on the bus; provisional | | U3 | QSound D-board: PALs not decoded, shared-RAM arbitration, the 250 Hz source | fuse maps in the sets (1) | decode at M6 | | U4 | Pang! 3's upper 96 KiB of sound EPROM | MAME ignores it | follow MAME | | U5 | The CPS Changer's own hardware (outputs, ports, region, boot) | none found | machine row | | U6 | Coin-control bit 15 ("CPS-A custom reset?") | MAME comment | ignore, log writes | | U7 | Power-on contents of RAMs, CPS-A/B registers, frame buffer | none | fixed values with a seed option | | U8 | When the object list is read across the frame; which tiles drop past 256 | die ("work-in-progress") | provisional; M3 | | U9 | The brightness DAC's transfer curve | resistor values (jtcps), two formulas within 3% | compare at the palette word; RGB for display only | | U10 | Palette copy length (`0x1800` "strobes" vs 780.4 us) | C4 | follow the measurement | | U11 | Mixer output when every layer is transparent | MAME uses `0xBFF` | follow MAME, provisional | | U12 | MULT-TC's function | die key layout names it | storage only | | U13 | Genuine CHECK1/CHECK2 data per game | game code (3 Wonders known) | open decision 11 | | U14 | Raster counter details (RASTER1 bit 0, the MSB behaviour) | die ("more work must be done"), MAME | MAME's model, provisional | | U15 | B-board wiring of the mapper PAL for types other than 89624B-3; which `/CE` reaches which sockets | schematics (only one in hand) | find schematics or derive wiring by matching MAME ranges | | U16 | Which sets really ran at 12 MHz | MAME's assignment | follow MAME | | U17 | Controls hardware: connector pin-out, uPD4701 data sheet | schematics (unread for this), NEC | read before M5 | | U18 | Pang! 3's Mach215 "kick" behaviour | MAME comment | not modelled, logged | | U19 | Audio mixing levels and output filters | MAME values | provisional | | U20 | Board speed in Python | none | measure at M3 | | U21 | Kabuki: confirm opcode-key use only on M1 cycles (operands use the data key) | `kabuki.cpp` wording; MAME's Z80 source not pinned | check at M6 | | U22 | jtcps's loop-count test ROM ("SF2 DMA no b3") | not in the pinned trees | search before M7 | ## Conflicts (C) | # | Conflict | Sides | Decision | | --- | --- | --- | --- | | C1 | Wait states | PRG1 PAL + jtcps board loop count: one per cycle; MAME: none | follow the PAL | | C2 | Layer-enable masks | die/keys: one bit per layer; MAME: multi-bit masks | follow the die; DL-0411 rows keep MAME's masks | | C3 | Palette base bit 0 | die: copy one section; MAME (Magic Sword board test): "doesn't seem to be copied" | follow the die; note that both may be true if the one section is not the visible one | | C4 | Palette DMA duration | die text 1,536 us; jtcps measured 780.4 us | follow the measurement | | C5 | Blanking edges | die counter values vs MAME `set_raw(8 MHz, 512, 64, 448, 262, 16, 240)` differ by one | follow the die's counters; reconcile edge-vs-count at M1 | | C6 | Star fields | MAME's enable index 0 draws the field the die calls stars 2 | follow the die | | C7 | CPS-ID | die: bits 6-9 count reads; MAME: constant | follow the die | | C8 | `/OBJUP` on CPS-1 | die: to the CPS-A only; MAME: to IPL2 via C-board JP1 on later boards | both: a row field (JP1) | | C9 | cworld2j priority masks 2-3 | key: `00 00`; MAME: `2A 28` | keep MAME's; the key's may be Cruz's simplification | | C10 | Frame rate | measured 59.61 Hz (one report); arithmetic 59.637 | count clocks; no constant | ## 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 `cps1_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 1: **shared CPS video, staged**: build it inside this repository behind a strict import boundary, extract to `cps-video-python` when cps2-python reaches its video milestone. Decision 4: **`qsound-python`** pinning dsp16-python. - Decision 3, changed: the 93Cxx serial EEPROM gets **its own small shared core** (users: these QSound boards and Pang! 3, cps2-python, Jaguar cartridges), not a module inside qsound-python. - Decision 8: the opcode-fetch hook in z80-python is **approved** (the ColecoVision board needs the same signal). Decision 6: the gate-level study waits until the rung that needs it. - Keys (Kabuki, CPS-B-21) stay in this repository as data with their sources cited; the board is private. - 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. 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. **How CPS-1 and CPS-2 share the graphics chips.** *Recommend* a shared chip package, staged: build `cps1.video` (CPS-A, CPS-B, palette) inside this repository behind a strict import boundary; extract it to `cps-video-python` the day `cps2-python` starts video; both pin it. Reject one merged `cps-python`; keep "cps2 pins cps1" only as the fallback ([cps2-sharing.md](cps2-sharing.md)). 2. **Names.** `cps1-python`, package `cps1`, classes as above. *Recommend* as written. 3. **The 93C46 EEPROM** (QSound boards, Pang! 3, CPS-2, many others). *Recommend* not in either board: in `qsound-python` if that is created, or a tiny `eeprom93c46` module there, until a third family board wants it. 4. **Where the QSound device lives.** *Recommend* a small `qsound-python` pinning `dsp16-python`, used identically by cps1 and cps2 (agree with the dsp16 brief). 5. **Kabuki.** *Recommend* `cps1.kabuki` now (one consumer); its own repository when a Mitchell board starts. 6. **A gate-level simulation of DL-0311/DL-0921 from Loïc Petit's KiCad sheets** as a tier-1 referee (like the Breaknes study for the NES PPU). *Recommend* yes, as a separate study repository after M2, scoped to the bus-request scheduler and the palette copy first (the parts the board cannot otherwise judge). 7. **CPS Changer** as a machine row, not a repository. *Recommend* yes. 8. **`read_opcode` in z80-python** (optional callable used by the M1 fetch only). *Recommend* a PR on z80-python before M6; recertify its ladder. 9. **68000 clock per set**: *Recommend* MAME's assignment (U16) as a row field. 10. **Mapper source**: *Recommend* compute from the fuse maps wherever the B-board wiring is known (schematic or a wiring proven by reproducing MAME's ranges), MAME's table for the rest and the 8 sets with undumped PALs, every row tagged with its source. 11. **CPS-B-21 CHECK data**: *Recommend* implement the lock-out; use the game's own known values (3 Wonders) and otherwise run the row as a de-suicided board does (CHECK disabled), recorded per row. 12. **Wait states and stolen bus time on by default** (the board is slower than MAME, as the hardware is). *Recommend* yes, with a switch for lockstep against MAME's timing.