# Interrupts: latches, IMASK, bank switch, dispatch, entry Sources: TRM p.38-39 (GPU), p.58-61, p.98-99, p.108-111 (DSP) (manufacturer); `NET/tom/INTER-UA.NET` (read in full), `NET/jerry/DSP_INT.NET` (latch and entry sections read), `NET/tom/GPU_CTRL.NET` l.1-50, `NET/tom/GRAPHICS.NET` l.70-80, `NET/jerry/DSP.NET` l.70-82 (netlist text, read, **not simulated**); MAME 0.285 `jaguar.cpp` `check_irqs`, `execute_set_input` (emulator). The board's view, read 2026-11-12: `../jaguar-python/docs/interrupts.md`. ## Sources | n | GPU (TRM p.38) | DSP (TRM p.98) | Shape at the latch input (netlist) | | --- | --- | --- | --- | | 0 | CPU interrupt: any write of 1 to CTRL bit 2 | same, D_CTRL bit 2 | one-tick pulse from a flip-flop on the write (`GPU_CTRL.NET` `Gpu_int := FD1Q`) | | 1 | Jerry's interrupt output | I2S interface | GPU: rising edge of Jerry's line, detected in `GRAPHICS.NET` l.73-77 ("Use dint for gpu_irq[1] (edge-triggered)"); DSP: rising edge of `i2int` (`DSP.NET` l.80-82) | | 2 | Tom's programmable timer (`tint`, not the video counter: board `interrupts.md`, `TOM.NET` l.307) | Jerry timer 0 | DSP: "timer interrupts are one-tick pulses" (`DSP.NET` l.77) | | 3 | Object Processor (GPU object) | Jerry timer 1 | DSP: one-tick pulse | | 4 | Blitter | external 0 | DSP: synchronised and edge-detected (`DSP.NET` l.72-75) | | 5 | - | external 1 | as 4 | So every input reaches the latch as a **one-tick pulse**. The shaping happens outside the processor block for the GPU (`GRAPHICS.NET`) and inside `DSP.NET` for the DSP; either way it is a property of the source, and this repository proposes that the board produce the pulse (the contract in [handoff-brief.md](handoff-brief.md)). ## The latch, enable and mask logic (`INTER-UA.NET` l.44-72, `DSP_INT.NET` l.44-75) Per source n, each tick: ``` latch[n] <- (irq[n] AND enable[n]) OR (latch[n] AND NOT (FLAGS write with clear bit n = 1)) ``` - **A latch is set only while its enable bit is set** (`Gpu_irqm := ND2 (irqm\, gpu_irq, int_ena)`): a pulse that arrives while its source is disabled is lost; enabling later does not recover it. The comment above the gates says "The interrupt mask prevents them being set", but the gate uses the enable bits, not IMASK (C7). **Read from the netlist, not simulated.** MAME does the same (`execute_set_input`: "Ignore irq if masked ... barkley, breakout, clubdriv, ironsol2, skyhamm, ultravor all want to not read a pending DSP serial irq before JPIT"). - A pulse and a clear in the same tick: the set term wins (the OR); a level held high on an enabled source would make the latch uncleareable, which is why the inputs are shaped into pulses. - Clearing the enable bit does not clear a latch already set. - Reads: enables at FLAGS bits 4-8 (DSP also 16); clear bits read 0; latches at CTRL bits 6-10 (DSP also 16) (`Statrd[6-10]`, `DSP_INT.NET` l.74-75). - **IMASK** (FLAGS bit 3): set by the entry sequence ("by romold and intser ... not set until romold so that it does not disturb the register addressing of the previous instruction", l.104-116); cleared only by a FLAGS write with bit 3 = 0 (`Imclr := ND2 (imclr\, flagwr, gpu_din\[3])`); writing 1 does nothing (TRM p.58). While IMASK is set **register bank 0 is forced** whatever REGPAGE says (TRM p.42-43, p.59), and no new interrupt is taken. ## When an interrupt is taken (`INTER-UA.NET` l.93-103) ``` start entry when any latch set AND not already in entry AND NOT IMASK AND NOT atomic ``` - **Atomic** (TRM p.39; `INS_EXEC.NET` l.141-208): the MOVEI data words, an MMULT until it completes, IMULTN/IMACN with the next instruction, a jump with its delay slot. Single-step mode and interrupts: not described (U9). - **Priority**: the highest-numbered set latch, encoded when the MOVEI data is injected ("interrupt 4 is highest priority", l.74-82; DSP: 5). Enables are not consulted at this point (they gated the latch), so a latch that was set while enabled is serviced even if its enable is cleared afterwards. "If two interrupts arrive within a few ticks of each other, the higher numbered will be serviced first" (TRM p.38) is this encoder looking at the latches late. - The entry does not clear the latch: the service routine must, or the source is serviced again as soon as IMASK is cleared. ## The entry sequence (`INTER-UA.NET` l.117-152) The interrupt block takes over the instruction stream from the prefetch unit ("hidden from the pre-fetch unit") and injects six instructions, eight words, counted by a 3-bit counter: ``` subqt #4,r31 ; r31 is the interrupt stack pointer (bank 0) move pc,r30 ; the address to return to, minus 2 store r30,(r31) movei #base + 16*n,r30 ; base 00F03000 (GPU) / 00F1B000 (DSP) jump (r30) nop ; the delay slot ``` The MOVEI data words are wired (`Ins4`/`Ins5`): low word `3000 + 16n` (GPU) or `B000 + 16n` (DSP), high word `00F0` / `00F1`, so each vector has room for 8 instructions. Consequences, all stated by TRM p.38 as well: - **R30 is corrupted** (it ends holding the vector address; MAME sets it so "(kasumi)"); R31 is predecremented by 4 and the return value stored there. Both are bank-0 registers because IMASK is already set when they are used. - The value pushed is "the address of the last instruction to be executed before the interrupt"; the routine adds 2 before returning (TRM p.38). - The return is the routine's own `jump (rX)` with the IMASK clear and the FLAGS store in or before the delay slot. TRM's example puts `store r29,(r30)` (which clears IMASK and the latch) in the delay slot; the "Lies and Damned Lies" note says that can leave the interrupted instruction on the wrong bank (U13, [pipeline-and-bugs.md](pipeline-and-bugs.md)). - Entry cost in ticks: the six injected instructions through the pipeline plus the jump's refill: not counted anywhere (U2); MAME takes it in zero time. ## The interrupt the processor sends CTRL bit 1 **CPUINT** (TRM p.60, p.110): writing 1 makes a one-tick pulse (`Cpu_int := FD1Q`) on a line that leaves the processor: on Tom it is source 1 of `INT1` for the 68000; on Jerry it is J_INT source 1 (board `interrupts.md`). Reads as 0. Bit 2 writes the processor's own interrupt 0, from any master. ## Who owns what (agreed with the board's draft) | Piece | Owner | Why | | --- | --- | --- | | FLAGS enable, clear and IMASK bits, the latches read in CTRL, the latch logic, priority, the injected entry, atomic sequences, the bank force | **core** | all inside `INTER-UA` / `DSP_INT`, which are inside the processor block; splitting `G_CTRL` across repositories would be worse (the board says the same) | | CPUINT and self-interrupt 0 | **core** (raises an output callback for CPUINT) | `GPU_CTRL` | | Shaping each source into a one-tick pulse (edge detectors, synchronisers) | **board** | they belong to the source; for the GPU they are outside the GPU block; the DSP's sit in `DSP.NET` but depend on pins the board owns | | Tom `INT1`/`INT2`, Jerry `J_INT`, timers, I2S, UART, external pins, the 68000 level | **board** | | The board's draft (`jaguar-python/docs/interrupts.md`, "Who owns what") already proposes this split with `core.raise_interrupt(n)` (a pulse) and a callback for the CPUINT write; this repository adopts the same names ([handoff-brief.md](handoff-brief.md), the contract). The two drafts **agree** on interrupts. The first drafts disagreed on the local RAM; the board's final brief (`9398480`) now gives it to the core as well (decision 3 in the brief). ## Unknowns for this page U2 entry tick count; U9 single-step and interrupts; U13 IMASK cleared in the return jump's delay slot; whether a pending-but-masked DSP interrupt 0 can be lost and what happens when set and clear meet (the board's U13-U15, decidable by simulation, [validation.md](validation.md)).