From 3f36f3d88eff2f62c1e571943f6cb698207788c4 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Tue, 6 Oct 2015 21:27:25 -0700 Subject: [PATCH] GBA Config: Add "override" layer for better one-time configuration --- CHANGES | 1 + src/gba/context/config.c | 28 ++++++++++++++++++++++++++++ src/gba/context/config.h | 6 ++++++ src/platform/commandline.c | 12 ++++++------ 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index f18dffa86..46d2cac48 100644 --- a/CHANGES +++ b/CHANGES @@ -38,6 +38,7 @@ Misc: - All: Reset next event to cycles instead of zero to interrupt - GBA Video: Remove lastHblank, as it is implied - GBA: Check for cycle count being too high + - GBA Config: Add "override" layer for better one-time configuration` 0.3.0: (2015-08-16) Features: diff --git a/src/gba/context/config.c b/src/gba/context/config.c index f7f6956fc..ee4eccb09 100644 --- a/src/gba/context/config.c +++ b/src/gba/context/config.c @@ -30,6 +30,16 @@ static const char* _lookupValue(const struct GBAConfig* config, const char* key) { const char* value; + if (config->port) { + value = ConfigurationGetValue(&config->overridesTable, config->port, key); + if (value) { + return value; + } + } + value = ConfigurationGetValue(&config->overridesTable, 0, key); + if (value) { + return value; + } if (config->port) { value = ConfigurationGetValue(&config->configTable, config->port, key); if (value) { @@ -106,6 +116,7 @@ static bool _lookupFloatValue(const struct GBAConfig* config, const char* key, f void GBAConfigInit(struct GBAConfig* config, const char* port) { ConfigurationInit(&config->configTable); ConfigurationInit(&config->defaultsTable); + ConfigurationInit(&config->overridesTable); if (port) { config->port = malloc(strlen("ports.") + strlen(port) + 1); snprintf(config->port, strlen("ports.") + strlen(port) + 1, "ports.%s", port); @@ -117,6 +128,7 @@ void GBAConfigInit(struct GBAConfig* config, const char* port) { void GBAConfigDeinit(struct GBAConfig* config) { ConfigurationDeinit(&config->configTable); ConfigurationDeinit(&config->defaultsTable); + ConfigurationDeinit(&config->overridesTable); free(config->port); } @@ -268,6 +280,22 @@ void GBAConfigSetDefaultFloatValue(struct GBAConfig* config, const char* key, fl ConfigurationSetFloatValue(&config->defaultsTable, config->port, key, value); } +void GBAConfigSetOverrideValue(struct GBAConfig* config, const char* key, const char* value) { + ConfigurationSetValue(&config->overridesTable, config->port, key, value); +} + +void GBAConfigSetOverrideIntValue(struct GBAConfig* config, const char* key, int value) { + ConfigurationSetIntValue(&config->overridesTable, config->port, key, value); +} + +void GBAConfigSetOverrideUIntValue(struct GBAConfig* config, const char* key, unsigned value) { + ConfigurationSetUIntValue(&config->overridesTable, config->port, key, value); +} + +void GBAConfigSetOverrideFloatValue(struct GBAConfig* config, const char* key, float value) { + ConfigurationSetFloatValue(&config->overridesTable, config->port, key, value); +} + void GBAConfigMap(const struct GBAConfig* config, struct GBAOptions* opts) { _lookupCharValue(config, "bios", &opts->bios); _lookupIntValue(config, "logLevel", &opts->logLevel); diff --git a/src/gba/context/config.h b/src/gba/context/config.h index 8d4039d92..659a02fa2 100644 --- a/src/gba/context/config.h +++ b/src/gba/context/config.h @@ -15,6 +15,7 @@ struct GBAConfig { struct Configuration configTable; struct Configuration defaultsTable; + struct Configuration overridesTable; char* port; }; @@ -73,6 +74,11 @@ void GBAConfigSetDefaultIntValue(struct GBAConfig*, const char* key, int value); void GBAConfigSetDefaultUIntValue(struct GBAConfig*, const char* key, unsigned value); void GBAConfigSetDefaultFloatValue(struct GBAConfig*, const char* key, float value); +void GBAConfigSetOverrideValue(struct GBAConfig*, const char* key, const char* value); +void GBAConfigSetOverrideIntValue(struct GBAConfig*, const char* key, int value); +void GBAConfigSetOverrideUIntValue(struct GBAConfig*, const char* key, unsigned value); +void GBAConfigSetOverrideFloatValue(struct GBAConfig*, const char* key, float value); + void GBAConfigMap(const struct GBAConfig* config, struct GBAOptions* opts); void GBAConfigLoadDefaults(struct GBAConfig* config, const struct GBAOptions* opts); diff --git a/src/platform/commandline.c b/src/platform/commandline.c index e4142fffd..1a62c222c 100644 --- a/src/platform/commandline.c +++ b/src/platform/commandline.c @@ -71,7 +71,7 @@ bool parseArguments(struct GBAArguments* opts, struct GBAConfig* config, int arg while ((ch = getopt_long(argc, argv, options, _options, 0)) != -1) { switch (ch) { case 'b': - GBAConfigSetDefaultValue(config, "bios", optarg); + GBAConfigSetOverrideValue(config, "bios", optarg); break; case 'c': opts->cheatsFile = strdup(optarg); @@ -99,13 +99,13 @@ bool parseArguments(struct GBAArguments* opts, struct GBAConfig* config, int arg opts->showHelp = true; break; case 'l': - GBAConfigSetDefaultValue(config, "logLevel", optarg); + GBAConfigSetOverrideValue(config, "logLevel", optarg); break; case 'p': opts->patch = strdup(optarg); break; case 's': - GBAConfigSetDefaultValue(config, "frameskip", optarg); + GBAConfigSetOverrideValue(config, "frameskip", optarg); break; case 'v': opts->movie = strdup(optarg); @@ -154,7 +154,7 @@ bool _parseGraphicsArg(struct SubParser* parser, struct GBAConfig* config, int o switch (option) { case 'f': graphicsOpts->fullscreen = true; - GBAConfigSetDefaultIntValue(config, "fullscreen", 1); + GBAConfigSetOverrideIntValue(config, "fullscreen", 1); return true; case '1': case '2': @@ -166,8 +166,8 @@ bool _parseGraphicsArg(struct SubParser* parser, struct GBAConfig* config, int o return false; } graphicsOpts->multiplier = option - '0'; - GBAConfigSetDefaultIntValue(config, "width", VIDEO_HORIZONTAL_PIXELS * graphicsOpts->multiplier); - GBAConfigSetDefaultIntValue(config, "height", VIDEO_VERTICAL_PIXELS * graphicsOpts->multiplier); + GBAConfigSetOverrideIntValue(config, "width", VIDEO_HORIZONTAL_PIXELS * graphicsOpts->multiplier); + GBAConfigSetOverrideIntValue(config, "height", VIDEO_VERTICAL_PIXELS * graphicsOpts->multiplier); return true; default: return false;