IF

Constant IF 

Source
pub const IF: VolAddress<u8, Safe, Safe>;
Expand description

Interrupt flag

76543210
IFJoypadSerialTimerLCDVBlank
  • VBlank (Read/Write): Controls whether the VBlank interrupt handler is being requested.
  • LCD (Read/Write) : Controls whether the LCD interrupt handler is being requested.
  • Timer (Read/Write) : Controls whether the Timer interrupt handler is being requested.
  • Serial (Read/Write) : Controls whether the Serial interrupt handler is being requested.
  • Joypad (Read/Write) : Controls whether the Joypad interrupt handler is being requested.

When an interrupt request signal (some internal wire going from the PPU/APU/… to the CPU) changes from low to high, the corresponding bit in the IF register becomes set. For example, bit 0 becomes set when the PPU enters the VBlank period.

Any set bits in the IF register are only requesting an interrupt. The actual execution of the interrupt handler happnes only if both the IME flag and the corresponding bit in the IE register are set; otherwise the interrupt “waits” until both IME and IE allow it to be serviced.

Since the CPU automatically sets and clears the bits in the IF register, it is usually not necessary to write to the IF register. However, the user still do that in order to manually request (or discard) interrupts. Just like real interrupts, a manually requeseted interrupt isn’t serviced unless/until IME and IE allow it.