ref: 7804dedce469cd40efbc140b80d84733ec853338
parent: e199aaa8fd73d932e81ef339f4f826cf95a700b9
author: yenatch <[email protected]>
date: Mon Jun 24 23:43:58 EDT 2013
gbz80disasm: detect data tables referenced in asm
--- a/extras/gbz80disasm.py
+++ b/extras/gbz80disasm.py
@@ -590,6 +590,8 @@
def asm_label(address):
# why using a random value when you can use the address?
return '.ASM_%x' % address
+def data_label(address):
+ return '.DATA_%x' % address
def output_bank_opcodes(original_offset, max_byte_count=0x4000, include_last_address=True, stop_at=[], debug = False):
#fs = current_address
@@ -622,6 +624,7 @@
end_address = original_offset + max_byte_count
byte_labels = {}
+ data_tables = {}
first_loop = True
output = ""
@@ -772,6 +775,13 @@
number = byte1
number += byte2 << 8
+ pointer = bank_id * 0x4000 + (number & 0x3fff)
+ if pointer not in data_tables.keys():
+ data_tables[pointer] = {}
+ data_tables[pointer]['usage'] = 0
+ else:
+ data_tables[pointer]['usage'] += 1
+
insertion = "$%.4x" % (number)
result = find_label(insertion, bank_id)
if result != None:
@@ -824,7 +834,7 @@
keep_reading = False
is_data = False #cleanup
break
- elif offset not in byte_labels.keys():
+ elif offset not in byte_labels.keys() or offset in data_tables.keys():
is_data = True
keep_reading = True
else:
@@ -838,6 +848,10 @@
else:
is_data = False
keep_reading = True
+
+ if offset in data_tables.keys():
+ output = output.replace('$%x' % ((offset & 0x3fff) + 0x4000 * bool(bank_id)), data_label(offset).lower())
+ output += data_label(offset).lower() + '\n'
first_loop = False