Hi,
I'm not sure how the Gameboy CPU handles interrupts exactly yet. Two questions:
How many cycles are needed to handle an interrupt? What I mean is, when an interrupt occurs, how many cycles pass between completion of the last instruction and fetching of the interrupt handler's first opcode?
Some emulator code suggests that this happens immediately, but that seems highly unlikely. The CPU needs to at least push the return address on the stack, which is one memory access minimum.
The second question is more subtle: Some documentation says "interrupts are acknowledged during the opcode fetch phase". Does that mean that
I have seen emulators handling interrupts after emulating the last instruction. If done right, this should be functionally equivalent to a). It's also cleaner, so I tend to lean towards a), but emulators are seldom perfect (as seen above).
Thanks a lot!
I'm not sure how the Gameboy CPU handles interrupts exactly yet. Two questions:
How many cycles are needed to handle an interrupt? What I mean is, when an interrupt occurs, how many cycles pass between completion of the last instruction and fetching of the interrupt handler's first opcode?
Some emulator code suggests that this happens immediately, but that seems highly unlikely. The CPU needs to at least push the return address on the stack, which is one memory access minimum.
The second question is more subtle: Some documentation says "interrupts are acknowledged during the opcode fetch phase". Does that mean that
- the CPU checks for interrupts before it would fetch the next opcode, and if an interrupt occurred, it injects the call to the interrupt instead, or
- the CPU already fetched the next instruction (i.e. has performed the read from memory) but discards the opcode, and injects the call to the interrupt?
I have seen emulators handling interrupts after emulating the last instruction. If done right, this should be functionally equivalent to a). It's also cleaner, so I tend to lean towards a), but emulators are seldom perfect (as seen above).
Thanks a lot!