# Handoff brief: play-pce ## The request Aubrey, 2026-11-12: "get our rust version and rust fast and the play-pce site ready", and **"I would like the play version to be any game in the pce family"**: HuCards (PC Engine and TurboGrafx-16), SuperGrafx cards, and CD-ROM², Super CD-ROM² and Arcade Card discs, in one page, for `play-pce.supertux.com`. ## What it is The PC Engine family in the browser: the family's Rust boards behind wasm-bindgen, with the page of the family's other sites. Model it on **`/data/emu/play-nes`** (branch `run-ahead`, the newest: `src/lib.rs`, `web/app.js`, `web/audio-worklet.js`, `web/index.html`, `web/style.css`, `scripts/build-wasm.sh`, `build-dist.sh`, `bench-node.mjs`, `check-browser.mjs`, `check-run-ahead.mjs`, `deploy/`, `README.md`) and `/data/emu/play-2600` and `/data/emu/play-md` for anything play-nes lacks (7z and zip loading, the round 8-way touch pad, phone landscape with controls over the picture, fullscreen, add-to-home-screen, per-game settings, IndexedDB). Copy the page's shape and behaviours; change what the machine changes. Package `play-pce`, MIT. The boards (all local, by path; the session that started you repins to GitHub revisions later): - `/data/emu/pcengine-rust` (crate `pcengine_rust`): the base board. **Depend on it under a name you can repoint**: `/data/emu/pcengine-rust-fast` is a speed fork being built right now with the same crate name and public API; the page will switch to it by changing one path (use a single `[patch]` or path entry so the add-ons follow). Do not touch that repository. - `/data/emu/supergrafx-rust` (crate `supergrafx_rust`): `is_supergrafx_card(bytes, name)`, `SuperGrafx::with_card(bytes, compat).build()`. - `/data/emu/pcenginecd-rust` (crate `pcenginecd_rust`): `PcEngineCd::new(system_card, disc)`, `arcade_card`, `bram`, the `SectorSource` trait, `parse_cue` without a filesystem, `unit.bram()`. - Read each crate's README ("public API", "Using the crate") before writing the wrapper. All three give a `pcengine_rust::system::System`, so one console type wraps them all. ## What the page must do 1. **Load any game of the family** from the user's own files (nothing is bundled; BYOR): - HuCards: `.pce`, and inside `.zip` / `.7z`. US cards need the TurboGrafx-16 row (the region bit): decide by a "(USA)" file name, with a per-game override (PC Engine / TurboGrafx-16). - SuperGrafx: by `is_supergrafx_card` (five known hashes or a `.sgx` name), with a per-game override "run as SuperGrafx" (other dumps and the Darius hybrid cards) and the compat switch. - CDs: a `.cue` with its `.bin` file(s), chosen together (multi-select or a folder; drag and drop of several files). The **System Card is bring-your-own**: asked for once, kept in IndexedDB (as play-nes keeps the FDS BIOS), replaceable; a 256 KiB image is a Super System Card. An "Arcade Card" setting per game (and on by default when the disc is one of the three known Arcade Card titles if you can tell without bundling data you may not ship). - `.chd` is not supported by the crate: say so plainly in the page when one is dropped (and how to convert: `chdman extractcd`). Do not add a CHD reader without checking its licence is permissive; if one is clearly MIT/BSD and small, report it as an option instead of adding it. 2. **Discs are large** (200-800 MiB) and the crate reads sectors **synchronously**. Never copy a whole disc into wasm memory. Choose the design and justify it in the README: either the emulator in a Web Worker reading `File` slices with `FileReaderSync`, or the main thread with the page holding the files and a chunked cache filled ahead of the drive (the drive's seek and read delays give time), or another that works on phones. Whatever is chosen must keep audio glitch-free and must be checked with a real disc under headless Chromium. 3. **Picture**: the frame is 242 rows whose widths can differ by row (341, 455 or 682 dots) of 9-bit colours; `vce.rgb_table` gives RGB. Scale each row to a common width (the widest in the frame), 4:3 presentation, integer or smooth scaling as the other sites do. 4. **Sound**: 44.1 kHz stereo from `take_audio()` (PSG, CD audio, ADPCM already mixed) through the audio worklet, paced as play-nes paces it. 5. **Input**: keyboard, gamepads and touch: d-pad (round, 8-way), I, II, Select, Run; a 6-button pad option (III-VI) and the multitap (up to five pads) as settings; turbo for I and II is a nice-to-have. 6. **Persistence** (IndexedDB): the System Card; backup RAM (the CD unit's 2 KiB `unit.bram()`, one shared store like a real console, exportable and importable; and the Tennokoe/Populous card RAM if the board exposes it); save states per game (several slots, with the disc named, not stored: loading needs the same disc chosen again, say so); per-game settings. 7. **Run-ahead** (the snapshot pair) as in play-nes's `run-ahead` branch: a setting, default off. 8. A game list from the user's own drops is fine; no ROM, BIOS, disc, or copyrighted title data is bundled. If a title database would help (which cards are US, which discs need the Arcade Card), use only data with a clear permissive licence and say which; otherwise file names and settings decide. ## Checks (scripts, as play-nes has them) - `scripts/bench-node.mjs`: frames per second under Node for a HuCard, a SuperGrafx card and a disc (with the files given on the command line; skip what is absent). - `scripts/check-browser.mjs` (headless Chromium): loads a HuCard, a SuperGrafx card and a disc (System Card + cue/bin), presses RUN, and reports the frame rate held, audio underruns, that the picture is not blank, the d-pad slices, landscape layout, a save state saved and loaded, backup RAM persisted across a reload. - `scripts/check-run-ahead.mjs`. - Test media, bring-your-own, read in place, never copied into the repository or `dist/`: HuCards `/data/emu/roms-retrobat/pcengine/*.7z`; SuperGrafx `/data/emu/roms-retrobat/supergrafx/*.7z`; discs `/data/emu/roms-retrobat/pcenginecd/*.chd` (extract one with `chdman extractcd` into `scratch/`, remove after); System Card `/data/emu/share/batocera/bios/syscard3.pce`. ## Rules - Do not modify the board crates, their speed fork or play-nes / play-2600 / play-md. If a crate's API blocks the page (the CD crate notes that reading backup RAM needs `&mut Board`), work within it and report what would make it cleaner. - **No GPL or LGPL code** in the page or its dependencies: check every crate and JS file you add (zip and 7z readers as play-nes pins them are fine if their licences are permissive: state each dependency's licence in the README). Do not open any `reference/` directory. - Nothing bundled that is not ours: no ROMs, BIOS, discs, screenshots or logos of games or of NEC. - **Do not deploy** (`scripts/deploy.sh` exists for Aubrey to run), do not create a GitHub repository, do not push. Build `dist/` and leave it. - wasm toolchain: the rustup 1.93.1 toolchain (see play-nes `rust-toolchain.toml` and `scripts/build-wasm.sh`; `/usr/bin/cargo` has no wasm std), wasm-bindgen pinned exactly as play-nes pins it. - At most 8 processes, `nice`. No `sed -i`, `rm -rf`, `ln -sfn`. Temp files under `target/`, `scratch/` (gitignored). - Commits locally at good points, trailer `Co-Authored-By: Claude Fable 5.2 `. - Report: what works checked how (the numbers from each check script, for a HuCard, a SuperGrafx card and at least two discs, one with the Arcade Card), the disc design chosen and why, wasm size, every dependency and its licence, what is not done, and what Aubrey has to do to deploy.