mirror of
https://github.com/zeldaret/tmc
synced 2026-05-24 15:21:09 -04:00
Use assembly macros instead
This commit is contained in:
@@ -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():
|
||||
|
||||
|
||||
Reference in New Issue
Block a user