Mercurial > repos > blastem
comparison config.c @ 2202:ee6d30c56eeb
Add separate model/IO selection settings for SMS/GG
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 22 Aug 2022 22:56:05 -0700 |
parents | 1270fe86eb89 |
children | 93918a6a8ab7 |
comparison
equal
deleted
inserted
replaced
2201:2f8984ff5c85 | 2202:ee6d30c56eeb |
---|---|
138 static void serialize_config_int(tern_node *config, serialize_state *state) | 138 static void serialize_config_int(tern_node *config, serialize_state *state) |
139 { | 139 { |
140 ensure_buf_capacity(1, state); | 140 ensure_buf_capacity(1, state); |
141 state->buf[state->size++] = '{'; | 141 state->buf[state->size++] = '{'; |
142 state->indent++; | 142 state->indent++; |
143 | 143 |
144 tern_foreach(config, serialize_iter, state); | 144 tern_foreach(config, serialize_iter, state); |
145 | 145 |
146 --state->indent; | 146 --state->indent; |
147 ensure_buf_capacity(2 + state->indent, state); | 147 ensure_buf_capacity(2 + state->indent, state); |
148 state->buf[state->size++] = '\n'; | 148 state->buf[state->size++] = '\n'; |
237 } | 237 } |
238 free(confpath); | 238 free(confpath); |
239 if (used_config_dir) { | 239 if (used_config_dir) { |
240 *used_config_dir = ret != NULL; | 240 *used_config_dir = ret != NULL; |
241 } | 241 } |
242 | 242 |
243 if (!ret) { | 243 if (!ret) { |
244 ret = parse_bundled_config(name); | 244 ret = parse_bundled_config(name); |
245 if (!ret) { | 245 if (!ret) { |
246 ret = parse_bundled_config(bundled_name); | 246 ret = parse_bundled_config(bundled_name); |
247 } | 247 } |
283 return; | 283 return; |
284 } | 284 } |
285 *pads = tern_insert_node(*pads, key, dupe_tree(val.ptrval)); | 285 *pads = tern_insert_node(*pads, key, dupe_tree(val.ptrval)); |
286 } | 286 } |
287 | 287 |
288 #define CONFIG_VERSION 2 | 288 #define CONFIG_VERSION 3 |
289 static tern_node *migrate_config(tern_node *config, int from_version) | 289 static tern_node *migrate_config(tern_node *config, int from_version) |
290 { | 290 { |
291 tern_node *def_config = parse_bundled_config("default.cfg"); | 291 tern_node *def_config = parse_bundled_config("default.cfg"); |
292 switch(from_version) | 292 switch(from_version) |
293 { | 293 { |
322 //Copy default pad configs if missing | 322 //Copy default pad configs if missing |
323 tern_node *pads = tern_find_path(config, "bindings\0pads\0", TVAL_NODE).ptrval; | 323 tern_node *pads = tern_find_path(config, "bindings\0pads\0", TVAL_NODE).ptrval; |
324 tern_node *def_pads = tern_find_path(def_config, "bindings\0pads\0", TVAL_NODE).ptrval; | 324 tern_node *def_pads = tern_find_path(def_config, "bindings\0pads\0", TVAL_NODE).ptrval; |
325 tern_foreach(def_pads, migrate_pads, &pads); | 325 tern_foreach(def_pads, migrate_pads, &pads); |
326 config = tern_insert_path(config, "bindings\0pads\0", (tern_val){.ptrval = pads}, TVAL_NODE); | 326 config = tern_insert_path(config, "bindings\0pads\0", (tern_val){.ptrval = pads}, TVAL_NODE); |
327 break; | |
328 } | 327 } |
329 case 1: { | 328 case 1: { |
330 char *l_bind = tern_find_path(config, "bindings\0keys\0l\0", TVAL_PTR).ptrval; | 329 char *l_bind = tern_find_path(config, "bindings\0keys\0l\0", TVAL_PTR).ptrval; |
331 if (!l_bind) { | 330 if (!l_bind) { |
332 config = tern_insert_path(config, "bindings\0keys\0l\0", (tern_val){.ptrval = strdup("ui.load_state")}, TVAL_PTR); | 331 config = tern_insert_path(config, "bindings\0keys\0l\0", (tern_val){.ptrval = strdup("ui.load_state")}, TVAL_PTR); |
333 } | 332 } |
334 break; | 333 } |
334 case 2: { | |
335 tern_node *sms = tern_find_node(config, "sms"); | |
336 char *model = tern_find_path_default(sms, "system\0model\0", (tern_val){.ptrval = "md1va3"}, TVAL_PTR).ptrval; | |
337 char *io1 = tern_find_path_default(sms, "io\0devices\0""1\0", (tern_val){.ptrval = "gamepad2.1"}, TVAL_PTR).ptrval; | |
338 char *io2 = tern_find_path_default(sms, "io\0devices\0""1\0", (tern_val){.ptrval = "gamepad2.2"}, TVAL_PTR).ptrval; | |
339 sms = tern_insert_path(sms, "system\0model\0", (tern_val){.ptrval = strdup(model)}, TVAL_PTR); | |
340 sms = tern_insert_path(sms, "io\0devices\0""1\0", (tern_val){.ptrval = strdup(io1)}, TVAL_PTR); | |
341 sms = tern_insert_path(sms, "io\0devices\0""2\0", (tern_val){.ptrval = strdup(io2)}, TVAL_PTR); | |
342 config = tern_insert_node(config, "sms", sms); | |
335 } | 343 } |
336 } | 344 } |
337 char buffer[16]; | 345 char buffer[16]; |
338 sprintf(buffer, "%d", CONFIG_VERSION); | 346 sprintf(buffer, "%d", CONFIG_VERSION); |
339 return tern_insert_ptr(config, "version", strdup(buffer)); | 347 return tern_insert_ptr(config, "version", strdup(buffer)); |
341 | 349 |
342 static uint8_t app_config_in_config_dir; | 350 static uint8_t app_config_in_config_dir; |
343 tern_node *load_config() | 351 tern_node *load_config() |
344 { | 352 { |
345 tern_node *ret = load_overrideable_config("blastem.cfg", "default.cfg", &app_config_in_config_dir); | 353 tern_node *ret = load_overrideable_config("blastem.cfg", "default.cfg", &app_config_in_config_dir); |
346 | 354 |
347 if (!ret) { | 355 if (!ret) { |
348 if (get_config_dir()) { | 356 if (get_config_dir()) { |
349 fatal_error("Failed to find a config file at %s or in the blastem executable directory\n", get_config_dir()); | 357 fatal_error("Failed to find a config file at %s or in the blastem executable directory\n", get_config_dir()); |
350 } else { | 358 } else { |
351 fatal_error("Failed to find a config file in the BlastEm executable directory and the config directory path could not be determined\n"); | 359 fatal_error("Failed to find a config file in the BlastEm executable directory and the config directory path could not be determined\n"); |
441 return systems; | 449 return systems; |
442 } | 450 } |
443 | 451 |
444 tern_node *get_model(tern_node *config, system_type stype) | 452 tern_node *get_model(tern_node *config, system_type stype) |
445 { | 453 { |
446 char *model = tern_find_path_default(config, "system\0model\0", (tern_val){.ptrval = "md1va3"}, TVAL_PTR).ptrval; | 454 char *model = tern_find_path_default(config, stype == SYSTEM_SMS ? "sms\0system\0model\0" : "system\0model\0", (tern_val){.ptrval = "md1va3"}, TVAL_PTR).ptrval; |
447 return tern_find_node(get_systems_config(), model); | 455 return tern_find_node(get_systems_config(), model); |
448 } | 456 } |