diff --git a/src/bus.rs b/src/bus.rs index bf52324..f61a90e 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -184,18 +184,8 @@ impl Bus { self.write(address.wrapping_add(1), bytes[1]); } - pub fn set_interrupt_enable(&mut self, interrupt: Interrupt, val: bool) { - let byte = self.read(INTERRUPT_ENABLE_ADDRESS); - self.write(INTERRUPT_ENABLE_ADDRESS, interrupt.set(byte, val)); - } - pub fn set_interrupt_flag(&mut self, interrupt: Interrupt, val: bool) { let byte = self.read(INTERRUPT_FLAG_ADDRESS); self.write(INTERRUPT_FLAG_ADDRESS, interrupt.set(byte, val)); } - - pub fn get_interrupt(&mut self, interrupt: Interrupt) -> bool { - let byte = self.read(INTERRUPT_ENABLE_ADDRESS) & self.read(INTERRUPT_FLAG_ADDRESS); - interrupt.get(byte) - } } diff --git a/src/cpu.rs b/src/cpu.rs index 730f863..94215ff 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -917,22 +917,23 @@ impl CPU { } pub fn check_interrupts(&mut self, bus: &mut Bus) -> Option { - if (bus.read(INTERRUPT_ENABLE_ADDRESS) & 0b00011111) & (bus.read(INTERRUPT_FLAG_ADDRESS) & 0b00011111) != 0 { + let interrupts = (bus.read(INTERRUPT_ENABLE_ADDRESS) & 0b00011111) & (bus.read(INTERRUPT_FLAG_ADDRESS) & 0b00011111); + if interrupts != 0 { self.is_halted = false; } if !self.ime { return None; } - if bus.get_interrupt(Interrupt::VBlank) { + if Interrupt::VBlank.get(interrupts) { return Some(Interrupt::VBlank); - } else if bus.get_interrupt(Interrupt::LCDSTAT) { + } else if Interrupt::LCDSTAT.get(interrupts) { return Some(Interrupt::LCDSTAT); - } else if bus.get_interrupt(Interrupt::Timer) { + } else if Interrupt::Timer.get(interrupts) { return Some(Interrupt::Timer); - } else if bus.get_interrupt(Interrupt::Serial) { + } else if Interrupt::Serial.get(interrupts) { return Some(Interrupt::Serial); - } else if bus.get_interrupt(Interrupt::Joypad) { + } else if Interrupt::Joypad.get(interrupts) { return Some(Interrupt::Joypad); } None