Example #1
0
def getDefaultEmulator(systemName):
    system = get_system_config(systemName)
    if "emulator" not in system or system["emulator"] == "":
        eslog.log("no emulator defined. exiting.")
        raise Exception("No emulator found")

    return Emulator(name=systemName, config=system)
Example #2
0
def runCommand(command):
    global proc

    command.env.update(os.environ)
    eslog.log("command:" + str(command.array))
    eslog.log("env: "    + str(command.env))
    proc = subprocess.Popen(command.array, env=command.env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    exitcode = -1
    try:
        out, err = proc.communicate()
        exitcode = proc.returncode
        sys.stdout.write(out)
        sys.stderr.write(err)
    except:
        eslog("emulator exited")

    return exitcode
Example #3
0
def main(args):
    playersControllers = dict()
    if not args.demo:
        # 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: " + systemName)
    system = getDefaultEmulator(systemName)
    if system is None:
        eslog.log("no emulator defined. exiting.")
        return 1
    system.configure(args.emulator, args.core, args.ratio, args.netplay)

    # the resolution must be changed before configuration while the configuration may depend on it (ie bezels)
    newResolution = generators[system.config['emulator']].getResolution(system.config)
    exitCode = -1
    try:
        videoMode.changeResolution(newResolution)
        gameResolution = videoMode.getCurrentResolution()
        eslog.log("resolution: " + str(gameResolution["width"]) + "x" + str(gameResolution["height"]))

        # savedir: create the save directory is not already done
        dirname = os.path.join(recalboxFiles.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 newResolution != 'default':
            try:
                videoMode.resetResolution()
            except Exception:
                pass # don't fail
    # exit
    return exitCode
Example #4
0
    parser.add_argument("-p4nbaxes", help="player4 controller number of axes", type=str, required=False)
    parser.add_argument("-p5index", help="player5 controller index", type=int, required=False)
    parser.add_argument("-p5guid", help="player5 controller SDL2 guid", type=str, required=False)
    parser.add_argument("-p5name", help="player5 controller name", type=str, required=False)
    parser.add_argument("-p5devicepath", help="player5 controller device", type=str, required=False)
    parser.add_argument("-p5nbaxes", help="player5 controller number of axes", type=str, required=False)
    parser.add_argument("-system", help="select the system to launch", type=str, required=True)
    parser.add_argument("-rom", help="rom absolute path", type=str, required=True)
    parser.add_argument("-emulator", help="force emulator", type=str, required=False)
    parser.add_argument("-core", help="force emulator core", type=str, required=False)
    parser.add_argument("-ratio", help="force game ratio", type=str, required=False)
    parser.add_argument("-demo", help="mode demo", type=bool, required=False)
    parser.add_argument("-netplay", help="host/client", type=str, required=False)

    args = parser.parse_args()
    try:
        exitcode = -1
        exitcode = main(args)
    except Exception as e:
        eslog.log("configgen exception: ")
        eslog.logtrace()
    time.sleep(1) # this seems to be required so that the gpu memory is restituated and available for es
    eslog.log("Exiting configgen with status " + str(exitcode))
    exit(exitcode)

# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
def writeBezelConfig(bezel, retroarchConfig, systemName, rom, gameResolution):
    # disable the overlay
    # if all steps are passed, enable them
    retroarchConfig['input_overlay_hide_in_menu'] = "false"
    overlay_cfg_file = recalboxFiles.overlayConfigFile

    # bezel are disabled
    # default values in case something wrong append
    retroarchConfig['input_overlay_enable'] = "false"
    retroarchConfig['video_message_pos_x'] = 0.05
    retroarchConfig['video_message_pos_y'] = 0.05

    if bezel is None:
        return

    # by order choose :
    # rom name in the user directory (mario.png)
    # rom name in the system directory (mario.png)
    # system name in the user directory (gb.png)
    # system name in the system directory (gb.png)
    # default name (default.png)
    # else return
    romBase = os.path.splitext(
        os.path.basename(rom))[0]  # filename without extension
    overlay_info_file = recalboxFiles.overlayUser + "/" + bezel + "/games/" + rom + ".info"
    overlay_png_file = recalboxFiles.overlayUser + "/" + bezel + "/games/" + rom + ".png"
    if not (os.path.isfile(overlay_info_file)
            and os.path.isfile(overlay_png_file)):
        overlay_info_file = recalboxFiles.overlaySystem + "/" + bezel + "/games/" + rom + ".info"
        overlay_png_file = recalboxFiles.overlaySystem + "/" + bezel + "/games/" + rom + ".png"
        if not (os.path.isfile(overlay_info_file)
                and os.path.isfile(overlay_png_file)):
            overlay_info_file = recalboxFiles.overlayUser + "/" + bezel + "/systems/" + systemName + ".info"
            overlay_png_file = recalboxFiles.overlayUser + "/" + bezel + "/systems/" + systemName + ".png"
            if not (os.path.isfile(overlay_info_file)
                    and os.path.isfile(overlay_png_file)):
                overlay_info_file = recalboxFiles.overlaySystem + "/" + bezel + "/systems/" + systemName + ".info"
                overlay_png_file = recalboxFiles.overlaySystem + "/" + bezel + "/systems/" + systemName + ".png"
                if not (os.path.isfile(overlay_info_file)
                        and os.path.isfile(overlay_png_file)):
                    overlay_info_file = recalboxFiles.overlayUser + "/" + bezel + "/default.info"
                    overlay_png_file = recalboxFiles.overlayUser + "/" + bezel + "/default.png"
                    if not (os.path.isfile(overlay_info_file)
                            and os.path.isfile(overlay_png_file)):
                        overlay_info_file = recalboxFiles.overlaySystem + "/" + bezel + "/default.info"
                        overlay_png_file = recalboxFiles.overlaySystem + "/" + bezel + "/default.png"
                        if not (os.path.isfile(overlay_info_file)
                                and os.path.isfile(overlay_png_file)):
                            return
    infos = json.load(open(overlay_info_file))

    # if image is not at the correct size, find the correct size
    bezelNeedAdaptation = False
    if gameResolution["width"] != infos["width"] and gameResolution[
            "height"] != infos["height"]:
        bezelNeedAdaptation = True
        resolutionDir = str(gameResolution["width"]) + 'x' + str(
            gameResolution["height"])
        overlay_png_file = recalboxFiles.overlayUser + "/" + bezel + "/" + resolutionDir + "/games/" + rom + ".png"
        if not os.path.isfile(overlay_png_file):
            overlay_png_file = recalboxFiles.overlaySystem + "/" + bezel + "/" + resolutionDir + "/games/" + rom + ".png"
            if not os.path.isfile(overlay_png_file):
                overlay_png_file = recalboxFiles.overlayUser + "/" + bezel + "/" + resolutionDir + "/systems/" + systemName + ".png"
                if not os.path.isfile(overlay_png_file):
                    overlay_png_file = recalboxFiles.overlaySystem + "/" + bezel + "/" + resolutionDir + "/systems/" + systemName + ".png"
                    if not os.path.isfile(overlay_png_file):
                        overlay_png_file = recalboxFiles.overlayUser + "/" + bezel + "/" + resolutionDir + "/default.png"
                        if not os.path.isfile(overlay_png_file):
                            overlay_png_file = recalboxFiles.overlaySystem + "/" + bezel + "/" + resolutionDir + "/default.png"
                            if not os.path.isfile(overlay_png_file):
                                eslog.log("no bezel found: " +
                                          recalboxFiles.overlaySystem + "/" +
                                          bezel + "/" + resolutionDir +
                                          "/systems/" + systemName + ".png")
                                return

    retroarchConfig['input_overlay_enable'] = "true"
    retroarchConfig['input_overlay_scale'] = "1.0"
    retroarchConfig['input_overlay'] = overlay_cfg_file
    retroarchConfig['input_overlay_hide_in_menu'] = "true"
    retroarchConfig['input_overlay_opacity'] = infos["opacity"]
    retroarchConfig[
        'aspect_ratio_index'] = 22  # overwrited from the beginning of this file

    if bezelNeedAdaptation:
        wratio = gameResolution["width"] / float(infos["width"])
        hratio = gameResolution["height"] / float(infos["height"])
        retroarchConfig['custom_viewport_x'] = infos["left"] * wratio
        retroarchConfig['custom_viewport_y'] = infos["top"] * hratio
        retroarchConfig['custom_viewport_width'] = (
            infos["width"] - infos["left"] - infos["right"]) * wratio
        retroarchConfig['custom_viewport_height'] = (
            infos["height"] - infos["top"] - infos["bottom"]) * hratio
        retroarchConfig['video_message_pos_x'] = infos["messagex"] * wratio
        retroarchConfig['video_message_pos_y'] = infos["messagey"] * hratio
    else:
        retroarchConfig['custom_viewport_x'] = infos["left"]
        retroarchConfig['custom_viewport_y'] = infos["top"]
        retroarchConfig['custom_viewport_width'] = infos["width"] - infos[
            "left"] - infos["right"]
        retroarchConfig['custom_viewport_height'] = infos["height"] - infos[
            "top"] - infos["bottom"]
        retroarchConfig['video_message_pos_x'] = infos["messagex"]
        retroarchConfig['video_message_pos_y'] = infos["messagey"]

    writeBezelCfgConfig(overlay_cfg_file, overlay_png_file)
Example #6
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 = getDefaultEmulator(systemName)
    system.configure(args.emulator, args.core, args.ratio, args.netplay)
    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(gamestationFiles.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
Example #7
0
                        help="force emulator core",
                        type=str,
                        required=False)
    parser.add_argument("-ratio",
                        help="force game ratio",
                        type=str,
                        required=False)
    parser.add_argument("-netplay",
                        help="host/client",
                        type=str,
                        required=False)

    args = parser.parse_args()
    try:
        exitcode = -1
        exitcode = main(args)
    except Exception as e:
        eslog.log("configgen exception: ")
        eslog.logtrace()
    time.sleep(
        1
    )  # this seems to be required so that the gpu memory is restituated and available for es
    eslog.log("Exiting configgen with status {}".format(str(exitcode)))
    exit(exitcode)

# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4: