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 | 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. | |
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.
The same type as VoidFn (types.h): this name says what the function is for, VoidFn is the generic one, and either can be passed where the other is expected.
| 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/color/ hicolor_1792/irq_stream.asm for the canonical shape) |
| 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 callback runs inside the NMI handler, once per frame the main thread was waiting for — NOT on lag frames (an NMI that arrives while the main loop is still computing skips all VBlank work, this callback included). It runs AFTER the library's own VBlank work: the OAM upload, the text tilemap flush and the background scroll sync have already used part of VBlank.
| callback | Function to call during VBlank, or NULL to disable (same as nmiClear()) |