Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.65 KB | None | 0 0
  1. # Dataliner by Bytebreaker of Hokuto Force (Vincent Truppe) in March 2019
  2.  
  3.  
  4. # python dataliner.py Z:/output.txt Z:/qspb.prg Z:/data.txt 9500
  5.  
  6. # Zuerst die Zeilen in der Datei output.txt zaehlen und davon 2 abziehen (die Adressbytes ganz am Anfang) um die Anzahl Bytes zu kennen, die als Datas gepoked werden sollen.
  7. # Byte-Laenge = Anzahl Zeilen in output.txt - 2
  8. # Wenn man die Datas in C64 Basic einliest, dann immer von Startadresse bis Startadresse + Byte-Laenge - 1 einlesen.
  9. # Beispiel:
  10. # Programmumfang: 6 Bytes
  11. # Startadresse: 49152
  12. # Dann: 49152 bis 49152 + 5 einlesen
  13.  
  14. from __future__ import print_function
  15.  
  16. import sys
  17. import os
  18.  
  19. print("")
  20.  
  21. if len(sys.argv)<4:
  22.     print("Please enter all needed parameters:")
  23.     print("Example: dataliner file.prg data.txt 100")
  24.     print("")
  25.     print("This converts the binary data of file.prg into C64 V2 Basic data lines beginning with line 100, stored in the file data.txt, which you can integrate in your Basic listing with any text editor and copy and paste into VICE.")
  26.     sys.exit()
  27.  
  28. count3 = 0
  29.  
  30. m = open('output.txt', "w") # "C:/Users/truppe/Desktop/VT_ProSeS/portable/Python/output.txt"
  31.  
  32. with open(sys.argv[1], "rb") as f: # "C:/Users/truppe/Desktop/VT_ProSeS/portable/Python/qspb.prg"
  33.     byte = f.read(1)
  34.     while (byte != "") and (byte != b''):
  35.         print(ord(byte), file=m)
  36.         byte = f.read(1)
  37.         count3 += 1
  38.  
  39. m.close()
  40.  
  41. count = 0
  42. count2 = 0
  43. countdatalines = 0
  44. i = 2  # Die ersten beiden Adressbytes des C64 PRGs fliegen raus
  45. j = 0
  46. k = 0
  47. l = int(sys.argv[3])
  48. f = open('output.txt')
  49.  
  50. zeilen = f.readlines()
  51. loadadr2 = int(zeilen[1]) * 256 + int(zeilen[0])
  52. loadadr = str(hex(loadadr2))
  53.  
  54. if len(loadadr) <= 5:
  55.     loadadr = "$" + "0" + loadadr[2:]
  56.  
  57. else:
  58.     loadadr = "$" + loadadr[2:]
  59.  
  60. f.close()
  61. f = open('output.txt')
  62.  
  63. for line in f : count += 1 # zur Sicherheit immer '/' sonst \t oder \p Steuerzeichen (Tab)
  64. f.close()
  65. g = open('output.txt')
  66. h = open(sys.argv[2],'w+') # 'C:/Users/truppe/Desktop/VT_ProSeS/portable/Python/data.txt'
  67.  
  68. lines = g.readlines()
  69.  
  70. if count3 < 19:
  71.     print("Aborting. Selected binary file is too small!")
  72.     sys.exit()
  73.  
  74. while i <= count:
  75.         print(str(l) + " " + "data" + " " + lines[i].strip('\n')+","+lines[i+1].strip('\n')+","+lines[i+2].strip('\n')+","+lines[i+3].strip('\n')+","+lines[i+4].strip('\n')+","+lines[i+5].strip('\n')+","+lines[i+6].strip('\n')+","+lines[i+7].strip('\n')+","+lines[i+8].strip('\n')+","+lines[i+9].strip('\n')+","+lines[i+10].strip('\n')+","+lines[i+11].strip('\n')+","+lines[i+12].strip('\n')+","+lines[i+13].strip('\n')+","+lines[i+14].strip('\n')+","+lines[i+15].strip('\n'), file=h)
  76.         i += 16
  77.         l += 1
  78.         if i >= count-16:
  79.                 count2 = count - i
  80.                 break
  81.                
  82. j = count - count2
  83.  
  84. print(str(l) + " " + "data",end=" ",file=h)
  85. for x in range (j, count-1):
  86.         print(lines[x].strip('\n') + ",",end=" ",file=h)
  87. print(lines[count-1].strip('\n'),file=h)
  88. h.close()
  89.  
  90. h = open(sys.argv[2])
  91. for line in h : countdatalines += 1
  92. h.close()
  93.  
  94. linesh = open(sys.argv[2], 'r').readlines()
  95. myvar = linesh[countdatalines-1]
  96. myvar = myvar.replace(", ",",")
  97. linesh[countdatalines-1] = myvar
  98. out = open(sys.argv[2], 'w')
  99. out.writelines(linesh)
  100. out.close()
  101.  
  102. print("No. of bytes in DATA stream, omiting the first  2 address-bytes: " + str(count3-2))
  103. print("File is loading in C64 memory at " + loadadr)
  104. print("Read into C64 memory from " + str(loadadr2) + " to " + str(loadadr2) + " + " + str(count3-3))
  105. print("Location of text file with C64 Basic DATAs:   " + sys.argv[2])
  106.  
  107. f.close()
  108. g.close()
  109. h.close()
  110. m.close()
  111.  
  112. os.remove('output.txt')
  113. print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement