|
DevelopmentSega Master System / Mark III / Game Gear |
Home - Forums - Games - Scans - Maps - Cheats - Credits |
The Z80 has two external interrupt mechanisms (via its INT and NMI pins) and an internal interrupt via the rst
instruction.
These all cause execution to jump to a specific interrupt vector which is some code at a fixed location. The current program counter is saved on the stack so execution can continue after the interrupt vector routine has finished.
NMIs (non-maskable interrupts) link to an interrupt vector at offset $0066. On most Sega 8-bit hardware (using the Z80's Interrupt Mode 1), IRQs (maskable interrupts) link to the interrupt vector at $0038.
Software interrupts can link to interrupt vectors at $0000, $0008, $0010, $0018, $0020, $0028, $0030 or $0038 using the rst n
instruction (where n
is one of the vector locations mentioned). They are a useful optimisation technique because they take less space than a call
(1 byte vs. 3) and execute faster (11 cycles vs. 17), but are generally only suitable for small functions.
It is important to have interrupt handlers defined at the relevant interrupt vector location before they are needed.
Some documents also regard the start of code at $0000 to be a hardware interrupt location, activated via the Z80's RESET pin, although some may not consider this a true "interrupt" as it does not save the program counter.
It is also worth noting that the opcode for rst $0038
is $ff. If empty space is filled with this (as is usually the case), a bug causing an incorrect jump into such data will result in the interrupt handler at $0038 being repeatedly executed. This also allows for the conditional rst
code hack.