aboutsummaryrefslogtreecommitdiff
path: root/scripts/round-rom-size.py
blob: a59a11fdd2268883d0102c02b4509bad77a2aa90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import sys
import os

if len(sys.argv) != 2:
    raise ValueError("Rom file must be specified as first argument")

rom_filename = sys.argv[1]
current_filesize = os.path.getsize(rom_filename)

i = 0
for n in range(0, 9):
    if current_filesize <= 32768 * (1 << n):
        break
    i += 1

missing = (32768 * (1 << i)) - current_filesize

print("Original file size =", current_filesize, "bytes")
print("ROM size =", hex(i), "({} bytes)".format(32768 * (1 << i)))

rom_file = open(rom_filename, 'r+b')

rom_file.seek(0x148)

rom_file.write(bytes(bytearray([i])))

rom_file.close()

rom_file = open(rom_filename, 'a+b')


rom_file.write(bytes(bytearray([0]*missing)))

rom_file.close()