You've already forked pokecrystal-board
mirror of
https://gitlab.com/xCrystal/pokecrystal-board.git
synced 2025-09-08 08:13:02 -07:00
gbz80disasm: detect data tables referenced in asm
This commit is contained in:
@@ -590,6 +590,8 @@ def find_label(local_address, bank_id=0):
|
|||||||
def asm_label(address):
|
def asm_label(address):
|
||||||
# why using a random value when you can use the address?
|
# why using a random value when you can use the address?
|
||||||
return '.ASM_%x' % 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):
|
def output_bank_opcodes(original_offset, max_byte_count=0x4000, include_last_address=True, stop_at=[], debug = False):
|
||||||
#fs = current_address
|
#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
|
end_address = original_offset + max_byte_count
|
||||||
|
|
||||||
byte_labels = {}
|
byte_labels = {}
|
||||||
|
data_tables = {}
|
||||||
|
|
||||||
first_loop = True
|
first_loop = True
|
||||||
output = ""
|
output = ""
|
||||||
@@ -772,6 +775,13 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000, include_last_add
|
|||||||
number = byte1
|
number = byte1
|
||||||
number += byte2 << 8
|
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)
|
insertion = "$%.4x" % (number)
|
||||||
result = find_label(insertion, bank_id)
|
result = find_label(insertion, bank_id)
|
||||||
if result != None:
|
if result != None:
|
||||||
@@ -824,7 +834,7 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000, include_last_add
|
|||||||
keep_reading = False
|
keep_reading = False
|
||||||
is_data = False #cleanup
|
is_data = False #cleanup
|
||||||
break
|
break
|
||||||
elif offset not in byte_labels.keys():
|
elif offset not in byte_labels.keys() or offset in data_tables.keys():
|
||||||
is_data = True
|
is_data = True
|
||||||
keep_reading = True
|
keep_reading = True
|
||||||
else:
|
else:
|
||||||
@@ -839,6 +849,10 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000, include_last_add
|
|||||||
is_data = False
|
is_data = False
|
||||||
keep_reading = True
|
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
|
first_loop = False
|
||||||
|
|
||||||
#clean up unused labels
|
#clean up unused labels
|
||||||
|
Reference in New Issue
Block a user