2017-03-28 16:22:33 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import sys, array, string
|
|
|
|
|
2017-04-06 19:09:30 +00:00
|
|
|
col0 = 0
|
|
|
|
|
|
|
|
def tocolor(x):
|
|
|
|
if x == 0:
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
return x + col0
|
2017-03-28 16:22:33 +00:00
|
|
|
|
|
|
|
def tohex2(v):
|
|
|
|
return '0x%02x'%v
|
|
|
|
|
|
|
|
with open(sys.argv[1],'rb') as f:
|
|
|
|
data = array.array('B', f.read())
|
|
|
|
assert data[0] == 0xa
|
|
|
|
assert data[3] == 8
|
|
|
|
|
|
|
|
# palette
|
2018-11-22 19:11:56 +00:00
|
|
|
print("byte palette[16] = {", end='')
|
2017-03-28 16:22:33 +00:00
|
|
|
for i in range(0,16):
|
|
|
|
r = data[16+i*3]
|
|
|
|
g = data[17+i*3]
|
|
|
|
b = data[18+i*3]
|
|
|
|
entry = (r>>5) | ((g>>2)&0x38) | (b&0xc0)
|
2018-11-22 19:11:56 +00:00
|
|
|
print('%s,' % (tohex2(entry)), end='')
|
|
|
|
print("}")
|
2017-03-28 16:22:33 +00:00
|
|
|
|
|
|
|
# image data
|
|
|
|
width = (data[9] << 8) + data[8] + 1
|
|
|
|
height = (data[11] << 8) + data[10] + 1
|
|
|
|
rowlen = (data[0x43] << 8) + data[0x42]
|
2018-11-22 19:11:56 +00:00
|
|
|
print("const byte sprite[] = {")
|
|
|
|
print("%d,%d," % ((width+1)/2,height))
|
2017-03-28 16:22:33 +00:00
|
|
|
for y in range(0,height):
|
|
|
|
ofs = 0x80 + y*rowlen
|
|
|
|
output = []
|
|
|
|
for x in range(0,width,2):
|
2017-04-06 19:09:30 +00:00
|
|
|
b = (tocolor(data[ofs]) << 4) + tocolor(data[ofs+1])
|
2017-03-28 16:22:33 +00:00
|
|
|
output.append(b)
|
|
|
|
ofs += 2
|
2018-11-22 19:11:56 +00:00
|
|
|
print(','.join(map(tohex2,output)) + ',')
|
|
|
|
print("}")
|
2017-04-06 19:09:30 +00:00
|
|
|
|