From b7978e23d2e7b2077d1093a05503c92fd804d03d Mon Sep 17 00:00:00 2001 From: yenatch Date: Tue, 25 Jun 2013 03:43:58 -0400 Subject: gbz80disasm: detect data tables referenced in asm original-commit-id: 7804dedce469cd40efbc140b80d84733ec853338 --- gbz80disasm.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/gbz80disasm.py b/gbz80disasm.py index 94df755..8da28ee 100644 --- a/gbz80disasm.py +++ b/gbz80disasm.py @@ -590,6 +590,8 @@ def find_label(local_address, bank_id=0): 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 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000, include_last_add end_address = original_offset + max_byte_count byte_labels = {} + data_tables = {} first_loop = True output = "" @@ -772,6 +775,13 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000, include_last_add 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 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000, include_last_add 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: @@ -839,6 +849,10 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000, include_last_add 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 #clean up unused labels -- cgit v1.2.3