all repos — mgba @ 6afa678a41545ab0ab4255e10fe25cb56dbbcd37

mGBA Game Boy Advance Emulator

GBA Config: Further separate arguments from options, renaming things in the process
Jeffrey Pfau jeffrey@endrift.com
Sun, 02 Nov 2014 02:19:57 -0800
commit

6afa678a41545ab0ab4255e10fe25cb56dbbcd37

parent

f36a74759a291b63520eaabf853025ffbd221c80

M src/gba/gba-thread.csrc/gba/gba-thread.c

@@ -2,6 +2,7 @@ #include "gba-thread.h"

#include "arm.h" #include "gba.h" +#include "gba-config.h" #include "gba-serialize.h" #include "debugger/debugger.h"

@@ -9,6 +10,8 @@

#include "util/patch.h" #include "util/png-io.h" #include "util/vfs.h" + +#include "platform/commandline.h" #include <signal.h>

@@ -225,18 +228,18 @@ threadContext->rewindBufferCapacity = opts->rewindBufferCapacity;

threadContext->rewindBufferInterval = opts->rewindBufferInterval; } -void GBAMapStartupOptionsToContext(struct StartupOptions* opts, struct GBAThread* threadContext) { - if (opts->dirmode) { - threadContext->gameDir = VDirOpen(opts->fname); +void GBAMapArgumentsToContext(struct GBAArguments* args, struct GBAThread* threadContext) { + if (args->dirmode) { + threadContext->gameDir = VDirOpen(args->fname); threadContext->stateDir = threadContext->gameDir; } else { - threadContext->rom = VFileOpen(opts->fname, O_RDONLY); + threadContext->rom = VFileOpen(args->fname, O_RDONLY); #if ENABLE_LIBZIP - threadContext->gameDir = VDirOpenZip(opts->fname, 0); + threadContext->gameDir = VDirOpenZip(args->fname, 0); #endif } - threadContext->fname = opts->fname; - threadContext->patch = VFileOpen(opts->patch, O_RDONLY); + threadContext->fname = args->fname; + threadContext->patch = VFileOpen(args->patch, O_RDONLY); } bool GBAThreadStart(struct GBAThread* threadContext) {
M src/gba/gba-thread.hsrc/gba/gba-thread.h

@@ -7,9 +7,10 @@ #include "gba.h"

#include "gba-input.h" #include "util/threading.h" -#include "platform/commandline.h" struct GBAThread; +struct GBAArguments; +struct GBAOptions; typedef void (*ThreadCallback)(struct GBAThread* threadContext); typedef void (*LogHandler)(struct GBAThread*, enum GBALogLevel, const char* format, va_list args);

@@ -95,7 +96,7 @@ int rewindBufferWriteOffset;

}; void GBAMapOptionsToContext(struct GBAOptions*, struct GBAThread*); -void GBAMapStartupOptionsToContext(struct StartupOptions*, struct GBAThread*); +void GBAMapArgumentsToContext(struct GBAArguments*, struct GBAThread*); bool GBAThreadStart(struct GBAThread* threadContext); bool GBAThreadHasStarted(struct GBAThread* threadContext);
M src/platform/commandline.csrc/platform/commandline.c

@@ -40,7 +40,7 @@ };

bool _parseGraphicsArg(struct SubParser* parser, struct GBAOptions* gbaOpts, int option, const char* arg); -bool parseCommandArgs(struct StartupOptions* opts, struct GBAOptions* gbaOpts, int argc, char* const* argv, struct SubParser* subparser) { +bool parseArguments(struct GBAArguments* opts, struct GBAOptions* gbaOpts, int argc, char* const* argv, struct SubParser* subparser) { int ch; char options[64] = "b:Dl:p:s:"

@@ -109,7 +109,7 @@ opts->fname = strdup(argv[0]);

return true; } -void freeOptions(struct StartupOptions* opts) { +void freeArguments(struct GBAArguments* opts) { free(opts->fname); opts->fname = 0;

@@ -148,7 +148,7 @@ return false;

} } -struct ARMDebugger* createDebugger(struct StartupOptions* opts) { +struct ARMDebugger* createDebugger(struct GBAArguments* opts) { union DebugUnion { struct ARMDebugger d; #ifdef USE_CLI_DEBUGGER
M src/platform/commandline.hsrc/platform/commandline.h

@@ -16,7 +16,7 @@ #endif

DEBUGGER_MAX }; -struct StartupOptions { +struct GBAArguments { char* fname; char* patch; bool dirmode;

@@ -36,12 +36,12 @@ struct GraphicsOpts {

int multiplier; }; -bool parseCommandArgs(struct StartupOptions* opts, struct GBAOptions* gbaOpts, int argc, char* const* argv, struct SubParser* subparser); -void freeOptions(struct StartupOptions* opts); +bool parseArguments(struct GBAArguments* opts, struct GBAOptions* gbaOpts, int argc, char* const* argv, struct SubParser* subparser); +void freeArguments(struct GBAArguments* opts); void usage(const char* arg0, const char* extraOptions); void initParserForGraphics(struct SubParser* parser, struct GraphicsOpts* opts); -struct ARMDebugger* createDebugger(struct StartupOptions* opts); +struct ARMDebugger* createDebugger(struct GBAArguments* opts); #endif
M src/platform/perf-main.csrc/platform/perf-main.c

@@ -1,6 +1,9 @@

#include "gba-thread.h" +#include "gba-config.h" #include "gba.h" #include "renderers/video-software.h" + +#include "platform/commandline.h" #include <errno.h> #include <fcntl.h>

@@ -43,9 +46,9 @@ .extraOptions = PERF_OPTIONS,

.opts = &perfOpts }; - struct GBAOptions gbaOpts = {}; - struct StartupOptions opts = {}; - if (!parseCommandArgs(&opts, &gbaOpts, argc, argv, &subparser)) { + struct GBAOptions opts = {}; + struct GBAArguments args = {}; + if (!parseArguments(&args, &opts, argc, argv, &subparser)) { usage(argv[0], PERF_USAGE); return 1; }

@@ -63,11 +66,11 @@ if (!perfOpts.noVideo) {

context.renderer = &renderer.d; } - context.debugger = createDebugger(&opts); + context.debugger = createDebugger(&args); char gameCode[5] = { 0 }; - GBAMapStartupOptionsToContext(&opts, &context); - GBAMapOptionsToContext(&gbaOpts, &context); + GBAMapArgumentsToContext(&args, &context); + GBAMapOptionsToContext(&opts, &context); GBAThreadStart(&context); GBAGetGameCode(context.gba, gameCode);

@@ -85,7 +88,8 @@ uint64_t end = 1000000LL * tv.tv_sec + tv.tv_usec;

uint64_t duration = end - start; GBAThreadJoin(&context); - freeOptions(&opts); + GBAConfigFreeOpts(&opts); + freeArguments(&args); free(context.debugger); free(renderer.outputBuffer);
M src/platform/qt/GBAApp.cppsrc/platform/qt/GBAApp.cpp

@@ -12,18 +12,19 @@ {

QApplication::setApplicationName(PROJECT_NAME); QApplication::setApplicationVersion(PROJECT_VERSION); - if (parseCommandArgs(&m_opts, &m_gbaOpts, argc, argv, 0)) { - m_window.setOptions(&m_gbaOpts); - m_window.optionsPassed(&m_opts); + if (parseArguments(&m_args, &m_opts, argc, argv, 0)) { + m_window.setOptions(&m_opts); + m_window.argumentsPassed(&m_args); } else { - m_window.setOptions(&m_gbaOpts); + m_window.setOptions(&m_opts); } m_window.show(); } GBAApp::~GBAApp() { - freeOptions(&m_opts); + freeArguments(&m_args); + GBAConfigFreeOpts(&m_opts); } bool GBAApp::event(QEvent* event) {
M src/platform/qt/GBAApp.hsrc/platform/qt/GBAApp.h

@@ -27,8 +27,8 @@

private: Window m_window; - StartupOptions m_opts; - GBAOptions m_gbaOpts; + GBAArguments m_args; + GBAOptions m_opts; Configuration m_config; };
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -101,13 +101,13 @@ return GBA_KEY_NONE;

} } -void Window::optionsPassed(StartupOptions* opts) { - if (opts->patch) { - m_controller->loadPatch(opts->patch); +void Window::argumentsPassed(GBAArguments* args) { + if (args->patch) { + m_controller->loadPatch(args->patch); } - if (opts->fname) { - m_controller->loadGame(opts->fname, opts->dirmode); + if (args->fname) { + m_controller->loadGame(args->fname, args->dirmode); } }
M src/platform/qt/Window.hsrc/platform/qt/Window.h

@@ -13,7 +13,7 @@ #include "Display.h"

#include "LoadSaveState.h" struct GBAOptions; -struct StartupOptions; +struct GBAArguments; namespace QGBA {

@@ -34,7 +34,7 @@

static GBAKey mapKey(int qtKey); void setOptions(GBAOptions*); - void optionsPassed(StartupOptions*); + void argumentsPassed(GBAArguments*); signals: void startDrawing(const uint32_t*, GBAThread*);
M src/platform/sdl/gl-main.csrc/platform/sdl/gl-main.c

@@ -69,31 +69,33 @@ struct Configuration config;

ConfigurationInit(&config); GBAConfigLoad(&config); - struct GBAOptions gbaOpts = {}; - struct StartupOptions opts = {}; + struct GBAOptions opts = {}; + struct GBAArguments args = {}; struct GraphicsOpts graphicsOpts = {}; struct SubParser subparser; - GBAConfigMapGeneralOpts(&config, PORT, &gbaOpts); - GBAConfigMapGraphicsOpts(&config, PORT, &gbaOpts); + GBAConfigMapGeneralOpts(&config, PORT, &opts); + GBAConfigMapGraphicsOpts(&config, PORT, &opts); initParserForGraphics(&subparser, &graphicsOpts); - if (!parseCommandArgs(&opts, &gbaOpts, argc, argv, &subparser)) { + if (!parseArguments(&args, &opts, argc, argv, &subparser)) { usage(argv[0], subparser.usage); - freeOptions(&opts); + freeArguments(&args); + GBAConfigFreeOpts(&opts); return 1; } - renderer.viewportWidth = gbaOpts.width; - renderer.viewportHeight = gbaOpts.height; + renderer.viewportWidth = opts.width; + renderer.viewportHeight = opts.height; #if SDL_VERSION_ATLEAST(2, 0, 0) - renderer.events.fullscreen = gbaOpts.fullscreen; + renderer.events.fullscreen = opts.fullscreen; renderer.events.windowUpdated = 0; #endif if (!_GBASDLInit(&renderer)) { - freeOptions(&opts); + freeArguments(&args); + GBAConfigFreeOpts(&opts); return 1; }

@@ -107,10 +109,10 @@ .sync.audioWait = true,

.userData = &renderer }; - context.debugger = createDebugger(&opts); + context.debugger = createDebugger(&args); - GBAMapOptionsToContext(&gbaOpts, &context); - GBAMapStartupOptionsToContext(&opts, &context); + GBAMapOptionsToContext(&opts, &context); + GBAMapArgumentsToContext(&args, &context); renderer.audio.samples = context.audioBuffers; GBASDLInitAudio(&renderer.audio);

@@ -123,7 +125,8 @@

_GBASDLRunloop(&context, &renderer); GBAThreadJoin(&context); - freeOptions(&opts); + freeArguments(&args); + GBAConfigFreeOpts(&opts); free(context.debugger); _GBASDLDeinit(&renderer);