pokecarde/scripts/stripgbc.py
2024-12-29 13:11:46 -07:00

32 lines
680 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
import sys
out = open(sys.argv[2], 'wb')
buffering = False
buf = bytes()
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 isnt $00
if not buffering and ord(byte) == 0xFF:
buf += byte
buffering = True
elif buffering and ord(byte) == 0x00:
buf += byte
elif buffering and ord(byte) == 0xFF:
out.write(buf)
buf = byte
elif buffering:
out.write(buf)
out.write(byte)
buf = bytes()
buffering = False
else:
out.write(byte)
f.closed