# Handoff: build `jrisc-python`, the Jaguar's GPU and DSP core ## Context you are inheriting The family's shape is **chips are cores, boards compose cores**. Each core is certified on its own against its oracles and pinned by commit by the boards that use it. This core's first user is `jaguar-python` (`/data/emu/jaguar-python`, its own Phase 0 in progress; do not edit it); a later `cojag-python` would be the second (same processors at 26 MHz, no 68000). A board that finds a corner of this core raises it **on the core** (an issue or a PR here; re-certification is fine), never as a workaround in the board. Models for the code and tooling: `z80-python` (readability contract: one instruction family per module, one mnemonic per handler docstring, the source and tier as a comment on the line that encodes a fact; tooling bar; `docs/` layout), `m68000-python` (a core with a prefetch queue and a clock total per step; its "reference-core boundary" section), `huc6280-python` and `sm83-python` (rung ladders; sm83's die-model referees are the closest thing in the family to the netlist referee planned here). The user's rules that bind this work: - **Oracle tiers** ([validation.md](validation.md)); a low tier is a detector, never a judge; state the tier of every claim, in the code too. - **Python floor 3.11** (the newest PyPy supports); CPython and PyPy both green; ruff `target-version = "py311"`. Watch PyPy's 80-attribute limit on the core object (`len(vars(cpu))`): put the register file and the pipeline state in lists, not one attribute each. - **Reference cores are correct, not fast.** `-fast` and Rust forks are later. - **Modern over compat**; no external users yet. - **Never copy code between repositories**; never copy netlist text or MiSTer (GPL) code into this MIT core: cite file and line, describe in our words. - **The user has no Jaguar hardware.** No rung needs a console. - No dangerous-looking shell one-liners in scripts or docs; local git only until the user says otherwise; keep CI minimal if a remote ever exists. - Run any Python that reads `reference/` with `python -I`. ### Read, in this order, before writing code 1. `README.md`, then [start-here.md](start-here.md). 2. [instruction-set.md](instruction-set.md), [pipeline-and-bugs.md](pipeline-and-bugs.md), [interrupts.md](interrupts.md), [timing.md](timing.md). 3. [netlists.md](netlists.md) and [validation.md](validation.md). 4. [mame-oracle.md](mame-oracle.md), [census.md](census.md). 5. The board's `docs/interrupts.md`, `docs/bus-arbitration.md`, `docs/memory-map.md` (`/data/emu/jaguar-python`), for the other side of the contract. Then `python -I scripts/fetch_references.py --verify` (the pins), and `python -I scripts/opcode_tables.py --quiet` to see the table run. (`mcode_table.py`, `netlist_comments.py` and `lint_referee.py` stop with a message since 2026-11-25: docs/provenance.md, "Netlists and source tables out".) ## Scope One stand-alone core: the RISC processor of Tom and Jerry, both variants, with its register file, prefetch unit, scoreboard and write-back, ALU, shifter, multiplier, saturator, divider, MAC and systolic MMULT unit, interrupt latches and entry, control registers, gateway (the processor's side of external transfers), its local bus controller with the local RAM, the DSP's wave-ROM slot and the GPU's LOCK bit, and the outside I/O port into that bus (decision 3, agreed with the board). Everything else in Tom and Jerry (Blitter, Object Processor, video, memory controller, arbiter, timers, I2S, UART, DACs, joystick, the wave-ROM image) is the board's. Chip rule: CPUs always get their own core; these two are one design, so one core. ## Names (decision 1) - Distribution **`jrisc-python`**, import package **`jrisc`**: "JRISC" is the name the community and the toolchains use for the architecture (rmac's `risc.tab`, vasm's `jagrisc`, `cubanismo/jrisc_tools`, the AtariAge and jagdox pages), it names the design rather than one chip, and both processors are it. Atari's manual has no architecture name, only "Graphics Processor" and "DSP". - Classes **`JaguarGPU`** and **`JaguarDSP`**, both subclasses of **`JaguarRISC`**, which holds everything shared. The variant classes carry data (RAM base and size, the six opcode slots, interrupt count, accumulator width, extra registers, MMULT mask, bus width) and the handful of handlers that exist in one variant only. Names follow the manual's terms and MAME's device names (`jaguargpu`, `jaguardsp`); "Tom"/"Jerry" are the chips, not the processors, so they are not used for the classes. ## The core boundary | Piece | Owner | Why | | --- | --- | --- | | instruction set of both variants, flags, register banks, REGPAGE/IMASK bank force | core | it is the processor | | prefetch queue, delay slot, scoreboard, write-back timing, the stall rules | core | visible to programs (bugs B1, B2, B13; [pipeline-and-bugs.md](pipeline-and-bugs.md)) | | divider, MAC accumulator (32/40 bit), systolic MMULT | core | inside the processor block | | control registers `F02100-F0211F` / `F1A100-F1A123` (FLAGS, MTXC, MTXA, END, PC, CTRL, HIDATA, MOD, REMAIN/DIVCTRL, MACHI) | core | inside the block; the board's draft agrees ("meaning of flags, PC: jrisc") | | interrupt latches, enables, IMASK, priority, the injected entry, atomic sequences, CPUINT output | core | `INTER-UA.NET`/`DSP_INT.NET`; agreed with the board ([interrupts.md](interrupts.md)) | | the gateway's processor side: transaction issue, two outstanding external loads, HIDATA update on every external load, DSP 16-bit splitting | core | `GATEWAY.NET`/`DSP_GATE.NET` | | **local bus controller**: local RAM bytes (4 KB / 8 KB), the DSP's wave-ROM slot (image handed in by the board), the local-bus priority (outside I/O, gateway, load/store, fetch), the GPU's LOCK bit (reset value a constructor argument) | **core** (decision 3, **agreed with the board's final brief**) | `GPU_MEM.NET` / `DSP_MEM.NET`; see below | | shaping each interrupt source into a one-tick pulse (edge detectors, synchronisers) | board | belongs to the source | | the 16-bit pairing of slave accesses, BIG_IO byte order on the slave port, the `+$8000` 32-bit write port decode | board | the board's draft claims it; it decodes the 68000's accesses | | memory controller, arbiter, grant latency, memory cycle lengths | board | `bus-arbitration.md` | | Blitter registers (decoded on the GPU's local bus), DAC/I2S registers (decoded on the DSP's) | board, reached by `local_io` with no bus cost | not processor blocks | | `INT1`/`INT2`, `J_INT`, timers, I2S, UART, pins, the `NOCPU` strap | board | | ### Local RAM: settled between the two Phase 0s (decision 3) The board's first draft (`memory-map.md`) gave the local RAM bytes to the board; this repository's draft gave them to the core. The board's final brief (`jaguar-python` @ `9398480`, `docs/handoff-brief.md` section 4 and its open decision 3) now recommends **the core**, and this brief agrees. Reasons on the core side: the netlist puts the RAM and its arbitration in the processor's own local bus controller (`GPU_MEM.NET`, `DSP_MEM.NET`; the DSP's RAM and wave-ROM slot are inside `DSP.NET`, l.167); the processor fetches from it, reads its MMULT matrix and pushes its interrupt return there every few ticks, so a callback per access would be the hottest path in the emulator; outside accesses are a priority port on that bus that steals a tick from the processor; a core certified alone (rungs 1-4) and a later CoJag board both need it; MAME's processor model, Virtual Jaguar and the MiSTer core keep it there too. The board's former reasons (four masters reach the RAM, one owner for every byte, Tom instancing `GPU_RAM` in `GRAPHICS.NET` l.180 beside the GPU block) are met by the outside I/O port: the board keeps the **16-bit pairing latch** of `GPU_CPU.NET` (low-address write latches, high-address write commits; low-address read fetches and latches; `+$8000` is the 32-bit port) using the core's `big_io`, and calls `io_read32`/`io_write32`. Save states: the board's state includes the core's, as it must for the registers anyway. ## The contract (proposed; decision 5) The names below are the board's final brief's (section 4), adopted unchanged so the two briefs match: ```python gpu = JaguarGPU(bus, local_io, reset_lock=False) dsp = JaguarDSP(bus, local_io, wave_rom=jagwave_bytes) # core -> board bus.read(address, width, clock) -> (value, done_clock) # an external transaction outside local space; bus.write(address, value, width, clock) -> done_clock # width 1, 2, 4, 8 bytes (the DSP core splits # into 2-byte transactions itself); clock = the # tick the gateway requests the bus; the board # arbitrates and says when it completes local_io.read(offset, clock) / local_io.write(offset, value, clock) # local-space registers the core does not own: # Blitter (GPU), DAC/I2S (DSP); no bus cost on_cpu_interrupt() # CPUINT written (a pulse) # board -> core core.io_read32(address, clock) / core.io_write32(address, value, clock) # the outside I/O port into local space (RAM, # control registers); highest local-bus priority core.raise_interrupt(n) # a one-tick pulse, already shaped by the board core.run_until(clock) # advance; returns at once if GO is clear core.next_event_clock() # when the core next needs the board (a bus request) core.big_io; core.running # BIG_IO for the pairing latch; GO core.dmaen; core.bus_hog # for the board's priority choice ``` - `on_cpu_interrupt` is passed as the board wires it (a constructor argument or an attribute; the build sessions settle the spelling together). - The latch rule (a pulse sets a latch only if its enable is set) is the core's; the shaping into pulses is the board's ([interrupts.md](interrupts.md)). - The board advances each processor with `run_until` to the next clock at which another master could affect it (an I/O write, a pulse, a bus event), the catch-up discipline of the board's `bus-arbitration.md`. Inside `run_until` the only callbacks are `bus`, `local_io` and `on_cpu_interrupt`. - A `step()` that retires one instruction (or one interrupt entry) and returns its ticks is for tests and tooling. - Plain integers and lists in the hot path, no generators, so a Rust or `-fast` fork can transcribe it. ## Proposed layout (the build session may refine) `src/jrisc/`: `core.py` (`JaguarRISC`: state, `step`, `run_until`, slave port), `gpu.py`, `dsp.py` (the variants as data plus their own handlers), `_decode.py` (the 64-slot tables generated from the microcode columns, one per variant), `_alu.py` (add/sub/logic with the netlist's carry rule), `_shift.py`, `_mult.py` (MULT, IMULT, MAC, MMULT), `_divide.py`, `_loadstore.py`, `_flow.py` (JUMP, JR, MOVE PC, MOVEI), `_special.py` (SAT*, PACK/UNPACK, MTOI, NORMI, MIRROR, modulo), `_pipeline.py` (prefetch queue, scoreboard, write-back schedule), `_interrupts.py`, `state.py`, `disasm.py`, `trace.py`, `debug.py`, `harness.py` (flat memory + fixed-latency bus for tests), `__main__.py`, `py.typed`. ## Unknowns (U) and contradictions (C) Contradictions between sources: - **C1** FLAGS written by STORE: TRM p.59 "at least one other instruction" before use; HWB item 11 "two NOP instructions". CoJag code (fishfren) uses two. - **C2** DSP DIV_OFFSET: TRM p.111 bit 1; both `DIVIDE.NET` copies data bit 0 (and TRM p.61 says bit 0 for the GPU). - **C3** PACK/UNPACK flags: TRM "unaffected"; `Mcode.rom` word `00069806` loads Z N C; MiSTer edited it to `00069006` to match the manual. - **C4** C after AND/OR/XOR/NOT/BTST/BSET/BCLR, MULT/IMULT/IMULTN, MTOI, NORMI, SAT*: TRM "not defined"; the netlist reloads C every time (adder carry or shifter carry by result selector, `ARITH.NET` l.260-262, l.296-381); MAME and Virtual Jaguar leave C unchanged. **Read, not simulated.** - **C5** throughput: TRM one per tick peak, about three-quarters typical; the libretro Verilator report: two ticks for every back-to-back register-writing instruction with disjoint registers (second-hand). - **C6** DSP opcode 62: TRM silent; rmac assembles SAT24; MiSTer NOP; MAME illegal. - **C7** interrupt latch: comment "The interrupt mask prevents them being set"; the gates use the enable bits (`INTER-UA.NET` l.55-61, `DSP_INT.NET` l.58-66). **Read, not simulated.** - **C8** TRM p.131 lifts the prototype's "illegal instruction sequences"; TRM p.40 keeps an illegal list. - **C9** prefetch queue: `PREFETCH.NET` header "a 32-bit prefetch queue holding a total of two instructions"; its logic and Tom bug 14: two longs, up to four words. - **C10** SAT16S N: TRM "cleared"; N = result bit 31 by the netlist rule (with MiSTer's word) and in MAME, so set for negative results. - **C11** MMULT flags: TRM "reflect the final multiply/accumulate operation"; the microwords say MMULT and IMACN load no flags and the forced IMULTN does, which would leave the flags of the first product unless `SYSTOLIC.NET` overrides (not read). - **C12** indexed STORE (60, 61): TRM p.56 says the offset is the destination field; MAME and rmac put the offset in reg1 and the data in reg2. - **C13** returning with IMASK cleared in the jump's delay slot: TRM p.38-39's example does it; TRM p.140 ("TWI - Brian McKee") says it can leave the interrupted instruction on the wrong bank. - **C14** taken-jump cost from local RAM: TRM p.62 "three clock cycles"; the netlist reading gives +2 (JUMP) and +3 (JR) (libretro R12-R13). - **C15** MTOI flags: TRM and the microword set Z, N; MAME sets none. Unknowns: - **U1** the six DSP-only microwords (and the assumption that shared opcodes use the GPU's words). - **U2** exact ticks: taken JUMP/JR refill, MMULT per element, interrupt entry, the fixed part of an external load (reported 7 + D), external program fetch. - **U3** what an indexed store of a not-yet-written DIV or external-load result stores (B1): the old register value, presumably. - **U4** the wrong quotient of the consecutive-divide bug (B7). - **U5** what the illegal sequences actually do (MOVEI or MOVE PC in a delay slot, two jumps in a row, non-MAC after IMULTN, LOAD/STORE before MMULT). - **U6** unaligned accesses; which bytes LOADB/LOADW return from local space. - **U7** which games rely on which corner (leads only, [pipeline-and-bugs.md](pipeline-and-bugs.md)). - **U8** provenance of the netlist archive and whether later Tom/Jerry steppings shipped. - **U9** single-step mode and interrupts. - **U10** divide by zero. - **U11** MMULT element order and sign; MWIDTH 0-2. - **U12** NORMI and MTOI exactly as the normaliser and mantissa units compute them (MAME's definitions are the only ones written down). - **U13** the bank seen by the interrupted instruction when IMASK is cleared in the return jump's delay slot (C13). - **U14** the failure mode of JUMP/JR from external memory (B4). - **U15** pulse and clear in the same tick; a masked DSP interrupt 0 being lost (the board's U13-U15). - **U16** the exact value MOVE PC captures inside the interrupt entry (depends on the queue size at injection), i.e. the "address of the last instruction" rule's edge cases. The draft's "DSP reset PC" unknown is settled by reading: `FF0008` for both (start-here.md; read, not simulated). ## The rung ladder Each rung is one or more commits; each exit test runs on CPython and PyPy. | Rung | Work | Exit test | | --- | --- | --- | | **0 tables** | `pyproject.toml` deps, package skeleton, the two 64-slot decode tables generated from `mcode_table.py`'s columns and the manual | a test asserts every slot's mnemonic and operand form against `opcode_tables.py`'s agreed set (all but DSP 62) and every GPU microword against `Mcode.rom` (64/64) | | **1 semantics** | every instruction's result and flags, instruction at a time, no timing; the netlist carry rule (C4) and the other defaults of decision 8, each a named class attribute | one directed test per opcode per variant with edge operands (0, 1, `7FFFFFFF`, `80000000`, `FFFFFFFF`, shift counts -33..33); the TRM's own examples (ABS of `80000000`, PACK/UNPACK bit maps, NEG of `80000000`, DIV remainder sign, SAT32S with accumulator bits); all pass | | **2 referee + corpus** | build the Verilator harness around Torlus's `graphics` island and MiSTer's `_j_dsp` (2-4 days, [validation.md](validation.md)); generate the per-instruction corpus (results only first) | harness reproduces the TRM interleaving example's 10 vs 6 ticks (TRM p.62) and a NOP stream at 1 per tick; core matches 100% of the GPU corpus results and of the DSP shared-opcode results; the six DSP-only opcodes match MiSTer (tier 4, labelled); Torlus and MiSTer GPU agree on the same corpus or each disagreement is explained from a `.NET` line | | **3 pipeline timing** | prefetch queue, scoreboard, write-back port, delay slot, DIV unit timing, MAC, MMULT, indexed-store stall, external transactions through a fixed-latency harness bus | retire ticks match the corpus for single instructions and producer/consumer pairs at distances 0-3; the bug sequences B1, B2, B5, B7, B13 give the corpus's (and the manual's) wrong results without special cases | | **4 interrupts** | latches, IMASK, priority, injected entry, atomic sequences, CPUINT | corpus interrupt cases (a pulse at each tick of a window around MOVEI, a jump, a MAC group, MMULT) match on entry tick, pushed value, R30, R31, bank | | **5 program replay** | run the boot ROM's GPU program (no cartridge), Tempest 2000's DSP loop and fishfren's GPU setup in `harness.py` with memory images captured from MAME | order of execution (PC sequence, flags) matches the MAME traces instruction for instruction, allowing for the delay-slot logging trap; every difference explained by a C or U entry | | **6 tooling** | `state.py`, `disasm.py` (checked against MAME's `cpu.trace` disassembly), `trace.py` (JSONL, family schema), `debug.py`, `python -m jrisc PROGRAM.bin --variant gpu --load F03000 --pc F03000` | disassembly identical to MAME's on every instruction of the three traces; a trace of rung 5's GPU run round-trips | | **7 speed** | measure; skip-halted, predecode-on-write if needed | numbers recorded in `docs/` for CPython and PyPy on a fixed workload; no rung result changes | **Owed (2026-11-25, decisions L4 and L5):** rung 0's microword check (`Mcode.rom`, read by `mcode_table.py`) and rung 2's Verilator harness (Torlus's `graphics`, MiSTer's `_j_dsp`) used JagNetlists (no licence) and the MiSTer RTL (GPL-2.0), neither kept in this repository now. Each needs a run-only tool in emu-tools-gpl whose output this repository reads, or a judge rebuilt from documentation, before those exit tests can run (provenance.md). ## Speed Two processors at 26.6 MHz is the most demanding CPU load in the family. A pipeline-accurate pure-Python core will run well below real time on CPython and below real time on PyPy ([timing.md](timing.md) has the arithmetic: an extrapolation from `m68000-python`'s 1.4 M/s CPython and 33 M/s PyPy, not a measurement). That is expected for a reference core; `run_until`, skipping a halted processor and predecoding local RAM keep it usable without changing a result. A `jrisc-rust-fast` is the production path if the family wants a playable Jaguar. ## Decided by the user Nothing yet for this repository; the board's Phase 0 has no decisions either. ## Open decisions for Aubrey **Decided by Aubrey on 2026-11-12** (recorded after a walk through all fourteen Phase 0 briefs): - The Python package is `jrisc_python` (family rule set the same day: a repository `x-python` always imports as `x_python`); read any other package name in these documents as that. - Decision 1: package **`jrisc_python`** (not `jrisc`); classes as proposed. Decision 3: the core owns the local RAM. Confirmed. - Decision 8, one change: the **six DSP-only opcodes are written from Atari's Technical Reference in our own words**, not taken from the MiSTer core's reconstructed microcode words (those are its authors' guesses and are GPL; this core is MIT). MiSTer's version is run only as a detector. The other defaults in decision 8 stand. - Decision 9 (asking TomNJerry's author for console results): deferred with the other outside contacts. - Referees built from die-derived material are built just before the rung that needs them, not up front. - Outside contacts proposed below are **deferred until the core or board exists**; Aubrey sends them himself, from a draft. - Remote: local through Phase 0; after the first passing rung or milestone, public like the other CPU cores, after the usual history audit. Where a recommendation below names a different point, this replaces it. - Every other recommendation below is **accepted as written** unless a line here says otherwise. Each with a recommendation. Items 3, 4 and 5 shape the first line of code. 1. **Names**: `jrisc-python`, package `jrisc`, classes `JaguarGPU` and `JaguarDSP` over `JaguarRISC` (reasons above). The board's brief suggests `jrisc_python` as the import name, by analogy with its own `jaguar_python`; the family's cores use the bare chip name (`huc6280`, `sixfiveohtwo`, `w65c816`), boards the `_python` form. Other alternatives: `jaguar_risc`; `TomGPU` / `JerryDSP`. **Recommend: `jrisc`, as the other cores.** 2. **One core, two variants as data** (not `jaguar-gpu-python` and `jaguar-dsp-python`): the netlists share the pipeline, scoreboard, divider and systolic files byte for byte; MAME and MiSTer each have one model with a flag. **Recommend: one core.** 3. **Who owns the local RAM** (the one point the two first drafts disagreed on). **Both final briefs now recommend the core**: the local bus controller with its RAM, the wave-ROM slot and LOCK in `jrisc`; the 16-bit pairing latch in the board, which calls `io_read32`/`io_write32`. **Recommend: confirm.** The alternative (board owns the bytes, the core calls back for every fetch) costs the hottest path in the emulator. 4. **Model depth**: pipeline-accurate (prefetch queue, scoreboard, write-back schedule, so the bug list falls out) versus instruction-at-a-time with a tick cost table (as every emulator does). **Recommend: pipeline-accurate**, ticks computed by rule from the scoreboard state rather than looping per tick; it is what a reference core is for, and the netlist referee can judge it. 5. **The contract** above, in the board's names (`bus.read`/`bus.write` returning a completion clock, `local_io`, `io_read32`/`io_write32`, `raise_interrupt`, `on_cpu_interrupt`, `run_until`, `next_event_clock`, `big_io`, `running`, `reset_lock`, `wave_rom`). **Recommend: as written**; the two build sessions refine it together. 6. **Commit the generated corpus?** It is behaviour data from our harness, not netlist text, but it derives from an unlicensed design archive. **Recommend: keep it out of git** (gitignored, regenerated by a pinned script from pinned referees, its SHA-256 recorded); revisit if the repository goes public. 7. **Build the Verilator referee as rung 2** (2-4 days; Verilator from the oss-cad-suite bundle already under `sm83-python/reference/build`; the board's board's brief proposes building it jointly, the GPU harness's `graphics` island also holding the Blitter, before the board's M4). **Recommend: yes, jointly with the board**, as tooling in a git-ignored build tree, before any timing work here; it is the only tier-1-like judge either repository has. 8. **Defaults where no judge decides**, each a named class attribute and labelled with its tier: C after logic/multiply = the netlist value (C4); the six DSP-only opcodes = MiSTer's words (tier 4); DSP opcode 62 = NOP plus a log line (C6); DIV_OFFSET = bit 0 on both (C2); PACK loads flags as the ROM says (C3); FLAGS store visible after the pipeline's own delay, whatever it proves to be (C1); latch set only while enabled (C7); divide by zero = what the netlist simulation gives (U10). **Recommend: adopt.** 9. **Ask for hardware results.** `laoo/TomNJerry`'s 20 DSP probes target exactly U5; their author may hold console results. Any post (GitHub issue, AtariAge) must follow the family's posting rules (name the model; AtariAge's AI policy unchecked). **Recommend: yes, a short GitHub issue on TomNJerry asking whether console results exist, drafted for your review**, not sent by an agent. 10. **Netlist licence handling**: the archive has no licence; the rule here is cite file and line, describe in our own words, quote only short comments. **Recommend: confirm**; ask Estrade only if the repository goes public with a committed corpus. 11. **Public or local.** **Recommend: local until rung 2 passes**, then public like the other chip cores (MIT, nothing third-party committed). 12. **Rust and `-fast` forks.** **Recommend: not now**; revisit with the board's first speed measurements, as for the Mega Drive. 13. **CoJag as a second user**: keep the core free of 68000 and console-map assumptions (the local callback and `external` already do). **Recommend: yes**; fishfren is the cheapest second program corpus (no CHD).