wram: try to determine addresses for section defs without any

This commit is contained in:
yenatch 2013-12-05 16:38:31 -05:00
parent c57e0f0706
commit 0fd121a81e

View File

@ -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': [],
}