# Handoff: build `snk-python`, SNK's triple-Z80 boards ## Context you are inheriting - Phase 0 (2026-11-26) left documents, pinned references, a census and a MAME recipe; no emulator code. Read [start-here.md](start-here.md), then [boards.md](boards.md), [cpus-and-shared-ram.md](cpus-and-shared-ram.md) and this brief. - The evidence base is thin and honest: SNK's T.N.K III schematics (SCH-TNK3, tier 2, a hard 1-bit scan of hand-drawn sheets), Yamaha's OPL documents (tier 2), one real-board repair log for Ikari Warriors (OBSERVED), and MAME 0.285 as a closed-box detector. **No hardware capture, no test ROM.** Say so in every claim. - The 68000 boards are another repository, [snk68-python](../snk68-python). ## Decided by Aubrey (standing rules that apply here) - x-python is the specification; MIT; nothing copied or transcribed from GPL/LGPL code; MAME and the FPGA cores are closed boxes ([provenance.md](provenance.md)). - furrtek's work and its lineage are set aside; for these boards that loses nothing known. - Romsets by `MAME_ROMPATH`, read in place; no ROM, PROM or PAL committed. - Reference boards are correct, not fast. Sound is "good enough" next to video. - Technical defaults are taken and marked PROVISIONAL rather than asked. - The chip rule: CPUs get their own core; other chips stay in the board until a second family board needs them. ## Scope All of MAME's `snk.cpp` in the end; built in this order (open decision 2): the A5001 family (tnk3, athena, aso), the Ikari family (ikari, victroad), the 400-wide family (psychos, gwar, bermudat, worldwar, chopper, tdfever, fsoccer), then the AY generation (marvins, madcrash, vangrd2, jcross, sgladiat, hal21). `mainsnk.cpp` (two CPUs) stays out. ## Package and classes (proposed) ```text snk_python/ board.py # SnkBoard: the three CPUs, the order of record, frame stepping cpus.py # CpuPair: main + sub Z80 (z80-python), the doorbells, the arbitration (U2) maps.py # MapA (tnk3, athena, aso), MapB (ikari, victroad), MapC (psychos, gwar ...) video.py # TextLayer, BackgroundLayer, SpriteGenerator (16 and 32), LineBuffer, Palette collision.py # CollisionPorts: the $CE00-$CEE0 / $CB00 reads (U8), PROVISIONAL until shown sound.py # SoundBoard: the sound Z80, the latch and status, FmSocket x 2 snkwave.py # SnkWave: the AY generation's wave generator (in the board, chip rule) inputs.py # Ls30Rotary, joysticks, dial, trackball, DIPs machines.py # one MachineRow per set: map family, clocks, chips, ROM layout romset.py # reads a MAME set from MAME_ROMPATH by CRC, in place ``` **Import boundary.** The board owns everything but the CPUs and the FM chips: decode, RAM, latches, the doorbells, video, the collision ports, inputs, the SNK wave generator. z80-python provides the three CPUs; the proposed `ym3812-python` provides YM3526, YM3812 and Y8950 (decision 1); ay8910-python provides the AYs. ## Sockets | Socket | Filled by | Empty behaviour | | --- | --- | --- | | `FmSocket` (two) | `ym3812-python`'s YM3526, YM3812 or Y8950 | silence; status reads 0, timers never fire (the boot may wait on a timer: then the socket must at least run the timers) | | `AySocket` (two) | ay8910-python | silence; port reads $FF | | `AdpcmRom` | the Y8950's external ROM (MAME region `ym2`) | none | ## What the board needs from its cores - **z80-python** (`1302260`): INT and NMI lines; a reset line for the sub if the main controls it (U4); **if U2 shows WAIT-based arbitration, a per-access wait-state hook**, which z80-python's README places outside its scope today (open decision 3). - **ym3812-python** (to be built): a write port (address/data), a status read (timer flags, and the Y8950's ADPCM flags), a timer IRQ line, the Y8950's external-memory read callback, stepping by input clocks, and samples out at clock/72. ## Unknowns (U) and conflicts (C) | | What | Blocks | Where the answer is | | --- | --- | --- | --- | | U1 | crystals, CPU dividers, dot clock, line and frame length | M1 timing, M2 | SCH-TNK3 (A5001); psychos's `horizon.8j`/`vertical.8k` PROMs (400-wide) | | U2 | how main and sub share RAM: antiphase, WAIT, BUSREQ, split | M1's cycle order; decision 3 | SCH-TNK3 sheet "CPU" (3A/3B/4A/4B, buffers 1A-2C) | | U3 | which games share one board design (A5001, A5004, A6001, A6002 seen) | scope | PAL names, schematics, PCB photos | | U4 | the doorbells: lines raised, acknowledged by read or write; who interrupts the main | M1 | SCH-TNK3; MAME traces as detector | | U5 | the sound latch handshake and MAME's $F800 port | M3 | SCH-TNK3 "SOUND, I/O" | | U6 | the SNK-marked parts on the sound and CPU sheets (relabelled Yamaha parts? a custom?) | M3 | a clearer scan or a board photograph | | U7 | the rotary PROMs' function; ikari's, bermudat's and worldwar's are undumped | M3 (tnk3), M6 | SCH-TNK3 input path; the dumped PROMs (victroad, gwar) | | U8 | the collision ports' logic | M6 | Ikari or Victory Road schematics (not in hand); PAL dumps | | U9 | priority between sprites and layers on maps B and C | M6, M7 | McPhail's "priority circuit on the top board"; schematics | | | Conflict | Sources | Resolution | | --- | --- | --- | --- | | C1 | CPU clock 3.36 MHz on marvins, madcrash, vangrd2 against 3.35 MHz on the rest | MAME | PROVISIONAL per set as MAME has it; settle from the crystals (U1) | | C2 | the brief lists YM2203 and MSM5205 for reuse; no set has either | brief vs MAME listxml | MAME's device lists stand; the reuse list was generic | | C3 | MAME's 60 Hz screens with derived pixel clocks against a real board's timing | MAME vs physics | MAME's numbers are not evidence; U1 | ## The gate (defined at milestone 1, before any second family) See [validation.md](validation.md): main/sub per-instruction lockstep against MAME as a detector for the boot; a per-cycle shared-RAM access log equal between tiers; attract-mode frame hashes; seeded faults listed there. ## Milestones | | Step | Evidence | Exit test | | --- | --- | --- | --- | | M0 | **Read SCH-TNK3 into a document**: clock tree, decode, RAMs, arbitration, doorbells, latch, input path, part list | SCH-TNK3 (2) | `docs/schematic-a5001.md` with every sheet's parts; U1, U2, U4, U5 answered or each narrowed to named nets | | M1 | tnk3 CPU pair: two z80-python cores, map A, shared RAM, doorbells | M0; MAME (5) | main and sub agree with MAME's trace for the first 600 frames of attract, every difference explained against M0 | | M2 | tnk3 video: text, background, 16x16 sprites, line buffers, palette PROMs | M0; MAME snapshots (5) | attract frames 600, 1200, 3600 match MAME's pictures, or each difference is traced to M0 | | M3 | tnk3 inputs and sound CPU: LS-30 rotary, DIPs, the latch, `FmSocket` empty | M0, LS30 docs | the sound command stream equals MAME's for 60 s of attract; the turret turns through 12 positions | | M4 | YM3526 in the socket (after ym3812-python's rungs) | Yamaha (2) | register write streams equal to MAME's; audio "good enough" by ear and spectrum | | M5 | athena (map A, two YM3526), aso | as above | M1-M4's tests on the new sets | | M6 | ikari, victroad: map B, 32x32 sprites, collision ports (PROVISIONAL), Y8950 ADPCM, rotary PROMs | McPhail (OBSERVED); MAME (5) | boots and plays attract; collision ports' reads equal MAME's over 600 frames, labelled detector-only | | M7 | psychos, gwar and the rest of the 400-wide family | timing PROMs (data); MAME (5) | as M6 | | M8 | the AY generation, the SNK wave generator | MAME (5) | as M6 | ## The chip rule | Chip | Family consumers | Where | | --- | --- | --- | | Z80 | many | z80-python | | YM3526 / YM3812 / Y8950 | snk-python, snk68-python, deco16-python, msx-python, ibmpc-python, c64-python | **new core** `ym3812-python` (decision 1) | | AY-3-8910A | many | ay8910-python | | SNK wave generator | this board only (MAME also uses it in Nichibutsu's cclimber.cpp, not a family board) | this board | | collision ports, video, rotary decode | this board | this board | ## Domains and speed Full working in [domains-and-speed.md](domains-and-speed.md). - **Domains:** C (main and sub Z80 sharing RAM, one domain), V (video; its own only if the arbitration gives it slots), A (sound Z80 and FM). **Channels:** the shared RAMs (C to V), the frame interrupt (V to C), the sound latch and the status port (C and A), the doorbells (inside C). - **Need:** 3.35 MHz / 7.17 cycles (OBSERVED) = 0.47 M instructions a second per main or sub Z80, 0.57 M for the sound Z80: **1.5 M a second** (1.7 M on the 4 MHz boards); FM 4 MHz / 72 x 18 slots = **1.0 M slot steps per OPL**, two on most boards; video about 6 M dots a second if the dot clock is near 6 MHz (U1). - **No-JIT path:** x-python on PyPy carries the CPUs easily (z80-python 66.6 M/s base workload on PyPy) and lands near or below real time with FM and per-dot video (acceptable for a reference). **x-rust reaches real time on desktop, phone and browser** (z80-rust about 50 M instructions a second natively, 30 times the need; a phone at a tenth still three times). x-rust-fast (350-400 M/s) only for run-ahead headroom. Threads at the latch are possible and unneeded. `recompile: none` on every target, the iPhone included. ## Open decisions for Aubrey (each with a recommendation) 1. **An OPL core.** Create `ym3812-python` (package `ym3812_python`) covering YM3526, YM3812 and Y8950 (with its delta-T ADPCM and I/O ports) and the YM3014 output, as `ay8910-python` covers its variants; six family consumers today. *Recommend: yes, as its own Phase 0 next, shared with deco16-python's OPL need, before snk-python's M4.* Name alternative: `opl-python` (the family names cores by chip number, so `ym3812-python`). 2. **Scope and order.** *Recommend: A5001 family first (the board we have schematics for), then Ikari and Victory Road, then the 400-wide family, the AY generation last; `mainsnk.cpp` out.* 3. **A WAIT corner on z80-python.** If M0 shows the shared RAM held with WAIT or BUSREQ, the board needs a per-access wait hook z80-python does not offer. *Recommend: decide after M0; if needed, raise it on z80-python (core corner), not as a board-side workaround.* 4. **Ikari Warriors / Victory Road schematics** (U8, U9) are not in hand: arcade-museum.com is set aside by its robots.txt, playright.dk did not answer. *Recommend: Aubrey fetches one himself if he finds it, and it is pinned by SHA-256; until then M6's collision ports are PROVISIONAL, MAME-detector only.* 5. **Undumped rotary PROMs** (ikari, bermudat, worldwar). *Recommend: model the rotary path from SCH-TNK3; use victroad's dumped PROMs for ikari only if the schematics show the same circuit, labelled HYPOTHESIS.* 6. **RndMnkIII's wish** that parallel developments of these games not be based on his core's code. Nothing here is. *Recommend: no action; if snk-python goes public, its README says it is independent of his core and built from SNK's schematics; whether to tell him is Aubrey's call.* 7. **snk68-python as a separate repository** (P.O.W., SAR, Ikari III, Street Smart, Prehistoric Isle). *Recommend: yes; nothing but the sound Z80 is shared (see its brief).*