Ability to reset emulator while running

This commit is contained in:
Jeffrey Pfau 2014-07-15 00:01:35 -07:00
parent 939c349533
commit 6716b13621
3 changed files with 22 additions and 0 deletions

View File

@ -146,6 +146,8 @@ static THREAD_ENTRY _GBAThreadRun(void* context) {
ARMRun(&cpu); ARMRun(&cpu);
} }
} }
int resetScheduled = 0;
MutexLock(&threadContext->stateMutex); MutexLock(&threadContext->stateMutex);
if (threadContext->state == THREAD_PAUSING) { if (threadContext->state == THREAD_PAUSING) {
threadContext->state = THREAD_PAUSED; threadContext->state = THREAD_PAUSED;
@ -155,10 +157,17 @@ static THREAD_ENTRY _GBAThreadRun(void* context) {
threadContext->state = THREAD_INTERRUPTED; threadContext->state = THREAD_INTERRUPTED;
ConditionWake(&threadContext->stateCond); ConditionWake(&threadContext->stateCond);
} }
if (threadContext->state == THREAD_RESETING) {
threadContext->state = THREAD_RUNNING;
resetScheduled = 1;
}
while (threadContext->state == THREAD_PAUSED) { while (threadContext->state == THREAD_PAUSED) {
ConditionWait(&threadContext->stateCond, &threadContext->stateMutex); ConditionWait(&threadContext->stateCond, &threadContext->stateMutex);
} }
MutexUnlock(&threadContext->stateMutex); MutexUnlock(&threadContext->stateMutex);
if (resetScheduled) {
ARMReset(&cpu);
}
} }
while (threadContext->state != THREAD_SHUTDOWN) { while (threadContext->state != THREAD_SHUTDOWN) {
@ -254,6 +263,14 @@ void GBAThreadEnd(struct GBAThread* threadContext) {
MutexUnlock(&threadContext->sync.audioBufferMutex); 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) { void GBAThreadJoin(struct GBAThread* threadContext) {
MutexLock(&threadContext->sync.videoFrameMutex); MutexLock(&threadContext->sync.videoFrameMutex);
threadContext->sync.videoFrameWait = 0; threadContext->sync.videoFrameWait = 0;

View File

@ -18,6 +18,7 @@ enum ThreadState {
THREAD_INTERRUPTING, THREAD_INTERRUPTING,
THREAD_PAUSED, THREAD_PAUSED,
THREAD_PAUSING, THREAD_PAUSING,
THREAD_RESETING,
THREAD_EXITING, THREAD_EXITING,
THREAD_SHUTDOWN THREAD_SHUTDOWN
}; };
@ -82,6 +83,7 @@ void GBAMapOptionsToContext(struct StartupOptions*, struct GBAThread*);
int GBAThreadStart(struct GBAThread* threadContext); int GBAThreadStart(struct GBAThread* threadContext);
int GBAThreadHasStarted(struct GBAThread* threadContext); int GBAThreadHasStarted(struct GBAThread* threadContext);
void GBAThreadEnd(struct GBAThread* threadContext); void GBAThreadEnd(struct GBAThread* threadContext);
void GBAThreadReset(struct GBAThread* threadContext);
void GBAThreadJoin(struct GBAThread* threadContext); void GBAThreadJoin(struct GBAThread* threadContext);
void GBAThreadInterrupt(struct GBAThread* threadContext); void GBAThreadInterrupt(struct GBAThread* threadContext);

View File

@ -118,6 +118,9 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, struct GBASDLEvents
context->frameCallback = _pauseAfterFrame; context->frameCallback = _pauseAfterFrame;
GBAThreadUnpause(context); GBAThreadUnpause(context);
break; break;
case SDLK_r:
GBAThreadReset(context);
break;
default: default:
break; break;
} }