mirror of https://github.com/mgba-emu/mgba.git
GB: Improve STOP and illegal instruction handling
This commit is contained in:
parent
8c0c03fb6a
commit
f5bf1221eb
26
src/gb/gb.c
26
src/gb/gb.c
|
@ -404,7 +404,19 @@ void GBHalt(struct LR35902Core* cpu) {
|
||||||
|
|
||||||
void GBStop(struct LR35902Core* cpu) {
|
void GBStop(struct LR35902Core* cpu) {
|
||||||
struct GB* gb = (struct GB*) cpu->master;
|
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->doubleSpeed ^= 1;
|
||||||
gb->memory.io[REG_KEY1] &= 1;
|
gb->memory.io[REG_KEY1] &= 1;
|
||||||
gb->memory.io[REG_KEY1] |= gb->doubleSpeed << 7;
|
gb->memory.io[REG_KEY1] |= gb->doubleSpeed << 7;
|
||||||
|
@ -413,8 +425,18 @@ void GBStop(struct LR35902Core* cpu) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBIllegal(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);
|
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) {
|
bool GBIsROM(struct VFile* vf) {
|
||||||
|
|
|
@ -769,10 +769,7 @@ DEFINE_RST_INSTRUCTION_LR35902(38);
|
||||||
|
|
||||||
DEFINE_INSTRUCTION_LR35902(ILL, cpu->irqh.hitIllegal(cpu));
|
DEFINE_INSTRUCTION_LR35902(ILL, cpu->irqh.hitIllegal(cpu));
|
||||||
|
|
||||||
DEFINE_INSTRUCTION_LR35902(STOP2,
|
DEFINE_INSTRUCTION_LR35902(STOP2, cpu->irqh.stop(cpu));
|
||||||
if (!cpu->bus) {
|
|
||||||
cpu->irqh.stop(cpu);
|
|
||||||
});
|
|
||||||
|
|
||||||
DEFINE_INSTRUCTION_LR35902(STOP, \
|
DEFINE_INSTRUCTION_LR35902(STOP, \
|
||||||
cpu->executionState = LR35902_CORE_READ_PC; \
|
cpu->executionState = LR35902_CORE_READ_PC; \
|
||||||
|
|
Loading…
Reference in New Issue