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/?
... populates a config struct with defaults & attempts to read overrides from a file, copies the filename stripping the extension, carefully reads in the BIOS to interpret, initializes SDL or exits with a message box displaying the error, initializes SDL subsystems (joystick, video, sound, & sync), with a lock held the output in a bitmap object with structural metadata, loads the game's ROM dump via core code, & initializes the core audio emulator followed by the rest of the core.
2/?