mirror of https://github.com/mgba-emu/mgba.git
Ability to reset emulator while running
This commit is contained in:
parent
939c349533
commit
6716b13621
|
@ -146,6 +146,8 @@ static THREAD_ENTRY _GBAThreadRun(void* context) {
|
|||
ARMRun(&cpu);
|
||||
}
|
||||
}
|
||||
|
||||
int resetScheduled = 0;
|
||||
MutexLock(&threadContext->stateMutex);
|
||||
if (threadContext->state == THREAD_PAUSING) {
|
||||
threadContext->state = THREAD_PAUSED;
|
||||
|
@ -155,10 +157,17 @@ static THREAD_ENTRY _GBAThreadRun(void* context) {
|
|||
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) {
|
||||
|
@ -254,6 +263,14 @@ void GBAThreadEnd(struct GBAThread* threadContext) {
|
|||
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) {
|
||||
MutexLock(&threadContext->sync.videoFrameMutex);
|
||||
threadContext->sync.videoFrameWait = 0;
|
||||
|
|
|
@ -18,6 +18,7 @@ enum ThreadState {
|
|||
THREAD_INTERRUPTING,
|
||||
THREAD_PAUSED,
|
||||
THREAD_PAUSING,
|
||||
THREAD_RESETING,
|
||||
THREAD_EXITING,
|
||||
THREAD_SHUTDOWN
|
||||
};
|
||||
|
@ -82,6 +83,7 @@ void GBAMapOptionsToContext(struct StartupOptions*, struct GBAThread*);
|
|||
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);
|
||||
|
|
|
@ -118,6 +118,9 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, struct GBASDLEvents
|
|||
context->frameCallback = _pauseAfterFrame;
|
||||
GBAThreadUnpause(context);
|
||||
break;
|
||||
case SDLK_r:
|
||||
GBAThreadReset(context);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue