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

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

Try to link RAM.

  • Property mode set to 100755
File size: 11.8 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/lowram.s",
175 "rom/timeint.s"
176]
177
178mod_ram = [
179 "ram/addfpu.c",
180 "ram/adfield.c",
181 "ram/adselbx.c",
182 "ram/asgdsp.c",
183 "ram/asgvce.c",
184 "ram/barbadj.c",
185 "ram/chgsef.c",
186 "ram/chksec.c",
187 "ram/cminit.c",
188 "ram/ctcpos.c",
189 "ram/curset.c",
190 "ram/dbentr.c",
191 "ram/dcopy.c",
192 "ram/dec2fr.c",
193 "ram/delnote.c",
194 "ram/delpnts.c",
195 "ram/dformat.c",
196 "ram/dopatch.c",
197 "ram/enterit.c",
198 "ram/etaccn.c",
199 "ram/etadep.c",
200 "ram/etadyn.c",
201 "ram/etagch.c",
202 "ram/etagpt.c",
203 "ram/etains.c",
204 "ram/etaint.c",
205 "ram/etaopt.c",
206 "ram/etaprg.c",
207 "ram/etarat.c",
208 "ram/etatab.c",
209 "ram/etatun.c",
210 "ram/etavgr.c",
211 "ram/etdyn.c",
212 "ram/etiact.c",
213 "ram/eticnf.c",
214 "ram/etidin.c",
215 "ram/etimlt.c",
216 "ram/etinst.c",
217 "ram/etioas.c",
218 "ram/etiosc.c",
219 "ram/etipnt.c",
220 "ram/etires.c",
221 "ram/etitim.c",
222 "ram/etival.c",
223 "ram/etivce.c",
224 "ram/etiwsn.c",
225 "ram/etloc.c",
226 "ram/etmcfn.c",
227 "ram/etrel.c",
228 "ram/etres1.c",
229 "ram/etscor.c",
230 "ram/etsnbt.c",
231 "ram/etstrn.c",
232 "ram/ettpch.c",
233 "ram/ettrns.c",
234 "ram/etttab.c",
235 "ram/ettval.c",
236 "ram/etvel.c",
237 "ram/etwavs.c",
238 "ram/etwhar.c",
239 "ram/etwhrv.c",
240 "ram/etwoff.c",
241 "ram/etwpnt.c",
242 "ram/etwslt.c",
243 "ram/etwvce.c",
244 "ram/fcnote.c",
245 "ram/frfind.c",
246 "ram/gcurpos.c",
247 "ram/idfield.c",
248 "ram/idselbx.c",
249 "ram/im700.c",
250 "ram/infield.c",
251 "ram/initi.c",
252 "ram/instdsp.c",
253 "ram/itcpos.c",
254 "ram/kbobj.c",
255 "ram/lcdlbls.c",
256 "ram/ldfield.c",
257 "ram/ldselbx.c",
258 "ram/libdsp.c",
259 "ram/librw.c",
260 "ram/localkb.c",
261 "ram/m7menu.c",
262 "ram/midas.c",
263 "ram/msl.c",
264 "ram/msm.c",
265 "ram/nedacc.c",
266 "ram/pix2mid.c",
267 "ram/ptdisp.c",
268 "ram/ptdkey.c",
269 "ram/ptfield.c",
270 "ram/ptread.c",
271 "ram/ptselbx.c",
272 "ram/ptwrite.c",
273 "ram/puteq.c",
274 "ram/rscript.c",
275 "ram/scadv.c",
276 "ram/scfield.c",
277 "ram/scgoto.c",
278 "ram/scinit.c",
279 "ram/scope.c",
280 "ram/scordsp.c",
281 "ram/scread.c",
282 "ram/scselbx.c",
283 "ram/sctrak.c",
284 "ram/scwrite.c",
285 "ram/seccpy.c",
286 "ram/sedump.c",
287 "ram/select.c",
288 "ram/sendval.c",
289 "ram/setgc.c",
290 "ram/setv2gi.c",
291 "ram/setwq.c",
292 "ram/showcfg.c",
293 "ram/smscrl.c",
294 "ram/sqdisp.c",
295 "ram/sqdkey.c",
296 "ram/sqexec.c",
297 "ram/sqfield.c",
298 "ram/sqread.c",
299 "ram/sqscan.c",
300 "ram/sqselbx.c",
301 "ram/sqwrite.c",
302 "ram/stcpos.c",
303 "ram/stmproc.c",
304 "ram/swinit.c",
305 "ram/tdfield.c",
306 "ram/tdselbx.c",
307 "ram/ttcpos.c",
308 "ram/tundsp.c",
309 "ram/ucslice.c",
310 "ram/uslice.c",
311 "ram/vtyper.c",
312 "ram/wdfield.c",
313 "ram/wdselbx.c",
314 "ram/wheel.c",
315 "ram/wscalc.c",
316 "ram/wsdsp.c",
317 "ram/execins.s",
318 "ram/execkey.s",
319 "ram/fpuint.s",
320 "ram/procpfl.s",
321 "ram/sedisp.s",
322 "ram/seexec.s",
323 "ram/serintr.s",
324 "ram/sreset.s",
325 "ram/timeint.s",
326 "ram/tofpu.s"
327]
328
329codes = {
330 "-": 12,
331 "=": 13,
332 "\b": 14,
333 "\t": 15,
334 "`": 41,
335 "[": 26,
336 "]": 27,
337 "\n": 28,
338 ";": 39,
339 "'": 40,
340 "\\": 43,
341 ",": 51,
342 ".": 52,
343 "/": 53,
344 " ": 57
345}
346
347codes_shifted = {
348 "!": 2,
349 "@": 3,
350 "#": 4,
351 "$": 5,
352 "%": 6,
353 "^": 7,
354 "&": 8,
355 "*": 9,
356 "(": 10,
357 ")": 11,
358 "_": 12,
359 "+": 13,
360 "~": 41,
361 "{": 26,
362 "}": 27,
363 ":": 39,
364 "\"": 40,
365 "|": 43,
366 "<": 51,
367 ">": 52,
368 "?": 53
369}
370
371sig_path = "hatari/d/signal"
372lis_path = "/tmp/buchla.sock"
373con = None
374
375def hatari_connect():
376 lis = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
377
378 if os.path.exists(lis_path):
379 os.unlink(lis_path)
380
381 lis.bind(lis_path)
382 lis.listen(1)
383
384 global con
385 (con, _) = lis.accept()
386
387def hatari_send(command):
388 global con
389 con.sendall((command + "\n").encode("ascii"))
390
391def send_alnum(c):
392 hatari_send("hatari-event keypress {}".format(c))
393
394def send_code(code):
395 hatari_send("hatari-event keypress {}".format(code))
396
397def send_code_shifted(code):
398 hatari_send("hatari-event keydown 42")
399 send_code(code)
400 hatari_send("hatari-event keyup 42")
401
402def send_line(line):
403 line += "\n"
404
405 for c in line:
406 if c in codes:
407 send_code(codes[c])
408 elif c in codes_shifted:
409 send_code_shifted(codes_shifted[c])
410 else:
411 send_alnum(c)
412
413 time.sleep(0.075)
414
415def run_command(command):
416 if os.path.exists(sig_path):
417 os.unlink(sig_path)
418
419 print("Executing {}".format(command))
420 send_line(command + "; touch d:\\signal")
421
422 print("Waiting for completion")
423 while not os.path.exists(sig_path):
424 time.sleep(0.25)
425
426 os.unlink(sig_path)
427
428def assemble(dir, base):
429 print("Assembling {}.s in {}".format(base, dir))
430 run_command("cp d:\\{}\\{}.s code.s".format(dir, base))
431 run_command("as code")
432 run_command("cp code.o d:\\out\\{}.o".format(base))
433 run_command("rm code.o")
434 run_command("rm code.s")
435 send_line("")
436
437def compile(dir, base):
438 print("Compiling {}.c in {}".format(base, dir))
439 run_command("cp d:\\{}\\{}.c code.c".format(dir, base))
440 run_command("cc code")
441 run_command("as code")
442 run_command("cp code.s d:\\out\\{}.s".format(base))
443 run_command("cp code.o d:\\out\\{}.o".format(base))
444 run_command("rm code.o")
445 run_command("rm code.s")
446 run_command("rm code.c")
447 send_line("")
448
449def store_file(file):
450 run_command("cp {} d:\\out\\{}".format(file, file))
451
452def fetch_file(file):
453 run_command("cp d:\\out\\{} {}".format(file, file))
454
455def remove_file(file):
456 run_command("rm {}".format(file))
457
458def store_archive(a_base):
459 store_file("{}.a".format(a_base))
460 store_file("{}.ndx".format(a_base))
461 send_line("")
462
463def fetch_archive(a_base):
464 fetch_file("{}.a".format(a_base))
465 fetch_file("{}.ndx".format(a_base))
466 send_line("")
467
468def remove_archive(a_base):
469 remove_file("{}.a".format(a_base))
470 remove_file("{}.ndx".format(a_base))
471 send_line("")
472
473def archive_one(a_base, base):
474 print("Adding {}.o to {}.a".format(base, a_base))
475 fetch_file("{}.o".format(base))
476 run_command("ar68 r {}.a {}.o".format(a_base, base))
477 remove_file("{}.o".format(base))
478 send_line("")
479
480def archive(a_base, mod):
481 print("Creating {}.a".format(a_base))
482
483 for path in mod:
484 (dir, file) = path.split("/")
485 (base, ext) = file.split(".")
486 archive_one(a_base, base)
487
488 run_command("doindex -w {}.a".format(a_base))
489 send_line("")
490
491 store_archive(a_base)
492 remove_archive(a_base)
493
494def link(com_file):
495 fetch_archive("prolog")
496 fetch_archive("libcio")
497 fetch_archive("vlib")
498 fetch_archive("iolib")
499 fetch_archive("libsm")
500 fetch_archive("lib700")
501
502 run_command("aln -w -l -c {}".format(com_file))
503 send_line("")
504
505 remove_archive("prolog")
506 remove_archive("libcio")
507 remove_archive("vlib")
508 remove_archive("iolib")
509 remove_archive("libsm")
510 remove_archive("lib700")
511
512def link_rom():
513 print("Linking ROM")
514
515 fetch_file("bios.o")
516 fetch_file("romp.o")
517 fetch_file("booter.o")
518 fetch_file("timeint.o")
519 send_line("")
520
521 link("rom.lnk")
522
523 remove_file("bios.o")
524 remove_file("romp.o")
525 remove_file("booter.o")
526 remove_file("timeint.o")
527 send_line("")
528
529 store_file("bios.abs")
530 remove_file("bios.abs")
531 send_line("")
532
533def link_ram():
534 print("Linking RAM")
535
536 for path in mod_ram:
537 (dir, file) = path.split("/")
538 (base, ext) = file.split(".")
539 fetch_file("{}.o".format(base))
540
541 fetch_file("lowram.o")
542 send_line("")
543
544 link("ram.lnk")
545
546 for path in mod_ram:
547 (dir, file) = path.split("/")
548 (base, ext) = file.split(".")
549 remove_file("{}.o".format(base))
550
551 remove_file("lowram.o")
552 send_line("")
553
554 store_file("midas.abs")
555 remove_file("midas.abs")
556 send_line("")
557
558print("Waiting for Hatari to connect to {}.".format(lis_path))
559hatari_connect()
560
561print("Hatari connected.")
562input("Please start C:\\BIN\\SH.TTP manually, then press enter.")
563
564send_line("PATH=\\bin")
565send_line("cd \\work")
566send_line("")
567
568start_at = None
569
570for mod in [mod_prolog, mod_iolib, mod_libcio, mod_libsm, mod_lib700, mod_vlib,
571 mod_rom, mod_ram]:
572 for path in mod:
573 if start_at != None:
574 if start_at != path:
575 continue
576 else:
577 start_at = None
578
579 (dir, file) = path.split("/")
580 (base, ext) = file.split(".")
581
582 if ext == "s":
583 assemble(dir, base)
584 elif ext == "c":
585 compile(dir, base)
586 else:
587 raise Exception("file {} with invalid extension {}".format(file, ext))
588
589archive("prolog", mod_prolog)
590archive("iolib", mod_iolib)
591archive("libcio", mod_libcio)
592archive("libsm", mod_libsm)
593archive("lib700", mod_lib700)
594archive("vlib", mod_vlib)
595
596link_rom()
597link_ram()
Note: See TracBrowser for help on using the repository browser.