# Handoff: build `model2-python`, the Sega Model 2 board ## Context you are inheriting Read the charter (emulator-lineage `docs/charter.md`), the late-era method proposal (`docs/proposals/2026-11-late-era-method.md`) and the N64 execution architecture (`../n64-python/docs/execution-architecture.md`) first. Model 2 is era 3 in the charter's table by date (1993-1998) and era 4 by evidence: instruction-level CPUs, functional-level geometry, a rasteriser known only through one emulator. The board embeds new cores that do not exist yet (i960, three DSP families) and existing ones (m68000, z80, ym2612). Read in order: [start-here.md](start-here.md), [board.md](board.md), [geometry.md](geometry.md), [rasteriser.md](rasteriser.md), [sound.md](sound.md), [model1.md](model1.md), [cpu-cores.md](cpu-cores.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` (60 files, about 72 MB; `--verify` to check). ## Scope All four Model 2 revisions as machine rows of one board: original (2O), 2A-CRX, 2B-CRX, 2C-CRX. First row: **2A-CRX** (Virtua Fighter 2: MAME's best-working set, an SCSP board, a TGP copro, the most common drive/billboard periphery). Model 1 is a separate later board (decision M7). Out of scope: Netmerc's 386, linked-cabinet play beyond a loopback comm board. ## Proposed package and classes ``` model2_python/ machine.py # rows: 2O, 2A, 2B, 2C; per-game wiring (sub-boards, protection, inputs) console.py # build(set_name, rompath) -> Model2: reads the MAME zip by CRC, never copies bus.py # the i960's map (board.md), wait-state registers, burst handling irq.py # request/enable registers, timers (25 MHz down-counters) copro.py # FIFOs, upload/boot protocol, the DSP socket (TGP | SHARC | TGPx4) geometrizer.py # GeometrizerDsp (2B/2C, a DSP running uploaded code) | GeometrizerModel (2O/2A) renderer.py # front end: Z-sort, clip, timing budget, polygon count; back end: pixels tiles.py # System 24 tilemaps, palette, colour translation, scan-out sound.py # SoundBoard (68000 + scsp-python) | Model1SoundBoard (68000 + YM3438 + MultiPCM) multipcm.py # YMW-258-F (in-board until a second user) usart.py # the uPD71051 link to the sound board subboards.py # drive (SJ25-0207-01), Model 1 I/O boards, billboard, comm, DSB/DSB2 protection.py # 315-5881, 315-5838, the MAXX PIC savestate.py # the late-era shared state format (schema file beside it) ``` ## The import boundary and sockets The board owns the map, the FIFOs, the renderer, the tilemaps, the periphery and the protection. Cores own their instruction sets and internal state. Sockets: 1. **CoproSocket**: a DSP core with `push_fifo`, `pop_fifo`, `fifo_state`, `upload(words)`, `run_until(t)`; the three DSP cores plug in. 2. **GeometrizerSocket**: either a DSP core (2B/2C) or the functional model (2O/2A), same ports: command input, polygon RAM output, status. 3. **SoundBoardSocket**: the USART byte stream in each direction, with time stamps; a board on its own thread in `-fast`. 4. **SubBoardSocket**: dual-port RAM or serial, per sub-board. 5. **ProtectionSocket**: the address window and its callbacks (the 315-5881 reads code RAM through a callback in MAME's model: M2 `crypt_read_callback`). ## What the board needs from its cores - **i960-python**: `run_until(deadline)` stopping at channel accesses; bus callbacks with burst length and waits; the four interrupt pins or the vector mode; a trace hook. - **mb86233-python / sharc-python / mb86235-python**: FIFO ports as external memory or flag-gated I/O, a host-boot (upload) path, `run_until`, trace hooks. - **scsp-python** (to be extracted from saturn-python's plan): the slot engine, DSP, timers, interrupts, and a sound-RAM port; the 68000 outside. - **m68000-python, z80-python, ym2612-python (`YM3438_ASIC`)**: as they are. ## Milestones | # | Milestone | Judge (tier) | Exit | | --- | --- | --- | --- | | M1 | 2A board skeleton: map, interrupts, timers, the i960 (pinned), FIFOs as plain queues, tilemap and palette registers, the I/O chip, EEPROM | MAME (5) | `vf2` from reset: the i960's instruction stream equal to MAME's for 2 frames, or every difference named | | M2 | Copro: the MB86234 core pinned, the upload/boot protocol, FIFO timing | MB86232 (2, partial), MAME (5) | the copro program uploads and its first N instructions match MAME's `:copro_tgp` trace | | M3 | 2D: System 24 tilemaps, palette, colour translation, scan-out | MAME frames (5) | `vf2`'s 2D layers (text, logo) equal to MAME's frame at a fixed frame number | | M4 | Geometrizer model (2A) and renderer front end (Z-sort, clip, timing, polygon count) | M2V's notes, MAME (5) | polygon lists per frame equal to MAME's HLE output on a slice, or differences named | | M5 | Renderer back end: textures, LOD, microtextures, fill buffer | MAME frames (5) | `vf2` attract frames pixel-compared, every difference classified | | M6 | Sound: 68000 + scsp-python, the USART | SCSP manual (2), MAME (5) | the sound program boots, its USART exchange equals MAME's | | M7 | 2B: sharc-python for copro and geometrizer (uploaded code) | ADSP-21020/2106x manuals (2) | a 2B game (Fighting Vipers or Virtual On) boots to attract; geometrizer output compared with MAME's HLE | | M8 | 2C: mb86235-python | MAME (5) | a 2C game to attract | | M9 | 2O: Model 1 sound board (YM3438, MultiPCM), Model 1 I/O board, drive board | MAME (5) | Daytona USA boots to attract with sound | | M10 | Protection: 315-5881, 315-5838, the MAXX PIC; save states; the slice list | MAME (5) | Dynamite Cop and Dead or Alive boot; a state round-trips; slices defined | Smoke lists before sweeps (Aubrey's rule); no library sweep in Python, ever (late-era method); sweeps run in `model2-rust`. ## The chip rule (summary; detail in cpu-cores.md) New cores: `i960-python` (Phase 0 done), `mb86233-python`, `sharc-python`, `mb86235-python`, and later `v60-python` for Model 1. Extract now: `scsp-python`. In the board: MultiPCM, System 24 tilemaps, 315-5881 (until a second user), the I/O chips, the renderer. ## Unknowns (U) and conflicts (C) | # | Unknown | Best source now | | --- | --- | --- | | U1 | The "Model 2B-CRX Manual" that MAME's authors cite: does a copy exist that may be read? | ask (decision M12) | | U2 | Wait states: the "CPU control (wait-states)" registers at 0x00E00000; MAME keeps them as RAM, and its Sega Rally note says car placement "may need wait state emulation" | none; FITTED | | U3 | The programs MAME patches (Pilot Kids, Zero Gunner interrupt tables): does real hardware survive the bug, and how? | none; a probe on real hardware would decide | | U4 | MB86233/86234 encoding vs the MB86232's | MB86232 data sheet against MAME's disassembler | | U5 | DSP instruction rates per clock: MB86234 at 50 MHz, MB86235 at 20 MHz | MB86232 timing chapter (relative); none for the TGPx4 | | U6 | The renderer's time budget and drop rule | MAME (5) | | U7 | Z-sort arithmetic and window ordering | M2V's quotes of the 2B manual | | U8 | Texture LOD and blend arithmetic; the `video_unk` tables' use | M2V; the table ROMs as data | | U9 | Fill buffer visibility to the CPU | none | | U10 | DSB/DSB2 MPEG layer and decoder quirks | MAME (5) | | U11 | Sound RAM size and 68000 wait states on the SCSP board | MAME's map; none better | | U12 | The 2O/2A geometrizer ROM's behaviour in full (the functional model's fields) | 2B/2C uploaded programs; MAME's HLE | | U13 | FIFO depths and status timing between the i960 and each DSP | MAME's generic FIFOs (depth not checked) | | # | Conflict | Sides | Proposal | | --- | --- | --- | --- | | C1 | Model 1's geometry DSP | this phase's brief: a TMS32025; MAME's PCB notes and `-listxml`: Fujitsu MB86233 | MB86233; correct the brief (decision M2) | | C2 | the number of TGPs | M2's header "(5x TGP)"; MAME emulates one copro and an HLE geometrizer | count from a board photo when one is in hand; irrelevant to the spec's shape | | C3 | the screen timing | M2: "from System 24, might not be accurate for Model 2" | a measured frame rate would settle it; keep MAME's raster as provisional | ## Domains and speed **Domains and channels** (detail in [domains-and-speed.md](domains-and-speed.md)): A main (i960, timers, interrupts), B copro DSP (FIFOs), C geometrizer (geo port, polygon RAM), D renderer (polygon RAM, frame buffers, status), E video (tilemaps, scan-out), F sound (a USART at MIDI-class rate, about 3,125 bytes/s), G sub-boards (dual-port RAM, serial). **Instructions per second, with the arithmetic** (budgets in desktop / phone app / phone browser host cycles per operation = 5.0e9 / 4.0e9 / 2.4e9 divided by the rate): - i960: 10-25 M/s (Intel 10 MIPS average at 25 MHz; one per clock peak): 200-500 / 160-400 / 96-240. - TGP copro (2O/2A): 13-17 M/s (MB86232-like, HYPOTHESIS) to 50 M/s (one per clock): 100-385 / 80-308 / 48-185. - SHARC x2 (2B): 32 M/s each: 156 / 125 / 75 each. - 68000: 1.4-2.8 M/s; SCSP 7.05 M operations/s: comfortable everywhere. - Renderer: 10.95 M visible pixels/s: 457 / 365 / 219 cycles per pixel against 200-400 needed. **Does the no-JIT path reach real time?** Rust `-fast` with cheap time-keeping, then threads at the domain channels (sound and sub-boards first: their channels are the loosest; then the copro behind its FIFOs; then the renderer back end): **yes on desktop and phone app for all revisions; yes in a phone browser for 2O and 2A; at the edge for 2B and 2C**, where the SHARC/TGPx4 pair may need `recompile: wasm` (HYPOTHESIS). A cached interpreter is not expected to be needed (the SH-2 lesson: time-keeping, not decode, is the cost). The renderer needs no GPU; a GPU back end would be turbo. MAME's single-threaded interpreter runs `vf2` at 193 % on one core here (MEASURED), consistent with this. ## Open decisions for Aubrey - **M1. Scope and first row.** *Recommend* one board with four machine rows (2O, 2A, 2B, 2C), 2A first (Virtua Fighter 2), as above. - **M2. Correct the brief's "TMS32025 on Model 1"** to Fujitsu MB86233 (C1). *Recommend* yes. - **M3. Three new DSP cores** (`mb86233-python` with the MB86234 as a variant, `sharc-python`, `mb86235-python`), each with its own Phase 0. *Recommend* yes, by the CPU rule; refuse the in-board alternative. - **M4. The 2O/2A geometrizer as a functional model** (its ROM is undumped), tagged per field and listed in the README as the board's known evidence gap; it is the specification, not a concession, until a dump appears. *Recommend* yes, and a standing note that a dump would replace it with the DSP core. - **M5. Extract `scsp-python` now**, before either Saturn's or Model 2's sound milestone, with the 68000 outside. *Recommend* yes: this board (and Model 3, with two) is the second consumer saturn-python's decision 5 was waiting for. - **M5b. Use MAME's BSD-3 `scspdsp.cpp` as the SCSP DSP's encoding source** (OBSERVED, credited, facts only), closing saturn-python's U13 as a FITTED/OBSERVED model. *Recommend* yes, and tell saturn-python's next session. - **M6. Renderer front/back split, timing from the front end**, with X3's question (does time depend on pixel results?) carried over from the N64. *Recommend* yes. - **M7. Model 1 as a separate board `model1-python`, later, with a `v60-python` Phase 0**; Netmerc (386) out of scope. When it is built, extract the System 24 tilemaps and MultiPCM (two users). *Recommend* yes. - **M8. MAME's BSD-3 Model 1/2 files: read for facts, never transcribed.** Transcription is legal with the notice but would import MAME's guesses as our specification. *Recommend* facts only, credited in docs/sources.md and later docs/provenance.md. This differs from the PlayStation brief's "closed box only" for MAME's BSD files; Aubrey may prefer that stricter line, in which case `reference/mame-bsd/` moves to `trash/`. - **M9. 315-5881 keys.** MAME holds one 32-bit key per game in its BSD-3 driver. They are Sega security values, closer to firmware than to facts. *Recommend* treating them like firmware: never committed; the board reads a key from the player's side (a file beside the romset, or the BSD driver copy in `reference/`) and the census only counts them. - **M10. sources.md rows** (Aubrey's file): MAME's Model 1/2/3 and shared Sega files (BSD-3-Clause, holders as in docs/sources.md, code OK with notice, used for facts); Fujitsu MB86232, Analog Devices ADSP-21020/2106x, NEC V60, TI TMS320C2x documents (facts only); ElSemi's Model 2 Emulator (closed-source freeware: closed box, not run); system16.com and forums.arcade-museum.com (**set aside (site's wishes)**: robots.txt); bitsavers.org (403 on every path from this machine; see M11). - **M11. bitsavers' 403.** *Recommend* recording it as a refusal of this machine, not an AI objection, and keeping the UK Mirror Service copies; Aubrey's call. - **M12. The Model 2B-CRX manual.** *Recommend* asking around (Aubrey's contacts or archives with clear terms) before milestone M4: it is the only manufacturer source for the renderer and Z-sort that anyone cites.