LR35902: Optimize CPU loop to prevent no-op cycles from being calculated
Jeffrey Pfau jeffrey@endrift.com
Sun, 14 Feb 2016 01:57:53 -0800
2 files changed,
17 insertions(+),
10 deletions(-)
M
src/lr35902/lr35902.c
→
src/lr35902/lr35902.c
@@ -148,8 +148,15 @@ }
} 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); }
M
src/lr35902/lr35902.h
→
src/lr35902/lr35902.h
@@ -36,16 +36,16 @@ };
#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 {