Closed dimabubenok closed 2 years ago
Let me look into it, I would have to find a way to make retroarch reload its keybinds from the config file.
Hi, I also need that feature! 👍 BTW, could you explain a bit how did you "reverse-engineering" the generated core_libretro.js
file ? I realy want to use that generated script to add more features in JS like volume adjustment and so on.
You did a great job, right now you've coded the hardest part! 🎉
What do you mean, reverse-engineering? Please clarify.
I mean, how did you found the key steps and variables in order to properly load libretro, game data and config ?
Some functions look like black magic to me, in particular the FS.writeFile
parts.
For example :
https://github.com/BinBashBanana/webretro/blob/4c437f7a55cb2f6898fcf10d567fbc657435da6a/assets/base.js#L920-L925
Is there documentation somewhere explaining how the web version of RetroArch works ? Did you read the C code or the generated emscripten code or maybe both ? I'm just curious about the technique you used to tackle some of the main steps :)
Some of the code for creating this was already present here, but it was VERY outdated, so I had to change some things (for example, Emscripten changed Module.FS_X
to FS.X
, and the retroarch configuration file path changed from /etc/retroarch.cfg
to /home/web_user/retroarch/userdata/retroarch.cfg
). Most of these I had to figure out through trial and error.
Emscripten FS documentation can be found here for basic usage, and here for advanced functions.
RetroArch Documentation
RetroArch Repository
The web version of retroarch essentially functions the same as any other unix retroarch.
You may also see calls to functions such as Module._cmd_save_state()
, these are direct calls to C functions, as specified in EXPORTED_FUNCTIONS
here
https://github.com/BinBashBanana/webretro/blob/4c437f7a55cb2f6898fcf10d567fbc657435da6a/source/overrides/RetroArch/Makefile.emscripten#L76 and here, to have the actual function declarations
https://github.com/BinBashBanana/webretro/blob/4c437f7a55cb2f6898fcf10d567fbc657435da6a/source/overrides/RetroArch/frontend/drivers/platform_emscripten.c#L53-L86
The game data is loaded automatically by specifying the rom path as the first startup argument (because the rom file is always created in the filesystem as rom.bin
, there is no need for it to ever change)
https://github.com/BinBashBanana/webretro/blob/4c437f7a55cb2f6898fcf10d567fbc657435da6a/assets/base.js#L939
For loading the cores, each core is separately contained in its respective .js and .wasm files. There is no emscripten-generated code present until the .js file is added to the page (via the getScript function).
P.S. It would be impossible to read and understand the emscripten-generated code ;)
You are awesome ! Thank you very much for the explanation ;)
@dimabubenok I found a way to update the configuration during emulation.
This is a bit obscure and I only tested it with the snes9x
core.
FS.writeFile('/home/web_user/retroarch/userdata/retroarch.cfg', updatedConfig);
wasmTable.get(108)();
If you try this, please let me know if it is also available with the other cores ;)
It works nice on snes9x, although I didn't test the other cores, I think it is almost always a really bad idea to directly call unidentified wasm functions from javascript. I just did some digging, and I should be able to get something set up that should work nicely, such as:
Module._cmd_reload_config();
I'll keep you posted.
I figured it out! Expect a release with the ability to change keybinds and download screenshots within the next month, at the latest. If you have any suggestions, feel free to leave them here!
It sounds promising. Waiting for an example
I'll send a screenshot when I have it looking nicer :)
Preview for the keybind manager
I'm getting window.Module._cmd_reload_config is not a function
. Did you update the C code to export that new function ?
I did, but I haven't committed the update yet. On my end, the keybind manager is done, and I'm working on the screenshot one. I will send a screenshot of it when I have it looking better.
I'm facing a keybinding issue : I can't bind any of the numpad keys. Are you able to do this or do you know what type of value RetroArch needs ?
@NicolasRoehm keypadX
(e.g. keypad1
)
Thank you very much, it's working ! 😍 Now I'm seeing that RetroArch is QWERTY only 😭
That's too bad :( however it is likely that it won't be a problem on the WASM emulator, because of how the keys are handled.
I might have to extend my deadline, I have been pretty busy with school.
Preview 2
Sorry it took me so long... But 6.4 is finally out! I finally got a chance to work on it during the break, and I also added a save/state manager. Enjoy!
Hi! Is there any way to change configuration after starting emulation? I need to change gamepad configuration. I know that this can be done through the menu, but can it be done through javascript?