Under the hood
How does Nostalgist.js work? There are several steps while launching an Emulator.
Step one
Load the emulator and the ROM.
Nostalgist.js itself doesn’t contain any emulators, but it has a resonable default options, so official emulators built with Emscripten and provided by RetroArch’s buildbot. It can also load some homebrew games from retrobrews project without additional configuration.
By default, cores will be loaded via fetch from retroarch-emscripten-build through jsDelivr. For example, the fceumm core, an NES emulator, will be loaded from these URLs:
- https://cdn.jsdelivr.net/gh/arianrhodsandlot/retroarch-emscripten-build@v1.19.1/retroarch/fceumm_libretro.js
- https://cdn.jsdelivr.net/gh/arianrhodsandlot/retroarch-emscripten-build@v1.19.1/retroarch/fceumm_libretro.wasm
Games from retrobrews are loaded in a similar way too. And of course you can also load all the nessasary contents by yourself.
If you own a server and your ROM files are hosted there, you can also load them by something like:
Make sure your server have configured the CORS headers properly.
Step two
Prepare a virtual file system.
We use BrowserFS’s MemoryFS
to create a virtual file system. The files loaded by step one will be written here as well.
Step three
Launch RetroArch with the virtual file system and the canvas element we specified in the code.
After launching, Nostalgist.js can comunicate with RetroArch in these ways:
- Read or write files to the virtual file system.
- Call functions exported by Emscripten. If the official builds are being used, the functions are listed in the
Makefile
for theses builds. - Send commands to the process of RetroArch. All available commands are listed in the document of RetroArch.