def start_rom(args, maxnbplayers, rom, romConfiguration): # controllers playersControllers = dict() controllersInput = [] for p in range(1, maxnbplayers+1): ci = {} ci["index"] = getattr(args, "p{}index" .format(p)) ci["guid"] = getattr(args, "p{}guid" .format(p)) ci["name"] = getattr(args, "p{}name" .format(p)) ci["devicepath"] = getattr(args, "p{}devicepath".format(p)) ci["nbbuttons"] = getattr(args, "p{}nbbuttons" .format(p)) ci["nbhats"] = getattr(args, "p{}nbhats" .format(p)) ci["nbaxes"] = getattr(args, "p{}nbaxes" .format(p)) controllersInput.append(ci) # Read the controller configuration playersControllers = controllers.loadControllerConfig(controllersInput) # find the system to run systemName = args.system eslog.debug("Running system: {}".format(systemName)) system = Emulator(systemName, romConfiguration) if args.emulator is not None: system.config["emulator"] = args.emulator system.config["emulator-forced"] = True if args.core is not None: system.config["core"] = args.core system.config["core-forced"] = True debugDisplay = system.config.copy() if "retroachievements.password" in debugDisplay: debugDisplay["retroachievements.password"] = "******" eslog.debug("Settings: {}".format(debugDisplay)) if "emulator" in system.config and "core" in system.config: eslog.debug("emulator: {}, core: {}".format(system.config["emulator"], system.config["core"])) else: if "emulator" in system.config: eslog.debug("emulator: {}".format(system.config["emulator"])) # the resolution must be changed before configuration while the configuration may depend on it (ie bezels) wantedGameMode = generators[system.config['emulator']].getResolutionMode(system.config) systemMode = videoMode.getCurrentMode() resolutionChanged = False mouseChanged = False exitCode = -1 try: # lower the resolution if mode is auto newsystemMode = systemMode # newsystemmode is the mode after minmax (ie in 1K if tv was in 4K), systemmode is the mode before (ie in es) if system.config["videomode"] == "" or system.config["videomode"] == "default": eslog.debug("minTomaxResolution") eslog.debug("video mode before minmax: {}".format(systemMode)) videoMode.minTomaxResolution() newsystemMode = videoMode.getCurrentMode() if newsystemMode != systemMode: resolutionChanged = True eslog.debug("current video mode: {}".format(newsystemMode)) eslog.debug("wanted video mode: {}".format(wantedGameMode)) if wantedGameMode != 'default' and wantedGameMode != newsystemMode: videoMode.changeMode(wantedGameMode) resolutionChanged = True gameResolution = videoMode.getCurrentResolution() # if resolution is reversed (ie ogoa boards), reverse it in the gameResolution to have it correct if system.isOptSet('resolutionIsReversed') and system.getOptBoolean('resolutionIsReversed') == True: x = gameResolution["width"] gameResolution["width"] = gameResolution["height"] gameResolution["height"] = x eslog.debug("resolution: {}x{}".format(str(gameResolution["width"]), str(gameResolution["height"]))) # savedir: create the save directory if not already done dirname = os.path.join(batoceraFiles.savesDir, system.name) if not os.path.exists(dirname): os.makedirs(dirname) # core effectiveCore = "" if "core" in system.config and system.config["core"] is not None: effectiveCore = system.config["core"] effectiveRom = "" effectiveRomConfiguration = "" if rom is not None: effectiveRom = rom effectiveRomConfiguration = romConfiguration # network options if args.netplaymode is not None: system.config["netplay.mode"] = args.netplaymode if args.netplaypass is not None: system.config["netplay.password"] = args.netplaypass if args.netplayip is not None: system.config["netplay.server.ip"] = args.netplayip if args.netplayport is not None: system.config["netplay.server.port"] = args.netplayport # autosave arguments if args.state_slot is not None: system.config["state_slot"] = args.state_slot if args.autosave is not None: system.config["autosave"] = args.autosave if generators[system.config['emulator']].getMouseMode(system.config): mouseChanged = True videoMode.changeMouse(True) # SDL VSync is a big deal on OGA and RPi4 if system.isOptSet('sdlvsync') and system.getOptBoolean('sdlvsync') == False: system.config["sdlvsync"] = '0' else: system.config["sdlvsync"] = '1' os.environ.update({'SDL_RENDER_VSYNC': system.config["sdlvsync"]}) # run a script before emulator starts callExternalScripts("/usr/share/batocera/configgen/scripts", "gameStart", [systemName, system.config['emulator'], effectiveCore, effectiveRom]) callExternalScripts("/userdata/system/scripts", "gameStart", [systemName, system.config['emulator'], effectiveCore, effectiveRom]) # run the emulator try: Evmapy.start(systemName, system.config['emulator'], effectiveCore, effectiveRomConfiguration, playersControllers) # change directory if wanted executionDirectory = generators[system.config['emulator']].executionDirectory(system.config, effectiveRom) if executionDirectory is not None: os.chdir(executionDirectory) cmd = generators[system.config['emulator']].generate(system, rom, playersControllers, gameResolution) if system.isOptSet('hud_support') and system.getOptBoolean('hud_support') == True: hud_bezel = getHudBezel(system, rom, gameResolution) if (system.isOptSet('hud') and system.config["hud"] != "" and system.config["hud"] != "none") or hud_bezel is not None: gameinfos = extractGameInfosFromXml(args.gameinfoxml) cmd.env["MANGOHUD_DLSYM"] = "1" hudconfig = getHudConfig(system, args.systemname, system.config['emulator'], effectiveCore, rom, gameinfos, hud_bezel) with open('/var/run/hud.config', 'w') as f: f.write(hudconfig) cmd.env["MANGOHUD_CONFIGFILE"] = "/var/run/hud.config" if generators[system.config['emulator']].hasInternalMangoHUDCall() == False: cmd.array.insert(0, "mangohud") exitCode = runCommand(cmd) finally: Evmapy.stop() # run a script after emulator shuts down callExternalScripts("/userdata/system/scripts", "gameStop", [systemName, system.config['emulator'], effectiveCore, effectiveRom]) callExternalScripts("/usr/share/batocera/configgen/scripts", "gameStop", [systemName, system.config['emulator'], effectiveCore, effectiveRom]) finally: # always restore the resolution if resolutionChanged: try: videoMode.changeMode(systemMode) except Exception: pass # don't fail if mouseChanged: try: videoMode.changeMouse(False) except Exception: pass # don't fail # exit return exitCode
def main(args, maxnbplayers): playersControllers = dict() controllersInput = [] for p in range(1, maxnbplayers + 1): ci = {} ci["index"] = getattr(args, "p{}index".format(p)) ci["guid"] = getattr(args, "p{}guid".format(p)) ci["name"] = getattr(args, "p{}name".format(p)) ci["devicepath"] = getattr(args, "p{}devicepath".format(p)) ci["nbbuttons"] = getattr(args, "p{}nbbuttons".format(p)) ci["nbhats"] = getattr(args, "p{}nbhats".format(p)) ci["nbaxes"] = getattr(args, "p{}nbaxes".format(p)) controllersInput.append(ci) # Read the controller configuration playersControllers = controllers.loadControllerConfig(controllersInput) # find the system to run systemName = args.system eslog.log("Running system: {}".format(systemName)) system = Emulator(systemName, args.rom) if args.emulator is not None: system.config["emulator"] = args.emulator system.config["emulator-forced"] = True if args.core is not None: system.config["core"] = args.core system.config["core-forced"] = True debugDisplay = system.config.copy() if "retroachievements.password" in debugDisplay: debugDisplay["retroachievements.password"] = "******" eslog.debug("Settings: {}".format(debugDisplay)) if "emulator" in system.config and "core" in system.config: eslog.log("emulator: {}, core: {}".format(system.config["emulator"], system.config["core"])) else: if "emulator" in system.config: eslog.log("emulator: {}".format(system.config["emulator"])) # the resolution must be changed before configuration while the configuration may depend on it (ie bezels) wantedGameMode = generators[system.config['emulator']].getResolutionMode( system.config) systemMode = videoMode.getCurrentMode() resolutionChanged = False mouseChanged = False exitCode = -1 try: # lower the resolution if mode is auto newsystemMode = systemMode # newsystemmode is the mode after minmax (ie in 1K if tv was in 4K), systemmode is the mode before (ie in es) if system.config["videomode"] == "" or system.config[ "videomode"] == "default": eslog.log("minTomaxResolution") eslog.log("video mode before minmax: {}".format(systemMode)) videoMode.minTomaxResolution() newsystemMode = videoMode.getCurrentMode() if newsystemMode != systemMode: resolutionChanged = True eslog.log("current video mode: {}".format(newsystemMode)) eslog.log("wanted video mode: {}".format(wantedGameMode)) if wantedGameMode != 'default' and wantedGameMode != newsystemMode: videoMode.changeMode(wantedGameMode) resolutionChanged = True gameResolution = videoMode.getCurrentResolution() # if resolution is reversed (ie ogoa boards), reverse it in the gameResolution to have it correct if system.isOptSet('resolutionIsReversed') and system.getOptBoolean( 'resolutionIsReversed') == True: x = gameResolution["width"] gameResolution["width"] = gameResolution["height"] gameResolution["height"] = x eslog.log("resolution: {}x{}".format(str(gameResolution["width"]), str(gameResolution["height"]))) # savedir: create the save directory if not already done dirname = os.path.join(batoceraFiles.savesDir, system.name) if not os.path.exists(dirname): os.makedirs(dirname) # core effectiveCore = "" if "core" in system.config and system.config["core"] is not None: effectiveCore = system.config["core"] effectiveRom = "" if args.rom is not None: effectiveRom = args.rom # network options if args.netplaymode is not None: system.config["netplay.mode"] = args.netplaymode if args.netplaypass is not None: system.config["netplay.password"] = args.netplaypass if args.netplayip is not None: system.config["netplay.server.ip"] = args.netplayip if args.netplayport is not None: system.config["netplay.server.port"] = args.netplayport # autosave arguments if args.state_slot is not None: system.config["state_slot"] = args.state_slot if args.autosave is not None: system.config["autosave"] = args.autosave if generators[system.config['emulator']].getMouseMode(system.config): mouseChanged = True videoMode.changeMouse(True) # run a script before emulator starts callExternalScripts("/usr/share/batocera/configgen/scripts", "gameStart", [ systemName, system.config['emulator'], effectiveCore, effectiveRom ]) callExternalScripts("/userdata/system/scripts", "gameStart", [ systemName, system.config['emulator'], effectiveCore, effectiveRom ]) # run the emulator try: Evmapy.start(systemName, system.config['emulator'], effectiveCore, effectiveRom, playersControllers) exitCode = runCommand( generators[system.config['emulator']].generate( system, args.rom, playersControllers, gameResolution)) finally: Evmapy.stop() # run a script after emulator shuts down callExternalScripts("/userdata/system/scripts", "gameStop", [ systemName, system.config['emulator'], effectiveCore, effectiveRom ]) callExternalScripts("/usr/share/batocera/configgen/scripts", "gameStop", [ systemName, system.config['emulator'], effectiveCore, effectiveRom ]) finally: # always restore the resolution if resolutionChanged: try: videoMode.changeMode(systemMode) except Exception: pass # don't fail if mouseChanged: try: videoMode.changeMouse(False) except Exception: pass # don't fail # exit return exitCode