diff options
author | Bryan Bishop <kanzure@gmail.com> | 2013-08-27 11:18:30 -0500 |
---|---|---|
committer | Bryan Bishop <kanzure@gmail.com> | 2013-08-27 11:18:30 -0500 |
commit | ddc4a929058ff103cac5743ca39bb8e4b520ee90 (patch) | |
tree | 9d986f9685c4c898e80aab898d199f5b72f9977b /extras/wram.py | |
parent | c61b3d42ad4e88b32e9c321b7fcc559ec0220e64 (diff) | |
parent | 94f5f61265b9654925b66dca7c3256668435eeea (diff) |
Merge pull request #161 from kanzure/remove-extras
This merges branch 'remove-extras' into master. The extras/ path is now
replaced by a git submodule that is independently version controlled and
separate from the pokecrystal project.
The git submodule is a reference to v1.1.0 of this repository:
https://github.com/kanzure/pokemon-reverse-engineering-tools
It's also available as a generic python module now:
https://pypi.python.org/pypi/pokemontools
https://github.com/kanzure/pokecrystal/pull/161
Diffstat (limited to 'extras/wram.py')
m--------- | extras | 0 | ||||
-rw-r--r-- | extras/wram.py | 81 |
2 files changed, 0 insertions, 81 deletions
diff --git a/extras b/extras new file mode 160000 +Subproject 016f0206b5029fc83a6200be29b0f980c76dfd9 diff --git a/extras/wram.py b/extras/wram.py deleted file mode 100644 index 85057bee4..000000000 --- a/extras/wram.py +++ /dev/null @@ -1,81 +0,0 @@ -# coding: utf-8 - -# RGBDS BSS section and constant parsing. - -import os -path = os.path.dirname(os.path.abspath(__file__)) - - -def read_bss_sections(bss): - sections = [] - section = {} - 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 - - address = eval(line[line.find('[')+1:line.find(']')].replace('$','0x')) - section = { - 'name': line.split('"')[1], - #'type': line.split(',')[1].split('[')[0].strip(), - 'start': address, - 'labels': [], - } - - elif ':' in line: - # rgbds allows labels without :, but prefer convention - label = line[:line.find(':')] - if ';' not in label: - section['labels'] += [{ - 'label': label, - 'address': address, - 'length': 0, - }] - - elif line[:3] == 'ds ': - length = eval(line[3:line.find(';')].replace('$','0x')) - address += 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(os.path.join(path, '../wram.asm'), 'r').readlines()) - - -def make_wram_labels(): - wram_labels = {} - for section in wram_sections: - for label in section['labels']: - if label['address'] not in wram_labels.keys(): - wram_labels[label['address']] = [] - wram_labels[label['address']] += [label['label']] - return wram_labels - -wram_labels = make_wram_labels() - - -def constants_to_dict(constants): - return dict((eval(constant[constant.find('EQU')+3:constant.find(';')].replace('$','0x')), constant[:constant.find('EQU')].strip()) for constant in constants) - -def scrape_constants(text): - if type(text) is not list: - text = text.split('\n') - return constants_to_dict([line for line in text if 'EQU' in line[:line.find(';')]]) - -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()) - |