diff options
author | yenatch <yenatch@gmail.com> | 2013-12-02 14:43:43 -0500 |
---|---|---|
committer | yenatch <yenatch@gmail.com> | 2013-12-02 14:44:16 -0500 |
commit | 79630cd43b8e814afa517b473344d065217c851a (patch) | |
tree | aeb3da8c587773ef989e7c356ce73143afddf63c | |
parent | 80f32f5b379877be7ee58a5961024adcf6ea67b1 (diff) |
wram: more consistent rgbasm value conversion
-rw-r--r-- | pokemontools/wram.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/pokemontools/wram.py b/pokemontools/wram.py index 1f61ff5..d34737e 100644 --- a/pokemontools/wram.py +++ b/pokemontools/wram.py @@ -9,6 +9,11 @@ import os NUM_OBJECTS = 0x10 OBJECT_LENGTH = 0x10 + +def rgbasm_to_py(text): + return text.replace('$', '0x').replace('%', '0b') + + def make_wram_labels(wram_sections): wram_labels = {} for section in wram_sections: @@ -30,7 +35,7 @@ def read_bss_sections(bss): if 'SECTION' in line: if section: sections.append(section) # last section - address = eval(line[line.find('[')+1:line.find(']')].replace('$','0x')) + address = eval(rgbasm_to_py(line[line.find('[')+1:line.find(']')])) section = { 'name': line.split('"')[1], #'type': line.split(',')[1].split('[')[0].strip(), @@ -49,7 +54,7 @@ def read_bss_sections(bss): }] elif line[:3] == 'ds ': - length = eval(line[3:line.find(';')].replace('$','0x')) + length = eval(rgbasm_to_py(line[3:line.find(';')])) address += length # adjacent labels use the same space for label in section['labels'][::-1]: @@ -61,14 +66,14 @@ def read_bss_sections(bss): 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') + name, value = name.strip(), rgbasm_to_py(value) globals()[name] = eval(value) sections.append(section) return sections 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) + return dict((eval(rgbasm_to_py(constant[constant.find('EQU')+3:constant.find(';')])), constant[:constant.find('EQU')].strip()) for constant in constants) def scrape_constants(text): if type(text) is not list: |