# Handoff: build `ps2-python`, the PlayStation 2 board ## Context you are inheriting Chips are cores, boards compose cores; the board pins its cores by commit and raises their corners on them. Cores: `ee-python` (`../ee-python`, Phase 0 beside this one; its brief proposes the EE Core's bus contract and COP2 socket), `vu-python` (proposed by ee-python's decision E6, not yet created), `r3000a-python` (`../r3000a-python`, the IOP, in a second configuration: decision P11). Era 4 (charter): thin evidence; instruction and functional levels dominate; turbo with recompilation; concessions likely on weak targets. This board is the family's hardest speed case and its thinnest-evidence case for the GS, the IOP side and the drive. Nearest models in the family: - `psx-python`: the disc board shape, the HLE CD controller judged later by an LLE, the GPU front/back split, the SPU caught up at register access, `REDUMP_DIR`. - `n64-python`: the execution architecture (time-keeping first, joins, the hazard map, GPU back ends under the per-pixel contract), and the late-era method. - `sega32x-python`, `segacd-python`: catch-up at channels; a drive stepped on another domain's clock. Rules: Python >= 3.11, CPython and PyPy; MIT; nothing read from GPL emulators (PCSX2, DobieStation); MAME closed; Play! readable with notice; Sony's manuals facts only; no firmware, discs, keys or Sony artwork in the repository (`MAME_ROMPATH`, `PS2_BIOS_DIR`, `REDUMP_DIR`); local git only; no sweeps; Python runs test programs and slices only. ### Read in this order README.md; docs/start-here.md; docs/domains.md; docs/execution-architecture.md; docs/memory-map.md; docs/dmac-intc-timers.md; docs/vif-gif.md; docs/gs.md; docs/iop.md; docs/sif.md; docs/cdvd-mechacon.md; docs/spu2.md; docs/pads-and-cards.md; docs/ipu.md; docs/bios.md; docs/census.md; docs/validation.md; docs/mame-oracle.md; then ee-python's handoff brief, and Sony's EE User's Manual and GS User's Manual for the milestone at hand. ## Scope In: everything on the PS2's buses except the CPU cores and the vector units: main RAM and its controller registers, the EE register block (timers, IPU, GIF, VIF0/1, DMAC, INTC, SIF), the GS (front end, back end, local memory, PCRTC), the IOP's peripherals (DMA, timers, INTC, SIO2, SPU2, the CDVD front end, DEV9 as an empty port), the SIF, pads and memory cards, ELF and IRX loading from a booted-kernel state, disc images (`.iso`, `.cue/.bin`; CHD later), PS1 mode (M9). Out: the EE Core (ee-python); VU0/VU1 (vu-python); the IOP CPU (r3000a-python); an LLE MechaCon (later, on arm7tdmi-python); USB, FireWire, the network adapter and HDD (later add-on boards, as sockets); hosts, windows, sites. ## Proposed names - Package **`ps2_python`**; `ps2_python.PlayStation2` (the board), constructed with a `model` chosen by BIOS SHA-1 (census.md), which selects region and video standard. - Modules: `bus.py` (EE physical map), `ee/` (`dmac.py`, `intc.py`, `timers.py`, `ipu.py`, `sif.py`), `vpu.py` (VIF0, VIF1), `gif.py`, `gs/` (`frontend.py`, `raster.py`, `localmem.py` with the swizzle tables, `pcrtc.py`), `iop/` (`bus.py`, `dma.py`, `intc.py`, `timers.py`, `sio2.py`, `cdvd.py`), `spu2/`, `pads.py`, `memcard.py`, `disc.py`, `elf.py`, `domains.py` (the channels as code), `state.py` (the shared state format, late-era L3), `machine.py`. - Sockets (pin-shaped interfaces, so a later extraction is a move): the EE Core (ee-python's `read`/`write`/`run`/`set_int0`/`set_int1`/`spram_*`), COP2 (vu-python's `VU0`), VU1 (vu-python's `VU1` with VIF1 and XGKICK ports), the IOP CPU (r3000a-python), the controller ports (`Device`), the memory-card ports, the drive (`Drive`: HLE now, LLE later), DEV9. ## Import boundary The board imports `ee_python`, `vu_python`, `r3000a_python`; nothing else of the family's. No core imports the board. ## Unknowns (U) and contradictions (C) collected from the documents - U1 the GS core clock - memory-map.md - U2 EE region access costs; U3 EE view of IOP RAM; U4 EE/DMAC bus arbitration detail - memory-map.md - U5 DMA rates; U6 slice arbitration timing; U7 INT1 edge behaviour; U8 H-blank timers in interlace - dmac-intc-timers.md - U9 VIF cycle costs; U10 MSKPATH3 take-effect point; U11 GIF FIFO depth; U12 PATH2 data underrun - vif-gif.md - U13 IPU IDCT precision; U14 IPU busy time - ipu.md - U15-U18 GS filter, LOD, divide precision, edge rules; U19 data-dependent GS busy time; U20 page-break cost; U21 interlace with two circuits; U22 V-sync timings - gs.md - U23 IOP PRId; U24 IOP caches and scratchpad; U25 SIF_CTRL bit 19; U26 IOP memory timing; U27 late models' IOP; U28 PS1-mode clock switch - iop.md - U29 SPU2 vs PS1 SPU identity; U30 ADMA timing; U31 effect algorithm; U32 register delays - spu2.md - U33 SIF FIFO depths and costs; U34 mailbox visibility timing - sif.md - U35 drive timings (tier 5 today); U36 who authenticates memory cards; U37 DVD-9 layer break; U38 MechaCon version checks; U39 S-commands per MechaCon generation - cdvd-mechacon.md - U40 SIO2 registers; U41 card timings; U42 key-free authentication parts - pads-and-cards.md - C1 GS rates stated at 150 MHz vs the 147.456 MHz bus (memory-map.md). - C2 IOP clock: Sony 36.864 MHz (DOC) vs MAME 33.8688 MHz in PS2 mode (OBSERVED). Sony wins; MAME's value matches PS1 mode's. - C3 ps2tek's CDVD timings are PCSX2's model by its own account: an emulator's numbers in a tier-3 document (cdvd-mechacon.md). ## Milestones M1 bus and boot skeleton; M2 DMAC, VIF, GIF, GS; M3 VUs; M4 SIF and the IOP; M5 kernel; M6 CDVD and discs; M7 SIO2, pads, cards; M8 SPU2 and IPU; M9 PS1 mode; M10 timing pass and seeded faults. Exit tests in validation.md. ## Domains and speed **Domains and channels** (domains.md): A = EE Core + VU0 + DMAC + INTC + timers + IPU front + SIF EE side; B = VIF1 + VU1 + GIF arbiter + GS front end; C = GS back end (producer, joins only); D = IOP + its peripherals + CDVD front end; E = SPU2 (inline in D); F = drive (events on D's clock). One integer time base: the EE cycle (bus = 2, IOP = 8; PS1 mode x147). **The need, with the arithmetic shown** (desktop-equivalent host cycles per guest operation on one core: desktop 5.0e9 / R, phone app 4.0e9 / R, browser 2.4e9 / R; HYPOTHESIS ratios from n64-python and psx-python): | Component | Guest rate R | Desktop | Phone app | Browser | Likely exact cost | | --- | --- | ---: | ---: | ---: | --- | | EE, typical | 150-295 M instr/s (0.5-1.0 IPC at 294.912 MHz) | 17-33 | 14-27 | 8-16 | 30-70 plain; 12-25 cached + memoized | | EE, peak | 589.8 M instr/s (2 x 294.912 M) | 8.5 | 6.8 | 4.1 | | | VU1 | 90-240 M LIW/s (30-80 % busy) | 21-56 | 17-44 | 10-27 | 25-60 SIMD; 8-20 block cache + flag liveness | | GS fill, typical | 100-600 M pixels/s | 8-50 | 7-40 | 4-24 | 15-50 software SIMD | | GS fill, peak | 1.18 G textured (2.4 G/s at 150 MHz per GSUM) | 4.2 | 3.4 | 2.0 | GPU only | | IOP | ~18 M instr/s | 280 | 220 | 135 | 25-60 | | SPU2 | 2.3 M voice-samples/s | 2,170 | 1,740 | 1,040 | 100-250 | **Does the no-JIT path reach real time?** (`-fast`, then a cached interpreter, then threads at domain channels): - **Desktop**: for light and medium games, plausibly, with thread A's cached EE at 0.4-1.5 cores' worth, thread B (VU1 with its block cache, the GS front end) at 0.2-2, and the GS back end on 2-6 tile threads. Not for heavy games: they need `recompile: native` (allowed on desktop) or the GPU back end. HYPOTHESIS. - **Phone app** (native iOS, no JIT): **no** for typical 3D games: thread A alone is 0.45-1.8x a performance core with the cached EE, 1.1-5.2x with the plain one; only light games at the best case of every estimate could fit, and only with the GS on Metal. With the named concessions (EE coarse timing, VU host floats, coarser A/B sync, idle skipping), some games may reach real time; Android apps may JIT. - **Browser**: **no**; `recompile: wasm` plus WebGPU plus worker threads plus concessions may make lighter games playable. - **Low-cost ARM handhelds**: no. - **Where GPU back ends, threads and concessions are unavoidable**: threads per domain everywhere (no host core runs the EE, VU1 and the GS together); a GPU back end for the GS on every phone and browser target and at fill peaks on desktops; concessions on every weak target. execution-architecture.md lists them (S5) and their order. - **What the Python specification can be**: test programs from a booted-kernel state, and GS, VU, IPU and whole-machine slices of a few frames (validation.md); a frame takes minutes, a boot hours. x-rust is the first runnable tier (late-era L2). ## Open decisions for Aubrey 1. **P1. Accept the late-era method (L1-L8) for this board without qualification**: slice cases, x-rust as the first runnable tier, the shared state format from M1, GPU back ends as turbo. *Recommend* yes: the PS2 cannot be validated any other way. 2. **P2. Domains as in domains.md** (A, B, C, D, E inline in D, F on D's clock), with VU0 in A and VU1 in B. *Recommend* yes. 3. **P3. vu-python** (ee-python's E6): the board wires VU0 to the EE's COP2 socket and VU1 to VIF1 and the GIF; VIF and GIF stay here. *Recommend* yes; vu-python's Phase 0 next if accepted. 4. **P4. The GS stays in the board** (chip rule: one machine), as `ps2_python.gs`, behind a pin-shaped interface. *Recommend* yes. 5. **P5. GS pixels at functional level, exact integer rules; timing at transaction level by primitive** (gs.md). *Recommend* yes. 6. **P6. GS local memory with the exact per-format swizzles as tables**, the texture page buffer and TEXFLUSH modelled. *Recommend* yes: games depend on both. 7. **P7. The GS busy time does not depend on pixel results** unless a judge shows it does (S3; U19). *Recommend* yes, marked HYPOTHESIS. 8. **P8. CDVD: HLE first, an LLE MechaCon later as its referee, on arm7tdmi-python with a Dragon (CXR7, ARM7TDMI) dump the player supplies; no keys ever shipped; MagicGate-dependent features (memory-card authentication, KELF loading) absent from the HLE and named in the capability record.** *Recommend* yes. The 14 MechaCon dumps in the Redump BIOS set make the LLE referee possible later without new acquisitions. 9. **P9. IPU: functional decode, transaction-level busy model**, decode ahead on a producer thread only if its time model needs no decoding. *Recommend* yes. 10. **P10. Extract `spu-python`** from psx-python's SPU when both boards have working models, with SPU and SPU2 configurations; until then the SPU2 lives here behind an interface shaped like psx-python's SPU. *Recommend* yes (the second-user test is now met; psx-python's decision 4 anticipated it). 11. **P11. r3000a-python gains an IOP configuration** (PRId, scratchpad and GTE presence, the KSEG2 register set, a PS1-mode hook), reversing its decision 2 now that a second configuration exists; raised on the core at M4, not before. *Recommend* yes. 12. **P12. Reference BIOS: SCPH-10000 (`scph10000_t`, aea061e6...) for M1, SCPH-39001 (`scph39001_a`, f9a5d629...) as the USA reference, SCPH-77001 (`scph77001_a`, 92e488d5...) for late-model differences.** *Recommend* yes; PAL and Japan picks from the census when needed. 13. **P13. No HLE BIOS; the BIOS runs as itself; fast boot only by state transplant** from ps2-rust (bios.md). *Recommend* yes. 14. **P14. PS1 mode as M9, run the hardware's way** (PS1DRV on the EE, TBIN on the IOP, the GS drawing); none of psx-python's GPU, SPU or CD models is reused. *Recommend* yes. 15. **P15. The local Redump PS2 set is partial (2,536 discs, almost all USA; the rest "moved to external 18TB NFFS drive")**: take the full DVD/CD counts when the drive is attached. *Recommend* Aubrey attaches it or points `REDUMP_DIR` at it once; the census script reruns unchanged. 16. **S1-S7** (execution-architecture.md): the capability statement, threads per domain, the GS busy-time rule, our own GPU back end, the named concessions, the VU block cache with flag liveness, and recompilation recorded as required on weak targets in the JIT proposal's family table. *Recommend* yes to each, as written there.