all repos — mgba @ 5d9e4d217a273bec4dfdddafdea85e25eda7a45f

mGBA Game Boy Advance Emulator

GB: Fix execution state and HALT getting out of sync
Vicki Pfau vi@endrift.com
Sun, 12 Nov 2017 17:25:26 -0800
commit

5d9e4d217a273bec4dfdddafdea85e25eda7a45f

parent

dcf42fb081a877a3af32f60020dd81a6f32e74e6

1 files changed, 8 insertions(+), 1 deletions(-)

jump to
M src/gb/gb.csrc/gb/gb.c

@@ -622,6 +622,8 @@ break;

} 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 @@ GBUpdateIRQs(gb);

} 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"); } }