Add frame advance

This commit is contained in:
Jeffrey Pfau 2014-01-20 16:39:46 -08:00
parent e7d4f3ae8a
commit 26c1fbd48f
4 changed files with 19 additions and 0 deletions

View File

@ -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) {

View File

@ -36,6 +36,7 @@ struct GBAThread {
ThreadCallback startCallback;
ThreadCallback cleanCallback;
ThreadCallback frameCallback;
void* userData;
struct GBASync {

View File

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

View File

@ -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;
}