diff options
author | Andrew Martinek <andrewrmartinek@gmail.com> | 2019-10-06 23:00:27 -0400 |
---|---|---|
committer | Andrew Martinek <andrewrmartinek@gmail.com> | 2019-10-06 23:00:27 -0400 |
commit | a44f17b9a15cf1a572d5e8056a69c368265729f2 (patch) | |
tree | e8137a71e6c6fb2cbb56d3d58be084f3958ba39e /tools/tcgdisasm.py | |
parent | fda59356c20813bb57d59de8d9b2b100f0fe275d (diff) |
Fixed a few macros that were giving weird code. Updated tcgdisasm
Diffstat (limited to 'tools/tcgdisasm.py')
-rw-r--r-- | tools/tcgdisasm.py | 29 |
1 files changed, 27 insertions, 2 deletions
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 |