From b213a6e5451ffb8baa0c5a9ea5b98523fc283879 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Sat, 20 Mar 2021 21:21:39 -0500 Subject: [PATCH] feat: make 0xFF0F aware of joypad struct interrupt bool --- src/bus.rs | 28 ++++++++++++++-------------- src/joypad.rs | 12 +++++++++++- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/bus.rs b/src/bus.rs index 765788d..4e692fe 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -261,24 +261,20 @@ impl Bus { impl Bus { fn interrupt_flag(&self) -> InterruptFlag { - // Read the current Interrupt status from the PPU - let ppu_vblank = self.ppu.interrupt.vblank(); - let ppu_lcd_stat = self.ppu.interrupt.lcd_stat(); + // Read the current interrupt information from the PPU + let vblank = self.ppu.interrupt.vblank(); + let lcd_stat = self.ppu.interrupt.lcd_stat(); - // We actually don't care about what the InterruptFlag currently says - // about vblank and lcd_stat, because the PPU has the more accurate - // 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 + // Read the currrent interrupt information from the Joypad + let joypad = self.joypad.interrupt(); // Copy the Interrupt Flag register 0xFF0F 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 } @@ -288,9 +284,13 @@ impl Bus { let vblank = self.interrupt.flag.vblank(); 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_lcd_stat(lcd_stat); + + // Update the Joypad's instance of the following interrupts + self.joypad.set_interrupt(joypad); } } diff --git a/src/joypad.rs b/src/joypad.rs index d2e1bcf..a8a30ce 100644 --- a/src/joypad.rs +++ b/src/joypad.rs @@ -3,7 +3,17 @@ use bitfield::bitfield; #[derive(Debug, Clone, Copy, Default)] pub struct Joypad { 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! {