loadertpl.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python3
  2. template = """\
  3. 10CLEAR10,&H{sym[Start-1].u:X}:BLOAD"{filename}"
  4. 20DEFFNS(A)=PEEK(A)+256*(PEEK(A)>127)
  5. 30DEFFNW(A)=PEEK(A)+256*PEEK(A+1)
  6. 40DEFUSR=&H{sym[Start].u:X}
  7. 50A=USR(0)
  8. 60B=FNW({sym[CycFrm1]})+65536*PEEK({sym[CycFrm3]})
  9. 70SCREEN0
  10. 80?"Cyc,Err"B;A
  11. 90?"ACK "FNS({sym[AckTiming]})FNS({sym[AckTiming+1]})FNS({sym[AckTiming+2]})FNS({sym[AckTiming+3]})
  12. """
  13. fnames = {'cas':'CAS:VDPtst', 'dsk':'vdptest.bin'}
  14. import sys, re
  15. class Val(object):
  16. def __init__(self, n):
  17. self.u = n & 0xFFFF
  18. self.s = self.u if self.u < 32768 else self.u - 65536
  19. def __str__(self):
  20. return str(self.s) # return the signed one
  21. pass
  22. def main():
  23. if len(sys.argv) < 2 or sys.argv[1].lower() not in fnames:
  24. sys.stderr.write("Usage: python3 loadertpl.py {cas|dsk}\n")
  25. parsesym = re.compile(r'^([A-Za-z_?@.][A-Za-z0-9_?@.$]*)'
  26. r'\s+EQU\s+0([0-9A-F]{4})H$')
  27. kind = sys.argv[1].lower()
  28. sym = {}
  29. f = open('vdptest%s.sym' % kind[0], 'r')
  30. try:
  31. for line in f:
  32. g = parsesym.search(line)
  33. if g:
  34. r = Val(int(g.group(2), 16))
  35. assert g.group(0) not in sym
  36. sym[g.group(1)] = r
  37. finally:
  38. f.close()
  39. fname = fnames[kind]
  40. # Deal with the line breaks as inserted by Python in this .py source file
  41. prg = template.replace('\r\n','\n').replace('\r','\n').replace('\n','\r\n')
  42. AckTiming = sym['AckTiming'].s
  43. sym['Start-1'] = Val(sym['Start'].s-1)
  44. sym['AckTiming+1'] = Val(AckTiming+1)
  45. sym['AckTiming+2'] = Val(AckTiming+2)
  46. sym['AckTiming+3'] = Val(AckTiming+3)
  47. prg = prg.format(sym=sym, filename=fname)
  48. sys.stdout.buffer.write(prg.encode('latin1'))
  49. main()