all repos — mgba @ d3a018c35b159d498a76df7f5dbfdc72ca811acc

mGBA Game Boy Advance Emulator

Switch: Configurable fast forward cap
Vicki Pfau vi@endrift.com
Wed, 19 Sep 2018 16:23:41 -0700
commit

d3a018c35b159d498a76df7f5dbfdc72ca811acc

parent

35d2e0eee9a1f5be82b223b712f03a517b4ef6a4

1 files changed, 34 insertions(+), 11 deletions(-)

jump to
M src/platform/switch/main.csrc/platform/switch/main.c

@@ -10,6 +10,7 @@ #include <mgba/internal/gba/audio.h>

#include <mgba/internal/gba/input.h> #include <mgba-util/gui.h> #include <mgba-util/gui/font.h> +#include <mgba-util/gui/menu.h> #include <switch.h> #include <EGL/egl.h>

@@ -19,7 +20,6 @@ #define AUTO_INPUT 0x4E585031

#define SAMPLES 0x400 #define BUFFER_SIZE 0x1000 #define N_BUFFERS 4 -#define FRAME_LIMIT 10 TimeType __nx_time_type = TimeType_UserSystemClock;

@@ -79,7 +79,8 @@ static struct GBAStereoSample audioBuffer[N_BUFFERS][SAMPLES] __attribute__((__aligned__(0x1000)));

static AudioOutBuffer audoutBuffer[N_BUFFERS]; static int enqueuedBuffers; static bool frameLimiter = true; -static int framecount = 0; +static unsigned framecount = 0; +static unsigned framecap = 10; static bool initEgl() { s_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

@@ -150,8 +151,9 @@ glClear(GL_COLOR_BUFFER_BIT);

} static void _drawEnd(void) { - if (frameLimiter || (framecount % FRAME_LIMIT) == 0) { + if (frameLimiter || framecount >= framecap) { eglSwapBuffers(s_display, s_surface); + framecount = 0; } }

@@ -198,6 +200,8 @@

double ratio = GBAAudioCalculateRatio(1, 60.0, 1); blip_set_rates(runner->core->getAudioChannel(runner->core, 0), runner->core->frequency(runner->core), samplerate * ratio); blip_set_rates(runner->core->getAudioChannel(runner->core, 1), runner->core->frequency(runner->core), samplerate * ratio); + + mCoreConfigGetUIntValue(&runner->config, "fastForwardCap", &framecap); } static void _drawTex(struct mGUIRunner* runner, unsigned width, unsigned height, bool faded) {

@@ -233,11 +237,21 @@ glBindVertexArray(0);

glUseProgram(0); } +static void _prepareForFrame(struct mGUIRunner* runner) { + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); + frameBuffer = glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, 256 * 256 * 4, GL_MAP_WRITE_BIT); + if (frameBuffer) { + runner->core->setVideoBuffer(runner->core, frameBuffer, 256); + } + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); +} + static void _drawFrame(struct mGUIRunner* runner, bool faded) { ++framecount; - if (!frameLimiter && (framecount % FRAME_LIMIT) != 0) { + if (!frameLimiter && framecount < framecap) { return; } + unsigned width, height; runner->core->desiredVideoDimensions(runner->core, &width, &height);

@@ -250,11 +264,6 @@ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, height, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); _drawTex(runner, width, height, faded); - - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); - frameBuffer = glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, 256 * 256 * 4, GL_MAP_WRITE_BIT); - runner->core->setVideoBuffer(runner->core, frameBuffer, 256); - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); } static void _drawScreenshot(struct mGUIRunner* runner, const color_t* pixels, unsigned width, unsigned height, bool faded) {

@@ -475,12 +484,26 @@ .nKeys = 26

}, { .id = 0 } }, - .nConfigExtra = 0, + .configExtra = (struct GUIMenuItem[]) { + { + .title = "Fast forward cap", + .data = "fastForwardCap", + .submenu = 0, + .state = 7, + .validStates = (const char*[]) { + "3", "4", "5", "6", "7", "8", "9", + "10", "11", "12", "13", "14", "15", + "20", "30" + }, + .nStates = 15 + }, + }, + .nConfigExtra = 1, .setup = _setup, .teardown = NULL, .gameLoaded = _gameLoaded, .gameUnloaded = NULL, - .prepareForFrame = NULL, + .prepareForFrame = _prepareForFrame, .drawFrame = _drawFrame, .drawScreenshot = _drawScreenshot, .paused = NULL,