# Start here: the machine, the clocks, the module shape Read [README.md](../README.md) first, then this, then [memory-map.md](memory-map.md), [encryption.md](encryption.md), [video.md](video.md), [qsound.md](qsound.md), [eeprom.md](eeprom.md), [inputs.md](inputs.md), [sockets.md](sockets.md), [census.md](census.md), [validation.md](validation.md), [mame-oracle.md](mame-oracle.md), and last [handoff-brief.md](handoff-brief.md) (milestones, the U and C lists, the open decisions). Nothing here is code: this is Phase 0. ## The machine in one paragraph Capcom CP System II (1993-2004): an A-board in the cabinet and a game B-board on top. The **68000 sits on the B-board inside the custom DL-1525**, which also holds the opcode cipher and its battery-backed key; the program ROMs are encrypted **for opcode fetches only**. The A-board carries the CPS-1's **CPS-A-01 and CPS-B-21** for three tile layers, palette and timing; a new **object engine** (DL-1525 on the B-board, object RAM there, a frame buffer under DL-1625/DL-2227 on the A-board) replaces CPS-1's sprites, with **per-object priority** against the layers and **raster interrupts** from the B-21's counters. Sound is a plain **Z80** at 8 MHz commanding a **QSound DSP** (DL-1425 = DSP16A with Capcom's program) through three byte registers; settings live in a **93C46 EEPROM**. 323 sets, 40 games, each region its own program and key. ## The machines as data One board, a machine table generated from MAME's set list (`reference/mame-listxml/cps2.xml`): per set, the ROM files and their layout, the key file, the input layout (14 kinds, [inputs.md](inputs.md)), and three hardware facts: extra RAM present (`804030` bit 14), network adapter present (bit 15), digital volume present (absent on single-board sets). Phoenix sets are rows with the all-`FF` key. No region switch exists: the region is in the ROMs and the key. ## Clocks and time | Clock | Value | Who uses it | | --- | --- | --- | | 16 MHz crystal (A-board) | 16,000,000 Hz | the 68000 (16 MHz), the CPS-A/CPS-B (pixel clock 8 MHz) | | 8 MHz crystal | 8,000,000 Hz | the Z80; its IRQ at 8 MHz / 32,000 = 250 Hz | | 60 MHz crystal | 60,000,000 Hz | the DSP16A (30 MHz machine cycles); one stereo sample per program loop (1,245 or 1,248 machine cycles: [qsound.md](qsound.md)) | | Line / frame | 512 pixel clocks; 262 lines | 15,625 Hz, 59.637 Hz by arithmetic; vblank IRQ at line 240 | Proposed time base: **one timeline in 16 MHz ticks** for the 68000, the video and the 8 MHz Z80 (exactly 2:1), with the DSP's 60 MHz domain caught up at QSound accesses (15:4 against the 16 MHz tick: exact rational stepping, no drift). The board owns the clock: the 68000 core reports clocks per access, the board adds wait states (profile `board`) or scales (profile `mame`), the CPS-A's stolen bus time, and raises IPL1/IPL2. ## The module shape (proposed) ``` cps2/ machine.py the machine table (generated rows: files, key, inputs, add-on bits) romset.py non-merged zip reader: word swap, ROM_LOAD64_WORD, graphics unshuffle, key cipher.py the two Feistel networks, the key schedule, the 65,536-entry subkey table (no board imports) bus.py the 68000 map, fc-split program fetch, wait-state profiles, DL-1727 registers objects.py object RAM banks, the vblank latch, the object engine and the CPS-2 mixer io.py IN0-IN2, 804030, 804040, paddles and dials, the EEPROM lines sound.py the Z80 map, shared RAM, the QSound device's Z80 side, volume sockets.py the Protocols and test-only fakes ([sockets.md](sockets.md)) system.py run_frame and the scheduler ``` Pinned by git revision, never copied: `m68000-python` (`3029f56`), `z80-python` (`65e7f08`), `dsp16-python` and `qsound-python` (when they exist), the shared CPS-A/CPS-B package (`cps-video-python`, staged inside cps1-python first: open decision 1), a 93C46 package (open decision 4). No module state: two boards in one process (a link-play test, the lockstep harness) must not share anything. ## Performance: correct, not fast Expected at roughly 1/10 to 1/30 of real time on PyPy and about 1/100 on CPython with low-level QSound ([qsound.md](qsound.md), "Speed, frankly"); the silent-QSound fake keeps video work at CPU speed. Use PyPy for anything longer than a unit test. Two habits from the family's README files: a CPython venv (`uv venv .venv`) for tests and linting, a PyPy venv (`.venv-pypy`) for runs; on this machine set `PYPY_GC_NURSERY=1M` for parallel runs (about 5x throughput). Respect the shared machine: one MAME at a time, short traces, no library sweeps until a board might be ready. ## Bring your own ROM sets, key files, `dl-1425.bin` and EEPROM images are read in place from the user's trees (`$MAME_ROMPATH` here) and never committed or copied into the repository; `.gitignore` excludes `*.zip`, `*.key`, `*.bin`, `*.nv`.