feat: make 0xFF0F aware of joypad struct interrupt bool

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-03-20 21:21:39 -05:00
parent 36e572b783
commit b213a6e545
2 changed files with 25 additions and 15 deletions

View File

@ -261,24 +261,20 @@ impl Bus {
impl Bus { impl Bus {
fn interrupt_flag(&self) -> InterruptFlag { fn interrupt_flag(&self) -> InterruptFlag {
// Read the current Interrupt status from the PPU // Read the current interrupt information from the PPU
let ppu_vblank = self.ppu.interrupt.vblank(); let vblank = self.ppu.interrupt.vblank();
let ppu_lcd_stat = self.ppu.interrupt.lcd_stat(); let lcd_stat = self.ppu.interrupt.lcd_stat();
// We actually don't care about what the InterruptFlag currently says // Read the currrent interrupt information from the Joypad
// about vblank and lcd_stat, because the PPU has the more accurate let joypad = self.joypad.interrupt();
// knowledge about what state these interrupt flags are in.
// In order to have the PPU be the source of truth
// (and accounting for the fact that we aren't able to update)
// the interrupt flag register 0xFF0F in the method, we can
// mask over those two interruptss
// Copy the Interrupt Flag register 0xFF0F // Copy the Interrupt Flag register 0xFF0F
let mut flag = self.interrupt.flag; let mut flag = self.interrupt.flag;
flag.set_vblank(ppu_vblank);
flag.set_lcd_stat(ppu_lcd_stat);
// Update the flag to have the most accurate information
flag.set_vblank(vblank);
flag.set_lcd_stat(lcd_stat);
flag.set_joypad(joypad);
flag flag
} }
@ -288,9 +284,13 @@ impl Bus {
let vblank = self.interrupt.flag.vblank(); let vblank = self.interrupt.flag.vblank();
let lcd_stat = self.interrupt.flag.lcd_stat(); let lcd_stat = self.interrupt.flag.lcd_stat();
let joypad = self.interrupt.flag.joypad();
// Update the PPU's internal tracking of the interrupt register 0xFF0F // Update the PPU's instance of the following interrupts
self.ppu.interrupt.set_vblank(vblank); self.ppu.interrupt.set_vblank(vblank);
self.ppu.interrupt.set_lcd_stat(lcd_stat); self.ppu.interrupt.set_lcd_stat(lcd_stat);
// Update the Joypad's instance of the following interrupts
self.joypad.set_interrupt(joypad);
} }
} }

View File

@ -3,7 +3,17 @@ use bitfield::bitfield;
#[derive(Debug, Clone, Copy, Default)] #[derive(Debug, Clone, Copy, Default)]
pub struct Joypad { pub struct Joypad {
pub status: JoypadStatus, pub status: JoypadStatus,
pub interrupt: bool, interrupt: bool,
}
impl Joypad {
pub fn interrupt(&self) -> bool {
self.interrupt
}
pub fn set_interrupt(&mut self, value: bool) {
self.interrupt = value;
}
} }
bitfield! { bitfield! {