all repos — mgba @ 90e932e12c0e093d9ff35989bf12778d7ff079eb

mGBA Game Boy Advance Emulator

SM83: Emulate HALT bug
Vicki Pfau vi@endrift.com
Fri, 05 Jun 2020 20:29:31 -0700
commit

90e932e12c0e093d9ff35989bf12778d7ff079eb

parent

3ef59bd2c401d49654b0d003ed83e86e55e245a3

4 files changed, 17 insertions(+), 3 deletions(-)

jump to
M CHANGESCHANGES

@@ -27,6 +27,7 @@ - GBA Video: Fix mosaic objects drawing past the end (fixes mgba.io/i/1702)

- GBA Video: Fix disabling OBJWIN in GL renderer (fixes mgba.io/i/1759) - GBA Video: Add missing parts of 256-color mode 0 mosaic (fixes mgba.io/1701) - GBA Video: Fix double-size OBJ wrapping in GL renderer (fixes mgba.io/1712) + - SM83: Emulate HALT bug Other fixes: - 3DS: Fix framelimiter on newer citro3d (fixes mgba.io/i/1771) - All: Improve export headers (fixes mgba.io/i/1738)
M include/mgba/internal/sm83/sm83.hinclude/mgba/internal/sm83/sm83.h

@@ -47,7 +47,8 @@ SM83_CORE_MEMORY_LOAD = 7,

SM83_CORE_MEMORY_STORE = 11, SM83_CORE_READ_PC = 15, SM83_CORE_STALL = 19, - SM83_CORE_OP2 = 23 + SM83_CORE_OP2 = 23, + SM83_CORE_HALT_BUG = 27, }; struct SM83Memory { uint8_t (*cpuLoad8)(struct SM83Core*, uint16_t address);
M src/gb/gb.csrc/gb/gb.c

@@ -749,8 +749,9 @@ struct GB* gb = (struct GB*) cpu->master;

if (!(gb->memory.ie & gb->memory.io[REG_IF] & 0x1F)) { cpu->cycles = cpu->nextEvent; cpu->halted = true; - } else if (gb->model < GB_MODEL_CGB) { - mLOG(GB, STUB, "Unimplemented HALT bug"); + } else { + mLOG(GB, GAME_ERROR, "HALT bug"); + cpu->executionState = SM83_CORE_HALT_BUG; } }
M src/sm83/sm83.csrc/sm83/sm83.c

@@ -131,6 +131,17 @@ break;

case SM83_CORE_STALL: cpu->instruction = _sm83InstructionTable[0]; // NOP break; + case SM83_CORE_HALT_BUG: + if (cpu->irqPending) { + cpu->index = cpu->sp; + cpu->irqPending = false; + cpu->instruction = _SM83InstructionIRQ; + cpu->irqh.setInterrupts(cpu, false); + break; + } + cpu->bus = cpu->memory.cpuLoad8(cpu, cpu->pc); + cpu->instruction = _sm83InstructionTable[cpu->bus]; + break; default: break; }