mirror of
https://github.com/zeldaret/tmc
synced 2026-05-25 07:23:16 -04:00
Create parser that resolves the .incbin macros
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
# This python script reads the script.s file which contains all the .incbin macros
|
||||
# Then it fetches the corresponding data of the baserom, o
|
||||
TMC_FOLDER='../..'
|
||||
|
||||
import subprocess
|
||||
from script_disassembler import disassemble_script
|
||||
|
||||
def main():
|
||||
# read baserom data
|
||||
with open(f'{TMC_FOLDER}/baserom.gba', 'rb') as baserom:
|
||||
baserom_data = bytearray(baserom.read())
|
||||
|
||||
# read scripts.s with incbins
|
||||
with open(f'{TMC_FOLDER}/data/scripts.s', 'r') as scripts:
|
||||
|
||||
while True:
|
||||
line = scripts.readline()
|
||||
|
||||
if not line:
|
||||
# end of file
|
||||
break
|
||||
|
||||
if ':: @' in line: # this might be a label
|
||||
incbin_line = scripts.readline()
|
||||
|
||||
if '.incbin' in incbin_line: # found a label with incbin
|
||||
label = line.split('::')[0]
|
||||
(_, start, end) = incbin_line.split(',')
|
||||
start = int(start, 16)
|
||||
end = int(end, 16)
|
||||
|
||||
# read data from rom
|
||||
data = baserom_data[start:start+end]
|
||||
|
||||
print(f'DISASM {label}')
|
||||
disassemble_script(data)
|
||||
|
||||
# print new include label
|
||||
print(f'.include "data/scripts/{label}.inc"')
|
||||
else:
|
||||
print(line, end='')
|
||||
print(incbin_line, end='')
|
||||
else:
|
||||
print(line, end='')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user