-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathParseSpriteData.py
69 lines (54 loc) · 1.59 KB
/
ParseSpriteData.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
61
62
63
64
65
66
67
68
69
f = open("src/compressed-sprite.asm", 'r')
o = open("src/decompressed-sprite.asm", 'w')
bytes = []
while True:
l = f.readline()
if not l:
break
bytes += list(filter(None, l[14:45].strip().split(',')))
print(bytes)
def addSequence(cur, i):
v = bytes[i-2]
c = int(bytes[i-1][-2:], 16)
cur += [v] * c
def writeSprite(cur, cur_raw, sprite_count):
h = ("0" + format(sprite_count, 'x'))[-2:]
o.write((" " * 8) + "; SPRITE $" + h + '\n')
for i in range(0,63,3):
bs = cur[i:i+3]
hex_chars = list(map(lambda x: x.replace("$",""), bs))
bins = [(bin(int(b, 16))[2:].zfill(8)) for b in hex_chars]
# * representation
sl = [s for l in bins for s in l]
xs = map(lambda x: x.replace("0", " ").replace("1","*"), sl)
o.write((" " * 8) + "; " + ",".join(bs) + " " + "".join(bins) + " " + "".join(xs) + '\n')
for i in range(0, len(cur_raw), 8):
raw_bytes = (" " * 8) + ".BYTE " + ','.join(cur_raw[i:i+8])
o.write(raw_bytes)
o.write('\n')
del cur[:64]
cur = []
cur_raw = []
tag = "$2B"
sprite_count = 0
index = 2
while (index < len(bytes) + 2):
i = index - 2
if len(cur) >= 64:
writeSprite(cur, cur_raw, sprite_count)
sprite_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
if len(cur) >= 64:
writeSprite(cur, cur_raw, sprite_count)
sprite_count += 1
cur_raw = []