changeset 2658:99297d5f4c5d

Persist save states and config in emscripten build via IDBFS module
author Michael Pavone <pavone@retrodev.com>
date Tue, 04 Mar 2025 00:05:12 -0800
parents d1f689ed3956
children e8d37b8fa532
files Makefile bindings.c bindings.h blastem.c emscripten_pre.js
diffstat 5 files changed, 29 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Mon Mar 03 22:11:34 2025 -0800
+++ b/Makefile	Tue Mar 04 00:05:12 2025 -0800
@@ -121,7 +121,7 @@
 CFLAGS+= --use-port=sdl2
 LDFLAGS+= --use-port=sdl2 --embed-file rom.db --embed-file default.cfg --embed-file systems.cfg \
  --embed-file shaders/ --embed-file images/ --embed-file DroidSans.ttf -sEXPORTED_FUNCTIONS=_main,_handle_chooser_result \
- -sEXPORTED_RUNTIME_METHODS=ccall,cwrap -sINITIAL_HEAP=50331648
+ -sEXPORTED_RUNTIME_METHODS=ccall,cwrap,callMain -sINITIAL_HEAP=50331648 --pre-js emscripten_pre.js -lidbfs.js
 EXE:=.html
 else #CPU=wasm
 
--- a/bindings.c	Mon Mar 03 22:11:34 2025 -0800
+++ b/bindings.c	Tue Mar 04 00:05:12 2025 -0800
@@ -206,6 +206,11 @@
 	content_binds_enabled = enabled;
 }
 
+uint8_t get_content_binding_state(void)
+{
+	return content_binds_enabled;
+}
+
 void bindings_set_joy_state(int joystick, uint8_t enabled)
 {
 	if (joystick >= MAX_JOYSTICKS || joystick < 0) {
--- a/bindings.h	Mon Mar 03 22:11:34 2025 -0800
+++ b/bindings.h	Tue Mar 04 00:05:12 2025 -0800
@@ -30,6 +30,7 @@
 void bindings_release_capture(void);
 void bindings_reacquire_capture(void);
 void set_content_binding_state(uint8_t enabled);
+uint8_t get_content_binding_state(void);
 void bindings_set_joy_state(int joystick, uint8_t enabled);
 
 #endif //BINDINGS_H_
--- a/blastem.c	Mon Mar 03 22:11:34 2025 -0800
+++ b/blastem.c	Tue Mar 04 00:05:12 2025 -0800
@@ -159,26 +159,27 @@
 #ifndef DISABLE_NUKLEAR
 	static uint8_t was_menu;
 	if (use_nuklear) {
-		if (menu && !was_menu) {
-			ui_enter();
-		} else if (!menu && was_menu) {
-			ui_exit();
-		}
 		if (menu) {
+			if (!was_menu) {
+				ui_enter();
+			}
+			was_menu = menu;
 			render_update_display();
+			menu = !get_content_binding_state();
+			if (!menu) {
+				ui_exit();
+				return;
+			}
+		} else {
+			was_menu = menu;
 		}
 	}
 #endif
 	if (!current_system && game_system) {
 		current_system = game_system;
-		menu = 0;
-#ifndef DISABLE_NUKLEAR
-		was_menu = 0;
-		ui_exit();
-#endif
 	}
 	if (current_system) {
-		if (system_started && render_is_audio_sync()) {
+		if (system_started && !current_system->force_release && render_is_audio_sync()) {
 			if (all_sources_ready()) {
 				return;
 			}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/emscripten_pre.js	Tue Mar 04 00:05:12 2025 -0800
@@ -0,0 +1,10 @@
+Module.noInitialRun = true;
+Module.preRun = [() => {
+	FS.mount(IDBFS, {autoPersist: true}, '/home/web_user');
+	FS.syncfs(true, (err) => {
+		if (err) {
+			console.log('Error loading IDBFS', err);
+		}
+		Module.callMain();
+	});
+}];