diff --git a/gb-emu/src/main.rs b/gb-emu/src/main.rs index fc095af..8a440fa 100644 --- a/gb-emu/src/main.rs +++ b/gb-emu/src/main.rs @@ -9,7 +9,7 @@ use cpal::{ }; use futures::executor; use gb_emu_lib::{ - connect::{AudioOutput, EmulatorMessage, JoypadState, Renderer}, + connect::{AudioOutput, EmulatorMessage, JoypadState, Renderer, RomFile}, util::scale_buffer, }; use gilrs::{ @@ -75,7 +75,7 @@ fn main() { }; let options = gb_emu_lib::Options { - rom_path: args.rom, + rom: RomFile::Path(args.rom), save_path: args.save, no_save: args.no_save, bootrom_path: args.bootrom, diff --git a/lib/src/connect/mod.rs b/lib/src/connect/mod.rs index 14c4ad9..d94027f 100644 --- a/lib/src/connect/mod.rs +++ b/lib/src/connect/mod.rs @@ -6,6 +6,11 @@ pub enum EmulatorMessage { Stop, } +pub enum RomFile { + Path(String), + Raw(Vec), +} + pub trait Renderer { fn prepare(&mut self, width: usize, height: usize); diff --git a/lib/src/lib.rs b/lib/src/lib.rs index ec64863..8d4b6d0 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -10,7 +10,7 @@ use crate::{ processor::memory::Memory, util::{pause, print_cycles}, }; -use connect::{AudioOutput, EmulatorMessage, Renderer}; +use connect::{AudioOutput, EmulatorMessage, Renderer, RomFile}; use once_cell::sync::OnceCell; use processor::{memory::Rom, Cpu}; use std::{ @@ -29,7 +29,7 @@ mod processor; pub mod util; pub struct Options { - pub rom_path: String, + pub rom: RomFile, pub save_path: Option, pub no_save: bool, pub bootrom_path: Option, @@ -56,24 +56,27 @@ pub fn init( ) { VERBOSE.set(options.verbose).unwrap(); - let maybe_save = if options.no_save { - None - } else { - Some(if let Some(path) = options.save_path { - PathBuf::from_str(&path).unwrap() - } else { - PathBuf::from_str(&options.rom_path) - .unwrap() - .with_extension("sav") - }) - }; + let rom = match options.rom { + RomFile::Path(path) => { + let maybe_save = if options.no_save { + None + } else { + Some(if let Some(path) = options.save_path { + PathBuf::from_str(&path).unwrap() + } else { + PathBuf::from_str(&path).unwrap().with_extension("sav") + }) + }; - let rom: Rom = match fs::read(options.rom_path) { - Ok(data) => Rom::load(data, maybe_save), - Err(e) => { - println!("Error reading ROM: {e}"); - return; + match fs::read(path) { + Ok(data) => Rom::load(data, maybe_save), + Err(e) => { + println!("Error reading ROM: {e}"); + return; + } + } } + RomFile::Raw(data) => Rom::load(data, None), }; window.prepare(WIDTH, HEIGHT);