take either loaded rom or path to rom
This commit is contained in:
parent
b13dc13d1f
commit
4a2c15e5ec
|
@ -9,7 +9,7 @@ use cpal::{
|
||||||
};
|
};
|
||||||
use futures::executor;
|
use futures::executor;
|
||||||
use gb_emu_lib::{
|
use gb_emu_lib::{
|
||||||
connect::{AudioOutput, EmulatorMessage, JoypadState, Renderer},
|
connect::{AudioOutput, EmulatorMessage, JoypadState, Renderer, RomFile},
|
||||||
util::scale_buffer,
|
util::scale_buffer,
|
||||||
};
|
};
|
||||||
use gilrs::{
|
use gilrs::{
|
||||||
|
@ -75,7 +75,7 @@ fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
let options = gb_emu_lib::Options {
|
let options = gb_emu_lib::Options {
|
||||||
rom_path: args.rom,
|
rom: RomFile::Path(args.rom),
|
||||||
save_path: args.save,
|
save_path: args.save,
|
||||||
no_save: args.no_save,
|
no_save: args.no_save,
|
||||||
bootrom_path: args.bootrom,
|
bootrom_path: args.bootrom,
|
||||||
|
|
|
@ -6,6 +6,11 @@ pub enum EmulatorMessage {
|
||||||
Stop,
|
Stop,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum RomFile {
|
||||||
|
Path(String),
|
||||||
|
Raw(Vec<u8>),
|
||||||
|
}
|
||||||
|
|
||||||
pub trait Renderer {
|
pub trait Renderer {
|
||||||
fn prepare(&mut self, width: usize, height: usize);
|
fn prepare(&mut self, width: usize, height: usize);
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::{
|
||||||
processor::memory::Memory,
|
processor::memory::Memory,
|
||||||
util::{pause, print_cycles},
|
util::{pause, print_cycles},
|
||||||
};
|
};
|
||||||
use connect::{AudioOutput, EmulatorMessage, Renderer};
|
use connect::{AudioOutput, EmulatorMessage, Renderer, RomFile};
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use processor::{memory::Rom, Cpu};
|
use processor::{memory::Rom, Cpu};
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -29,7 +29,7 @@ mod processor;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
pub rom_path: String,
|
pub rom: RomFile,
|
||||||
pub save_path: Option<String>,
|
pub save_path: Option<String>,
|
||||||
pub no_save: bool,
|
pub no_save: bool,
|
||||||
pub bootrom_path: Option<String>,
|
pub bootrom_path: Option<String>,
|
||||||
|
@ -56,24 +56,27 @@ pub fn init(
|
||||||
) {
|
) {
|
||||||
VERBOSE.set(options.verbose).unwrap();
|
VERBOSE.set(options.verbose).unwrap();
|
||||||
|
|
||||||
|
let rom = match options.rom {
|
||||||
|
RomFile::Path(path) => {
|
||||||
let maybe_save = if options.no_save {
|
let maybe_save = if options.no_save {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(if let Some(path) = options.save_path {
|
Some(if let Some(path) = options.save_path {
|
||||||
PathBuf::from_str(&path).unwrap()
|
PathBuf::from_str(&path).unwrap()
|
||||||
} else {
|
} else {
|
||||||
PathBuf::from_str(&options.rom_path)
|
PathBuf::from_str(&path).unwrap().with_extension("sav")
|
||||||
.unwrap()
|
|
||||||
.with_extension("sav")
|
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
let rom: Rom = match fs::read(options.rom_path) {
|
match fs::read(path) {
|
||||||
Ok(data) => Rom::load(data, maybe_save),
|
Ok(data) => Rom::load(data, maybe_save),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("Error reading ROM: {e}");
|
println!("Error reading ROM: {e}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RomFile::Raw(data) => Rom::load(data, None),
|
||||||
};
|
};
|
||||||
|
|
||||||
window.prepare(WIDTH, HEIGHT);
|
window.prepare(WIDTH, HEIGHT);
|
||||||
|
|
Loading…
Reference in a new issue