comparison blastem.c @ 1483:001120e91fed nuklear_ui

Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
author Michael Pavone <pavone@retrodev.com>
date Sat, 25 Nov 2017 20:43:20 -0800
parents c5c022c7aa54
children a6881d0d76d0
comparison
equal deleted inserted replaced
1482:2d203bf73dbd 1483:001120e91fed
22 #include "romdb.h" 22 #include "romdb.h"
23 #include "terminal.h" 23 #include "terminal.h"
24 #include "arena.h" 24 #include "arena.h"
25 #include "config.h" 25 #include "config.h"
26 #include "menu.h" 26 #include "menu.h"
27 #ifndef DISABLE_NUKLEAR
27 #include "nuklear_ui/blastem_nuklear.h" 28 #include "nuklear_ui/blastem_nuklear.h"
29 #endif
28 30
29 #define BLASTEM_VERSION "0.5.2-pre" 31 #define BLASTEM_VERSION "0.5.2-pre"
30 32
31 #ifdef __ANDROID__ 33 #ifdef __ANDROID__
32 #define FULLSCREEN_DEFAULT 1 34 #define FULLSCREEN_DEFAULT 1
233 lock_on.name = basename_no_extension(lock_on_path); 235 lock_on.name = basename_no_extension(lock_on_path);
234 lock_on.extension = path_extension(lock_on_path); 236 lock_on.extension = path_extension(lock_on_path);
235 lock_on.size = load_rom(lock_on_path, &lock_on.buffer, NULL); 237 lock_on.size = load_rom(lock_on_path, &lock_on.buffer, NULL);
236 } 238 }
237 239
240 static uint32_t opts = 0;
241 static uint8_t force_region = 0;
242 void init_system_with_media(char *path, system_type force_stype)
243 {
244 if (game_system) {
245 game_system->persist_save(game_system);
246 //swap to game context arena and mark all allocated pages in it free
247 if (current_system == menu_system) {
248 current_system->arena = set_current_arena(game_system->arena);
249 }
250 mark_all_free();
251 game_system->free_context(game_system);
252 } else if(current_system) {
253 //start a new arena and save old one in suspended system context
254 current_system->arena = start_new_arena();
255 }
256 system_type stype = SYSTEM_UNKNOWN;
257 if (!(cart.size = load_rom(path, &cart.buffer, &stype))) {
258 fatal_error("Failed to open %s for reading\n", path);
259 }
260 free(cart.dir);
261 free(cart.name);
262 free(cart.extension);
263 cart.dir = path_dirname(path);
264 cart.name = basename_no_extension(path);
265 cart.extension = path_extension(path);
266 if (force_stype != SYSTEM_UNKNOWN) {
267 stype = force_stype;
268 }
269 if (stype == SYSTEM_UNKNOWN) {
270 stype = detect_system_type(&cart);
271 }
272 if (stype == SYSTEM_UNKNOWN) {
273 fatal_error("Failed to detect system type for %s\n", path);
274 }
275 rom_info info;
276 //allocate new system context
277 game_system = alloc_config_system(stype, &cart, opts, force_region, &info);
278 if (!game_system) {
279 fatal_error("Failed to configure emulated machine for %s\n", path);
280 }
281 if (menu_system) {
282 menu_system->next_context = game_system;
283 }
284 game_system->next_context = menu_system;
285 setup_saves(&cart, &info, game_system);
286 update_title(info.name);
287 }
288
238 int main(int argc, char ** argv) 289 int main(int argc, char ** argv)
239 { 290 {
240 set_exe_str(argv[0]); 291 set_exe_str(argv[0]);
241 config = load_config(); 292 config = load_config();
242 int width = -1; 293 int width = -1;
243 int height = -1; 294 int height = -1;
244 int debug = 0; 295 int debug = 0;
245 uint32_t opts = 0;
246 int loaded = 0; 296 int loaded = 0;
247 system_type stype = SYSTEM_UNKNOWN, force_stype = SYSTEM_UNKNOWN; 297 system_type stype = SYSTEM_UNKNOWN, force_stype = SYSTEM_UNKNOWN;
248 uint8_t force_region = 0;
249 char * romfname = NULL; 298 char * romfname = NULL;
250 char * statefile = NULL; 299 char * statefile = NULL;
251 debugger_type dtype = DEBUGGER_NATIVE; 300 debugger_type dtype = DEBUGGER_NATIVE;
252 uint8_t start_in_debugger = 0; 301 uint8_t start_in_debugger = 0;
253 uint8_t fullscreen = FULLSCREEN_DEFAULT, use_gl = 1; 302 uint8_t fullscreen = FULLSCREEN_DEFAULT, use_gl = 1;
380 width = atoi(argv[i]); 429 width = atoi(argv[i]);
381 } else if (height < 0) { 430 } else if (height < 0) {
382 height = atoi(argv[i]); 431 height = atoi(argv[i]);
383 } 432 }
384 } 433 }
434
435 int def_width = 0, def_height = 0;
436 char *config_width = tern_find_path(config, "video\0width\0", TVAL_PTR).ptrval;
437 if (config_width) {
438 def_width = atoi(config_width);
439 }
440 if (!def_width) {
441 def_width = 640;
442 }
443 char *config_height = tern_find_path(config, "video\0height\0", TVAL_PTR).ptrval;
444 if (config_height) {
445 def_height = atoi(config_height);
446 }
447 if (!def_height) {
448 def_height = -1;
449 }
450 width = width < 1 ? def_width : width;
451 height = height < 1 ? def_height : height;
452
453 char *config_fullscreen = tern_find_path(config, "video\0fullscreen\0", TVAL_PTR).ptrval;
454 if (config_fullscreen && !strcmp("on", config_fullscreen)) {
455 fullscreen = !fullscreen;
456 }
457 if (!headless) {
458 render_init(width, height, "BlastEm", fullscreen);
459 render_set_drag_drop_handler(on_drag_drop);
460 }
461
385 uint8_t menu = !loaded; 462 uint8_t menu = !loaded;
386 if (!loaded) { 463 uint8_t use_nuklear = 0;
464 #ifndef DISABLE_NUKLEAR
465 use_nuklear = is_nuklear_available();
466 #endif
467 if (!loaded && !use_nuklear) {
387 //load menu 468 //load menu
388 romfname = tern_find_path(config, "ui\0rom\0", TVAL_PTR).ptrval; 469 romfname = tern_find_path(config, "ui\0rom\0", TVAL_PTR).ptrval;
389 if (!romfname) { 470 if (!romfname) {
390 romfname = "menu.bin"; 471 romfname = "menu.bin";
391 } 472 }
409 cart.dir = path_dirname(romfname); 490 cart.dir = path_dirname(romfname);
410 cart.name = basename_no_extension(romfname); 491 cart.name = basename_no_extension(romfname);
411 cart.extension = path_extension(romfname); 492 cart.extension = path_extension(romfname);
412 loaded = 1; 493 loaded = 1;
413 } 494 }
414
415 int def_width = 0, def_height = 0;
416 char *config_width = tern_find_path(config, "video\0width\0", TVAL_PTR).ptrval;
417 if (config_width) {
418 def_width = atoi(config_width);
419 }
420 if (!def_width) {
421 def_width = 640;
422 }
423 char *config_height = tern_find_path(config, "video\0height\0", TVAL_PTR).ptrval;
424 if (config_height) {
425 def_height = atoi(config_height);
426 }
427 if (!def_height) {
428 def_height = -1;
429 }
430 width = width < 1 ? def_width : width;
431 height = height < 1 ? def_height : height;
432
433 char *config_fullscreen = tern_find_path(config, "video\0fullscreen\0", TVAL_PTR).ptrval;
434 if (config_fullscreen && !strcmp("on", config_fullscreen)) {
435 fullscreen = !fullscreen;
436 }
437 if (!headless) {
438 render_init(width, height, "BlastEm", fullscreen);
439 render_set_drag_drop_handler(on_drag_drop);
440 }
441
442 if (stype == SYSTEM_UNKNOWN) {
443 stype = detect_system_type(&cart);
444 }
445 if (stype == SYSTEM_UNKNOWN) {
446 fatal_error("Failed to detect system type for %s\n", romfname);
447 }
448 rom_info info;
449 current_system = alloc_config_system(stype, &cart, menu ? 0 : opts, force_region, &info);
450 if (!current_system) {
451 fatal_error("Failed to configure emulated machine for %s\n", romfname);
452 }
453 char *state_format = tern_find_path(config, "ui\0state_format\0", TVAL_PTR).ptrval; 495 char *state_format = tern_find_path(config, "ui\0state_format\0", TVAL_PTR).ptrval;
454 if (state_format && !strcmp(state_format, "gst")) { 496 if (state_format && !strcmp(state_format, "gst")) {
455 use_native_states = 0; 497 use_native_states = 0;
456 } else if (state_format && strcmp(state_format, "native")) { 498 } else if (state_format && strcmp(state_format, "native")) {
457 warning("%s is not a valid value for the ui.state_format setting. Valid values are gst and native\n", state_format); 499 warning("%s is not a valid value for the ui.state_format setting. Valid values are gst and native\n", state_format);
458 } 500 }
459 setup_saves(&cart, &info, current_system); 501
460 update_title(info.name); 502 if (loaded) {
461 if (menu) { 503 if (stype == SYSTEM_UNKNOWN) {
462 menu_system = current_system; 504 stype = detect_system_type(&cart);
463 } else { 505 }
464 game_system = current_system; 506 if (stype == SYSTEM_UNKNOWN) {
465 } 507 fatal_error("Failed to detect system type for %s\n", romfname);
508 }
509 rom_info info;
510 current_system = alloc_config_system(stype, &cart, menu ? 0 : opts, force_region, &info);
511 if (!current_system) {
512 fatal_error("Failed to configure emulated machine for %s\n", romfname);
513 }
466 514
467 blastem_nuklear_init(game_system == current_system); 515 setup_saves(&cart, &info, current_system);
468 516 update_title(info.name);
517 if (menu) {
518 menu_system = current_system;
519 } else {
520 game_system = current_system;
521 }
522 }
523
524 #ifndef DISABLE_NUKLEAR
525 if (use_nuklear) {
526 blastem_nuklear_init(!menu);
527 current_system = game_system;
528 }
529 #endif
530
469 current_system->debugger_type = dtype; 531 current_system->debugger_type = dtype;
470 current_system->enter_debugger = start_in_debugger && menu == debug_target; 532 current_system->enter_debugger = start_in_debugger && menu == debug_target;
471 current_system->start_context(current_system, menu ? NULL : statefile); 533 current_system->start_context(current_system, menu ? NULL : statefile);
472 for(;;) 534 for(;;)
473 { 535 {
475 break; 537 break;
476 } 538 }
477 if (current_system->next_rom) { 539 if (current_system->next_rom) {
478 char *next_rom = current_system->next_rom; 540 char *next_rom = current_system->next_rom;
479 current_system->next_rom = NULL; 541 current_system->next_rom = NULL;
480 if (game_system) { 542 init_system_with_media(next_rom, force_stype);
481 game_system->persist_save(game_system);
482 //swap to game context arena and mark all allocated pages in it free
483 if (menu) {
484 current_system->arena = set_current_arena(game_system->arena);
485 }
486 mark_all_free();
487 game_system->free_context(game_system);
488 } else {
489 //start a new arena and save old one in suspended genesis context
490 current_system->arena = start_new_arena();
491 }
492 if (!(cart.size = load_rom(next_rom, &cart.buffer, &stype))) {
493 fatal_error("Failed to open %s for reading\n", next_rom);
494 }
495 free(cart.dir);
496 free(cart.name);
497 free(cart.extension);
498 cart.dir = path_dirname(next_rom);
499 cart.name = basename_no_extension(next_rom);
500 cart.extension = path_extension(next_rom);
501 stype = force_stype;
502 if (stype == SYSTEM_UNKNOWN) {
503 stype = detect_system_type(&cart);
504 }
505 if (stype == SYSTEM_UNKNOWN) {
506 fatal_error("Failed to detect system type for %s\n", next_rom);
507 }
508 //allocate new system context
509 game_system = alloc_config_system(stype, &cart, opts,force_region, &info);
510 if (!game_system) {
511 fatal_error("Failed to configure emulated machine for %s\n", next_rom);
512 }
513 if (menu_system) {
514 menu_system->next_context = game_system;
515 }
516 game_system->next_context = menu_system;
517 setup_saves(&cart, &info, game_system);
518 update_title(info.name);
519 free(next_rom); 543 free(next_rom);
520 menu = 0; 544 menu = 0;
521 current_system = game_system; 545 current_system = game_system;
522 current_system->debugger_type = dtype; 546 current_system->debugger_type = dtype;
523 current_system->enter_debugger = start_in_debugger && menu == debug_target; 547 current_system->enter_debugger = start_in_debugger && menu == debug_target;