# Handoff: build `namcos21-python`, the Namco System 21 board ## Context you are inheriting Read the family's CLAUDE.md, the charter and methodology (emulator-lineage `docs/`), then [namcos2-python's handoff brief](../../namcos2-python/docs/handoff-brief.md): System 21 is System 2's board plus a DSP polygon side, and most of its customs are System 2's. It is a "game owns the machine" board, inside the era boundary: the full contract applies (exact, timed Python specification; Rust transcription; `-fast` by proof). 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), [video-and-sound.md](video-and-sound.md), [domains-and-speed.md](domains-and-speed.md), [sources.md](sources.md), [validation.md](validation.md), [mame-oracle.md](mame-oracle.md). Then `python -I scripts/fetch_references.py` (2 files, ~38 MB; `--verify` to check). ## Scope In: Winning Run's three sets (one TMS320C25, three 68000s, C65), then the seven C67 sets (Starblade, Solvalou, Air Combat, Cyber Sled: five C67 DSPs, C68, C355 sprites). Later rows: Driver's Eyes (three boards and a gearbox device). Out: Galaxian 3 (a different machine that reuses the C67 group), the C139 link between cabinets, hosts and sites. ## Package and classes (proposed) ``` namcos21_python/ machine.py # set table: ROM regions by SHA-1, kind (winrun | c67 | driveyes), MCU kind romset.py # MAME zips read in place, verified by SHA-1; namcoc65/namcoc67/namcoc68 device sets board.py # build(set, rompath) -> System21; the time base; save states main.py # MainDomain: 68000 x 2 (+ gpu 68000 on Winning Run), C148s (pinned from the # extracted System 2 customs: decision 5), shared RAM, palette, C355 or gpu side dsp.py # DspDomain: tms320c25-python x 1 (RAM program) or x 5 (C67 mask ROM image), # vertex ROM, communication RAM, master/slave ports render.py # Renderer: front end (primitive intake, timing) and back end (pixels), functional sound.py # SoundDomain: 6809 + ym2151-python + C140 (pinned c140-python: decision 5) mcu.py # McuDomain: C65 (m6805-python) or C68 (m740-python), inputs, analogue controls ``` ## What the board needs from its cores - **m68000-python:** two or three instances; per-cycle bus callbacks; vectored interrupts through the C148s; held reset. - **tms320c25-python** (new, decision 3): the TMS320C25 with its 4K-word on-chip ROM supplied by the board (C67 image) or absent (Winning Run, program in RAM); data and program spaces; I/O ports; BIO, XF, HOLD and the interrupt pins as board-visible signals; time charged per instruction from data (decision 6). - **m6809-python, m6805-python, m740-python, ym2151-python:** as namcos2-python's brief. ## Milestones | # | Milestone | Judge (tier) | Exit | | --- | --- | --- | --- | | C0 | `tms320c25-python` core and ladder; System 2's cores as namcos2-python orders them | C2X (2) | every instruction against C2X; Winning Run's DSP stream equal to MAME's for 60 frames after upload | | M1 | Winning Run main domain: three 68000s, C148s, RAMs, the gpu side's registers | MAME trace (5) | main, slave and gpu streams equal to MAME's for 300 frames, or a named reason per difference | | M2 | DSP domain on Winning Run: upload, vertex ROM, handshakes | MAME (5) | the DSP's writes toward the renderer equal to MAME's over 600 frames of a race | | M3 | renderer, functional, and the gpu side's picture | MAME pictures (5) | Winning Run's attract and race pictures; every difference triaged | | M4 | sound and MCU (System 2's) | MAME (5) | write streams equal | | M5 | C67 boards: five C67s, C68, C355 sprites | MAME (5): master stream; slaves by output content only | Starblade's attract reaches its 3D scenes; DSP output equal in content | | M6 | the other C67 sets; save states | self, MAME | each set reaches play; save states continue identically | | M7 | Driver's Eyes (three boards, gearbox) | MAME (preliminary) | three screens in step | ## The chip rule | Chip | Users in the family | Proposal | | --- | --- | --- | | MC68000 | many | m68000-python | | MC6809E | namcos1, namcos2 | m6809-python | | HD63705Z0 (C65), M37450 (C68) | namcos2 | `m6805-python`, `m740-python` (namcos2's decisions 3, 4) | | TMS320C25 (C67 and plain) | namcos22 (C71) | new core **`tms320c25-python`** (decision 3) | | C140 | namcos2 | extract **`c140-python`** from namcos2-python (decision 5) | | C148, C139, dual-port RAM, C355 sprites | namcos2 | extract from namcos2-python when this board needs each (decision 5) | | `namcos21_3d` renderer, vertex ROM interface | none (Galaxian 3 in MAME) | in-board | | YM2151 | cps1, namcos1, namcos2, system16 | ym2151-python | ## Unknowns (U) and contradictions (C) | # | Unknown | Best source now | | --- | --- | --- | | U1 | the renderer's primitive format, depth test, shading and fill rules | DSP output traces; MAME pictures; MAME's BSD `namcos21_3d.cpp` if decision 1 allows | | U2 | the renderer's timing and the DSP-side wait on it | none; traces of the DSP's polling | | U3 | frame buffers: count, size, swap, mixing with sprites | traces, pictures | | U4 | how the master shares work among four slaves, and their real clock (MAME runs one at 96 MHz) | none; a board photograph for the crystal; traces of the master's port writes | | U5 | which TMS320C25 multiprocessing features (global memory, HOLD, BIO/XF) the board wires | traces of the master's BIO-dependent branches and XF writes | | U6 | the vertex ROM formats (`point16`, `point24`) | DSP traces (what it reads and how it unpacks) | | U7 | the C67's and C71's identity as plain TMS320C25s with mask ROM (no Namco document) | the C2X instruction set running the image without unknown opcodes | | U8 | Winning Run's gpu 68000: which picture parts are bitmaps and which polygons | traces of its writes | | U9 | the two undumped Winning Run PALs (`wr-g2b.4p`, `wr-g3.4s`) | none; MAME runs without them | | # | Contradiction | Sides | Proposal | | --- | --- | --- | --- | | C1 | DSP count and clock | Wikipedia (uncited): four TMS320C25 at 24.576 MHz, Starblade five TMS320C20; MAME `-listxml`: Winning Run one TMS320C25 at 40 MHz, C67 boards five C67 (TMS320C25) at 24 MHz, Driver's Eyes one per PCB at 40 MHz | follow MAME's part identity (the C67 image is exactly the C25's 4K-word ROM, U7); treat the clocks as unknown until a crystal is seen | | C2 | the time base | the 68000 side is 12.288 MHz (a 24.576 MHz family), MAME's DSP clocks are 24 and 40 MHz | choose the integer unit once the DSP crystal is known (U4); until then a common multiple | | C3 | the 6809's clock | Wikipedia 3.072 MHz; MAME 2.048 MHz (3.072 MHz only on Driver's Eyes) | MAME's per-set clocks, with C3 noted | ## Domains and speed Summary of [domains-and-speed.md](domains-and-speed.md): - **Domains:** main (68000s, C148s, sprite/palette side, renderer front end), DSP (one C25 or five C67s, one domain), sound (6809, YM2151, C140), MCU; the renderer's pixel work is a producer. **Channels:** the 68000/DSP communication RAM and registers, the DSP master/slave ports, the dual-port RAM, the C148 lines, the frame buffer at its joins. - **Need, with arithmetic:** C67 board ~33 M instructions/s at peak (5 x 24 MHz / 4 = 30 M DSP machine cycles, plus ~2 M 68000 and ~1 M 6809/MCU instructions, OBSERVED rates); Winning Run ~13 M (10 M DSP + 3 M). Budgets on one core: 152 / 121 / 73 host cycles per instruction (desktop / phone app / phone browser) for a C67 board; 385 / 308 / 185 for Winning Run. - **No-JIT path:** an exact DSP interpreter at 20-50 cycles per instruction (HYPOTHESIS) uses 15-33 % of a desktop core for a C67 board, 19-41 % of a phone core, 31-69 % of a phone browser's: real time on all three with `recompile: none`, **if** the DSP's time-keeping is table-driven. An SH-2-style stage scheduler (145 cycles, MEASURED on sh2-rust-fast) would not fit a phone. The renderer (flat shading with depth) is a producer thread; no GPU needed. Order: Rust `-fast` with cheap time-keeping; a cached interpreter for the DSPs (programs in mask ROM and RAM uploaded once: invalidate on the upload); then threads at the producers and at the dual-port RAM. ## Measure first 1. `tms320c25-rust`'s host cycles per instruction on a DSP-only case (a captured Winning Run DSP job), with the profile split (time-keeping, fetch, handlers). 2. The 68000-to-DSP channel rate per emulated second (communication RAM and register accesses), which decides whether the DSP domain can have its own thread. 3. The C67 master-to-slave port rate, for the same reason inside the DSP domain. ## Open decisions for Aubrey (each with a recommendation) 1. **MAME's BSD-3-Clause System 21 files** (the late-era MAME-BSD question, pending): every file this board would want carries `license: BSD-3-Clause`. *Recommend* reading them for facts only, notice in NOTICE.md, never transcribed, if Aubrey allows it for the late era; otherwise the renderer and the DSP handshakes are rebuilt from traces alone, which is slow but clean. 2. **Board order.** *Recommend* namcos2-python first (its C148, C139, C140, C355 and MCUs become this board's pins), then Winning Run here (one DSP, MAME's best-behaved System 21 kind), then the C67 boards. 3. **The DSP core.** *Recommend* **`tms320c25-python`** (package `tms320c25_python`), one repository with the TMS320C25 as its variant and the mask ROM supplied by the board, serving this board and namcos22-python. The name follows the part; `tms320c2x-python` would only pay if a TMS320C20 or C26 user appears. 4. **The C67 slaves.** MAME runs one slave at 96 MHz in place of four at 24 MHz. *Recommend* the specification models all four at the real clock, and the gate compares slave **output content**, not timing, with MAME, recording the substitution as the reason. 5. **Extractions from namcos2-python** (C140, C148, C139, dual-port RAM, C355): this board is the chip rule's second user for each. *Recommend* extracting each with history when this board's milestone first needs it (C148 at M1, C140 at M4, C355 at M5), pinned by both boards. One repository per chip, or one `namco-system2-customs-python` for the four non-sound customs: *recommend* one per chip, as the family has done. 6. **DSP timing as specification data** (as n64-python X1): each C25 instruction's machine cycles and its extra cycles (external memory, wait states, branches) stated as tables. *Recommend* yes: it is what makes real time on phones plausible. 7. **Driver's Eyes and Galaxian 3.** *Recommend* Driver's Eyes as a late row of this board (three instances of it); Galaxian 3 out of scope (68020 masters, laserdisc), noted as a C67 user.