all repos — mgba @ a718a08e470457910f751448d6d76d26e3940cf2

mGBA Game Boy Advance Emulator

SDL: Remove mSDLRunGBA
Jeffrey Pfau jeffrey@endrift.com
Thu, 04 Feb 2016 22:16:33 -0800
commit

a718a08e470457910f751448d6d76d26e3940cf2

parent

407335e2f464828d5fe517372442fce798b58490

3 files changed, 30 insertions(+), 63 deletions(-)

jump to
M src/core/thread.csrc/core/thread.c

@@ -162,6 +162,9 @@ sigaddset(&signals, SIGTRAP);

pthread_sigmask(SIG_BLOCK, &signals, 0); #endif + threadContext->sync.audioWait = threadContext->core->opts.audioSync; + threadContext->sync.videoFrameWait = threadContext->core->opts.videoSync; + MutexLock(&threadContext->stateMutex); ThreadCreate(&threadContext->thread, _mCoreThreadRun, threadContext); while (threadContext->state < THREAD_RUNNING) {
M src/gba/core.csrc/gba/core.c

@@ -8,6 +8,7 @@

#include "core/core.h" #include "core/log.h" #include "gba/gba.h" +#include "gba/context/overrides.h" #include "gba/renderers/video-software.h" #include "gba/serialize.h" #include "util/memory.h"

@@ -134,9 +135,21 @@ return GBAUnloadROM(core->board);

} static void _GBACoreReset(struct mCore* core) { + struct GBA* gba = (struct GBA*) core->board; ARMReset(core->cpu); if (core->opts.skipBios) { GBASkipBIOS(core->board); + } + + struct GBACartridgeOverride override; + const struct GBACartridge* cart = (const struct GBACartridge*) gba->memory.rom; + memcpy(override.id, &cart->id, sizeof(override.id)); + struct Configuration* overrides = 0; +#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 + overrides = mCoreConfigGetOverrides(&core->config); +#endif + if (GBAOverrideFind(overrides, &override)) { + GBAOverrideApply(gba, &override); } }
M src/platform/sdl/main.csrc/platform/sdl/main.c

@@ -51,12 +51,7 @@

static bool mSDLInit(struct mSDLRenderer* renderer); static void mSDLDeinit(struct mSDLRenderer* renderer); -// TODO: Clean up signatures -#ifdef M_CORE_GBA -static int mSDLRunGBA(struct mSDLRenderer* renderer, struct mArguments* args, struct mCoreOptions* opts, struct mCoreConfig* config); -#endif static int mSDLRun(struct mSDLRenderer* renderer, struct mArguments* args); - int main(int argc, char** argv) { struct mSDLRenderer renderer = {};

@@ -151,6 +146,7 @@ applyArguments(&args, &subparser, &renderer.core->config);

mCoreConfigLoadDefaults(&renderer.core->config, &opts); + // TODO: Load from config renderer.viewportWidth = opts.width; renderer.viewportHeight = opts.height; #if SDL_VERSION_ATLEAST(2, 0, 0)

@@ -159,6 +155,7 @@ renderer.player.windowUpdated = 0;

#else renderer.fullscreen = opts.fullscreen; #endif + renderer.ratio = graphicsOpts.multiplier; if (renderer.ratio == 0) { renderer.ratio = 1;

@@ -203,76 +200,25 @@

return ret; } -#ifdef M_CORE_GBA -int mSDLRunGBA(struct mSDLRenderer* renderer, struct mArguments* args, struct mCoreOptions* opts, struct mCoreConfig* config) { - struct GBAThread context = { - .userData = renderer - }; - - context.debugger = createDebugger(args, &context); - - GBAMapOptionsToContext(opts, &context); - GBAMapArgumentsToContext(args, &context); - context.overrides = mCoreConfigGetOverrides(config); - - bool didFail = false; - - renderer->audio.samples = context.audioBuffers; - renderer->audio.sampleRate = 44100; - if (opts->sampleRate) { - renderer->audio.sampleRate = opts->sampleRate; - } - if (!mSDLInitAudio(&renderer->audio, &context)) { - didFail = true; - } - - if (!didFail) { -#if SDL_VERSION_ATLEAST(2, 0, 0) - mSDLSetScreensaverSuspendable(&renderer->events, opts->suspendScreensaver); - mSDLSuspendScreensaver(&renderer->events); -#endif - if (GBAThreadStart(&context)) { - renderer->runloop(renderer, &context); - GBAThreadJoin(&context); - } else { - didFail = true; - printf("Could not run game. Are you sure the file exists and is a Game Boy Advance game?\n"); - } - -#if SDL_VERSION_ATLEAST(2, 0, 0) - mSDLResumeScreensaver(&renderer->events); - mSDLSetScreensaverSuspendable(&renderer->events, false); -#endif - - if (GBAThreadHasCrashed(&context)) { - didFail = true; - printf("The game crashed!\n"); - } - } - free(context.debugger); - mDirectorySetDeinit(&context.dirs); - - return didFail; -} -#endif - int mSDLRun(struct mSDLRenderer* renderer, struct mArguments* args) { struct mCoreThread thread = { - .core = renderer->core, - .sync = { - .audioWait = true - } + .core = renderer->core }; if (!mCoreLoadFile(renderer->core, args->fname)) { return 1; } mCoreAutoloadSave(renderer->core); + // TODO: Create debugger - renderer->audio.samples = 1024; + renderer->audio.samples = renderer->core->opts.audioBuffers; renderer->audio.sampleRate = 44100; bool didFail = !mSDLInitAudio(&renderer->audio, 0); if (!didFail) { +#if SDL_VERSION_ATLEAST(2, 0, 0) + mSDLSetScreensaverSuspendable(&renderer->events, renderer->core->opts.suspendScreensaver); + mSDLSuspendScreensaver(&renderer->events); +#endif renderer->audio.core = renderer->core; renderer->audio.sync = &thread.sync;

@@ -284,6 +230,11 @@ } else {

didFail = true; printf("Could not run game. Are you sure the file exists and is a compatible game?\n"); } + +#if SDL_VERSION_ATLEAST(2, 0, 0) + mSDLResumeScreensaver(&renderer->events); + mSDLSetScreensaverSuspendable(&renderer->events, false); +#endif if (mCoreThreadHasCrashed(&thread)) { didFail = true;