annotate config.c @ 2493:b62336ceb626 default tip

Kinda hacky fix to make sure Nuklear has the right GL context
author Michael Pavone <pavone@retrodev.com>
date Wed, 17 Apr 2024 22:18:45 -0700
parents 2972a8e16ed2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
467
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
1 /*
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
2 Copyright 2013 Michael Pavone
495
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
3 This file is part of BlastEm.
467
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 431
diff changeset
5 */
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
6 #include "tern.h"
495
39cad98d2789 Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
7 #include "util.h"
1489
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
8 #include "paths.h"
1901
5433252329fb Set version reg and TAS behavior based on model config
Michael Pavone <pavone@retrodev.com>
parents: 1900
diff changeset
9 #include "config.h"
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
10 #include <stdio.h>
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
11 #include <stdlib.h>
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
12 #include <string.h>
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
13
795
bce97fc0bb8a Fix mingw-w64 build and cross-compilation
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
14 #ifdef __MINGW64_VERSION_MAJOR
bce97fc0bb8a Fix mingw-w64 build and cross-compilation
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
15 #define MINGW_W64_VERSION (__MINGW64_VERSION_MAJOR * 1000 + __MINGW64_VERSION_MINOR)
bce97fc0bb8a Fix mingw-w64 build and cross-compilation
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
16 #else
bce97fc0bb8a Fix mingw-w64 build and cross-compilation
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
17 #define MINGW_W64_VERSION 0
bce97fc0bb8a Fix mingw-w64 build and cross-compilation
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
18 #endif
bce97fc0bb8a Fix mingw-w64 build and cross-compilation
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
19
bce97fc0bb8a Fix mingw-w64 build and cross-compilation
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
20 #if defined(_WIN32) && (MINGW_W64_VERSION < 3003)
741
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
21 char * strtok_r(char * input, char * sep, char ** state)
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
22 {
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
23 if (input) {
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
24 *state = input;
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
25 }
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
26 char * ret = *state;
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
27 while (**state && **state != *sep)
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
28 {
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
29 ++*state;
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
30 }
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
31 if (**state)
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
32 {
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
33 **state = 0;
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
34 ++*state;
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
35 return ret;
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
36 }
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
37 return NULL;
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
38 }
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
39 #endif
80a67be1770b Initial work on Windows port
Michael Pavone <pavone@retrodev.com>
parents: 496
diff changeset
40
1489
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
41 static tern_node * parse_config_int(char **state, int started, int *line)
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
42 {
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
43 char *config_data, *curline;
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
44 tern_node * head = NULL;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
45 config_data = started ? NULL : *state;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
46 while ((curline = strtok_r(config_data, "\n", state)))
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
47 {
866
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 859
diff changeset
48
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
49 config_data = NULL;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
50 curline = strip_ws(curline);
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
51 int len = strlen(curline);
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
52 if (!len) {
1783
eda8df5bc74c Minor cleanup
Michael Pavone <pavone@retrodev.com>
parents: 1693
diff changeset
53 (*line)++;
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
54 continue;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
55 }
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
56 if (curline[0] == '#') {
1783
eda8df5bc74c Minor cleanup
Michael Pavone <pavone@retrodev.com>
parents: 1693
diff changeset
57 (*line)++;
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
58 continue;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
59 }
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
60 if (curline[0] == '}') {
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
61 if (started) {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
62 return head;
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
63 }
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
64 fatal_error("unexpected } on line %d\n", *line);
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
65 }
866
69a6ec208111 Menu ROM now pulls real file names from the OS rather than using a fake list
Michael Pavone <pavone@retrodev.com>
parents: 859
diff changeset
66
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
67 char * end = curline + len - 1;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
68 if (*end == '{') {
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
69 *end = 0;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
70 curline = strip_ws(curline);
1783
eda8df5bc74c Minor cleanup
Michael Pavone <pavone@retrodev.com>
parents: 1693
diff changeset
71 (*line)++;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
72 head = tern_insert_node(head, curline, parse_config_int(state, 1, line));
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
73 } else {
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
74 char * val = strip_ws(split_keyval(curline));
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
75 char * key = curline;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
76 if (*val) {
431
440efd7d27a9 Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
77 head = tern_insert_ptr(head, key, strdup(val));
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
78 } else {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
79 fprintf(stderr, "Key %s is missing a value on line %d\n", key, *line);
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
80 }
1783
eda8df5bc74c Minor cleanup
Michael Pavone <pavone@retrodev.com>
parents: 1693
diff changeset
81 (*line)++;
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
82 }
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
83 }
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
84 return head;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
85 }
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
86
875
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
87 tern_node *parse_config(char * config_data)
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
88 {
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
89 int line = 1;
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
90 return parse_config_int(&config_data, 0, &line);
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
91 }
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 742
diff changeset
92
1489
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
93 typedef struct {
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
94 char *buf;
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
95 uint32_t capacity;
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
96 uint32_t size;
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
97 uint32_t indent;
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
98 } serialize_state;
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
99
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
100 static void ensure_buf_capacity(uint32_t ensure, serialize_state *state)
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
101 {
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
102 if (ensure + state->size > state->capacity) {
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
103 state->capacity = state->capacity * 2;
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
104 state->buf = realloc(state->buf, state->capacity);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
105 }
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
106 }
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
107
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
108 static void indent(serialize_state *state)
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
109 {
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
110 memset(state->buf + state->size, '\t', state->indent);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
111 state->size += state->indent;
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
112 }
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
113
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
114 static void serialize_config_int(tern_node *config, serialize_state *state);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
115
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
116 static void serialize_iter(char *key, tern_val val, uint8_t valtype, void *data)
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
117 {
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
118 serialize_state *state = data;
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
119 uint32_t keylen = strlen(key);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
120 uint32_t vallen = 0;
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
121 if (valtype == TVAL_PTR) {
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
122 vallen = strlen(val.ptrval);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
123 }
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
124 ensure_buf_capacity(state->indent + keylen + 2 + vallen, state);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
125 state->buf[state->size++] = '\n';
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
126 indent(state);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
127 memcpy(state->buf + state->size, key, keylen);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
128 state->size += keylen;
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
129 state->buf[state->size++] = ' ';
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
130 if (valtype == TVAL_PTR) {
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
131 memcpy(state->buf + state->size, val.ptrval, vallen);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
132 state->size += vallen;
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
133 } else {
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
134 serialize_config_int(val.ptrval, state);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
135 }
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
136 }
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
137
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
138 static void serialize_config_int(tern_node *config, serialize_state *state)
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
139 {
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
140 ensure_buf_capacity(1, state);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
141 state->buf[state->size++] = '{';
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
142 state->indent++;
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
143
1489
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
144 tern_foreach(config, serialize_iter, state);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
145
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
146 --state->indent;
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
147 ensure_buf_capacity(2 + state->indent, state);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
148 state->buf[state->size++] = '\n';
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
149 indent(state);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
150 state->buf[state->size++] = '}';
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
151 }
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
152
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
153 char *serialize_config(tern_node *config, uint32_t *size_out)
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
154 {
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
155 serialize_state state = {
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
156 .size = 0,
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
157 .capacity = 1024,
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
158 .indent = 0
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
159 };
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
160 state.buf = malloc(state.capacity);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
161 tern_foreach(config, serialize_iter, &state);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
162 //serialize_config_int(config, &state);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
163 *size_out = state.size;
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
164 return state.buf;
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
165 }
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
166
875
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
167 tern_node *parse_config_file(char *config_path)
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
168 {
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
169 tern_node * ret = NULL;
816
7ed55a361e79 Use binary mode for reading shaders and config files so we actually get the number of bytes we expect
Michael Pavone <pavone@retrodev.com>
parents: 799
diff changeset
170 FILE * config_file = fopen(config_path, "rb");
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
171 if (!config_file) {
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
172 goto open_fail;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
173 }
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
174 long config_size = file_size(config_file);
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
175 if (!config_size) {
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
176 goto config_empty;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
177 }
1783
eda8df5bc74c Minor cleanup
Michael Pavone <pavone@retrodev.com>
parents: 1693
diff changeset
178 char *config_data = calloc(config_size + 1, 1);
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
179 if (fread(config_data, 1, config_size, config_file) != config_size) {
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
180 goto config_read_fail;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
181 }
796
41f73c76b978 Fix some memory issues
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 795
diff changeset
182
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
183 ret = parse_config(config_data);
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
184 config_read_fail:
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
185 free(config_data);
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
186 config_empty:
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
187 fclose(config_file);
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
188 open_fail:
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
189 return ret;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
190 }
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
191
1489
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
192 uint8_t serialize_config_file(tern_node *config, char *path)
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
193 {
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
194 FILE *f = fopen(path, "w");
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
195 if (!f) {
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
196 return 0;
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
197 }
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
198 uint32_t buf_size;
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
199 char *buffer = serialize_config(config, &buf_size);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
200 uint8_t ret = buf_size == fwrite(buffer, 1, buf_size, f);
1593
24508cb54f87 Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents: 1555
diff changeset
201 free(buffer);
1489
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
202 fclose(f);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
203 return ret;
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
204 }
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
205
875
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
206 tern_node *parse_bundled_config(char *config_name)
859
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
207 {
1693
ba3fb7a3be6b Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
208 tern_node *ret = NULL;
ba3fb7a3be6b Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
209 #ifdef CONFIG_PATH
ba3fb7a3be6b Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
210 if (!strcmp("default.cfg", config_name) || !strcmp("blastem.cfg", config_name)) {
ba3fb7a3be6b Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
211 char *confpath = path_append(CONFIG_PATH, config_name);
ba3fb7a3be6b Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
212 ret = parse_config_file(confpath);
ba3fb7a3be6b Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
213 free(confpath);
ba3fb7a3be6b Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
214 } else {
ba3fb7a3be6b Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
215 #endif
1140
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 876
diff changeset
216 uint32_t confsize;
875
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
217 char *confdata = read_bundled_file(config_name, &confsize);
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
218 if (confdata) {
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
219 confdata[confsize] = 0;
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
220 ret = parse_config(confdata);
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
221 free(confdata);
859
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
222 }
1693
ba3fb7a3be6b Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
223 #ifdef CONFIG_PATH
ba3fb7a3be6b Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
224 }
ba3fb7a3be6b Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
225 #endif
859
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
226 return ret;
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
227 }
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
228
1852
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
229 tern_node *load_overrideable_config(char *name, char *bundled_name, uint8_t *used_config_dir)
1599
1fc61c844ec5 Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
230 {
1fc61c844ec5 Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
231 char const *confdir = get_config_dir();
1fc61c844ec5 Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
232 char *confpath = NULL;
1fc61c844ec5 Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
233 tern_node *ret;
1fc61c844ec5 Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
234 if (confdir) {
1fc61c844ec5 Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
235 confpath = path_append(confdir, name);
1fc61c844ec5 Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
236 ret = parse_config_file(confpath);
1852
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
237 }
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
238 free(confpath);
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
239 if (used_config_dir) {
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
240 *used_config_dir = ret != NULL;
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
241 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
242
1852
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
243 if (!ret) {
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
244 ret = parse_bundled_config(name);
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
245 if (!ret) {
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
246 ret = parse_bundled_config(bundled_name);
1599
1fc61c844ec5 Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
247 }
1fc61c844ec5 Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
248 }
1fc61c844ec5 Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
249
1852
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
250 return ret;
1599
1fc61c844ec5 Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
251 }
1fc61c844ec5 Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
252
2158
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
253 static tern_node *dupe_tree(tern_node *head)
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
254 {
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
255 if (!head) {
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
256 return head;
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
257 }
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
258 tern_node *out = calloc(1, sizeof(tern_node));
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
259 out->left = dupe_tree(head->left);
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
260 out->right = dupe_tree(head->right);
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
261 out->el = head->el;
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
262 out->valtype = head->valtype;
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
263 if (out->el) {
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
264 out->straight.next = dupe_tree(head->straight.next);
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
265 } else if (out->valtype == TVAL_NODE) {
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
266 out->straight.value.ptrval = dupe_tree(head->straight.value.ptrval);
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
267 } else if (out->valtype == TVAL_PTR) {
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
268 out->straight.value.ptrval = strdup(head->straight.value.ptrval);
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
269 } else {
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
270 out->straight.value = head->straight.value;
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
271 }
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
272 return out;
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
273 }
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
274
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
275 static void migrate_pads(char *key, tern_val val, uint8_t valtype, void *data)
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
276 {
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
277 tern_node **pads = data;
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
278 if (valtype != TVAL_NODE) {
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
279 return;
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
280 }
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
281 tern_node *existing = tern_find_node(*pads, key);
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
282 if (existing) {
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
283 return;
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
284 }
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
285 *pads = tern_insert_node(*pads, key, dupe_tree(val.ptrval));
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
286 }
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
287
2306
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
288 static void update_menu_binding(char *key, tern_val val, uint8_t valtype, void *data)
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
289 {
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
290 tern_node **key_bindings = data;
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
291 if (valtype != TVAL_PTR) {
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
292 return;
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
293 }
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
294 if (strcmp(val.ptrval, "ui.exit")) {
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
295 return;
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
296 }
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
297 *key_bindings = tern_insert_ptr(*key_bindings, key, strdup("ui.menu"));
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
298 }
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
299
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
300 static void update_pad_menu_binding(char *key, tern_val val, uint8_t valtype, void *data)
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
301 {
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
302 tern_node **pads = data;
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
303 if (valtype != TVAL_NODE) {
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
304 return;
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
305 }
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
306 tern_node *buttons = tern_find_node(val.ptrval, "buttons");
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
307 if (buttons) {
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
308 tern_foreach(buttons, update_menu_binding, &buttons);
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
309 val.ptrval = tern_insert_node(val.ptrval, "buttons", buttons);
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
310 }
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
311 tern_node *axes = tern_find_node(val.ptrval, "axes");
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
312 if (axes) {
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
313 tern_foreach(axes, update_menu_binding, &axes);
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
314 val.ptrval = tern_insert_node(val.ptrval, "axes", axes);
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
315 }
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
316 *pads = tern_insert_node(*pads, key, val.ptrval);
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
317 }
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
318
2413
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
319 #define CONFIG_VERSION 9
2158
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
320 static tern_node *migrate_config(tern_node *config, int from_version)
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
321 {
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
322 tern_node *def_config = parse_bundled_config("default.cfg");
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
323 switch(from_version)
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
324 {
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
325 case 0: {
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
326 //Add CD image formats to ui.extensions
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
327 uint32_t num_exts;
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
328 char **ext_list = get_extension_list(config, &num_exts);
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
329 char *old = num_exts ? ext_list[0] : NULL;
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
330 uint32_t new_size = num_exts + 2;
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
331 uint8_t need_cue = 1, need_iso = 1;
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
332 for (uint32_t i = 0; i < num_exts; i++)
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
333 {
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
334 if (!strcmp(ext_list[i], "cue")) {
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
335 need_cue = 0;
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
336 new_size--;
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
337 } else if (!strcmp(ext_list[i], "iso")) {
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
338 need_iso = 0;
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
339 new_size--;
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
340 }
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
341 }
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
342 if (new_size != num_exts) {
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
343 ext_list = realloc(ext_list, sizeof(char*) * new_size);
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
344 if (need_cue) {
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
345 ext_list[num_exts++] = "cue";
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
346 }
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
347 if (need_iso) {
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
348 ext_list[num_exts++] = "iso";
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
349 }
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
350 }
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
351 char *combined = alloc_join(new_size, (char const **)ext_list, ' ');
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
352 config = tern_insert_path(config, "ui\0extensions\0", (tern_val){.ptrval = combined}, TVAL_PTR);
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
353 //Copy default pad configs if missing
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
354 tern_node *pads = tern_find_path(config, "bindings\0pads\0", TVAL_NODE).ptrval;
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
355 tern_node *def_pads = tern_find_path(def_config, "bindings\0pads\0", TVAL_NODE).ptrval;
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
356 tern_foreach(def_pads, migrate_pads, &pads);
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
357 config = tern_insert_path(config, "bindings\0pads\0", (tern_val){.ptrval = pads}, TVAL_NODE);
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
358 }
2162
1270fe86eb89 Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents: 2158
diff changeset
359 case 1: {
1270fe86eb89 Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents: 2158
diff changeset
360 char *l_bind = tern_find_path(config, "bindings\0keys\0l\0", TVAL_PTR).ptrval;
1270fe86eb89 Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents: 2158
diff changeset
361 if (!l_bind) {
1270fe86eb89 Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents: 2158
diff changeset
362 config = tern_insert_path(config, "bindings\0keys\0l\0", (tern_val){.ptrval = strdup("ui.load_state")}, TVAL_PTR);
1270fe86eb89 Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents: 2158
diff changeset
363 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
364 }
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
365 case 2: {
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
366 tern_node *sms = tern_find_node(config, "sms");
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
367 char *model = tern_find_path_default(sms, "system\0model\0", (tern_val){.ptrval = "md1va3"}, TVAL_PTR).ptrval;
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
368 char *io1 = tern_find_path_default(sms, "io\0devices\0""1\0", (tern_val){.ptrval = "gamepad2.1"}, TVAL_PTR).ptrval;
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
369 char *io2 = tern_find_path_default(sms, "io\0devices\0""1\0", (tern_val){.ptrval = "gamepad2.2"}, TVAL_PTR).ptrval;
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
370 sms = tern_insert_path(sms, "system\0model\0", (tern_val){.ptrval = strdup(model)}, TVAL_PTR);
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
371 sms = tern_insert_path(sms, "io\0devices\0""1\0", (tern_val){.ptrval = strdup(io1)}, TVAL_PTR);
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
372 sms = tern_insert_path(sms, "io\0devices\0""2\0", (tern_val){.ptrval = strdup(io2)}, TVAL_PTR);
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
373 config = tern_insert_node(config, "sms", sms);
2162
1270fe86eb89 Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents: 2158
diff changeset
374 }
2235
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2202
diff changeset
375 case 3: {
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2202
diff changeset
376 char *tap11 = tern_find_path_default(config, "io\0sega_multitap.1\0""1\0", (tern_val){.ptrval = "gamepad6.2"}, TVAL_PTR).ptrval;
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2202
diff changeset
377 char *tap12 = tern_find_path_default(config, "io\0sega_multitap.1\0""2\0", (tern_val){.ptrval = "gamepad6.3"}, TVAL_PTR).ptrval;
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2202
diff changeset
378 char *tap13 = tern_find_path_default(config, "io\0sega_multitap.1\0""3\0", (tern_val){.ptrval = "gamepad6.4"}, TVAL_PTR).ptrval;
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2202
diff changeset
379 char *tap14 = tern_find_path_default(config, "io\0sega_multitap.1\0""4\0", (tern_val){.ptrval = "gamepad6.5"}, TVAL_PTR).ptrval;
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2202
diff changeset
380 config = tern_insert_path(config, "io\0sega_multitap.1\0""1\0", (tern_val){.ptrval = strdup(tap11)}, TVAL_PTR);
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2202
diff changeset
381 config = tern_insert_path(config, "io\0sega_multitap.1\0""2\0", (tern_val){.ptrval = strdup(tap12)}, TVAL_PTR);
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2202
diff changeset
382 config = tern_insert_path(config, "io\0sega_multitap.1\0""3\0", (tern_val){.ptrval = strdup(tap13)}, TVAL_PTR);
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2202
diff changeset
383 config = tern_insert_path(config, "io\0sega_multitap.1\0""4\0", (tern_val){.ptrval = strdup(tap14)}, TVAL_PTR);
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2202
diff changeset
384 }
2238
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
385 case 4: {
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
386 char *tap11 = tern_find_path_default(config, "io\0ea_multitap\0""1\0", (tern_val){.ptrval = "gamepad6.1"}, TVAL_PTR).ptrval;
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
387 char *tap12 = tern_find_path_default(config, "io\0ea_multitap\0""2\0", (tern_val){.ptrval = "gamepad6.2"}, TVAL_PTR).ptrval;
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
388 char *tap13 = tern_find_path_default(config, "io\0ea_multitap\0""3\0", (tern_val){.ptrval = "gamepad6.3"}, TVAL_PTR).ptrval;
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
389 char *tap14 = tern_find_path_default(config, "io\0ea_multitap\0""4\0", (tern_val){.ptrval = "gamepad6.4"}, TVAL_PTR).ptrval;
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
390 config = tern_insert_path(config, "io\0ea_multitap\0""1\0", (tern_val){.ptrval = strdup(tap11)}, TVAL_PTR);
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
391 config = tern_insert_path(config, "io\0ea_multitap\0""2\0", (tern_val){.ptrval = strdup(tap12)}, TVAL_PTR);
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
392 config = tern_insert_path(config, "io\0ea_multitap\0""3\0", (tern_val){.ptrval = strdup(tap13)}, TVAL_PTR);
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
393 config = tern_insert_path(config, "io\0ea_multitap\0""4\0", (tern_val){.ptrval = strdup(tap14)}, TVAL_PTR);
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
394 }
2243
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2238
diff changeset
395 case 5: {
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2238
diff changeset
396 char *binding_o = tern_find_path_default(config, "bindings\0keys\0o\0", (tern_val){.ptrval = "ui.oscilloscope"}, TVAL_PTR).ptrval;
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2238
diff changeset
397 config = tern_insert_path(config, "bindings\0keys\0o\0", (tern_val){.ptrval = strdup(binding_o)}, TVAL_PTR);
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2238
diff changeset
398 }
2306
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
399 case 6: {
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
400 tern_node *key_bindings = tern_find_path(config, "bindings\0keys\0", TVAL_NODE).ptrval;
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
401 if (key_bindings) {
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
402 tern_foreach(key_bindings, update_menu_binding, &key_bindings);
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
403 config = tern_insert_path(config, "bindings\0keys\0", (tern_val){.ptrval = key_bindings}, TVAL_NODE);
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
404 }
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
405 tern_node *pad_bindings = tern_find_path(config, "bindings\0pads\0", TVAL_NODE).ptrval;
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
406 if (pad_bindings) {
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
407 tern_foreach(pad_bindings, update_pad_menu_binding, &pad_bindings);
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
408 config = tern_insert_path(config, "bindings\0pads\0", (tern_val){.ptrval = pad_bindings}, TVAL_NODE);
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
409 }
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
410 }
2378
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
411 case 7: {
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
412 uint32_t num_exts;
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
413 char **exts = get_extension_list(config, &num_exts);
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
414 char *need_add[] = {"vgm", "vgz", "flac", "wav"};
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
415 uint32_t num_need_add = sizeof(need_add)/sizeof(*need_add);
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
416 for (uint32_t i = 0; i < num_exts && num_need_add; i++)
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
417 {
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
418 for (uint32_t j = 0; j < num_need_add; j++)
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
419 {
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
420 if (!strcmp(exts[i], need_add[j])) {
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
421 num_need_add--;
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
422 need_add[j] = need_add[num_need_add];
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
423 break;
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
424 }
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
425 }
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
426 }
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
427 if (num_need_add) {
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
428 const char **parts = calloc(2 * (num_exts + num_need_add) - 1, sizeof(char*));
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
429 uint32_t dest = 0;
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
430 for (uint32_t i = 0; i < num_exts; i++)
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
431 {
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
432 parts[dest++] = exts[i];
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
433 parts[dest++] = " ";
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
434 }
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
435 for (uint32_t i = 0; i < num_need_add - 1; i++)
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
436 {
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
437 parts[dest++] = need_add[i];
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
438 parts[dest++] = " ";
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
439 }
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
440 parts[dest++] = need_add[num_need_add - 1];
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
441 config = tern_insert_path(config, "ui\0extensions\0", (tern_val){.ptrval = alloc_concat_m(dest, parts)}, TVAL_PTR);
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
442 free(parts);
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
443 }
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
444 free(exts[0]);//All extensions in this list share an allocation, first one is a pointer to the buffer
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
445 free(exts);
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
446 }
2413
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
447 case 8: {
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
448 uint32_t num_exts;
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
449 char **exts = get_extension_list(config, &num_exts);
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
450 char *need_add[] = {"col"};
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
451 uint32_t num_need_add = sizeof(need_add)/sizeof(*need_add);
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
452 for (uint32_t i = 0; i < num_exts && num_need_add; i++)
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
453 {
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
454 for (uint32_t j = 0; j < num_need_add; j++)
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
455 {
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
456 if (!strcmp(exts[i], need_add[j])) {
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
457 num_need_add--;
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
458 need_add[j] = need_add[num_need_add];
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
459 break;
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
460 }
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
461 }
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
462 }
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
463 if (num_need_add) {
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
464 const char **parts = calloc(2 * (num_exts + num_need_add) - 1, sizeof(char*));
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
465 uint32_t dest = 0;
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
466 for (uint32_t i = 0; i < num_exts; i++)
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
467 {
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
468 parts[dest++] = exts[i];
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
469 parts[dest++] = " ";
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
470 }
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
471 for (uint32_t i = 0; i < num_need_add - 1; i++)
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
472 {
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
473 parts[dest++] = need_add[i];
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
474 parts[dest++] = " ";
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
475 }
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
476 parts[dest++] = need_add[num_need_add - 1];
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
477 config = tern_insert_path(config, "ui\0extensions\0", (tern_val){.ptrval = alloc_concat_m(dest, parts)}, TVAL_PTR);
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
478 free(parts);
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
479 }
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
480 free(exts[0]);//All extensions in this list share an allocation, first one is a pointer to the buffer
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
481 free(exts);
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2378
diff changeset
482 }
2158
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
483 }
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
484 char buffer[16];
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
485 sprintf(buffer, "%d", CONFIG_VERSION);
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
486 return tern_insert_ptr(config, "version", strdup(buffer));
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
487 }
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
488
1852
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
489 static uint8_t app_config_in_config_dir;
875
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 866
diff changeset
490 tern_node *load_config()
859
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
491 {
1852
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
492 tern_node *ret = load_overrideable_config("blastem.cfg", "default.cfg", &app_config_in_config_dir);
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
493
1852
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
494 if (!ret) {
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
495 if (get_config_dir()) {
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
496 fatal_error("Failed to find a config file at %s or in the blastem executable directory\n", get_config_dir());
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
497 } else {
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
498 fatal_error("Failed to find a config file in the BlastEm executable directory and the config directory path could not be determined\n");
859
46bb673eed4e Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents: 816
diff changeset
499 }
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
500 }
2158
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
501 int config_version = atoi(tern_find_ptr_default(ret, "version", "0"));
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
502 if (config_version < CONFIG_VERSION) {
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
503 migrate_config(ret, config_version);
bdd83b47d78a Implement config file migrations and add iso and cue to extension list
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
504 }
1852
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
505 return ret;
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
506 }
1485
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
507
2477
2972a8e16ed2 Make sticky_path respect save config with EXE option
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
508 uint8_t is_config_in_exe_dir(tern_node *app_config)
1489
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
509 {
1852
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
510 char*use_exe_dir = tern_find_path_default(app_config, "ui\0config_in_exe_dir\0", (tern_val){.ptrval = "off"}, TVAL_PTR).ptrval;
2477
2972a8e16ed2 Make sticky_path respect save config with EXE option
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
511 return !strcmp(use_exe_dir, "on");
2972a8e16ed2 Make sticky_path respect save config with EXE option
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
512 }
2972a8e16ed2 Make sticky_path respect save config with EXE option
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
513
2972a8e16ed2 Make sticky_path respect save config with EXE option
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
514 void persist_config_at(tern_node *app_config, tern_node *to_save, char *fname)
2972a8e16ed2 Make sticky_path respect save config with EXE option
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
515 {
1852
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
516 char *confpath;
2477
2972a8e16ed2 Make sticky_path respect save config with EXE option
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
517 if (is_config_in_exe_dir(app_config)) {
1852
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
518 confpath = path_append(get_exe_dir(), fname);
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
519 if (app_config == to_save && app_config_in_config_dir) {
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
520 //user switched to "portable" configs this session and there is an
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
521 //existing config file in the user-specific config directory
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
522 //delete it so we don't end up loading it next time
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
523 char *oldpath = path_append(get_config_dir(), fname);
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
524 delete_file(oldpath);
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
525 free(oldpath);
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
526 }
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
527 } else {
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
528 char const *confdir = get_config_dir();
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
529 if (!confdir) {
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
530 fatal_error("Failed to locate config file directory\n");
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
531 }
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
532 ensure_dir_exists(confdir);
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
533 confpath = path_append(confdir, fname);
1489
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
534 }
1852
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
535 if (!serialize_config_file(to_save, confpath)) {
1489
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
536 fatal_error("Failed to write config to %s\n", confpath);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
537 }
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
538 free(confpath);
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
539 }
637fbc3b5063 Added code to persist config back to a file
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
540
1599
1fc61c844ec5 Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
541 void persist_config(tern_node *config)
1fc61c844ec5 Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
542 {
1852
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1783
diff changeset
543 persist_config_at(config, config, "blastem.cfg");
1599
1fc61c844ec5 Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
544 }
1fc61c844ec5 Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
545
2018
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 1901
diff changeset
546 void delete_custom_config_at(char *fname)
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 1901
diff changeset
547 {
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 1901
diff changeset
548 char *confpath = path_append(get_exe_dir(), fname);
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 1901
diff changeset
549 delete_file(confpath);
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 1901
diff changeset
550 free(confpath);
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 1901
diff changeset
551 confpath = path_append(get_config_dir(), fname);
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 1901
diff changeset
552 delete_file(confpath);
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 1901
diff changeset
553 free(confpath);
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 1901
diff changeset
554 }
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 1901
diff changeset
555
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 1901
diff changeset
556 void delete_custom_config(void)
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 1901
diff changeset
557 {
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 1901
diff changeset
558 delete_custom_config_at("blastem.cfg");
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 1901
diff changeset
559 }
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 1901
diff changeset
560
1485
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
561 char **get_extension_list(tern_node *config, uint32_t *num_exts_out)
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
562 {
2378
af3075c1e421 Add media player file extensions to file browser config
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
563 char *ext_filter = strdup(tern_find_path_default(config, "ui\0extensions\0", (tern_val){.ptrval = "bin gen md smd sms gg zip gz cue iso vgm vgz flac wav"}, TVAL_PTR).ptrval);
1485
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
564 uint32_t num_exts = 0, ext_storage = 5;
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
565 char **ext_list = malloc(sizeof(char *) * ext_storage);
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
566 char *cur_filter = ext_filter;
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
567 while (*cur_filter)
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
568 {
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
569 if (num_exts == ext_storage) {
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
570 ext_storage *= 2;
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
571 ext_list = realloc(ext_list, sizeof(char *) * ext_storage);
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
572 }
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
573 ext_list[num_exts++] = cur_filter;
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
574 cur_filter = split_keyval(cur_filter);
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
575 }
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
576 *num_exts_out = num_exts;
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
577 return ext_list;
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
578 }
1555
6ce36c3f250b More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents: 1544
diff changeset
579
6ce36c3f250b More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents: 1544
diff changeset
580 #define DEFAULT_LOWPASS_CUTOFF 3390
6ce36c3f250b More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents: 1544
diff changeset
581 uint32_t get_lowpass_cutoff(tern_node *config)
6ce36c3f250b More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents: 1544
diff changeset
582 {
6ce36c3f250b More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents: 1544
diff changeset
583 char * lowpass_cutoff_str = tern_find_path(config, "audio\0lowpass_cutoff\0", TVAL_PTR).ptrval;
6ce36c3f250b More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents: 1544
diff changeset
584 return lowpass_cutoff_str ? atoi(lowpass_cutoff_str) : DEFAULT_LOWPASS_CUTOFF;
6ce36c3f250b More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents: 1544
diff changeset
585 }
1900
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
586
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
587 tern_node *get_systems_config(void)
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
588 {
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
589 static tern_node *systems;
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
590 if (!systems) {
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
591 systems = parse_bundled_config("systems.cfg");
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
592 }
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
593 return systems;
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
594 }
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
595
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
596 tern_node *get_model(tern_node *config, system_type stype)
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
597 {
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
598 char *model = tern_find_path_default(config, stype == SYSTEM_SMS ? "sms\0system\0model\0" : "system\0model\0", (tern_val){.ptrval = "md1va3"}, TVAL_PTR).ptrval;
1900
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
599 return tern_find_node(get_systems_config(), model);
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
600 }