|
|
1.1 root 1: #!/usr/bin/env python
2: #
3: # Classes for Hatari emulator instance and mapping its congfiguration
4: # variables with its command line option.
5: #
1.1.1.3 root 6: # Copyright (C) 2008-2011 by Eero Tamminen <eerot at berlios>
1.1 root 7: #
8: # This program is free software; you can redistribute it and/or modify
9: # it under the terms of the GNU General Public License as published by
10: # the Free Software Foundation; either version 2 of the License, or
11: # (at your option) any later version.
12: #
13: # This program is distributed in the hope that it will be useful,
14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: # GNU General Public License for more details.
17:
18: import os
19: import sys
20: import time
21: import signal
22: import socket
23: import select
24: from config import ConfigStore
25:
26:
27: # Running Hatari instance
28: class Hatari:
29: "running hatari instance and methods for communicating with it"
30: basepath = "/tmp/hatari-ui-" + str(os.getpid())
31: logpath = basepath + ".log"
32: tracepath = basepath + ".trace"
33: debugpath = basepath + ".debug"
34: controlpath = basepath + ".socket"
35: server = None # singleton due to path being currently one per user
36:
37: def __init__(self, hataribin = None):
38: # collect hatari process zombies without waitpid()
39: signal.signal(signal.SIGCHLD, signal.SIG_IGN)
40: if hataribin:
41: self.hataribin = hataribin
42: else:
43: self.hataribin = "hatari"
44: self._create_server()
45: self.control = None
46: self.paused = False
47: self.pid = 0
48:
1.1.1.2 root 49: def is_compatible(self):
50: "check Hatari compatibility and return error string if it's not"
1.1 root 51: for line in os.popen(self.hataribin + " -h").readlines():
52: if line.find("--control-socket") >= 0:
1.1.1.2 root 53: return None
54: return "Hatari not found or it doesn't support the required --control-socket option!"
55:
56: def save_config(self):
57: os.popen(self.hataribin + " --saveconfig")
1.1 root 58:
59: def _create_server(self):
60: if self.server:
61: return
62: self.server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
63: if os.path.exists(self.controlpath):
64: os.unlink(self.controlpath)
65: self.server.bind(self.controlpath)
66: self.server.listen(1)
67:
68: def _send_message(self, msg):
69: if self.control:
70: self.control.send(msg)
71: return True
72: else:
1.1.1.3 root 73: print("ERROR: no Hatari (control socket)")
1.1 root 74: return False
75:
76: def change_option(self, option):
77: "change_option(option), changes given Hatari cli option"
78: return self._send_message("hatari-option %s\n" % option)
79:
80: def set_path(self, key, path):
81: "set_path(key, path), sets path with given key"
82: return self._send_message("hatari-path %s %s\n" % (key, path))
83:
84: def set_device(self, device, enabled):
85: # needed because CLI options cannot disable devices, only enable
86: "set_path(device, enabled), sets whether given device is enabled or not"
87: if enabled:
88: return self._send_message("hatari-enable %s\n" % device)
89: else:
90: return self._send_message("hatari-disable %s\n" % device)
91:
92: def trigger_shortcut(self, shortcut):
93: "trigger_shortcut(shortcut), triggers given Hatari (keyboard) shortcut"
94: return self._send_message("hatari-shortcut %s\n" % shortcut)
95:
96: def insert_event(self, event):
97: "insert_event(event), synthetizes given key/mouse Atari event"
98: return self._send_message("hatari-event %s\n" % event)
99:
100: def debug_command(self, cmd):
101: "debug_command(command), runs given Hatari debugger command"
102: return self._send_message("hatari-debug %s\n" % cmd)
103:
104: def pause(self):
105: "pause(), pauses Hatari emulation"
106: return self._send_message("hatari-stop\n")
107:
108: def unpause(self):
109: "unpause(), continues Hatari emulation"
110: return self._send_message("hatari-cont\n")
111:
112: def _open_output_file(self, hataricommand, option, path):
113: if os.path.exists(path):
114: os.unlink(path)
115: # TODO: why fifo doesn't work properly (blocks forever on read or
116: # reads only byte at the time and stops after first newline)?
117: #os.mkfifo(path)
118: #raw_input("attach strace now, then press Enter\n")
119:
120: # ask Hatari to open/create the requested output file...
121: hataricommand("%s %s" % (option, path))
122: wait = 0.025
123: # ...and wait for it to appear before returning it
124: for i in range(0, 8):
125: time.sleep(wait)
126: if os.path.exists(path):
127: return open(path, "r")
128: wait += wait
129: return None
130:
131: def open_debug_output(self):
132: "open_debug_output() -> file, opens Hatari debugger output file"
133: return self._open_output_file(self.debug_command, "f", self.debugpath)
134:
135: def open_trace_output(self):
136: "open_trace_output() -> file, opens Hatari tracing output file"
137: return self._open_output_file(self.change_option, "--trace-file", self.tracepath)
138:
139: def open_log_output(self):
140: "open_trace_output() -> file, opens Hatari debug log file"
141: return self._open_output_file(self.change_option, "--log-file", self.logpath)
142:
143: def get_lines(self, fileobj):
144: "get_lines(file) -> list of lines readable from given Hatari output file"
145: # wait until data is available, then wait for some more
146: # and only then the data can be read, otherwise its old
1.1.1.3 root 147: print("Request&wait data from Hatari...")
1.1 root 148: select.select([fileobj], [], [])
149: time.sleep(0.1)
1.1.1.3 root 150: print("...read the data lines")
1.1 root 151: lines = fileobj.readlines()
1.1.1.3 root 152: print("".join(lines))
1.1 root 153: return lines
154:
155: def enable_embed_info(self):
156: "enable_embed_info(), request embedded Hatari window ID change information"
157: self._send_message("hatari-embed-info\n")
158:
159: def get_embed_info(self):
160: "get_embed_info() -> (width, height), get embedded Hatari window size"
161: width, height = self.control.recv(12).split("x")
162: return (int(width), int(height))
163:
164: def get_control_socket(self):
165: "get_control_socket() -> socket which can be checked for embed ID changes"
166: return self.control
167:
168: def is_running(self):
169: "is_running() -> bool, True if Hatari is running, False otherwise"
170: if not self.pid:
171: return False
172: try:
173: os.waitpid(self.pid, os.WNOHANG)
1.1.1.3 root 174: except OSError as value:
175: print("Hatari PID %d had exited in the meanwhile:\n\t%s" % (self.pid, value))
1.1 root 176: self.pid = 0
177: return False
178: return True
179:
180: def run(self, extra_args = None, parent_win = None):
181: "run([parent window][,embedding args]), runs Hatari"
182: # if parent_win given, embed Hatari to it
183: pid = os.fork()
184: if pid < 0:
1.1.1.3 root 185: print("ERROR: fork()ing Hatari failed!")
1.1 root 186: return
187: if pid:
188: # in parent
189: self.pid = pid
190: if self.server:
1.1.1.3 root 191: print("WAIT hatari to connect to control socket...")
1.1 root 192: (self.control, addr) = self.server.accept()
1.1.1.3 root 193: print("connected!")
1.1 root 194: else:
195: # child runs Hatari
196: env = os.environ
197: if parent_win:
198: self._set_embed_env(env, parent_win)
199: # callers need to take care of confirming quitting
200: args = [self.hataribin, "--confirm-quit", "off"]
201: if self.server:
202: args += ["--control-socket", self.controlpath]
203: if extra_args:
204: args += extra_args
1.1.1.3 root 205: print("RUN:", args)
1.1 root 206: os.execvpe(self.hataribin, args, env)
207:
208: def _set_embed_env(self, env, parent_win):
209: if sys.platform == 'win32':
210: win_id = parent_win.handle
211: else:
212: win_id = parent_win.xid
213: # tell SDL to use given widget's window
214: #env["SDL_WINDOWID"] = str(win_id)
215:
216: # above is broken: when SDL uses a window it hasn't created itself,
217: # it for some reason doesn't listen to any events delivered to that
218: # window nor implements XEMBED protocol to get them in a way most
219: # friendly to embedder:
220: # http://standards.freedesktop.org/xembed-spec/latest/
221: #
222: # Instead we tell hatari to reparent itself after creating
223: # its own window into this program widget window
224: env["PARENT_WIN_ID"] = str(win_id)
225:
226: def kill(self):
227: "kill(), kill Hatari if it's running"
228: if self.pid:
229: os.kill(self.pid, signal.SIGKILL)
1.1.1.3 root 230: print("killed hatari with PID %d" % self.pid)
1.1 root 231: self.pid = 0
232: if self.control:
233: self.control.close()
234: self.control = None
235:
236:
237: # Mapping of requested values both to Hatari configuration
238: # and command line options.
239: #
240: # By default this doesn't allow setting any other configuration
241: # variables than the ones that were read from the configuration
242: # file i.e. you get an exception if configuration variables
1.1.1.2 root 243: # don't match to current Hatari. So before using this the current
244: # Hatari configuration should have been saved at least once.
1.1 root 245: #
246: # Because of some inconsistencies in the values (see e.g. sound),
247: # this cannot just do these according to some mapping table, but
248: # it needs actual method for (each) setting.
249: class HatariConfigMapping(ConfigStore):
250: _paths = {
251: "memauto": ("[Memory]", "szAutoSaveFileName", "Automatic memory snapshot"),
252: "memsave": ("[Memory]", "szMemoryCaptureFileName", "Manual memory snapshot"),
253: "midiin": ("[Midi]", "sMidiInFileName", "Midi input"),
254: "midiout": ("[Midi]", "sMidiOutFileName", "Midi output"),
255: "rs232in": ("[RS232]", "szInFileName", "RS232 I/O input"),
256: "rs232out": ("[RS232]", "szOutFileName", "RS232 I/O output"),
257: "printout": ("[Printer]", "szPrintToFileName", "Printer output"),
258: "soundout": ("[Sound]", "szYMCaptureFileName", "Sound output")
259: }
260: "access methods to Hatari configuration file variables and command line options"
261: def __init__(self, hatari):
1.1.1.2 root 262: userconfdir = ".hatari"
263: ConfigStore.__init__(self, userconfdir)
264: conffilename = "hatari.cfg"
265: self.load(self.get_filepath(conffilename))
266:
1.1 root 267: self._hatari = hatari
268: self._lock_updates = False
1.1.1.4 ! root 269: self._desktop_w = 0
! 270: self._desktop_h = 0
1.1 root 271: self._options = []
272:
1.1.1.2 root 273: def validate(self):
274: "exception is thrown if the loaded configuration isn't compatible"
275: for method in dir(self):
276: if '_' not in method:
277: continue
278: # check class getters
279: starts = method[:method.find("_")]
280: if starts != "get":
281: continue
282: # but ignore getters for other things than config
283: ends = method[method.rfind("_")+1:]
284: if ends in ("types", "names", "values", "changes", "checkpoint", "filepath"):
285: continue
286: if ends in ("floppy", "joystick"):
287: # use port '0' for checks
288: getattr(self, method)(0)
289: else:
290: getattr(self, method)()
291:
1.1 root 292: def _change_option(self, option):
293: if self._lock_updates:
294: self._options.append(option)
295: else:
296: self._hatari.change_option(option)
297:
298: def lock_updates(self):
299: "lock_updates(), collect Hatari configuration changes"
300: self._lock_updates = True
301:
302: def flush_updates(self):
303: "flush_updates(), apply collected Hatari configuration changes"
304: self._lock_updates = False
305: if not self._options:
306: return
307: self._hatari.change_option(" ".join(self._options))
308: self._options = []
309:
310: # ------------ paths ---------------
311: def get_paths(self):
312: paths = []
313: for key, item in self._paths.items():
314: paths.append((key, self.get(item[0], item[1]), item[2]))
315: return paths
316:
317: def set_paths(self, paths):
318: for key, path in paths:
319: self.set(self._paths[key][0], self._paths[key][1], path)
320: self._hatari.set_path(key, path)
321:
322: # ------------ midi ---------------
323: def get_midi(self):
324: return self.get("[Midi]", "bEnableMidi")
325:
326: def set_midi(self, value):
327: self.set("[Midi]", "bEnableMidi", value)
328: self._hatari.set_device("midi", value)
329:
330: # ------------ printer ---------------
331: def get_printer(self):
332: return self.get("[Printer]", "bEnablePrinting")
333:
334: def set_printer(self, value):
335: self.set("[Printer]", "bEnablePrinting", value)
336: self._hatari.set_device("printer", value)
337:
338: # ------------ RS232 ---------------
339: def get_rs232(self):
340: return self.get("[RS232]", "bEnableRS232")
341:
342: def set_rs232(self, value):
343: self.set("[RS232]", "bEnableRS232", value)
344: self._hatari.set_device("rs232", value)
345:
346: # ------------ machine ---------------
347: def get_machine_types(self):
348: return ("ST", "STE", "TT", "Falcon")
349:
350: def get_machine(self):
351: return self.get("[System]", "nMachineType")
352:
353: def set_machine(self, value):
354: self.set("[System]", "nMachineType", value)
355: self._change_option("--machine %s" % ("st", "ste", "tt", "falcon")[value])
356:
1.1.1.2 root 357: # ------------ CPU level ---------------
358: def get_cpulevel_types(self):
359: return ("68000", "68010", "68020", "68EC030+FPU", "68040")
360:
361: def get_cpulevel(self):
362: return self.get("[System]", "nCpuLevel")
363:
364: def set_cpulevel(self, value):
365: self.set("[System]", "nCpuLevel", value)
366: self._change_option("--cpulevel %d" % value)
367:
368: # ------------ CPU clock ---------------
369: def get_cpuclock_types(self):
370: return ("8 MHz", "16 MHz", "32 MHz")
371:
372: def get_cpuclock(self):
373: clocks = {8:0, 16: 1, 32:2}
374: return clocks[self.get("[System]", "nCpuFreq")]
375:
376: def set_cpuclock(self, value):
377: clocks = [8, 16, 32]
378: if value < 0 or value > 2:
1.1.1.3 root 379: print("WARNING: CPU clock idx %d, clock fixed to 8 Mhz" % value)
1.1.1.2 root 380: value = 8
381: else:
382: value = clocks[value]
383: self.set("[System]", "nCpuFreq", value)
384: self._change_option("--cpuclock %d" % value)
385:
386: # ------------ DSP type ---------------
387: def get_dsp_types(self):
388: return ("None", "Dummy", "Emulated")
389:
390: def get_dsp(self):
391: return self.get("[System]", "nDSPType")
392:
393: def set_dsp(self, value):
394: self.set("[System]", "nDSPType", value)
395: self._change_option("--dsp %s" % ("none", "dummy", "emu")[value])
396:
1.1 root 397: # ------------ compatible ---------------
398: def get_compatible(self):
399: return self.get("[System]", "bCompatibleCpu")
400:
401: def set_compatible(self, value):
402: self.set("[System]", "bCompatibleCpu", value)
403: self._change_option("--compatible %s" % str(value))
404:
405: # ------------ Timer-D ---------------
406: def get_timerd(self):
407: return self.get("[System]", "bPatchTimerD")
408:
409: def set_timerd(self, value):
410: self.set("[System]", "bPatchTimerD", value)
411: self._change_option("--timer-d %s" % str(value))
412:
1.1.1.3 root 413: # ------------ RTC ---------------
414: def get_rtc(self):
415: return self.get("[System]", "bRealTimeClock")
416:
417: def set_rtc(self, value):
418: self.set("[System]", "bRealTimeClock", value)
419: self._change_option("--rtc %s" % str(value))
420:
1.1 root 421: # ------------ fastforward ---------------
422: def get_fastforward(self):
423: return self.get("[System]", "bFastForward")
424:
425: def set_fastforward(self, value):
426: self.set("[System]", "bFastForward", value)
427: self._change_option("--fast-forward %s" % str(value))
428:
429: # ------------ sound ---------------
430: def get_sound_values(self):
431: # 48kHz, 44.1kHz and STE/TT/Falcon DMA 50066Hz divisable values
432: return ("6000", "6258", "8000", "11025", "12000", "12517",
433: "16000", "22050", "24000", "25033", "32000",
434: "48000", "44100", "50066")
435:
436: def get_sound(self):
437: enabled = self.get("[Sound]", "bEnableSound")
438: hz = str(self.get("[Sound]", "nPlaybackFreq"))
439: return (enabled, hz)
440:
441: def set_sound(self, enabled, hz):
442: # map get_sound_values() index to Hatari config
443: try:
444: hz = int(hz)
445: except ValueError:
446: hz = 0
447: if hz < 6000 or hz > 50066:
448: hz = 44100
449: self.set("[Sound]", "nPlaybackFreq", hz)
450: self.set("[Sound]", "bEnableSound", enabled)
451: value = str(hz)
452: # and to cli option
453: if enabled:
454: self._change_option("--sound %s" % value)
455: else:
456: self._change_option("--sound off")
457: return value
458:
459:
460: # ----------- joystick --------------
461: def get_joystick_types(self):
462: return ("Disabled", "Real joystick", "Keyboard")
463:
464: def get_joystick_names(self):
465: return (
466: "ST Joystick 0",
467: "ST Joystick 1",
468: "STE Joypad A",
469: "STE Joypad B",
470: "Parport stick 1",
471: "Parport stick 2"
472: )
473:
474: def get_joystick(self, port):
475: # return index to get_joystick_values() array
476: return self.get("[Joystick%d]" % port, "nJoystickMode")
477:
478: def set_joystick(self, port, value):
479: # map get_sound_values() index to Hatari config
480: self.set("[Joystick%d]" % port, "nJoystickMode", value)
481: joytype = ("none", "real", "keys")[value]
482: self._change_option("--joy%d %s" % (port, joytype))
483:
484: # ------------ floppy image dir ---------------
485: def get_floppydir(self):
486: return self.get("[Floppy]", "szDiskImageDirectory")
487:
488: def set_floppydir(self, path):
489: return self.set("[Floppy]", "szDiskImageDirectory", path)
490:
491: # ------------ floppy disk images ---------------
492: def get_floppy(self, drive):
493: return self.get("[Floppy]", "szDisk%cFileName" % ("A", "B")[drive])
494:
495: def set_floppy(self, drive, filename):
496: self.set("[Floppy]", "szDisk%cFileName" % ("A", "B")[drive], filename)
497: self._change_option("--disk-%c %s" % (("a", "b")[drive], filename))
498:
1.1.1.4 ! root 499: # ------------ fast FDC access ---------------
! 500: def get_fastfdc(self):
! 501: return self.get("[Floppy]", "FastFloppy")
! 502:
! 503: def set_fastfdc(self, value):
! 504: self.set("[Floppy]", "FastFloppy", value)
! 505: self._change_option("--fastfdc %s" % str(value))
1.1.1.2 root 506:
507: # ------------- disk protection -------------
508: def get_protection_types(self):
509: return ("Off", "On", "Auto")
510:
511: def get_floppy_protection(self):
512: return self.get("[Floppy]", "nWriteProtection")
513:
514: def get_hd_protection(self):
515: return self.get("[HardDisk]", "nWriteProtection")
516:
517: def set_floppy_protection(self, value):
518: self.set("[Floppy]", "nWriteProtection", value)
519: self._change_option("--protect-floppy %s" % self.get_protection_types()[value])
520:
521: def set_hd_protection(self, value):
522: self.set("[HardDisk]", "nWriteProtection", value)
523: self._change_option("--protect-hd %s" % self.get_protection_types()[value])
524:
525: # ------------ GEMDOS HD (dir) ---------------
526: def get_gemdos_dir(self):
527: self.get("[HardDisk]", "bUseHardDiskDirectory") # for validation
1.1 root 528: return self.get("[HardDisk]", "szHardDiskDirectory")
1.1.1.2 root 529:
530: def set_gemdos_dir(self, dirname):
531: if dirname and os.path.isdir(dirname):
532: self.set("[HardDisk]", "bUseHardDiskDirectory", True)
1.1 root 533: self.set("[HardDisk]", "szHardDiskDirectory", dirname)
1.1.1.2 root 534: self._change_option("--harddrive %s" % dirname)
535:
536: # ------------ ACSI HD (file) ---------------
537: def get_acsi_image(self):
538: self.get("[HardDisk]", "bUseHardDiskImage") # for validation
539: return self.get("[HardDisk]", "szHardDiskImage")
540:
541: def set_acsi_image(self, filename):
542: if filename and os.path.isfile(filename):
543: self.set("[HardDisk]", "bUseHardDiskImage", True)
544: self.set("[HardDisk]", "szHardDiskImage", filename)
545: self._change_option("--acsi %s" % filename)
546:
547: # ------------ IDE master (file) ---------------
548: def get_idemaster_image(self):
549: self.get("[HardDisk]", "bUseIdeMasterHardDiskImage") # for validation
550: return self.get("[HardDisk]", "szIdeMasterHardDiskImage")
551:
552: def set_idemaster_image(self, filename):
553: if filename and os.path.isfile(filename):
554: self.set("[HardDisk]", "bUseIdeMasterHardDiskImage", True)
555: self.set("[HardDisk]", "szIdeMasterHardDiskImage", filename)
556: self._change_option("--ide-master %s" % filename)
557:
558: # ------------ IDE slave (file) ---------------
559: def get_ideslave_image(self):
560: self.get("[HardDisk]", "bUseIdeSlaveHardDiskImage") # for validation
561: return self.get("[HardDisk]", "szIdeSlaveHardDiskImage")
562:
563: def set_ideslave_image(self, filename):
564: if filename and os.path.isfile(filename):
565: self.set("[HardDisk]", "bUseIdeSlaveHardDiskImage", True)
566: self.set("[HardDisk]", "szIdeSlaveHardDiskImage", filename)
567: self._change_option("--ide-slave %s" % filename)
1.1 root 568:
569: # ------------ TOS ROM ---------------
570: def get_tos(self):
571: return self.get("[ROM]", "szTosImageFileName")
572:
573: def set_tos(self, filename):
574: self.set("[ROM]", "szTosImageFileName", filename)
575: self._change_option("--tos %s" % filename)
576:
577: # ------------ memory ---------------
578: def get_memory_names(self):
579: # empty item in list shouldn't be shown, filter them out
580: return ("512kB", "1MB", "2MB", "4MB", "8MB", "14MB")
581:
582: def get_memory(self):
583: "return index to what get_memory_names() returns"
584: sizemap = (0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5)
585: memsize = self.get("[Memory]", "nMemorySize")
586: if memsize >= 0 and memsize < len(sizemap):
587: return sizemap[memsize]
588: return 1 # default = 1BM
589:
590: def set_memory(self, idx):
591: # map memory item index to memory size
592: sizemap = (0, 1, 2, 4, 8, 14)
593: if idx >= 0 and idx < len(sizemap):
594: memsize = sizemap[idx]
595: else:
596: memsize = 1
597: self.set("[Memory]", "nMemorySize", memsize)
598: self._change_option("--memsize %d" % memsize)
599:
600: # ------------ monitor ---------------
601: def get_monitor_types(self):
602: return ("Mono", "RGB", "VGA", "TV")
603:
604: def get_monitor(self):
605: return self.get("[Screen]", "nMonitorType")
606:
607: def set_monitor(self, value):
608: self.set("[Screen]", "nMonitorType", value)
609: self._change_option("--monitor %s" % ("mono", "rgb", "vga", "tv")[value])
610:
611: # ------------ frameskip ---------------
612: def get_frameskip_names(self):
613: return (
614: "Disabled",
615: "1 frame",
616: "2 frames",
617: "3 frames",
618: "4 frames",
619: "Automatic"
620: )
621:
622: def get_frameskip(self):
623: fs = self.get("[Screen]", "nFrameSkips")
1.1.1.3 root 624: print("Frameskip", fs)
1.1 root 625: if fs < 0 or fs > 5:
626: return 5
627: return fs
628:
629: def set_frameskip(self, value):
630: value = int(value) # guarantee correct type
631: self.set("[Screen]", "nFrameSkips", value)
632: self._change_option("--frameskips %d" % value)
633:
634: # ------------ spec512 ---------------
635: def get_spec512threshold(self):
636: return self.get("[Screen]", "nSpec512Threshold")
637:
638: def set_spec512threshold(self, value):
639: value = int(value) # guarantee correct type
640: self.set("[Screen]", "nSpec512Threshold", value)
641: self._change_option("--spec512 %d" % value)
642:
1.1.1.3 root 643: # --------- keep desktop res -----------
644: def get_desktop(self):
645: return self.get("[Screen]", "bKeepResolution")
646:
647: def set_desktop(self, value):
648: self.set("[Screen]", "bKeepResolution", value)
649: self._change_option("--desktop %s" % str(value))
650:
1.1 root 651: # ------------ show borders ---------------
652: def get_borders(self):
653: return self.get("[Screen]", "bAllowOverscan")
654:
655: def set_borders(self, value):
656: self.set("[Screen]", "bAllowOverscan", value)
657: self._change_option("--borders %s" % str(value))
658:
659: # ------------ show statusbar ---------------
660: def get_statusbar(self):
661: return self.get("[Screen]", "bShowStatusbar")
662:
663: def set_statusbar(self, value):
664: self.set("[Screen]", "bShowStatusbar", value)
665: self._change_option("--statusbar %s" % str(value))
666:
1.1.1.3 root 667: # ------------ crop statusbar ---------------
668: def get_crop(self):
669: return self.get("[Screen]", "bCrop")
670:
671: def set_crop(self, value):
672: self.set("[Screen]", "bCrop", value)
673: self._change_option("--crop %s" % str(value))
674:
1.1 root 675: # ------------ show led ---------------
676: def get_led(self):
677: return self.get("[Screen]", "bShowDriveLed")
678:
679: def set_led(self, value):
680: self.set("[Screen]", "bShowDriveLed", value)
681: self._change_option("--drive-led %s" % str(value))
682:
1.1.1.2 root 683: # ------------ monitor aspect ratio ---------------
684: def get_aspectcorrection(self):
685: return self.get("[Screen]", "bAspectCorrect")
686:
687: def set_aspectcorrection(self, value):
688: self.set("[Screen]", "bAspectCorrect", value)
689: self._change_option("--aspect %s" % str(value))
690:
691: # ------------ max window size ---------------
1.1.1.4 ! root 692: def set_desktop_size(self, w, h):
! 693: self._desktop_w = w
! 694: self._desktop_h = h
! 695:
1.1.1.2 root 696: def get_max_size(self):
697: w = self.get("[Screen]", "nMaxWidth")
698: h = self.get("[Screen]", "nMaxHeight")
1.1.1.4 ! root 699: # default to desktop size?
! 700: if not (w or h):
! 701: w = self._desktop_w
! 702: h = self._desktop_h
1.1.1.2 root 703: return (w, h)
704:
705: def set_max_size(self, w, h):
706: # guarantee correct type (Gtk float -> config int)
707: w = int(w); h = int(h)
708: self.set("[Screen]", "nMaxWidth", w)
709: self.set("[Screen]", "nMaxHeight", h)
710: self._change_option("--max-width %d" % w)
711: self._change_option("--max-height %d" % h)
712:
713: # TODO: remove once UI doesn't need this anymore
1.1 root 714: def set_zoom(self, value):
1.1.1.3 root 715: print("Just setting Zoom, configuration doesn't anymore have setting for this.")
1.1 root 716: if value:
717: zoom = 2
718: else:
719: zoom = 1
720: self._change_option("--zoom %d" % zoom)
721:
722: # ------------ configured Hatari window size ---------------
723: def get_window_size(self):
724: if self.get("[Screen]", "bFullScreen"):
1.1.1.3 root 725: print("WARNING: don't start Hatari UI with fullscreened Hatari!")
1.1 root 726:
727: # VDI resolution?
728: if self.get("[Screen]", "bUseExtVdiResolutions"):
729: width = self.get("[Screen]", "nVdiWidth")
730: height = self.get("[Screen]", "nVdiHeight")
731: return (width, height)
732:
733: # window sizes for other than ST & STE can differ
734: if self.get("[System]", "nMachineType") not in (0, 1):
1.1.1.3 root 735: print("WARNING: neither ST nor STE machine, window size inaccurate!")
1.1.1.2 root 736: videl = True
737: else:
738: videl = False
1.1 root 739:
740: # mono monitor?
1.1.1.2 root 741: if self.get_monitor() == 0:
1.1 root 742: return (640, 400)
743:
744: # no, color
745: width = 320
746: height = 200
747: # statusbar?
1.1.1.2 root 748: if self.get_statusbar():
749: sbar = 12
750: height += sbar
751: else:
752: sbar = 0
753: # zoom?
754: maxw, maxh = self.get_max_size()
755: if 2*width <= maxw and 2*height <= maxh:
1.1 root 756: width *= 2
757: height *= 2
1.1.1.2 root 758: zoom = 2
759: else:
760: zoom = 1
761: # overscan borders?
762: if self.get_borders() and not videl:
763: # properly aligned borders on top of zooming
764: leftx = (maxw-width)/zoom
765: borderx = 2*(min(48,leftx/2)/16)*16
766: lefty = (maxh-height)/zoom
767: bordery = min(29+47, lefty)
768: width += zoom*borderx
769: height += zoom*bordery
1.1 root 770:
771: return (width, height)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.