mirror of
https://gitlab.com/xCrystal/pokecrystal-board.git
synced 2025-01-23 09:16:20 -08:00
Merge pull request #158 from yenatch/gbz80disasm-more-data
gbz80disasm bugfixes
This commit is contained in:
commit
226729d175
@ -1476,7 +1476,7 @@ class PointerLabelToScriptPointer(PointerLabelParam):
|
|||||||
def parse(self):
|
def parse(self):
|
||||||
PointerLabelParam.parse(self)
|
PointerLabelParam.parse(self)
|
||||||
address = calculate_pointer_from_bytes_at(self.parsed_address, bank=self.bank)
|
address = calculate_pointer_from_bytes_at(self.parsed_address, bank=self.bank)
|
||||||
address2 = calculate_pointer_from_bytes_at(address, bank="reverse") # maybe not "reverse"?
|
address2 = calculate_pointer_from_bytes_at(address, bank=True)
|
||||||
self.script = parse_script_engine_script_at(address2, origin=False, map_group=self.map_group, map_id=self.map_id, force=self.force, debug=self.debug)
|
self.script = parse_script_engine_script_at(address2, origin=False, map_group=self.map_group, map_id=self.map_id, force=self.force, debug=self.debug)
|
||||||
|
|
||||||
|
|
||||||
@ -2657,10 +2657,10 @@ text_command_classes = inspect.getmembers(sys.modules[__name__], \
|
|||||||
pksv_crystal_more = {
|
pksv_crystal_more = {
|
||||||
0x00: ["2call", ["pointer", ScriptPointerLabelParam]],
|
0x00: ["2call", ["pointer", ScriptPointerLabelParam]],
|
||||||
0x01: ["3call", ["pointer", ScriptPointerLabelBeforeBank]],
|
0x01: ["3call", ["pointer", ScriptPointerLabelBeforeBank]],
|
||||||
0x02: ["2ptcall", ["pointer", PointerLabelToScriptPointer]],
|
0x02: ["2ptcall", ["pointer", RAMAddressParam]],
|
||||||
0x03: ["2jump", ["pointer", ScriptPointerLabelParam]],
|
0x03: ["2jump", ["pointer", ScriptPointerLabelParam]],
|
||||||
0x04: ["3jump", ["pointer", ScriptPointerLabelBeforeBank]],
|
0x04: ["3jump", ["pointer", ScriptPointerLabelBeforeBank]],
|
||||||
0x05: ["2ptjump", ["pointer", PointerLabelToScriptPointer]],
|
0x05: ["2ptjump", ["pointer", RAMAddressParam]],
|
||||||
0x06: ["if equal", ["byte", SingleByteParam], ["pointer", ScriptPointerLabelParam]],
|
0x06: ["if equal", ["byte", SingleByteParam], ["pointer", ScriptPointerLabelParam]],
|
||||||
0x07: ["if not equal", ["byte", SingleByteParam], ["pointer", ScriptPointerLabelParam]],
|
0x07: ["if not equal", ["byte", SingleByteParam], ["pointer", ScriptPointerLabelParam]],
|
||||||
0x08: ["iffalse", ["pointer", ScriptPointerLabelParam]],
|
0x08: ["iffalse", ["pointer", ScriptPointerLabelParam]],
|
||||||
@ -2671,7 +2671,7 @@ pksv_crystal_more = {
|
|||||||
0x0D: ["callstd", ["predefined_script", MultiByteParam]],
|
0x0D: ["callstd", ["predefined_script", MultiByteParam]],
|
||||||
0x0E: ["3callasm", ["asm", AsmPointerParam]],
|
0x0E: ["3callasm", ["asm", AsmPointerParam]],
|
||||||
0x0F: ["special", ["predefined_script", MultiByteParam]],
|
0x0F: ["special", ["predefined_script", MultiByteParam]],
|
||||||
0x10: ["2ptcallasm", ["asm", PointerToAsmPointerParam]],
|
0x10: ["2ptcallasm", ["asm", RAMAddressParam]],
|
||||||
# should map_group/map_id be dealt with in some special way in the asm?
|
# should map_group/map_id be dealt with in some special way in the asm?
|
||||||
0x11: ["checkmaptriggers", ["map_group", SingleByteParam], ["map_id", SingleByteParam]],
|
0x11: ["checkmaptriggers", ["map_group", SingleByteParam], ["map_id", SingleByteParam]],
|
||||||
0x12: ["domaptrigger", ["map_group", MapGroupParam], ["map_id", MapIdParam], ["trigger_id", SingleByteParam]],
|
0x12: ["domaptrigger", ["map_group", MapGroupParam], ["map_id", MapIdParam], ["trigger_id", SingleByteParam]],
|
||||||
@ -7353,15 +7353,15 @@ def write_all_labels(all_labels, filename="labels.json"):
|
|||||||
fh.close()
|
fh.close()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# TODO: implement get_ram_label
|
from wram import wram_labels
|
||||||
# wram.asm integration would be nice
|
|
||||||
def get_ram_label(address):
|
def get_ram_label(address):
|
||||||
"""not implemented yet.. supposed to get a label for a particular RAM location
|
"""returns a label assigned to a particular ram address"""
|
||||||
like W_PARTYPOKE1HP"""
|
if address in wram_labels.keys():
|
||||||
|
return wram_labels[address][-1]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_label_for(address):
|
def get_label_for(address):
|
||||||
"""returns a label assigned to a particular address"""
|
"""returns a label assigned to a particular rom address"""
|
||||||
global all_labels
|
global all_labels
|
||||||
|
|
||||||
if address == None:
|
if address == None:
|
||||||
|
@ -555,6 +555,8 @@ end_08_scripts_with = [
|
|||||||
##0x18, #jr
|
##0x18, #jr
|
||||||
###0xda, 0xe9, 0xd2, 0xc2, 0xca, 0xc3, 0x38, 0x30, 0x20, 0x28, 0x18, 0xd8, 0xd0, 0xc0, 0xc8, 0xc9
|
###0xda, 0xe9, 0xd2, 0xc2, 0xca, 0xc3, 0x38, 0x30, 0x20, 0x28, 0x18, 0xd8, 0xd0, 0xc0, 0xc8, 0xc9
|
||||||
]
|
]
|
||||||
|
|
||||||
|
discrete_jumps = [0xda, 0xe9, 0xd2, 0xc2, 0xca, 0xc3]
|
||||||
relative_jumps = [0x38, 0x30, 0x20, 0x28, 0x18, 0xc3, 0xda, 0xc2]
|
relative_jumps = [0x38, 0x30, 0x20, 0x28, 0x18, 0xc3, 0xda, 0xc2]
|
||||||
relative_unconditional_jumps = [0xc3, 0x18]
|
relative_unconditional_jumps = [0xc3, 0x18]
|
||||||
|
|
||||||
@ -597,6 +599,12 @@ def find_label(local_address, bank_id=0):
|
|||||||
return constants[local_address]
|
return constants[local_address]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def find_address_from_label(label):
|
||||||
|
for label_entry in all_labels:
|
||||||
|
if label == label_entry["label"]:
|
||||||
|
return label_entry["address"]
|
||||||
|
return None
|
||||||
|
|
||||||
def asm_label(address):
|
def asm_label(address):
|
||||||
"""
|
"""
|
||||||
Return the ASM label using the address.
|
Return the ASM label using the address.
|
||||||
@ -612,7 +620,9 @@ def get_local_address(address):
|
|||||||
return (address & 0x3fff) + 0x4000 * bool(bank)
|
return (address & 0x3fff) + 0x4000 * bool(bank)
|
||||||
|
|
||||||
def get_global_address(address, bank):
|
def get_global_address(address, bank):
|
||||||
return (address & 0x3fff) + 0x4000 * bank
|
if address < 0x8000:
|
||||||
|
return (address & 0x3fff) + 0x4000 * bank
|
||||||
|
return None
|
||||||
|
|
||||||
return ".ASM_" + hex(address)[2:]
|
return ".ASM_" + hex(address)[2:]
|
||||||
|
|
||||||
@ -802,12 +812,13 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000, include_last_add
|
|||||||
number = byte1
|
number = byte1
|
||||||
number += byte2 << 8
|
number += byte2 << 8
|
||||||
|
|
||||||
pointer = get_global_address(number, bank_id)
|
if current_byte not in call_commands + discrete_jumps + relative_jumps:
|
||||||
if pointer not in data_tables.keys():
|
pointer = get_global_address(number, bank_id)
|
||||||
data_tables[pointer] = {}
|
if pointer not in data_tables.keys():
|
||||||
data_tables[pointer]['usage'] = 0
|
data_tables[pointer] = {}
|
||||||
else:
|
data_tables[pointer]['usage'] = 0
|
||||||
data_tables[pointer]['usage'] += 1
|
else:
|
||||||
|
data_tables[pointer]['usage'] += 1
|
||||||
|
|
||||||
insertion = "$%.4x" % (number)
|
insertion = "$%.4x" % (number)
|
||||||
result = find_label(insertion, bank_id)
|
result = find_label(insertion, bank_id)
|
||||||
@ -861,7 +872,7 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000, include_last_add
|
|||||||
keep_reading = False
|
keep_reading = False
|
||||||
is_data = False #cleanup
|
is_data = False #cleanup
|
||||||
break
|
break
|
||||||
elif offset not in byte_labels.keys() or offset in data_tables.keys():
|
elif offset not in byte_labels.keys() and offset in data_tables.keys():
|
||||||
is_data = True
|
is_data = True
|
||||||
keep_reading = True
|
keep_reading = True
|
||||||
else:
|
else:
|
||||||
@ -920,10 +931,15 @@ def all_outstanding_labels_are_reverse(byte_labels, offset):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
load_labels()
|
||||||
addr = sys.argv[1]
|
addr = sys.argv[1]
|
||||||
if ":" in addr:
|
if ":" in addr:
|
||||||
addr = addr.split(":")
|
addr = addr.split(":")
|
||||||
addr = int(addr[0], 16)*0x4000+(int(addr[1], 16)%0x4000)
|
addr = int(addr[0], 16)*0x4000+(int(addr[1], 16)%0x4000)
|
||||||
else:
|
else:
|
||||||
addr = int(addr, 16)
|
label_addr = find_address_from_label(addr)
|
||||||
|
if label_addr:
|
||||||
|
addr = label_addr
|
||||||
|
else:
|
||||||
|
addr = int(addr, 16)
|
||||||
print output_bank_opcodes(addr)[0]
|
print output_bank_opcodes(addr)[0]
|
||||||
|
@ -31,8 +31,10 @@ def line_has_comment_address(line, returnable={}, bank=None):
|
|||||||
returnable["bank"] = None
|
returnable["bank"] = None
|
||||||
returnable["offset"] = None
|
returnable["offset"] = None
|
||||||
returnable["address"] = None
|
returnable["address"] = None
|
||||||
#only valid characters are 0-9A-F
|
#only valid characters are 0-9a-fA-F
|
||||||
valid = [str(x) for x in range(0,10)] + [chr(x) for x in range(97, 102+1)]
|
valid = [str(x) for x in range(10)] + \
|
||||||
|
[chr(x) for x in range(ord('a'), ord('f')+1)] + \
|
||||||
|
[chr(x) for x in range(ord('A'), ord('F')+1)]
|
||||||
#check if there is a comment in this line
|
#check if there is a comment in this line
|
||||||
if ";" not in line:
|
if ";" not in line:
|
||||||
return False
|
return False
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
# RGBDS BSS section and constant parsing.
|
# RGBDS BSS section and constant parsing.
|
||||||
|
|
||||||
|
import os
|
||||||
|
path = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
|
||||||
def read_bss_sections(bss):
|
def read_bss_sections(bss):
|
||||||
sections = []
|
sections = []
|
||||||
section = {}
|
section = {}
|
||||||
@ -19,21 +23,37 @@ def read_bss_sections(bss):
|
|||||||
'start': address,
|
'start': address,
|
||||||
'labels': [],
|
'labels': [],
|
||||||
}
|
}
|
||||||
|
|
||||||
elif ':' in line:
|
elif ':' in line:
|
||||||
# the only labels that don't use :s so far are enders,
|
# rgbds allows labels without :, but prefer convention
|
||||||
# which we typically don't want to end up in the output
|
|
||||||
label = line[:line.find(':')]
|
label = line[:line.find(':')]
|
||||||
if ';' not in label:
|
if ';' not in label:
|
||||||
section['labels'] += [{'label': label, 'address': address, 'length': 0}]
|
section['labels'] += [{
|
||||||
|
'label': label,
|
||||||
|
'address': address,
|
||||||
|
'length': 0,
|
||||||
|
}]
|
||||||
|
|
||||||
elif line[:3] == 'ds ':
|
elif line[:3] == 'ds ':
|
||||||
length = eval(line[3:line.find(';')].replace('$','0x'))
|
length = eval(line[3:line.find(';')].replace('$','0x'))
|
||||||
address += length
|
address += length
|
||||||
if section['labels']:
|
# adjacent labels use the same space
|
||||||
section['labels'][-1]['length'] += length
|
for label in section['labels'][::-1]:
|
||||||
|
if label['length'] == 0:
|
||||||
|
label['length'] = length
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
elif 'EQU' in line:
|
||||||
|
# some space is defined using constants
|
||||||
|
name, value = line.split('EQU')
|
||||||
|
name, value = name.strip(), value.strip().replace('$','0x').replace('%','0b')
|
||||||
|
globals()[name] = eval(value)
|
||||||
|
|
||||||
sections.append(section)
|
sections.append(section)
|
||||||
return sections
|
return sections
|
||||||
|
|
||||||
wram_sections = read_bss_sections(open('../wram.asm', 'r').readlines())
|
wram_sections = read_bss_sections(open(os.path.join(path, '../wram.asm'), 'r').readlines())
|
||||||
|
|
||||||
|
|
||||||
def make_wram_labels():
|
def make_wram_labels():
|
||||||
@ -56,6 +76,6 @@ def scrape_constants(text):
|
|||||||
text = text.split('\n')
|
text = text.split('\n')
|
||||||
return constants_to_dict([line for line in text if 'EQU' in line[:line.find(';')]])
|
return constants_to_dict([line for line in text if 'EQU' in line[:line.find(';')]])
|
||||||
|
|
||||||
hram_constants = scrape_constants(open('../hram.asm','r').readlines())
|
hram_constants = scrape_constants(open(os.path.join(path, '../hram.asm'),'r').readlines())
|
||||||
gbhw_constants = scrape_constants(open('../gbhw.asm','r').readlines())
|
gbhw_constants = scrape_constants(open(os.path.join(path, '../gbhw.asm'),'r').readlines())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user