diff --git a/src/gb/gb.c b/src/gb/gb.c index 64b5e3b06..6b43140ee 100644 --- a/src/gb/gb.c +++ b/src/gb/gb.c @@ -404,7 +404,19 @@ void GBHalt(struct LR35902Core* cpu) { 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 @@ void GBStop(struct LR35902Core* cpu) { } 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) { diff --git a/src/lr35902/isa-lr35902.c b/src/lr35902/isa-lr35902.c index dbf8651f0..c9298f57d 100644 --- a/src/lr35902/isa-lr35902.c +++ b/src/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; \