Turbo mode
Jeffrey Pfau jeffrey@endrift.com
Tue, 23 Apr 2013 22:32:15 -0700
3 files changed,
19 insertions(+),
2 deletions(-)
M
src/gba/gba-video.h
→
src/gba/gba-video.h
@@ -143,6 +143,9 @@
uint16_t* palette; uint16_t* vram; union GBAOAM* oam; + + int framesPending; + int turbo; }; struct GBAVideo {
M
src/gba/renderers/video-software.c
→
src/gba/renderers/video-software.c
@@ -26,6 +26,9 @@ renderer->d.writeVideoRegister = GBAVideoSoftwareRendererWriteVideoRegister;
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* renderer) {
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); }
M
src/main.c
→
src/main.c
@@ -110,8 +110,13 @@ glBindTexture(GL_TEXTURE_2D, renderer->tex);
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 @@ break;
case SDLK_RIGHT: key = GBA_KEY_RIGHT; break; + case SDLK_TAB: + context->renderer->turbo = !context->renderer->turbo; + return; default: return; }