diff --git a/src/gba/gba-thread.c b/src/gba/gba-thread.c index 2fd6ec3cc..de916b5a4 100644 --- a/src/gba/gba-thread.c +++ b/src/gba/gba-thread.c @@ -291,6 +291,11 @@ void GBASyncPostFrame(struct GBASync* sync) { } } MutexUnlock(&sync->videoFrameMutex); + + struct GBAThread* thread = GBAThreadGetContext(); + if (thread->frameCallback) { + thread->frameCallback(thread); + } } int GBASyncWaitFrameStart(struct GBASync* sync, int frameskip) { diff --git a/src/gba/gba-thread.h b/src/gba/gba-thread.h index 82bcc4b92..4c9ef7f01 100644 --- a/src/gba/gba-thread.h +++ b/src/gba/gba-thread.h @@ -36,6 +36,7 @@ struct GBAThread { ThreadCallback startCallback; ThreadCallback cleanCallback; + ThreadCallback frameCallback; void* userData; struct GBASync { diff --git a/src/platform/sdl/gl-main.c b/src/platform/sdl/gl-main.c index b397555b6..af592d94f 100644 --- a/src/platform/sdl/gl-main.c +++ b/src/platform/sdl/gl-main.c @@ -73,6 +73,7 @@ int main(int argc, char** argv) { context.sync.audioWait = 1; context.startCallback = _GBASDLStart; context.cleanCallback = _GBASDLClean; + context.frameCallback = 0; context.userData = &renderer; GBAThreadStart(&context); diff --git a/src/platform/sdl/sdl-events.c b/src/platform/sdl/sdl-events.c index d7dde1251..5525d0c1f 100644 --- a/src/platform/sdl/sdl-events.c +++ b/src/platform/sdl/sdl-events.c @@ -11,6 +11,7 @@ int GBASDLInitEvents(struct GBASDLEvents* context) { } SDL_JoystickEventState(SDL_ENABLE); context->joystick = SDL_JoystickOpen(0); + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); return 1; } @@ -19,6 +20,11 @@ void GBASDLDeinitEvents(struct GBASDLEvents* context) { SDL_QuitSubSystem(SDL_INIT_JOYSTICK); } +static void _pauseAfterFrame(struct GBAThread* context) { + context->frameCallback = 0; + GBAThreadPause(context); +} + static void _GBASDLHandleKeypress(struct GBAThread* context, const struct SDL_KeyboardEvent* event) { enum GBAKey key = 0; switch (event->keysym.sym) { @@ -68,6 +74,12 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, const struct SDL_Ke switch (event->keysym.sym) { case SDLK_p: GBAThreadTogglePause(context); + break; + case SDLK_n: + GBAThreadPause(context); + context->frameCallback = _pauseAfterFrame; + GBAThreadUnpause(context); + break; default: break; }