changeset 2306:62f316b76e9a

Migrate ui.exit to ui.menu and create a new ui.exit for quitting
author Michael Pavone <pavone@retrodev.com>
date Thu, 23 Mar 2023 22:37:08 -0700
parents 6aca1734d573
children a8080240cb92
files README bindings.c config.c default.cfg nuklear_ui/blastem_nuklear.c
diffstat 5 files changed, 74 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/README	Wed Mar 15 19:28:11 2023 -0700
+++ b/README	Thu Mar 23 22:37:08 2023 -0700
@@ -17,13 +17,12 @@
 
 This version of BlastEm has a GUI that allows access to most configuration options.
 Simply start BlastEm without passing a ROM filename on the command line to access
-the main menu. You can also access the menu by hitting the button mapped to the ui.exit
+the main menu. You can also access the menu by hitting the button mapped to the ui.menu
 action (default Esc).
 
-If Open GL is disabled or unavaible, or you explicitly request it, the old ROM-based UI
-will be used instead. This UI does not support configuration so you will need to modify
-the configuration file manually if you use it. See the rest of this README for instructions
-on modifying the configuration file.
+If you explicitly request it, you can still use the old ROM-based UI instead. This UI does
+not support configuration so you will need to modify the configuration file manually if you
+use it. See the rest of this README for instructions on modifying the configuration file.
 
 Some operations are currently only supported through the command line. To get a
 list of supported command line options on Linux or OSX type:
@@ -158,8 +157,9 @@
 ui.enter_debugger            Enters the debugger for the main CPU of the
 							 currently emulated system
 ui.screenshot                Takes an internal screenshot
-ui.exit                      Returns to the menu ROM if currently in a game
-                             that was launched from the menu. Exits otherwise
+ui.menu                      Opens the in-game menu, or exits the menu if it
+                             is currently open.
+ui.exit                      Quits the emulator
 ui.save_state                Saves a savestate to the quicksave slot
 ui.set_speed.N               Selects a specific machine speed specified by N
                              which should be a number between 0-9. Speeds are
--- a/bindings.c	Wed Mar 15 19:28:11 2023 -0700
+++ b/bindings.c	Thu Mar 23 22:37:08 2023 -0700
@@ -39,6 +39,7 @@
 	UI_SCREENSHOT,
 	UI_RECORD_VIDEO,
 	UI_VGM_LOG,
+	UI_MENU,
 	UI_EXIT,
 	UI_PLANE_DEBUG,
 	UI_VRAM_DEBUG,
@@ -438,7 +439,7 @@
 				}
 			}
 			break;
-		case UI_EXIT:
+		case UI_MENU:
 #ifndef DISABLE_NUKLEAR
 			if (is_nuklear_active()) {
 				show_pause_menu();
@@ -457,6 +458,8 @@
 			}
 #endif
 			break;
+		case UI_EXIT:
+			exit(0);
 		case UI_PLANE_DEBUG:
 		case UI_VRAM_DEBUG:
 		case UI_CRAM_DEBUG:
@@ -696,6 +699,8 @@
 			*subtype_a = UI_RECORD_VIDEO;
 		} else if (!strcmp(target + 3, "vgm_log")) {
 			*subtype_a = UI_VGM_LOG;
+		} else if(!strcmp(target + 3, "menu")) {
+			*subtype_a = UI_MENU;
 		} else if(!strcmp(target + 3, "exit")) {
 			*subtype_a = UI_EXIT;
 		} else if (!strcmp(target + 3, "plane_debug")) {
--- a/config.c	Wed Mar 15 19:28:11 2023 -0700
+++ b/config.c	Thu Mar 23 22:37:08 2023 -0700
@@ -285,7 +285,38 @@
 	*pads = tern_insert_node(*pads, key, dupe_tree(val.ptrval));
 }
 
-#define CONFIG_VERSION 6
+static void update_menu_binding(char *key, tern_val val, uint8_t valtype, void *data)
+{
+	tern_node **key_bindings = data;
+	if (valtype != TVAL_PTR) {
+		return;
+	}
+	if (strcmp(val.ptrval, "ui.exit")) {
+		return;
+	}
+	*key_bindings = tern_insert_ptr(*key_bindings, key, strdup("ui.menu"));
+}
+
+static void update_pad_menu_binding(char *key, tern_val val, uint8_t valtype, void *data)
+{
+	tern_node **pads = data;
+	if (valtype != TVAL_NODE) {
+		return;
+	}
+	tern_node *buttons = tern_find_node(val.ptrval, "buttons");
+	if (buttons) {
+		tern_foreach(buttons, update_menu_binding, &buttons);
+		val.ptrval = tern_insert_node(val.ptrval, "buttons", buttons);
+	}
+	tern_node *axes = tern_find_node(val.ptrval, "axes");
+	if (axes) {
+		tern_foreach(axes, update_menu_binding, &axes);
+		val.ptrval = tern_insert_node(val.ptrval, "axes", axes);
+	}
+	*pads = tern_insert_node(*pads, key, val.ptrval);
+}
+
+#define CONFIG_VERSION 7
 static tern_node *migrate_config(tern_node *config, int from_version)
 {
 	tern_node *def_config = parse_bundled_config("default.cfg");
@@ -365,6 +396,18 @@
 		char *binding_o = tern_find_path_default(config, "bindings\0keys\0o\0", (tern_val){.ptrval = "ui.oscilloscope"}, TVAL_PTR).ptrval;
 		config = tern_insert_path(config, "bindings\0keys\0o\0", (tern_val){.ptrval = strdup(binding_o)}, TVAL_PTR);
 	}
+	case 6: {
+		tern_node *key_bindings = tern_find_path(config, "bindings\0keys\0", TVAL_NODE).ptrval;
+		if (key_bindings) {
+			tern_foreach(key_bindings, update_menu_binding, &key_bindings);
+			config = tern_insert_path(config, "bindings\0keys\0", (tern_val){.ptrval = key_bindings}, TVAL_NODE);
+		}
+		tern_node *pad_bindings = tern_find_path(config, "bindings\0pads\0", TVAL_NODE).ptrval;
+		if (pad_bindings) {
+			tern_foreach(pad_bindings, update_pad_menu_binding, &pad_bindings);
+			config = tern_insert_path(config, "bindings\0pads\0", (tern_val){.ptrval = pad_bindings}, TVAL_NODE);
+		}
+	}
 	}
 	char buffer[16];
 	sprintf(buffer, "%d", CONFIG_VERSION);
--- a/default.cfg	Wed Mar 15 19:28:11 2023 -0700
+++ b/default.cfg	Thu Mar 23 22:37:08 2023 -0700
@@ -24,7 +24,7 @@
 		n ui.compositing_debug
 		o ui.oscilloscope
 		m ui.vgm_log
-		esc ui.exit
+		esc ui.menu
 		` ui.save_state
 		l ui.load_state
 		0 ui.set_speed.0
@@ -62,7 +62,7 @@
 				leftshoulder gamepads.n.z
 				back gamepads.n.mode
 				start gamepads.n.start
-				guide ui.exit
+				guide ui.menu
 				leftstick ui.save_state
 			}
 			axes {
@@ -87,7 +87,7 @@
 				a gamepads.n.a
 				b gamepads.n.b
 				back ui.sms_pause
-				guide ui.exit
+				guide ui.menu
 				leftshoulder gamepads.n.mode
 				leftstick ui.save_state
 				rightshoulder gamepads.n.z
@@ -118,7 +118,7 @@
 				a gamepads.n.a
 				b gamepads.n.b
 				back ui.sms_pause
-				guide ui.exit
+				guide ui.menu
 				leftshoulder gamepads.n.mode
 				leftstick ui.save_state
 				rightshoulder gamepads.n.z
@@ -149,7 +149,7 @@
 				a gamepads.n.a
 				b gamepads.n.b
 				back ui.sms_pause
-				guide ui.exit
+				guide ui.menu
 				leftshoulder gamepads.n.mode
 				leftstick ui.save_state
 				rightshoulder gamepads.n.z
@@ -180,7 +180,7 @@
 				a gamepads.n.a
 				b gamepads.n.b
 				back ui.sms_pause
-				guide ui.exit
+				guide ui.menu
 				leftshoulder gamepads.n.mode
 				leftstick ui.save_state
 				rightshoulder gamepads.n.z
@@ -200,14 +200,14 @@
 		}
 		genesis_6b_bumpers {
 			axes {
-				lefttrigger ui.exit
+				lefttrigger ui.menu
 				righttrigger gamepads.n.mode
 			}
 			buttons {
 				a gamepads.n.a
 				b gamepads.n.b
 				back ui.sms_pause
-				guide ui.exit
+				guide ui.menu
 				leftshoulder gamepads.n.z
 				rightshoulder gamepads.n.c
 				start gamepads.n.start
@@ -225,14 +225,14 @@
 		}
 		saturn_6b_bumpers {
 			axes {
-				lefttrigger ui.exit
+				lefttrigger ui.menu
 				righttrigger gamepads.n.mode
 			}
 			buttons {
 				a gamepads.n.a
 				b gamepads.n.b
 				back ui.sms_pause
-				guide ui.exit
+				guide ui.menu
 				leftshoulder gamepads.n.z
 				rightshoulder gamepads.n.c
 				start gamepads.n.start
--- a/nuklear_ui/blastem_nuklear.c	Wed Mar 15 19:28:11 2023 -0700
+++ b/nuklear_ui/blastem_nuklear.c	Thu Mar 23 22:37:08 2023 -0700
@@ -478,12 +478,12 @@
 		"gamepads.2.start", "gamepads.2.mode"
 	};
 	static const char *general_binds[] = {
-		"ui.exit", "ui.save_state", "ui.load_state", "ui.toggle_fullscreen", "ui.soft_reset", "ui.reload",
-		"ui.screenshot", "ui.vgm_log", "ui.sms_pause", "ui.toggle_keyboard_captured", "ui.release_mouse"
+		"ui.menu", "ui.save_state", "ui.load_state", "ui.toggle_fullscreen", "ui.soft_reset", "ui.reload",
+		"ui.screenshot", "ui.vgm_log", "ui.sms_pause", "ui.toggle_keyboard_captured", "ui.release_mouse", "ui.exit"
 	};
 	static const char *general_names[] = {
 		"Show Menu", "Quick Save", "Quick Load", "Toggle Fullscreen", "Soft Reset", "Reload Media",
-		"Internal Screenshot", "Toggle VGM Log", "SMS Pause", "Capture Keyboard", "Release Mouse"
+		"Internal Screenshot", "Toggle VGM Log", "SMS Pause", "Capture Keyboard", "Release Mouse", "Exit"
 	};
 	static const char *speed_binds[] = {
 		"ui.next_speed", "ui.prev_speed",
@@ -631,7 +631,8 @@
 		conf_names = tern_insert_ptr(conf_names, "ui.enter_debugger", "Enter CPU Debugger");
 		conf_names = tern_insert_ptr(conf_names, "ui.screenshot", "Take Screenshot");
 		conf_names = tern_insert_ptr(conf_names, "ui.vgm_log", "Toggle VGM Log");
-		conf_names = tern_insert_ptr(conf_names, "ui.exit", "Show Menu");
+		conf_names = tern_insert_ptr(conf_names, "ui.menu", "Show Menu");
+		conf_names = tern_insert_ptr(conf_names, "ui.exit", "Exit");
 		conf_names = tern_insert_ptr(conf_names, "ui.save_state", "Quick Save");
 		conf_names = tern_insert_ptr(conf_names, "ui.load_state", "Quick Load");
 		conf_names = tern_insert_ptr(conf_names, "ui.set_speed.0", "Set Speed 0");
@@ -698,9 +699,10 @@
 	static const char *emu_control[] = {
 		"ui.save_state",
 		"ui.load_state",
-		"ui.exit",
+		"ui.menu",
 		"ui.toggle_fullscreen",
 		"ui.screenshot",
+		"ui.exit",
 		"ui.release_mouse",
 		"ui.toggle_keyboard_captured"
 	};