src/gba/gba-config.c (view raw)
1#include "gba-config.h"
2
3#include "platform/commandline.h"
4#include "util/configuration.h"
5
6#define SECTION_NAME_MAX 128
7
8static const char* _lookupValue(const struct Configuration* config, const char* key, const char* port) {
9 if (port) {
10 char sectionName[SECTION_NAME_MAX];
11 snprintf(sectionName, SECTION_NAME_MAX, "ports.%s", port);
12 sectionName[SECTION_NAME_MAX - 1] = '\0';
13 const char* value = ConfigurationGetValue(config, sectionName, key);
14 if (value) {
15 return value;
16 }
17 }
18 return ConfigurationGetValue(config, 0, key);
19}
20
21static bool _lookupIntValue(const struct Configuration* config, const char* key, const char* port, int* out) {
22 const char* charValue = _lookupValue(config, key, port);
23 if (!charValue) {
24 return false;
25 }
26 char* end;
27 long value = strtol(charValue, &end, 10);
28 if (*end) {
29 return false;
30 }
31 *out = value;
32 return true;
33}
34
35bool GBAConfigLoad(struct Configuration* config) {
36 return ConfigurationRead(config, BINARY_NAME ".ini");
37}
38
39void GBAConfigMapStartupOpts(const struct Configuration* config, const char* port, struct StartupOptions* opts) {
40 _lookupIntValue(config, "logLevel", port, &opts->logLevel);
41 _lookupIntValue(config, "frameskip", port, &opts->frameskip);
42 _lookupIntValue(config, "rewindBufferCapacity", port, &opts->rewindBufferCapacity);
43 _lookupIntValue(config, "rewindBufferInterval", port, &opts->rewindBufferInterval);
44}
45
46void GBAConfigMapGraphicsOpts(const struct Configuration* config, const char* port, struct GraphicsOpts* opts) {
47 _lookupIntValue(config, "fullscreen", port, &opts->fullscreen);
48 _lookupIntValue(config, "width", port, &opts->width);
49 _lookupIntValue(config, "height", port, &opts->height);
50}