Skip to content
Snippets Groups Projects
Verified Commit 06bd16df authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

chore: better handling of errors

parent 9cbd4b77
No related branches found
No related tags found
1 merge request!31System state save
......@@ -989,32 +989,37 @@ impl GameBoy {
self.mmu_i().rom_i()
}
pub fn load_boot_path(&mut self, path: &str) {
let data = read_file(path).unwrap();
pub fn load_boot_path(&mut self, path: &str) -> Result<(), String> {
let data = read_file(path)?;
self.load_boot(&data);
Ok(())
}
pub fn load_boot_file(&mut self, boot_rom: BootRom) {
pub fn load_boot_file(&mut self, boot_rom: BootRom) -> Result<(), String> {
match boot_rom {
BootRom::Dmg => self.load_boot_path("./res/boot/dmg_boot.bin"),
BootRom::Sgb => self.load_boot_path("./res/boot/sgb_boot.bin"),
BootRom::DmgBootix => self.load_boot_path("./res/boot/dmg_bootix.bin"),
BootRom::MgbBootix => self.load_boot_path("./res/boot/mgb_bootix.bin"),
BootRom::Cgb => self.load_boot_path("./res/boot/cgb_boot.bin"),
BootRom::Dmg => self.load_boot_path("./res/boot/dmg_boot.bin")?,
BootRom::Sgb => self.load_boot_path("./res/boot/sgb_boot.bin")?,
BootRom::DmgBootix => self.load_boot_path("./res/boot/dmg_bootix.bin")?,
BootRom::MgbBootix => self.load_boot_path("./res/boot/mgb_bootix.bin")?,
BootRom::Cgb => self.load_boot_path("./res/boot/cgb_boot.bin")?,
BootRom::None => (),
}
Ok(())
}
pub fn load_boot_default_f(&mut self) {
self.load_boot_dmg_f();
pub fn load_boot_default_f(&mut self) -> Result<(), String> {
self.load_boot_dmg_f()?;
Ok(())
}
pub fn load_boot_dmg_f(&mut self) {
self.load_boot_file(BootRom::DmgBootix);
pub fn load_boot_dmg_f(&mut self) -> Result<(), String> {
self.load_boot_file(BootRom::DmgBootix)?;
Ok(())
}
pub fn load_boot_cgb_f(&mut self) {
self.load_boot_file(BootRom::Cgb);
pub fn load_boot_cgb_f(&mut self) -> Result<(), String> {
self.load_boot_file(BootRom::Cgb)?;
Ok(())
}
pub fn load_cartridge(&mut self, rom: Cartridge) -> &mut Cartridge {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment