mirror of
https://github.com/pret/pokemon-reverse-engineering-tools.git
synced 2026-03-21 17:24:42 -05:00
Read labels from symfile, not mapfile.
This commit is contained in:
parent
2ca31f660b
commit
7a6efcfdf1
|
|
@ -15,7 +15,7 @@ class Labels(object):
|
|||
Store all labels.
|
||||
"""
|
||||
|
||||
def __init__(self, config, filename="pokecrystal.map"):
|
||||
def __init__(self, config, filename="pokecrystal.sym"):
|
||||
"""
|
||||
Setup the instance.
|
||||
"""
|
||||
|
|
@ -27,18 +27,18 @@ class Labels(object):
|
|||
"""
|
||||
Handle anything requiring file-loading and such.
|
||||
"""
|
||||
# Look for a mapfile if it's not given
|
||||
# Look for a symfile if it's not given
|
||||
if not os.path.exists(self.path):
|
||||
self.filename = find_mapfile_in_dir(self.config.path)
|
||||
self.filename = find_symfile_in_dir(self.config.path)
|
||||
if self.filename == None:
|
||||
raise Exception, "Couldn't find any mapfiles. Run rgblink -m to create a mapfile."
|
||||
raise Exception, "Couldn't find any .sym files. Run rgblink -n to create a .sym file."
|
||||
self.path = os.path.join(self.config.path, self.filename)
|
||||
|
||||
self.labels = sym.read_mapfile(self.path)
|
||||
self.labels = sym.read_symfile(self.path)
|
||||
|
||||
def find_mapfile_in_dir(path):
|
||||
def find_symfile_in_dir(path):
|
||||
for filename in os.listdir(path):
|
||||
if os.path.splitext(filename)[1] == '.map':
|
||||
if os.path.splitext(filename)[1] == '.sym':
|
||||
return filename
|
||||
return None
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
# coding: utf-8
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import json
|
||||
|
||||
|
|
@ -81,6 +82,40 @@ def make_sym_from_mapfile(filename = '../pokecrystal.sym', mapfile = '../mapfile
|
|||
with open(filename, 'w') as sym:
|
||||
sym.write(output)
|
||||
|
||||
def read_symfile(filename='pokecrystal.sym'):
|
||||
"""
|
||||
Scrape label addresses from an rgbds .sym file.
|
||||
"""
|
||||
labels = []
|
||||
|
||||
with open(filename, 'r') as symfile:
|
||||
lines = symfile.readlines()
|
||||
|
||||
# Example line from sym file: "06:5531 Func_19531"
|
||||
label_regex = re.compile('([0-9A-Fa-f]+):([0-9A-Fa-f]+) (\S+)')
|
||||
|
||||
for line in lines:
|
||||
match = label_regex.match(line)
|
||||
if match:
|
||||
bank = int(match.group(1), 16)
|
||||
local_address = int(match.group(2), 16)
|
||||
label = match.group(3)
|
||||
absolute_address = local_address
|
||||
|
||||
if local_address < 0x8000 and bank > 0:
|
||||
absolute_address += (bank - 1) * 0x4000
|
||||
|
||||
labels += [{
|
||||
'label': label,
|
||||
'bank': bank,
|
||||
'address': absolute_address,
|
||||
'offset': absolute_address,
|
||||
'local_address': local_address,
|
||||
}]
|
||||
|
||||
return labels
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
#if os.path.exists('../pokecrystal.sym'):
|
||||
# sys.exit()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user