diff options
author | Cleverking2003 <30466983+Cleverking2003@users.noreply.github.com> | 2020-06-19 00:02:47 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-19 00:02:47 +0300 |
commit | 41317a2b7625919ebba39c06b5aaf9e3b0800b1d (patch) | |
tree | 1780ce6f8ee57a163b95beaa99e45e6aed776346 /explode_incbins.py | |
parent | e3077928198b2f51854812bcd04e1ebe1e6112f5 (diff) | |
parent | a455bac566535ec559aac9164e05781093653057 (diff) |
Merge branch 'master' into master
Diffstat (limited to 'explode_incbins.py')
-rw-r--r-- | explode_incbins.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/explode_incbins.py b/explode_incbins.py new file mode 100644 index 00000000..4e1af1b5 --- /dev/null +++ b/explode_incbins.py @@ -0,0 +1,21 @@ +import sys +import re + +with open(sys.argv[1], 'rb') as rom: + for fname in sys.argv[2:]: + with open(fname, 'r+') as fp: + lines = [] + for line in fp: + m = re.search(r'\.incbin "baserom.nds", (0x\w+), (0x\w+)', line) + if m is not None: + addr = int(m[1], 16) + size = int(m[2], 16) + rom.seek(addr) + for i in range(0, size, 16): + data = rom.read(min(size - i, 16)) + lines.append('\t.byte ' + ', '.join(f'0x{k:02X}' for k in data) + '\n') + else: + lines.append(line) + fp.seek(0) + fp.truncate() + fp.write(''.join(lines)) |