irq (Interrupt Requests)#

Hardware interrupt manager from libugba.


Importing this module will automatically enable interrupts and set up the master ISR.


type IrqIndex = enum#

IRQ indices, used to enable/disable and register handlers for interrupts.

Interrupt Management#

proc put(irqId: IrqIndex, handler: FnPtr)#

Enable an interrupt, and register a handler for it.

If the interrupt already has a handler it will be replaced.

proc delete(irqId: IrqIndex)#

Disable an interrupt, and remove its handler.

proc enable(irqId: IrqIndex)#

Enable an interrupt.

proc disable(irqId: IrqIndex)#

Disable an interrupt.

I/O Registers#


The registers are exposed directly, but for most purposes you don’t need to worry about them as the IRQ management procs above can take care of everything.

var ie: set[IrqIndex]#

“Interrupt Enable” register.

Setting a bit allows an interrupt to be received. But nothing will happen unless the relevant bit to request the interrupt is also set, e.g. dispcnt.vblankIrq = true.


irq.put or irq.enable will take care of this for you.

var `if`: set[IrqIndex]#

“Interrupt Flags” register.

When an interrupt occurs, the corresponding bit in if will be set.

Once the interrupt has been handled, it is acknowledged by setting the bit again (even though it’s already set)! After doing so, the bit will be automatically cleared by the hardware.


The master ISR will take care of this for you.

var ime: bool#

“Interrupt Master Enable” register.

Setting this to false will disable all interrupts.


This is automatically set to true when the module is initialised, and temporarily set to false while one of your handlers is being called.

Setting ime = true within a handler will allow that handler to be interrupted by another interrupt. i.e. nested interrupts are supported.

var ifbios: set[IrqIndex]#

“BIOS Interrupt Flags” register.

In addition to the if register, this must be acknowledged in order to wake up from the IntrWait and VBlankIntrWait system calls.


The master ISR will take care of this for you.

var isr: FnPtr#

Contains the address of the master interrupt service routine.