# Handoff: build `psp-python`, the PlayStation Portable board ## Context you are inheriting The family's shape (charter): boards compose pinned cores; `x-python` is the specification; CPUs get their own core (`../allegrex-python`, Phase 0 beside this one); other chips stay in the board until a second family board needs them. The PSP sits between era 3 and era 4: a 333 MHz CPU with a vector unit, thin hardware evidence, and an operating system that every game calls. The decisive document is [hle-vs-lle.md](hle-vs-lle.md). Read also `../emulator-lineage/docs/proposals/2026-11-late-era-method.md` (slice gates, a shared state format: decisions L1-L8) and `../n64-python/docs/execution-architecture.md` (time-keeping and joins). Models: psx-python (a CPU with a COP2 vector unit, a GPU front/back split, a CD subsystem weighed HLE against LLE), n64-python (the RDP's hazard map and joins, GPU backends held to per-pixel CRCs), gameboy-python's Super Game Boy (a functional model of firmware judged against a lower-level run), megadrive-python (save states, devices). Rules that bind this work: oracle tiers (validation.md); Python floor 3.11, PyPy green; reference boards are correct, not fast; no dangerous-looking one-liners; never copy a chip file between repositories; no hardware probes; `python -I` for anything that reads `reference/`; PPSSPP, JPCSP, FFmpeg, binutils/gcc's Allegrex patches are closed boxes, never read; uOFW is not read (P3); the PSP Developer Wiki is set aside by its robots.txt; **Sony's boot ROM, IPL, kernel, libraries, fonts, syscon and Lepton firmware and every key are never committed, copied, shipped or embedded**; a player's own dumps are identified by SHA-1 and loaded from an environment variable. ### Read, in this order 1. `README.md`, `docs/start-here.md`, `docs/hle-vs-lle.md`. 2. `docs/memory-map.md`, `docs/cpus-and-media-engine.md`, `docs/ge.md`, `docs/audio.md`, `docs/storage.md`, `docs/syscon-and-power.md`, `docs/boot-and-firmware.md`. 3. `docs/domains-and-speed.md`, `docs/census.md`, `docs/validation.md`, `docs/mame-oracle.md`, `docs/provenance.md`. 4. `../allegrex-python/docs/handoff-brief.md`. 5. YAPSPD chapters 7, 10, 11 (`reference/docs/yapspd/psp_doc.txt/psp_doc.txt`), Copetti's article, pspsdk `src/ge/pspge.h`, `src/gu/`, `src/kernel/`, `src/user/`, and the pspautotests sources beside each `.expected` you gate on (cite, never copy). Then `python -I scripts/fetch_references.py --verify`. ## Scope In: the main CPU (allegrex-python) and its memory system; scratchpad, DDR (32/64 MB), eDRAM/VRAM with its mirrors; the GE (list processor, surface engine, software rasteriser) and the display; the audio output; DMA as the kernel exposes it; interrupts and timers as events; the **HLE kernel and Sony's user libraries** as a functional model of firmware 6.61 (`psp_python.kernel`, `psp_python.libs`); the UMD as an ISO behind the I/O manager with a read-time model; the Memory Stick as a host directory; controls and power; the media decoders behind an interface (P4). Out (for now): the Media Engine's CPU and its AVC/VME hardware, KIRK, SPOCK, Lepton, NAND, the syscon MCU, the boot chain (an LLE row, P5); Wi-Fi, USB, IrDA, the remote port (late, stubbed); video out; the PSP Go's and Street's rows. ## Proposed names - Repository `psp-python`, package `psp_python`; class `PSP(machine="psp-2000")`. - Modules: `board.py` (memory map, segments to physical, mirrors), `events.py`, `clock.py` (PLL time base), `ge/` (`frontend.py`, `state.py`, `transform.py`, `raster.py`, `texture.py`, `blend.py`), `display.py`, `audio.py`, `kernel/` (`loader.py`, `nid.py`, `threads.py`, `sync.py`, `memory.py`, `io.py`, `interrupts.py`, `power.py`, `ctrl.py`), `libs/` (`ge.py`, `display.py`, `audio.py`, `sas.py`, `utility.py`, `mpeg.py`, `atrac.py`, `font.py`, `rtc.py`), `media/` (decoder interface), `iso.py`, `state.py`. - HLE functions are named by library and NID, with the pspsdk name in the docstring and the evidence tag per behaviour. ## The import boundary and the sockets - The board imports `allegrex_python` (pinned by commit); the core imports nothing from the board. The board gives the core one `Bus` and the interrupt pin; at SYSCALL the core raises its exception, and the board's HLE dispatcher (standing in for the kernel's exception vector) runs the function by the code in SCCode-equivalent state, then returns with ERET semantics. Whether the HLE kernel sits *at the exception vector* (the core unchanged) or behind a core hook is decision P11; recommend the vector, so the core needs no HLE awareness. - **Sockets:** the media decoders (`media.Decoder`: AVC, ATRAC3, ATRAC3+, MP3, AAC), each supplied by the host; the Memory Stick's backing store; the firmware directory (`$PSP_FIRMWARE_DIR`: fonts, and for a later LLE row the dumps); the controller input. ## Unknowns (U) and contradictions (C) - U1. Whether KU0's high mirrors (above 0x1FFFFFFF) fault or alias. - U2. The address of the second 32 MB on 64 MB models, and how the kernel exposes it. - U3. The kernel's behaviour switches on a game's SDK version (`sceKernelGetCompiledSdkVersion`): which calls change, from which tests. - U4. HLE calls' cycle costs: FITTED from nothing until a judge exists; stated per call. - U5. The PLL/CPU/bus divider structure and its exact ratios at each setting. - U6. The ME's control block and reset protocol (homebrew on the ME). - U7. Which games read the depth buffer through the VRAM mirrors. - U8. The GE's timing per command and per pixel. - U9. The audio output's hardware sample rate (44.1 or 48 kHz). - U10. SAS's envelope, pitch and interpolation details. - U11. UMD seek and read timing. - U12. Fonts: what to do without the player's `flash0:/font` (P8). - U13. The syscon MCU's identity and protocol. - U14. Whether the display and audio run from separate crystals. - U15. The VFPU's share of instructions in 3D games. - U16. The fraction of frames spent halted under the HLE kernel. - U17. `.edat`/`.pbp` containers in the PSN sets: what the loader must accept. - U18. Which PSP model and firmware recorded each pspautotests file. - C1. The ISA's lineage (allegrex-python C1). - C2. The user program's load address: 0x08900000 (YAPSPD 7.3.2, "user main program start address", 2006) vs 0x08804000 (ghidra-allegrex README: "the usual address where games are loaded"). Firmware versions differ (HYPOTHESIS); the HLE loader follows the firmware it models. - C3. Segment sizes: YAPSPD's table gives KU0 1024 MB but maps every segment to physical `0x0.......` with 29-bit addresses (U1). - C4. Audio: "two PCM channels" at the hardware endpoint (Copetti) vs 8 channels plus an SRC channel in the kernel's API (pspsdk): the kernel mixes (HYPOTHESIS); the model puts the 8 in the HLE kernel and 2 in the hardware output. ## Milestones M0-M9 as validation.md, each with its exit test. Rungs 1-7 of allegrex-python run on M1. From M1 the board writes and reads the **shared state format** (late-era proposal L3), and from M4 the gate adds slices from states written by psp-rust (L1). ## Domains and speed (Full version: domains-and-speed.md.) **Domains and channels.** A: CPU, HLE kernel, memory, the GE's front end, display timing, events. B: the GE back end (a producer, joined through a hazard map over DDR and VRAM pages). C: audio mixing and SAS. D: decoders. E: UMD/Memory Stick I/O timing. Channels: SYSCALL (inside A), GE registers and stall address, memory joins, display line fetches, audio and decoder results at their returning calls, I/O completion events. Under LLE the ME, syscon and Lepton would be further domains. **The need, with its arithmetic:** the Allegrex at 222 MHz with IPC 0.5-0.8 is 111-178 M instructions/s; at 333 MHz 167-266 M. The GE draws about 16-31 M shaded pixels a second (480 x 272 x 60 = 7.8 M visible, x2-4 overdraw: HYPOTHESIS). Budgets on one core (desktop 5.0e9, phone app 4.0e9, phone browser 2.4e9 host cycles/s): **28-45 / 22-36 / 13-22 cycles an instruction at 222 MHz, 19-30 / 15-24 / 9-14 at 333 MHz.** An exact interpreter with cheap time-keeping costs 25-60 (HYPOTHESIS, from n64-python's estimate); with an SH-2-style scheduler 89-145 (MEASURED, sh2-rust-fast). **Does the no-JIT path reach real time?** | Target | Rust -fast | + cached interpreter, memoized timing | + threads at channels | Verdict | | --- | --- | --- | --- | --- | | Desktop native | 222 MHz games: probably; 333 MHz busy games: no | 333 MHz: at the edge | the GE back end, audio, decoders off the CPU's core | **real time for 222 MHz games; not guaranteed at 333 MHz** | | Phone app (no JIT) | no at 333 MHz; at the edge at 222 MHz | 222 MHz: probably | GE on Metal compute or 2 cores | **222 MHz at the edge; 333 MHz no** | | Phone browser | no | no | WebGPU / workers for the GE | **no: needs `recompile: wasm` (turbo)** | | Python specification | 1/550 to 1/2,700 of real time | | | test programs and slices only | Under LLE every row gets worse: the kernel's code and the Media Engine's (a second 333 MHz CPU running codecs) are emulated too, roughly doubling the CPU need. ## Open decisions for Aubrey (each with my recommendation) - **P1. The boundary: HLE at SYSCALL and Sony's library NIDs, low-level hardware below for the CPU, memory, GE, display and audio output** (hle-vs-lle.md). *Recommend* yes. The specification is then two specifications with separate evidence: hardware (judged by hardware tests) and firmware 6.61 as a functional model (judged by pspautotests' OS outputs recorded on real PSPs). Every HLE behaviour carries its evidence tag; HLE timing is never called evidence. - **P2. Encrypted executables.** Every image checked has an encrypted `EBOOT.BIN`. The family must not ship Sony's keys. *Recommend*: M1-M4 load **only plain modules** (homebrew, pspautotests, and executables a player decrypted on their own console); a later, separate decision whether the board may read a **player-supplied** key or firmware file from `$PSP_FIRMWARE_DIR` at run time (never shipped, never committed). This is a legal and ethical call as much as a technical one: Aubrey's. - **P3. uOFW.** MIT-licensed, but a reverse-engineered transcription of Sony's firmware (boot ROM, IPL, kernel, syscon firmware). *Recommend* not reading it, as with the N64's firmware transcriptions; revisit only for its kernel API documentation, if Aubrey judges that API documentation differs from transcribed code. - **P4. Codecs.** H.264 through a permissive decoder (openh264, BSD-2-Clause: licence and patent terms to check); ATRAC3/3+ has no permissive decoder we know. *Recommend* a `media.Decoder` socket: the MIT board ships with no ATRAC3+ decoder (silence, logged as a missing device, not a concession: the emulation is exact up to the socket), and a separate GPL/LGPL host package may provide one by running FFmpeg (charter, licences 4). - **P5. An LLE row later, as a judge of the HLE kernel, not as the product.** *Recommend* deferring it until the HLE board runs games and until register-level evidence exists from sources we may use (today it lives on the set-aside wiki and in uOFW). - **P6. First machine row: PSP-2000** (64 MB, no VFPU erratum), PSP-1000 second. *Recommend* yes: every game runs on a 2000; the 1000's erratum is an opt-in row (allegrex-python A7). - **P7. Build PPSSPP headless in emu-tools-gpl** as the board's tier-5 detector for pspautotests and games' first frames. *Recommend* yes, at M1, run only, outputs read. - **P8. Fonts.** Games and the `font/*` tests read Sony's fonts from `flash0:/font`. *Recommend* loading the player's own font files from `$PSP_FIRMWARE_DIR` when present, and otherwise an open font as a **named concession** (it changes the picture), off when the player's fonts exist. - **P9. Time base: PLL cycles, re-based at each clock change** (domains-and-speed.md). *Recommend* yes, provisional until U5 is settled. - **P10. The shared state format and slice gates from M1** (late-era proposal L1-L4). *Recommend* yes: Python will never boot a game to its first 3D frame in minutes. - **P11. HLE dispatch at the exception vector, not a core hook.** *Recommend* yes: the core stays a hardware core; the kernel is the board's. - **P12. Wi-Fi late:** `net/*` (109 tests) and ad hoc play stubbed as "no network" until M9. *Recommend* yes. - **P13. The sources.md rows** in provenance.md, including the PSP Developer Wiki as "set aside (site's wishes)" (it hosts PS2 and PS3 pages too: relevant to ee-python). *Recommend* adding them as written. ## What was not verified in this phase (candour) - No test program and no game was run: no detector exists outside a GPL build (P7). - Nine images were read for their executable's first 4 bytes and their PARAM.SFO; no other game data was read. - YAPSPD was read for chapters 3.1, 4-11 headings, 5, 6, 7, 8.1, 10, 11.1-11.5 (list only); Copetti's article in full; pspsdk headers for ge, display, audio, power. - Every speed number is an estimate whose inputs are named; the GE's costs have no basis in PSP measurements at all.