-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
example_fceux_symbols.py
43 lines (40 loc) · 1.44 KB
/
example_fceux_symbols.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
#!/usr/bin/env python3
import sys
assert sys.version_info[0] >= 3, "Python 3 required."
from collections import OrderedDict
def label_to_nl(label_file, nl_file, range_min, range_max):
labels = []
try:
of = open(label_file, "rt")
labels = of.readlines()
except IOError:
print("skipped: "+label_file)
return
labs = {}
sout = ""
for line in labels:
words = line.split()
if (words[0] == "al"):
adr = int(words[1], 16)
sym = words[2]
sym = sym.lstrip('.')
if (sym[0] == '_' and sym[1] == '_'):
continue # skip compiler internals
if (adr >= range_min and adr <= range_max):
if (adr in labs):
# multiple symbol
text = labs[adr]
textsplit = text.split()
if (sym not in textsplit):
text = text + " " + sym
labs[adr] = text
else:
labs[adr] = sym
for (adr, sym) in labs.items():
sout += ("$%04X#%s#\n" % (adr, sym))
open(nl_file, "wt").write(sout)
print("debug symbols: " + nl_file)
if __name__ == "__main__":
label_to_nl("example.labels.txt", "example.nes.ram.nl", 0x0000, 0x7FF)
label_to_nl("example.labels.txt", "example.nes.0.nl", 0x8000, 0xBFFF)
label_to_nl("example.labels.txt", "example.nes.1.nl", 0xC000, 0xFFFF)