Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 75 lines (59 sloc) 1.882 kb
828d54b @mythmon Initial commit
authored
1 #!/usr/bin/python
2
3 import re
4
5 data_path = 'data.txt'
6 blocks = []
7
cb52a2b @mythmon New feature: OOPS block will return to the screen they came from.
authored
8 class OopsBlock:
9
10 oopsId = 0
11
12 @classmethod
13 def make(cls, prevOpt, id=[]):
14
15 oopsBlock = {
16 'name': 'OOPS_{}'.format(cls.oopsId),
17 'line1': 'Oops! No one has',
18 'line2': 'written this yet',
19 'opt1' : prevOpt,
20 'opt2' : prevOpt
21 }
22 cls.oopsId += 1
23 return oopsBlock['name'], oopsBlock
24
828d54b @mythmon Initial commit
authored
25 try:
26 data_file = open(data_path)
27 for line in data_file:
28 if line.strip() == '':
29 continue
cb52a2b @mythmon New feature: OOPS block will return to the screen they came from.
authored
30
31 name = line.strip()
32
828d54b @mythmon Initial commit
authored
33 line1 = data_file.readline()[:-1]
34 line2 = data_file.readline()[:-1]
cb52a2b @mythmon New feature: OOPS block will return to the screen they came from.
authored
35
828d54b @mythmon Initial commit
authored
36 # 0x7E and 0x7F are right/left arrows on the microcontroller.
37 if line1[0] == '<':
38 line1 = chr(0x7F) + line1[1:]
39 if line2[0] == '>':
40 line2 = chr(0x7E) + line2[1:]
41
cb52a2b @mythmon New feature: OOPS block will return to the screen they came from.
authored
42 line1 = line1.ljust(16)
43 line2 = line2.ljust(16)
44
45 opt1, opt2 = [x.strip() for x in data_file.readline().split(',')]
46 if opt1 == 'OOPS':
47 opt1, oopsBlock = OopsBlock.make(name)
48 blocks.append(oopsBlock)
49 if opt2 == 'OOPS':
50 opt2, oopsBlock = OopsBlock.make(name)
51 blocks.append(oopsBlock)
52
53 blocks.append({
54 'name': name,
55 'line1': line1,
56 'line2': line2,
57 'opt1': opt1,
58 'opt2': opt2
59 })
828d54b @mythmon Initial commit
authored
60 finally:
61 data_file.close()
62
63 try:
64 output = open('storydata.asm', 'w')
65
66 for block in blocks:
67 output.write('{0[name]}:\n'.format(block))
68 output.write('.DB "{0[line1]}"\n'.format(block))
69 output.write('.DB "{0[line2]}"\n'.format(block))
70 output.write('.DW {0[opt1]} << 1\n'.format(block))
71 output.write('.DW {0[opt2]} << 1\n'.format(block))
72 output.write('\n')
73 finally:
74 output.close()
Something went wrong with that request. Please try again.