cpu/cpu - Handle halt mode

This commit is contained in:
madmaurice 2023-08-29 23:30:31 +02:00
parent 077f834c28
commit 5cabe03d25
2 changed files with 12 additions and 1 deletions

View file

@ -56,6 +56,9 @@ void Cpu::step()
{
if(!handleInterrupts()) // if no isr has been called, decode an instruction
{
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)

View file

@ -91,6 +91,8 @@ struct Cpu_state {
u8 IE;
u8 IF;
bool halted;
void setAF(u16 v);
u16 getAF();