mirror of
https://github.com/FranLMSP/rmg-001.git
synced 2024-11-23 10:12:11 +00:00
Refactor check_interrupts
This commit is contained in:
parent
66182da336
commit
c68f24ea05
10
src/bus.rs
10
src/bus.rs
@ -184,18 +184,8 @@ impl Bus {
|
|||||||
self.write(address.wrapping_add(1), bytes[1]);
|
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) {
|
pub fn set_interrupt_flag(&mut self, interrupt: Interrupt, val: bool) {
|
||||||
let byte = self.read(INTERRUPT_FLAG_ADDRESS);
|
let byte = self.read(INTERRUPT_FLAG_ADDRESS);
|
||||||
self.write(INTERRUPT_FLAG_ADDRESS, interrupt.set(byte, val));
|
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
13
src/cpu.rs
13
src/cpu.rs
@ -917,22 +917,23 @@ impl CPU {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_interrupts(&mut self, bus: &mut Bus) -> Option<Interrupt> {
|
pub fn check_interrupts(&mut self, bus: &mut Bus) -> Option<Interrupt> {
|
||||||
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;
|
self.is_halted = false;
|
||||||
}
|
}
|
||||||
if !self.ime {
|
if !self.ime {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if bus.get_interrupt(Interrupt::VBlank) {
|
if Interrupt::VBlank.get(interrupts) {
|
||||||
return Some(Interrupt::VBlank);
|
return Some(Interrupt::VBlank);
|
||||||
} else if bus.get_interrupt(Interrupt::LCDSTAT) {
|
} else if Interrupt::LCDSTAT.get(interrupts) {
|
||||||
return Some(Interrupt::LCDSTAT);
|
return Some(Interrupt::LCDSTAT);
|
||||||
} else if bus.get_interrupt(Interrupt::Timer) {
|
} else if Interrupt::Timer.get(interrupts) {
|
||||||
return Some(Interrupt::Timer);
|
return Some(Interrupt::Timer);
|
||||||
} else if bus.get_interrupt(Interrupt::Serial) {
|
} else if Interrupt::Serial.get(interrupts) {
|
||||||
return Some(Interrupt::Serial);
|
return Some(Interrupt::Serial);
|
||||||
} else if bus.get_interrupt(Interrupt::Joypad) {
|
} else if Interrupt::Joypad.get(interrupts) {
|
||||||
return Some(Interrupt::Joypad);
|
return Some(Interrupt::Joypad);
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
Loading…
Reference in New Issue
Block a user