all repos — mgba @ f5bf1221eba8fcc572c1f66ce74de31f6049451e

mGBA Game Boy Advance Emulator

GB: Improve STOP and illegal instruction handling
Jeffrey Pfau jeffrey@endrift.com
Tue, 06 Sep 2016 00:24:55 -0700
commit

f5bf1221eba8fcc572c1f66ce74de31f6049451e

parent

8c0c03fb6a8c2ade5dc3d411166096708c4219e5

2 files changed, 25 insertions(+), 6 deletions(-)

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

@@ -404,7 +404,19 @@ }

void GBStop(struct LR35902Core* cpu) { struct GB* gb = (struct GB*) cpu->master; - if (gb->memory.io[REG_KEY1] & 1) { + if (cpu->bus) { + mLOG(GB, GAME_ERROR, "Hit illegal stop at address %04X:%02X\n", cpu->pc, cpu->bus); + if (cpu->components && cpu->components[CPU_COMPONENT_DEBUGGER]) { + struct mDebuggerEntryInfo info = { + .address = cpu->pc - 1, + .opcode = 0x1000 | cpu->bus + }; + mDebuggerEnter((struct mDebugger*) cpu->components[CPU_COMPONENT_DEBUGGER], DEBUGGER_ENTER_ILLEGAL_OP, &info); + } + // Hang forever + gb->memory.ime = 0; + cpu->pc -= 2; + } else if (gb->memory.io[REG_KEY1] & 1) { gb->doubleSpeed ^= 1; gb->memory.io[REG_KEY1] &= 1; gb->memory.io[REG_KEY1] |= gb->doubleSpeed << 7;

@@ -413,8 +425,18 @@ // TODO: Actually stop

} void GBIllegal(struct LR35902Core* cpu) { - // TODO + struct GB* gb = (struct GB*) cpu->master; mLOG(GB, GAME_ERROR, "Hit illegal opcode at address %04X:%02X\n", cpu->pc, cpu->bus); + if (cpu->components && cpu->components[CPU_COMPONENT_DEBUGGER]) { + struct mDebuggerEntryInfo info = { + .address = cpu->pc, + .opcode = cpu->bus + }; + mDebuggerEnter((struct mDebugger*) cpu->components[CPU_COMPONENT_DEBUGGER], DEBUGGER_ENTER_ILLEGAL_OP, &info); + } + // Hang forever + gb->memory.ime = 0; + --cpu->pc; } bool GBIsROM(struct VFile* vf) {
M src/lr35902/isa-lr35902.csrc/lr35902/isa-lr35902.c

@@ -769,10 +769,7 @@ DEFINE_RST_INSTRUCTION_LR35902(38);

DEFINE_INSTRUCTION_LR35902(ILL, cpu->irqh.hitIllegal(cpu)); -DEFINE_INSTRUCTION_LR35902(STOP2, - if (!cpu->bus) { - cpu->irqh.stop(cpu); - }); +DEFINE_INSTRUCTION_LR35902(STOP2, cpu->irqh.stop(cpu)); DEFINE_INSTRUCTION_LR35902(STOP, \ cpu->executionState = LR35902_CORE_READ_PC; \