GBA Config: Add "override" layer for better one-time configuration
Jeffrey Pfau jeffrey@endrift.com
Tue, 06 Oct 2015 21:27:25 -0700
4 files changed,
41 insertions(+),
6 deletions(-)
M
CHANGES
→
CHANGES
@@ -38,6 +38,7 @@ - GBA BIOS: Implement RegisterRamReset for SIO registers
- 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:
M
src/gba/context/config.c
→
src/gba/context/config.c
@@ -31,6 +31,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) { return value;@@ -106,6 +116,7 @@
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 GBAConfigDeinit(struct GBAConfig* config) { ConfigurationDeinit(&config->configTable); ConfigurationDeinit(&config->defaultsTable); + ConfigurationDeinit(&config->overridesTable); free(config->port); }@@ -266,6 +278,22 @@ }
void GBAConfigSetDefaultFloatValue(struct GBAConfig* config, const char* key, float value) { 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) {
M
src/gba/context/config.h
→
src/gba/context/config.h
@@ -15,6 +15,7 @@
struct GBAConfig { struct Configuration configTable; struct Configuration defaultsTable; + struct Configuration overridesTable; char* port; };@@ -72,6 +73,11 @@ void GBAConfigSetDefaultValue(struct GBAConfig*, const char* key, const char* value);
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);
M
src/platform/commandline.c
→
src/platform/commandline.c
@@ -71,7 +71,7 @@ }
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 @@ case 'h':
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 @@ struct GraphicsOpts* graphicsOpts = parser->opts;
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 @@ if (graphicsOpts->multiplier) {
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;