From ac2f1860d502dbdde0130c1c0659c79ac5042a92 Mon Sep 17 00:00:00 2001 From: Kevin Cathcart Date: Thu, 1 Mar 2018 18:59:37 -0500 Subject: [PATCH] Automatically strip headered Roms --- Rom.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Rom.py b/Rom.py index 653e2e82..d711c088 100644 --- a/Rom.py +++ b/Rom.py @@ -44,7 +44,7 @@ class LocalRom(object): def __init__(self, file, patch=True): with open(file, 'rb') as stream: - self.buffer = bytearray(stream.read()) + self.buffer = read_rom(stream) if patch: self.patch_base_rom() @@ -94,6 +94,13 @@ class LocalRom(object): inv = crc ^ 0xFFFF self.write_bytes(0x7FDC, [inv & 0xFF, (inv >> 8) & 0xFF, crc & 0xFF, (crc >> 8) & 0xFF]) +def read_rom(stream): + "Reads rom into bytearray and strips off any smc header" + buffer = bytearray(stream.read()) + if len(buffer)%0x400 == 0x200: + buffer = buffer[0x200:] + return buffer + class Sprite(object): default_palette = [255, 127, 126, 35, 183, 17, 158, 54, 165, 20, 255, 1, 120, 16, 157, 89, 71, 54, 104, 59, 74, 10, 239, 18, 92, 42, 113, 21, 24, 122,