# Interrupts, clocks and the bus Tags as in [memory-map.md](memory-map.md). ## Clocks | Clock | Value | Source | | --- | --- | --- | | A-board master | 16 MHz crystal; CPS-A/B run from it; pixel clock 8 MHz | `[die: video-signals.md]`, `[mame]` | | 68000 | 10 MHz crystal (A-boards up to 89626A-4), 12 MHz on 89626A-4 DASH; MAME assigns 12 MHz to 58 sets, 10 MHz to 110 | `[mame: "verified on pcb"]`; MAME: "likely ... all games after a certain point should use the 12MHz xtal" (U16) | | Z80, YM2151 (standard sound) | 3.579545 MHz crystal | `[mame: "verified on pcb"]` | | MSM6295 | 1 MHz: the CPS-A's 4 MHz pin-117 output divided by 4 by two 74LS74 | `[mame: comment in cps1_10MHz]` | | Z80 (QSound) | 8 MHz | `[mame: "verified on pcb"]` | | QSound DSP16A | 60 MHz input (MAME's device clock); sample rate is the DSP program's business | `[mame]`; [sound.md](sound.md) | **One timeline**: the board counts in 16 MHz master clocks. A frame is 512 x 262 = 134,144 pixel clocks = 268,288 master clocks. A 68000 clock is 8/5 master clocks at 10 MHz and 4/3 at 12 MHz: not integers, so the board keeps the 68000 in its own clocks and converts with exact rationals, the way megadrive-python schedules its two CPUs. The sound crystals (3.579545 MHz, 8 MHz) are independent oscillators; the board treats every ratio as exact (real crystals drift apart; no source measures it). ## 68000 interrupts The 68000's `IPL0` is not used; `IPL1` is vertical blank and `IPL2` the raster interrupt, so the CPU sees **level 2 (vblank), level 4 (raster), or level 6 when both are pending** `[mame: cps1.cpp, interrupt notes]`. Every interrupt is autovectored: the acknowledge cycle (function code 7, `BGACK` inactive) asserts `/VPA` and **clears both IPL1 and IPL2** `[mame: irqack_r, "FC0-FC2(any) + BGACK: VPA and clears both"]`. A level-6 acknowledge therefore drops a pending level 2 too. - **Vblank** asserts at line 240 in MAME's numbering (the first non-visible line) and stays until acknowledged. Line numbering: [cps-a.md](cps-a.md), "Raster" (C5). - **Raster** (IPL2): on standard boards `IPL2` is tied high on early B-boards (89624B-3) and routed on later ones (90629B-2, 91634B-2, 91635B-2) through connector CNA pin 9 to the C-board, where jumper JP1 joins it to the CPS-B-21's `/OBJUP` (pin 57) `[mame]`. Only Ganbare! Marine Kun and Puchi Monster use it (MAME machine `ganbare`; "HARD ERROR" without it). Strider has a level-4 handler and no hardware to call it. The die documentation says `/OBJUP` reaches only the CPS-A on CPS-1 (C8). The counters themselves: [cps-b.md](cps-b.md) (U14). `m68000-python` (pin `3029f56`, v0.1.0) already provides what this needs: `set_ipl(level)` and an `acknowledge(level)` callback that can return `AUTOVECTOR`; it models the E-clock wait of an autovector acknowledge as MAME does (its `docs/timing.md`). The board computes the level from its two lines and clears both in the acknowledge. ## Bus: wait states and the CPS-A's bus requests Neither is modelled by MAME; both are on the board ([quirks.md](quirks.md) Q1, Q2): 1. **One wait state** on every 68000 bus cycle to ROM, I/O, graphics RAM and work RAM (`/ONE WAIT` from PRG1; [memory-map.md](memory-map.md)). jtcps1 implements it, and its timing history shows a loop counter run on a real board (`2C00`) that the core matches only with the wait in place (C1). 2. **Bus requests**: at the start of each scanline the CPS-A may take the bus for objects, row scroll, scroll-layer refills, and during vblank the palette copy ([cps-a.md](cps-a.md), "Bus requests"). About 10% of a frame with all layers on, about 15% with a palette copy. `m68000-python` does not model BR/BG/BGACK or wait states and says so (`docs/interrupt-lifecycle.md`, `docs/claims.md`). Its `step_clocks` property, read inside a bus callback, gives the clock at which the current access happens, which is what the board needs to place both: a wait state adds 2 clocks to the access; a pending bus request stalls the CPU at its next bus access until the CPS-A releases the bus (the 68000 keeps executing internal cycles while the bus is granted, and the board's approximation of stalling at the next access is exact for a CPU whose every few clocks is a bus cycle). No core change is needed; the stall clocks are added to `step()`'s total by the board. ## The Z80s - Standard sound: `/INT` from the YM2151's `/IRQ` only; no NMI source. - QSound: a periodic interrupt at 250 Hz (`irq0_line_hold` in MAME: held for one instruction, "measured (cps2.cpp)"); its generator on the D-board is U3. - The 68000 cannot reset or halt the standard Z80 (no control register); QSound's neither, in what was read.