bootrom as option
This commit is contained in:
parent
932e70a443
commit
3df569a7a1
26
src/main.rs
26
src/main.rs
|
@ -45,11 +45,7 @@ struct Args {
|
|||
|
||||
/// BootROM path
|
||||
#[arg(short, long)]
|
||||
bootrom: String,
|
||||
|
||||
/// Just run BootROM
|
||||
#[arg(long)]
|
||||
run_bootrom: bool,
|
||||
bootrom: Option<String>,
|
||||
|
||||
/// Verbose print
|
||||
#[arg(short, long)]
|
||||
|
@ -102,12 +98,18 @@ fn main() {
|
|||
return;
|
||||
}
|
||||
};
|
||||
let bootrom: Vec<u8> = match fs::read(args.bootrom) {
|
||||
Ok(data) => data,
|
||||
Err(e) => {
|
||||
println!("Error reading bootROM: {e}");
|
||||
return;
|
||||
|
||||
let bootrom_enabled = args.bootrom.is_some();
|
||||
let bootrom: Option<Vec<u8>> = if let Some(path) = args.bootrom {
|
||||
match fs::read(path) {
|
||||
Ok(data) => Some(data),
|
||||
Err(e) => {
|
||||
println!("Error reading bootROM: {e}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let mut window = Window::new(
|
||||
|
@ -125,10 +127,10 @@ fn main() {
|
|||
window.topmost(true);
|
||||
|
||||
let mut cpu = Cpu::new(
|
||||
Memory::init(bootrom, args.run_bootrom, rom),
|
||||
Memory::init(bootrom, rom),
|
||||
window,
|
||||
args.tile_window,
|
||||
args.run_bootrom,
|
||||
bootrom_enabled,
|
||||
Gilrs::new().unwrap(),
|
||||
);
|
||||
|
||||
|
|
|
@ -11,8 +11,7 @@ pub(crate) type Address = u16;
|
|||
|
||||
#[allow(dead_code)]
|
||||
pub struct Memory {
|
||||
bootrom: Vec<u8>,
|
||||
bootrom_enabled: bool,
|
||||
bootrom: Option<Vec<u8>>,
|
||||
rom: Rom,
|
||||
vram: [u8; 8192],
|
||||
ram: [u8; 8192],
|
||||
|
@ -30,10 +29,9 @@ pub struct Memory {
|
|||
}
|
||||
|
||||
impl Memory {
|
||||
pub fn init(bootrom: Vec<u8>, bootrom_enabled: bool, rom: Rom) -> Self {
|
||||
pub fn init(bootrom: Option<Vec<u8>>, rom: Rom) -> Self {
|
||||
Self {
|
||||
bootrom,
|
||||
bootrom_enabled,
|
||||
rom,
|
||||
vram: [0x0; 8192],
|
||||
ram: [0x0; 8192],
|
||||
|
@ -56,8 +54,8 @@ impl Memory {
|
|||
0x0..0x8000 => {
|
||||
// rom access
|
||||
// todo - switchable rom banks
|
||||
if self.bootrom_enabled && ((address as usize) < self.bootrom.len()) {
|
||||
self.bootrom[address as usize]
|
||||
if let Some(bootrom) = &self.bootrom && (address as usize) < bootrom.len() {
|
||||
bootrom[address as usize]
|
||||
} else {
|
||||
self.rom.get(address)
|
||||
}
|
||||
|
@ -91,7 +89,7 @@ impl Memory {
|
|||
0xFE00..0xFEA0 => self.oam[(address - 0xFE00) as usize] = data,
|
||||
0xFEA0..0xFF00 => {}
|
||||
0xFF00..0xFF4C => self.set_io(address, data),
|
||||
0xFF50 => self.bootrom_enabled = false,
|
||||
0xFF50 => self.bootrom = None,
|
||||
0xFF4C..0xFF50 | 0xFF51..0xFF80 => {}
|
||||
0xFF80..0xFFFF => self.cpu_ram[(address - 0xFF80) as usize] = data,
|
||||
0xFFFF => {
|
||||
|
|
|
@ -50,7 +50,7 @@ impl Cpu {
|
|||
run_bootrom: bool,
|
||||
gamepad_handler: Gilrs,
|
||||
) -> Self {
|
||||
if run_bootrom {
|
||||
if !run_bootrom {
|
||||
memory.cpu_ram_init();
|
||||
}
|
||||
Self {
|
||||
|
|
Loading…
Reference in a new issue