Split at externally referenced labels

This commit is contained in:
octorock
2021-03-05 23:42:17 +01:00
parent c83c3e60d3
commit 9441dac477
144 changed files with 1614 additions and 4705 deletions
+13 -3
View File
@@ -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]
@@ -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'] != '':