summaryrefslogtreecommitdiff
path: root/extras/gbz80disasm.py
diff options
context:
space:
mode:
authorBryan Bishop <kanzure@gmail.com>2012-01-20 16:13:38 -0600
committerBryan Bishop <kanzure@gmail.com>2012-01-20 16:13:38 -0600
commita43794ce2ee9a2037ee12b8ae26b1045e62556e5 (patch)
tree0e3d5d4ecdad155aed1b8d86cda8d15ffa8d36e7 /extras/gbz80disasm.py
parent0bf1f601c4c4adf44160ea5d425afbecec407895 (diff)
update gbz80disasm to account for conditional relative forward jumps
hg-commit-id: 86a98b551bf2
Diffstat (limited to 'extras/gbz80disasm.py')
-rw-r--r--extras/gbz80disasm.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/extras/gbz80disasm.py b/extras/gbz80disasm.py
index 08115602..dbfb4e32 100644
--- a/extras/gbz80disasm.py
+++ b/extras/gbz80disasm.py
@@ -546,7 +546,7 @@ end_08_scripts_with = [
0xc9, #ret
###0xda, 0xe9, 0xd2, 0xc2, 0xca, 0xc3, 0x38, 0x30, 0x20, 0x28, 0x18, 0xd8, 0xd0, 0xc0, 0xc8, 0xc9
]
-relative_jumps = [0x38, 0x30, 0x20, 0x28, 0x18, 0xc3]
+relative_jumps = [0x38, 0x30, 0x20, 0x28, 0x18, 0xc3, 0xda]
relative_unconditional_jumps = [0xc3, 0x18]
#TODO: replace call and a pointer with call and a label
@@ -746,7 +746,7 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
if current_byte == 0xc3:
if number == 0x3d97: used_3d97 = True
#if number == 0x24d7: #jp
- if not has_outstanding_labels(byte_labels):
+ if not has_outstanding_labels(byte_labels) or all_outstanding_labels_are_reverse(byte_labels, offset):
keep_reading = False
is_data = False
break
@@ -754,11 +754,17 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
is_data = True
#stop reading at a jump, relative jump or return
- if current_byte in end_08_scripts_with or (current_byte == 0x18 and target_address < offset):
- if not has_outstanding_labels(byte_labels) or (current_byte == 0x18 and target_address < offset):
+ if current_byte in end_08_scripts_with:
+ if not has_outstanding_labels(byte_labels) and all_outstanding_labels_are_reverse(byte_labels, offset):
keep_reading = False
is_data = False #cleanup
break
+ else:
+ is_data = False
+ keep_reading = True
+ else:
+ is_data = False
+ keep_reading = True
else:
# if is_data and keep_reading:
output += spacing + "db $" + hex(ord(rom[offset]))[2:] #+ " ; " + hex(offset)
@@ -792,6 +798,13 @@ def has_outstanding_labels(byte_labels):
if real_line["definition"] == False: return True
return False
+def all_outstanding_labels_are_reverse(byte_labels, offset):
+ for label_id in byte_labels.keys():
+ line = byte_labels[label_id] # label_id is also the address
+ if line["definition"] == False:
+ if not label_id < offset: return False
+ return True
+
def text_asm_pretty_printer(label, address_of_08, include_08=True):
"""returns (output, end_address)"""
output = label + ": ; " + hex(address_of_08) + "\n"