This commit is contained in:
Aroymart 2023-05-28 21:07:59 -05:00 committed by GitHub
commit 35f9c7f6b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -560,6 +560,8 @@ relative_unconditional_jumps = [0xc3, 0x18]
call_commands = [0xdc, 0xd4, 0xc4, 0xcc, 0xcd]
avoid_wram_execution = False
def asm_label(address):
"""
Return the ASM label using the address.
@ -624,7 +626,7 @@ class Disassembler(object):
rom_path = os.path.join(self.config.path, "baserom.gbc")
self.rom = bytearray(open(rom_path, "rb").read())
def find_label(self, local_address, bank_id=0):
def find_label(self, local_address, bank_id=0, wram_suitable = True):
# keep an integer
if type(local_address) == str:
local_address = int(local_address.replace("$", "0x"), 16)
@ -632,6 +634,9 @@ class Disassembler(object):
if local_address < 0x8000:
for label_entry in self.labels.labels:
if get_local_address(label_entry["address"]) == local_address:
if label_entry["label"][0] == "w": # we assume this means it'll be wram
if avoid_wram_execution and not wram_suitable:
continue
if "bank" in label_entry and (label_entry["bank"] == bank_id or label_entry["bank"] == 0):
return label_entry["label"]
if local_address in self.wram.wram_labels.keys():
@ -641,6 +646,19 @@ class Disassembler(object):
return constants[local_address]
return None
def check_if_wram_label_suitable(self, opcode):
if opcode in call_commands:
return False
if opcode in relative_unconditional_jumps:
return False
if opcode in relative_jumps:
return False
if opcode in discrete_jumps:
return False
if opcode == 0xdf or opcode == 0xef:
return False
return True
def find_address_from_label(self, label):
for label_entry in self.labels.labels:
if label == label_entry["label"]:
@ -840,7 +858,7 @@ class Disassembler(object):
data_tables[pointer]['usage'] += 1
insertion = "$%.4x" % (number)
result = self.find_label(insertion, bank_id)
result = self.find_label(insertion, bank_id, self.check_if_wram_label_suitable(current_byte) )
if result != None:
insertion = result
@ -892,7 +910,7 @@ class Disassembler(object):
number += byte2 << 8
insertion = "$%.4x" % (number)
result = self.find_label(insertion, temp_bank)
result = self.find_label(insertion, temp_bank, self.check_if_wram_label_suitable(current_byte))
if op_code_byte == 0xef:
if result != None:
insertion = result
@ -979,6 +997,8 @@ if __name__ == "__main__":
disasm = Disassembler(conf)
disasm.initialize()
if "-nwe" in sys.argv:
avoid_wram_execution = True
addr = sys.argv[1]
if ":" in addr:
addr = addr.split(":")