From 2ef80983d5d11aec60c4a4fbe0958a261e42fb6b Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Tue, 21 Nov 2017 19:07:43 -0800 Subject: Initial work on Nuklear-based UI --HG-- branch : nuklear_ui --- blastem.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'blastem.c') diff --git a/blastem.c b/blastem.c index 9a9d84d..620f721 100644 --- a/blastem.c +++ b/blastem.c @@ -24,6 +24,7 @@ #include "arena.h" #include "config.h" #include "menu.h" +#include "nuklear_ui/blastem_nuklear.h" #define BLASTEM_VERSION "0.5.2-pre" @@ -462,6 +463,8 @@ int main(int argc, char ** argv) } else { game_system = current_system; } + + blastem_nuklear_init(game_system == current_system); current_system->debugger_type = dtype; current_system->enter_debugger = start_in_debugger && menu == debug_target; -- cgit v1.2.3 From f4767bb05392fa4a04d72969fa35aa91b688c8cb Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sat, 25 Nov 2017 20:43:20 -0800 Subject: 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 --HG-- branch : nuklear_ui --- blastem.c | 200 +++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 112 insertions(+), 88 deletions(-) (limited to 'blastem.c') diff --git a/blastem.c b/blastem.c index 620f721..39ebfa4 100644 --- a/blastem.c +++ b/blastem.c @@ -24,7 +24,9 @@ #include "arena.h" #include "config.h" #include "menu.h" +#ifndef DISABLE_NUKLEAR #include "nuklear_ui/blastem_nuklear.h" +#endif #define BLASTEM_VERSION "0.5.2-pre" @@ -235,6 +237,55 @@ void lockon_media(char *lock_on_path) lock_on.size = load_rom(lock_on_path, &lock_on.buffer, NULL); } +static uint32_t opts = 0; +static uint8_t force_region = 0; +void init_system_with_media(char *path, system_type force_stype) +{ + if (game_system) { + game_system->persist_save(game_system); + //swap to game context arena and mark all allocated pages in it free + if (current_system == menu_system) { + current_system->arena = set_current_arena(game_system->arena); + } + mark_all_free(); + game_system->free_context(game_system); + } else if(current_system) { + //start a new arena and save old one in suspended system context + current_system->arena = start_new_arena(); + } + system_type stype = SYSTEM_UNKNOWN; + if (!(cart.size = load_rom(path, &cart.buffer, &stype))) { + fatal_error("Failed to open %s for reading\n", path); + } + free(cart.dir); + free(cart.name); + free(cart.extension); + cart.dir = path_dirname(path); + cart.name = basename_no_extension(path); + cart.extension = path_extension(path); + if (force_stype != SYSTEM_UNKNOWN) { + stype = force_stype; + } + if (stype == SYSTEM_UNKNOWN) { + stype = detect_system_type(&cart); + } + if (stype == SYSTEM_UNKNOWN) { + fatal_error("Failed to detect system type for %s\n", path); + } + rom_info info; + //allocate new system context + game_system = alloc_config_system(stype, &cart, opts, force_region, &info); + if (!game_system) { + fatal_error("Failed to configure emulated machine for %s\n", path); + } + if (menu_system) { + menu_system->next_context = game_system; + } + game_system->next_context = menu_system; + setup_saves(&cart, &info, game_system); + update_title(info.name); +} + int main(int argc, char ** argv) { set_exe_str(argv[0]); @@ -242,10 +293,8 @@ int main(int argc, char ** argv) int width = -1; int height = -1; int debug = 0; - uint32_t opts = 0; int loaded = 0; system_type stype = SYSTEM_UNKNOWN, force_stype = SYSTEM_UNKNOWN; - uint8_t force_region = 0; char * romfname = NULL; char * statefile = NULL; debugger_type dtype = DEBUGGER_NATIVE; @@ -382,35 +431,6 @@ int main(int argc, char ** argv) height = atoi(argv[i]); } } - uint8_t menu = !loaded; - if (!loaded) { - //load menu - romfname = tern_find_path(config, "ui\0rom\0", TVAL_PTR).ptrval; - if (!romfname) { - romfname = "menu.bin"; - } - if (is_absolute_path(romfname)) { - if (!(cart.size = load_rom(romfname, &cart.buffer, &stype))) { - fatal_error("Failed to open UI ROM %s for reading", romfname); - } - } else { - cart.buffer = (uint16_t *)read_bundled_file(romfname, &cart.size); - if (!cart.buffer) { - fatal_error("Failed to open UI ROM %s for reading", romfname); - } - uint32_t rom_size = nearest_pow2(cart.size); - if (rom_size > cart.size) { - cart.buffer = realloc(cart.buffer, rom_size); - cart.size = rom_size; - } - } - //force system detection, value on command line is only for games not the menu - stype = detect_system_type(&cart); - cart.dir = path_dirname(romfname); - cart.name = basename_no_extension(romfname); - cart.extension = path_extension(romfname); - loaded = 1; - } int def_width = 0, def_height = 0; char *config_width = tern_find_path(config, "video\0width\0", TVAL_PTR).ptrval; @@ -438,17 +458,39 @@ int main(int argc, char ** argv) render_init(width, height, "BlastEm", fullscreen); render_set_drag_drop_handler(on_drag_drop); } - - if (stype == SYSTEM_UNKNOWN) { + + uint8_t menu = !loaded; + uint8_t use_nuklear = 0; +#ifndef DISABLE_NUKLEAR + use_nuklear = is_nuklear_available(); +#endif + if (!loaded && !use_nuklear) { + //load menu + romfname = tern_find_path(config, "ui\0rom\0", TVAL_PTR).ptrval; + if (!romfname) { + romfname = "menu.bin"; + } + if (is_absolute_path(romfname)) { + if (!(cart.size = load_rom(romfname, &cart.buffer, &stype))) { + fatal_error("Failed to open UI ROM %s for reading", romfname); + } + } else { + cart.buffer = (uint16_t *)read_bundled_file(romfname, &cart.size); + if (!cart.buffer) { + fatal_error("Failed to open UI ROM %s for reading", romfname); + } + uint32_t rom_size = nearest_pow2(cart.size); + if (rom_size > cart.size) { + cart.buffer = realloc(cart.buffer, rom_size); + cart.size = rom_size; + } + } + //force system detection, value on command line is only for games not the menu stype = detect_system_type(&cart); - } - if (stype == SYSTEM_UNKNOWN) { - fatal_error("Failed to detect system type for %s\n", romfname); - } - rom_info info; - current_system = alloc_config_system(stype, &cart, menu ? 0 : opts, force_region, &info); - if (!current_system) { - fatal_error("Failed to configure emulated machine for %s\n", romfname); + cart.dir = path_dirname(romfname); + cart.name = basename_no_extension(romfname); + cart.extension = path_extension(romfname); + loaded = 1; } char *state_format = tern_find_path(config, "ui\0state_format\0", TVAL_PTR).ptrval; if (state_format && !strcmp(state_format, "gst")) { @@ -456,16 +498,36 @@ int main(int argc, char ** argv) } else if (state_format && strcmp(state_format, "native")) { warning("%s is not a valid value for the ui.state_format setting. Valid values are gst and native\n", state_format); } - setup_saves(&cart, &info, current_system); - update_title(info.name); - if (menu) { - menu_system = current_system; - } else { - game_system = current_system; + + if (loaded) { + if (stype == SYSTEM_UNKNOWN) { + stype = detect_system_type(&cart); + } + if (stype == SYSTEM_UNKNOWN) { + fatal_error("Failed to detect system type for %s\n", romfname); + } + rom_info info; + current_system = alloc_config_system(stype, &cart, menu ? 0 : opts, force_region, &info); + if (!current_system) { + fatal_error("Failed to configure emulated machine for %s\n", romfname); + } + + setup_saves(&cart, &info, current_system); + update_title(info.name); + if (menu) { + menu_system = current_system; + } else { + game_system = current_system; + } } - blastem_nuklear_init(game_system == current_system); - +#ifndef DISABLE_NUKLEAR + if (use_nuklear) { + blastem_nuklear_init(!menu); + current_system = game_system; + } +#endif + current_system->debugger_type = dtype; current_system->enter_debugger = start_in_debugger && menu == debug_target; current_system->start_context(current_system, menu ? NULL : statefile); @@ -477,45 +539,7 @@ int main(int argc, char ** argv) if (current_system->next_rom) { char *next_rom = current_system->next_rom; current_system->next_rom = NULL; - if (game_system) { - game_system->persist_save(game_system); - //swap to game context arena and mark all allocated pages in it free - if (menu) { - current_system->arena = set_current_arena(game_system->arena); - } - mark_all_free(); - game_system->free_context(game_system); - } else { - //start a new arena and save old one in suspended genesis context - current_system->arena = start_new_arena(); - } - if (!(cart.size = load_rom(next_rom, &cart.buffer, &stype))) { - fatal_error("Failed to open %s for reading\n", next_rom); - } - free(cart.dir); - free(cart.name); - free(cart.extension); - cart.dir = path_dirname(next_rom); - cart.name = basename_no_extension(next_rom); - cart.extension = path_extension(next_rom); - stype = force_stype; - if (stype == SYSTEM_UNKNOWN) { - stype = detect_system_type(&cart); - } - if (stype == SYSTEM_UNKNOWN) { - fatal_error("Failed to detect system type for %s\n", next_rom); - } - //allocate new system context - game_system = alloc_config_system(stype, &cart, opts,force_region, &info); - if (!game_system) { - fatal_error("Failed to configure emulated machine for %s\n", next_rom); - } - if (menu_system) { - menu_system->next_context = game_system; - } - game_system->next_context = menu_system; - setup_saves(&cart, &info, game_system); - update_title(info.name); + init_system_with_media(next_rom, force_stype); free(next_rom); menu = 0; current_system = game_system; -- cgit v1.2.3 From 3b2e343a1088abc7fe1cf1dffcf6a20aa97b0918 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sun, 26 Nov 2017 19:22:09 -0800 Subject: Pause game execution when in the new UI pause menu --HG-- branch : nuklear_ui --- blastem.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'blastem.c') diff --git a/blastem.c b/blastem.c index 39ebfa4..40077f9 100644 --- a/blastem.c +++ b/blastem.c @@ -525,6 +525,7 @@ int main(int argc, char ** argv) if (use_nuklear) { blastem_nuklear_init(!menu); current_system = game_system; + menu = 0; } #endif @@ -551,10 +552,16 @@ int main(int argc, char ** argv) current_system = game_system; menu = 0; current_system->resume_context(current_system); - } else if (!menu && menu_system) { - current_system->arena = set_current_arena(menu_system->arena); - current_system = menu_system; - menu = 1; + } else if (!menu && (menu_system || use_nuklear)) { + if (use_nuklear) { +#ifndef DISABLE_NUKLEAR + ui_idle_loop(); +#endif + } else { + current_system->arena = set_current_arena(menu_system->arena); + current_system = menu_system; + menu = 1; + } current_system->resume_context(current_system); } else { break; -- cgit v1.2.3 From 4a9e985267f3c88b480f9f3b3d07e4a0c70716ae Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sun, 26 Nov 2017 20:17:22 -0800 Subject: Enable lock-on in Nuklear UI --HG-- branch : nuklear_ui --- blastem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'blastem.c') diff --git a/blastem.c b/blastem.c index 40077f9..24c1ecd 100644 --- a/blastem.c +++ b/blastem.c @@ -562,7 +562,9 @@ int main(int argc, char ** argv) current_system = menu_system; menu = 1; } - current_system->resume_context(current_system); + if (!current_system->next_rom) { + current_system->resume_context(current_system); + } } else { break; } -- cgit v1.2.3 From 0b409a1a9ccc9d7d566a0a867eec4f6eb5a1f5e1 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Wed, 29 Nov 2017 08:41:37 -0800 Subject: Added code to persist config back to a file --HG-- branch : nuklear_ui --- blastem.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'blastem.c') diff --git a/blastem.c b/blastem.c index 24c1ecd..09bcecb 100644 --- a/blastem.c +++ b/blastem.c @@ -286,6 +286,11 @@ void init_system_with_media(char *path, system_type force_stype) update_title(info.name); } +static void save_config(void) +{ + persist_config(config); +} + int main(int argc, char ** argv) { set_exe_str(argv[0]); @@ -521,6 +526,8 @@ int main(int argc, char ** argv) } } + atexit(save_config); + #ifndef DISABLE_NUKLEAR if (use_nuklear) { blastem_nuklear_init(!menu); -- cgit v1.2.3