diff --git a/src/lr35902/lr35902.c b/src/lr35902/lr35902.c index f40ab6462..ff92587fb 100644 --- a/src/lr35902/lr35902.c +++ b/src/lr35902/lr35902.c @@ -148,8 +148,15 @@ void LR35902Tick(struct LR35902Core* cpu) { } void LR35902Run(struct LR35902Core* cpu) { - while (cpu->cycles < cpu->nextEvent) { + while (true) { _LR35902Step(cpu); + if (cpu->cycles >= cpu->nextEvent) { + break; + } else if (cpu->executionState < LR35902_CORE_EXECUTE) { + // Silly hack: keep us from calling step if we know the next step is a no-op + ++cpu->cycles; + ++cpu->executionState; + } } cpu->irqh.processEvents(cpu); } diff --git a/src/lr35902/lr35902.h b/src/lr35902/lr35902.h index 240195c9d..93c8c8613 100644 --- a/src/lr35902/lr35902.h +++ b/src/lr35902/lr35902.h @@ -36,16 +36,16 @@ union FlagRegister { #pragma pack(pop) enum LR35902ExecutionState { - LR35902_CORE_FETCH = 0, - LR35902_CORE_IDLE_0, - LR35902_CORE_IDLE_1, - LR35902_CORE_EXECUTE = 3, + LR35902_CORE_FETCH = 3, + LR35902_CORE_IDLE_0 = 0, + LR35902_CORE_IDLE_1 = 1, + LR35902_CORE_EXECUTE = 2, - LR35902_CORE_MEMORY_LOAD = 4, - LR35902_CORE_MEMORY_STORE = 8, - LR35902_CORE_READ_PC = 12, - LR35902_CORE_STALL = 16, - LR35902_CORE_OP2 = 20 + LR35902_CORE_MEMORY_LOAD = 7, + LR35902_CORE_MEMORY_STORE = 11, + LR35902_CORE_READ_PC = 15, + LR35902_CORE_STALL = 19, + LR35902_CORE_OP2 = 23 }; struct LR35902Memory {