From 054f9f49cbefac1308e858aa98ef2a26f8705591 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 25 Jun 2024 21:27:31 -0500 Subject: [PATCH] boy-debug: Load multiple files at bootup, as a temporary workaround for not having a disablable bootrom slot --- boy-debug/src/bus.rs | 4 ++-- boy-debug/src/main.rs | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/boy-debug/src/bus.rs b/boy-debug/src/bus.rs index 04ff8f1..1d2ada5 100644 --- a/boy-debug/src/bus.rs +++ b/boy-debug/src/bus.rs @@ -8,7 +8,7 @@ pub trait BusIOTools: BusIO { /// Prints all successful reads and writes fn trace(&mut self) -> TracingBus; fn ascii(&mut self) -> AsciiSerial; - fn read_file(self, path: impl AsRef) -> IoResult + fn read_file(&mut self, path: impl AsRef) -> IoResult<&mut Self> where Self: Sized; } @@ -24,7 +24,7 @@ impl BusIOTools for T { bus: self, } } - fn read_file(mut self, path: impl AsRef) -> IoResult { + fn read_file(&mut self, path: impl AsRef) -> IoResult<&mut Self> { let data = std::fs::read(path)?; eprintln!("Read {} bytes.", data.len()); for (addr, data) in data.into_iter().enumerate() { diff --git a/boy-debug/src/main.rs b/boy-debug/src/main.rs index 7fd6061..fbb479a 100644 --- a/boy-debug/src/main.rs +++ b/boy-debug/src/main.rs @@ -9,18 +9,17 @@ use boy_debug::{ message::Response, }; use rustyline::{config::Configurer, history::FileHistory, Editor}; -use std::error::Error; +use std::{env::args, error::Error}; fn main() -> Result<(), Box> { // Set up the gameboy // TODO: move off the main thread - let args: Vec<_> = std::env::args().collect(); - let mut bus = match args.len() { - 2 => vec![0; 0x10000].read_file(&args[1])?, - _ => return Err(format!("Usage: {} [rom.gb]", args[0]).into()), - }; + let mut bus = vec![0; 0x10000]; + for arg in std::env::args().skip(1) { + bus.read_file(arg)?; + } // let mut bus = Bus::new(Cart::new(bus)); - let mut gb = Gameboy::new(bus.ascii()); + let mut gb = Gameboy::new(bus); // Set up and run the REPL let mut rl: Editor<(), FileHistory> = Editor::new()?;