Last active
July 19, 2023 14:55
-
-
Save SukkoPera/4a9b7f3ce8edffea8bb8ffadbc6eee68 to your computer and use it in GitHub Desktop.
Split an Amiga ROM file into even/odd words
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import sys | |
import re | |
REGEXP = "AMIGA" | |
BUFSIZE = 4096 | |
ODD_SUFFIX = "_odd_hi_uXa" | |
EVEN_SUFFIX = "_even_low_uXb" | |
if len (sys.argv) != 2: | |
print "Usage: %s <romfile>" % sys.argv[0] | |
sys.exit (1) | |
fn_in = sys.argv[1] | |
split = os.path.splitext (fn_in) | |
fn_odd = split[0] + ODD_SUFFIX + split[1] | |
fn_even = split[0] + EVEN_SUFFIX + split[1] | |
print ("Writing to %s and %s..." % (fn_odd, fn_even)) | |
warningIssued = False | |
with open (fn_in) as fin, open (fn_odd, "w") as fodd, open (fn_even, "w") as feven: | |
while True: | |
buf = fin.read (BUFSIZE) | |
if not buf: | |
break | |
if not warningIssued and re.search (REGEXP, buf, re.IGNORECASE): | |
print ("WARNING: ROM does not look byteswapped, be careful!") | |
warningIssued = True | |
pairs = zip (buf[::2], buf[1::2]) | |
odd = pairs[0::2] | |
even = pairs[1::2] | |
for pair in odd: | |
fodd.write (bytearray (pair)) | |
for pair in even: | |
feven.write (bytearray (pair)) |
Thanks! I'll try in a bit. I used a tool written in C on OSX for now. It also does CRC checksums of a lot of the ROMs provided, so it'll ensure that it's not a wrong one. Pretty cool stuff.
Yeah, this was a quiiiick'n'dirty hack I wrote maaaany years ago (5+), I'm sure there's better stuff around but I could not find anything at the time.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was written for Python 2, try running it through the 2to3 tool.
Change w to wb and add rb in the other call for binary mode.