# Handoff: build `cdi-python`, the Philips CD-i board ## Context you are inheriting Chips are cores, boards compose cores; the board pins its cores by commit. The CPU is an SCC68070, a 68000 with a different microarchitecture and five on-chip peripherals; this brief proposes a new core **scc68070-python** that pins and subclasses the public **m68000-python** (`../m68000-python`) for the instruction semantics (decision 1). The slave and servo processors are MC68HC05C8s: the CD-i is the second family board (after the PlayStation's CD controller) to need **mc68hc05-python** (decision 3). Era 2 by structure (several CPUs, cycle-lockstep), with a CD drive domain like segacd-python and pcenginecd-python. Nearest models in the family: `segacd-python` and `pcenginecd-python` (disc boards, Redump images through `REDUMP_DIR`), `sega32x-python` (catch-up at the channel, domains.md), `gameboy-python`'s SGB (a functional model judged by a lower-level run: the functional slave judged by the slave firmware). Rules: Python >= 3.11, CPython and PyPy; MIT; nothing read from GPL emulators or HDL; MAME's BSD-3 CD-i files closed too (decision 6); no system ROM, MCU firmware, DVC ROM, disc or Philips artwork in the repository; `MAME_ROMPATH`, `REDUMP_DIR`; local git only; no sweeps. ### Read in this order README.md; docs/start-here.md; docs/domains.md; docs/scc68070.md; docs/mcd212.md; docs/cdic-audio.md; docs/slave-and-input.md; docs/bios-and-models.md; docs/census.md; docs/validation.md; docs/mame-oracle.md; docs/provenance.md; then the MCD212 data sheet's chapters 3-5 and the SCC68070 data sheet's chapters 5-6 for the milestone at hand. ## Scope In: the Mono-I board (CD-i 205/210/220, Magnavox 200): DRAM, ROM, the MCD212 (system controller and video), the CDIC and the disc, CD-i ADPCM and CD-DA, the slave (firmware on mc68hc05-python, or functional first), the servo or a functional drive, pointing devices, the front display, the M48T08 NVRAM/RTC, the SCC68070's UART as a host serial port. Out: the CPU core (scc68070-python), the 6805 core (mc68hc05-python); Mono-II/III/IV, the MMC boards and the DVC as later rows (bios-and-models.md, dvc.md); the Quizard arcade machines (their 8751 needs an MCS-51 core the family lacks); hosts, windows, sites. ## Proposed names - Package **`cdi_python`**; `cdi_python.CDi` (the board), constructed with a `model` (`"mono1-pal"`, `"mono1-ntsc"` chosen by system ROM SHA-1: bios-and-models.md) that sets the MCD212 crystal (30 / 30.2097 MHz), the DRAM size, the slave firmware. - Modules: `bus.py` (Mono-I decode, DTACK sources), `mcd212/` (`system.py`: DRAM arbiter, ROM/IO decode, reset, BERR, watchdog; `timing.py`; `ica.py`: ICA/DCA engines; `picture.py`: decoding and mixing, the D2 producer), `cdic/` (`controller.py`, `adpcm.py`, `disc.py`: cue/bin with `CDI/2352` and pre-gaps), `slave/` (`firmware.py`: the socket for mc68hc05-python; `functional.py`), `pointer.py`, `nvram.py` (M48T08), `sound.py` (D6), `domains.py` (the channels as code), `machine.py`. - Sockets (pin-shaped, so later extraction is a move): the CPU (scc68070-python's bus callbacks, pins IN2/IN4/IN5/NMI/INT1/INT2, DMA REQ/ACK), the slave (`Slave` protocol: firmware or functional), the drive (`Drive` protocol), the pointer port (`Device` protocol), the expansion slot (for the DVC), the NVRAM image and clock epoch from the host. ## Import boundary The board imports `scc68070_python` (which imports `m68000_python`) and, for the slave, `mc68hc05_python`. The cores never import the board. The CPU's bus callbacks return wait clocks computed by `bus.py` from the MCD212's slot position, the ROM DTACK setting and the CDIC's and slave's DTACK delays. ## Domains and speed Full text: [domains.md](domains.md). - **Domains:** D1 main (SCC68070 with its on-chip peripherals; the MCD212's system controller, video timing, ICA/DCA engines and display fetches; DRAM, ROM, NVRAM), D2 picture (the MCD212 pixel pipeline, a pure producer), D3 disc (drive and CDIC), D4 slave (with pointer, IR, front display), D5 servo (optional), D6 sound (ADPCM, CD-DA, mixing: a pure producer), D7 DVC (later). The CPU and the MCD212's arbiter are one domain because every CPU DRAM access waits for a slot the video timing places. - **Channels:** the CDIC window and its DTACK, IN4, DMA REQ/ACK; the slave's four byte channels, IN2; slave-servo SPI; drive control; the display-fetch log (D1 -> D2); the audio log (D3 -> D6); pointer, IR and keys from the host; the UART to the host. - **Need, with arithmetic:** CPU clock 15 MHz; the fastest instruction is 7 clocks, so at most 15 M / 7 = 2.14 M instructions/s; a busy ROM loop costs 51 clocks per 4 instructions (1.18 M/s); MAME runs that loop at 0.43 M/s and the idle shell at 0.027 M/s. Design need 1.2 M/s sustained, 2.2 M/s peak. Two 6805s at 2 MHz: about 1 M/s together. Pixels: 384 x 280 x 50 = 5.4 M per plane per second, about 16 M pixel operations/s with two planes and the mix, 32 M at high resolution. - **No-JIT answer:** m68000-rust-fast runs 191 M instructions/s native and m68000-rust 112 M/s as WebAssembly on the desktop: margins of 70-150x native, about 50x in a desktop browser, 10-30x on a phone (*estimates* until cdi-rust measures). **cdi-rust-fast reaches real time single-threaded on desktop, as an iPhone app and in the browser; `recompile: none` on every target; no cached interpreter and no turbo tier needed.** Threads at the channels (D2, D6 first) are optional headroom, e.g. for 2-frame run-ahead on weak handhelds. cdi-python itself runs at roughly 0.2-0.5x real time on CPython and possibly near real time on PyPy (*estimates*); it is the specification, with short targeted cases. ## Unknowns (U) and contradictions (C) - U1 The SCC68070 "User Manual 1991, Part 1 - Hardware" is not in hand; only the data sheets. - U2 Where each bus access falls inside a 68070 instruction (the tables give totals and counts). - U3 The 68070's prefetch depth and refill (the long frame names an IRC). - U4 68070 flags where the 68000 leaves them undefined; cputest's real-player failures. - U5 Whether any consumer player's CD-RTOS enables the MMU. - U6 Which MCD212 crystal each player model fits (30 vs 30.2097 MHz; PAL vs NTSC players). - U7 The Mono-I's fitted DRAM size and bank configuration (CSR1W.TD, CAS strapping). - U8 MAME's Mono-I runs a functional slave: no emulator judge for the slave firmware path except the MiSTer core (closed box). - U9 What the "with test ROM" 8 KB slave/servo images hold besides the user program. - U10 The VSD/VSR back ends of the MMC boards: no data sheet. - U11 CDIC register bits ("TBA" in cdichips); DBUF's buffer bit; CD-DA routing (seen only in MAME's behaviour). - U12 Seek and spin-up times; the "20-sector seek delay" the MiSTer author attributes to a real CDIC. - U13 ADPCM decoder rounding and saturation in the CDIC. - U14 Slave timing beyond the MiSTer captures (those are of slave 3.2, not 2.0). - U15 IKAT (Mono-III/IV) firmware: not dumped in MAME's sets. - U16 The slave 3.2 dump (front-panel play key, remote media keys on a 210/05): not available. - U17 DVC output to the bit (IDCT rounding, chroma, overlay timing): no captures. - U18 The pointing-device byte-0 marker bit (illegible in the scan). - U19 The write-only latch at `318000`. - U20 MAME's 0.43 M/s module-scan rate against the data sheet's 1.18 M/s: ROM wait states? - U21 The 2026 MIT emulators' (edi, cdipc, opencdi) lineage. - C1 Goldstar GPI-1200: MAME runs it on an SCC68070; cdiemu.org's player page says the Goldstar board has a 68340. - C2 The SCC68070 data sheets of 1990 and 1993 against each other and against ICDIA's warning of "inaccuracies" (not yet compared table by table; the RESET pulse, 146 clocks, agrees). - C3 The slave's ROM: cdichips' README says 1,744 bytes, its `mc6805slave.md` says 7,744 (the MC68HC05C8's user ROM is 7,744 bytes; the README is likely a typo). - C4 MAME's screen (768 x 560 at a 28.416 MHz pixel clock, htotal 960) against the MCD212's line of 1,920 CLK at 30 MHz: MAME's raster is its presentation, not the chip's timing. - C5 Green Book vs MCD212 on when a DCA interrupt fires (the MiSTer author's capture: "fits the datasheet, but not the green book"). ## Milestones M0 scc68070-python rung 1; M1 bus and boot skeleton; M2 MCD212 display; M3 slave and pointer; M4 disc and CDIC; M5 audio; M6 timing pass; M7 seeded faults; later Mono-II/III/IV, DVC, MMC boards. Exit tests in [validation.md](validation.md). ## Open decisions for Aubrey 1. **The CPU core: a new repository `scc68070-python` that pins m68000-python and subclasses it** (semantics inherited; timing tables, frames, RTE, interrupt inputs, MMU, DMA, UART, timer and I2C its own), rather than a variant class inside m68000-python or a fresh core. Recommended (scc68070.md: the chip rule, m68000-python's claims boundary, and reuse). It asks m68000-python for a subclassing contract: a clock-charging hook, overridable exception entry and RTE, the decoded EA modes per step, an acknowledge hook, a pre-bus hook for the `8000xxxx` window. 2. **Timing at instruction level for the 68070** (data sheet totals and access counts; bus accesses in the 68000's order), until a hardware trace exists. Recommended: it is all the evidence supports; mark it so. 3. **mc68hc05-python as one core for both users** (PS1 CD controller, CD-i slave/servo, later the IKAT), with the C8/i8/PS1 parts as variants. Recommended: the chip rule is met twice. 4. **The slave runs its firmware (slave 2.0 on Mono-I) as the reference; a functional slave only as a stepping stone.** Recommended: the slave owns the input path and the boot handshake every title sees, and its dump is in hand. 5. **Reference firmware: Mono-I `cdi220b.rom` (Philips 220 F2, SHA-1 53360a1f...) with slave 2.0 and servo 2.1; `cdi200.rom` (Magnavox 200) for 60 Hz.** Recommended. 6. **MAME's BSD-3 CD-i files stay closed**, as for the PlayStation. Recommended: their lineage is unclear (the MiSTer author says MAME's CD-i code is inspired by CD-i Emulator's shared snippets), and the documents plus cdichips suffice. 7. **The MiSTer CD-i core (GPL-3.0) as a closed-box detector built in emu-tools-gpl, later**, for the low-level slave and real DMA that MAME's Mono-I lacks. Recommended as a later step, only if M3/M4 need a second opinion. 8. **May the prose in CDi_MiSTer's `doc/` (logic-analyser captures and real-player verdicts in a GPL-3.0 repository) be cited for facts under the middle rule?** Recommended yes, as facts (not code, never copied), each cited with its commit; it is the only hardware-captured material known. Until you decide, this repository cites it and marks it so. 9. **NVRAM image and real-time clock epoch supplied by the host** (deterministic runs; MAME's saved NVRAM changes its next boot). Recommended. 10. **Disc formats: `.cue`/`.bin` (Redump) first, with the `CDI/2352` track type and readable pre-gaps for the 80 CD-i Ready discs; CHD later** (libchdr BSD-3 to check). Recommended. 11. **Rows after Mono-I: Mono-II (needs a DSP56001 core or a functional drive DSP), then Mono-III/IV (CIAP summary only, IKAT undumped), the DVC (VMPEG) as a socketed add-on, the MMC boards last.** Recommended; the other-CPU players (Goldstar MC68340, Sony, Kyocera, I2M) out of scope unless you want them. 12. **Speed plan as the record: no JIT, no turbo, `recompile: none` everywhere; cdi-rust-fast single-threaded is enough, threads optional.** Recommended (domains.md); all figures estimates until cdi-rust measures them.