# Interrupts, resets and the watchdog Sources and the `[HYPOTHESIS: was wiki Page]` tag as in [memory-map.md](memory-map.md). The timer's own counting and reload rules are in [video.md](video.md) (the LSPC owns the timer); this page is about the lines, the acknowledge, the priorities, and what the 68000 core must provide. ## The 68000's three levels (cartridge systems) | Level | Source | Raised | Cleared by | Source | | --- | --- | --- | --- | --- | | 1 | vertical blank (LSPC) | once per frame at the start of vblank | writing bit 2 to `$3C000C` | [CM:426, 442, 515-527], [SNK p9], [MAME 851-858] | | 2 | the LSPC timer | when the timer's down counter reaches 0, if timer IRQs are enabled (`$3C0006` bit 4) | writing bit 1 to `$3C000C` | [CM:449-500, 443], [SNK p8-9], [MAME 818-835] | | 3 | pending after a cold boot | at power-on only | writing bit 0 to `$3C000C` | [CM:430-434], [MAME 1558-1559: "start with an IRQ3 - but NOT on a reset"] | All three are **autovectored** (vectors 25-27): "the hardware will respond to an interrupt acknowledge cycle by asserting /VPA" [CM:542-544]. Each stays asserted until its bit is written to `$3C000C`; several bits may be written at once (`$0007` acknowledges all) [CM:446-447], [MAME 805-815]. The video circuit encodes one level on IPL2-0: "If IRQ2 is pending, IRQ1 will not occur until IRQ2 is acknowledged"; IRQ2 can interrupt the IRQ1 handler; with IRQ1 and IRQ2 both pending the 68000 does **not** see level 3 (the OR of the two codes) but 2 then 1 [CM]. MAME holds separate lines and lets the 68000 pick the highest [MAME 797-802], which gives the same order. MacDonald's own text names bit 0 for IRQ3 in the register list and "bit 1" in his programming tips; bit 0 is the one his register list and MAME use. On Neo Geo CD three vectored CD interrupts are added (vectors 21-23, `$15-$17`) [MAME neogeocd.cpp:1037-1063], and the vblank and timer **vectors are swapped**: MAME's CD raises vblank on level 1 and the timer on level 3 but answers level 1 with autovector 2 and level 3 with autovector 1 [MAME neogeocd.cpp:862-863, 940-944]. The wiki's wording (levels swapped, timer 1, vblank 2) is [HYPOTHESIS: was wiki 68k interrupts]; which line the hardware raises is for the CD's own Phase 0. It belongs to the CD board through the interrupt socket ([sockets.md](sockets.md), CD5). ### When vblank is raised Measured [CM]: on line 224 (counter `$1F0`, the first line after the active area), /VBLANK falls 56 master clocks (14 pixels) after /HSYNC rises, and **two master clocks later** the IRQ1 flip-flop is set. MAME uses exactly that, `NEOGEO_VBLANK_IRQ_HTIM = 56 + 2` ticks of 24 MHz after the start of its line `$F0` [`neogeo.h` 40, MAME 851-858], and reloads the timer for the "once per frame" mode 1,146 master clocks after the same point [MAME 752, 838-848], MacDonald's other figure (C3 is SNK's different wording). The acknowledge cycle itself varies: 26, 32 or 44 master clocks, "typically 32 is the other length that happens most often"; NOP before the interrupt gives the fastest (26 at best) [CM]. The jitter moves the start of a timer ISR, which matters for mid-line palette or shadow changes. ## What the board needs from `m68000-python` Read at `m68000-python` `c827cca` (origin/main, v0.1.0 + 4 commits; the local checkout is at `3029f56`, 2 behind). Everything the Neo Geo needs is already there: | Need | Core hook | Note | | --- | --- | --- | | three levels, held until acknowledged | `set_ipl(level)`: the level stays until changed | the board computes the highest pending level after every LSPC event and every `$3C000C` write | | autovector acknowledge | `acknowledge(level)` callable returning `AUTOVECTOR` (or leave it out: everything autovectors) | the CD board needs its own callable (vectored); keep it a constructor argument the board passes through | | watchdog reset | `reset()` (returns 40 clocks; vectors fetched through the bus, so the vector swap applies) | the board holds the CPU (does not step it) for the reset's length, then calls `reset()` | | `RESET` instruction | `reset_devices=` callable, called when the instruction pulses the line | the board resets the devices; see C2 for whether the 68000 itself is reset | | wait states | none in the core; `step_clocks` inside a bus callable says where the access falls | the board adds ROMWAIT/PWAIT and memory-card stalls ([memory-map.md](memory-map.md)) | | save states | `capture_state()` / `restore_state()`; `c827cca` also builds the dispatch table on first read, "so an unpickled CPU steps" | why `c827cca` over `3029f56` | **Pin `m68000-python` at `c827cca`.** Two things to raise **on the core** (issues, not board workarounds; family rule "boards exist to find core corners"): 1. **The acknowledge cycle's length (C6).** The core adds MAME 0.285's E-clock wait to an autovectored acknowledge (`_e_clock_wait`: aligned to the next E-clock period, 5-14 extra clocks), which its own docs call provisional. MacDonald measured the Neo Geo's acknowledge at 26, 32 or 44 master clocks (13, 16 or 22 CPU clocks), with /VPA asserted, and writes that the variation "has nothing to do with the E clock phase relation" but comes from the 68000 negating /AS "based on some internal decision" [CM]. That contradicts the textbook VPA/E-clock synchronisation both MAME and the core implement. The core's model gives a range of similar width from a different cause, so lockstep against MAME will agree and neither will match MacDonald's distribution. Raise it on the core as a documented hardware observation (tier 3) against its provisional acknowledge timing; the board does not work around it. (If ever needed, the board could return the autovector number itself, 24 + level, from `acknowledge()`: the core takes any 0-255 answer as a vector and skips the E wait.) 2. **The reset's length.** MAME's trace shows the first instruction after `totalcycles` 34; the core's `reset()` returns 40 (UM Table 8-14 with Nuked-MD's 14 internal clocks). The difference is MAME's, not hardware's; note it in the lockstep tolerances rather than change the core. ## Resets - **Power-on / reset button / MVS VCCON**: a PST518B generator gives the global reset, and while it is asserted the watchdog is held in reset [CM:127-130]. That NEO-B1 then holds RESET low for **8 more frames** (the watchdog counter), so RESET lasts at least about 135 ms, and that the LSPC pulses RESETP for one master clock when RESET rises, to resynchronise NEO-D0's clocks, are [HYPOTHESIS: was wiki Reset] (8 frames is MacDonald's watchdog low time, 3,244,030 mclk). So is "the LSPC keeps generating video sync while RESET is low". - **The 68000's RESET instruction** (C2): MacDonald says that because the line is common, RESET "will reset the system in the same way a watchdog will, including the 68000 as /HALT is asserted in response to /RESET going low" [CM:143-145]. The opposite reading, that it "will reset everything except the 68k", and NEO-B1 driving RESET and HALT "from the same signal", are [HYPOTHESIS: was wiki Reset]; the two could both be true only if NEO-B1 answered the pulse by starting its own reset sequence. MacDonald's is the measured statement on a real MV2F; follow it, with the board's `reset_devices` callable starting the watchdog-style reset (8 frames low), and the CPU reset after it. MAME does not hook the instruction. No game is known to execute RESET (U-list). - **Z80**: reset with the system; command `$03` is a software reset by convention; there is no 68000-controlled Z80 reset on cartridge systems (the CD has one, `$FF0183`). ## The watchdog - "Kicked" by writing to `$300001` at least every 100 ms [SNK p12]; that it is a frame counter in NEO-B1 clocked by CHBL is [HYPOTHESIS: was wiki Watchdog]. MacDonald found that **any odd byte write or even word write in `$300000-$31FFFF`** kicks it [CM:153-158]; MAME maps only the odd byte at `$300001` with mirror `$01FFFE` [MAME 1733] (C5: the two agree on odd bytes; the board should follow MacDonald, which is the measured superset). - Timing [CM:147-151]: a looping watchdog reset holds /RESET low 3,244,030 master clocks (8 frames) and high 8,120,860 (20 frames less 7 lines). MAME's comment gives 0.128762 s (about 7.6 frames). A looping reset gives the "click of death" at 3.7 Hz. - That it can be disabled by grounding DOGE (NEO-B1 pin 94; jumper J2 on some boards) is [HYPOTHESIS: was wiki Watchdog]; MAME wonders whether JP2 disables the watchdog [MAME 1906]. - That some games use it as protection (loop on purpose, expect a reset, record a failure in backup RAM if none comes) is [HYPOTHESIS: was wiki Watchdog]. The watchdog must be exact to the frame anyway: MacDonald measured it to the master clock. ## Interrupts on the Z80 side NMI from the sound-command latch (gated by `$08`/`$18`), IRQ from the YM2610's timers; see [sound.md](sound.md).