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

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

Added version file to emulator build.

  • Property mode set to 100755
File size: 11.8 KB
RevLine 
[109c83b]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",
[a6f5b95]174 "rom/lowram.s",
[109c83b]175 "rom/timeint.s"
176]
177
[a6f5b95]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",
[1f698bb]326 "ram/tofpu.s",
327 "ram/verdate.s"
[a6f5b95]328]
329
[109c83b]330codes = {
331 "-": 12,
332 "=": 13,
333 "\b": 14,
334 "\t": 15,
335 "`": 41,
336 "[": 26,
337 "]": 27,
338 "\n": 28,
339 ";": 39,
340 "'": 40,
341 "\\": 43,
342 ",": 51,
343 ".": 52,
344 "/": 53,
345 " ": 57
346}
347
348codes_shifted = {
349 "!": 2,
350 "@": 3,
351 "#": 4,
352 "$": 5,
353 "%": 6,
354 "^": 7,
355 "&": 8,
356 "*": 9,
357 "(": 10,
358 ")": 11,
359 "_": 12,
360 "+": 13,
361 "~": 41,
362 "{": 26,
363 "}": 27,
364 ":": 39,
365 "\"": 40,
366 "|": 43,
367 "<": 51,
368 ">": 52,
369 "?": 53
370}
371
372sig_path = "hatari/d/signal"
373lis_path = "/tmp/buchla.sock"
374con = None
375
376def hatari_connect():
377 lis = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
378
379 if os.path.exists(lis_path):
380 os.unlink(lis_path)
381
382 lis.bind(lis_path)
383 lis.listen(1)
384
385 global con
386 (con, _) = lis.accept()
387
388def hatari_send(command):
389 global con
390 con.sendall((command + "\n").encode("ascii"))
391
392def send_alnum(c):
393 hatari_send("hatari-event keypress {}".format(c))
394
395def send_code(code):
396 hatari_send("hatari-event keypress {}".format(code))
397
398def send_code_shifted(code):
399 hatari_send("hatari-event keydown 42")
400 send_code(code)
401 hatari_send("hatari-event keyup 42")
402
403def send_line(line):
404 line += "\n"
405
406 for c in line:
407 if c in codes:
408 send_code(codes[c])
409 elif c in codes_shifted:
410 send_code_shifted(codes_shifted[c])
411 else:
412 send_alnum(c)
413
[f40d52b]414 time.sleep(0.075)
[109c83b]415
416def run_command(command):
417 if os.path.exists(sig_path):
418 os.unlink(sig_path)
419
420 print("Executing {}".format(command))
421 send_line(command + "; touch d:\\signal")
422
423 print("Waiting for completion")
424 while not os.path.exists(sig_path):
[f40d52b]425 time.sleep(0.25)
[109c83b]426
427 os.unlink(sig_path)
428
429def assemble(dir, base):
430 print("Assembling {}.s in {}".format(base, dir))
431 run_command("cp d:\\{}\\{}.s code.s".format(dir, base))
432 run_command("as code")
433 run_command("cp code.o d:\\out\\{}.o".format(base))
434 run_command("rm code.o")
435 run_command("rm code.s")
436 send_line("")
437
438def compile(dir, base):
439 print("Compiling {}.c in {}".format(base, dir))
440 run_command("cp d:\\{}\\{}.c code.c".format(dir, base))
441 run_command("cc code")
442 run_command("as code")
443 run_command("cp code.s d:\\out\\{}.s".format(base))
444 run_command("cp code.o d:\\out\\{}.o".format(base))
445 run_command("rm code.o")
446 run_command("rm code.s")
447 run_command("rm code.c")
448 send_line("")
449
[698a58a]450def store_file(file):
451 run_command("cp {} d:\\out\\{}".format(file, file))
452
453def fetch_file(file):
454 run_command("cp d:\\out\\{} {}".format(file, file))
455
456def remove_file(file):
457 run_command("rm {}".format(file))
458
459def store_archive(a_base):
460 store_file("{}.a".format(a_base))
461 store_file("{}.ndx".format(a_base))
[f40d52b]462 send_line("")
463
[698a58a]464def fetch_archive(a_base):
465 fetch_file("{}.a".format(a_base))
466 fetch_file("{}.ndx".format(a_base))
467 send_line("")
468
469def remove_archive(a_base):
470 remove_file("{}.a".format(a_base))
471 remove_file("{}.ndx".format(a_base))
472 send_line("")
473
474def archive_one(a_base, base):
475 print("Adding {}.o to {}.a".format(base, a_base))
476 fetch_file("{}.o".format(base))
477 run_command("ar68 r {}.a {}.o".format(a_base, base))
478 remove_file("{}.o".format(base))
479 send_line("")
480
481def archive(a_base, mod):
482 print("Creating {}.a".format(a_base))
[f40d52b]483
484 for path in mod:
485 (dir, file) = path.split("/")
486 (base, ext) = file.split(".")
[698a58a]487 archive_one(a_base, base)
[f40d52b]488
[698a58a]489 run_command("doindex -w {}.a".format(a_base))
490 send_line("")
491
492 store_archive(a_base)
493 remove_archive(a_base)
494
[a6f5b95]495def link(com_file):
[698a58a]496 fetch_archive("prolog")
497 fetch_archive("libcio")
498 fetch_archive("vlib")
499 fetch_archive("iolib")
500 fetch_archive("libsm")
501 fetch_archive("lib700")
502
[a6f5b95]503 run_command("aln -w -l -c {}".format(com_file))
[698a58a]504 send_line("")
505
506 remove_archive("prolog")
507 remove_archive("libcio")
508 remove_archive("vlib")
509 remove_archive("iolib")
510 remove_archive("libsm")
511 remove_archive("lib700")
512
[a6f5b95]513def link_rom():
514 print("Linking ROM")
515
516 fetch_file("bios.o")
517 fetch_file("romp.o")
518 fetch_file("booter.o")
519 fetch_file("timeint.o")
520 send_line("")
521
522 link("rom.lnk")
523
[698a58a]524 remove_file("bios.o")
525 remove_file("romp.o")
526 remove_file("booter.o")
527 remove_file("timeint.o")
528 send_line("")
529
530 store_file("bios.abs")
531 remove_file("bios.abs")
[f40d52b]532 send_line("")
533
[a6f5b95]534def link_ram():
535 print("Linking RAM")
536
537 for path in mod_ram:
538 (dir, file) = path.split("/")
539 (base, ext) = file.split(".")
540 fetch_file("{}.o".format(base))
541
542 fetch_file("lowram.o")
543 send_line("")
544
545 link("ram.lnk")
546
547 for path in mod_ram:
548 (dir, file) = path.split("/")
549 (base, ext) = file.split(".")
550 remove_file("{}.o".format(base))
551
552 remove_file("lowram.o")
553 send_line("")
554
555 store_file("midas.abs")
556 remove_file("midas.abs")
557 send_line("")
558
[109c83b]559print("Waiting for Hatari to connect to {}.".format(lis_path))
560hatari_connect()
561
562print("Hatari connected.")
563input("Please start C:\\BIN\\SH.TTP manually, then press enter.")
564
565send_line("PATH=\\bin")
566send_line("cd \\work")
[a6f5b95]567send_line("")
[109c83b]568
569start_at = None
570
[a6f5b95]571for mod in [mod_prolog, mod_iolib, mod_libcio, mod_libsm, mod_lib700, mod_vlib,
572 mod_rom, mod_ram]:
[109c83b]573 for path in mod:
574 if start_at != None:
575 if start_at != path:
576 continue
577 else:
578 start_at = None
579
580 (dir, file) = path.split("/")
581 (base, ext) = file.split(".")
582
583 if ext == "s":
584 assemble(dir, base)
585 elif ext == "c":
586 compile(dir, base)
587 else:
588 raise Exception("file {} with invalid extension {}".format(file, ext))
[f40d52b]589
[698a58a]590archive("prolog", mod_prolog)
591archive("iolib", mod_iolib)
592archive("libcio", mod_libcio)
593archive("libsm", mod_libsm)
594archive("lib700", mod_lib700)
595archive("vlib", mod_vlib)
596
597link_rom()
[a6f5b95]598link_ram()
Note: See TracBrowser for help on using the repository browser.