summaryrefslogtreecommitdiff
path: root/tools/dump_names.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/dump_names.py')
-rw-r--r--tools/dump_names.py42
1 files changed, 1 insertions, 41 deletions
diff --git a/tools/dump_names.py b/tools/dump_names.py
index c7ef02d..a80677e 100644
--- a/tools/dump_names.py
+++ b/tools/dump_names.py
@@ -1,18 +1,7 @@
#!/usr/bin/env python
import sys, os, io
-
-def parse_int(s):
- s = s.strip()
- if s.startswith('$'):
- return int(s[1:], 16)
- if s.startswith('%'):
- return int(s[1:], 2)
- return int(s)
-
-def parse_string(s):
- # assumes strings are literal, no STRCAT() etc
- return s.strip('" ')
+from read_charmap import get_project_dir, read_charmap
def calc_bank(p):
return p // 0x4000
@@ -26,39 +15,10 @@ def get_sym_loc(p):
b, a = calc_bank(p), calc_address(p)
return '%02x:%04x' % (b, a)
-def strip_comment(s):
- # assumes ";" is not in the charmap
- return s.split(';')[0].rstrip()
-
-def get_project_dir():
- script_path = os.path.realpath(__file__)
- script_dir = os.path.dirname(script_path)
- project_dir = os.path.join(script_dir, '..')
- return os.path.normpath(project_dir)
-
-def get_charmap_path():
- project_dir = get_project_dir()
- return os.path.join(project_dir, 'charmap.asm')
-
def get_baserom_path():
project_dir = get_project_dir()
return os.path.join(project_dir, 'baserom.gb')
-def read_charmap():
- charmap_path = get_charmap_path()
- charmap = {}
- with io.open(charmap_path, 'r', encoding='utf-8') as f:
- lines = f.readlines()
- for line in lines:
- line = strip_comment(line).lstrip()
- if not line.startswith('charmap '):
- continue
- char, value = line[len('charmap '):].rsplit(',', 1)
- char = parse_string(char)
- value = parse_int(value)
- charmap[value] = char
- return charmap
-
def dump_strings(data):
charmap = read_charmap()
ss = []