# Handoff: build `virtualboy-python`, the Virtual Boy board ## Context you are inheriting The family's shape: chips are cores, boards compose cores, CPUs always get their own core (charter). This board's CPU is `v810-python` (`../v810-python`, Phase 0 tonight) in its `Variant.NVC` configuration; it is pinned by commit, never copied. A corner of the CPU found here is raised **on the core**. The VIP and VSU live in this board (chip rule, below). Era 3 (charter) in its CPU, era 2 in its video: a 32-bit RISC with a cache next to a fixed-function tile/world engine. Python is too slow for long runs; rung cases are short. Models to read: `pcengine-python` (a board with the family's sockets, save states and import boundaries), `gameboy-python` (a handheld board with a serial port socket and a cartridge table keyed by SHA-1), `psx-python` docs/domains.md (the domains-and-speed arithmetic this brief follows). Rules: Python >= 3.11, CPython and PyPy; local git only; MIT; nothing read from GPL, LGPL or unlicensed emulators (Mednafen, MAME's `vboy.cpp`, shrooms-vb-core, Lemur, Red Viper: closed); no game bytes committed; Python that reads `reference/` runs with `-I`. ### Read in this order README.md; docs/start-here.md; docs/memory-map.md; docs/vip.md; docs/vsu.md; docs/system.md; docs/cartridge.md; docs/census.md; docs/domains-and-speed.md; docs/validation.md; docs/mame-oracle.md; then the Sacred Tech Scroll in full (`reference/docs/stsvb.html`), and `../v810-python/docs/handoff-brief.md`. ## Scope In: the memory map and its mirrors, the wait controller, WRAM, the game pak (ROM, SRAM, expansion, interrupt), the timer, the game pad (hardware and software reads), the link port with a peer socket, the VIP (memory, registers, interrupts, drawing with all world kinds and objects, the display procedure with the column table and brightness), the VSU, reset, save states, a frame and audio output for hosts. Out: the CPU (v810-python), presentation (how hosts show two eyes on one screen), flash cart programming, the link cable's electrical behaviour, the mirror servo. ## Proposed names - Repository `virtualboy-python`, package **`virtualboy_python`**. - `virtualboy_python.VirtualBoy` (the machine: CPU, board, cart), `board.Board` (the decode), `vip.Vip`, `vsu.Vsu`, `timer.Timer`, `pad.GamePad`, `link.LinkPort`, `cart.RomCart`, `state` (save states in the family's format). - Sockets (Protocols): `GamePak`, `LinkPeer`, `PadInput`. Fakes for tests in `tests/fake_devices.py`, as pcengine-python does. - Output: per game frame, two 384 x 224 arrays of 2-bit values plus the BRTA/BRTB/BRTC and REST values in force (hosts turn them into intensities); per audio block, 10-bit stereo samples at the VSU's rate. ## The chip rule | Chip | Other users | Decision | | --- | --- | --- | | NVC (V810) | PC-FX (µPD70732) | its own core, `v810-python` (CPUs always do) | | VIP | none (MAME 0.285: only `vboy`, and its VIP is inside the driver) | stays in the board, behind an import boundary | | VSU | none (`vboysound` serves only `vboy`) | stays in the board | | timer, pad, link, wait controller | none | stay in the board | ## Unknowns (U) and contradictions (C) - U1 What WRAM does when software skips the 200 µs wait and 8 dummy reads. - U2 What 16- and 32-bit accesses to the byte-wide hardware registers do. - U3 Wait states for WRAM, VIP memory, VSU, game pak RAM and the hardware registers. - U4 CPU accesses to VIP memory while the VIP draws or displays: waits, collisions. - U5 How simultaneous interrupt sources are prioritised onto the INTV pins. - U6 **VIP drawing time** per world kind, row group, object and affine row (STS: research needed; about 2.8 ms for an empty frame). - U7 When the drawn buffer becomes the displayed one. - U8 Which frame buffer is first after reset. - U9 The affine fixed-point accumulation and rounding per pixel. - U10 SCANERR and the servo (modelled as always stable). - U11 The VSU's output divider (41,700 Hz by STS; 41,666.7 Hz if 20 MHz / 480). - U12 The VSU's reset state ("appears" zeroed). - U13 The timer's tick phase (counting up from 0 or down from 4). - U14 The SRAM's address step on the bus (8 bits wide on a 16-bit bus). - C1 Display frame: 20 ms, 50.0 Hz (STS) vs 19.985 ms, 50.04 Hz in MAME (OBSERVED). STS is the judge; MAME is a detector. - C2 The VSU's output rate as written (41,700 Hz) vs the clock arithmetic (U11). ## Milestones (exit tests in validation.md) 0. Board skeleton on v810-python: memory map, mirrors, unmapped reads 0, WCR, WRAM; our own assembled test cart prints through the VIP's frame buffer by software rendering. 1. Timer, pad, link (null peer), interrupts FE00-FE40. 2. VIP drawing: characters, palettes, BKCOL, normal worlds, objects; commercial warning screens. 3. Display procedure, FRMCYC, interrupts and DPSTTS/XPSTTS flags; all 28 retail carts pass their warning screens. 4. H-bias and affine worlds; the drawing-time model (FITTED, U6) with OVERTIME behaviour. 5. VSU. 6. SRAM, save states, then the aftermarket "Hardware Version" builds. 7. Seeded faults, each caught. ## Domains and speed Summary of [domains-and-speed.md](domains-and-speed.md): - **Domains:** CPU (20 MHz, with WRAM, cart, timer, pad, link, wait controller); VIP drawing (clock unknown); VIP display (20 ms frame); VSU (5 MHz base, 41.7 kHz out). - **Channels:** VIP memory (shared), VIP registers and its interrupt, VSU registers (write-only: the VSU is a pure producer from a register-write log), the interrupt lines, the link port. - **Need, with the arithmetic:** CPU at most 20 M instructions/s (one per clock), ~11 M/s typical (MAME's model: 639,093 instructions in 0.05995 s); VIP 43,008 halfword outputs per frame x 50 = 2.15 M/s, times 4-8 worlds each = 9-17 M world-halfword steps/s (HYPOTHESIS, profile first). - **No-JIT verdict:** real time at x-rust on desktop; -fast on a native phone app; -fast plus the VIP on a worker thread in a phone browser, with a cached interpreter for run-ahead. `recompile: none` suffices everywhere. ## Open decisions for Aubrey 1. **VIP and VSU stay in this board** (no second user anywhere). Recommended: yes, behind import boundaries; extract only if a second consumer appears. 2. **The Sacred Tech Scroll is the main judge though it carries no licence.** Facts are cited, nothing copied; no AI-use objection from Guy Perfect or Planet Virtual Boy was found (STS's "About", the PVB document pages, pvbemu's Zlib licence, checked 2026-11-26). Recommended: proceed on facts; optionally ask Guy Perfect for an explicit licence on the document (he licensed pvbemu under Zlib), which would let us quote tables. 3. **Presentation is the host's job.** The board outputs both eyes' 2-bit frames and the brightness/REST values; how column-table repeats change perceived brightness, and side-by-side versus anaglyph versus one eye, are host choices. Recommended: yes; record the column table's effect in the output for hosts that want it. 4. **Drawing time starts FITTED.** Recommended: a cost model per world kind and object, tuned so the empty frame takes STS's 2.8 ms and commercial games show no spurious OVERTIME, every constant tagged FITTED, with a probe queued for a hardware owner. 5. **SRAM table by SHA-1, seeded from MAME's CC0 software list** (with credit), plus a user override. Recommended. 6. **Ask emu-tools-gpl2 for a Mednafen `vb` build** as a second detector (shared with v810-python's decision 5). Recommended: yes. 7. **Default provisional choices** (HYPOTHESIS in code): U3 zero waits outside the game pak; U5 the highest level wins; U7 the swap at FCLK's rise; U8 buffer 0 first; U10 the mirrors always stable; U11 41,700 Hz as STS writes it; U12 VSU zeroed at reset; U14 SRAM on even byte lanes, one byte per halfword address step.