# Handoff: build `namcos22-python`, the Namco System 22 and Super System 22 boards ## Context you are inheriting Read the family's CLAUDE.md, the charter and methodology (emulator-lineage `docs/`), the JIT proposal and the era-boundary proposal (`docs/proposals/`), and [n64-python's execution-architecture.md](../../n64-python/docs/execution-architecture.md), whose cost model this board reuses. System 22 is a "game owns the machine" board inside the era boundary: the full contract applies. It shares its DSP core with [namcos21-python](../../namcos21-python/docs/handoff-brief.md) and nothing else with System 21. Read in order: [start-here.md](start-here.md), [census.md](census.md), [memory-map.md](memory-map.md), [cpu-cores.md](cpu-cores.md), [polygon-pipeline.md](polygon-pipeline.md), [mcu-and-sound.md](mcu-and-sound.md), [domains-and-speed.md](domains-and-speed.md), [execution-architecture.md](execution-architecture.md), [sources.md](sources.md), [validation.md](validation.md), [mame-oracle.md](mame-oracle.md). Then `python -I scripts/fetch_references.py` (4 files, ~86 MB; `--verify` to check). ## Scope In: System 22 (18 sets: Ridge Racer first), then Super System 22 (22 sets: the M37710S4, the sprite layer, the MB87078). Out: linked cabinets, the cabinets' motors and lamps beyond named outputs, Ridge Racer Full Scale's car (a later row), hosts and sites. ## Package and classes (proposed) ``` namcos22_python/ machine.py # set table: ROM regions by SHA-1, board kind (s22 | super22), MCU kind, gamma PROMs romset.py # MAME zips read in place, verified by SHA-1; namcoc71 / namcoc74 device sets board.py # build(set, rompath) -> System22; the time base; save states main.py # MainDomain: m68020-python (MC68020 | MC68EC020), work RAM, system registers, keycus dsp.py # DspDomain: tms320c25-python x 2 with the C71 image, point ROM, polygonram, ports render/ # front.py (primitive intake, DSP-visible timing), back.py (software rasteriser), # text.py, sprites.py (Super 22), mixer.py (palette, czram, gamma) mcu.py # McuDomain: m7700-python (M37702 C74 | M37710S4), shared RAM, inputs c352.py # C352, in-board, pin-shaped iomcu.py # System 22's I/O board MCU (U8) ``` ## What the board needs from its cores - **m68020-python** (new, decision 3): MC68020 and MC68EC020 variants; table-driven instruction timing within UM020's bounds plus bus transactions; the 256-byte instruction cache with CACR/CAAR; vectored interrupts; dynamic bus sizing as the board's ports need. - **tms320c25-python** (new, shared with namcos21-python): mask ROM supplied by the board, RAM program spaces, I/O ports, BIO/XF/HOLD/interrupt pins as board signals. - **m7700-python** (new, decision 3): M37702 (with a 16 KiB internal ROM image) and M37710S4 (ROM-less) variants; SFRs, timers, serial, A-D; bus with wait states. ## Milestones | # | Milestone | Judge (tier) | Exit | | --- | --- | --- | --- | | C0 | the three cores and their ladders | UM020, C2X, SW7700 (2) | each core's instruction ladder green | | M1 | main domain on Ridge Racer: 68020, RAM, system registers, interrupts, keycus as observed | MAME (5) | 68020 stream equal to MAME's for 600 frames from reset, or a named reason per difference | | M2 | MCU domain: C74, shared RAM, inputs, the C352 write stream | MAME (5) | MCU in lockstep; C352 writes equal | | M3 | DSP domain: master and slave, polygonram, point ROM | MAME (5) for the master | master stream equal; the slave run as the C25 would (MAME cannot judge it) | | M4 | renderer front end and software back end; text layer; mixer | MAME pictures (5, imperfect) | Ridge Racer's attract race drawn; every difference triaged and recorded, not assumed ours | | M5 | the other System 22 games (Ridge Racer 2, Rave Racer, Ace Driver, Victory Lap, Cyber Commando) | MAME (5) | each reaches play | | M6 | Super System 22: MC68EC020, M37710S4, sprites, MB87078 | MAME (5) | Time Crisis and Alpine Racer reach play | | M7 | save states; Rust transcription begins | self | save states continue identically | ## The chip rule | Chip | Users | Proposal | | --- | --- | --- | | MC68020 / MC68EC020 | Taito F3, Konami GX (Phase 0s running); many MAME boards | new core **`m68020-python`** (decision 3) | | TMS320C25 (C71) | namcos21-python (C67) | new core **`tms320c25-python`** (with namcos21-python) | | M37702 (C74), M37710S4 | Namco System 11, NA-1/2, NB-1/2, FL in MAME | new core **`m7700-python`** (decision 3) | | C352 | Namco System 11, 12, 23, NB-1, ND-1, FL in MAME; no family board | in-board (decision 6) | | renderer, text layer, sprite chip, mixer, keycus, MB87078 | none in the family | in-board | ## Unknowns (U) and contradictions (C) | # | Unknown | Best source now | | --- | --- | --- | | U1 | the primitive format between the DSPs and the renderer | traces of the DSP output ports once the DSP domain runs; MAME's BSD driver if decision 1 allows | | U2 | texel addressing, filtering, the `textile` and `textilemap` formats | MAME pictures; ROM inspection | | U3 | Gouraud and depth-cue arithmetic (`czram`), translucency, the depth test; whether state crosses pixels | pictures; none better | | U4 | the slave DSP's role, and why MAME never runs it | none in hand; the C2X instruction set over the C71 image, traced in our own core | | U5 | the renderer's timing and anything the DSPs or the 68020 read from it mid-frame | DSP traces (polling loops on ports that the renderer drives) | | U6 | the point ROM's formats | DSP traces | | U7 | the keycus: address, values, timing per game | 68020 traces from reset | | U8 | the I/O board's C74: its program and role (MAME maps no external ROM and never runs it) | none; a dump of the I/O board's ROM, if one exists | | U9 | which inputs reach which MCU port and A-D channel per game | MCU traces | | U10 | the M37710's manual (SFR map, any instruction differences from the M37702) | the mirror's 1994 Mitsubishi 16-bit volumes, to check | | U11 | the C352's register layout, sample formats, mixing | the MCU's write stream; MAME audio | | U12 | the 68020's exact instruction overlap (the manual gives bounds only) | none; instruction level is the modelling choice (decision 4) | | # | Contradiction | Sides | Proposal | | --- | --- | --- | --- | | C1 | which games are System 22 | the task brief lists Cyber Cycles and Time Crisis with Ridge Racer as System 22; MAME: both are Super System 22 (MC68EC020, M37710S4, sprites) | MAME's split; both boards are in scope | | C2 | DSP clock | MAME 40 MHz CLKIN (10 M machine cycles); Wikipedia (uncited) 49.152 MHz (12.288 M) | unknown until a crystal is seen; the time base waits on it | | C3 | who made the renderer ("TR3") | Wikipedia: Namco in-house; Giant Bomb and the Batocera wiki (snippets): Evans & Sutherland | no primary source either way; immaterial to the model, material to where documents might be found | | C4 | the sound CPU | Wikipedia: "M37702 sound CPU" on System 22, M37710 on Super 22; MAME: two C74 (M37702) on System 22, one running sound and inputs, one on the I/O board | MAME's two-MCU description, with U8 open | ## Domains and speed Summary of [domains-and-speed.md](domains-and-speed.md) and [execution-architecture.md](execution-architecture.md): - **Domains:** main (68020, renderer front end, text, sprites, mixer), DSP (master and slave, one domain), MCU/sound (C74 or M37710S4, C352, inputs), I/O MCU (System 22); the renderer's pixel work is a producer. **Channels:** `polygonram`, the DSP ports, the 68020/MCU shared RAM, interrupts, the frame swap. The 68020 has no window onto the frame buffer (OBSERVED), so the renderer's back end joins the rest once a frame. - **Need, with arithmetic:** CPUs ~29 M instructions/s at peak (2 x 40 MHz / 4 = 20 M DSP machine cycles; ~8 M 68020 at peak, 3.6 M observed; ~1 M MCU): budgets of 172 / 138 / 83 host cycles per instruction on one core (desktop / phone app / phone browser). Renderer 18.4 M pixels/s per full layer, 37-55 M with overdraw: at 80-200 host cycles a pixel, 3-11 G cycles a second. - **No-JIT path:** the CPU side fits one core everywhere with table-driven time-keeping (15-34 % / 19-42 % / 32-70 % of a core). The renderer needs 0.6-2.2 desktop cores, 0.75-2.75 phone cores, 1.25-4.6 browser workers in software. Desktop: real time with `recompile: none` and 1-3 renderer threads. Phone app: at the edge; Metal compute back end recommended. Phone browser: a WebGPU back end or a named concession. Recompilation does not move this board. ## Measure first 1. `tms320c25-rust` host cycles per instruction (shared with namcos21-python). 2. One Ridge Racer frame's primitive stream, then the software rasteriser's ns per pixel. 3. Overdraw per frame in Ridge Racer, Rave Racer, Time Crisis, Alpine Racer. 4. Whether anything CPU-visible depends on the renderer mid-frame (U5). ## Open decisions for Aubrey (each with a recommendation) 1. **MAME's BSD-3-Clause System 22 files** (the late-era MAME-BSD question, pending). Every board file carries `license: BSD-3-Clause`; the 68020's generated handlers do not (GPL-2.0+, never fetched). *Recommend* allowing the BSD board files to be read for facts only (notice in NOTICE.md, never transcribed): without them the renderer's primitive format, the keycus and the slave DSP's role are rebuilt from traces of a detector that does not run the slave at all, which may not be possible. 2. **Board order.** *Recommend* after namcos21-python's Winning Run (which builds `tms320c25-python` against a MAME that runs its one DSP faithfully), then System 22 with Ridge Racer, then Super System 22. 3. **New CPU cores:** *Recommend* **`m68020-python`** (MC68020 and MC68EC020 variants, coordinated with the Taito F3 and Konami GX Phase 0s, which need the EC020) and **`m7700-python`** (M37702 and M37710 variants). Each is its own repository by the CPU rule. 4. **The 68020's modelling level:** instruction level with per-transaction bus timing, because UM020 documents only best/cache/worst bounds. *Recommend* yes, marked in the specification as a modelling choice with the bounds as its test. 5. **DSP timing as specification data** (as n64-python X1 and namcos21-python decision 6). *Recommend* yes. 6. **The C352** stays in this board behind a pin-shaped class until a second family board (a Namco System 11/12/23 or NB-1) starts. *Recommend* yes. 7. **The renderer's GPU back end** (turbo, integer-only, proven per device, one join per frame): *Recommend* planning it from the start of the turbo tier and recording that its judge is our software rasteriser, whose own judge is tier 5. The capability record should say plainly that phone browsers need it. 8. **The slave DSP:** *Recommend* the specification runs both DSPs as the hardware does (C2X semantics over the C71 image), and the gate records that MAME cannot judge the slave: its output is checked only against pictures until better evidence exists.