summaryrefslogtreecommitdiff
path: root/extras/wram.py
diff options
context:
space:
mode:
authorBryan Bishop <kanzure@gmail.com>2013-05-15 12:09:31 -0700
committerBryan Bishop <kanzure@gmail.com>2013-05-15 12:09:31 -0700
commit5feb5fd208d68a3d8f4d0ce4d925512a8fbe3b97 (patch)
tree831df9be5469d1390f9b279a013ed0251c24fca7 /extras/wram.py
parent14567c2beeeb9272bcd98dfc68e0729ac3b3929e (diff)
parent5521aa5ce0ad5249ff0d369dd33b4f63cd804b73 (diff)
Merge pull request #137 from yenatch/master
gbz80disasm reads wram/gbhw/hram and spaces blocks of asm
Diffstat (limited to 'extras/wram.py')
-rw-r--r--extras/wram.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/extras/wram.py b/extras/wram.py
new file mode 100644
index 000000000..bad0b9fa9
--- /dev/null
+++ b/extras/wram.py
@@ -0,0 +1,61 @@
+# coding: utf-8
+
+# RGBDS BSS section and constant parsing.
+
+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:
+ # the only labels that don't use :s so far are enders,
+ # which we typically don't want to end up in the output
+ 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
+ if section['labels']:
+ section['labels'][-1]['length'] += length
+ sections.append(section)
+ return sections
+
+wram_sections = read_bss_sections(open('../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('../hram.asm','r').readlines())
+gbhw_constants = scrape_constants(open('../gbhw.asm','r').readlines())
+