core: Make gpio optional

Former-commit-id: 2efe3a5486d76b2be0fc99abbe2e1ea14b21d180
Former-commit-id: b2ce408e12913a050354258b3e6f3c5e0714183d
This commit is contained in:
Michel Heily 2020-05-21 22:35:08 +03:00 committed by MishMish
parent 3839b8eb02
commit f84e425d24
3 changed files with 16 additions and 14 deletions

View file

@ -177,10 +177,10 @@ impl GamepakBuilder {
let backup = create_backup(save_type, self.save_path); let backup = create_backup(save_type, self.save_path);
let gpio = match gpio_device { let gpio = match gpio_device {
GpioDeviceType::None => Gpio::new_none(), GpioDeviceType::None => None,
GpioDeviceType::Rtc => { GpioDeviceType::Rtc => {
info!("Emulating RTC!"); info!("Emulating RTC!");
Gpio::new_rtc() Some(Gpio::new_rtc())
} }
_ => unimplemented!("Gpio device {:?} not implemented", gpio_device), _ => unimplemented!("Gpio device {:?} not implemented", gpio_device),
}; };

View file

@ -40,7 +40,7 @@ pub struct Cartridge {
pub header: CartridgeHeader, pub header: CartridgeHeader,
bytes: Box<[u8]>, bytes: Box<[u8]>,
size: usize, size: usize,
gpio: Gpio, gpio: Option<Gpio>,
symbols: Option<SymbolTable>, // TODO move it somewhere else symbols: Option<SymbolTable>, // TODO move it somewhere else
pub(in crate) backup: BackupMedia, pub(in crate) backup: BackupMedia,
} }
@ -49,7 +49,7 @@ impl Cartridge {
pub fn get_symbols(&self) -> &Option<SymbolTable> { pub fn get_symbols(&self) -> &Option<SymbolTable> {
&self.symbols &self.symbols
} }
pub fn get_gpio(&self) -> &Gpio { pub fn get_gpio(&self) -> &Option<Gpio> {
&self.gpio &self.gpio
} }
} }
@ -85,11 +85,13 @@ impl Bus for Cartridge {
} }
fn read_16(&self, addr: u32) -> u16 { fn read_16(&self, addr: u32) -> u16 {
if let Some(gpio) = &self.gpio {
if is_gpio_access(addr) { if is_gpio_access(addr) {
if !(self.gpio.is_readable()) { if !(gpio.is_readable()) {
info!("trying to read GPIO when reads are not allowed"); warn!("trying to read GPIO when reads are not allowed");
}
return gpio.read(addr & 0x1ff_ffff);
} }
return self.gpio.read(addr & 0x1ff_ffff);
} }
if addr & 0xff000000 == GAMEPAK_WS2_HI if addr & 0xff000000 == GAMEPAK_WS2_HI
@ -114,10 +116,12 @@ impl Bus for Cartridge {
} }
fn write_16(&mut self, addr: u32, value: u16) { fn write_16(&mut self, addr: u32, value: u16) {
if let Some(gpio) = &mut self.gpio {
if is_gpio_access(addr) { if is_gpio_access(addr) {
self.gpio.write(addr & 0x1ff_ffff, value); gpio.write(addr & 0x1ff_ffff, value);
return; return;
} }
}
if addr & 0xff000000 == GAMEPAK_WS2_HI if addr & 0xff000000 == GAMEPAK_WS2_HI
&& (self.bytes.len() <= 16 * 1024 * 1024 || addr >= EEPROM_BASE_ADDR) && (self.bytes.len() <= 16 * 1024 * 1024 || addr >= EEPROM_BASE_ADDR)

View file

@ -79,9 +79,7 @@ impl Debugger {
println!("IF={:#?}", self.gba.sysbus.io.intc.interrupt_flags); println!("IF={:#?}", self.gba.sysbus.io.intc.interrupt_flags);
} }
GpuInfo => println!("GPU: {:#?}", self.gba.sysbus.io.gpu), GpuInfo => println!("GPU: {:#?}", self.gba.sysbus.io.gpu),
GpioInfo => { GpioInfo => println!("GPIO: {:#?}", self.gba.sysbus.cartridge.get_gpio()),
println!("GPIO: {:#?}", self.gba.sysbus.cartridge.get_gpio());
}
Step(count) => { Step(count) => {
for _ in 0..count { for _ in 0..count {
self.gba.cpu.step(&mut self.gba.sysbus); self.gba.cpu.step(&mut self.gba.sysbus);