2014-11-01 10:04:10 +00:00
|
|
|
#include "gba-config.h"
|
|
|
|
|
|
|
|
#include "platform/commandline.h"
|
|
|
|
|
|
|
|
#define SECTION_NAME_MAX 128
|
|
|
|
|
2014-11-05 07:54:09 +00:00
|
|
|
static const char* _lookupValue(const struct GBAConfig* config, const char* key) {
|
|
|
|
const char* value;
|
|
|
|
if (config->port) {
|
|
|
|
value = ConfigurationGetValue(&config->configTable, config->port, key);
|
2014-11-01 10:04:10 +00:00
|
|
|
if (value) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
2014-11-05 07:54:09 +00:00
|
|
|
value = ConfigurationGetValue(&config->configTable, 0, key);
|
|
|
|
if (value) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
if (config->port) {
|
|
|
|
value = ConfigurationGetValue(&config->defaultsTable, config->port, key);
|
|
|
|
if (value) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ConfigurationGetValue(&config->defaultsTable, 0, key);
|
2014-11-01 10:04:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-05 07:54:09 +00:00
|
|
|
static bool _lookupCharValue(const struct GBAConfig* config, const char* key, char** out) {
|
|
|
|
const char* value = _lookupValue(config, key);
|
2014-11-02 08:31:12 +00:00
|
|
|
if (!value) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-11-05 07:54:09 +00:00
|
|
|
if (*out) {
|
|
|
|
free(*out);
|
|
|
|
}
|
2014-11-02 08:31:12 +00:00
|
|
|
*out = strdup(value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-05 07:54:09 +00:00
|
|
|
static bool _lookupIntValue(const struct GBAConfig* config, const char* key, int* out) {
|
|
|
|
const char* charValue = _lookupValue(config, key);
|
2014-11-01 10:04:10 +00:00
|
|
|
if (!charValue) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
char* end;
|
|
|
|
long value = strtol(charValue, &end, 10);
|
|
|
|
if (*end) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*out = value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-05 07:54:09 +00:00
|
|
|
static bool _lookupUIntValue(const struct GBAConfig* config, const char* key, unsigned* out) {
|
|
|
|
const char* charValue = _lookupValue(config, key);
|
2014-11-02 10:34:16 +00:00
|
|
|
if (!charValue) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
char* end;
|
|
|
|
unsigned long value = strtoul(charValue, &end, 10);
|
|
|
|
if (*end) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*out = value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-05 07:54:09 +00:00
|
|
|
static bool _lookupFloatValue(const struct GBAConfig* config, const char* key, float* out) {
|
|
|
|
const char* charValue = _lookupValue(config, key);
|
2014-11-02 10:34:16 +00:00
|
|
|
if (!charValue) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
char* end;
|
|
|
|
float value = strtof(charValue, &end);
|
|
|
|
if (*end) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*out = value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-05 07:54:09 +00:00
|
|
|
void GBAConfigInit(struct GBAConfig* config, const char* port) {
|
|
|
|
ConfigurationInit(&config->configTable);
|
|
|
|
ConfigurationInit(&config->defaultsTable);
|
|
|
|
config->port = malloc(strlen("ports.") + strlen(port) + 1);
|
|
|
|
sprintf(config->port, "ports.%s", port);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GBAConfigDeinit(struct GBAConfig* config) {
|
|
|
|
ConfigurationDeinit(&config->configTable);
|
|
|
|
ConfigurationDeinit(&config->defaultsTable);
|
|
|
|
free(config->port);
|
2014-11-01 10:04:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-05 07:54:09 +00:00
|
|
|
bool GBAConfigLoad(struct GBAConfig* config) {
|
|
|
|
return ConfigurationRead(&config->configTable, BINARY_NAME ".ini");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GBAConfigSave(const struct GBAConfig* config) {
|
|
|
|
return ConfigurationWrite(&config->configTable, BINARY_NAME ".ini");
|
|
|
|
}
|
|
|
|
|
|
|
|
void GBAConfigSetValue(struct GBAConfig* config, const char* key, const char* value) {
|
|
|
|
ConfigurationSetValue(&config->configTable, config->port, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GBAConfigSetIntValue(struct GBAConfig* config, const char* key, int value) {
|
|
|
|
ConfigurationSetIntValue(&config->configTable, config->port, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GBAConfigSetUIntValue(struct GBAConfig* config, const char* key, unsigned value) {
|
|
|
|
ConfigurationSetUIntValue(&config->configTable, config->port, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GBAConfigSetFloatValue(struct GBAConfig* config, const char* key, float value) {
|
|
|
|
ConfigurationSetFloatValue(&config->configTable, config->port, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GBAConfigSetDefaultValue(struct GBAConfig* config, const char* key, const char* value) {
|
|
|
|
ConfigurationSetValue(&config->defaultsTable, config->port, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GBAConfigSetDefaultIntValue(struct GBAConfig* config, const char* key, int value) {
|
|
|
|
ConfigurationSetIntValue(&config->defaultsTable, config->port, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GBAConfigSetDefaultUIntValue(struct GBAConfig* config, const char* key, unsigned value) {
|
|
|
|
ConfigurationSetUIntValue(&config->defaultsTable, config->port, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GBAConfigSetDefaultFloatValue(struct GBAConfig* config, const char* key, float value) {
|
|
|
|
ConfigurationSetFloatValue(&config->defaultsTable, config->port, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GBAConfigMap(const struct GBAConfig* config, struct GBAOptions* opts) {
|
|
|
|
_lookupCharValue(config, "bios", &opts->bios);
|
|
|
|
_lookupIntValue(config, "logLevel", &opts->logLevel);
|
|
|
|
_lookupIntValue(config, "frameskip", &opts->frameskip);
|
|
|
|
_lookupIntValue(config, "rewindBufferCapacity", &opts->rewindBufferCapacity);
|
|
|
|
_lookupIntValue(config, "rewindBufferInterval", &opts->rewindBufferInterval);
|
|
|
|
_lookupFloatValue(config, "fpsTarget", &opts->fpsTarget);
|
2014-11-02 10:34:16 +00:00
|
|
|
unsigned audioBuffers;
|
2014-11-05 07:54:09 +00:00
|
|
|
if (_lookupUIntValue(config, "audioBuffers", &audioBuffers)) {
|
2014-11-02 10:34:16 +00:00
|
|
|
opts->audioBuffers = audioBuffers;
|
|
|
|
}
|
2014-11-04 09:19:10 +00:00
|
|
|
|
|
|
|
int fakeBool;
|
2014-11-05 07:54:09 +00:00
|
|
|
if (_lookupIntValue(config, "audioSync", &fakeBool)) {
|
2014-11-04 09:19:10 +00:00
|
|
|
opts->audioSync = fakeBool;
|
|
|
|
}
|
2014-11-05 07:54:09 +00:00
|
|
|
if (_lookupIntValue(config, "videoSync", &fakeBool)) {
|
2014-11-04 09:19:10 +00:00
|
|
|
opts->videoSync = fakeBool;
|
|
|
|
}
|
2014-11-05 07:54:09 +00:00
|
|
|
|
|
|
|
_lookupIntValue(config, "fullscreen", &opts->fullscreen);
|
|
|
|
_lookupIntValue(config, "width", &opts->width);
|
|
|
|
_lookupIntValue(config, "height", &opts->height);
|
2014-11-01 10:04:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-05 07:54:09 +00:00
|
|
|
void GBAConfigLoadDefaults(struct GBAConfig* config, const struct GBAOptions* opts) {
|
|
|
|
ConfigurationSetValue(&config->defaultsTable, 0, "bios", opts->bios);
|
|
|
|
ConfigurationSetIntValue(&config->defaultsTable, 0, "logLevel", opts->logLevel);
|
|
|
|
ConfigurationSetIntValue(&config->defaultsTable, 0, "frameskip", opts->frameskip);
|
|
|
|
ConfigurationSetIntValue(&config->defaultsTable, 0, "rewindBufferCapacity", opts->rewindBufferCapacity);
|
|
|
|
ConfigurationSetIntValue(&config->defaultsTable, 0, "rewindBufferInterval", opts->rewindBufferInterval);
|
|
|
|
ConfigurationSetFloatValue(&config->defaultsTable, 0, "fpsTarget", opts->fpsTarget);
|
|
|
|
ConfigurationSetUIntValue(&config->defaultsTable, 0, "audioBuffers", opts->audioBuffers);
|
|
|
|
ConfigurationSetIntValue(&config->defaultsTable, 0, "audioSync", opts->audioSync);
|
|
|
|
ConfigurationSetIntValue(&config->defaultsTable, 0, "videoSync", opts->videoSync);
|
|
|
|
ConfigurationSetIntValue(&config->defaultsTable, 0, "fullscreen", opts->fullscreen);
|
|
|
|
ConfigurationSetIntValue(&config->defaultsTable, 0, "width", opts->width);
|
|
|
|
ConfigurationSetIntValue(&config->defaultsTable, 0, "height", opts->height);
|
2014-11-01 10:04:10 +00:00
|
|
|
}
|
2014-11-02 09:49:15 +00:00
|
|
|
|
|
|
|
void GBAConfigFreeOpts(struct GBAOptions* opts) {
|
|
|
|
free(opts->bios);
|
|
|
|
opts->bios = 0;
|
|
|
|
}
|