-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbin2woz.py
37 lines (35 loc) · 1021 Bytes
/
bin2woz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import sys
import os
# This script takes a compiled 6502 binary file and creates a text
# file containing the Wozmon commands to load the program into
# memory.
filename = None
address = int("F480", 16)
argaddr = None
try:
filename = sys.argv[1]
if len(sys.argv) > 2:
argaddr = sys.argv[2].upper()
address = int(argaddr, 16)
outfile = os.path.basename(filename)
outfile = os.path.splitext(outfile)[0]+'.woz'
fh = open(filename, "rb")
data = fh.read()
hexarr = ["%02x" % b for b in data]
fh.close()
i = address
lines = []
for h in hexarr:
addr = "%04x" % i
strout = "%s:%s\r" % (addr.upper(), h.upper())
lines.append(strout)
i += 1
fh = open(outfile, "w")
fh.writelines(lines)
fh.close()
except IndexError as e:
print("USAGE: %s FILE [START ADDRESS]" % sys.argv[0])
except FileNotFoundError as e:
print("%s not found." % filename)
except ValueError as e:
print("%s is not a valid address." % argaddr)