Impose a minimum length of 4MB for the gamepak memory

Former-commit-id: 08e66bff0bc39968e572b941da84c155a45f31c8
This commit is contained in:
Michel Heily 2019-07-07 23:33:47 +03:00
parent d36da30618
commit 6eab76d52f
3 changed files with 18 additions and 10 deletions

View file

@ -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"),
};
}

View file

@ -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();

View file

@ -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<u8>) -> 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<Cartridge, GBAError> {
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),
})
}
}