diff --git a/cpu/cpu.cpp b/cpu/cpu.cpp index 4d29218..b14ecee 100644 --- a/cpu/cpu.cpp +++ b/cpu/cpu.cpp @@ -56,7 +56,10 @@ void Cpu::step() { if(!handleInterrupts()) // if no isr has been called, decode an instruction { - executeInstruction(); + if (halted) + processed_mcycles += 4; + else + executeInstruction(); } } @@ -77,6 +80,8 @@ void Cpu::reset() state.IME = IME_OFF; state.IE = 0; state.IF = 0; + + halted = false; } u8 Cpu::readPC8() @@ -225,6 +230,10 @@ bool Cpu::handleInterrupts() // servicable interrupts (assuming IME is on) u8 si = state.IE & state.IF & INT_MASK; + // Once there's an interrupt we exit halt mode + if (si) + halted = false; + if (state.IME == IME_SCHEDULED) state.IME = IME_ON; else if (state.IME == IME_ON && si != 0) diff --git a/cpu/cpu.h b/cpu/cpu.h index b31fdec..0432c6f 100644 --- a/cpu/cpu.h +++ b/cpu/cpu.h @@ -91,6 +91,8 @@ struct Cpu_state { u8 IE; u8 IF; + bool halted; + void setAF(u16 v); u16 getAF();