GB: Fix execution state and HALT getting out of sync

This commit is contained in:
Vicki Pfau 2017-11-12 17:25:26 -08:00
parent dcf42fb081
commit 5d9e4d217a
1 changed files with 8 additions and 1 deletions

View File

@ -622,6 +622,8 @@ void GBProcessEvents(struct LR35902Core* cpu) {
}
if (cpu->halted) {
cpu->cycles = cpu->nextEvent;
cpu->executionState += cpu->nextEvent;
cpu->executionState &= 3;
if (!gb->memory.ie || !gb->memory.ime) {
break;
}
@ -677,9 +679,14 @@ static void _enableInterrupts(struct mTiming* timing, void* user, uint32_t cycle
}
void GBHalt(struct LR35902Core* cpu) {
if (!cpu->irqPending) {
struct GB* gb = (struct GB*) cpu->master;
if (!(gb->memory.ie & gb->memory.io[REG_IF])) {
cpu->executionState += cpu->nextEvent - cpu->cycles;
cpu->executionState &= 3;
cpu->cycles = cpu->nextEvent;
cpu->halted = true;
} else if (gb->model < GB_MODEL_CGB) {
mLOG(GB, STUB, "Unimplemented HALT bug");
}
}