From 188717e22867351177cbf25129fb7cc773dcaf2b Mon Sep 17 00:00:00 2001 From: transistor Date: Sat, 25 Dec 2021 16:30:07 -0800 Subject: [PATCH] Added option to ignore reads/writes to unmapped bus areas --- src/machines/genesis.rs | 8 +++++--- src/memory.rs | 24 ++++++++++++++++++++++-- src/system.rs | 4 ++++ todo.txt | 7 ++++--- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/machines/genesis.rs b/src/machines/genesis.rs index 496e2bf..5b5fe96 100644 --- a/src/machines/genesis.rs +++ b/src/machines/genesis.rs @@ -6,7 +6,7 @@ use crate::error::Error; use crate::system::System; use crate::signals::{Signal}; use crate::memory::{MemoryBlock, Bus, BusPort}; -use crate::devices::{wrap_transmutable, Address, Addressable}; +use crate::devices::{wrap_transmutable, Address, Addressable, Debuggable}; use crate::cpus::m68k::{M68k, M68kType}; use crate::cpus::z80::{Z80, Z80Type}; @@ -68,13 +68,15 @@ pub fn build_genesis(host: &mut H, options: SegaGenesisOptions) -> Resu let coproc_register = wrap_transmutable(CoprocessorBankRegister::new(bank_register.clone())); let coproc_area = wrap_transmutable(CoprocessorBankArea::new(bank_register, system.bus.clone())); - let coproc_bus = Rc::new(RefCell::new(Bus::new())); + let mut coproc_bus = Rc::new(RefCell::new(Bus::new())); + coproc_bus.borrow_mut().set_ignore_unmapped(true); coproc_bus.borrow_mut().insert(0x0000, coproc_ram.clone()); coproc_bus.borrow_mut().insert(0x4000, coproc_ym_sound.clone()); coproc_bus.borrow_mut().insert(0x6000, coproc_register.clone()); coproc_bus.borrow_mut().insert(0x7f11, coproc_sn_sound.clone()); coproc_bus.borrow_mut().insert(0x8000, coproc_area); - let coproc = Z80::new(Z80Type::Z80, 3_579_545, BusPort::new(0, 16, 8, coproc_bus.clone())); + let mut coproc = Z80::new(Z80Type::Z80, 3_579_545, BusPort::new(0, 16, 8, coproc_bus.clone())); + coproc.set_debugging(true); let mut reset = coproc.reset.clone(); let mut bus_request = coproc.bus_request.clone(); reset.set(true); diff --git a/src/memory.rs b/src/memory.rs index 1539838..8dc35e7 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -118,16 +118,22 @@ pub struct Block { } pub struct Bus { + ignore_unmapped: bool, blocks: Vec, } impl Bus { pub fn new() -> Bus { Bus { + ignore_unmapped: false, blocks: vec!(), } } + pub fn set_ignore_unmapped(&mut self, ignore_unmapped: bool) { + self.ignore_unmapped = ignore_unmapped; + } + pub fn clear_all_bus_devices(&mut self) { self.blocks.clear(); } @@ -180,13 +186,27 @@ impl Addressable for Bus { } fn read(&mut self, addr: Address, data: &mut [u8]) -> Result<(), Error> { - let (dev, relative_addr) = self.get_device_at(addr, data.len())?; + let (dev, relative_addr) = match self.get_device_at(addr, data.len()) { + Ok(result) => result, + Err(err) if self.ignore_unmapped => { + info!("{:?}", err); + return Ok(()) + }, + Err(err) => return Err(err), + }; let result = dev.borrow_mut().as_addressable().unwrap().read(relative_addr, data); result } fn write(&mut self, addr: Address, data: &[u8]) -> Result<(), Error> { - let (dev, relative_addr) = self.get_device_at(addr, data.len())?; + let (dev, relative_addr) = match self.get_device_at(addr, data.len()) { + Ok(result) => result, + Err(err) if self.ignore_unmapped => { + info!("{:?}", err); + return Ok(()) + }, + Err(err) => return Err(err), + }; let result = dev.borrow_mut().as_addressable().unwrap().write(relative_addr, data); result } diff --git a/src/system.rs b/src/system.rs index 798d0a2..d144583 100644 --- a/src/system.rs +++ b/src/system.rs @@ -50,6 +50,10 @@ impl System { self.interrupt_controller.borrow_mut() } + pub fn get_device(&self, name: &str) -> Result { + self.devices.get(name).cloned().ok_or_else(|| Error::new(&format!("system: no device named {}", name))) + } + pub fn add_device(&mut self, name: &str, device: TransmutableBox) -> Result<(), Error> { self.try_queue_device(device.clone()); self.devices.insert(name.to_string(), device); diff --git a/todo.txt b/todo.txt index b1534e8..6c6c2aa 100644 --- a/todo.txt +++ b/todo.txt @@ -1,12 +1,13 @@ +* there is an issue with Mortal Kombat 2 where it will crash randomly at the start of a fight. The code is actually swapping + stacks a bunch of times, and at some point, the stack is corrupted or something and it `rts`s to the wrong address... -* for the line based hscroll, you need to add that extra cell cycle... * there is still some kind of hscroll glitch, and it seems to entirely be caused by the horizontal scroll offset value. I could be calculating or adding/moding it incorrectly somewhere somehow, or the data in the hscroll table could be incorrect due to the cpu impl + + * go through the testcases and make sure they are decoded correctly - - * should you rename devices.rs traits.rs? * add command line arguments to speed up or slow down either the frame rate limiter or the simulated time per frame