Esempio n. 1
0
class ports(emulator):
    @staticmethod
    def get_system_list():
        return ["ports"]

    def pre_configure(self):
        self.p_sPort = None
        logging.info("INFO: Script for port: {%s}" % self.m_sFilePath)
        with open(self.m_sFilePath, "r") as f:
            for line in f:
                if "_PORT_" in line:
                    string = line.split("_PORT_")[1].strip()
                    self.p_sPort = re.sub(r' +', " ",
                                          string).split(' ')[0].strip()
                    self.p_sPort = self.p_sPort.replace('"', '')
                    self.p_sPort = self.p_sPort.replace("'", '')
                    # try to get if rom is needed on bash batch launcher
                    try:
                        self.p_sPortROM = re.sub(r' +', " ",
                                                 string).split(' ')[1:]
                        self.p_sPortROM = " ".join(self.p_sPortROM)
                        self.p_sPortROM = self.p_sPortROM.replace('"', '')
                        self.p_sPortROM = self.p_sPortROM.replace("'", '')
                    except Exception as e:
                        self.p_sPortROM = ""
                    logging.info("INFO: Port ID: {%s}" % self.p_sPort)
                    logging.info("INFO: Port ROM: {%s}" % self.p_sPortROM)
                    break
        if not self.p_sPort: self.panic("Don't valid port game")
        p_sPortPath = os.path.join(self.m_sSystem, self.p_sPort,
                                   "emulators.cfg")
        self.m_sCfgSystemPath = os.path.join(RETROPIE_CFG_PATH, p_sPortPath)
        logging.info("INFO: emulators.cfg for this port: {%s}" %
                     self.m_sCfgSystemPath)

    def direct_start(self):
        """ launch_core: run emulator without runcommand!"""
        if self.m_sFileNameVar and self.m_sFileNameVar in self.m_sCleanLaunch:
            self.m_sCleanLaunch = self.m_sCleanLaunch.replace(
                self.m_sFileNameVar, "\"%s\"" % self.p_sPortROM)
        commandline = self.m_sCleanLaunch
        if not os.path.exists("/tmp/retroarch"):
            os.system("mkdir /tmp/retroarch")
        self.m_oRunProcess = subprocess.Popen(commandline, shell=True)
        logging.info("INFO: Subprocess running: %s", commandline)

    def screen_set(self):
        self.m_oCRT = CRT(self.p_sPort)
        self.m_oCRT.screen_calculated(DB_PORTS)
        self.m_oBlackScreen.fill()
        logging.info("INFO: clean: %s", TMP_SLEEPER_FILE)
        remove_file(TMP_SLEEPER_FILE)

    def runcommand_start(self):
        """ launch_core: run emulator!"""
        commandline = "bash \"%s\"" % self.m_sFilePath
        self.m_oRunProcess = subprocess.Popen(shlex.split(commandline),
                                              shell=False)
        logging.info("INFO: Subprocess running: %s", commandline)
        self.runcommand_wait()
def launch_test_suite():
    global oCRT
    ra_version_fixes(RA_MD_CFG_FILE2)
    oCRT = CRT("megadrive")
    oCRT.screen_calculated(CRT_DB_SYSTEMS_FILE)
    commandline = "%s -L %s " % (RA_BIN_FILE, RA_MD_CORE_FILE)
    commandline += "--config %s " % RA_MD_CFG_FILE1
    commandline += "--appendconfig %s " % RA_MD_CFG_FILE2
    commandline += "\"%s\" " % TEST_SUITE_FILE
    commandline += "> /dev/null 2>&1"
    launch_application(commandline, True)
 def panic(self, p_sErrorLine1, p_sErrorLine2="-", p_bForceQuit=True):
     """ stop the program and show error to the user """
     logging.error("PANIC: %s" % p_sErrorLine1)
     CRT().screen_restore()
     something_is_bad(p_sErrorLine1, p_sErrorLine2)
     if p_bForceQuit:
         logging.error("EXIT: crt_launcher forced")
         self.__clean()
         sys.exit(1)
Esempio n. 4
0
def run(sCommandline, sDBSys=None):
    oCRT = None
    if sDBSys:
        oCRT = CRT(sDBSys)
        oCRT.screen_calculated(CRT_DB_SYSTEMS_FILE)
    oRunProcess = subprocess.Popen(shlex.split(sCommandline), shell=False)
    iExitCode = oRunProcess.wait()
    if oCRT:
        oCRT.screen_restore()
def launch_credits():
    global oCRT
    global oBlackScreen
    global iExitCode
    ra_version_fixes(RA_GBA_CFG_FILE2)
    oCRT = CRT(sSystem)
    oBlackScreen = HideScreen()
    oBlackScreen.fill()
    oCRT.screen_calculated(CRT_DB_SYSTEMS_FILE)
    commandline = "%s -L %s " % (RA_BIN_FILE, RA_GBA_CORE_FILE)
    commandline += "--config %s " % RA_GBA_CFG_FILE1
    commandline += "--appendconfig %s " % RA_GBA_CFG_FILE2
    commandline += "\"%s\" " % ROM_FILE
    commandline += "> /dev/null 2>&1"
    oRunProcess = subprocess.Popen(commandline, shell=True)
    iExitCode = oRunProcess.wait()
    oCRT.screen_restore()
Esempio n. 6
0
 def create_arcade_config(self):
     self.core_database()
     self.m_oCRT = CRT(self.m_sGameName)
     self.m_dVideo = self.m_oCRT.arcade_data(self.m_sArcadeDB)
     self.arcade_encapsulator()
     self.core_config()    
Esempio n. 7
0
class arcade(emulator):
    m_sArcadeDB = ""
    m_lTimingData = []
    m_dVideo = {}

    m_bRndCoreCheck = False # first core emulation check
    m_sRndCore01  = ""  # first core selected before runcommand
    m_sRndCore02  = ""  # second core selected after runcommand

    m_iSide = 0
    cfg_encap = ""
    cfg_offsetx = 0
    cfg_offsety = 0
    cfg_hres = 0
    cfg_vres = 0
    cfg_iscale = "false"
    cfg_ghres = 0 #Real Horizontal Resolution of the game
    
    m_sTitEnc = "Arcade Encapsulator"
    m_lOptEnc = [("Play CROPPED", "CROPPED"),
                 ("Play FORCED", "FORCED")]

    def screen_prepare(self):
        self.m_iSide = get_side()
        self.core_round_checks()

    def start(self):
        if self.m_bFastBoot: 
            super(arcade, self).start()
        else:
            self.runcommand_start()
            self.emulatorcfg_check_or_die()
            self.screen_set()

    def screen_set(self):
        self.core_round_checks()
        self.m_oCRT.arcade_set()

    def core_round_checks(self):
        # first round of core check - before runcommand
        if not self.m_bRndCoreCheck:
            self.m_sRndCore01 = self.m_sSelCore
            self.create_arcade_config()
            self.m_bRndCoreCheck = True # identifying first round
        # second round of core check - after runcommand
        else:
            self.m_sRndCore02 = self.m_sSelCore
            if self.m_sRndCore01 != self.m_sRndCore02:
                logging.info("INFO: core selection changed during " + \
                             "runcomand execution, changing " + \
                             "configuration")
                self.create_arcade_config()

    def create_arcade_config(self):
        self.core_database()
        self.m_oCRT = CRT(self.m_sGameName)
        self.m_dVideo = self.m_oCRT.arcade_data(self.m_sArcadeDB)
        self.arcade_encapsulator()
        self.core_config()    

    def core_config(self):
        #Check if libretro core of advmame is selected whitin
        #arcade system to generate configuration
        if "lr-" in self.m_sSelCore:
            logging.info("INFO: generating retroarch configuration " + \
                         "for ARCADE binary selected (%s)" % self.m_sSelCore)
            self.ra_config_generate()
        elif "advmame" in self.m_sSelCore:
            logging.info("INFO: generating advmame configuration " + \
                         "for ARCADE binary selected (%s)" % self.m_sSelCore)
            self.adv_config_generate()

    def core_database(self):
        self.m_sArcadeDB = DB_MAME078_FILE # mame2003
        if "2000" in self.m_sSelCore:
            self.m_sArcadeDB = DB_MAME037_FILE
        elif "2010" in self.m_sSelCore:
            self.m_sArcadeDB = DB_MAME139_FILE
        elif "fbneo" in self.m_sSelCore:
            self.m_sArcadeDB = DB_FINALBURN_FILE
        elif "fbalpha" in self.m_sSelCore:
            self.m_sArcadeDB = DB_FINALBURN_FILE
        elif "advmame" in self.m_sSelCore:
            self.m_sArcadeDB = DB_ADVMAME_FILE
        logging.info("CURRENT binary: {%s}; database: {%s}" % \
                    (self.m_sSelCore, self.m_sArcadeDB))

    def ra_config_generate(self):
        self.cfg_hres = self.m_dVideo["H_Res"]
        self.cfg_vres = self.m_dVideo["V_Res"]
        self.cfg_ghres = self.m_dVideo["Game_H_Res"]
        self.cfg_offsetx = 0
        if self.m_oCRT.m_sSide_Game != 'V':
            if self.m_bIScale:
                self.ra_integer_calculator()
            self.ra_config_create()
        else:
            if self.m_iSide != 0:
                if self.m_iSide == 1:
                    self.m_oCRT.m_sSide_Game = 'V1'
                elif self.m_iSide == 3:
                    self.m_oCRT.m_sSide_Game = 'V3'
                self.ra_config_create()
            else:
                self.m_oCRT.m_sSide_Game = 'H'
                self.cfg_hres = 1160
                #Force vertical resolution to 224 in rotated games
                self.m_dVideo["V_Res"] = 224
                self.cfg_vres = self.m_dVideo["V_Res"]
                self.cfg_offsetx = 360
                self.cfg_offsety = 0
                self.ra_config_create(p_bSmooth = True)
                    
    def ra_config_create(self, p_bSmooth = False):
        self.ra_config_write(p_bSmooth)

    def ra_config_write(self, p_bSmooth):
        logging.info("result - w %s, h %s (%s/%s) - scale integer{%s} - %sHz - s[%s] smooth{%s}" % (
            self.cfg_hres,
            self.cfg_vres,
            self.cfg_offsetx,
            self.cfg_offsety,
            self.cfg_iscale,
            self.m_dVideo["R_Rate"],
            self.m_oCRT.m_sSide_Game,
            p_bSmooth
            ))
        # copy cfg base
        add_line(self.m_sCustomRACFG, 'custom_viewport_width = "%s"' % self.cfg_hres)
        add_line(self.m_sCustomRACFG, 'custom_viewport_height = "%s"' % self.cfg_vres)
        add_line(self.m_sCustomRACFG, 'custom_viewport_x = "%s"' % self.cfg_offsetx)
        add_line(self.m_sCustomRACFG, 'custom_viewport_y = "%s"' % self.cfg_offsety)
        add_line(self.m_sCustomRACFG, 'video_refresh_rate = "%s"' % self.m_dVideo["R_Rate"])

        # smooth vertical games on horizontal screens
        ini_set(self.m_sCustomRACFG, "video_smooth", str(p_bSmooth).lower())

        # Check orientation
        logging.info("m_sSide_Game %s" % (self.m_oCRT.m_sSide_Game))
        logging.info("System Side: %s" % (self.m_iSide))
        if self.m_oCRT.m_sSide_Game == "H":
            add_line(self.m_sCustomRACFG, 'video_rotation = "0"')
        elif self.m_oCRT.m_sSide_Game == "V3":
            add_line(self.m_sCustomRACFG, 'video_rotation = "1"')
        elif self.m_oCRT.m_sSide_Game == "V1":
            add_line(self.m_sCustomRACFG, 'video_rotation = "3"')

        # Video Scale Integer activation
        ini_set(self.m_sCustomRACFG, "video_scale_integer", self.cfg_iscale)

        # Change custom core config if applies, like neogeo
        if self.m_sCoreCFG:
            ini_set(self.m_sCustomRACFG, "core_options_path", self.m_sCoreCFG)

        # Check retroarch version
        ra_version_fixes(self.m_sCustomRACFG)

    def adv_config_generate(self):
        display_ror = "no"
        display_rol = "no"

        if self.m_oCRT.m_sSide_Game == 'V':
            if self.m_iSide == 1:
                display_ror = "yes"
            elif self.m_iSide == 3:
                display_rol = "yes"

        logging.info("INFO: advmame result - ror %s, rol %s - DIR: %s" % (display_ror, display_rol, self.m_sFileDir))

        modify_line(RC_ADVANCEDMAME_FILE, "display_ror ", "display_ror %s" % display_ror)
        modify_line(RC_ADVANCEDMAME_FILE, "display_rol ", "display_rol %s" % display_rol)
        # put the correct game folder
        modify_line(RC_ADVANCEDMAME_FILE, "dir_rom ", "dir_rom %s:/home/pi/RetroPie/BIOS" % self.m_sFileDir)
        # after run this options are lost, reenable it
        modify_line(RC_ADVANCEDMAME_FILE, "misc_smp ", "misc_smp yes")
        modify_line(RC_ADVANCEDMAME_FILE, "display_vsync ", "display_vsync yes")
        modify_line(RC_ADVANCEDMAME_FILE, "misc_safequit ", "misc_safequit no")
        modify_line(RC_ADVANCEDMAME_FILE, "misc_quiet ", "misc_quiet yes")
        modify_line(RC_ADVANCEDMAME_FILE, "display_resizeeffect ", "display_resizeeffect auto")
        modify_line(RC_ADVANCEDMAME_FILE, "display_resize ", "display_resize integer")
        modify_line(RC_ADVANCEDMAME_FILE, "display_mode ", "display_mode auto")
        modify_line(RC_ADVANCEDMAME_FILE, "display_aspect ", "display_aspect 4/3")
        modify_line(RC_ADVANCEDMAME_FILE, "display_expand ", "display_expand 1.0")

    def ra_integer_calculator(self):
        """
        Integer scaling function.
        This function find for the real horizontal size of the game in selected database,
        and must be located just after game side:

        Example:
        gpilots 1920 224 60.000000 -4 -27 3 48 192 240 5 15734 mame078_libretro.so H [304] <- This last
        
        If exist and this option is enabled on config, system will find the exact multiplier for 
        integer scale, just above of hardware horizontal resolution, tipically 1920.
        Image will be oversized a little bit on sides but we can espect better internal performance
        and horizontal pixel perfect.
        If real resolution is found in DB then self.m_dVideo["Game_H_Res"] will be different of '0'.
        """
        if self.cfg_ghres != 0: #H_Res of the game is present
            int_multiplier = self.cfg_hres/(self.cfg_ghres*1.0)
            self.cfg_hres = self.cfg_ghres*int(math.ceil(int_multiplier))
            if (math.ceil(int_multiplier)-0.5) >= int_multiplier:
                #manual center if divider from H_Res and Game_H_Res is below x.5
                self.cfg_offsetx -= 64
            else:
                #Horizontal auto center through 'video_scale_integer'
                self.cfg_iscale = "true"
            logging.info("game h_res %s - Calculated Int_Multiplier %s" % (self.cfg_ghres,int_multiplier))
        
    def arcade_encapsulator(self):
        # Small centering if vertical resolution is 240 lines
        if self.m_dVideo["V_Res"] == 240 and self.m_oCRT.m_sSide_Game != "H":
            self.m_dVideo["V_Pos"] -= int(1)

        if (self.m_dVideo["V_Res"] > 240 and self.m_dVideo["R_Rate"] == 60):
            # for games with high v_res at 60hz
            logging.info("INFO: high V_Res game found %sx%s@%sHz" % (self.m_dVideo["H_Res"],
                          self.m_dVideo["V_Res"],self.m_dVideo["R_Rate"]))
            self.adv_config_generate()
            if self.m_dVideo["V_Res"] == 448:
                self.m_dVideo["V_Res"] = 224
            else:
                self.m_dVideo["V_Res"] = 240
        elif self.m_dVideo["V_Res"] > 240: # Classic encapsulator
            """
            If encapsulation needed only will ask on first core check,
            just before of runcommand launching and save selection in
            'cfg_encap'.
            On second round (after runcommand) will check previous 
            selection.
            """
            if self.cfg_encap:
                select = self.cfg_encap
                logging.info("INFO: there is a previous selection for " + \
                             "encapsulation: {%s}" % select)
            else:
                if not self.m_bRndCoreCheck:
                    select = menu_options(self.m_lOptEnc, self.m_sTitEnc)
                else:
                    select = "CROPPED"
                    logging.info("WARNING: AUTO SELECTION for encapsulation: " + \
                                 "{%s}, core changed and there " % select + \
                                 "is no previous selection")

            if select == "FORCED": # Encapsulate
                self.m_dVideo["H_Freq"] = int(15841)
                self.m_dVideo["V_Pos"] += int(10)
            elif select == "CROPPED": # Cropped if is under 55Hz
                if self.m_dVideo["R_Rate"] < 55:
                    self.m_dVideo["H_Freq"] = int(15095)
                self.m_dVideo["V_Pos"] -= int(10)
            
            self.cfg_encap = select # save selection for second check
class center(object):
    """ virtual class for centering pattern """
    m_dVideo = {}
    m_oCRT = None
    m_oPatternHandle = None
    m_sEnv = ""
    m_bRestart = True

    m_dPatternAdj = {}

    def __init__(self):
        self.__temp()
        self.__clean()
        self.m_oPatternHandle = generate()

    def launch(self, p_sArgv="current", p_sRestart=True):
        logging.info("INFO: arg 1 (test) = %s" % p_sArgv)
        self.m_sEnv = p_sArgv
        self.m_bRestart = p_sRestart
        if self.m_sEnv == "force":
            logging.info("INFO: Force mode, only apply sys resolution")
            self._force_system_res()
        else:
            self.configure()  # rom name work
            self.prepare()  # screen and pattern generator
            self.run()  # launch, wait and cleanup

    # called at start, called by __init__()
    def configure(self):
        """Get from utility.cfg system resolution"""
        if self.m_sEnv == "current":
            self.m_sEnv = ini_get(CRT_UTILITY_FILE, "default")

    def prepare(self):
        self.screen_prepare()
        self.m_oPatternHandle.initialize(self.m_sEnv, self.m_dVideo)

    def run(self):
        self.start()
        self.cleanup()

    def start(self):
        self.apply_diff_timings()
        self.screen_set()
        self.m_oPatternHandle.launch()

    def apply_diff_timings(self):
        DiffTimings = self.m_oPatternHandle.get_diff_timings()
        logging.info("INFO: timing_data_set PRE-CALCULATED Diff - %s" %
                     self.m_dVideo)
        for timing in DiffTimings:
            self.m_oCRT.timing_add(timing, int(DiffTimings[timing]))
        logging.info("INFO: timing_data_set POST-CALCULATED Diff - %s" %
                     self.m_dVideo)

    def _force_system_res(self):
        p_oSaveBoot = saveboot()
        p_oSaveBoot.save()
        self.m_oCRT = CRT()
        self.cleanup()
        self._restart_es()

    def screen_prepare(self):
        self.m_oCRT = CRT(self.m_sEnv + "_timings")
        self.m_dVideo = self.m_oCRT.pattern_data(CRT_UTILITY_FILE)

    def screen_set(self):
        self.m_oCRT.resolution_set()

    def panic(self, p_sErrorLine1, p_sErrorLine2="-", p_bForceQuit=True):
        """ stop the program and show error to the user """
        logging.error("PANIC: %s" % p_sErrorLine1)
        CRT().screen_restore()
        something_is_bad(p_sErrorLine1, p_sErrorLine2)
        if p_bForceQuit:
            logging.error("EXIT: crt_launcher forced")
            self.__clean()
            sys.exit(1)

    def _restart_es(self):
        commandline = None
        if self.m_bRestart:
            if check_process("emulationstatio"):
                commandline = "touch /tmp/es-restart "
                commandline += "&& pkill -f \"/opt/retropie"
                commandline += "/supplementary/.*/emulationstation([^.]|$)\""
                show_info("RESTARTING EMULATIONSTATION")
                os.system(commandline)
                time.sleep(2)
                sys.exit(1)

    # cleanup code
    def cleanup(self):
        self.m_oCRT.screen_restore()
        logging.info("ES mode recover")
        os.system('clear')
        self.__clean()

    # clean system
    def __clean(self):
        pass

    def __temp(self):
        if CLEAN_LOG_ONSTART:
            remove_file(LOG_PATH)
        logging.basicConfig(
            filename=LOG_PATH,
            level=__DEBUG__,
            format=
            '[%(asctime)s] %(levelname)s - %(filename)s:%(funcName)s - %(message)s'
        )
 def screen_prepare(self):
     self.m_oCRT = CRT(self.m_sEnv + "_timings")
     self.m_dVideo = self.m_oCRT.pattern_data(CRT_UTILITY_FILE)
 def _force_system_res(self):
     p_oSaveBoot = saveboot()
     p_oSaveBoot.save()
     self.m_oCRT = CRT()
     self.cleanup()
     self._restart_es()
Esempio n. 11
0
 def screen_set(self):
     self.m_oCRT = CRT(self.p_sPort)
     self.m_oCRT.screen_calculated(DB_PORTS)
     self.m_oBlackScreen.fill()
     logging.info("INFO: clean: %s", TMP_SLEEPER_FILE)
     remove_file(TMP_SLEEPER_FILE)