GB: Improve STOP and illegal instruction handling

This commit is contained in:
Jeffrey Pfau 2016-09-06 00:24:55 -07:00
parent 8c0c03fb6a
commit f5bf1221eb
2 changed files with 25 additions and 6 deletions

View File

@ -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) {

View File

@ -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; \