Esempio n. 1
0
def main(args):
    playersControllers = dict()
    # Read the controller configuration
    playersControllers = controllers.loadControllerConfig(
        args.p1index, args.p1guid, args.p1name, args.p1devicepath,
        args.p1nbaxes, args.p2index, args.p2guid, args.p2name,
        args.p2devicepath, args.p2nbaxes, args.p3index, args.p3guid,
        args.p3name, args.p3devicepath, args.p3nbaxes, args.p4index,
        args.p4guid, args.p4name, args.p4devicepath, args.p4nbaxes,
        args.p5index, args.p5guid, args.p5name, args.p5devicepath,
        args.p5nbaxes)
    # find the system to run
    systemName = args.system
    eslog.log("Running system: {}".format(systemName))
    system = Emulator(systemName)
    eslog.debug("Settings: {}".format(system.config))
    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
    exitCode = -1
    try:
        eslog.log("current video mode: {}".format(systemMode))
        eslog.log("wanted video mode: {}".format(wantedGameMode))
        if wantedGameMode != 'default' and wantedGameMode != systemMode:
            videoMode.changeMode(wantedGameMode)
            resolutionChanged = True
        gameResolution = videoMode.getCurrentResolution()
        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)

        # run the emulator
        exitCode = runCommand(generators[system.config['emulator']].generate(
            system, args.rom, playersControllers, gameResolution))
    finally:
        # always restore the resolution
        if resolutionChanged:
            try:
                videoMode.changeMode(systemMode)
            except Exception:
                pass  # don't fail
    # exit
    return exitCode
Esempio n. 2
0
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)

    system.config["emulator-forced"] = False
    system.config["core-forced"] = False
    if args.emulator is not None:
        system.config["emulator"] = args.emulator
        system.config[
            "emulator-forced"] = True  # tip to indicated that the emulator was forced
    if args.core is not None:
        system.config["core"] = args.core
        system.config["core-forced"] = True

    eslog.debug("Settings: {}".format(system.config))
    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
    exitCode = -1
    try:
        eslog.log("current video mode: {}".format(systemMode))
        eslog.log("wanted video mode: {}".format(wantedGameMode))
        if wantedGameMode != 'default' and wantedGameMode != systemMode:
            videoMode.changeMode(wantedGameMode)
            resolutionChanged = True
        gameResolution = videoMode.getCurrentResolution()
        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.netplayspectator is not None:
            system.config["netplay.spectator"] = args.netplayspectator
        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

        # 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
        exitCode = runCommand(generators[system.config['emulator']].generate(
            system, args.rom, playersControllers, gameResolution))

        # 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
    # exit
    return exitCode
Esempio n. 3
0
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
Esempio n. 4
0
def main(args):
    playersControllers = dict()
    # Read the controller configuration
    playersControllers = controllers.loadControllerConfig(
        args.p1index, args.p1guid, args.p1name, args.p1devicepath,
        args.p1nbaxes, args.p2index, args.p2guid, args.p2name,
        args.p2devicepath, args.p2nbaxes, args.p3index, args.p3guid,
        args.p3name, args.p3devicepath, args.p3nbaxes, args.p4index,
        args.p4guid, args.p4name, args.p4devicepath, args.p4nbaxes,
        args.p5index, args.p5guid, args.p5name, args.p5devicepath,
        args.p5nbaxes)
    # 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
    if args.core is not None:
        system.config["core"] = args.core

    eslog.debug("Settings: {}".format(system.config))
    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
    exitCode = -1
    try:
        eslog.log("current video mode: {}".format(systemMode))
        eslog.log("wanted video mode: {}".format(wantedGameMode))
        if wantedGameMode != 'default' and wantedGameMode != systemMode:
            videoMode.changeMode(wantedGameMode)
            resolutionChanged = True
        gameResolution = videoMode.getCurrentResolution()
        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.netplayip is not None:
            system.config["netplay.server.ip"] = args.netplayip
        if args.netplayport is not None:
            system.config["netplay.server.port"] = args.netplayport

        # run a script before emulator starts
        callExternalScripts("/userdata/system/scripts", "gameStart", [
            systemName, system.config['emulator'], effectiveCore, effectiveRom
        ])

        # run the emulator
        exitCode = runCommand(generators[system.config['emulator']].generate(
            system, args.rom, playersControllers, gameResolution))

        # run a script after emulator shuts down
        callExternalScripts("/userdata/system/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
    # exit
    return exitCode