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

chore: gracefull fail of default ROM loading

parent 61369b73
No related branches found
No related tags found
No related merge requests found
Pipeline #3142 passed
......@@ -43,6 +43,10 @@ const VOLUME: f32 = 64.0;
/// backed RAM is going to be stored into the file system.
const STORE_RATE: u8 = 5;
/// The path to the default ROM file that is going to be
/// loaded in case no other ROM path is provided.
const DEFAULT_ROM_PATH: &str = "../../res/roms/demo/pocket.gb";
pub struct Benchmark {
count: usize,
cpu_only: Option<bool>,
......@@ -752,7 +756,7 @@ struct Args {
)]
cycles: u64,
#[arg(short, long, default_value_t = String::from("../../res/roms/demo/pocket.gb"), help = "Path to the ROM file to be loaded")]
#[arg(short, long, default_value_t = String::from(DEFAULT_ROM_PATH), help = "Path to the ROM file to be loaded")]
rom_path: String,
}
......@@ -787,6 +791,14 @@ fn main() {
};
let auto_mode = args.mode == "auto";
// in case the default ROM path is provided and the file does not
// exist then fails gracefully
let path = Path::new(&args.rom_path);
if &args.rom_path == DEFAULT_ROM_PATH && !path.exists() {
println!("No ROM file provided, please provide one using the --rom-path option");
return;
}
// creates a new Game Boy instance and loads both the boot ROM
// and the initial game ROM to "start the engine"
let mut game_boy = GameBoy::new(Some(mode));
......
......@@ -8,6 +8,8 @@ use std::{
pub type SharedMut<T> = Rc<RefCell<T>>;
/// Reads the contents of the file at the given path into
/// a vector of bytes.
pub fn read_file(path: &str) -> Vec<u8> {
let mut file = match File::open(path) {
Ok(file) => file,
......@@ -18,6 +20,7 @@ pub fn read_file(path: &str) -> Vec<u8> {
data
}
/// Writes the given data to the file at the given path.
pub fn write_file(path: &str, data: &[u8]) {
let mut file = match File::create(path) {
Ok(file) => file,
......
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