From 9c2fcf813b7bf51a395c238b5edaa90dd0fef299 Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Sat, 4 Jun 2016 00:11:38 -0400 Subject: [PATCH 1/4] added "nwe" command line option to skip wram labels when considering operation that involve execution such as jp and call --- pokemontools/tcgdisasm.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/pokemontools/tcgdisasm.py b/pokemontools/tcgdisasm.py index 2e9e8b3..f2fc777 100755 --- a/pokemontools/tcgdisasm.py +++ b/pokemontools/tcgdisasm.py @@ -558,6 +558,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. @@ -622,7 +624,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) @@ -630,6 +632,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(): @@ -639,6 +644,17 @@ 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 + return True + def find_address_from_label(self, label): for label_entry in self.labels.labels: if label == label_entry["label"]: @@ -838,7 +854,8 @@ 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 @@ -890,7 +907,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 @@ -976,7 +993,10 @@ if __name__ == "__main__": conf = configuration.Config() disasm = Disassembler(conf) disasm.initialize() - + + if "-nwe" in sys.argv: + avoid_wram_execution = True + print(avoid_wram_execution) addr = sys.argv[1] if ":" in addr: addr = addr.split(":") From 2967ceb1352f8fd033c229f8eea09c9695228bff Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Sat, 4 Jun 2016 00:17:32 -0400 Subject: [PATCH 2/4] Formatting --- pokemontools/tcgdisasm.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pokemontools/tcgdisasm.py b/pokemontools/tcgdisasm.py index f2fc777..6025a49 100755 --- a/pokemontools/tcgdisasm.py +++ b/pokemontools/tcgdisasm.py @@ -855,7 +855,6 @@ class Disassembler(object): insertion = "$%.4x" % (number) result = self.find_label(insertion, bank_id, self.check_if_wram_label_suitable(current_byte) ) - if result != None: insertion = result @@ -993,7 +992,7 @@ if __name__ == "__main__": conf = configuration.Config() disasm = Disassembler(conf) disasm.initialize() - + if "-nwe" in sys.argv: avoid_wram_execution = True print(avoid_wram_execution) From 53a41590ec5157186b236771915af9fd23d6e4c7 Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Sat, 4 Jun 2016 00:42:15 -0400 Subject: [PATCH 3/4] Fix extra debug prints from appearing --- pokemontools/tcgdisasm.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pokemontools/tcgdisasm.py b/pokemontools/tcgdisasm.py index 6025a49..8f2cec0 100755 --- a/pokemontools/tcgdisasm.py +++ b/pokemontools/tcgdisasm.py @@ -995,7 +995,6 @@ if __name__ == "__main__": if "-nwe" in sys.argv: avoid_wram_execution = True - print(avoid_wram_execution) addr = sys.argv[1] if ":" in addr: addr = addr.split(":") From 3a37b822f9634c97c5e5a810621ecb1130e068c0 Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Sat, 4 Jun 2016 02:28:21 -0400 Subject: [PATCH 4/4] fixed rst macros. --- pokemontools/tcgdisasm.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pokemontools/tcgdisasm.py b/pokemontools/tcgdisasm.py index 8f2cec0..6189332 100755 --- a/pokemontools/tcgdisasm.py +++ b/pokemontools/tcgdisasm.py @@ -653,6 +653,8 @@ class Disassembler(object): 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):