|
|
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.2 ! 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:
49: def is_compatible(self):
50: "check Hatari compatibility and return error string if it's not"
51: for line in os.popen(self.hataribin + " -h").readlines():
52: if line.find("--control-socket") >= 0:
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")
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.2 ! 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.2 ! root 147: print("Request&wait data from Hatari...")
1.1 root 148: select.select([fileobj], [], [])
149: time.sleep(0.1)
1.1.1.2 ! root 150: print("...read the data lines")
1.1 root 151: lines = fileobj.readlines()
1.1.1.2 ! 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.2 ! 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.2 ! 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.2 ! root 191: print("WAIT hatari to connect to control socket...")
1.1 root 192: (self.control, addr) = self.server.accept()
1.1.1.2 ! 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.2 ! 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.2 ! 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
243: # don't match to current Hatari. So before using this the current
244: # Hatari configuration should have been saved at least once.
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):
262: userconfdir = ".hatari"
263: ConfigStore.__init__(self, userconfdir)
264: conffilename = "hatari.cfg"
265: self.load(self.get_filepath(conffilename))
266:
267: self._hatari = hatari
268: self._lock_updates = False
269: self._options = []
270:
271: def validate(self):
272: "exception is thrown if the loaded configuration isn't compatible"
273: for method in dir(self):
274: if '_' not in method:
275: continue
276: # check class getters
277: starts = method[:method.find("_")]
278: if starts != "get":
279: continue
280: # but ignore getters for other things than config
281: ends = method[method.rfind("_")+1:]
282: if ends in ("types", "names", "values", "changes", "checkpoint", "filepath"):
283: continue
284: if ends in ("floppy", "joystick"):
285: # use port '0' for checks
286: getattr(self, method)(0)
287: else:
288: getattr(self, method)()
289:
290: def _change_option(self, option):
291: if self._lock_updates:
292: self._options.append(option)
293: else:
294: self._hatari.change_option(option)
295:
296: def lock_updates(self):
297: "lock_updates(), collect Hatari configuration changes"
298: self._lock_updates = True
299:
300: def flush_updates(self):
301: "flush_updates(), apply collected Hatari configuration changes"
302: self._lock_updates = False
303: if not self._options:
304: return
305: self._hatari.change_option(" ".join(self._options))
306: self._options = []
307:
308: # ------------ paths ---------------
309: def get_paths(self):
310: paths = []
311: for key, item in self._paths.items():
312: paths.append((key, self.get(item[0], item[1]), item[2]))
313: return paths
314:
315: def set_paths(self, paths):
316: for key, path in paths:
317: self.set(self._paths[key][0], self._paths[key][1], path)
318: self._hatari.set_path(key, path)
319:
320: # ------------ midi ---------------
321: def get_midi(self):
322: return self.get("[Midi]", "bEnableMidi")
323:
324: def set_midi(self, value):
325: self.set("[Midi]", "bEnableMidi", value)
326: self._hatari.set_device("midi", value)
327:
328: # ------------ printer ---------------
329: def get_printer(self):
330: return self.get("[Printer]", "bEnablePrinting")
331:
332: def set_printer(self, value):
333: self.set("[Printer]", "bEnablePrinting", value)
334: self._hatari.set_device("printer", value)
335:
336: # ------------ RS232 ---------------
337: def get_rs232(self):
338: return self.get("[RS232]", "bEnableRS232")
339:
340: def set_rs232(self, value):
341: self.set("[RS232]", "bEnableRS232", value)
342: self._hatari.set_device("rs232", value)
343:
344: # ------------ machine ---------------
345: def get_machine_types(self):
346: return ("ST", "STE", "TT", "Falcon")
347:
348: def get_machine(self):
349: return self.get("[System]", "nMachineType")
350:
351: def set_machine(self, value):
352: self.set("[System]", "nMachineType", value)
353: self._change_option("--machine %s" % ("st", "ste", "tt", "falcon")[value])
354:
355: # ------------ CPU level ---------------
356: def get_cpulevel_types(self):
357: return ("68000", "68010", "68020", "68EC030+FPU", "68040")
358:
359: def get_cpulevel(self):
360: return self.get("[System]", "nCpuLevel")
361:
362: def set_cpulevel(self, value):
363: self.set("[System]", "nCpuLevel", value)
364: self._change_option("--cpulevel %d" % value)
365:
366: # ------------ CPU clock ---------------
367: def get_cpuclock_types(self):
368: return ("8 MHz", "16 MHz", "32 MHz")
369:
370: def get_cpuclock(self):
371: clocks = {8:0, 16: 1, 32:2}
372: return clocks[self.get("[System]", "nCpuFreq")]
373:
374: def set_cpuclock(self, value):
375: clocks = [8, 16, 32]
376: if value < 0 or value > 2:
1.1.1.2 ! root 377: print("WARNING: CPU clock idx %d, clock fixed to 8 Mhz" % value)
1.1 root 378: value = 8
379: else:
380: value = clocks[value]
381: self.set("[System]", "nCpuFreq", value)
382: self._change_option("--cpuclock %d" % value)
383:
384: # ------------ DSP type ---------------
385: def get_dsp_types(self):
386: return ("None", "Dummy", "Emulated")
387:
388: def get_dsp(self):
389: return self.get("[System]", "nDSPType")
390:
391: def set_dsp(self, value):
392: self.set("[System]", "nDSPType", value)
393: self._change_option("--dsp %s" % ("none", "dummy", "emu")[value])
394:
395: # ------------ compatible ---------------
396: def get_compatible(self):
397: return self.get("[System]", "bCompatibleCpu")
398:
399: def set_compatible(self, value):
400: self.set("[System]", "bCompatibleCpu", value)
401: self._change_option("--compatible %s" % str(value))
402:
403: # ------------ Timer-D ---------------
404: def get_timerd(self):
405: return self.get("[System]", "bPatchTimerD")
406:
407: def set_timerd(self, value):
408: self.set("[System]", "bPatchTimerD", value)
409: self._change_option("--timer-d %s" % str(value))
410:
1.1.1.2 ! root 411: # ------------ RTC ---------------
! 412: def get_rtc(self):
! 413: return self.get("[System]", "bRealTimeClock")
! 414:
! 415: def set_rtc(self, value):
! 416: self.set("[System]", "bRealTimeClock", value)
! 417: self._change_option("--rtc %s" % str(value))
! 418:
1.1 root 419: # ------------ fastforward ---------------
420: def get_fastforward(self):
421: return self.get("[System]", "bFastForward")
422:
423: def set_fastforward(self, value):
424: self.set("[System]", "bFastForward", value)
425: self._change_option("--fast-forward %s" % str(value))
426:
427: # ------------ sound ---------------
428: def get_sound_values(self):
429: # 48kHz, 44.1kHz and STE/TT/Falcon DMA 50066Hz divisable values
430: return ("6000", "6258", "8000", "11025", "12000", "12517",
431: "16000", "22050", "24000", "25033", "32000",
432: "48000", "44100", "50066")
433:
434: def get_sound(self):
435: enabled = self.get("[Sound]", "bEnableSound")
436: hz = str(self.get("[Sound]", "nPlaybackFreq"))
437: return (enabled, hz)
438:
439: def set_sound(self, enabled, hz):
440: # map get_sound_values() index to Hatari config
441: try:
442: hz = int(hz)
443: except ValueError:
444: hz = 0
445: if hz < 6000 or hz > 50066:
446: hz = 44100
447: self.set("[Sound]", "nPlaybackFreq", hz)
448: self.set("[Sound]", "bEnableSound", enabled)
449: value = str(hz)
450: # and to cli option
451: if enabled:
452: self._change_option("--sound %s" % value)
453: else:
454: self._change_option("--sound off")
455: return value
456:
457:
458: # ----------- joystick --------------
459: def get_joystick_types(self):
460: return ("Disabled", "Real joystick", "Keyboard")
461:
462: def get_joystick_names(self):
463: return (
464: "ST Joystick 0",
465: "ST Joystick 1",
466: "STE Joypad A",
467: "STE Joypad B",
468: "Parport stick 1",
469: "Parport stick 2"
470: )
471:
472: def get_joystick(self, port):
473: # return index to get_joystick_values() array
474: return self.get("[Joystick%d]" % port, "nJoystickMode")
475:
476: def set_joystick(self, port, value):
477: # map get_sound_values() index to Hatari config
478: self.set("[Joystick%d]" % port, "nJoystickMode", value)
479: joytype = ("none", "real", "keys")[value]
480: self._change_option("--joy%d %s" % (port, joytype))
481:
482: # ------------ floppy image dir ---------------
483: def get_floppydir(self):
484: return self.get("[Floppy]", "szDiskImageDirectory")
485:
486: def set_floppydir(self, path):
487: return self.set("[Floppy]", "szDiskImageDirectory", path)
488:
489: # ------------ floppy disk images ---------------
490: def get_floppy(self, drive):
491: return self.get("[Floppy]", "szDisk%cFileName" % ("A", "B")[drive])
492:
493: def set_floppy(self, drive, filename):
494: self.set("[Floppy]", "szDisk%cFileName" % ("A", "B")[drive], filename)
495: self._change_option("--disk-%c %s" % (("a", "b")[drive], filename))
496:
497: # ------------ slow FDC access ---------------
498: def get_slowfdc(self):
499: return self.get("[Floppy]", "bSlowFloppy")
500:
501: def set_slowfdc(self, value):
502: self.set("[Floppy]", "bSlowFloppy", value)
503: self._change_option("--slowfdc %s" % str(value))
504:
505: # ------------- disk protection -------------
506: def get_protection_types(self):
507: return ("Off", "On", "Auto")
508:
509: def get_floppy_protection(self):
510: return self.get("[Floppy]", "nWriteProtection")
511:
512: def get_hd_protection(self):
513: return self.get("[HardDisk]", "nWriteProtection")
514:
515: def set_floppy_protection(self, value):
516: self.set("[Floppy]", "nWriteProtection", value)
517: self._change_option("--protect-floppy %s" % self.get_protection_types()[value])
518:
519: def set_hd_protection(self, value):
520: self.set("[HardDisk]", "nWriteProtection", value)
521: self._change_option("--protect-hd %s" % self.get_protection_types()[value])
522:
523: # ------------ GEMDOS HD (dir) ---------------
524: def get_gemdos_dir(self):
525: self.get("[HardDisk]", "bUseHardDiskDirectory") # for validation
526: return self.get("[HardDisk]", "szHardDiskDirectory")
527:
528: def set_gemdos_dir(self, dirname):
529: if dirname and os.path.isdir(dirname):
530: self.set("[HardDisk]", "bUseHardDiskDirectory", True)
531: self.set("[HardDisk]", "szHardDiskDirectory", dirname)
532: self._change_option("--harddrive %s" % dirname)
533:
534: # ------------ ACSI HD (file) ---------------
535: def get_acsi_image(self):
536: self.get("[HardDisk]", "bUseHardDiskImage") # for validation
537: return self.get("[HardDisk]", "szHardDiskImage")
538:
539: def set_acsi_image(self, filename):
540: if filename and os.path.isfile(filename):
541: self.set("[HardDisk]", "bUseHardDiskImage", True)
542: self.set("[HardDisk]", "szHardDiskImage", filename)
543: self._change_option("--acsi %s" % filename)
544:
545: # ------------ IDE master (file) ---------------
546: def get_idemaster_image(self):
547: self.get("[HardDisk]", "bUseIdeMasterHardDiskImage") # for validation
548: return self.get("[HardDisk]", "szIdeMasterHardDiskImage")
549:
550: def set_idemaster_image(self, filename):
551: if filename and os.path.isfile(filename):
552: self.set("[HardDisk]", "bUseIdeMasterHardDiskImage", True)
553: self.set("[HardDisk]", "szIdeMasterHardDiskImage", filename)
554: self._change_option("--ide-master %s" % filename)
555:
556: # ------------ IDE slave (file) ---------------
557: def get_ideslave_image(self):
558: self.get("[HardDisk]", "bUseIdeSlaveHardDiskImage") # for validation
559: return self.get("[HardDisk]", "szIdeSlaveHardDiskImage")
560:
561: def set_ideslave_image(self, filename):
562: if filename and os.path.isfile(filename):
563: self.set("[HardDisk]", "bUseIdeSlaveHardDiskImage", True)
564: self.set("[HardDisk]", "szIdeSlaveHardDiskImage", filename)
565: self._change_option("--ide-slave %s" % filename)
566:
567: # ------------ TOS ROM ---------------
568: def get_tos(self):
569: return self.get("[ROM]", "szTosImageFileName")
570:
571: def set_tos(self, filename):
572: self.set("[ROM]", "szTosImageFileName", filename)
573: self._change_option("--tos %s" % filename)
574:
575: # ------------ memory ---------------
576: def get_memory_names(self):
577: # empty item in list shouldn't be shown, filter them out
578: return ("512kB", "1MB", "2MB", "4MB", "8MB", "14MB")
579:
580: def get_memory(self):
581: "return index to what get_memory_names() returns"
582: sizemap = (0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5)
583: memsize = self.get("[Memory]", "nMemorySize")
584: if memsize >= 0 and memsize < len(sizemap):
585: return sizemap[memsize]
586: return 1 # default = 1BM
587:
588: def set_memory(self, idx):
589: # map memory item index to memory size
590: sizemap = (0, 1, 2, 4, 8, 14)
591: if idx >= 0 and idx < len(sizemap):
592: memsize = sizemap[idx]
593: else:
594: memsize = 1
595: self.set("[Memory]", "nMemorySize", memsize)
596: self._change_option("--memsize %d" % memsize)
597:
598: # ------------ monitor ---------------
599: def get_monitor_types(self):
600: return ("Mono", "RGB", "VGA", "TV")
601:
602: def get_monitor(self):
603: return self.get("[Screen]", "nMonitorType")
604:
605: def set_monitor(self, value):
606: self.set("[Screen]", "nMonitorType", value)
607: self._change_option("--monitor %s" % ("mono", "rgb", "vga", "tv")[value])
608:
609: # ------------ frameskip ---------------
610: def get_frameskip_names(self):
611: return (
612: "Disabled",
613: "1 frame",
614: "2 frames",
615: "3 frames",
616: "4 frames",
617: "Automatic"
618: )
619:
620: def get_frameskip(self):
621: fs = self.get("[Screen]", "nFrameSkips")
1.1.1.2 ! root 622: print("Frameskip", fs)
1.1 root 623: if fs < 0 or fs > 5:
624: return 5
625: return fs
626:
627: def set_frameskip(self, value):
628: value = int(value) # guarantee correct type
629: self.set("[Screen]", "nFrameSkips", value)
630: self._change_option("--frameskips %d" % value)
631:
632: # ------------ spec512 ---------------
633: def get_spec512threshold(self):
634: return self.get("[Screen]", "nSpec512Threshold")
635:
636: def set_spec512threshold(self, value):
637: value = int(value) # guarantee correct type
638: self.set("[Screen]", "nSpec512Threshold", value)
639: self._change_option("--spec512 %d" % value)
640:
1.1.1.2 ! root 641: # --------- keep desktop res -----------
! 642: def get_desktop(self):
! 643: return self.get("[Screen]", "bKeepResolution")
! 644:
! 645: def set_desktop(self, value):
! 646: self.set("[Screen]", "bKeepResolution", value)
! 647: self._change_option("--desktop %s" % str(value))
! 648:
1.1 root 649: # ------------ show borders ---------------
650: def get_borders(self):
651: return self.get("[Screen]", "bAllowOverscan")
652:
653: def set_borders(self, value):
654: self.set("[Screen]", "bAllowOverscan", value)
655: self._change_option("--borders %s" % str(value))
656:
657: # ------------ show statusbar ---------------
658: def get_statusbar(self):
659: return self.get("[Screen]", "bShowStatusbar")
660:
661: def set_statusbar(self, value):
662: self.set("[Screen]", "bShowStatusbar", value)
663: self._change_option("--statusbar %s" % str(value))
664:
1.1.1.2 ! root 665: # ------------ crop statusbar ---------------
! 666: def get_crop(self):
! 667: return self.get("[Screen]", "bCrop")
! 668:
! 669: def set_crop(self, value):
! 670: self.set("[Screen]", "bCrop", value)
! 671: self._change_option("--crop %s" % str(value))
! 672:
1.1 root 673: # ------------ show led ---------------
674: def get_led(self):
675: return self.get("[Screen]", "bShowDriveLed")
676:
677: def set_led(self, value):
678: self.set("[Screen]", "bShowDriveLed", value)
679: self._change_option("--drive-led %s" % str(value))
680:
681: # ------------ monitor aspect ratio ---------------
682: def get_aspectcorrection(self):
683: return self.get("[Screen]", "bAspectCorrect")
684:
685: def set_aspectcorrection(self, value):
686: self.set("[Screen]", "bAspectCorrect", value)
687: self._change_option("--aspect %s" % str(value))
688:
689: # ------------ max window size ---------------
690: def get_max_size(self):
691: w = self.get("[Screen]", "nMaxWidth")
692: h = self.get("[Screen]", "nMaxHeight")
693: return (w, h)
694:
695: def set_max_size(self, w, h):
696: # guarantee correct type (Gtk float -> config int)
697: w = int(w); h = int(h)
698: self.set("[Screen]", "nMaxWidth", w)
699: self.set("[Screen]", "nMaxHeight", h)
700: self._change_option("--max-width %d" % w)
701: self._change_option("--max-height %d" % h)
702:
703: # TODO: remove once UI doesn't need this anymore
704: def set_zoom(self, value):
1.1.1.2 ! root 705: print("Just setting Zoom, configuration doesn't anymore have setting for this.")
1.1 root 706: if value:
707: zoom = 2
708: else:
709: zoom = 1
710: self._change_option("--zoom %d" % zoom)
711:
712: # ------------ configured Hatari window size ---------------
713: def get_window_size(self):
714: if self.get("[Screen]", "bFullScreen"):
1.1.1.2 ! root 715: print("WARNING: don't start Hatari UI with fullscreened Hatari!")
1.1 root 716:
717: # VDI resolution?
718: if self.get("[Screen]", "bUseExtVdiResolutions"):
719: width = self.get("[Screen]", "nVdiWidth")
720: height = self.get("[Screen]", "nVdiHeight")
721: return (width, height)
722:
723: # window sizes for other than ST & STE can differ
724: if self.get("[System]", "nMachineType") not in (0, 1):
1.1.1.2 ! root 725: print("WARNING: neither ST nor STE machine, window size inaccurate!")
1.1 root 726: videl = True
727: else:
728: videl = False
729:
730: # mono monitor?
731: if self.get_monitor() == 0:
732: return (640, 400)
733:
734: # no, color
735: width = 320
736: height = 200
737: # statusbar?
738: if self.get_statusbar():
739: sbar = 12
740: height += sbar
741: else:
742: sbar = 0
743: # zoom?
744: maxw, maxh = self.get_max_size()
745: if 2*width <= maxw and 2*height <= maxh:
746: width *= 2
747: height *= 2
748: zoom = 2
749: else:
750: zoom = 1
751: # overscan borders?
752: if self.get_borders() and not videl:
753: # properly aligned borders on top of zooming
754: leftx = (maxw-width)/zoom
755: borderx = 2*(min(48,leftx/2)/16)*16
756: lefty = (maxh-height)/zoom
757: bordery = min(29+47, lefty)
758: width += zoom*borderx
759: height += zoom*bordery
760:
761: return (width, height)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.