Generate using inline assembly

This commit is contained in:
octorock
2021-03-04 17:29:56 +01:00
parent 3336b91812
commit 174694a99b
3 changed files with 101 additions and 239 deletions
@@ -120,10 +120,10 @@ commands = [
{'fun': 'sub_0807E898'},
{'fun': 'sub_0807E8C4', 'params': 'w'},
{'fun': 'sub_0807E8D4'},
{'fun': 'sub_0807E8E4', 'params': ''},
{'fun': 'sub_0807E8E4', 'params': ''},
{'fun': 'sub_0807E8E4', 'params': ''},
{'fun': 'sub_0807E8E4', 'params': ''},
{'fun': 'sub_0807E8E4_0', 'params': ''}, # duplicate
{'fun': 'sub_0807E8E4_1', 'params': ''}, # duplicate
{'fun': 'sub_0807E8E4_2', 'params': ''}, # duplicate
{'fun': 'sub_0807E8E4_3', 'params': ''}, # duplicate
{'fun': 'sub_0807E908'},
{'fun': 'sub_0807E914'},
{'fun': 'sub_0807E924'},
@@ -199,25 +199,25 @@ parameters = {
's': {
'length': 1,
'param': 's',
'expr': 's,',
'expr': 'asm(".short " #s);',
'read': lambda ctx: barray_to_u16_hex(ctx.data[ctx.ptr+2:ctx.ptr+4])[0]
},
'w': {
'length': 2,
'param': 'w',
'expr': 'WORD_TO_SHORTS(w),',
'expr': 'asm(".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': 'a,b,',
'expr': 'asm(".short " #a);asm(".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': 'WORD_TO_SHORTS(a), WORD_TO_SHORTS(b),',
'expr': 'asm(".word " #a);asm(".word " #b);',
'read': lambda ctx: ','.join(barray_to_u32_hex(ctx.data[ctx.ptr+2:ctx.ptr+10]))
},
}
@@ -276,9 +276,9 @@ def generate_macros():
print('#ifndef SCRIPT_MACROS_H')
print('#define SCRIPT_MACROS_H')
print('// Generated by disassemble_script.py')
print('#define START_SCRIPT(name) const unsigned short name[] = {')
print('#define END_SCRIPT() };')
print('#define WORD_TO_SHORTS(word) (unsigned short)word & 0xffff,(unsigned short)word >> 16')
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('')
for num, command in enumerate(commands):
if not 'params' in command:
@@ -289,7 +289,7 @@ def generate_macros():
params = parameters[command['params']]
id = ((params['length']+1) << 0xA) + num
print('#define ' + command['fun'] + '(' + params['param'] + ') '+u16_to_hex(id)+', ' + params['expr'])
print('#define ' + command['fun'] + '(' + params['param'] + ') asm(".short '+u16_to_hex(id)+'");' + params['expr'])
print ('#endif')