all repos — mgba @ c89c3964dbde285b318d80cb82b642dcc0eefb21

mGBA Game Boy Advance Emulator

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
commit

c89c3964dbde285b318d80cb82b642dcc0eefb21

parent

ed94288902a67d9dd0fd86211e07cb27000ec826

2 files changed, 17 insertions(+), 10 deletions(-)

jump to
M src/lr35902/lr35902.csrc/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.hsrc/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 {