From ee1f772c391c8527f39988d6b9486bd5cc3df0a0 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 5 Nov 2023 04:54:12 +0100 Subject: [PATCH] Automatically detect surplus cartridge header --- src/bin/souper/main.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/bin/souper/main.rs b/src/bin/souper/main.rs index 3491229..126a535 100644 --- a/src/bin/souper/main.rs +++ b/src/bin/souper/main.rs @@ -45,10 +45,17 @@ fn main() -> Result<()> { let args = Args::parse(); let f = fs::read(args.filename)?; + let load_offset = match f.len() % 1024 { + 0 => 0, + 0x200 => { + println!("Cartridge contains 0x200 bytes of weird header"); + 0x200 + }, + _ => panic!("Illogical cartridge file size: 0x{:08X}", f.len()), + }; let display = SDLRenderer::new(SCREEN_WIDTH, SCREEN_HEIGHT)?; - - let bus = Mainbus::::new(&f, args.bustrace, display); + let bus = Mainbus::::new(&f[load_offset..], args.bustrace, display); let reset = bus.read16(0xFFFC); let mut cpu = Cpu65816::>::new(bus, reset);