# Handoff: build `dreamcast-python`, the Sega Dreamcast 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 this repository's [start-here.md](start-here.md). The Dreamcast sits between era 3 and era 4 in the charter's table: a 200 MHz dual-issue CPU, thin evidence (no tier-2 documents for the custom chips in use), the specification far too slow for long runs, threads and a recompiler needed for some targets. Boards to model this one on: **saturn-python** (Phase 0: a CD board, boot ROMs by SHA-1, the SCSP, the AICA's ancestor), **psx-python** and **n64-python** (era-3 Phase 0s: domains and speed, CD/HLE choices), **pcenginecd-python** (a CD BIOS run as the program that tests the board, CHD/bin-cue), **sega32x-python** (cores embedded, ROMs by hash in save states). Cores: **sh4-python** (Phase 0 beside this one) and **arm7tdmi-python** (for the ARM7DI variant). Read in order before writing code: 1. [README.md](../README.md), [start-here.md](start-here.md), [memory-map.md](memory-map.md). 2. The chips: [buses-dma-interrupts.md](buses-dma-interrupts.md), [holly-pvr2.md](holly-pvr2.md), [aica.md](aica.md), [gdrom.md](gdrom.md), [maple-vmu.md](maple-vmu.md), [bios-flash.md](bios-flash.md). 3. [domains-and-speed.md](domains-and-speed.md), [census.md](census.md). 4. [sources.md](sources.md), [validation.md](validation.md), [mame-oracle.md](mame-oracle.md). 5. sh4-python's `docs/handoff-brief.md`. Then `python -I scripts/fetch_references.py --verify`. ## Decided by Aubrey (standing rules that apply here) - Name `dreamcast-python`, package `dreamcast_python` (the x-python naming rule). - Local, no remote, until he says otherwise. Bring your own boot ROM, flash and discs; nothing of Sega's in the repository; boot ROMs and factory flash by SHA-1. - 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. - The no-JIT path first (proposals/2026-11-jit.md, accepted): every board meets its stated target with `recompile: none` or says plainly where it cannot (this one cannot everywhere: domains-and-speed.md). - Technical choices are made, marked provisional and reported; policy waits for him. ## Proposed by this Phase 0 - **NTSC US machine first** (`dc-us`: boot ROM v1.01d `8951d1bb...` with the USA factory flash `1efa00ab...`), JP and EU as machine rows (flash images) from milestone 1. - **Drive HLE** behind a `GdromPort` socket at the G1 ATA register level, the player's boot ROM running unchanged (gdrom.md). - **The ARM7DI as a variant of arm7tdmi-python** (aica.md), requested upstream. - **The VMU functional first**, its CPU an optional later core. - **Domains and channels first-class from milestone 1** (domains-and-speed.md): C, V, S, D, M, with the channel table's sync points. ## Package and classes (proposed) ``` dreamcast_python/ machine.py # machine rows: region, boot ROM and factory flash SHA-1s, video standard console.py # build(machine, disc=None, bios_dir=..., flash=...) -> Dreamcast bus.py # the SH-4's physical map: areas 0-7, mirrors, Holly's arbitration and waits holly.py # Holly's system block: interrupt controller (events A/B/C, IRL routing), # G1 and G2 interfaces, the DMA engines (PVR, G1, G2 x4, Maple) ta.py # the tile accelerator: parameter stream, lists, object pointer buffer render.py # the ISP/TSP: per-tile visibility, sorting, texturing, shading, fog textures.py # texture formats: twiddled, VQ, palettes, YUV, strides, mipmaps display.py # the display controller: timing, raster events, scan-out, colour modes aica.py # Aica: channels, envelope, LFO, mixer, DSP, timers, the ARM7DI socket sound.py # SoundDomain: the ARM7DI (arm7tdmi-python variant) + Aica + sound RAM + RTC gdrom_hle.py # GdromHle: ATA registers, packet commands, PIO/DMA reads, CD-DA, timing table disc.py # Redump bin/cue (and GDI, CHD) track reader, IP.BIN parser maple.py # the Maple DMA engine and frame routing devices/ # controller.py, vmu.py (functional), keyboard.py, mouse.py, purupuru.py flash.py # the flash chip: command protocol, partitions, write-back sockets.py # the socket Protocols (GdromPort, MaplePort, VmuCpu) and test fakes savestate.py # whole-machine states naming boot ROM, flash and disc by hash ``` ## What the board needs from its cores (the embedding contracts) From **sh4-python** (its brief, "The import boundary and the sockets"): the bus interface with transaction kinds and I-clock times; IRL3-0 driven by Holly; NMI; the DMAC channel 2's DREQ/DACK for PVR DMA; little-endian mode; a snapshot that round-trips. Raised there already as part of its scope. From **arm7tdmi-python** (a request, open decision 5): an ARMv3 variant (`ARM7DI`): Thumb, BX, long multiplies and halfword/signed transfers removed (their encodings undefined), ARM7DI ch. 9's cycle operations for MUL/MLA, optional 26-bit configuration; the existing per-cycle bus callback (N/S/I/C) stays, the board charges sound RAM waits. ## The gate (defined at milestone 1) The board's lockstep cases (the boot ROM's SH-4 instruction stream from reset against MAME's trace, `0 unexplained` over a fixed number of instructions; the ARM7's stream from its release), unit tests of the documented facts, and picture rows against MAME's snapshots (frames 300 and 600 of the boot ROM, every difference triaged). Seeded faults: validation.md's list. ## Milestones | # | Milestone | Judge (tier) | Exit | | --- | --- | --- | --- | | M1 | **Bus, Holly's interrupt controller and register file, the flash, the display controller's timing (raster events, V-blank), Maple DMA with an empty port, the AICA register file with the ARM7 held in reset, the sockets and fakes** | KOS, Comstedt (3); MAME stream (5) | the boot ROM's SH-4 stream equal to MAME's for the first 1 M instructions or a named reason per difference (in PyPy that is minutes, not hours) | | M2 | **The TA and the renderer, opaque and punch-through lists, the textures the boot ROM uses** | KOS, Comstedt (3); MAME pictures (5) | the boot ROM's swirl (frame 300) drawn; pixel differences triaged | | M3 | **Translucent lists with sorting, modifier volumes, fog; the Set Date/Time dialog; Maple controller** | the same | the dialog (frame 600) drawn and answerable with a scripted controller | | M4 | **Sound**: the ARM7DI variant, AICA channels, timers, interrupts; the DSP per U11 | ARM7DI (2); MAME audio (5) | the boot ROM's sounds play; audio compared with MAME, differences named | | M5 | **GD-ROM (drive HLE)**: ATA registers, packet commands, G1 DMA, CD-DA, bin/cue; the boot ROM's disc check and IP.BIN boot | the boot ROM accepting a disc (program); KOS, Comstedt (3) | 5 games of a smoke list reach their licence screens (in the Rust transcription for length; the Python board for the first frames and the packets) | | M6 | **The VMU (functional), rumble, keyboard, mouse; flash write-back; save states** | Comstedt (3) | a game saves to and loads from a VMU; a save state loads into a fresh machine and continues identically | | M7 | **The MMU path for Windows CE titles; MIL-CD boot (descrambling, Mode 2)** | the boot ROM and the titles (programs) | one Windows CE title and one MIL-CD reach their first screens | | M8 | **The LLE VMU** (only by decision 6): `lc86k87-python` pinned, the VMU's own firmware | Comstedt *vms/cpu* (3); MAME `svmu` (5) | a VMU mini-game runs on the LLE VMU | Full Redump sweeps only in a Rust tier and only when the board might be ready (Aubrey's smoke-sweep rule); the Python board never sweeps. ## The chip rule (existing family cores first) | Chip | Users in or near the family | Existing family core | Proposal | | --- | --- | --- | --- | | SH-4 (SH7091) | Dreamcast; NAOMI, NAOMI 2, Atomiswave (MAME sets present) | none; sh2-python is related (all 142 SH-2 encodings kept) | new core `sh4-python` (Phase 0 done beside this) | | ARM7DI (in the AICA) | Dreamcast, NAOMI, Atomiswave | arm7tdmi-python (ARMv4T) | a variant of arm7tdmi-python, requested upstream (decision 5) | | AICA (channels, DSP) | Dreamcast, NAOMI, NAOMI 2, Atomiswave | none; saturn-python's SCSP (in-board) is its ancestor | stays in the board behind a pin-shaped class; extract as `aica-python` when a NAOMI board needs it | | Holly / PowerVR2 CLX2 | Dreamcast, NAOMI, Atomiswave (NAOMI 2 adds Elan) | none | stays in the board | | GD-ROM drive (HLE) | Dreamcast (NAOMI GD-ROM uses a different DIMM board) | none | board (socket) | | Maple and its devices | Dreamcast; NAOMI's MIE bridges Maple to JVS with a Z80 (MAME `mie`) | z80-python would serve the MIE later | board | | VMU CPU (LC86K87 family) | the VMU only | none | optional new core `lc86k87-python` (decision 6) | | Flash (MBM29LV002TC) | Dreamcast | none | board | ## Unknowns (U) and conflicts (C) **Unknowns** (the best source for each; none settleable without hardware or Sega's documents unless noted): | # | Unknown | Best source now | Status | | --- | --- | --- | --- | | U1 | mirrors inside areas 0-6; what unused areas return | MAME (5) | detector; tag HYPOTHESIS | | U2 | the modem/expansion and G2 expansion addresses | Comstedt *hw*, KOS | read KOS's modem and BBA drivers | | U3 | DMA bandwidth and arbitration against the CPU (PVR, G1, G2, Maple) | none | FITTED, one table | | U4 | each Holly event's exact time; edge or level; acknowledge rules | KOS `asic.c` (3) | read the driver; FITTED times | | U5 | the TA's parameter formats in full (headers, every vertex type, sprites, modifier volumes) | KOS `pvr.h`, `pvr_header.h` (3) | transcribe from KOS; MAME pictures as detector; Sega's TA document if decision 1 allows | | U6 | ISP depth formats and comparisons (1/w) | none in use | detectors | | U7 | translucency auto-sort's exact rules and limits | none in use | detectors | | U8 | modifier volumes (inclusion/exclusion, cheap shadow) | KOS (3) partly | detectors | | U9 | texture filtering arithmetic, mipmap selection, VQ decoding details | KOS (formats only) | detectors | | U10 | TSP colour combine, specular offset, fog arithmetic, dither | KOS (modes only) | detectors | | U11 | **the AICA DSP's instruction encoding and arithmetic** | MAME's `aicadsp.cpp` is BSD-3-Clause but closed by this batch's brief; Sega's AICA manual behind decision 1 | blocks the DSP; see decision 7 | | U12 | the AICA's register map in full | KOS (3) | transcribe KOS; the rest by detector | | U13 | the CD-DA path from drive to AICA | none | HYPOTHESIS by the Saturn's analogy | | U14 | the ARM7DI's handling of ARMv4 encodings (undefined trap or other) | ARM7DI ch. 4 (2) | read in full at the arm7tdmi-python request | | U15 | sound RAM arbitration and waits (ARM7, channels, DSP, G2) | none | FITTED | | U16 | the AICA's sample clock and output rate | MAME 22.57 MHz (= 512 x 44.1 kHz) | HYPOTHESIS 44.1 kHz | | U17 | the high-density area's start address in the drive's TOC | none read | read KOS `cdrom.c` TOC handling | | U18 | the GD-ROM packet command set in full | KOS (3) partly | transcribe; detectors | | U19 | a drive firmware dump (for LLE) | none | LLE impossible now | | U20 | drive seek, spin-up and transfer timing | none | FITTED, one table | | U21 | the GD-ROM security exchange the boot ROM performs | none | detectors; the boot ROM itself is the test | | U22 | Maple response timing per device | none | wire time + FITTED device delay | | U23 | the VMU CPU's clocks (32.768 kHz and a faster oscillator?) | Comstedt *vms/* (3) | read in full before M8 | | U24 | the flash chip's command protocol | Fujitsu's data sheet if found (2) | JEDEC-style default | **Conflicts** (sources disagree): | # | Conflict | Sides | Proposal | | --- | --- | --- | --- | | C1 | flash size | Comstedt: "Flash ROM (256K)"; MAME images and KOS partitions: 128 KB; MAME's chip: a 2-Mbit part | model 128 KB of contents in the window MAME shows; record Comstedt's figure | | C2 | pixel clock / sync totals | Comstedt's register values read minus-one: 27.0 MHz family; MAME's screen: 26.91 MHz | minus-one reading (HYPOTHESIS), MAME's in a comment; settle by document or hardware timing | | C3 | the VMU's CPU | Comstedt: Sanyo LC86K87, "code compatible with the LC86000 series"; MAME: Sanyo LC8670 | same family (HYPOTHESIS); name the future core after the part on the VMU's board once a photo or document shows it | | C4 | the ARM7's clock | MAME: 2.82 MHz; common descriptions of the AICA's ARM: a much faster core clock (not from any source pinned here) | MAME's figure as the effective rate, tagged OBSERVED; settle with a timing test | | C5 | the SH-4's instruction rate | Hitachi via Comstedt: 360 MIPS (1.8 a cycle); MAME: 0.73-0.78 a cycle | neither is a game measurement; the board counts its own | ## Open decisions for Aubrey (each with a recommendation) 1. **Sega Retro's anti-AI wall.** Sega's Dreamcast documents (system architecture, Holly's TA and CORE, the AICA manual) appear to be hosted only on segaretro.org, which challenges every request "to protect the server against the scourge of AI companies aggressively scraping websites". Nothing was fetched. *Recommend* treating it as the site's wish and not working around it; if Aubrey wants the documents, he fetches them himself (or asks Sega Retro's operators), places them where the repository's fetch script can verify them by SHA-256 from a local path, and the agent uses them for facts only, as the Saturn's are. Without them the TA formats, the renderer's rules, the AICA DSP and the GD-ROM packets stay at tier 3 or detector level. 2. **Scope and first machine.** *Recommend* the NTSC US console (v1.01d, USA flash) first, JP and EU as flash rows; development boxes later as rows; NAOMI/Atomiswave as separate boards that pin this one, not started. 3. **Accept that the no-JIT path does not reach every target.** *Recommend* the capability statement in domains-and-speed.md: real time with `recompile: none` on fast desktop cores for typical software; phones and browsers need recompilation or named concessions. The first family board to say so. 4. **GD-ROM: drive HLE, no BIOS HLE in the specification.** *Recommend* drive HLE behind a socket at the ATA level, the player's boot ROM always running; a BIOS HLE only ever as a turbo-tier concession for players without a boot ROM, and only if Aubrey wants that policy. 5. **The ARM7DI as an arm7tdmi-python variant.** *Recommend* raising the request upstream now (Thumb, BX, long multiplies and halfword transfers off; ARM7DI ch. 9 timing) rather than a new repository; the ARM7DI is the same pipeline family. 6. **The VMU's CPU.** *Recommend* the functional VMU in the board (milestone 6) and a new core `lc86k87-python` only if Aubrey wants VMU games played (milestone 8, optional). 7. **MAME's BSD-licensed Dreamcast files.** `aicadsp.cpp` (the AICA DSP, BSD-3-Clause by its header), `powervr2.cpp`, `maple-dc.cpp`, `gdrom.cpp`, `sh4*.cpp`, `lc8670.cpp` are BSD, which sources.md would normally allow as "code OK (with notice)"; this batch's brief treats all of MAME as closed, and psx-python left the same question open. *Recommend* allowing facts from `aicadsp.cpp` only (the DSP encoding, U11, has no other source without decision 1), with the notice kept, and keeping the rest closed. 8. **The renderer's form on weak targets.** The exact software renderer is the specification; a GPU renderer (WebGL/Metal) would be a named concession (not bit-exact) in a turbo tier. *Recommend* deciding only when a host needs it; record it now as the expected concession for phones and browsers. 9. **NAOMI, NAOMI 2, Atomiswave.** MAME's sets are present. *Recommend* no work until the Dreamcast board reaches M5; then a Phase 0 for `naomi-python` pinning this board, which triggers the AICA's extraction (chip rule). 10. **sources.md rows.** *Recommend* adding the rows proposed in [sources.md](sources.md), including Sega Retro as "set aside (site's wishes), pending Aubrey". 11. **profile-env**: add `DREAMCAST_BIOS_DIR` (the loose BIOS directory the census reads) to the family's environment profile beside `SEGA32X_BIOS_DIR`. *Recommend* yes, pointing at the user's own BIOS folder.