--- hatari/python-ui/hatari.py 2019/04/09 08:51:33 1.1.1.6 +++ hatari/python-ui/hatari.py 2019/04/09 08:57:22 1.1.1.9 @@ -3,7 +3,7 @@ # Classes for Hatari emulator instance and mapping its congfiguration # variables with its command line option. # -# Copyright (C) 2008-2012 by Eero Tamminen +# Copyright (C) 2008-2016 by Eero Tamminen # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -60,6 +60,20 @@ class Hatari: pass return error + def is_winuae(self): + "check whether Hatari has WinUAE CPU core (=more features) or oldUAE one" + result = False + pipe = os.popen(self.hataribin + " -h") + for line in pipe.readlines(): + if line.find("--mmu") >= 0: + result = True + break + try: + pipe.close() + except IOError: + pass + return result + def save_config(self): os.popen(self.hataribin + " --saveconfig") @@ -187,8 +201,8 @@ class Hatari: return False return True - def run(self, extra_args = None, parent_win = None): - "run([parent window][,embedding args]), runs Hatari" + def run(self, extra_args = None, parent_id = None): + "run([embedding args][,parent window ID]), runs Hatari" # if parent_win given, embed Hatari to it pid = os.fork() if pid < 0: @@ -204,8 +218,8 @@ class Hatari: else: # child runs Hatari env = os.environ - if parent_win: - self._set_embed_env(env, parent_win) + if parent_id: + self._set_embed_env(env, parent_id) # callers need to take care of confirming quitting args = [self.hataribin, "--confirm-quit", "off"] if self.server: @@ -215,11 +229,7 @@ class Hatari: print("RUN:", args) os.execvpe(self.hataribin, args, env) - def _set_embed_env(self, env, parent_win): - if sys.platform == 'win32': - win_id = parent_win.handle - else: - win_id = parent_win.xid + def _set_embed_env(self, env, win_id): # tell SDL to use given widget's window #env["SDL_WINDOWID"] = str(win_id) @@ -267,10 +277,12 @@ class HatariConfigMapping(ConfigStore): "printout": ("[Printer]", "szPrintToFileName", "Printer output"), "soundout": ("[Sound]", "szYMCaptureFileName", "Sound output") } + has_modeltype = True # from v2.0 onwards + has_keepstres = True # only with SDL1 "access methods to Hatari configuration file variables and command line options" def __init__(self, hatari): - userconfdir = ".hatari" - ConfigStore.__init__(self, userconfdir) + confdirs = [".config/hatari", ".hatari"] + ConfigStore.__init__(self, confdirs) conffilename = "hatari.cfg" self.load(self.get_filepath(conffilename)) @@ -279,6 +291,11 @@ class HatariConfigMapping(ConfigStore): self._desktop_w = 0 self._desktop_h = 0 self._options = [] + self._winuae = hatari.is_winuae() + # initialize has_* attribs for things that may not be anymore + # valid on Hatari config file and/or command line + self.get_machine() + self.get_desktop_st() def validate(self): "exception is thrown if the loaded configuration isn't compatible" @@ -323,7 +340,7 @@ class HatariConfigMapping(ConfigStore): # ------------ paths --------------- def get_paths(self): paths = [] - for key, item in self._paths.items(): + for key, item in list(self._paths.items()): paths.append((key, self.get(item[0], item[1]), item[2])) return paths @@ -358,23 +375,45 @@ class HatariConfigMapping(ConfigStore): # ------------ machine --------------- def get_machine_types(self): - return ("ST", "STE", "TT", "Falcon") + if self.has_modeltype: + return ("ST", "MegaST", "STE", "MegaSTE", "TT", "Falcon") + else: + return ("ST", "STE", "TT", "Falcon") def get_machine(self): - return self.get("[System]", "nMachineType") + try: + return self.get("[System]", "nModelType") + except KeyError: + self.has_modeltype = False + return self.get("[System]", "nMachineType") + + def has_accurate_winsize(self): + if self.has_modeltype: + return (self.get_machine() < 4) + else: + return (self.get_machine() < 2) def set_machine(self, value): - self.set("[System]", "nMachineType", value) - self._change_option("--machine %s" % ("st", "ste", "tt", "falcon")[value]) + if self.has_modeltype: + self.set("[System]", "nModelType", value) + self._change_option("--machine %s" % ("st", "megast", "ste", "megaste", "tt", "falcon")[value]) + else: + self.set("[System]", "nMachineType", value) + self._change_option("--machine %s" % ("st", "ste", "tt", "falcon")[value]) # ------------ CPU level --------------- def get_cpulevel_types(self): - return ("68000", "68010", "68020", "68EC030+FPU", "68040") + if self._winuae: + return ("68000", "68010", "68020", "68E030", "68040", "68060") + else: + return ("68000", "68010", "68020", "68EC030+FPU", "68040") def get_cpulevel(self): return self.get("[System]", "nCpuLevel") def set_cpulevel(self, value): + if value == 5: # WinUAE 060 + value = 6 self.set("[System]", "nCpuLevel", value) self._change_option("--cpulevel %d" % value) @@ -423,14 +462,6 @@ class HatariConfigMapping(ConfigStore): self.set("[System]", "bPatchTimerD", value) self._change_option("--timer-d %s" % str(value)) - # ------------ RTC --------------- - def get_rtc(self): - return self.get("[System]", "bRealTimeClock") - - def set_rtc(self, value): - self.set("[System]", "bRealTimeClock", value) - self._change_option("--rtc %s" % str(value)) - # ------------ fastforward --------------- def get_fastforward(self): return self.get("[System]", "bFastForward") @@ -474,6 +505,23 @@ class HatariConfigMapping(ConfigStore): self.set("[Sound]", "YmVolumeMixing", value+1) self._change_option("--ym-mixing %s" % self.get_ymmixer_types()[value]) + def get_bufsize(self): + return self.get("[Sound]", "nSdlAudioBufferSize") + + def set_bufsize(self, value): + value = int(value) + if value < 10: value = 10 + if value > 100: value = 100 + self.set("[Sound]", "nSdlAudioBufferSize", value) + self._change_option("--sound-buffer-size %d" % value) + + def get_sync(self): + return self.get("[Sound]", "bEnableSoundSync") + + def set_sync(self, value): + self.set("[Sound]", "bEnableSoundSync", value) + self._change_option("--sound-sync %s" % str(value)) + def get_mic(self): return self.get("[Sound]", "bEnableMicrophone") @@ -505,14 +553,13 @@ class HatariConfigMapping(ConfigStore): joytype = ("none", "real", "keys")[value] self._change_option("--joy%d %s" % (port, joytype)) - # ------------ floppy image dir --------------- + # ------------ floppy handling --------------- def get_floppydir(self): return self.get("[Floppy]", "szDiskImageDirectory") def set_floppydir(self, path): return self.set("[Floppy]", "szDiskImageDirectory", path) - # ------------ floppy disk images --------------- def get_floppy(self, drive): return self.get("[Floppy]", "szDisk%cFileName" % ("A", "B")[drive]) @@ -520,7 +567,17 @@ class HatariConfigMapping(ConfigStore): self.set("[Floppy]", "szDisk%cFileName" % ("A", "B")[drive], filename) self._change_option("--disk-%c" % ("a", "b")[drive], str(filename)) - # ------------ fast FDC access --------------- + def get_floppy_drives(self): + return (self.get("[Floppy]", "EnableDriveA"), self.get("[Floppy]", "EnableDriveB")) + + def set_floppy_drives(self, drives): + idx = 0 + for drive in ("A", "B"): + value = drives[idx] + self.set("[Floppy]", "EnableDrive%c" % drive, value) + self._change_option("--drive-%c %s" % (drive.lower(), str(value))) + idx += 1 + def get_fastfdc(self): return self.get("[Floppy]", "FastFloppy") @@ -528,6 +585,20 @@ class HatariConfigMapping(ConfigStore): self.set("[Floppy]", "FastFloppy", value) self._change_option("--fastfdc %s" % str(value)) + def get_doublesided(self): + driveA = self.get("[Floppy]", "DriveA_NumberOfHeads") + driveB = self.get("[Floppy]", "DriveB_NumberOfHeads") + if driveA > 1 or driveB > 1: + return True + return False + + def set_doublesided(self, value): + if value: sides = 2 + else: sides = 1 + for drive in ("A", "B"): + self.set("[Floppy]", "Drive%c_NumberOfHeads" % drive, sides) + self._change_option("--drive-%c-heads %d" % (drive.lower(), sides)) + # ------------- disk protection ------------- def get_protection_types(self): return ("Off", "On", "Auto") @@ -546,12 +617,37 @@ class HatariConfigMapping(ConfigStore): self.set("[HardDisk]", "nWriteProtection", value) self._change_option("--protect-hd %s" % self.get_protection_types()[value]) - # ------------ GEMDOS HD (dir) --------------- - def get_gemdos_dir(self): + # ------------ GEMDOS HD (dir) emulation --------------- + def get_hd_cases(self): + return ("No conversion", "Upper case", "Lower case") + + def get_hd_case(self): + return self.get("[HardDisk]", "nGemdosCase") + + def set_hd_case(self, value): + values = ("off", "upper", "lower") + self.set("[HardDisk]", "nGemdosCase", value) + self._change_option("--gemdos-case %s" % values[value]) + + def get_hd_drives(self): + return ['skip ACSI/IDE'] + [("%c:" % x) for x in range(ord('C'), ord('Z')+1)] + + def get_hd_drive(self): + return self.get("[HardDisk]", "nGemdosDrive") + 1 + + def set_hd_drive(self, value): + value -= 1 + self.set("[HardDisk]", "nGemdosDrive", value) + drive = chr(ord('C') + value) + if value < 0: + drive = "skip" + self._change_option("--gemdos-drive %s" % drive) + + def get_hd_dir(self): self.get("[HardDisk]", "bUseHardDiskDirectory") # for validation return self.get("[HardDisk]", "szHardDiskDirectory") - def set_gemdos_dir(self, dirname): + def set_hd_dir(self, dirname): if dirname and os.path.isdir(dirname): self.set("[HardDisk]", "bUseHardDiskDirectory", True) self.set("[HardDisk]", "szHardDiskDirectory", dirname) @@ -621,6 +717,23 @@ class HatariConfigMapping(ConfigStore): self.set("[Memory]", "nMemorySize", memsize) self._change_option("--memsize %d" % memsize) + def get_ttram(self): + return self.get("[Memory]", "nTTRamSize") + + def set_ttram(self, memsize): + # guarantee correct type (Gtk float -> config int) + memsize = int(memsize) + self.set("[Memory]", "nTTRamSize", memsize) + self._change_option("--ttram %d" % memsize) + if memsize: + # TT-RAM need 32-bit addressing (i.e. disable 24-bit) + self.set("[System]", "bAddressSpace24", False) + self._change_option("--addr24 off") + else: + # switch 24-bit addressing back for compatibility + self.set("[System]", "bAddressSpace24", True) + self._change_option("--addr24 on", False) + # ------------ monitor --------------- def get_monitor_types(self): return ("Mono", "RGB", "VGA", "TV") @@ -654,6 +767,14 @@ class HatariConfigMapping(ConfigStore): self.set("[Screen]", "nFrameSkips", value) self._change_option("--frameskips %d" % value) + # ------------ VBL slowdown --------------- + def get_slowdown_names(self): + return ("Disabled", "2x", "3x", "4x", "5x", "6x", "8x") + + def set_slowdown(self, value): + value = 1 + int(value) + self._change_option("--slowdown %d" % value) + # ------------ spec512 --------------- def get_spec512threshold(self): return self.get("[Screen]", "nSpec512Threshold") @@ -666,18 +787,23 @@ class HatariConfigMapping(ConfigStore): # --------- keep desktop res ----------- def get_desktop(self): return self.get("[Screen]", "bKeepResolution") - + def set_desktop(self, value): self.set("[Screen]", "bKeepResolution", value) self._change_option("--desktop %s" % str(value)) # --------- keep desktop res - st ------ def get_desktop_st(self): - return self.get("[Screen]", "bKeepResolutionST") - + try: + return self.get("[Screen]", "bKeepResolutionST") + except KeyError: + self.has_keepstres = False + return False + def set_desktop_st(self, value): - self.set("[Screen]", "bKeepResolutionST", value) - self._change_option("--desktop-st %s" % str(value)) + if self.has_keepstres: + self.set("[Screen]", "bKeepResolutionST", value) + self._change_option("--desktop-st %s" % str(value)) # ------------ force max --------------- def get_force_max(self): @@ -773,11 +899,11 @@ class HatariConfigMapping(ConfigStore): return (width, height) # window sizes for other than ST & STE can differ - if self.get("[System]", "nMachineType") not in (0, 1): - print("WARNING: neither ST nor STE machine, window size inaccurate!") - videl = True - else: + if self.has_accurate_winsize(): videl = False + else: + print("WARNING: With Videl, window size is unknown -> may be inaccurate!") + videl = True # mono monitor? if self.get_monitor() == 0: