SNES Interrupt Handling. More...
#include <snes/types.h>Go to the source code of this file.
Macros | |
| #define | IRQ_HTIMER 0x10 |
| Fire an IRQ when the H counter reaches the HTIME value (every scanline). | |
| #define | IRQ_VTIMER 0x20 |
| Fire an IRQ when the V counter reaches the VTIME value (once per frame). | |
Typedefs | |
| typedef void(* | VBlankCallback) (void) |
| VBlank callback function pointer type. | |
Functions | |
| void | irqClear (void) |
| Restore the default IRQ handler (acknowledge + return). | |
| void | irqDisable (void) |
| Disable H/V timer IRQs. | |
| void | irqEnable (u8 flags) |
| Enable H/V timer IRQs and unmask interrupts (CLI). | |
| void | irqSet (void *handler) |
| Install a raw hardware IRQ handler (H/V timer interrupts). | |
| void | irqSetBank (void *handler, u8 bank) |
| irqSet() with an explicit ROM bank for the handler | |
| void | irqSetHTimer (u16 h) |
| Set the H-timer target (0-339 dots). | |
| void | irqSetVTimer (u16 v) |
| Set the V-timer target (0-261 scanlines NTSC). | |
| void | nmiClear (void) |
| Clear the VBlank callback. | |
| void | nmiSet (VBlankCallback callback) |
| Register a VBlank callback function. | |
| void | nmiSetBank (VBlankCallback callback, u8 bank) |
| Register a VBlank callback with explicit bank. | |
SNES Interrupt Handling.
Manages NMI (VBlank), IRQ, and other interrupts.
| #define IRQ_HTIMER 0x10 |
Fire an IRQ when the H counter reaches the HTIME value (every scanline).
| #define IRQ_VTIMER 0x20 |
Fire an IRQ when the V counter reaches the VTIME value (once per frame).
| typedef void(* VBlankCallback) (void) |
VBlank callback function pointer type.
Functions of this type can be registered with nmiSet() to be called automatically during every VBlank interrupt.
| void irqClear | ( | void | ) |
Restore the default IRQ handler (acknowledge + return).
| void irqDisable | ( | void | ) |
Disable H/V timer IRQs.
Clears both timer bits in the NMITIMEN shadow. The I flag is left clear — with no timer source enabled, no IRQ can fire.
| void irqEnable | ( | u8 | flags | ) |
Enable H/V timer IRQs and unmask interrupts (CLI).
Sets the requested timer bits in the NMITIMEN shadow (NMI and auto-joypad bits are preserved) and clears the CPU I flag. Install the handler with irqSet() and program the timer with irqSetHTimer()/irqSetVTimer() BEFORE calling this.
| flags | IRQ_HTIMER, IRQ_VTIMER, or both |
| void irqSet | ( | void * | handler | ) |
Install a raw hardware IRQ handler (H/V timer interrupts).
The crt0 IRQ vector does a single JML [irq_callback] into your handler — nothing is saved, acknowledged, or set up for you. This is deliberate: an H-timer IRQ fires EVERY SCANLINE (~15.7 kHz) and cannot afford a C prologue, so the SDK imposes zero overhead and zero policy.
| handler | Address of the ASM handler (see examples/graphics/effects/ hicolor_1792/irq_stream.asm for the canonical shape) |
| void irqSetBank | ( | void * | handler, |
| u8 | bank ) |
irqSet() with an explicit ROM bank for the handler
| handler | Address of the ASM handler |
| bank | ROM bank containing the handler |
| void irqSetHTimer | ( | u16 | h | ) |
Set the H-timer target (0-339 dots).
With IRQ_HTIMER enabled, the IRQ fires at this horizontal position on every scanline. Values near the end of the visible line (e.g. 190) let a short handler's PPU writes land in H-blank.
| void irqSetVTimer | ( | u16 | v | ) |
Set the V-timer target (0-261 scanlines NTSC).
With IRQ_VTIMER enabled, the IRQ fires once per frame at this scanline (combined with IRQ_HTIMER: at that exact H/V position).
| void nmiClear | ( | void | ) |
Clear the VBlank callback.
Equivalent to nmiSet(NULL).
| void nmiSet | ( | VBlankCallback | callback | ) |
Register a VBlank callback function.
The registered callback will be called during every VBlank interrupt, BEFORE the vblank_flag is set. This allows time-critical operations (like DMA transfers) to be performed reliably during VBlank.
| callback | Function to call during VBlank, or NULL to disable |
| void nmiSetBank | ( | VBlankCallback | callback, |
| u8 | bank ) |
Register a VBlank callback with explicit bank.
Use this when the callback function might not be in bank 0.
| callback | Function to call during VBlank |
| bank | ROM bank where the callback is located (0-255) |