-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathParseCharsetData.py
60 lines (47 loc) · 1.32 KB
/
ParseCharsetData.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
f = open("src/charset.asm", 'r')
o = open("src/decompressed-charset.asm", 'w')
bytes = []
while True:
l = f.readline()
if not l:
break
bytes += list(filter(None, l[24:55].strip().split(',')))
print(bytes)
def addSequence(cur, i):
v = bytes[i-2]
c = int(bytes[i-1][-2:], 16)
cur += [v] * c
def writeChar(cur, cur_raw, char_count):
raw_bytes = ".BYTE " + ','.join(cur_raw)
o.write(raw_bytes)
o.write(" " * (38 - len(raw_bytes)) + " ;.BYTE " + ','.join(cur[:8]) + '\n')
h = ("0" + format(char_count, 'x'))[-2:]
o.write((" " * 40) + "; CHARACTER $" + h + '\n')
hex_chars = list(map(lambda x: x.replace("$",""), cur[:8]))
print(hex_chars)
bins = [(bin(int(b, 16))[2:].zfill(8)) for b in hex_chars]
for b in bins:
o.write((" " * 40) + "; " + b + " " + b.replace("0", " ").replace("1","*") + '\n')
o.write('\n')
del cur[:8]
cur = []
cur_raw = []
tag = "$67"
char_count = 0
index = 2
while (index < len(bytes)):
i = index - 2
if len(cur) >= 8:
writeChar(cur, cur_raw, char_count)
char_count += 1
cur_raw = []
cb = bytes[index]
if cb == tag:
addSequence(cur, index)
index += 3
cur_raw += bytes[i:i+3]
continue
b = bytes[i]
cur_raw += [b]
cur.append(b)
index += 1