DCPU-16 Specification

Interrupts

The DCPU-16 will perform at most one interrupt between each instruction. If multiple interrupts are triggered at the same time, they are added to a queue. If the queue grows longer than 256 interrupts, the DCPU-16 will catch fire.

When IA is set to something other than 0, interrupts triggered on the DCPU-16 will turn on interrupt queueing, push PC to the stack, followed by pushing A to the stack, then set the PC to IA, and A to the interrupt message.

If IA is set to 0, a triggered interrupt does nothing. Software interrupts still take up four clock cycles, but immediately return, incoming hardware interrupts are ignored. Note that a queued interrupt is considered triggered when it leaves the queue, not when it enters it.

Interrupt handlers should end with RFI, which will disable interrupt queueing and pop A and PC from the stack as a single atomic instruction. IAQ is normally not needed within an interrupt handler, but is useful for time critical code.