diff --git a/src/arm7tdmi/arm/exec.rs b/src/arm7tdmi/arm/exec.rs index 337e051..a8b2463 100644 --- a/src/arm7tdmi/arm/exec.rs +++ b/src/arm7tdmi/arm/exec.rs @@ -381,7 +381,7 @@ impl Core { ArmHalfwordTransferType::UnsignedHalfwords => { self.store_16(addr, value as u16, bus) } - _ => panic!("invalid HS flags for L=0") + _ => panic!("invalid HS flags for L=0"), }; } diff --git a/src/bin/main.rs b/src/bin/main.rs index a1c14b2..be79b80 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -14,13 +14,12 @@ use rustboyadvance_ng::{GBAResult, GameBoyAdvance}; fn run_debug(matches: &ArgMatches) -> GBAResult<()> { let skip_bios = match matches.occurrences_of("skip_bios") { 0 => false, - _ => true + _ => true, }; let bios_bin = read_bin_file(matches.value_of("bios").unwrap_or_default())?; - let rom_bin = read_bin_file(matches.value_of("game_rom").unwrap())?; - let gamepak = Cartridge::new(rom_bin); + let gamepak = Cartridge::load(matches.value_of("game_rom").unwrap())?; println!("loaded rom: {:#?}", gamepak.header); let mut core = Core::new(); diff --git a/src/cartridge.rs b/src/cartridge.rs index 5b16c60..6c66f4e 100644 --- a/src/cartridge.rs +++ b/src/cartridge.rs @@ -5,6 +5,8 @@ use crate::arm7tdmi::{ Addr, }; use crate::sysbus::WaitState; +use crate::util::read_bin_file; +use crate::GBAError; /// From GBATEK /// @@ -73,13 +75,20 @@ pub struct Cartridge { } impl Cartridge { - pub fn new(gamepak: Vec) -> Cartridge { - let header = CartridgeHeader::parse(&gamepak); - Cartridge { - header: header, - bytes: gamepak.into_boxed_slice(), - ws: WaitState::new(5, 5, 8), + const MIN_SIZE: usize = 4 * 1024 * 1024; + + pub fn load(path: &str) -> Result { + let mut rom_bin = read_bin_file(path)?; + if rom_bin.len() < Cartridge::MIN_SIZE { + rom_bin.resize_with(Cartridge::MIN_SIZE, Default::default); } + + let header = CartridgeHeader::parse(&rom_bin); + Ok(Cartridge { + header: header, + bytes: rom_bin.into_boxed_slice(), + ws: WaitState::new(5, 5, 8), + }) } }