all repos — mgba @ ef66e4a8c7ca318ac8e7ed29647d23608bbd9325

mGBA Game Boy Advance Emulator

Only unpause from state operations when we paused manually
Jeffrey Pfau jeffrey@endrift.com
Sun, 26 Jan 2014 23:17:17 -0800
commit

ef66e4a8c7ca318ac8e7ed29647d23608bbd9325

parent

c3a5fb497af232da51a45e1fb14d8e57557fb951

3 files changed, 28 insertions(+), 7 deletions(-)

jump to
M src/gba/gba-thread.csrc/gba/gba-thread.c

@@ -256,6 +256,14 @@ }

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);

@@ -277,7 +285,6 @@ ConditionWake(&threadContext->sync.videoFrameAvailableCond);

} MutexUnlock(&threadContext->sync.videoFrameMutex); } - #ifdef USE_PTHREADS struct GBAThread* GBAThreadGetContext(void) {
M src/gba/gba-thread.hsrc/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);
M src/platform/sdl/sdl-events.csrc/platform/sdl/sdl-events.c

@@ -27,6 +27,7 @@ }

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 @@ case SDLK_TAB:

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 @@ case SDLK_F7:

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 @@ case SDLK_F7:

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;