# Handoff: build `namcos1-python`, the Namco System 1 board ## Context you are inheriting The family's shape: chips are cores, boards compose cores; CPUs always get their own core; a non-CPU chip used by one family board stays in that board and is extracted when a second needs it; never copy a file between repositories, pin the sibling by commit. Read the charter first (emulator-lineage `docs/charter.md`), then [start-here.md](start-here.md). System 1 is era 2 in the charter's table (several CPUs, still cycle-lockstep; `-fast` needed on weak targets; threads optional). 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), [keys-and-protection.md](keys-and-protection.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, ~54 MB; `--verify` to check). **The board cannot start before its CPU cores exist.** m6809-python is Phase 0 only (no core), m6800-python has no HD6301 variant, ym2151-python is Phase 0 only. The order of work is in "Milestones" below. ## Scope In: the 40 System 1 sets of MAME 0.285's `namcos1.cpp` (20 games). Out: `tankfrceb` (a bootleg on other hardware), hosts, windows, sites. ## Package and classes (proposed) ``` namcos1_python/ machine.py # set table: ROM regions by SHA-1 (from -listxml), orientation, key type per game romset.py # read a MAME zip in place, verify by SHA-1, build the regions board.py # build(set, rompath) -> System1; the order of record; save states by hash c117.py # Cus117: the 23-bit space, per-CPU bank windows, IRQ and reset lines keys.py # the key customs, one functional model per key type (FITTED from traces) video.py # C116 palette, C123 tilemaps, sprite generator, screen timing (pin-shaped # classes: candidates for extraction with namcos2-python, decision 4) sound.py # SoundDomain: sound 6809 + ym2151-python + Cus30 + bank logic cus30.py # Cus30: Namco 8-voice wavetable (in-board, pin-shaped) mcu.py # McuDomain: the HD6301-variant core + its on-chip ports/timer/SCI, # inputs, DIP switches, DACs, NVRAM, voice-ROM bank triram.py # the three-port RAM channel ``` ## What the board needs from its cores From **m6809-python** (three instances): the MC6809E instruction set with E-cycle counts; host-owned `read_byte`/`write_byte`; NMI, FIRQ, IRQ, RESET as inputs the board drives; a held reset. Nothing beyond its handoff brief. From **m6800-python**: an **HD6301 variant** (U07's instruction set and cycle counts, the trap) with a Namco CUS6x flag for op-codes $12/$13 (jrok: "add the value at the top of the stack to the X register"), and the HD63701V0's on-chip ports, 16-bit timer and SCI (decision 3). The CUS64 firmware uses `OIM` (OBSERVED), so the variant is required. From **ym2151-python**: write port, status (BUSY, timer flags), IRQ output, stereo samples at clock/64; what cps1-python asks of it. ## Milestones | # | Milestone | Judge (tier) | Exit | | --- | --- | --- | --- | | C0 | **Cores first**: m6809-python rungs (its brief); m6800-python's HD6301 variant with its own rungs (U07 tables, MAME `hd63701v0` lockstep on the CUS64 firmware) | DOC (2) / MAME (5) | each core's ladder green | | M1 | **Main domain skeleton**: romset loading by SHA-1, the CUS117 space as observed, bank windows (U1), the main and sub 6809s, RAM, IRQ/reset lines, screen timing | MAME trace (5), detector | main-CPU instruction stream equal to MAME's for 120 frames of Pac-Mania from reset, or a named reason per difference | | M2 | **All four CPUs**: sound 6809 and MCU domains, triram, the release at frame 110; inputs, DIP switches, NVRAM | MAME traces (5) | all four streams equal to MAME's for 240 frames of 3 smoke games (Pac-Mania, Galaga '88, Splatter House) | | M3 | **Keys**: the key window traced per game; functional key models | MAME traces (5) | every one of the 20 games past its key check, the key's observed pairs as tests | | M4 | **Video**: C116, C123 layers, sprites, priority | MAME pictures (5) | the smoke games' attract screens; every pixel difference triaged | | M5 | **Sound**: YM2151 (pinned), CUS30, DACs, the mix | MAME audio (5); ym2151-python's own judges | register-write streams equal to MAME's; audio differences named | | M6 | **Library**: all 40 sets; save states | detectors | each set reaches gameplay in a smoke run; a save state continues identically in a fresh board | Smoke lists before sweeps (Aubrey's rule); no full-library sweep until M6. ## The chip rule | Chip | Users in or near the family | Proposal | | --- | --- | --- | | MC6809E x 3 | System 2 (sound), Vectrex, Williams, System 86 | m6809-python | | HD63701V0 / CUS64 | System 86, Baraduke, Pac-Land, Sky Kid, Thunder Ceptor (MAME); none built | HD6301 variant in m6800-python (decision 3) | | YM2151 | cps1-python, namcos2-python, system16-python | ym2151-python | | C116 + C123 | **namcos2-python** (and NB-1, FL in MAME) | in-board now, extract as `namco-c123-python` at namcos2's video milestone (decision 4) | | CUS30 | none in the family (emu-galaga models the different 3-voice WSG) | in-board, pin-shaped | | CUS117, sprite chip, keys, DACs | System 1 only | in-board | ## Unknowns (U) and contradictions (C) | # | Unknown | Best source now | | --- | --- | --- | | U1 | the CUS117's bank windows: size, registers, which CPU owns which | MAME traces with watchpoints; MAME's BSD `c117.cpp` (decision 1) | | U2 | interrupt sources and timing for each CPU (vblank, raster, sub/sound/MCU) | traces | | U3 | the CUS64's $00 -> $A6 write oddity seen by jrok with a stock HD63701 | jrok (tier 3), unexplained; model only if a game shows it | | U4 | C123 layer formats, line scroll, priority | MAME pictures | | U5 | sprite format, size, zoom (if any), the list copy trigger | MAME pictures and traces | | U6 | C116 colour output (bits per gun, shadow/highlight) | MAME pictures | | U7 | the per-game key types and their algorithms | traces (FITTED) | | U8 | DAC levels, the analogue mix, filters | none | | U9 | whether the HD63701's on-chip timer/SCI are used by the CUS64 firmware | trace | | U10 | the master crystal (49.152 MHz is arithmetic only) | a board photograph or manual | | U11 | power-on RAM contents | none; option for zeros or random | | # | Contradiction | Sides | Proposal | | --- | --- | --- | --- | | C1 | number of 6809s | task brief: four; MAME and jrok: three plus the HD63701 | three (OBSERVED and stated by jrok) | | C2 | number of Namco sound chips | jrok: "two Namco 8-channel custom sound chips"; MAME: one `namco_cus30` (stereo) | follow MAME's observable stereo output until a board photo settles the part count | | C3 | the MCU's RAM size (checked, no conflict) | U07's HD63701V0 notes: "128 Bytes of RAM"; jrok: 128; MAME map: $80-$FF | agreed: 128 bytes | ## Domains and speed Summary of [domains-and-speed.md](domains-and-speed.md): - **Domains**: main (main + sub 6809 + CUS117 + video + key), sound (sound 6809 + YM2151 + CUS30), MCU (HD63701 + DACs + I/O). **Channels**: the 2 KB triram (three ports), the CUS30 window (main and sound), the reset and interrupt lines from the CUS117. - **Need**: 6.144 M CPU cycles a second (4 x 1.536 MHz); ~1.11 M instructions a second measured (Pac-Mania, 2.21 M in 2 s across the four); 6.144 M video dots a second. - **No-JIT path**: plain Rust is ~2% of a desktop core for instructions; the lockstep board is about a Mega Drive's load, so by megadrive-rust's 4-6x, **real time on desktop and in a desktop browser in plain Rust** (HYPOTHESIS, scaled); **phones need `-fast`**, the phone browser `-fast` plus a cached interpreter (all code in ROM: no invalidation problem). Threads at the triram are unlikely to pay (polled constantly); picture and audio producers can run beside. `recompile: none` should meet every target. ## Open decisions for Aubrey (each with a recommendation) 1. **MAME's BSD-3-Clause Namco files.** Every MAME file for these boards (`namcos1*.cpp`, `c117.cpp`, `namco_c116/c123tmap.cpp`, `sound/namco.cpp`, the CPU cores) carries `license: BSD-3-Clause` (59 files checked at `mame0285`, [sources.md](sources.md)), which the family register calls "code OK (with notice)". This Phase 0 kept them closed as told. Without them, the CUS117 banks, the keys, the CUS30 and the video formats must be reconstructed by observation (slow, FITTED). **Recommend: allow reading them for facts, cited with their notice in NOTICE.md (the PC Engine precedent), not transcribed**, and record which facts came from where; the alternative (observation only) is possible but multiplies M1-M5. 2. **Board order.** Recommend **System 1 before System 2**: smaller, 8-bit, and its C116/C123 work transfers to System 2; but it needs two cores built first (m6809-python core, m6800-python HD6301 variant). 3. **The HD63701 / CUS64.** Recommend an **HD6301 variant in m6800-python** (with a `namco_cus6x` flag for $12/$13) and the HD63701V0's on-chip ports/timer/SCI as a peripheral module there, not a new repository; it is a public, released core, so this is its next minor version. 4. **C116 + C123 extraction.** Recommend building them in namcos1-python behind pin-shaped classes and extracting them with history as `namco-c123-python` when namcos2-python's video milestone needs them (the second family consumer). 5. **CUS30 vs the WSG.** Recommend keeping the CUS30 in this board; no family "namco-wsg" core now (emu-galaga's 3-voice WSG is a different register map and lives in a site project outside the x-python shape). Revisit if a System 86 or Pac-Land board starts. 6. **Keys as functional models.** Recommend one functional model per key type, FITTED from MAME traces of each game's key window, tagged so, with the traces as tests (or, under decision 1, from MAME's BSD key code as facts). 7. **sources.md rows** (emulator-lineage): the six rows proposed at the end of [sources.md](sources.md), including system16.com and vgmrips.net as set aside (site's wishes). 8. **m6809-python's Python floor** says 3.12+; the family floor is PyPy's 3.11. Recommend the core's build session take 3.11 (raise on that repository, not changed here).