-
Notifications
You must be signed in to change notification settings - Fork 1
/
decodeshapes.py
67 lines (51 loc) · 1.12 KB
/
decodeshapes.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
# Python < 3
# see LICENSE file for licensing information
# Shape table reconstruction using turtle graphics based on info from the
# Applesoft BASIC Programming Reference Manual.
# Takes binary memory dump from emulator as input. For Mystery House, dump
# $5700-$5a00 and $5500-$5700.
import sys
import turtle
DOTSIZE = 5
def plot(x):
plot = x >> 2
if plot:
turtle.dot(DOTSIZE)
dir = [ 90, 0, 270, 180 ][x & 3]
turtle.setheading(dir)
turtle.fd(DOTSIZE)
def shape(data):
turtle.reset()
turtle.ht()
turtle.pu()
turtle.tracer(0, 0)
i = 0
while True:
byte = data[i]
i += 1
if byte == 0:
break
A = byte & 7
B = (byte >> 3) & 7
C = (byte >> 6) & 7
plot(A)
plot(B)
if C != 0:
plot(C)
turtle.update()
def table(data):
n = data[0]
print n, 'shapes in shape table'
for i in range(1, n+1):
print 'shape definition', i
index = (data[i * 2 + 1] << 8) | data[i * 2]
shape(data[index:])
raw_input()
if __name__ == '__main__':
if len(sys.argv) != 2:
print 'usage: python', argv[0], '<memorydump.bin>'
exit()
f = open(sys.argv[1], 'rb')
data = bytearray(f.read())
f.close
table(data)