aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAstatin <[email protected]>2025-09-03 14:27:00 +0200
committerAstatin <[email protected]>2025-09-03 14:27:00 +0200
commita893988c10736d324330fbdcacabd6ac862500e1 (patch)
tree41b5b85a90489803e1319fe8049fc765f341d33b /scripts
parenta1b6da7fa43627a08b8bc75a48805ec96fc77583 (diff)
Add a post assembly script to round up ROM size (fixes ROM banking on some emulator)
Diffstat (limited to 'scripts')
-rw-r--r--scripts/round-rom-size.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/scripts/round-rom-size.py b/scripts/round-rom-size.py
new file mode 100644
index 0000000..a59a11f
--- /dev/null
+++ b/scripts/round-rom-size.py
@@ -0,0 +1,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()