mgba/src/gba/gba-config.c

66 lines
2.0 KiB
C
Raw Normal View History

2014-11-01 10:04:10 +00:00
#include "gba-config.h"
#include "platform/commandline.h"
#include "util/configuration.h"
#define SECTION_NAME_MAX 128
static const char* _lookupValue(const struct Configuration* config, const char* key, const char* port) {
if (port) {
char sectionName[SECTION_NAME_MAX];
snprintf(sectionName, SECTION_NAME_MAX, "ports.%s", port);
sectionName[SECTION_NAME_MAX - 1] = '\0';
const char* value = ConfigurationGetValue(config, sectionName, key);
if (value) {
return value;
}
}
return ConfigurationGetValue(config, 0, key);
}
static bool _lookupCharValue(const struct Configuration* config, const char* key, const char* port, char** out) {
const char* value = _lookupValue(config, key, port);
if (!value) {
return false;
}
*out = strdup(value);
return true;
}
2014-11-01 10:04:10 +00:00
static bool _lookupIntValue(const struct Configuration* config, const char* key, const char* port, int* out) {
const char* charValue = _lookupValue(config, key, port);
if (!charValue) {
return false;
}
char* end;
long value = strtol(charValue, &end, 10);
if (*end) {
return false;
}
*out = value;
return true;
}
bool GBAConfigLoad(struct Configuration* config) {
return ConfigurationRead(config, BINARY_NAME ".ini");
}
void GBAConfigMapGeneralOpts(const struct Configuration* config, const char* port, struct GBAOptions* opts) {
_lookupCharValue(config, "bios", port, &opts->bios);
2014-11-01 10:04:10 +00:00
_lookupIntValue(config, "logLevel", port, &opts->logLevel);
_lookupIntValue(config, "frameskip", port, &opts->frameskip);
_lookupIntValue(config, "rewindBufferCapacity", port, &opts->rewindBufferCapacity);
_lookupIntValue(config, "rewindBufferInterval", port, &opts->rewindBufferInterval);
}
void GBAConfigMapGraphicsOpts(const struct Configuration* config, const char* port, struct GBAOptions* opts) {
2014-11-01 10:04:10 +00:00
_lookupIntValue(config, "fullscreen", port, &opts->fullscreen);
_lookupIntValue(config, "width", port, &opts->width);
_lookupIntValue(config, "height", port, &opts->height);
}
void GBAConfigFreeOpts(struct GBAOptions* opts) {
free(opts->bios);
opts->bios = 0;
}