bootrom as romfile + inline include_bytes

This commit is contained in:
Alex Janka 2023-03-09 10:21:21 +11:00
parent d041475ced
commit 79f9d70ff2
3 changed files with 17 additions and 14 deletions

View file

@ -79,7 +79,7 @@ fn main() {
rom: RomFile::Path(args.rom),
save_path: args.save,
no_save: args.no_save,
bootrom_path: args.bootrom,
bootrom: args.bootrom.map(|v| RomFile::Path(v)),
connect_serial: args.connect_serial,
verbose: args.verbose,
cycle_count: args.cycle_count,

View file

@ -32,8 +32,6 @@ pub struct GameboyEmu {
type FrameReceiver = Mutex<Option<Receiver<Vec<[u8; 4]>>>>;
type JoypadSender = Mutex<Option<Sender<(JoypadButtons, bool)>>>;
const ROM: &[u8; 32768] = include_bytes!("../../test-roms/Tetris.gb");
impl Plugin for GameboyEmu {
const NAME: &'static str = "Gameboy";
@ -104,10 +102,16 @@ impl Plugin for GameboyEmu {
_context: &mut impl InitContext<Self>,
) -> bool {
let options = gb_emu_lib::Options {
rom: RomFile::Raw(ROM.to_vec()),
rom: RomFile::Raw(
include_bytes!("../../test-roms/TwinPeaksMeanwhile.gb")
.to_vec()
.to_vec(),
),
save_path: None,
no_save: true,
bootrom_path: None,
bootrom: Some(RomFile::Raw(
include_bytes!("../../bootrom/dmg_boot.bin").to_vec(),
)),
connect_serial: false,
verbose: false,
cycle_count: false,

View file

@ -26,7 +26,7 @@ pub struct Options {
pub rom: RomFile,
pub save_path: Option<String>,
pub no_save: bool,
pub bootrom_path: Option<String>,
pub bootrom: Option<RomFile>,
pub connect_serial: bool,
pub verbose: bool,
pub cycle_count: bool,
@ -85,18 +85,17 @@ impl<ColourFormat: From<Colour> + Clone> EmulatorCore<ColourFormat> {
window.prepare(WIDTH, HEIGHT);
window.set_title(format!("{} on {}", rom.get_title(), rom.mbc_type()));
let bootrom_enabled = options.bootrom_path.is_some();
let bootrom: Option<Vec<u8>> = if let Some(path) = options.bootrom_path {
match fs::read(path) {
Ok(data) => Some(data),
let bootrom_enabled = options.bootrom.is_some();
let bootrom: Option<Vec<u8>> = options.bootrom.map(|v| match v {
RomFile::Path(path) => match fs::read(path) {
Ok(data) => data,
Err(e) => {
println!("Error reading bootROM: {e}");
exit(1);
}
}
} else {
None
};
},
RomFile::Raw(data) => data,
});
Self::new(
receiver,