boy-debug: Load multiple files at bootup, as a temporary workaround for not having a disablable bootrom slot

This commit is contained in:
John 2024-06-25 21:27:31 -05:00
parent c971ff47cc
commit 054f9f49cb
2 changed files with 8 additions and 9 deletions

View File

@ -8,7 +8,7 @@ pub trait BusIOTools: BusIO {
/// Prints all successful reads and writes
fn trace(&mut self) -> TracingBus<Self>;
fn ascii(&mut self) -> AsciiSerial<Self>;
fn read_file(self, path: impl AsRef<Path>) -> IoResult<Self>
fn read_file(&mut self, path: impl AsRef<Path>) -> IoResult<&mut Self>
where
Self: Sized;
}
@ -24,7 +24,7 @@ impl<T: BusIO> BusIOTools for T {
bus: self,
}
}
fn read_file(mut self, path: impl AsRef<Path>) -> IoResult<Self> {
fn read_file(&mut self, path: impl AsRef<Path>) -> IoResult<&mut Self> {
let data = std::fs::read(path)?;
eprintln!("Read {} bytes.", data.len());
for (addr, data) in data.into_iter().enumerate() {

View File

@ -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<dyn Error>> {
// 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()?;