chore(cpu): rename discriminants of ImeState enum

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-08-14 16:42:15 -05:00
parent 53dfaf0de2
commit 8c9567b610
2 changed files with 7 additions and 14 deletions

View File

@ -118,7 +118,7 @@ impl Cpu {
let opcode = self.fetch(); let opcode = self.fetch();
let instr = self.decode(opcode); let instr = self.decode(opcode);
let elapsed = self.execute(instr); let elapsed = self.execute(instr);
self.check_ime(); self.handle_ei();
elapsed elapsed
} }
}; };
@ -159,18 +159,11 @@ impl Cpu {
&mut self.bus.joypad &mut self.bus.joypad
} }
fn check_ime(&mut self) { fn handle_ei(&mut self) {
match self.ime { match self.ime {
ImeState::Pending => { ImeState::EiExecuted => self.ime = ImeState::Pending,
// This is within the context of the EI instruction, we need to not update EI until the end of the ImeState::Pending => self.ime = ImeState::Enabled,
// next executed Instruction ImeState::Disabled | ImeState::Enabled => {}
self.ime = ImeState::PendingEnd;
}
ImeState::PendingEnd => {
// The Instruction after EI has now been executed, so we want to enable the IME flag here
self.ime = ImeState::Enabled;
}
ImeState::Disabled | ImeState::Enabled => {} // Do Nothing
} }
} }
@ -514,8 +507,8 @@ pub(crate) enum HaltState {
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub(crate) enum ImeState { pub(crate) enum ImeState {
Disabled, Disabled,
EiExecuted,
Pending, Pending,
PendingEnd,
Enabled, Enabled,
} }

View File

@ -971,7 +971,7 @@ impl Instruction {
} }
Instruction::EI => { Instruction::EI => {
// EI | Enable IME after the next instruction // EI | Enable IME after the next instruction
cpu.set_ime(ImeState::Pending); cpu.set_ime(ImeState::EiExecuted);
Cycle::new(4) Cycle::new(4)
} }
Instruction::CALL(cond) => { Instruction::CALL(cond) => {