nepx / halfix

x86 PC emulator that runs both natively and in the browser, via WebAssembly
https://nepx.github.io/halfix-demo/
GNU General Public License v3.0
669 stars 86 forks source link

emscripten_load_state missing #15

Closed pgodwin closed 3 years ago

pgodwin commented 3 years ago

Hi there

Looks emscripten_load_state referenced in libhalfix.js is missing in emscripten.c ?

pgodwin commented 3 years ago

I quickly added in

EMSCRIPTEN_KEEPALIVE
void emscripten_load_state(void){
    state_read_from_file("");
}

Which seems to load state correctly. However, loading it with a drive image specified (http://localhost:8080/?hda=os2&savestate=states/os2) causes the XHR paths to be corrupted for subsequent disk access. Ie http://localhost:8080/%C2%88%7F%01%C2%88%7F%01%10/blk0000000b.bin.gz which obviously don't work

Using it without savestate= works, with the expected XHR URLS (Eg http://localhost:8080/os2/blk00000000.bin.gz). So I suspect something is getting overriden when state is loaded, but unsure where.

pgodwin commented 3 years ago

after an embarrassing amount of time trying to work this out, uncommenting this line fixed it. https://github.com/nepx/halfix/blob/92527759911370eacb4b520e83f21154fbb40ce9/src/drive.c#L565

nepx commented 3 years ago

Savestates were primarily used for debugging (shorten boot times) and added to the browser version as an afterthought. That's the reason behind the (currently unused) jszip.min.js dependency in index.html. Theoretically, they should work, but I've run into some problems regarding them. I tried it with Windows XP a few months ago and the whole system BSOD'ed on me after a few seconds, likely due to hard drive problems.

They work like a charm on the native version, provided that all settings are identical, but at the moment, they're not very "user-friendly," requiring you to comment/uncomment a preprocessor macro. Browser support has historically been much more flaky, but I'm also interested in getting savestates to work to speed up boot times.

pgodwin commented 3 years ago

They're quite handy :)

Here's OS2 2.0 which seems to work with Halfix. https://labs.obsoletemadness.com/labs/halfix/index.html?hda=os2&savestate=states/os2