--- hatari/python-ui/hatari.py 2019/04/09 08:49:57 1.1.1.4 +++ hatari/python-ui/hatari.py 2019/04/09 08:53:47 1.1.1.7 @@ -3,7 +3,7 @@ # Classes for Hatari emulator instance and mapping its congfiguration # variables with its command line option. # -# Copyright (C) 2008-2011 by Eero Tamminen +# Copyright (C) 2008-2012 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 @@ -48,10 +48,17 @@ class Hatari: def is_compatible(self): "check Hatari compatibility and return error string if it's not" - for line in os.popen(self.hataribin + " -h").readlines(): + error = "Hatari not found or it doesn't support the required --control-socket option!" + pipe = os.popen(self.hataribin + " -h") + for line in pipe.readlines(): if line.find("--control-socket") >= 0: - return None - return "Hatari not found or it doesn't support the required --control-socket option!" + error = None + break + try: + pipe.close() + except IOError: + pass + return error def save_config(self): os.popen(self.hataribin + " --saveconfig") @@ -174,6 +181,9 @@ class Hatari: except OSError as value: print("Hatari PID %d had exited in the meanwhile:\n\t%s" % (self.pid, value)) self.pid = 0 + if self.control: + self.control.close() + self.control = None return False return True @@ -225,7 +235,7 @@ class Hatari: def kill(self): "kill(), kill Hatari if it's running" - if self.pid: + if self.is_running(): os.kill(self.pid, signal.SIGKILL) print("killed hatari with PID %d" % self.pid) self.pid = 0 @@ -289,7 +299,10 @@ class HatariConfigMapping(ConfigStore): else: getattr(self, method)() - def _change_option(self, option): + def _change_option(self, option, quoted = None): + "handle option changing, and quote spaces for quoted part of it" + if quoted: + option = "%s %s" % (option, quoted.replace(" ", "\\ ")) if self._lock_updates: self._options.append(option) else: @@ -431,32 +444,60 @@ class HatariConfigMapping(ConfigStore): # 48kHz, 44.1kHz and STE/TT/Falcon DMA 50066Hz divisable values return ("6000", "6258", "8000", "11025", "12000", "12517", "16000", "22050", "24000", "25033", "32000", - "48000", "44100", "50066") + "44100", "48000", "50066") def get_sound(self): enabled = self.get("[Sound]", "bEnableSound") hz = str(self.get("[Sound]", "nPlaybackFreq")) - return (enabled, hz) + idx = self.get_sound_values().index(hz) + return (enabled, idx) - def set_sound(self, enabled, hz): + def set_sound(self, enabled, idx): # map get_sound_values() index to Hatari config - try: - hz = int(hz) - except ValueError: - hz = 0 - if hz < 6000 or hz > 50066: - hz = 44100 - self.set("[Sound]", "nPlaybackFreq", hz) + hz = self.get_sound_values()[idx] + self.set("[Sound]", "nPlaybackFreq", int(hz)) self.set("[Sound]", "bEnableSound", enabled) - value = str(hz) # and to cli option if enabled: - self._change_option("--sound %s" % value) + self._change_option("--sound %s" % hz) else: self._change_option("--sound off") - return value - - + + def get_ymmixer_types(self): + return ("linear", "table", "model") + + def get_ymmixer(self): + # values for types are start from 1, not 0 + return self.get("[Sound]", "YmVolumeMixing")-1 + + def set_ymmixer(self, value): + 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") + + def set_mic(self, value): + self.set("[Sound]", "bEnableMicrophone", value) + self._change_option("--mic %s" % str(value)) + # ----------- joystick -------------- def get_joystick_types(self): return ("Disabled", "Real joystick", "Keyboard") @@ -481,22 +522,31 @@ 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]) def set_floppy(self, drive, filename): self.set("[Floppy]", "szDisk%cFileName" % ("A", "B")[drive], filename) - self._change_option("--disk-%c %s" % (("a", "b")[drive], filename)) + self._change_option("--disk-%c" % ("a", "b")[drive], str(filename)) + + 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 - # ------------ fast FDC access --------------- def get_fastfdc(self): return self.get("[Floppy]", "FastFloppy") @@ -504,6 +554,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") @@ -522,7 +586,18 @@ class HatariConfigMapping(ConfigStore): self.set("[HardDisk]", "nWriteProtection", value) self._change_option("--protect-hd %s" % self.get_protection_types()[value]) - # ------------ GEMDOS HD (dir) --------------- + # ------------ 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_gemdos_dir(self): self.get("[HardDisk]", "bUseHardDiskDirectory") # for validation return self.get("[HardDisk]", "szHardDiskDirectory") @@ -531,7 +606,7 @@ class HatariConfigMapping(ConfigStore): if dirname and os.path.isdir(dirname): self.set("[HardDisk]", "bUseHardDiskDirectory", True) self.set("[HardDisk]", "szHardDiskDirectory", dirname) - self._change_option("--harddrive %s" % dirname) + self._change_option("--harddrive", str(dirname)) # ------------ ACSI HD (file) --------------- def get_acsi_image(self): @@ -542,7 +617,7 @@ class HatariConfigMapping(ConfigStore): if filename and os.path.isfile(filename): self.set("[HardDisk]", "bUseHardDiskImage", True) self.set("[HardDisk]", "szHardDiskImage", filename) - self._change_option("--acsi %s" % filename) + self._change_option("--acsi", str(filename)) # ------------ IDE master (file) --------------- def get_idemaster_image(self): @@ -553,7 +628,7 @@ class HatariConfigMapping(ConfigStore): if filename and os.path.isfile(filename): self.set("[HardDisk]", "bUseIdeMasterHardDiskImage", True) self.set("[HardDisk]", "szIdeMasterHardDiskImage", filename) - self._change_option("--ide-master %s" % filename) + self._change_option("--ide-master", str(filename)) # ------------ IDE slave (file) --------------- def get_ideslave_image(self): @@ -564,7 +639,7 @@ class HatariConfigMapping(ConfigStore): if filename and os.path.isfile(filename): self.set("[HardDisk]", "bUseIdeSlaveHardDiskImage", True) self.set("[HardDisk]", "szIdeSlaveHardDiskImage", filename) - self._change_option("--ide-slave %s" % filename) + self._change_option("--ide-slave", str(filename)) # ------------ TOS ROM --------------- def get_tos(self): @@ -572,7 +647,7 @@ class HatariConfigMapping(ConfigStore): def set_tos(self, filename): self.set("[ROM]", "szTosImageFileName", filename) - self._change_option("--tos %s" % filename) + self._change_option("--tos", str(filename)) # ------------ memory --------------- def get_memory_names(self): @@ -621,7 +696,6 @@ class HatariConfigMapping(ConfigStore): def get_frameskip(self): fs = self.get("[Screen]", "nFrameSkips") - print("Frameskip", fs) if fs < 0 or fs > 5: return 5 return fs @@ -631,6 +705,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") @@ -648,6 +730,22 @@ class HatariConfigMapping(ConfigStore): 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") + + def set_desktop_st(self, value): + self.set("[Screen]", "bKeepResolutionST", value) + self._change_option("--desktop-st %s" % str(value)) + + # ------------ force max --------------- + def get_force_max(self): + return self.get("[Screen]", "bForceMax") + + def set_force_max(self, value): + self.set("[Screen]", "bForceMax", value) + self._change_option("--force-max %s" % str(value)) + # ------------ show borders --------------- def get_borders(self): return self.get("[Screen]", "bAllowOverscan") @@ -692,6 +790,9 @@ class HatariConfigMapping(ConfigStore): def set_desktop_size(self, w, h): self._desktop_w = w self._desktop_h = h + + def get_desktop_size(self): + return (self._desktop_w, self._desktop_h) def get_max_size(self): w = self.get("[Screen]", "nMaxWidth")