diff options
author | yenatch <yenatch@gmail.com> | 2013-12-05 16:38:31 -0500 |
---|---|---|
committer | yenatch <yenatch@gmail.com> | 2013-12-05 21:21:05 -0500 |
commit | 0fd121a81e1cbbf1a42e72a5d7c9e8099ef59f97 (patch) | |
tree | 5e4ed5ade5a648cc8d4916ac594b809dff5b6e86 | |
parent | c57e0f0706608a4acba89182945bec975a43acfd (diff) |
wram: try to determine addresses for section defs without any
-rw-r--r-- | pokemontools/wram.py | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/pokemontools/wram.py b/pokemontools/wram.py index 60001aa..e467a01 100644 --- a/pokemontools/wram.py +++ b/pokemontools/wram.py @@ -14,22 +14,48 @@ def make_wram_labels(wram_sections): wram_labels[label['address']] += [label['label']] return wram_labels +def bracket_value(string, i=0): + return string.split('[')[1 + i*2].split(']')[0] + def read_bss_sections(bss): sections = [] section = { - "labels": [], } address = None if type(bss) is not list: bss = bss.split('\n') for line in bss: line = line.lstrip() - if 'SECTION' in line: - if section: sections.append(section) # last section + if 'SECTION' == line[:7]: + if section: # previous + sections += [section] + + section_def = line.split(',') + name = section_def[0].split('"')[1] + type_ = section_def[1].strip() + if len(section_def) > 2: + bank = bracket_value(section_def[2]) + else: + bank = None + + if '[' in type_: + address = int(bracket_value(type_).replace('$','0x'), 16) + else: + if address == None or bank != section['bank']: + for type__, addr in [ + ('VRAM', 0x8000), + ('SRAM', 0xa000), + ('WRAM0', 0xc000), + ('WRAMX', 0xd000), + ('HRAM', 0xff80), + ]: + if type__ == type_ and section['type'] == type__: + address = addr + # else: keep going from this address - address = eval(line[line.find('[')+1:line.find(']')].replace('$','0x')) section = { - 'name': line.split('"')[1], - #'type': line.split(',')[1].split('[')[0].strip(), + 'name': name, + 'type': type_, + 'bank': bank, 'start': address, 'labels': [], } |