# Handoff: build `namcos2-python`, the Namco System 2 board ## Context you are inheriting Family shape and rules as in [namcos1-python's brief](../../namcos1-python/docs/handoff-brief.md) (read its "Context" first). System 2 is era 2: several CPUs in cycle lockstep, `-fast` needed, threads likely useful on phones. It is its own board, not a System 1 row: it shares the sound 6809, the YM2151, the C116 and the C123 with System 1, and nothing else. Read in order: [start-here.md](start-here.md), [memory-map.md](memory-map.md), [cpu-cores.md](cpu-cores.md), [video.md](video.md), [sound.md](sound.md), [domains-and-speed.md](domains-and-speed.md), [sources.md](sources.md), [validation.md](validation.md), [mame-oracle.md](mame-oracle.md), [census.md](census.md). Then `python -I scripts/fetch_references.py` (3 files, ~79 MB; `--verify` to check). ## Scope In: the 60 sets of MAME 0.285's `namcos2.cpp` (28 games), in this order: the C65 games with the System 2 sprite and ROZ boards; then the C355 and C169 games; then the C68 games; the road games (C45) last. Out: the C139 link between cabinets (single cabinet first), hosts, sites. ## Package and classes (proposed) ``` namcos2_python/ machine.py # set table: ROM regions by SHA-1, MCU kind (C65/C68), video kind # (s2 sprites | C355; s2 ROZ | C169 | C45 road), orientation, key romset.py # MAME zips read in place, verified by SHA-1; the namcoc65/namcoc68 device sets board.py # build(set, rompath) -> System2; the 49.152 MHz tick timeline; save states c148.py # C148 x 2: interrupt levels, acknowledges, resets of slave/sound/MCU dpram.py # the dual-port RAM channel (68000 / 6809 / MCU) keys.py # protection key at $D00000 (HYPOTHESIS), functional, FITTED video/ # c116, c123 (to be pinned from namco-c123-python: decision 5), # sprite_s2, sprite_c355, roz_s2, roz_c169, road_c45 sound.py # SoundDomain: 6809 + ym2151-python + C140 c140.py # C140, in-board, pin-shaped mcu.py # McuDomain: C65 (m6805-python, HD63705 variant) or C68 (m740-python), # inputs, DIP switches, analogue inputs c139.py # serial link stub (RAM present, no partner) ``` ## What the board needs from its cores - **m68000-python**: two instances; per-cycle bus callbacks with the board's waits; interrupt levels with vector fetch (the C148 answers the CPU-space cycles); held reset. - **m6809-python**: as namcos1-python (one instance, 2.048 MHz). - **m6805-python** (new, decision 3): the HD6305/HD63705 variant: U08's instruction set and cycles; the Z0's larger map (U4) from MAME's map until a document is found; ports and timers for the board. - **m740-python** (new, decision 4): the M37450's 740 core with MUL/DIV, on the 6502 frame. - **ym2151-python**: as namcos1-python. ## Milestones | # | Milestone | Judge (tier) | Exit | | --- | --- | --- | --- | | C0 | cores: m6809-python core; m6805-python with the HD63705 variant | DOC (2), MAME (5) | their ladders green; the C65 firmware runs against MAME's trace for 300 frames | | M1 | main 68000, memory map as observed, C148 skeleton, data ROM, RAM, screen timing | MAME trace (5) | Valkyrie's main-CPU stream equal to MAME's for 120 frames, or a named reason per difference | | M2 | slave, sound 6809, C65, the dual-port RAM, inputs, DIP switches, EEPROM | MAME traces (5) | all four released at MAME's frames and in lockstep for 300 frames, 3 smoke games (Valkyrie, Assault, Phelios) | | M3 | keys | traces (5) | every C65 ROZ game past its protection check | | M4 | video: C116 + C123 (pinned from the extracted core, or in-board), s2 sprites, s2 ROZ | MAME pictures (5) | the smoke games' attract screens; differences triaged | | M5 | sound: YM2151, C140 | MAME audio (5) | write streams equal, audio differences named | | M6 | C355, C169, then the C68 games (after `m740-python`) | detectors | Steel Gunner, Metal Hawk, Super World Stadium reach play | | M7 | C45 road games | weak detector (MAME "imperfect") | Final Lap and Four Trax reach play; every difference with MAME recorded, not assumed ours | | M8 | library and save states | detectors | each of the 60 sets reaches play in a smoke run; save states continue identically | ## The chip rule | Chip | Users | Proposal | | --- | --- | --- | | MC68000 x 2 | many | m68000-python | | MC6809E | namcos1 | m6809-python | | HD63705Z0 (C65) | psx-python (MC68HC05, LLE CD) | new core **m6805-python** with variants (decision 3) | | M37450 (C68) | Namco System 21 (MAME) | new core **m740-python** (decision 4) | | YM2151 | cps1, namcos1, system16 | ym2151-python | | C116 + C123 | **namcos1-python** | extract as namco-c123-python (decision 5) | | C140 | System 21, NA-1 (C219) in MAME | in-board | | C139, C148, sprites, ROZ, C355, C169, C45, key | MAME's later Namco boards; no family board | in-board, pin-shaped | ## Unknowns (U) and contradictions (C) | # | Unknown | Best source now | | --- | --- | --- | | U1 | the C148's registers: interrupt levels, resets, which CPU is released when | traces; MAME's BSD `namco_c148.cpp` (decision 1) | | U2 | the dual-port RAM's arbitration (two 68000s and two 8-bit CPUs on one RAM) | none; observation | | U3 | 68000 wait states per region | none; MAME approximates | | U4 | the HD63705**Z0**: memory size and any difference from the V0 the U08 documents | MAME's map (384 B RAM, 8 KB internal image); a later Hitachi handbook to find | | U5 | C123 driven from a 16-bit bus: register layout at $420000 | MAME pictures | | U6 | the key custom at $D00000 (if it is one) per game | traces | | U7 | how Final Lap's C65 runs with no external ROM in the set | MAME trace of finallap's C65 | | U8 | C140 register layout, sample formats, rate | observation (decision 1) | | U9 | ROZ precision, sprite formats, the C45 road | MAME pictures | | U10 | the master crystal (49.152 MHz by arithmetic only) | a board photograph or manual | | # | Contradiction | Sides | Proposal | | --- | --- | --- | --- | | C1 | the MCU | task brief: one, "the HD63705 MCU (a 68HC05)"; MAME: C65 = HD63705Z0 on 43 sets, C68 = M37450 on 17; Hitachi U08: the HD63705 is an HD6305 (6805-compatible), not a Motorola 68HC05 | two MCU families; one 6805-family core for HD6305 and MC68HC05 | | C2 | the C65's clock | MAME listxml: 2.048 MHz; its trace: 512 kHz of cycles | MAME's clock is the oscillator; confirm the HD6305 divider in U08 | ## Domains and speed Summary of [domains-and-speed.md](domains-and-speed.md): - **Domains**: main (two 68000s + C148s + video + key), sound (6809 + YM2151 + C140), MCU (C65 or C68 + I/O); link later. **Channels**: the dual-port RAM (four CPUs), the C148 reset and interrupt lines, the C139 RAM. - **Need**: 24.58 M 68000 cycles a second; ~2.7 M instructions a second measured on a C65 board (1.14 M main, 0.76 M slave, 0.66 M sound, 0.15 M MCU); ~27.1 M bus cycles to interleave; 6.144 M dots. - **No-JIT path**: plain Rust ~1.5-2.5x real time on this desktop (HYPOTHESIS, scaled from megadrive-rust's 4-6x at 11.25 M bus cycles); **`-fast` is the desktop and browser target**, then the cached interpreter (code in ROM), then threads for phones (main domain on one core, picture and audio producers beside it; sound and MCU domains could run ahead to the next dual-port access). `recompile: none` should meet desktop and browser; phones are plausible but unproven. ## Open decisions for Aubrey (each with a recommendation) 1. **MAME's BSD-3-Clause Namco files** (as in namcos1-python, decision 1): every relevant file carries `license: BSD-3-Clause`. Recommend allowing them to be read for facts with their notice in NOTICE.md, never transcribed; otherwise the C148, C140, sprite, ROZ and road formats are rebuilt from observation alone. 2. **Board order.** Recommend namcos1-python first; namcos2-python after it, starting with the C65 ROZ games. 3. **The C65 core.** Recommend **`m6805-python`**, one core with variants (MC6805, HD6305/HD63705, MC68HC05), serving both this board and psx-python's LLE CD controller, in place of the PSX Phase 0's `mc68hc05-python` name. Its first variant is whichever board reaches its MCU first. 4. **The C68 core.** Recommend **`m740-python`** on the 6502 CPU frame (as 65816-python is), built only at milestone 6; until then the 17 C68 sets are out of the early smoke lists. 5. **C116 + C123.** Recommend extracting them from namcos1-python as `namco-c123-python` when this board reaches milestone 4, and pinning it in both boards. 6. **The C140.** Recommend it stays in this board; extract (with C219 as a variant) if a System 21 or NA-1 board ever starts. 7. **The road games.** Recommend scheduling them last and treating MAME as a weak detector there (it marks all of them imperfect); a road model may need evidence MAME does not have. 8. **The link (C139).** Recommend a single-cabinet board with the C139 RAM present and no partner; linked play only if Aubrey wants it.