LibRetro's Genesis emulator can run on the GCW0 handheld console, & I'll now study its entrypoint for this host.
It first registers a shutdown callback which saves the simulated-cartridge's RAM to a file if appropriate (3 conditions), invokes some of the core finalizers, & invokes some of SDL's finalizers.
If no game's specified it then displays a message box describing how to invoke this command. Otherwise it opens an error log, creates a bunch of directories, ...
1/?