[109c83b] | 1 | #!/usr/bin/env python3
|
---|
| 2 |
|
---|
| 3 | import os
|
---|
| 4 | import socket
|
---|
| 5 | import time
|
---|
| 6 |
|
---|
| 7 | mod_prolog = [
|
---|
| 8 | "rom/croot.c",
|
---|
| 9 | "rom/fsmain.s"
|
---|
| 10 | ]
|
---|
| 11 |
|
---|
| 12 | mod_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 |
|
---|
| 27 | mod_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 |
|
---|
| 74 | mod_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 |
|
---|
| 110 | mod_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 |
|
---|
| 133 | mod_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 |
|
---|
| 170 | mod_rom = [
|
---|
| 171 | "rom/booter.c",
|
---|
| 172 | "rom/romp.c",
|
---|
| 173 | "rom/bios.s",
|
---|
| 174 | "rom/timeint.s"
|
---|
| 175 | ]
|
---|
| 176 |
|
---|
| 177 | codes = {
|
---|
| 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 |
|
---|
| 195 | codes_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 |
|
---|
| 219 | sig_path = "hatari/d/signal"
|
---|
| 220 | lis_path = "/tmp/buchla.sock"
|
---|
| 221 | con = None
|
---|
| 222 |
|
---|
| 223 | def 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 |
|
---|
| 235 | def hatari_send(command):
|
---|
| 236 | global con
|
---|
| 237 | con.sendall((command + "\n").encode("ascii"))
|
---|
| 238 |
|
---|
| 239 | def send_alnum(c):
|
---|
| 240 | hatari_send("hatari-event keypress {}".format(c))
|
---|
| 241 |
|
---|
| 242 | def send_code(code):
|
---|
| 243 | hatari_send("hatari-event keypress {}".format(code))
|
---|
| 244 |
|
---|
| 245 | def send_code_shifted(code):
|
---|
| 246 | hatari_send("hatari-event keydown 42")
|
---|
| 247 | send_code(code)
|
---|
| 248 | hatari_send("hatari-event keyup 42")
|
---|
| 249 |
|
---|
| 250 | def 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.1)
|
---|
| 262 |
|
---|
| 263 | def 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.5)
|
---|
| 273 |
|
---|
| 274 | os.unlink(sig_path)
|
---|
| 275 |
|
---|
| 276 | def 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 |
|
---|
| 285 | def 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 |
|
---|
| 297 | print("Waiting for Hatari to connect to {}.".format(lis_path))
|
---|
| 298 | hatari_connect()
|
---|
| 299 |
|
---|
| 300 | print("Hatari connected.")
|
---|
| 301 | input("Please start C:\\BIN\\SH.TTP manually, then press enter.")
|
---|
| 302 |
|
---|
| 303 | send_line("PATH=\\bin")
|
---|
| 304 | send_line("cd \\work")
|
---|
| 305 |
|
---|
| 306 | start_at = None
|
---|
| 307 |
|
---|
| 308 | for mod in [mod_prolog, mod_iolib, mod_libcio, mod_libsm, mod_lib700, mod_vlib, mod_rom]:
|
---|
| 309 | for path in mod:
|
---|
| 310 | if start_at != None:
|
---|
| 311 | if start_at != path:
|
---|
| 312 | continue
|
---|
| 313 | else:
|
---|
| 314 | start_at = None
|
---|
| 315 |
|
---|
| 316 | (dir, file) = path.split("/")
|
---|
| 317 | (base, ext) = file.split(".")
|
---|
| 318 |
|
---|
| 319 | if ext == "s":
|
---|
| 320 | assemble(dir, base)
|
---|
| 321 | elif ext == "c":
|
---|
| 322 | compile(dir, base)
|
---|
| 323 | else:
|
---|
| 324 | raise Exception("file {} with invalid extension {}".format(file, ext))
|
---|