# Handoff: build `psx-python`, the PlayStation board ## Context you are inheriting Chips are cores, boards compose cores; the board pins its cores by commit. The CPU core is `r3000a-python` (`../r3000a-python`, Phase 0 done tonight; its brief proposes the bus contract this board implements). The board finds the core's corners and raises them there. Era 3 (charter): transaction level appears in the specification, Python is too slow for long runs (domains.md: 1/85 to 1/340 of real time), and cases are short and targeted. Nearest models in the family: - `segacd-python` and `pcenginecd-python`: disc boards (a CD drive domain, Redump images through `REDUMP_DIR`, decision T4); `segacd-python/docs/domains.md` and `sega32x-python/docs/domains.md` show the domains-and-channels document this board's `docs/domains.md` follows. - `sega32x-python`: the catch-up-at-the-channel pattern between domains. - `gameboy-python`'s Super Game Boy: a functional model judged against a lower-level run, the pattern proposed for the CD controller (HLE judged by LLE). Rules: Python >= 3.11, CPython and PyPy; MIT; nothing read from GPL emulators (MAME's psx files closed too, decision 6 below); no BIOS, firmware, disc or Sony artwork in the repository (MAME screenshots of the BIOS shell stay in git-ignored `tests/mame_traces/`); `MAME_ROMPATH`, `PSX_BIOS_DIR`, `REDUMP_DIR`; local git only; no sweeps. ### Read in this order README.md; docs/start-here.md; docs/domains.md; docs/memory-map.md; docs/gpu.md; docs/dma-timers-irq.md; docs/cdrom.md; docs/spu.md; docs/mdec.md; docs/pads-and-cards.md; docs/bios.md; docs/census.md; docs/validation.md; docs/mame-oracle.md; then r3000a-python's handoff-brief.md (the bus contract) and psx-spx's chapters for the milestone at hand. ## Scope In: everything on the PlayStation's buses except the CPU core: RAM, BIOS ROM, memory control, DMA, interrupt controller, root counters, SIO0 with pads and memory cards, SIO1 (late), the GPU (v2 first), the SPU, the MDEC, the CD-ROM subsystem (HLE first), the expansion port (empty, late), PS-EXE side-loading, disc images (.cue/.bin; CHD later). Out: the CPU core and GTE (r3000a-python); the LLE CD controller's MC68HC05 core (a new `mc68hc05-python`, later); hosts, windows, sites. ## Proposed names - Package **`psx_python`**; `psx_python.PlayStation` (the board), constructed with a `model` (`"SCPH-1001"` ... by BIOS SHA-1: bios.md) that selects GPU v0/v2, the CD firmware version string and region. - Modules: `bus.py` (decode, memory control, write-queue arrival), `dma.py`, `irq.py`, `timers.py`, `sio.py` (+ `pad.py`, `memcard.py`), `gpu/` (`frontend.py`: FIFO, GPUSTAT, busy model, video timing; `raster.py`: the back end; `vram.py`), `spu/`, `mdec.py`, `cdrom/` (`controller.py` HLE, `disc.py` images, `xa.py`), `exe.py` (PS-EXE loader), `domains.py` (the channels as code), `machine.py`. - Sockets (pin-shaped interfaces, so later extraction is a move): the CPU (r3000a-python's `read`/`write`/`run`/`set_interrupt`), the controller ports (a `Device` protocol), the CD controller (`Controller` protocol: HLE now, LLE later), the expansion port. ## Import boundary The board imports `r3000a_python` (CW33300, GTE) and nothing else of the family's. The core never imports the board. The CPU's bus callbacks return cycle costs computed by `bus.py` from memory control and DMA state. ## Unknowns (U) and contradictions (C) collected from the documents - U1 GPU rendering cycle costs (no document; fit to ps1-tests) - gpu.md. - U2 The display dot counter mechanics beyond amidog's Tajmiing prose - gpu.md. - U3 v0 GPU timings - gpu.md. - U4 SPU per-voice order within a sample; ENDX/ENVX/IRQ timing - spu.md. - U5 SPU "unstable" I/O delays - spu.md. - U6 Which IDCT the MDEC computes; MDEC throughput; the rev-90025 MDEC bug - mdec.md. - U7 SPU and CD DMA word rates - dma-timers-irq.md. - U8 The timer-0 dot-clock rounding - dma-timers-irq.md. - U9 DMA preemption and refresh costs - dma-timers-irq.md. - U10 CD command delays, seek and spin-up times; the sub-CPU clock; MAME's psu subcpu - cdrom.md. - U11 The memory-control access-time formula (psx-spx's is approximate) - memory-map.md. - U12 Garbage upper bits on some I/O reads - memory-map.md. - U13 Memory card write busy times; /ACK delays - pads-and-cards.md. - U14 The real CPU's cycles per instruction on game code (domains.md uses MAME's 1.998 and the 1.0 ceiling). - C1 PAL video clock 53.203425 MHz (psx-spx table) vs 53.2224 MHz (nocash's CPU x 11/7). - C2 MAME's ~2 cycles per instruction vs a cache- and bus-dependent cost (r3000a C4). - C3 The loose BIOS folder's `scph1001.bin` is v2.0a, not v2.2a (bios.md): names are not evidence. ## Milestones M1 bus and boot skeleton; M2 GPU and EXE side-loading; M3 DMA modes, MDEC, timers, interrupts; M4 CD-ROM (HLE) and discs; M5 SPU; M6 pads and cards; M7 timing pass; M8 seeded faults; later the LLE CD controller. Exit tests in validation.md. The speed plan (domains.md): Python is the specification only. `psx-rust` transcribes it; `psx-rust-fast` adds threads (GPU back end first, then SPU, CD) and the usual exact optimisations; `psx-rust-turbo` adds a cached interpreter for the R3000A, which the i-cache makes exact for cached code; recompilation only on targets that allow it and only if measured need remains. ## Open decisions for Aubrey 1. **CD-ROM controller: high-level first, emulated sub-CPU later as its referee.** Recommended (cdrom.md): HLE is one module and needs no firmware; LLE needs a new MC68HC05 core, a decoder model and a drive model whose analogue timings are as unmeasured as HLE's delays. The LLE's value is as a judge of the HLE's responses and relative timings, using the 15 firmware dumps the player supplies. 2. **GPU v2 first (CXD8561), v0 (CXD8514, early SCPH-1000/1001/1002) as a later model switch.** Recommended: v2 is in nearly every console and in the tests' recorded outputs. 3. **GPU modelling level: video timing and display output at dot level, rasterisation at transaction level (each command's pixels in the hardware's scan order, with a busy time).** Recommended: it is what the evidence can judge (pictures and GPUSTAT), and it gives the threaded tiers a pure producer to move. 4. **The SPU and MDEC stay inside the board** (chip rule: single machine; the PS2's SPU2 is era 4). Recommended; extract the SPU only if a PS2 board ever exists. 5. **Reference BIOS SCPH-1001 v2.2a (`psu`, SHA-1 10155d8d...), PAL SCPH-7502 v4.1e, Japan SCPH-5500 v3.0j; OpenBIOS (MIT) as the free BIOS for tests and players without a dump, built in `reference/`, never committed.** Recommended. Open sub-question: its authors studied the retail BIOS closely; its licence is clear MIT but clean-room status is not stated. Recommended: accept it as MIT with its notice, like any MIT source, and say so in the provenance file. 6. **MAME's BSD-3 psx device files stay closed** (they would be "code OK with notice" by their `license:` lines). Recommended: closed, as tonight's brief said; psx-spx and the tier-3 tests suffice. 7. **No HLE BIOS.** Recommended: the BIOS always runs as itself; PS-EXEs are side-loaded at the shell entry (80030000h) for tests. 8. **Disc formats: .cue/.bin (Redump) first, CHD later** (the curated library is 1,804 CHDs; a CHD reader needs its own licence check: libchdr is BSD-3). Recommended. 9. **`docs/domains.md` as written: one CPU-and-bus domain that includes the GPU front end and video timing; the GPU back end, SPU, CD and MDEC as separate domains.** Recommended: it keeps every per-cycle observable inside the CPU domain and makes the costly parts (rasterising, sound) movable. 10. **Speed answer, to accept as the plan:** no JIT needed on desktop or as an iPhone app (estimates: x-rust-fast 42-95 M / 34-76 M instructions/s against a 17-34 M need); the phone browser needs the turbo tier's cached interpreter, and low-cost ARM handhelds need native recompilation (allowed there). All estimates until psx-rust measures them.