-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathlaunch.py
More file actions
executable file
·162 lines (130 loc) · 5.24 KB
/
Copy pathlaunch.py
File metadata and controls
executable file
·162 lines (130 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python3
import argparse
import os
import shlex
import subprocess
from pathlib import Path
from libtmux import Server, Session, exc
def HerePath(*components):
path = Path(os.getenv('TOPDIR', ''), *components)
if not path.exists():
print(f"warning: '{path}' does not exists")
return str(path)
SOCKET = 'fsuae'
SESSION = 'fsuae'
GDBSERVER = 'uaedbg.py'
REMOTE = 'localhost:8888'
TMUX_CONF = HerePath('.tmux.conf')
class Launchable():
def __init__(self, name, cmd):
self.name = name
self.cmd = cmd
self.window = None
self.options = []
def configure(self, *args, **kwargs):
raise NotImplementedError
def start(self, session):
cmd = ' '.join([self.cmd] + list(map(shlex.quote, self.options)))
# XXX: print `cmd` to display command and its arguments
self.window = session.new_window(
attach=False, window_name=self.name, window_shell=cmd)
class FSUAE(Launchable):
def __init__(self):
super().__init__('fs-uae', HerePath('tools', GDBSERVER))
def configure(self, floppy=None, model=None, log='', debug=False):
self.options.extend(['-e', 'fs-uae'])
if debug:
self.options.append('-g')
if log:
self.options.extend(['-l', log])
# Now options for FS-UAE.
self.options.append('--')
if floppy:
self.options.append(
'--floppy_drive_0={}'.format(Path(floppy).resolve()))
if model:
self.options.append(f'--amiga_model={model}')
if debug:
self.options.append('--use_debugger=1')
self.options.append('--warp_mode=1')
self.options.append(HerePath('config.fs-uae'))
class SOCAT(Launchable):
def __init__(self, name):
super().__init__(name, 'socat')
def configure(self, tcp_port):
# The simulator will only open the server after some time has
# passed. To minimize the delay, keep reconnecting until success.
self.options = [
'STDIO', 'tcp:localhost:%d,retry,forever,interval=0.01' % tcp_port]
class GDB(Launchable):
def __init__(self):
super().__init__('gdb', 'm68k-amigaos-gdb')
# gdbtui & cgdb output is garbled if there is no delay
self.cmd = 'sleep 0.5 && ' + self.cmd
def configure(self, program=''):
self.options += ['-ex=set prompt \033[35;1m(gdb) \033[0m']
self.options += [
'-iex=directory {}/'.format(HerePath()),
'-ix={}'.format(HerePath('.gdbinit')),
'-ex=set tcp connect-timeout 30',
'-ex=target remote {}'.format(REMOTE),
'--nh',
'--silent',
program]
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Launch effect in FS-UAE emulator.')
parser.add_argument('-f', '--floppy', metavar='ADF', type=str,
help='Floppy disk image in ADF format.')
parser.add_argument('-e', '--executable', metavar='EXE', type=str,
help='Provide executable file for GDB debugger.')
parser.add_argument('-d', '--debug', choices=['gdbserver', 'gdb'],
help=('Run gdbserver on {} and launch gdb '
'if requested.'.format(REMOTE)))
parser.add_argument('-w', '--window', metavar='WIN', type=str,
default='fs-uae',
help='Select tmux window name to switch to.')
parser.add_argument('-m', '--model', choices=['A500', 'A1200'],
default=os.getenv('MODEL', 'A500'),
help='Emulate given Amiga computer model.')
args = parser.parse_args()
# Check if floppy disk image file exists
if args.floppy and not Path(args.floppy).is_file():
raise SystemExit('%s: file does not exist!' % args.floppy)
# Check if executable file exists.
if args.debug and not Path(args.executable).is_file():
raise SystemExit('%s: file does not exist!' % args.executable)
uae = FSUAE()
uae.configure(floppy=args.floppy,
model=args.model,
log=Path(args.floppy).stem + '.log',
debug=args.debug)
ser_port = SOCAT('serial')
ser_port.configure(tcp_port=8000)
par_port = SOCAT('parallel')
par_port.configure(tcp_port=8001)
if args.debug == 'gdb':
debugger = GDB()
debugger.configure(args.executable)
subprocess.run(['tmux', '-f', TMUX_CONF, '-L', SOCKET, 'start-server'])
server = Server(config_file=TMUX_CONF, socket_name=SOCKET)
if server.has_session(SESSION):
server.kill_session(SESSION)
session = server.new_session(session_name=SESSION, attach=False,
window_name=':0', window_command='sleep 1')
try:
uae.start(session)
ser_port.start(session)
par_port.start(session)
if args.debug == 'gdb':
debugger.start(session)
session.kill_window(':0')
if args.debug == 'gdb':
session.select_window(debugger.name)
else:
session.select_window(args.window or par_port.name)
Session.attach(session)
except exc.TmuxObjectDoesNotExist:
pass
finally:
Server.kill(server)