Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Dataliner by Bytebreaker of Hokuto Force (Vincent Truppe) in March 2019
- # python dataliner.py Z:/output.txt Z:/qspb.prg Z:/data.txt 9500
- # 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.
- # Byte-Laenge = Anzahl Zeilen in output.txt - 2
- # Wenn man die Datas in C64 Basic einliest, dann immer von Startadresse bis Startadresse + Byte-Laenge - 1 einlesen.
- # Beispiel:
- # Programmumfang: 6 Bytes
- # Startadresse: 49152
- # Dann: 49152 bis 49152 + 5 einlesen
- from __future__ import print_function
- import sys
- import os
- print("")
- if len(sys.argv)<4:
- print("Please enter all needed parameters:")
- print("Example: dataliner file.prg data.txt 100")
- print("")
- 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.")
- sys.exit()
- count3 = 0
- m = open('output.txt', "w") # "C:/Users/truppe/Desktop/VT_ProSeS/portable/Python/output.txt"
- with open(sys.argv[1], "rb") as f: # "C:/Users/truppe/Desktop/VT_ProSeS/portable/Python/qspb.prg"
- byte = f.read(1)
- while (byte != "") and (byte != b''):
- print(ord(byte), file=m)
- byte = f.read(1)
- count3 += 1
- m.close()
- count = 0
- count2 = 0
- countdatalines = 0
- i = 2 # Die ersten beiden Adressbytes des C64 PRGs fliegen raus
- j = 0
- k = 0
- l = int(sys.argv[3])
- f = open('output.txt')
- zeilen = f.readlines()
- loadadr2 = int(zeilen[1]) * 256 + int(zeilen[0])
- loadadr = str(hex(loadadr2))
- if len(loadadr) <= 5:
- loadadr = "$" + "0" + loadadr[2:]
- else:
- loadadr = "$" + loadadr[2:]
- f.close()
- f = open('output.txt')
- for line in f : count += 1 # zur Sicherheit immer '/' sonst \t oder \p Steuerzeichen (Tab)
- f.close()
- g = open('output.txt')
- h = open(sys.argv[2],'w+') # 'C:/Users/truppe/Desktop/VT_ProSeS/portable/Python/data.txt'
- lines = g.readlines()
- if count3 < 19:
- print("Aborting. Selected binary file is too small!")
- sys.exit()
- while i <= count:
- 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)
- i += 16
- l += 1
- if i >= count-16:
- count2 = count - i
- break
- j = count - count2
- print(str(l) + " " + "data",end=" ",file=h)
- for x in range (j, count-1):
- print(lines[x].strip('\n') + ",",end=" ",file=h)
- print(lines[count-1].strip('\n'),file=h)
- h.close()
- h = open(sys.argv[2])
- for line in h : countdatalines += 1
- h.close()
- linesh = open(sys.argv[2], 'r').readlines()
- myvar = linesh[countdatalines-1]
- myvar = myvar.replace(", ",",")
- linesh[countdatalines-1] = myvar
- out = open(sys.argv[2], 'w')
- out.writelines(linesh)
- out.close()
- print("No. of bytes in DATA stream, omiting the first 2 address-bytes: " + str(count3-2))
- print("File is loading in C64 memory at " + loadadr)
- print("Read into C64 memory from " + str(loadadr2) + " to " + str(loadadr2) + " + " + str(count3-3))
- print("Location of text file with C64 Basic DATAs: " + sys.argv[2])
- f.close()
- g.close()
- h.close()
- m.close()
- os.remove('output.txt')
- print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement