# Handoff: build `i960-python`, the Intel 80960KB/KA core ## Context A CPU core of Aubrey's emulator family (charter: emulator-lineage `docs/charter.md`). Its first and only planned consumer is [model2-python](../model2-python) (Sega Model 2, all revisions). No family core is related: the i960 shares nothing with the family's other RISC cores (r3000a, vr4300, sh2, v810, arm7tdmi) beyond being 32-bit. Read [architecture.md](architecture.md), [validation.md](validation.md), [mame-oracle.md](mame-oracle.md) and [sources.md](sources.md), then run `python -I scripts/fetch_references.py` (8 files, about 56 MB; `--verify` to check). ## Scope The 80960KB as Model 2 uses it, with a `has_fpu=False` variant for the KA. Not the MC's MMU/tags, not the later Cx/Jx/Hx parts. Bus-transaction exact: every L-bus access the chip makes (instruction fetches, bursts, loads/stores, register-set spills and fills, interrupt table and stack accesses) in order, with Intel's timing. ## Package and classes (proposed) ``` i960_python/ decode.py # the opcode table as data: format, operands, class, appendix C cost row cpu.py # I960: registers, IP/AC/PC/TC, step(), the scoreboard, run_until(deadline) regcache.py # the four local register sets, spill/fill order, erratum-4 option memory.py # MEMA/MEMB effective addresses, bus callback (address, width, kind, burst) faults.py # fault table, fault records interrupts.py # interrupt table, pending bits, priority, the four pins / 8259 mode fpu.py # fp0-fp3, 80-bit extended arithmetic in integers (KB variant only) timing.py # appendix C tables, interlocks disasm.py # for traces ``` ## The import boundary and sockets The core owns the registers, the register cache, the instruction cache (once U3 is settled), the scoreboard and the timing tables. The board owns memory, wait states, interrupt sources and the copro FIFOs. Sockets: 1. `BusPort.read(addr, width, kind) -> (value, waits)` / `write(...)`, `kind` in fetch, data, spill, fill, table, with burst length. 2. Interrupt inputs: four pins or a vector source (8259 mode), level and edge as KBHDRM. 3. Reset and a cycle budget: `run_until(t)` returns at the first bus access whose time the board must decide, so the board can catch up other domains at channels. 4. A trace hook (IP, registers, cycle) for lockstep against `model2-python`. ## Unknowns (U) and conflicts (C) | # | Unknown | Best source now | | --- | --- | --- | | U1 | KB or KA in Model 2, and stepping (affects FP and erratum 4) | MAME says KB; a board photo or FP opcode counts in traces | | U2 | Whether the interrupt-return flushes (erratum 4) apply to Model 2's chip | SPECUPD lists steppings; stepping unknown | | U3 | Instruction cache line size, fill policy, what a miss costs on the L-bus | KBPRM appendix C (pipeline), KBHDRM burst chapter: not yet read in full | | U4 | Interrupt latency in clocks from pin to first handler fetch | KBPRM ch. 8, appendix C | | U5 | Behaviour of reserved opcodes and unaligned accesses on the KB | KBPRM fault chapter; MAME `fatalerror`s here, so no detector | | U6 | Exact FP results in extended precision for the transcendental-free subset the games use | KBPRM ch. 12 (judge); no detector (MAME uses host double) | | # | Conflict | Sides | Proposal | | --- | --- | --- | --- | | C1 | instruction length | KBPRM 2-3 "all instructions are 32 bits long"; KBPRM 3-6 "one or two words" | two words for MEMB with displacement (the format tables decide) | | C2 | throughput at 25 MHz | KBPRM 2-6: 10 MIPS average; MAME: 0.67 per clock = 16.7 M/s on `vf2`'s boot | Intel's tables; MAME's cycle counts are its own constants | ## Milestones The rungs of [validation.md](validation.md), in order: R0 decode table, R1 integer core, R2 calls and register cache, R3 faults/interrupts/start-up, R4 timing, R5 FPU. A self-checking test program is needed from R1 on (decision I5). ## Domains and speed **Domains and channels.** The i960 is one domain on Model 2's main board, with its RAM and the board's registers behind it. Its channels to other domains are the copro (TGP, SHARC or TGPx4) input and output FIFOs, the geometrizer's command RAM, the sound board's serial link (an 8251-type UART, 31.25 kbaud class), the I/O chip and the interrupt controller (model2-python docs/domains-and-speed.md). The core's job for the board is a `run_until(deadline)` that stops at those channel accesses. **Instructions per second needed.** Model 2's i960 runs at 25 MHz (MAME's 50 MHz crystal / 2, OBSERVED). Intel rates the KB at 10 MIPS average at 25 MHz (KBPRM 2-6, DOC); the peak is one instruction per clock, **25 M/s**. MAME's model retired 0.67 per clock on `vf2`'s boot (16.7 M/s, OBSERVED). Plan for 10-17 M/s typical, 25 M/s peak. Budgets in desktop-equivalent host cycles per instruction, with the N64 Phase 0's host assumptions (5.0 / 4.0 / 2.4 GHz-equivalent for desktop, phone app, phone browser: n64-python docs/execution-architecture.md): | Rate | Desktop | Phone app | Phone browser | | --- | ---: | ---: | ---: | | 25 M/s (peak) | 5.0e9 / 25e6 = 200 | 160 | 96 | | 16.7 M/s (MAME's ratio) | 299 | 240 | 144 | | 10 M/s (Intel average) | 500 | 400 | 240 | The family's measured yardstick for an exact era-3 interpreter is sh2-rust-fast at about 145 host cycles per instruction on an E-core, 89 on a P-core, most of it time-keeping (sh2-rust-fast docs/status.md, quoted by the N64 document). Against that: - **x-python** at 0.2-1 M instructions/s on PyPy (HYPOTHESIS, from sh2-python's 1.33-2.38 M on a minimal harness, before a board's overhead) is 1/12 to 1/125 of real time: test programs and short slices only, as the late-era method expects. - **Rust `-fast`, no JIT:** real time on desktop and phone app with margin, and in a phone browser if the time-keeping stays below ~100 cycles per instruction at peak. The appendix C tables make time-keeping a table lookup plus the scoreboard, the cheap kind the N64 document recommends. - **Cached interpreter, threads:** not needed for the CPU alone. The board's load is in the geometry DSPs and the rasteriser (model2-python), not here. - So `recompile: none` reaches real time on all three targets for this core (HYPOTHESIS until i960-rust-fast is measured: the first measurement to take). ## Open decisions for Aubrey - **I1. Model the KB, with a KA variant flag.** *Recommend* yes: every MAME Model 2 set says KB; the KA costs one flag. - **I2. Bus-transaction exact with Intel's appendix C timing as data** (decode table rows carry their cost class). *Recommend* yes: it is the "timing as data" rule with a tier-2 source behind it. - **I3. Instruction cache modelled** (as state, for purge behaviour and miss timing), once U3 is read. *Recommend* yes, behind the timing rung; MAME omits it, so it will be a documented difference. - **I4. Erratum 4 as a stepping option**, default on (the C stepping is what Intel shipped from the 1990s: SPECUPD). *Recommend* yes, provisional until U1/U2. - **I5. A test-program toolchain.** No permissive i960 assembler is in the family; GNU binutils' i960 support is GPL (and, as far as this phase knows, long dropped upstream: not checked). *Recommend* a small assembler inside this repository's tests (the decode table run backwards), so test programs are MIT and self-checking. - **I6. MAME's BSD-3 i960 files: read for facts, never transcribed.** *Recommend* facts and cross-checks only (a notice in `docs/sources.md`), so the core stays a specification from Intel's manuals; transcription is legal under BSD-3 with the notice, but would import MAME's approximations (no I-cache, host-double FP, its cycle constants). - **I7. bitsavers' 403.** *Recommend* recording bitsavers.org as "refused this machine (403 on every path, 2026-11-26)" without treating it as an AI objection, and keeping the UK Mirror Service copies; if Aubrey reads it as a wish, move the four Intel PDFs to `trash/` and fetch from Intel or the Internet Archive instead. - **I8. sources.md rows** (Aubrey's file): "Intel 80960KB/KA/MC manuals and specification update: Intel's copyright, facts only, cite page; fetched from the UK Mirror Service's bitsavers copy" and "MAME `cpu/i960/*` (Farfetch'd, R. Belmont): BSD-3-Clause by `license:` lines at f379cd0; code OK (with notice), used for facts only".