From 7c7e934dacb82150e1565ce9149c60ac6144ef31 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Tue, 23 Apr 2013 22:32:15 -0700 Subject: [PATCH] Turbo mode --- src/gba/gba-video.h | 3 +++ src/gba/renderers/video-software.c | 8 +++++++- src/main.c | 10 +++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/gba/gba-video.h b/src/gba/gba-video.h index c94eebf2c..5f4d52629 100644 --- a/src/gba/gba-video.h +++ b/src/gba/gba-video.h @@ -143,6 +143,9 @@ struct GBAVideoRenderer { uint16_t* palette; uint16_t* vram; union GBAOAM* oam; + + int framesPending; + int turbo; }; struct GBAVideo { diff --git a/src/gba/renderers/video-software.c b/src/gba/renderers/video-software.c index 836e8275d..f7086769b 100644 --- a/src/gba/renderers/video-software.c +++ b/src/gba/renderers/video-software.c @@ -26,6 +26,9 @@ void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer) { renderer->d.drawScanline = GBAVideoSoftwareRendererDrawScanline; renderer->d.finishFrame = GBAVideoSoftwareRendererFinishFrame; + renderer->d.turbo = 0; + renderer->d.framesPending = 0; + renderer->sortedBg[0] = &renderer->bg[0]; renderer->sortedBg[1] = &renderer->bg[1]; renderer->sortedBg[2] = &renderer->bg[2]; @@ -170,7 +173,10 @@ static void GBAVideoSoftwareRendererFinishFrame(struct GBAVideoRenderer* rendere struct GBAVideoSoftwareRenderer* softwareRenderer = (struct GBAVideoSoftwareRenderer*) renderer; pthread_mutex_lock(&softwareRenderer->mutex); - pthread_cond_wait(&softwareRenderer->cond, &softwareRenderer->mutex); + renderer->framesPending++; + if (!renderer->turbo) { + pthread_cond_wait(&softwareRenderer->cond, &softwareRenderer->mutex); + } pthread_mutex_unlock(&softwareRenderer->mutex); } diff --git a/src/main.c b/src/main.c index 71e39b6ce..b80984e85 100644 --- a/src/main.c +++ b/src/main.c @@ -110,8 +110,13 @@ static void _GBASDLRunloop(struct GBAThread* context, struct GLSoftwareRenderer* glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5, 256, 256, 0, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, renderer->d.outputBuffer); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - SDL_GL_SwapBuffers(); pthread_mutex_lock(&renderer->d.mutex); + if (renderer->d.d.framesPending) { + --renderer->d.d.framesPending; + pthread_mutex_unlock(&renderer->d.mutex); + SDL_GL_SwapBuffers(); + pthread_mutex_lock(&renderer->d.mutex); + } pthread_cond_broadcast(&renderer->d.cond); pthread_mutex_unlock(&renderer->d.mutex); while (SDL_PollEvent(&event)) { @@ -168,6 +173,9 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, const struct SDL_Ke case SDLK_RIGHT: key = GBA_KEY_RIGHT; break; + case SDLK_TAB: + context->renderer->turbo = !context->renderer->turbo; + return; default: return; }