Ability to reset emulator while running
Jeffrey Pfau jeffrey@endrift.com
Tue, 15 Jul 2014 00:01:35 -0700
3 files changed,
22 insertions(+),
0 deletions(-)
M
src/gba/gba-thread.c
→
src/gba/gba-thread.c
@@ -146,6 +146,8 @@ while (threadContext->state == THREAD_RUNNING) {
ARMRun(&cpu); } } + + int resetScheduled = 0; MutexLock(&threadContext->stateMutex); if (threadContext->state == THREAD_PAUSING) { threadContext->state = THREAD_PAUSED;@@ -155,10 +157,17 @@ if (threadContext->state == THREAD_INTERRUPTING) {
threadContext->state = THREAD_INTERRUPTED; ConditionWake(&threadContext->stateCond); } + if (threadContext->state == THREAD_RESETING) { + threadContext->state = THREAD_RUNNING; + resetScheduled = 1; + } while (threadContext->state == THREAD_PAUSED) { ConditionWait(&threadContext->stateCond, &threadContext->stateMutex); } MutexUnlock(&threadContext->stateMutex); + if (resetScheduled) { + ARMReset(&cpu); + } } while (threadContext->state != THREAD_SHUTDOWN) {@@ -252,6 +261,14 @@ MutexLock(&threadContext->sync.audioBufferMutex);
threadContext->sync.audioWait = 0; ConditionWake(&threadContext->sync.audioRequiredCond); MutexUnlock(&threadContext->sync.audioBufferMutex); +} + +void GBAThreadReset(struct GBAThread* threadContext) { + MutexLock(&threadContext->stateMutex); + _waitOnInterrupt(threadContext); + threadContext->state = THREAD_RESETING; + ConditionWake(&threadContext->stateCond); + MutexUnlock(&threadContext->stateMutex); } void GBAThreadJoin(struct GBAThread* threadContext) {
M
src/gba/gba-thread.h
→
src/gba/gba-thread.h
@@ -18,6 +18,7 @@ THREAD_INTERRUPTED,
THREAD_INTERRUPTING, THREAD_PAUSED, THREAD_PAUSING, + THREAD_RESETING, THREAD_EXITING, THREAD_SHUTDOWN };@@ -82,6 +83,7 @@
int GBAThreadStart(struct GBAThread* threadContext); int GBAThreadHasStarted(struct GBAThread* threadContext); void GBAThreadEnd(struct GBAThread* threadContext); +void GBAThreadReset(struct GBAThread* threadContext); void GBAThreadJoin(struct GBAThread* threadContext); void GBAThreadInterrupt(struct GBAThread* threadContext);
M
src/platform/sdl/sdl-events.c
→
src/platform/sdl/sdl-events.c
@@ -118,6 +118,9 @@ GBAThreadPause(context);
context->frameCallback = _pauseAfterFrame; GBAThreadUnpause(context); break; + case SDLK_r: + GBAThreadReset(context); + break; default: break; }