From a44f17b9a15cf1a572d5e8056a69c368265729f2 Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Sun, 6 Oct 2019 23:00:27 -0400 Subject: Fixed a few macros that were giving weird code. Updated tcgdisasm --- tools/tcgdisasm.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'tools/tcgdisasm.py') diff --git a/tools/tcgdisasm.py b/tools/tcgdisasm.py index d6731d0..1ca622a 100644 --- a/tools/tcgdisasm.py +++ b/tools/tcgdisasm.py @@ -310,6 +310,8 @@ call_commands = [0xcd, 0xc4, 0xcc, 0xd4, 0xdc, 0xdf, 0xef] relative_jumps = [0x18, 0x20, 0x28, 0x30, 0x38] unconditional_jumps = [0xc3, 0x18] +# the flag macros found in bank 3. They db a byte after calling so need to be treated specially +flag_macros = [(0xca8f,"set_flag_value {}"),(0xcacd,"zero_flag_value {}"), (0xca69,"get_flag_value {}")] def asm_label(address): """ @@ -740,11 +742,17 @@ class Disassembler(object): opcode_output_str = bit_ops_table[opcode_arg_1] elif opcode_nargs == 2: + + # define opcode_output_str as None so we can substitute our own if a macro appears + opcode_output_str = None + # opcodes with a pointer as an argument # format the two arguments into a little endian 16-bit pointer local_target_offset = opcode_arg_2 << 8 | opcode_arg_1 + # get the global offset of the pointer target_offset = get_global_address(local_target_offset, bank_id) + # attempt to look for a matching label if opcode_byte == 0xdf: # bank1call @@ -753,7 +761,23 @@ class Disassembler(object): # regular call or jump instructions target_label = self.find_label(local_target_offset, bank_id) - if opcode_byte in call_commands + absolute_jumps: + # handle the special flag macros + found_flag_macro = False + for flag_macro in flag_macros: + if flag_macro[0] == target_offset: + print "hi" + found_flag_macro = True + current_flag_macro = flag_macro + event_flag = "EVENT_FLAG_" + format(opcode_arg_3, "02X") + opcode_output_str = flag_macro[1].format(event_flag) + + # we need to skip a byte since this macro takes one extra + opcode_nargs+=1 + break + + + if not found_flag_macro and opcode_byte in call_commands + absolute_jumps: + if target_label is None: # if this is a call or jump opcode and the target label is not defined, create an undocumented label descriptor target_label = "Func_%x" % target_offset @@ -793,7 +817,8 @@ class Disassembler(object): data_tables[local_target_offset]["definition"] = False # format the label that was created into the opcode string - opcode_output_str = opcode_str.format(target_label) + if opcode_output_str is None: + opcode_output_str = opcode_str.format(target_label) elif opcode_nargs == 3: # macros with bank and pointer as an argument -- cgit v1.2.3 From 299f013b8b14184b9f06da3b89ba87ce2ba9e0f3 Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Sun, 13 Oct 2019 19:39:13 -0400 Subject: More scripts, start to figure out mapscripts --- tools/tcgdisasm.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tools/tcgdisasm.py') diff --git a/tools/tcgdisasm.py b/tools/tcgdisasm.py index 1ca622a..edc5df4 100644 --- a/tools/tcgdisasm.py +++ b/tools/tcgdisasm.py @@ -304,7 +304,7 @@ bit_ops_table = [ "set 7, b", "set 7, c", "set 7, d", "set 7, e", "set 7, h", "set 7, l", "set 7, [hl]", "set 7, a" # $f8 - $ff ] -unconditional_returns = [0xc9, 0xd9] +unconditional_returns = [0xc9, 0xd9, 0xe7] # e7 begins a script, which is not handled by tcgdisasm absolute_jumps = [0xc3, 0xc2, 0xca, 0xd2, 0xda] call_commands = [0xcd, 0xc4, 0xcc, 0xd4, 0xdc, 0xdf, 0xef] relative_jumps = [0x18, 0x20, 0x28, 0x30, 0x38] @@ -765,7 +765,6 @@ class Disassembler(object): found_flag_macro = False for flag_macro in flag_macros: if flag_macro[0] == target_offset: - print "hi" found_flag_macro = True current_flag_macro = flag_macro event_flag = "EVENT_FLAG_" + format(opcode_arg_3, "02X") -- cgit v1.2.3 From 0b1318f49d0f17847f52c3fd35ea2574d9b7af78 Mon Sep 17 00:00:00 2001 From: Andrew Martinek Date: Tue, 29 Oct 2019 16:35:33 -0400 Subject: Updated tcgdisasm to include a few new stack macros --- tools/tcgdisasm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/tcgdisasm.py') diff --git a/tools/tcgdisasm.py b/tools/tcgdisasm.py index edc5df4..579d577 100644 --- a/tools/tcgdisasm.py +++ b/tools/tcgdisasm.py @@ -311,7 +311,7 @@ relative_jumps = [0x18, 0x20, 0x28, 0x30, 0x38] unconditional_jumps = [0xc3, 0x18] # the flag macros found in bank 3. They db a byte after calling so need to be treated specially -flag_macros = [(0xca8f,"set_flag_value {}"),(0xcacd,"zero_flag_value {}"), (0xca69,"get_flag_value {}")] +flag_macros = [(0xca8f,"set_flag_value {}"),(0xcacd,"zero_flag_value {}"),(0xca84,"zero_flag_value2 {}"), (0xcac2,"max_flag_value {}"), (0xca69,"get_flag_value {}")] def asm_label(address): """ -- cgit v1.2.3