forked from shirriff/xc2064
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfmtrbt.py
57 lines (46 loc) · 1.34 KB
/
fmtrbt.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
""" Formats an RBT file."""
import re
import sys
def fmt(fname):
buf = {}
with open(fname) as f:
cnt = 0
for line in f.readlines():
m = re.match('0([01]{71})111', line)
if m:
buf[cnt] = m.group(1)[::-1] # Reverse each line
# Flip 1's and 0's
buf[cnt] = ''.join(['1' if x == '0' else '0' for x in buf[cnt]])
cnt += 1
assert(cnt == 160)
# Put a space before the break index
ybreaks = [9]
for i in range(0, 10):
ybreaks.append(ybreaks[-1] + 18)
if i == 1 or i == 4: ybreaks.append(ybreaks[-1] + 2)
xbreaks = [1]
for i in range(0, 10):
xbreaks.append(xbreaks[-1] + 8)
if i == 2 or i == 5: xbreaks.append(xbreaks[-1] + 1)
labels = ['', 'H', 'G', '', 'F', 'E', 'D', '', 'C', 'B', 'A', '']
ylinecount = 0
yregioncount = 0
for y in range(0, 160):
ylinecount += 1
if y in ybreaks:
ylinecount = 1
yregioncount += 1
print
if labels[yregioncount]:
print ' A%c B%c C%c D%c E%c F%c G%c H%c' % tuple([labels[yregioncount]]*8)
print '%2d ' % ylinecount,
for x in range(0, 71):
if x in xbreaks: sys.stdout.write(' ')
sys.stdout.write(buf[y][x])
print
def main():
if len(sys.argv) != 2:
exit("Usage: python fmtrbt.py FOO.RBT")
fmt(sys.argv[1])
if __name__ == "__main__":
main()