diff --git a/src/gba/gba-thread.c b/src/gba/gba-thread.c index 7dd8cffb0..ec3b30880 100644 --- a/src/gba/gba-thread.c +++ b/src/gba/gba-thread.c @@ -256,6 +256,14 @@ void GBAThreadUnpause(struct GBAThread* threadContext) { MutexUnlock(&threadContext->sync.videoFrameMutex); } +int GBAThreadIsPaused(struct GBAThread* threadContext) { + int isPaused; + MutexLock(&threadContext->stateMutex); + isPaused = threadContext->state == THREAD_PAUSED; + MutexUnlock(&threadContext->stateMutex); + return isPaused; +} + void GBAThreadTogglePause(struct GBAThread* threadContext) { int frameOn = 1; MutexLock(&threadContext->stateMutex); @@ -278,7 +286,6 @@ void GBAThreadTogglePause(struct GBAThread* threadContext) { MutexUnlock(&threadContext->sync.videoFrameMutex); } - #ifdef USE_PTHREADS struct GBAThread* GBAThreadGetContext(void) { pthread_once(&_contextOnce, _createTLS); diff --git a/src/gba/gba-thread.h b/src/gba/gba-thread.h index 8ec1a629f..bfd220a92 100644 --- a/src/gba/gba-thread.h +++ b/src/gba/gba-thread.h @@ -66,6 +66,7 @@ void GBAThreadJoin(struct GBAThread* threadContext); void GBAThreadPause(struct GBAThread* threadContext); void GBAThreadUnpause(struct GBAThread* threadContext); +int GBAThreadIsPaused(struct GBAThread* threadContext); void GBAThreadTogglePause(struct GBAThread* threadContext); struct GBAThread* GBAThreadGetContext(void); diff --git a/src/platform/sdl/sdl-events.c b/src/platform/sdl/sdl-events.c index 830865213..261bf3682 100644 --- a/src/platform/sdl/sdl-events.c +++ b/src/platform/sdl/sdl-events.c @@ -27,6 +27,7 @@ static void _pauseAfterFrame(struct GBAThread* context) { static void _GBASDLHandleKeypress(struct GBAThread* context, const struct SDL_KeyboardEvent* event) { enum GBAKey key = 0; + int isPaused = GBAThreadIsPaused(context); switch (event->keysym.sym) { case SDLK_z: key = GBA_KEY_A; @@ -69,9 +70,13 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, const struct SDL_Ke context->sync.audioWait = event->type != SDL_KEYDOWN; return; case SDLK_LEFTBRACKET: - GBAThreadPause(context); + if (!isPaused) { + GBAThreadPause(context); + } GBARewind(context, 10); - GBAThreadUnpause(context); + if (!isPaused) { + GBAThreadUnpause(context); + } default: if (event->type == SDL_KEYDOWN) { if (event->keysym.mod & KMOD_CTRL) { @@ -100,9 +105,13 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, const struct SDL_Ke case SDLK_F8: case SDLK_F9: case SDLK_F10: - GBAThreadPause(context); + if (!isPaused) { + GBAThreadPause(context); + } GBASaveState(context->gba, event->keysym.sym - SDLK_F1); - GBAThreadUnpause(context); + if (!isPaused) { + GBAThreadUnpause(context); + } break; default: break; @@ -119,9 +128,13 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, const struct SDL_Ke case SDLK_F8: case SDLK_F9: case SDLK_F10: - GBAThreadPause(context); + if (!isPaused) { + GBAThreadPause(context); + } GBALoadState(context->gba, event->keysym.sym - SDLK_F1); - GBAThreadUnpause(context); + if (!isPaused) { + GBAThreadUnpause(context); + } break; default: break;