From 000b49e45b30ec9c856b7b2e8cf8baee21daa56d Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 18 Jul 2020 15:41:46 -0700 Subject: [PATCH] DS: Backport GBA event changes --- src/ds/ds.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/ds/ds.c b/src/ds/ds.c index 492b7a831..a00912f44 100644 --- a/src/ds/ds.c +++ b/src/ds/ds.c @@ -418,26 +418,22 @@ static void DSProcessEvents(struct DSCommon* dscore) { int32_t nextEvent = cpu->nextEvent; while (cpu->cycles >= nextEvent) { - int32_t cycles = cpu->cycles; - - cpu->cycles = 0; - cpu->nextEvent = 0; - -#ifndef NDEBUG - if (cycles < 0) { - mLOG(DS, FATAL, "Negative cycles passed: %i", cycles); - } -#endif - nextEvent = cycles; + cpu->nextEvent = INT_MAX; + nextEvent = 0; do { - nextEvent = mTimingTick(&dscore->timing, nextEvent); + int32_t cycles = cpu->cycles; + cpu->cycles = 0; +#ifdef USE_DEBUGGERS + dscore->timing.globalCycles += cycles; +#endif +#ifndef NDEBUG + if (cycles < 0) { + mLOG(DS, FATAL, "Negative cycles passed: %i", cycles); + } +#endif + nextEvent = mTimingTick(&dscore->timing, cycles < nextEvent ? nextEvent : cycles); } while (ds->cpuBlocked && !ds->earlyExit); - if (ds->earlyExit) { - ds->earlyExit = false; - break; - } - cpu->nextEvent = nextEvent; if (cpu->halted) { cpu->cycles = nextEvent; @@ -447,6 +443,13 @@ static void DSProcessEvents(struct DSCommon* dscore) { mLOG(DS, FATAL, "Negative cycles will pass: %i", nextEvent); } #endif + if (ds->earlyExit) { + break; + } + } + ds->earlyExit = false; + if (ds->cpuBlocked) { + cpu->cycles = cpu->nextEvent; } }