source: buchla-68k/hatari/rem.py@ 698a58a

Last change on this file since 698a58a was 698a58a, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Successfully linked ROM!

  • Property mode set to 100755
File size: 8.3 KB
Line 
1#!/usr/bin/env python3
2
3import os
4import socket
5import time
6
7mod_prolog = [
8 "rom/croot.c",
9 "rom/fsmain.s"
10]
11
12mod_iolib = [
13 "lib/dofmt.c",
14 "lib/mdump.c",
15 "lib/pause.c",
16 "lib/printf.c",
17 "lib/rawio.c",
18 "lib/sprintf.c",
19 "lib/waitcr.c",
20 "lib/hwdefs.s",
21 "lib/rtraps.s",
22 "lib/setipl.s",
23 "lib/setsr.s",
24 "lib/traps.s"
25]
26
27mod_libcio = [
28 "lib/atoi.c",
29 "lib/atol.c",
30 "lib/blkrd.c",
31 "lib/blkwr.c",
32 "lib/close.c",
33 "lib/clusmap.c",
34 "lib/conin.c",
35 "lib/conwr.c",
36 "lib/dirfns.c",
37 "lib/fgets.c",
38 "lib/filesys.c",
39 "lib/filname.c",
40 "lib/flread.c",
41 "lib/fopen.c",
42 "lib/fprintf.c",
43 "lib/fputs.c",
44 "lib/fread.c",
45 "lib/fscanf.c",
46 "lib/fseek.c",
47 "lib/fsinit.c",
48 "lib/fsize.c",
49 "lib/fstubs.c",
50 "lib/ftell.c",
51 "lib/fwrite.c",
52 "lib/getbuff.c",
53 "lib/getc.c",
54 "lib/getl.c",
55 "lib/getw.c",
56 "lib/lseek.c",
57 "lib/open.c",
58 "lib/posit.c",
59 "lib/putc.c",
60 "lib/putl.c",
61 "lib/putw.c",
62 "lib/read.c",
63 "lib/readrn.c",
64 "lib/rename.c",
65 "lib/scan.c",
66 "lib/setbuf.c",
67 "lib/ungetc.c",
68 "lib/unlink.c",
69 "lib/write.c",
70 "lib/writern.c",
71 "lib/ptcl12.s"
72]
73
74mod_libsm = [
75 "lib/index.c",
76 "lib/memccpy.c",
77 "lib/memchr.c",
78 "lib/memcmp.c",
79 "lib/memcmpu.c",
80 "lib/memcpy.c",
81 "lib/memcpyw.c",
82 "lib/memset.c",
83 "lib/memsetw.c",
84 "lib/rindex.c",
85 "lib/str2lc.c",
86 "lib/str2uc.c",
87 "lib/strcat.c",
88 "lib/strccpy.c",
89 "lib/strchr.c",
90 "lib/strcmp.c",
91 "lib/strcpy.c",
92 "lib/strcspn.c",
93 "lib/strfill.c",
94 "lib/strlcmp.c",
95 "lib/strlen.c",
96 "lib/strltrm.c",
97 "lib/strncat.c",
98 "lib/strncmp.c",
99 "lib/strncpy.c",
100 "lib/strpbrk.c",
101 "lib/strrchr.c",
102 "lib/strrev.c",
103 "lib/strrevi.c",
104 "lib/strrtrm.c",
105 "lib/strspn.c",
106 "lib/strtok.c",
107 "lib/strtol.c"
108]
109
110mod_lib700 = [
111 "lib/bitrev.c",
112 "lib/ctype.c",
113 "lib/ispow2.c",
114 "lib/mangle.c",
115 "lib/micons.c",
116 "lib/tolower.c",
117 "lib/toupper.c",
118 "lib/aldiv.s",
119 "lib/almul.s",
120 "lib/alrem.s",
121 "lib/blkfill.s",
122 "lib/blkmove.s",
123 "lib/finalone.s",
124 "lib/jumpto.s",
125 "lib/ldiv.s",
126 "lib/lmul.s",
127 "lib/lrem.s",
128 "lib/rand24.s",
129 "lib/setjmp.s",
130 "lib/uldiv.s"
131]
132
133mod_vlib = [
134 "lib/cg2.c",
135 "lib/cg3.c",
136 "lib/glcinit.c",
137 "lib/lseg.c",
138 "lib/vbfill4.c",
139 "lib/vclrs.c",
140 "lib/vhinit.c",
141 "lib/vmput.c",
142 "lib/vobjfns.c",
143 "lib/vputs.c",
144 "lib/vputsv.c",
145 "lib/vsetpal.c",
146 "lib/vsinit.c",
147 "lib/vspray4.c",
148 "lib/vtext.c",
149 "lib/vwputm.c",
150 "lib/acctrl.s",
151 "lib/glcplot.s",
152 "lib/tsplot4.s",
153 "lib/vbank.s",
154 "lib/vclrav.s",
155 "lib/vcputs.s",
156 "lib/vcputsv.s",
157 "lib/viint.s",
158 "lib/vputa.s",
159 "lib/vputc.s",
160 "lib/vputcv.s",
161 "lib/vputp.s",
162 "lib/vsetav.s",
163 "lib/vsetcv.s",
164 "lib/vsplot4.s",
165 "lib/vvputsv.s",
166 "lib/vwputp.s",
167 "lib/vwputs.s"
168]
169
170mod_rom = [
171 "rom/booter.c",
172 "rom/romp.c",
173 "rom/bios.s",
174 "rom/timeint.s"
175]
176
177codes = {
178 "-": 12,
179 "=": 13,
180 "\b": 14,
181 "\t": 15,
182 "`": 41,
183 "[": 26,
184 "]": 27,
185 "\n": 28,
186 ";": 39,
187 "'": 40,
188 "\\": 43,
189 ",": 51,
190 ".": 52,
191 "/": 53,
192 " ": 57
193}
194
195codes_shifted = {
196 "!": 2,
197 "@": 3,
198 "#": 4,
199 "$": 5,
200 "%": 6,
201 "^": 7,
202 "&": 8,
203 "*": 9,
204 "(": 10,
205 ")": 11,
206 "_": 12,
207 "+": 13,
208 "~": 41,
209 "{": 26,
210 "}": 27,
211 ":": 39,
212 "\"": 40,
213 "|": 43,
214 "<": 51,
215 ">": 52,
216 "?": 53
217}
218
219sig_path = "hatari/d/signal"
220lis_path = "/tmp/buchla.sock"
221con = None
222
223def hatari_connect():
224 lis = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
225
226 if os.path.exists(lis_path):
227 os.unlink(lis_path)
228
229 lis.bind(lis_path)
230 lis.listen(1)
231
232 global con
233 (con, _) = lis.accept()
234
235def hatari_send(command):
236 global con
237 con.sendall((command + "\n").encode("ascii"))
238
239def send_alnum(c):
240 hatari_send("hatari-event keypress {}".format(c))
241
242def send_code(code):
243 hatari_send("hatari-event keypress {}".format(code))
244
245def send_code_shifted(code):
246 hatari_send("hatari-event keydown 42")
247 send_code(code)
248 hatari_send("hatari-event keyup 42")
249
250def send_line(line):
251 line += "\n"
252
253 for c in line:
254 if c in codes:
255 send_code(codes[c])
256 elif c in codes_shifted:
257 send_code_shifted(codes_shifted[c])
258 else:
259 send_alnum(c)
260
261 time.sleep(0.075)
262
263def run_command(command):
264 if os.path.exists(sig_path):
265 os.unlink(sig_path)
266
267 print("Executing {}".format(command))
268 send_line(command + "; touch d:\\signal")
269
270 print("Waiting for completion")
271 while not os.path.exists(sig_path):
272 time.sleep(0.25)
273
274 os.unlink(sig_path)
275
276def assemble(dir, base):
277 print("Assembling {}.s in {}".format(base, dir))
278 run_command("cp d:\\{}\\{}.s code.s".format(dir, base))
279 run_command("as code")
280 run_command("cp code.o d:\\out\\{}.o".format(base))
281 run_command("rm code.o")
282 run_command("rm code.s")
283 send_line("")
284
285def compile(dir, base):
286 print("Compiling {}.c in {}".format(base, dir))
287 run_command("cp d:\\{}\\{}.c code.c".format(dir, base))
288 run_command("cc code")
289 run_command("as code")
290 run_command("cp code.s d:\\out\\{}.s".format(base))
291 run_command("cp code.o d:\\out\\{}.o".format(base))
292 run_command("rm code.o")
293 run_command("rm code.s")
294 run_command("rm code.c")
295 send_line("")
296
297def store_file(file):
298 run_command("cp {} d:\\out\\{}".format(file, file))
299
300def fetch_file(file):
301 run_command("cp d:\\out\\{} {}".format(file, file))
302
303def remove_file(file):
304 run_command("rm {}".format(file))
305
306def store_archive(a_base):
307 store_file("{}.a".format(a_base))
308 store_file("{}.ndx".format(a_base))
309 send_line("")
310
311def fetch_archive(a_base):
312 fetch_file("{}.a".format(a_base))
313 fetch_file("{}.ndx".format(a_base))
314 send_line("")
315
316def remove_archive(a_base):
317 remove_file("{}.a".format(a_base))
318 remove_file("{}.ndx".format(a_base))
319 send_line("")
320
321def archive_one(a_base, base):
322 print("Adding {}.o to {}.a".format(base, a_base))
323 fetch_file("{}.o".format(base))
324 run_command("ar68 r {}.a {}.o".format(a_base, base))
325 remove_file("{}.o".format(base))
326 send_line("")
327
328def archive(a_base, mod):
329 print("Creating {}.a".format(a_base))
330
331 for path in mod:
332 (dir, file) = path.split("/")
333 (base, ext) = file.split(".")
334 archive_one(a_base, base)
335
336 run_command("doindex -w {}.a".format(a_base))
337 send_line("")
338
339 store_archive(a_base)
340 remove_archive(a_base)
341
342def link_rom():
343 print("Linking ROM")
344
345 fetch_archive("prolog")
346 fetch_archive("libcio")
347 fetch_archive("vlib")
348 fetch_archive("iolib")
349 fetch_archive("libsm")
350 fetch_archive("lib700")
351
352 fetch_file("bios.o")
353 fetch_file("romp.o")
354 fetch_file("booter.o")
355 fetch_file("timeint.o")
356 send_line("")
357
358 run_command("aln -w -l -c rom.lnk")
359 send_line("")
360
361 remove_archive("prolog")
362 remove_archive("libcio")
363 remove_archive("vlib")
364 remove_archive("iolib")
365 remove_archive("libsm")
366 remove_archive("lib700")
367
368 remove_file("bios.o")
369 remove_file("romp.o")
370 remove_file("booter.o")
371 remove_file("timeint.o")
372 send_line("")
373
374 store_file("bios.abs")
375 remove_file("bios.abs")
376 send_line("")
377
378print("Waiting for Hatari to connect to {}.".format(lis_path))
379hatari_connect()
380
381print("Hatari connected.")
382input("Please start C:\\BIN\\SH.TTP manually, then press enter.")
383
384send_line("PATH=\\bin")
385send_line("cd \\work")
386
387start_at = None
388
389for mod in [mod_prolog, mod_iolib, mod_libcio, mod_libsm, mod_lib700, mod_vlib, mod_rom]:
390 for path in mod:
391 if start_at != None:
392 if start_at != path:
393 continue
394 else:
395 start_at = None
396
397 (dir, file) = path.split("/")
398 (base, ext) = file.split(".")
399
400 if ext == "s":
401 assemble(dir, base)
402 elif ext == "c":
403 compile(dir, base)
404 else:
405 raise Exception("file {} with invalid extension {}".format(file, ext))
406
407archive("prolog", mod_prolog)
408archive("iolib", mod_iolib)
409archive("libcio", mod_libcio)
410archive("libsm", mod_libsm)
411archive("lib700", mod_lib700)
412archive("vlib", mod_vlib)
413
414link_rom()
Note: See TracBrowser for help on using the repository browser.