# HG changeset patch # User Michael Pavone # Date 1741075512 28800 # Node ID 99297d5f4c5d022e4bd3745e09b9e79703377972 # Parent d1f689ed395635c25c15831915a96df2604dfff9 Persist save states and config in emscripten build via IDBFS module diff -r d1f689ed3956 -r 99297d5f4c5d Makefile --- 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 diff -r d1f689ed3956 -r 99297d5f4c5d bindings.c --- 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) { diff -r d1f689ed3956 -r 99297d5f4c5d bindings.h --- 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_ diff -r d1f689ed3956 -r 99297d5f4c5d blastem.c --- 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; } diff -r d1f689ed3956 -r 99297d5f4c5d emscripten_pre.js --- /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(); + }); +}];