all repos — mgba @ da62e772a423de9e1b04a309047cc202058de7f7

mGBA Game Boy Advance Emulator

LR35902: Fix IRQ timing
Jeffrey Pfau jeffrey@endrift.com
Wed, 27 Jan 2016 21:42:06 -0800
commit

da62e772a423de9e1b04a309047cc202058de7f7

parent

213ba2996479391de53af8cca42f48820ce75d69

1 files changed, 14 insertions(+), 5 deletions(-)

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

@@ -75,11 +75,20 @@ cpu->irqPending = true;

cpu->irqVector = vector; } +static void _LR35902InstructionIRQStall(struct LR35902Core* cpu) { + cpu->executionState = LR35902_CORE_STALL; +} + static void _LR35902InstructionIRQFinish(struct LR35902Core* cpu) { + cpu->executionState = LR35902_CORE_OP2; + cpu->instruction = _LR35902InstructionIRQStall; +} + +static void _LR35902InstructionIRQDelay(struct LR35902Core* cpu) { cpu->index = cpu->sp + 1; cpu->bus = cpu->pc >> 8; cpu->executionState = LR35902_CORE_MEMORY_STORE; - cpu->instruction = _lr35902InstructionTable[0]; // NOP + cpu->instruction = _LR35902InstructionIRQFinish; cpu->pc = cpu->irqVector; cpu->memory.setActiveRegion(cpu, cpu->pc); }

@@ -89,11 +98,11 @@ cpu->sp -= 2; /* TODO: Atomic incrementing? */

cpu->index = cpu->sp; cpu->bus = cpu->pc; cpu->executionState = LR35902_CORE_MEMORY_STORE; - cpu->instruction = _LR35902InstructionIRQFinish; + cpu->instruction = _LR35902InstructionIRQDelay; cpu->irqh.setInterrupts(cpu, false); } -static void _lr35902Step(struct LR35902Core* cpu) { +static void _LR35902Step(struct LR35902Core* cpu) { ++cpu->cycles; enum LR35902ExecutionState state = cpu->executionState; ++cpu->executionState;

@@ -132,7 +141,7 @@ }

} void LR35902Tick(struct LR35902Core* cpu) { - _lr35902Step(cpu); + _LR35902Step(cpu); if (cpu->cycles >= cpu->nextEvent) { cpu->irqh.processEvents(cpu); }

@@ -140,7 +149,7 @@ }

void LR35902Run(struct LR35902Core* cpu) { while (cpu->cycles < cpu->nextEvent) { - _lr35902Step(cpu); + _LR35902Step(cpu); } cpu->irqh.processEvents(cpu); }