-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.py
More file actions
52 lines (33 loc) · 1.17 KB
/
Copy pathconvert.py
File metadata and controls
52 lines (33 loc) · 1.17 KB
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
import re
equates = []
def is_jump_table(eq):
return 0x000084 <= eq[0] <= 0x00063C or 0x020104 <= eq[0] <= 0x022278
with open('ti84pce.inc', 'r') as f:
re_right = re.compile(r'(\w+?)\s+equ\s+0([0-9A-F]{6})h')
for line in f:
obj = re.match(re_right, line)
if obj:
equates.append((int(obj.group(2), 16), obj.group(1)))
equates = sorted(equates, key=lambda tup: tup[0])
print('Amount of equates:', len(equates))
jump_table_equates = len([x for x in equates if is_jump_table(x)])
print('Amount of jump table entries:', jump_table_equates)
output = """include 'includes/commands.alm'
include 'includes/ez80.alm'
include 'includes/tiformat.inc'
format ti appvar 'DISASM'
\tdl {}, {}
""".format(len(equates), jump_table_equates)
for equate in equates:
output += '\tdl 0x{:06X}, {}'.format(equate[0], equate[1])
if is_jump_table(equate):
output += ' + 1'
output += '\n'
output += '\n\trb {}\n\n'.format(jump_table_equates * 6)
for equate in equates:
output += equate[1] + ':\n\tdb "'
if is_jump_table(equate):
output += '_'
output += equate[1] + '", 0\n'
with open('equates.asm', 'w') as f:
f.write(output)