From 0fd121a81e1cbbf1a42e72a5d7c9e8099ef59f97 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 5 Dec 2013 16:38:31 -0500 Subject: wram: try to determine addresses for section defs without any --- pokemontools/wram.py | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'pokemontools/wram.py') 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': [], } -- cgit v1.2.3 From 460171a2c52d6fcd591559ab1c5fff09e9bc49cb Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 6 Dec 2013 19:42:58 -0500 Subject: wram: cleaner line parsing fixes 0fd121a8 --- pokemontools/wram.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'pokemontools/wram.py') diff --git a/pokemontools/wram.py b/pokemontools/wram.py index e467a01..7bc017d 100644 --- a/pokemontools/wram.py +++ b/pokemontools/wram.py @@ -20,11 +20,19 @@ def bracket_value(string, i=0): def read_bss_sections(bss): sections = [] section = { + 'name': None, + 'type': None, + 'bank': None, + 'start': None, + 'labels': [], } address = None if type(bss) is not list: bss = bss.split('\n') for line in bss: - line = line.lstrip() + + comment_index = line.find(';') + line, comment = line[:comment_index].lstrip(), line[comment_index:] + if 'SECTION' == line[:7]: if section: # previous sections += [section] @@ -71,7 +79,7 @@ def read_bss_sections(bss): }] elif line[:3] == 'ds ': - length = eval(line[3:line.find(';')].replace('$','0x')) + length = eval(line[3:].replace('$','0x')) address += length # adjacent labels use the same space for label in section['labels'][::-1]: -- cgit v1.2.3 From b0fa67a51191a9ddc2a4ce548ade0243b6be554c Mon Sep 17 00:00:00 2001 From: yenatch Date: Wed, 11 Dec 2013 20:28:25 -0500 Subject: wram: fix section address allocation who wrote this? --- pokemontools/wram.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'pokemontools/wram.py') diff --git a/pokemontools/wram.py b/pokemontools/wram.py index 7bc017d..87af4a2 100644 --- a/pokemontools/wram.py +++ b/pokemontools/wram.py @@ -48,16 +48,16 @@ def read_bss_sections(bss): 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 + types = { + 'VRAM': 0x8000, + 'SRAM': 0xa000, + 'WRAM0': 0xc000, + 'WRAMX': 0xd000, + 'HRAM': 0xff80, + } + if address == None or bank != section['bank'] or section['type'] != type_: + if type_ in types.keys(): + address = types[type_] # else: keep going from this address section = { -- cgit v1.2.3