summaryrefslogtreecommitdiff
path: root/extras/gbz80disasm.py
diff options
context:
space:
mode:
Diffstat (limited to 'extras/gbz80disasm.py')
-rw-r--r--extras/gbz80disasm.py48
1 files changed, 35 insertions, 13 deletions
diff --git a/extras/gbz80disasm.py b/extras/gbz80disasm.py
index 08fea8b02..03824180e 100644
--- a/extras/gbz80disasm.py
+++ b/extras/gbz80disasm.py
@@ -13,6 +13,11 @@ if not hasattr(json, "read"):
json.read = json.loads
def load_rom(filename="../baserom.gbc"):
+ """
+ Load the specified rom.
+
+ If no rom is given, load "../baserom.gbc".
+ """
global rom
rom = bytearray(open(filename,'rb').read())
return rom
@@ -559,6 +564,11 @@ call_commands = [0xdc, 0xd4, 0xc4, 0xcc, 0xcd]
all_labels = {}
def load_labels(filename="labels.json"):
+ """
+ Load labels from specified file.
+
+ If no filename is given, loads 'labels.json'.
+ """
global all_labels
# don't re-load labels each time
@@ -596,31 +606,42 @@ def find_address_from_label(label):
return None
def asm_label(address):
+ """
+ Return the ASM label using the address.
+ """
# why using a random value when you can use the address?
return '.asm_%x' % address
+
def data_label(address):
return '.data_%x' % address
def get_local_address(address):
bank = address / 0x4000
return (address & 0x3fff) + 0x4000 * bool(bank)
+
def get_global_address(address, bank):
if address < 0x8000:
return (address & 0x3fff) + 0x4000 * bank
return None
-def output_bank_opcodes(original_offset, max_byte_count=0x4000, include_last_address=True, stop_at=[], debug = False):
- #fs = current_address
- #b = bank_byte
- #in = input_data -- rom
- #bank_size = byte_count
- #i = offset
- #ad = end_address
- #a, oa = current_byte_number
+ return ".ASM_" + hex(address)[2:]
- # stop_at can be used to supply a list of addresses to not disassemble
- # over. This is useful if you know in advance that there are a lot of
- # fall-throughs.
+def output_bank_opcodes(original_offset, max_byte_count=0x4000, include_last_address=True, stop_at=[], debug=False):
+ """
+ Output bank opcodes.
+
+ fs = current_address
+ b = bank_byte
+ in = input_data -- rom
+ bank_size = byte_count
+ i = offset
+ ad = end_address
+ a, oa = current_byte_number
+
+ stop_at can be used to supply a list of addresses to not disassemble
+ over. This is useful if you know in advance that there are a lot of
+ fall-throughs.
+ """
load_labels()
load_rom()
@@ -891,8 +912,9 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000, include_last_add
def has_outstanding_labels(byte_labels):
"""
- If a label is used once in the asm output, then that means it has to be
- called or specified later.
+ Check whether a label is used once in the asm output.
+
+ If so, then that means it has to be called or specified later.
"""
for label_line in byte_labels.keys():
real_line = byte_labels[label_line]