Use assembly macros instead

This commit is contained in:
octorock
2021-03-04 19:26:20 +01:00
parent 174694a99b
commit 223cf98a51
5 changed files with 482 additions and 244 deletions
@@ -199,25 +199,25 @@ parameters = {
's': {
'length': 1,
'param': 's',
'expr': 'asm(".short " #s);',
'expr': ' .short \s',
'read': lambda ctx: barray_to_u16_hex(ctx.data[ctx.ptr+2:ctx.ptr+4])[0]
},
'w': {
'length': 2,
'param': 'w',
'expr': 'asm(".word " #w);',
'expr': ' .word \w',
'read': lambda ctx: barray_to_u32_hex(ctx.data[ctx.ptr+2:ctx.ptr+6])[0]
},
'ss': {
'length': 2,
'param': 'a,b',
'expr': 'asm(".short " #a);asm(".short " #b);',
'expr': ' .short \\a\n .short \\b',
'read': lambda ctx: ','.join(barray_to_u16_hex(ctx.data[ctx.ptr+2:ctx.ptr+6]))
},
'ww': {
'length': 4,
'param': 'a,b',
'expr': 'asm(".word " #a);asm(".word " #b);',
'expr': ' .word \\a\n .word \\b',
'read': lambda ctx: ','.join(barray_to_u32_hex(ctx.data[ctx.ptr+2:ctx.ptr+10]))
},
}
@@ -251,7 +251,7 @@ def ExecuteScriptCommandSet(ctx: Context):
raise Exception('Call with ' + (unk_06-1) +' length, while length of ' + params['length']+' defined')
print(command['fun'] + '(' + params['read'](ctx) + ')')
print(command['fun'] + ' ' + params['read'](ctx))
# Execute script
ctx.ptr += unk_06*2
@@ -271,14 +271,22 @@ def disassemble_script(input_data):
# Print rest (did not manage to get there)
print(',\n'.join(barray_to_u16_hex(ctx.data[ctx.ptr:])))
def generate_macros():
print('#ifndef SCRIPT_MACROS_H')
print('#define SCRIPT_MACROS_H')
print('// Generated by disassemble_script.py')
print('#define START_SCRIPT(name) asm(".globl "#name); asm(".section .rodata"); asm(#name":");')
print('#define END_SCRIPT()')
#print('#define WORD_TO_SHORTS(word) (unsigned short)word & 0xffff,(unsigned short)word >> 16')
print('@ All the macro functions for scripts')
print('@ Generated by disassemble_script.py')
print('.macro SCRIPT_START name')
print(' .globl \\name')
print(' .section .rodata')
print('\\name:')
print('.endm')
print('.macro SCRIPT_END')
print(' .short 0xffff')
print('.endm')
print('')
for num, command in enumerate(commands):
if not 'params' in command:
@@ -289,9 +297,16 @@ def generate_macros():
params = parameters[command['params']]
id = ((params['length']+1) << 0xA) + num
print('#define ' + command['fun'] + '(' + params['param'] + ') asm(".short '+u16_to_hex(id)+'");' + params['expr'])
print ('#endif')
print(f'.macro {command["fun"]} {params["param"]}')
print(f' .short {u16_to_hex(id)}')
if params['expr'] != '':
print(params['expr'])
print('.endm')
print('')
#print('#define ' + command['fun'] + '(' + params['param'] + ') asm(".short '+u16_to_hex(id)+'");' + params['expr'])
print('')
def main():