From 1039569b01af29472edff27ad8eacc5883abbfd0 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Tue, 21 Feb 2017 01:07:11 -0800 Subject: [PATCH] DS: Improve step stability --- src/arm/arm.c | 10 ++++++---- src/ds/ds.c | 28 +++++++++++++++++----------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/arm/arm.c b/src/arm/arm.c index 372da1411..460e4228e 100644 --- a/src/arm/arm.c +++ b/src/arm/arm.c @@ -303,10 +303,12 @@ void ARMHalt(struct ARMCore* cpu) { } \ \ void ARM ## VERSION ## Run(struct ARMCore* cpu) { \ - if (cpu->executionMode == MODE_THUMB) { \ - Thumb ## VERSION ## Step(cpu); \ - } else { \ - ARM ## VERSION ## Step(cpu); \ + if (cpu->cycles < cpu->nextEvent) { \ + if (cpu->executionMode == MODE_THUMB) { \ + Thumb ## VERSION ## Step(cpu); \ + } else { \ + ARM ## VERSION ## Step(cpu); \ + } \ } \ if (cpu->cycles >= cpu->nextEvent) { \ cpu->irqh.processEvents(cpu); \ diff --git a/src/ds/ds.c b/src/ds/ds.c index e56e4c858..262c6c1e0 100644 --- a/src/ds/ds.c +++ b/src/ds/ds.c @@ -359,7 +359,7 @@ static void DSProcessEvents(struct DSCommon* dscore) { int32_t cycles = cpu->cycles; cpu->cycles = 0; - cpu->nextEvent = INT_MAX; + cpu->nextEvent = 0; #ifndef NDEBUG if (cycles < 0) { @@ -371,12 +371,12 @@ static void DSProcessEvents(struct DSCommon* dscore) { nextEvent = mTimingTick(&dscore->timing, nextEvent); } while (ds->cpuBlocked); - cpu->nextEvent = nextEvent; - if (ds->earlyExit) { ds->earlyExit = false; break; } + + cpu->nextEvent = nextEvent; if (cpu->halted) { cpu->cycles = nextEvent; } @@ -397,17 +397,23 @@ void DSRunLoop(struct DS* ds) { } void DS7Step(struct DS* ds) { - while (ds->activeCpu == ds->ds9.cpu) { - ARMv5RunLoop(ds->ds9.cpu); - } - ARMv4Run(ds->ds7.cpu); + int32_t pc = ds->ds7.cpu->gprs[ARM_PC]; + do { + while (ds->activeCpu == ds->ds9.cpu) { + ARMv5RunLoop(ds->ds9.cpu); + } + ARMv4Run(ds->ds7.cpu); + } while (ds->ds7.cpu->halted || ds->ds7.cpu->gprs[ARM_PC] == pc); } void DS9Step(struct DS* ds) { - while (ds->activeCpu == ds->ds7.cpu) { - ARMv4RunLoop(ds->ds7.cpu); - } - ARMv5Run(ds->ds9.cpu); + int32_t pc = ds->ds9.cpu->gprs[ARM_PC]; + do { + while (ds->activeCpu == ds->ds7.cpu) { + ARMv4RunLoop(ds->ds7.cpu); + } + ARMv5Run(ds->ds9.cpu); + } while (ds->ds9.cpu->halted || ds->ds9.cpu->gprs[ARM_PC] == pc); } void DSAttachDebugger(struct DS* ds, struct mDebugger* debugger) {