# The CD-ROM subsystem: controller, sub-CPU, decoder, drive Sources: psx-spx `cdromdrive.md` (host ports, commands, timings), `cdrominternalinfoonpsxcdromcontroller.md` (the HC05 and the decoder from the inside), `cdromformat.md` (sector formats, XA, LibCrypt) at `6d7d1bc` (tier 3, facts only); psxdev `wiki_eng/subcpu.md`, `cddec.md`, `cddsp.md`, `cdrf.md`, `cddriver.md` and the data sheets in `docs/` (MC68HC05L16, CXD1199, CXD1812Q, CXD2510Q, CXD2545Q: tier 2 for those chips; CC0 repository, the sheets are their makers'); ps1-tests `cdrom/*` (disc-swap, getloc, terminal). ## The parts (DIE/DOC) - **Sub-CPU** (IC304, "mechacon"): a Motorola MC68HC05-family 8-bit MCU with on-chip mask ROM. psxdev: "L16" 80-pin on PU-7 and early PU-8, "G6" 52-pin from late PU-8; memory map 00-3Fh I/O, 40h-23Fh 512 B RAM, 1000h-4FFFh 16 KB mask ROM, FE00h-FFFFh self-test ROM and vectors; its clock (OSC1) is the CD DSP's FSOF, a quarter of the DSP's frequency. It talks to the decoder through ports A (data) and E (address) with port D strobes, to the DSP over a 3-wire serial link, reads SUBQ, drives the laser, the 1x/2x speed line and reads the door and limit switches (psxdev subcpu.md pin table). - **Decoder/FIFO**: CXD1199BQ (PU-7), CXD1815Q (later), later merged into the SPU chip; "about 99% the CXD1199AQ data sheet" (psx-spx). Error correction, XA-ADPCM decoding, the 32 KB sector buffer, and the host interface the main CPU sees at 1F801800h-03h. - **DSP and servo**: CXD2510Q / CXD2545Q, CXA1791 RF amplifier; motors. - **Firmware versions** (psx-spx "19h,20h"): vC0 (1994, PU-7) through vC3 (2001, PSone), with region strings "for Europe", "for U/C", "for Japan", "for NETNA"; the DTL-H2000 dev kit used an SPC700 instead of the HC05. ## What the main CPU sees (DOC psx-spx `cdromdrive.md`) Four banked byte ports: index/status (HSTS), command, parameter FIFO (16), response FIFO (16), data FIFO (sector data, also DMA3), interrupt enable and flags (INT1 data ready, INT2 complete, INT3 acknowledge, INT4 end, INT5 error), audio volume matrix for CD audio into the SPU. About 30 commands (Getstat, Setloc, ReadN/ReadS, SeekL/SeekP, Play, Pause, Init, Setmode, Setfilter, GetlocL/P, GetTN/TD, ReadTOC, GetID, Test sub-functions). Each command answers with INT3 after a delay, many with a second response (INT2) after the mechanism has acted; reads deliver a sector every 1/75 s (1/150 at double speed). Seek and spin-up times are not constant (psx-spx gives approximate ranges; ps1-tests `getloc` measures stat bits during seeks). ## The decision: a high-level controller or the emulated sub-CPU? Two ways to model the controller: **A. High-level (HLE) controller**: a Python model of the command protocol as the host sees it: the FIFOs, the INT sequence, the response bytes, the delays (first response, second response, seek, spin-up, sector cadence), the XA filter, the stat bits, the audio path. The drive is a disc image (Redump .cue/.bin) plus a seek/rotation timing model. **B. Emulated controller (LLE)**: an MC68HC05 core running Sony's sub-CPU firmware, a CXD1815Q decoder model at register level, and a DSP/servo/drive model good enough for the firmware's closed loops (SUBQ timing, focus/tracking "OK" signals, the sled). | | A. HLE | B. LLE | | --- | --- | --- | | Evidence available | psx-spx's host-side command chapters (tier 3, much observed on hardware), ps1-tests getloc/disc-swap, amidog's disc images | the firmware itself (MAME's `psx_cd` set: 15 dumped versions, all present here - bios.md), psx-spx's HC05 and decoder register chapters, psxdev pinouts, MC68HC05L16 and CXD1199 data sheets (tier 2) | | What it gets right for free | nothing: every delay is a fitted number | the command semantics, error paths, response bytes, test commands, and **relative** timings, because they are the firmware's | | What it still needs | timing measurements we do not have (we have no hardware) | a model of the drive's analogue side (seek physics, servo lock times) the firmware waits on: also unmeasured | | New code | ~1 module | a **new CPU core** (mc68hc05-python; family rule: CPUs get their own core; no 6805 core exists, m6800-python is a different ISA), a decoder model, a mechanism model | | Speed | negligible | an extra CPU domain at ~2-4 MHz (cheap in Rust, slow in Python) | | Firmware | none needed | player-supplied (never shipped), one per console model | | Provenance | facts only | facts only; no firmware disassembly is copied (it is console firmware) | **Recommendation: A first, B later as its referee.** Build the HLE controller in psx-python milestone 4, fitted to psx-spx's documented behaviour and ps1-tests, with each delay marked FITTED. Then, as a later milestone, build B (mc68hc05-python + decoder + mechanism) and use it the way gameboy-python judges its SGB functional model against snes-python running the real SGB program (charter, modelling level): the LLE run decides the HLE's response bytes and its relative timings wherever the firmware decides them. The mechanism's analogue timings stay FITTED in both until someone measures a console. MAME observation (closed box): `psx_cd` lists the 15 firmware dumps in a `cdrom_mcu` region, yet `-listxml` lists **no CPU** for it on psu/pse/psj/psa; psu alone lists a "subcpu" Hitachi HD63705Z0 at 4,166,667 Hz with `scea.ic304` (16 KB), `ram.ic304` (1 KB), `test.ic304` (512 B). Whether MAME executes that firmware is not visible from outside (OBSERVED; its source stays closed). ## Copy protection and region The licence string sectors ("Licensed by Sony Computer Entertainment Amer/Euro/Inc") and the wobble-groove "SCEx" string checked by the firmware (GetID); LibCrypt's subchannel tricks on some PAL discs (233 SBI files in the Redump set: census.md). The HLE model needs the SBI data to answer subchannel reads correctly for those discs. ## Unknowns - U1 Command response delays and seek/spin-up times as distributions (no hardware here). - U2 The sub-CPU's exact clock (psxdev: DSP FSOF / 4; MAME lists 4,166,667 Hz on psu). - U3 Decoder corner cases (buffer overrun, the "only two sectors accessible" note in psx-spx's memory map). - U4 What MAME's psu HD63705 actually runs (closed box).