# Handoff: build `segasys24-python`, Sega's System 24 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 machine stays in its board and is extracted only when a second family project 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). Boards to model this one on: **megadrive-python** (a 68000 board with per-dot video and an FM chip), **system16-python** (Phase 0: Sega's 68000 arcade board, the FD1094, MAME romsets by environment variable), **segacd-python** (a second 68000 released by the first, a drive stepped on CPU clocks: the charter's precedent for the floppy). Cores it embeds, read and not touched by this phase: **m68000-python** (twice), later **ym2151-python**. Read before writing code: [boards.md](boards.md), [floppy.md](floppy.md), [protection.md](protection.md), [video.md](video.md), [sound.md](sound.md), [system32.md](system32.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` (4 files, about 27 MB; `--verify` to check). ## Scope System 24: the ROM-board sets and the plain floppy sets first, the FD1094 sets after, all 27 of MAME's machines in the end. System 32 and Multi 32 are **not** in this board's scope: they go to a sibling (decision 3), seeded by [system32.md](system32.md). ## Decided by Aubrey (standing rules that apply here) - Name `segasys24-python`, package `segasys24_python`. Local, no remote, until he says otherwise. - Romsets through `MAME_ROMPATH` (non-merged), never a machine path; no ROM, floppy image, BIOS or key committed; the BIOS ROMs identified by SHA-1 ([census.md](census.md)). - MIT; nothing copied or transcribed from GPL/LGPL code; MAME is a closed box (its files' `license:` lines only). - Python floor = PyPy's (3.11), PyPy must work; modern over compat; reference boards are correct, not fast; sound may be less exact than pictures; smoke lists before sweeps. - Technical choices are made, marked provisional and reported; policy waits for him. ## Package and classes (proposed) ``` segasys24_python/ machine.py # rows: BIOS (epr-11338/9 or epr-12186/7) or ROM board; sub CPU plain or FD1094; controls romset.py # load a MAME set from MAME_ROMPATH; CRC/SHA-1 checks; BIOS by SHA-1 console.py # build(machine, rompath=...) -> System24 bus.py # the main and sub CPUs' maps, shared RAM, the sub CPU's hold and release io5296.py # the Sega 315-5296 I/O chip (pin-shaped: System 18 and 32 have it too) floppy.py # FloppyImage (MAME .img -> track/side/sector) and the controller (U3) romboard.py # the ROM-board sets' mapping (U5) timers.py # the board's interrupt timers (U4) tilemap.py # the System 24 tilemap (to extract later: decision 4) sprites.py # the System 24 sprites mixer.py # the mixer, palette, priority sound.py # the YM2151 socket and the DAC controls.py # MSM6253 ADCs, uPD4701A encoders, switches fd1094.py # the FetchFilter socket on the sub CPU (shared with system16-python: decision 5) sockets.py # the socket Protocols and their test-only fakes savestate.py # whole-machine states naming the set by machine name and ROM hashes ``` ## The import boundary The **cores** own instruction semantics and bus timing: the 68000s (prefetch, function codes, interrupt acknowledge, /HALT and reset), the YM2151. The **board** owns every decode, the shared RAM, the sub CPU's control, the floppy and its controller, the ROM board, the video chips, the I/O chip, the DAC, the controls and the FD1094 filter. ## Sockets | Socket | Fills it | Empty or fake | | --- | --- | --- | | `FmSocket` | ym2151-python when its rungs land | a silent fake keeping registers and timer flags | | `Media` | `FloppyImage` + controller, or `RomBoard` | the machine row picks one | | `FetchFilter` (sub CPU program reads) | FD1094 with the set's key | identity | | `Controls` | the ADCs and encoders per game | neutral inputs | ## The gate (defined at milestone 1, before any socket is filled) Unit tests of documented facts; the main 68000 lockstep from power-on against `scripts/mame_trace.py` (`0 unexplained` over N frames), then the sub's after the load; later the pictures ([validation.md](validation.md)). ## Milestones | # | Milestone | Judge (tier) | Exit | | --- | --- | --- | --- | | M1 | **Main CPU on a ROM-board set** (`dcclub` or `qrouka`): map, RAM, I/O chip, timers, interrupts, the sub CPU's release; video RAMs as plain memory | MAME (5) as detector; decisions 1-2 for facts | main 68000 stream equals MAME's for 120 frames, or each difference has a named reason | | M2 | **Both CPUs on the ROM-board set** | MAME (5) | the sub's stream equals MAME's for N frames | | M3 | **The floppy**: `FloppyImage`, the controller, the BIOS's load on `hotrod` (early format) and `bnzabros` (later) | MAME (5); [floppy.md](floppy.md)'s arithmetic | the main CPU's stream through the load equals MAME's; the sub starts at the same cycle (8.9 s on `hotrod` in MAME) or the difference is named | | M4 | **Pictures**: tilemap, sprites, mixer, palette at 496 x 384 | MAME snapshots (5) | `hotrod` attract frames against `--snap`, every pixel difference named | | M5 | **YM2151 and DAC**: pin ym2151-python | its ladder; MAME audio (5) | music and samples; differences named | | M6 | **FD1094** (decision 5) | AHFD (3); MAME (5) | `gground`, `crkdown`, `sgmast`, `roughrac`, `qsww` boot and lock-step after the load | | M7 | **Smoke list and states** | the gate | a state saved in play loads into a fresh machine and continues bit-identically (MAME itself does not support states for these sets) | ## Unknowns (U) and conflicts (C) | # | Unknown | Best source now | Status | | --- | --- | --- | --- | | U1 | crystals, a measured frame rate | MAME: 10 MHz CPUs, 16 MHz dots, 57.524 Hz | MAME's, HYPOTHESIS | | U2 | the memory maps: which page is which chip; shared RAM; the sub CPU's hold and release | MAME traces (5) | decision 1 or 2 | | U3 | the floppy controller, sector layout, image order, load timing | sizes (arithmetic), MAME (5) | one sector of each size, HYPOTHESIS | | U4 | interrupt and timer sources and rates (MAME has five timer devices) | MAME (5) | decision 1 or 2 | | U5 | the ROM board's mapping | MAME (5) | M1 | | U6 | which CPU drives the YM2151 and the DAC; YM2151 /IRQ | MAME (5) | M5 | | U7 | tilemap layers, scroll, character format (patterns in RAM) | none | decision 1 or 2 | | U8 | sprite format, zoom, limits | none | as U7 | | U9 | mixer priority and blending, palette format | none | as U7 | | U10 | line timing inside 656 x 424 (where the interrupts fall) | MAME (5) | as U7 | | # | Conflict | Sides | Proposal | | --- | --- | --- | --- | | C1 | Model 2's agent recommends extracting the System 24 tilemap "when Model 1 is built"; the chip rule says at the second consumer, which Model 2's own M3 already is | model2-python decision M7; charter | extract at the second build, whichever comes first (decision 4) | | C2 | the task brief calls System 32 "a row or sibling" | this Phase 0's evidence: nothing shared but the I/O chip | sibling (decision 3) | ## Domains and speed - **Domains**: C (both 68000s, shared RAM, I/O, FDC, YM2151 and DAC writes), V (tilemap, sprites, mixer), F (the drive, steppable inside C), A (audio, a pure producer). **Channels**: the video RAMs, the interrupts, the FDC registers and data, the YM2151 writes and DAC byte, the I/O chip. Detail: [domains-and-speed.md](domains-and-speed.md). - **Instructions a second**: main 68000 10 MHz / 14.8 cycles in play = 0.68 M (1.23 M while loading at 8.2); sub 10 MHz / 10.9-13.0 = 0.77-0.92 M (OBSERVED in MAME). **About 1.6 M CPU instructions a second**, plus 2.0 M YM2151 operator steps and 16.0 M dots (656 x 424 x 57.524). - **The no-JIT path**: the Python specification is below real time on PyPy with FM and per-dot video (HYPOTHESIS until measured; megadrive-python's precedent). **segasys24-rust reaches real time on desktop, phone and browser without -fast**: m68000-rust's 134 M (native) and 112 M (WebAssembly) instructions a second are about 70 times the need; the 16 M dots are the budget. `-fast` for run-ahead headroom; threads (video as a producer) only if a phone asks; `recompile: none` everywhere, the iPhone included. System 32's V60 (about 2 M instructions a second in MAME's flat model) is expected to need no JIT either, with a cached interpreter as the fallback. ## The chip rule | Chip | Users in or near the family | Proposal | | --- | --- | --- | | 68000 (and FD1094 as a 68000 with a filter) | many | m68000-python; the FD1094 filter written once (decision 5) | | YM2151 | cps1-python, system16-python, this board | ym2151-python | | System 24 tilemap | this board, Model 1, Model 2 | here first, extract at the second build (decision 4) | | 315-5296 I/O | System 18, System 24, System 32 | in the board, pin-shaped; extract at the second build | | V60/V70 | System 32/Multi 32, Model 1 | new `v60-python` (decision 2) | | V25 | System 32 (6 sets) | a row of a future V20/V30 core (decision 7) | | uPD7725, YM3438, RF5C68, MultiPCM | upd7725-python, ym2612-python, segacd-python/System 18, model2-python | for the sibling ([cpu-cores.md](cpu-cores.md)) | ## Open decisions for Aubrey (each with a recommendation) 1. **MacDonald's s24tech.txt and s32tech.txt.** Their host's robots.txt disallows the folder to every crawler, so I did not fetch them. They are the tier-3 source for almost every unknown above. *Recommend*: you fetch the two files yourself, the repository pins them by SHA-256 marked "fetched by Aubrey", and they are used for facts only with his requested credit (his notes' Disclaimer asks for credit and forbids re-hosting or direct links); and decide whether the earlier agent fetches from that folder (system16-python, saturn-python, megadrive-python) stand. 2. **v60-python.** *Recommend* one `v60-python` Phase 0 serving Model 1 (model2-python's M7) and System 32 / Multi 32 (a V70 row), started when either board is next; its timing has no source in hand (V60PRM has none, MAME charges 8 cycles flat), so a V60 hardware manual or data sheet with clock counts should be its first search. 3. **System 32: sibling, not row.** *Recommend* a separate `segasys32-python` with Multi 32 as its row, after v60-python; move [system32.md](system32.md) and the System 32 census rows into it then. 4. **The System 24 tilemap.** *Recommend* specifying it here, behind a pin-shaped class, and extracting it with history at the second family build (Model 2's M3 or Model 1, whichever comes first), so Model 1, Model 2 and System 24 pin one specification. 5. **One FD1094 for System 16, 18 and 24.** *Recommend* writing the FD1094 fetch filter once, in whichever board reaches it first, and extracting it as a small shared module (it is board code around the 68000, not a CPU core) when the second needs it; its algorithm decision is system16-python's decision 3/4 (MAME's BSD-3 `fd1094.cpp` read for facts, or not). 6. **MAME's BSD-3 System 24 files for facts.** No tier 1-3 source is in hand if decision 1 is no. *Recommend* yes for `segas24.cpp`, `segas24_v.cpp`, `segaic24.cpp` (facts, never transcribed, notice in NOTICE.md), as model2-python recommends for its Model 1/2 files (its decision M8) and pcenginecd-python did for `msm5205.cpp`; prefer MacDonald's notes where both speak. 7. **The V25.** *Recommend* a V25 row on a future V20/V30 core (irem-python's Phase 0 is weighing V30/V33) rather than its own repository; needed only for 6 System 32 sets. 8. **First machine.** *Recommend* a ROM-board set (`dcclub`) for M1-M2, which avoids the floppy until M3, then `hotrod`. 9. **sources.md rows**: the five proposed in [sources.md](sources.md) (the two set-aside sites; NEC's V60 and V25 documents, with the V60 manual's lack of timings; MAME's System 24/32 files with their `license:` lines and the V60's flat timing; `ym2151.txt` as GPL).