diff options
author | Háčky <hatschky@gmail.com> | 2014-11-27 07:15:45 +0000 |
---|---|---|
committer | Háčky <hatschky@gmail.com> | 2014-11-27 07:15:45 +0000 |
commit | 319ed6d0e0266f5f6174a5acd929914db8cfae1d (patch) | |
tree | 76408d9cadcbed1e702efa8c44f4cf5e364b0a4d /scripts/stripgbc.py | |
parent | 17853b802692237d98f96d1a80caf2019f71753e (diff) |
Diffstat (limited to 'scripts/stripgbc.py')
-rw-r--r-- | scripts/stripgbc.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/scripts/stripgbc.py b/scripts/stripgbc.py new file mode 100644 index 0000000..146d119 --- /dev/null +++ b/scripts/stripgbc.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +import sys + +out = open(sys.argv[2], 'w') +buffering = False +buf = "" +with open(sys.argv[1], 'rb') as f: + f.read(256) # skip to $0100 + while True: + byte = f.read(1) + if not byte: + break + + # the program shall end with $FF followed only by $00 bytes + # for every $FF we hit, buffer until something that isn’t $00 + if (not buffering and ord(byte) == 0xFF) or (buffering and ord(byte) == 0x00): + buf += byte + buffering = True + elif buffering and ord(byte) == 0xFF: + out.write(buf) + buf = byte + elif buffering: + out.write(buf) + out.write(byte) + buf = "" + buffering = False + else: + out.write(byte) +f.closed
\ No newline at end of file |