summaryrefslogtreecommitdiff
path: root/tools/script_disassembler
diff options
context:
space:
mode:
authoroctorock <79596758+octorock@users.noreply.github.com>2021-03-05 23:42:17 +0100
committeroctorock <79596758+octorock@users.noreply.github.com>2021-03-06 14:53:33 +0100
commit9441dac477d46218cc2e1879df1d1c2127189761 (patch)
treeb6c695db548b3cb035ad7bf4a5cdd72f0a9ef94d /tools/script_disassembler
parentc83c3e60d373b29efef0688f622d061c6cde6a1b (diff)
Split at externally referenced labels
Diffstat (limited to 'tools/script_disassembler')
-rw-r--r--tools/script_disassembler/incbin_parser.py16
-rw-r--r--tools/script_disassembler/script_disassembler.py13
2 files changed, 22 insertions, 7 deletions
diff --git a/tools/script_disassembler/incbin_parser.py b/tools/script_disassembler/incbin_parser.py
index 5d184b28..3d4076a5 100644
--- a/tools/script_disassembler/incbin_parser.py
+++ b/tools/script_disassembler/incbin_parser.py
@@ -9,7 +9,10 @@ from script_disassembler import disassemble_script, generate_macros
ROM_OFFSET=0x08000000
SCRIPTS_START=0x08008B5C
SCRIPTS_END=0x08016984
-# cat data/scripts.s | grep @ | cut -d " " -f 3 | sed -e 's/^/0x/' | sed -e 's/\\n/, /g' > labels.txt
+
+# Create labels for these additional script instructions
+# Currently done by splitting the script at that point
+LABEL_BREAKS=[ 0x0800B41C, 0x08012F0C, 0x080142B0, 0x08014A80]
def read_baserom():
# read baserom data
@@ -33,9 +36,13 @@ def main():
.text
- '''
+'''
while script_start < SCRIPTS_END-ROM_OFFSET:
+ if len(LABEL_BREAKS) > 0 and script_start+ROM_OFFSET >=LABEL_BREAKS[0]:
+ print(f'{hex(script_start+ROM_OFFSET)} > {LABEL_BREAKS[0]}')
+ LABEL_BREAKS.pop(0)
+
label = get_label(script_start+ROM_OFFSET)
print(f"Disassembling \033[1;34m{label}\033[0m ({script_start} / { SCRIPTS_END-ROM_OFFSET} bytes converted)...")
# find end of the script signified by 0xffff0000
@@ -44,7 +51,10 @@ def main():
if script_end > SCRIPTS_END-ROM_OFFSET:
script_end = SCRIPTS_END-ROM_OFFSET
- script_start+ROM_OFFSET
+ if len(LABEL_BREAKS) > 0 and script_end+ROM_OFFSET > LABEL_BREAKS[0]:
+ print(f'break at {hex(LABEL_BREAKS[0])} instead of {hex(script_end)}')
+ script_end = LABEL_BREAKS[0]-ROM_OFFSET
+
# read data from rom
data = baserom_data[script_start:script_end]
diff --git a/tools/script_disassembler/script_disassembler.py b/tools/script_disassembler/script_disassembler.py
index ae8f3272..44ca0a74 100644
--- a/tools/script_disassembler/script_disassembler.py
+++ b/tools/script_disassembler/script_disassembler.py
@@ -55,7 +55,7 @@ commands = [
{'fun': 'ScriptCommand_TestBit', 'params': 'w'},
{'fun': 'ScriptCommand_CheckInventory1', 'params': 's'},
{'fun': 'ScriptCommand_CheckInventory2', 'params': 's'},
- {'fun': 'ScriptCommand_HasRoomItemForSale', 'params': ''},
+ {'fun': 'ScriptCommand_HasRoomItemForSale', 'params': 'v'},
{'fun': 'ScriptCommand_CheckLocalFlag', 'params': 's'},
{'fun': 'ScriptCommand_CheckLocalFlagByOffset', 'params': 'ss'},
{'fun': 'ScriptCommand_CheckGlobalFlag', 'params': 's'},
@@ -330,14 +330,16 @@ def ExecuteScriptCommandSet(ctx: Context):
if params['length'] == -1: # variable parameter length
- print(build_script_command(command['fun']))
+ print(f'.short {u16_to_hex(cmd)} @ {build_script_command(command["fun"])} with {commandSize-1} parameters')
if commandSize > 1:
print('\n'.join(['.short ' + x for x in barray_to_u16_hex(ctx.data[ctx.ptr+2:ctx.ptr+commandSize*2])]))
- print(f'@ End of {commandSize-1} parameters')
+ print(f'@ End of parameters')
ctx.ptr += commandSize*2
return 1
elif params['length'] == -2: # point and var
- print(build_script_command(command['fun']) + ' '+ get_pointer(ctx.data[ctx.ptr+2:ctx.ptr+6]))
+ print(f'.short {u16_to_hex(cmd)} @ {build_script_command(command["fun"])} with parameters:')
+
+ print('.word'+ get_pointer(ctx.data[ctx.ptr+2:ctx.ptr+6]))
if commandSize > 3:
print('\n'.join(['.short ' + x for x in barray_to_u16_hex(ctx.data[ctx.ptr+6:ctx.ptr+commandSize*2])]))
print(f'% End of {commandSize-3} parameters')
@@ -428,6 +430,9 @@ def generate_macros():
params = parameters[command['params']]
id = ((params['length']+1) << 0xA) + num
+ if params['length'] < 0:
+ continue
+
print(f'.macro {build_script_command(command["fun"])} {params["param"]}')
print(f' .short {u16_to_hex(id)}')
if params['expr'] != '':