# Handoff: build `v810-python`, the NEC V810 core ## Context you are inheriting The family's shape: chips are cores, boards compose cores, CPUs always get their own core (charter). This core has two first users, `virtualboy-python` (`../virtualboy-python`) and `pcfx-python` (`../pcfx-python`), both at Phase 0 tonight. A board that finds a corner of this core raises it **on the core**. Era 3 (charter): a 32-bit RISC with a cache, modelled at **instruction level with bus transactions**; Python is too slow for long runs, so cases are short and targeted; the Rust tiers carry the playing. Models to read before writing code (copy their shape, never their code): - `sh2-python` (`../sh2-python`): a 32-bit RISC with a cache, a bus contract with `kind` bits, a decode table generated from the manual (`scripts/gen_decode.py`), one small handler per instruction, pipeline timing as data. - `r3000a-python` (`../r3000a-python`, Phase 0 of 2026-11-25): the nearest brief; its bus contract proposal is the template for the one below. - `z80-python`: the readability contract and tooling bar. - `../emulator-lineage/docs/proposals/2026-11-jit.md` (accepted 2026-11-25): sync points, memory kinds, timing as data, and a named handler subset checked by a lint (follow sh2-python's `handler-subset` branch once it lands). Rules: Python >= 3.11, CPython and PyPy; modern forms; no dangerous-looking shell one-liners; local git only; MIT; nothing read from GPL or unlicensed emulators; no firmware or game bytes committed; run Python that reads `reference/` with `-I`. ### Read in this order README.md; docs/start-here.md; docs/isa.md; docs/fpu-and-bitstrings.md; docs/cache-and-timing.md; docs/variants.md; docs/validation.md; docs/mame-oracle.md; then ARCH (U10082EJ1V0UM00) chapters 2, 5, 6, 7 and 9 in full, HW (U10661EJ5V0UM00) chapters 2.3, 3 and 4, and STS's CPU chapter (`reference/docs/stsvb.html`, "CPU - NVC/V810" to "Opcode Map"). ## Scope In: the integer unit, the system registers, exceptions, interrupts (a 4-bit level plus INT and NMI inputs), HALT, the FPU instructions, the bit-string instructions with their resume state, CAXI's locked sequence, the instruction cache with clear/dump/restore, the address trap, the bus contract with 32-bit and 16-bit modes, the instruction timing model, the NVC configuration (six instructions, sysregs 29-31, its PIR), a disassembler and a small assembler. Out (the boards): every address decode, wait states (returned by the board per transaction), the Virtual Boy's timer, pad, link and wait controller, the PC-FX's interrupt controller (it drives the level pins), all video and sound. ## Proposed names - Repository `v810-python`, package **`v810_python`** (the 2026-11-12 naming rule). - `v810_python.V810`: the core, configured by a `Variant` value: `Variant.UPD70732` (the stock part: PIR per ARCH, no NVC opcodes) and `Variant.NVC` (Nintendo's). Two variants of one class rather than two classes: the differences are six decode rows, three registers and a constant. - `v810_python.bus`: `read(address, size, kind) -> (value, cycles)` and `write(address, size, value, kind) -> cycles`; `kind` bits from HW 2.3's status table: `FETCH`, `BRANCH_FETCH`, `DATA`, `IO`, plus `LOCKED` (CAXI) and observe-only `HIT` (a cache hit, no bus cycle). - `v810_python.disasm`, `v810_python.asm`, `v810_python.trace` (MAME-comparable lines). ## The bus contract (proposal, to settle in the first commit) The core strips nothing (the V810 has no MMU): addresses are 32-bit; the board masks (the Virtual Boy uses 27 bits). Each access is one transaction of 1, 2 or 4 bytes as the instruction asks, with the bus mode deciding how many bus cycles a word costs: in 16-bit mode the core issues a word as two halfword transactions, low then high (HW 3.2), so the board's waits are charged per halfword. The board returns the cycles each transaction takes beyond T1 + T2 (its waits). Instruction fetches go through the cache model; a miss becomes `FETCH` transactions for the sub-block(s) (U1's default: the missed 4-byte sub-block only, HYPOTHESIS). `run(cycles)` runs to a budget and returns at an instruction boundary or, inside a bit-string instruction, at a resumable step; `set_interrupt(level: int | None)` and `set_nmi(bool)` drive the inputs. ## Unknowns (U) and contradictions (C) - U1 A cache miss fills one 4-byte sub-block or the whole 8-byte block. - U2 Whether ICHEEN is tied active on both boards (assumed yes). - U3 How the two sub-block valid bits sit in the dumped tag word. - U4 The PC-FX's bus mode (32-bit or 16-bit fixed). - U5 System registers 29-31 on the µPD70732. - U6 PIR on the PC-FX's part. - U7 Whether every free opcode traps as invalid on each part (the NVC opcodes on the stock part). - U8 What state an interrupted DIV or FPU instruction leaves (assumed none: restart). - U9 The register result of an FPU overflow before the trap. - U10 The data-dependent clocks of DIV and the FPU instructions inside ARCH's ranges. - U11 Where inside a bit-string instruction an interrupt can be taken. - U12 The bus accesses a bit-string transfer makes, and their order. - U13 The source of STS's clocks for the NVC additions. - U14 Stage timing: how a load's result interlocks with the next instruction beyond the 3/2/1 rule. - U15 How a cache fill overlaps execution. - U16 How board waits add to ARCH table 5-11's "no wait" minimum. - U17 The PC-FX's crystal and CPU divider (21.47727 MHz assumed). - C1 Cache valid bits: one per 4-byte sub-block (ARCH fig. 7-1) vs one per entry (STS). - C2 PIR: 0000810Xh (ARCH 2.2.5) vs 00005346h on the NVC (STS). Both may be right (different parts); MAME reads 0. - C3 TRNC.SW: 8-14 clocks (ARCH table 5-11) vs 9-14 (STS). - C4 ARCH table 5-13 TYPE4, 16-bit bus, Nth word: 6N + 36 where the other rows give 12N + c. - C5 ARCH table 5-13's caption says "without cache hit"; tables 5-11 and 5-12 say "with". - C6 REV: STS's table reads reg1, its prose reg2. - C7 MAME's timing (about 1.9 clocks per instruction in the VB's WRAM-clear loop) is MAME's model, not evidence. ## Milestones (rungs; exit tests in validation.md) 0. Decode table generated from ARCH appendix C + STS, disassembler matching MAME's text on the recipe's traces, assembler able to build `gauntlet.s`, state/trace/debug tools in z80-python's shape. 1. Instruction semantics from ARCH 5.3's pages, the FPU rules, the bit strings. 2. Pizza Gauntlet reaches `done` (NVC). 3. MAME lockstep on the two recorded windows (PC-FX BIOS, Mario's Tennis). 4. On the boards: VB carts boot; the PC-FX BIOS reaches its menu. 5. Timing reproduces ARCH tables 5-11..5-14 under their stated conditions. 6. Seeded faults, each caught. ## Domains and speed **The core is one domain** (the CPU and its bus), with the boards' channels at its edge: the bus (every transaction can reach another domain's registers), the interrupt inputs (level pins and NMI) and HALT. Sync points: every bus transaction to a board-declared device region, and every instruction boundary (where interrupts are sampled); inside a bit-string instruction, each resumable step. **Memory kinds** for a cached interpreter's invalidation map come from the boards: Virtual Boy ROM (never written), WRAM (CPU only), VIP memory (CPU and the VIP's drawing); PC-FX BIOS ROM, RAM (CPU and the KING's DMA? pcfx U-list), backup RAM. The V810's i-cache never sees stores (cache-and-timing.md), so a decoded-block cache keyed on the i-cache's own lines is exact for cached code, as r3000a-python found for the R3000A. **Instructions per second needed:** at most one instruction per clock (ARCH: "1 clock pitch"), so **20.0 M/s (VB) and 21.5 M/s (PC-FX) are hard ceilings**. Real code runs well below: loads cost 1-5 clocks, branches 3, waits 1-2 per game pak access, DIV 36-38; MAME's own model gives 10.7 M/s (VB) and 13.3 M/s (PC-FX boot) (mame-oracle.md). Working need: **~11-14 M/s typical, 21.5 M/s ceiling.** **What the tiers give** (measured on this machine for the nearest relative, a 32-bit RISC transcription: sh2-rust 30-47 M instructions/s native, 20-27 M as wasm32 under Node, psx-python docs/domains.md; HYPOTHESIS that v810-rust lands in the same band, to be measured; device ratios as psx-python: phone ~0.8x desktop native, browser ~0.6x): | Target | v810-rust | v810-rust-fast (x1.4-1.9) | cached interpreter (x1.5-3 over -fast, HYPOTHESIS) | Need | Verdict | | --- | --- | --- | --- | --- | --- | | Desktop native | 30-47 M | 42-89 M | 63-270 M | 11-21.5 M | real time already at x-rust | | iPhone app, native (no JIT) | 24-38 M | 34-71 M | 50-210 M | 11-21.5 M | real time at x-rust; -fast for run-ahead | | Browser (wasm), desktop | 18-28 M | 25-53 M | 38-160 M | 11-21.5 M | -fast comfortable | | Browser (wasm), iPhone Safari | 14-23 M | 20-43 M | 30-130 M | 11-21.5 M | -fast enough; cached interpreter for 2-frame run-ahead | **The no-JIT path reaches real time on all three targets for the CPU alone**, with `recompile: none`. The boards' other domains (the VIP's drawing, the PC-FX's KING and Rainbow) decide the frame cost: see each board's domains document. Python itself runs at roughly 0.1-0.2 M instructions/s (sh2-python's order), about **1/100-1/200 of real time**: correctness only. ## Open decisions for Aubrey 1. **One class `V810` with two variants (`NVC`, `UPD70732`)**, not two classes or two repositories. Recommended: the difference is six opcodes, three registers and a constant; the boards choose the variant. 2. **Instruction level with bus transactions; no stage model.** Recommended: NEC publishes minimum clocks and three pairing rules, not stages; a stage model would claim more than the evidence. 3. **The instruction cache in the specification.** Recommended: stale lines are observable (no snooping), and the PC-FX BIOS manages the cache on every boot. 4. **An assembler of our own in the package**, so Pizza Gauntlet and the probes build without the GPL binutils or the llvm-v810 toolchain (its makefile names `$(HOME)/llvm-v810`). Recommended: a two-pass assembler for the subset the tests use is small, MIT, and doubles as the disassembler's round-trip test. 5. **Ask emu-tools-gpl2 for Mednafen `vb` and `pcfx` builds** (its `build.py` knows `pce` and `ss`; Mednafen 1.32.1 has both modules) as a second detector beside MAME. Recommended: yes, untouched builds, run only; a trace patch only if lockstep needs it. 6. **MAME's BSD-3 V810 files stay closed.** Recommended: keep them closed (MAME's v810 is "preliminary" in both drivers and reads PIR and TKCW as 0; the manuals are better); revisit only for a question nothing else answers. 7. **Pizza Gauntlet is pinned but unlicensed:** run only, nothing copied. Recommended: ask its maintainers (Planet Virtual Boy) for a licence if the family wants to ship it in a test suite; until then it stays in `reference/`. 8. **Default provisional choices** (Aubrey's 2026-11-12 rule), each HYPOTHESIS in code until judged: U1 fill the missed 4-byte sub-block only; U2 ICHEEN active; U4 PC-FX 32-bit bus (the board decides); U7 every free opcode traps as invalid on both parts; U8 interrupted DIV/FPU restart from scratch; C1 two valid bits (ARCH, the manufacturer, over STS); r1-r31 zero at reset (a modelling choice).