diff options
author | Bryan Bishop <kanzure@gmail.com> | 2013-07-11 09:01:02 -0700 |
---|---|---|
committer | Bryan Bishop <kanzure@gmail.com> | 2013-07-11 09:01:02 -0700 |
commit | 1bb9b7757cff27b086a16bf4ad926979146efaa4 (patch) | |
tree | bb9f875ef0ff2c882c166a9539c016a6ca2368af /wram.py | |
parent | 642fb1c7a23450b3c7caed1a49137c5d364b6365 (diff) | |
parent | f2717519a86edfde72d519d707c50ad08d146255 (diff) |
Merge pull request #158 from yenatch/gbz80disasm-more-data
gbz80disasm bugfixes
original-commit-id: 226729d1750bc6ee0c45d96e3f6b7dcf0844a609
Diffstat (limited to 'wram.py')
-rw-r--r-- | wram.py | 36 |
1 files changed, 28 insertions, 8 deletions
@@ -2,6 +2,10 @@ # RGBDS BSS section and constant parsing. +import os +path = os.path.dirname(os.path.abspath(__file__)) + + def read_bss_sections(bss): sections = [] section = {} @@ -19,21 +23,37 @@ def read_bss_sections(bss): 'start': address, 'labels': [], } + elif ':' in line: - # the only labels that don't use :s so far are enders, - # which we typically don't want to end up in the output + # rgbds allows labels without :, but prefer convention label = line[:line.find(':')] if ';' not in label: - section['labels'] += [{'label': label, 'address': address, 'length': 0}] + section['labels'] += [{ + 'label': label, + 'address': address, + 'length': 0, + }] + elif line[:3] == 'ds ': length = eval(line[3:line.find(';')].replace('$','0x')) address += length - if section['labels']: - section['labels'][-1]['length'] += length + # adjacent labels use the same space + for label in section['labels'][::-1]: + if label['length'] == 0: + label['length'] = length + else: + break + + elif 'EQU' in line: + # some space is defined using constants + name, value = line.split('EQU') + name, value = name.strip(), value.strip().replace('$','0x').replace('%','0b') + globals()[name] = eval(value) + sections.append(section) return sections -wram_sections = read_bss_sections(open('../wram.asm', 'r').readlines()) +wram_sections = read_bss_sections(open(os.path.join(path, '../wram.asm'), 'r').readlines()) def make_wram_labels(): @@ -56,6 +76,6 @@ def scrape_constants(text): text = text.split('\n') return constants_to_dict([line for line in text if 'EQU' in line[:line.find(';')]]) -hram_constants = scrape_constants(open('../hram.asm','r').readlines()) -gbhw_constants = scrape_constants(open('../gbhw.asm','r').readlines()) +hram_constants = scrape_constants(open(os.path.join(path, '../hram.asm'),'r').readlines()) +gbhw_constants = scrape_constants(open(os.path.join(path, '../gbhw.asm'),'r').readlines()) |