When is the STAT IRQ line de-asserted?

Discussion of programming and development for the original Game Boy and Game Boy Color.
Post Reply
Alyosha_TAS
Posts: 173
Joined: Wed Jun 15, 2016 11:49 am

When is the STAT IRQ line de-asserted?

Post by Alyosha_TAS »

I am starting to work on interrupts in my emulator, but I don't quite follow exactly what's happening.

So, let me pose an example. Let's say I have STAT IRQs enabled and both LY=LYC IRQs and mode 0 IRQs enabled, but, interrupts are disabled on the CPU side (with the DI instruction.) Let's say I enable interrupts again some time on the LYC scanline after the mode 0 interrupt would have triggered

So at scanline LY=LYC we have :

Code: Select all

+----......mode 2.......-.......mode 3.........-+-..........mode 0..................EI.............
^                                                             ^                      ^
LY=LYC IRQ triggers                                  Mode 0 Interrupt triggers      Master Interrupt enable
My understanding is that STAT IRQ blocking occurs in this case, and only one IRQ ultimately triggers. Is this correct?

Then, suppose instead I enable interrupts some time during mode 3, and the interrupt is short and immediately exits.

EX:

Code: Select all

+----......mode 2.......-...EI........RETI.......mode 3.........-+-..........mode 0........................
^                           ^                                                   ^
LY=LYC IRQ triggers                Master Interrupt enable                  Mode 0 Interrupt triggers      
Am I correct that the Mode 0 interrupt will also trigger correctly? If so, at what point in the LYC interrupt was the STAT IRQ line de-asserted?

Finally, let's say I enable interrupts before the mode 0 interrupt triggers, but the LYC interrupt doesn't complete before the mode zero one would otherwise occur:

Code: Select all

+----......mode 2.......-...........mode 3....EI.....-+-...............mode 0......RETI............???......
^                                              ^                           ^
LY=LYC IRQ triggers                Master Interrupt enable                  Mode 0 Interrupt triggers      
Does the mode 0 interrupt occur after the RETI?

I hope these questions are clear. I appreciate any responses, as I would really like to get this right before I start writing spaghetti. :)
nitro2k01
Posts: 252
Joined: Sat Aug 28, 2010 9:01 am

Re: When is the STAT IRQ line de-asserted?

Post by nitro2k01 »

Each interrupt line is only one bit, so there's not interrupt queue if multiple events happen before the interrupt is served. Whenever an interrupt condition is true, the corresponding bit in IF ($FF0F) is set. It's never cleared when an interrupt condition stops being true (for example mode 0 ends) so it will stay set. It's only cleared when an interrupt routine is served, or when manually writing something to IF.
Post Reply