From 2ee7642d0ba2ec66488e3bf4897d6196ee281723 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Tue, 29 Dec 2020 01:59:38 -0800 Subject: [PATCH] GB, GBA: Fix global cycle counter discrepancy --- src/gb/gb.c | 6 +++--- src/gba/gba.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gb/gb.c b/src/gb/gb.c index 6fa16b919..5f4207880 100644 --- a/src/gb/gb.c +++ b/src/gb/gb.c @@ -707,13 +707,13 @@ void GBProcessEvents(struct SM83Core* cpu) { int32_t nextEvent; cpu->cycles = 0; -#ifdef USE_DEBUGGERS - gb->timing.globalCycles += cycles; -#endif cpu->nextEvent = INT_MAX; nextEvent = cycles; do { +#ifdef USE_DEBUGGERS + gb->timing.globalCycles += nextEvent; +#endif nextEvent = mTimingTick(&gb->timing, nextEvent); } while (gb->cpuBlocked && !gb->earlyExit); cpu->nextEvent = nextEvent; diff --git a/src/gba/gba.c b/src/gba/gba.c index 68e03784e..ca5d97370 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -288,7 +288,7 @@ static void GBAProcessEvents(struct ARMCore* cpu) { int32_t cycles = cpu->cycles; cpu->cycles = 0; #ifdef USE_DEBUGGERS - gba->timing.globalCycles += cycles; + gba->timing.globalCycles += cycles < nextEvent ? nextEvent : cycles; #endif #ifndef NDEBUG if (cycles < 0) {