From f84e425d24981fa773fcbd68b1bdc24523bacd13 Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Thu, 21 May 2020 22:35:08 +0300 Subject: [PATCH] core: Make gpio optional Former-commit-id: 2efe3a5486d76b2be0fc99abbe2e1ea14b21d180 Former-commit-id: b2ce408e12913a050354258b3e6f3c5e0714183d --- rustboyadvance-core/src/cartridge/builder.rs | 4 ++-- rustboyadvance-core/src/cartridge/mod.rs | 22 ++++++++++++-------- rustboyadvance-core/src/debugger/command.rs | 4 +--- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/rustboyadvance-core/src/cartridge/builder.rs b/rustboyadvance-core/src/cartridge/builder.rs index 38aacf8..9cb67c3 100644 --- a/rustboyadvance-core/src/cartridge/builder.rs +++ b/rustboyadvance-core/src/cartridge/builder.rs @@ -177,10 +177,10 @@ impl GamepakBuilder { let backup = create_backup(save_type, self.save_path); let gpio = match gpio_device { - GpioDeviceType::None => Gpio::new_none(), + GpioDeviceType::None => None, GpioDeviceType::Rtc => { info!("Emulating RTC!"); - Gpio::new_rtc() + Some(Gpio::new_rtc()) } _ => unimplemented!("Gpio device {:?} not implemented", gpio_device), }; diff --git a/rustboyadvance-core/src/cartridge/mod.rs b/rustboyadvance-core/src/cartridge/mod.rs index ab3ecd0..0c8dc62 100644 --- a/rustboyadvance-core/src/cartridge/mod.rs +++ b/rustboyadvance-core/src/cartridge/mod.rs @@ -40,7 +40,7 @@ pub struct Cartridge { pub header: CartridgeHeader, bytes: Box<[u8]>, size: usize, - gpio: Gpio, + gpio: Option, symbols: Option, // TODO move it somewhere else pub(in crate) backup: BackupMedia, } @@ -49,7 +49,7 @@ impl Cartridge { pub fn get_symbols(&self) -> &Option { &self.symbols } - pub fn get_gpio(&self) -> &Gpio { + pub fn get_gpio(&self) -> &Option { &self.gpio } } @@ -85,11 +85,13 @@ impl Bus for Cartridge { } fn read_16(&self, addr: u32) -> u16 { - if is_gpio_access(addr) { - if !(self.gpio.is_readable()) { - info!("trying to read GPIO when reads are not allowed"); + if let Some(gpio) = &self.gpio { + if is_gpio_access(addr) { + if !(gpio.is_readable()) { + 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 @@ -114,9 +116,11 @@ impl Bus for Cartridge { } fn write_16(&mut self, addr: u32, value: u16) { - if is_gpio_access(addr) { - self.gpio.write(addr & 0x1ff_ffff, value); - return; + if let Some(gpio) = &mut self.gpio { + if is_gpio_access(addr) { + gpio.write(addr & 0x1ff_ffff, value); + return; + } } if addr & 0xff000000 == GAMEPAK_WS2_HI diff --git a/rustboyadvance-core/src/debugger/command.rs b/rustboyadvance-core/src/debugger/command.rs index 22e3e43..98ae8ad 100644 --- a/rustboyadvance-core/src/debugger/command.rs +++ b/rustboyadvance-core/src/debugger/command.rs @@ -79,9 +79,7 @@ impl Debugger { println!("IF={:#?}", self.gba.sysbus.io.intc.interrupt_flags); } GpuInfo => println!("GPU: {:#?}", self.gba.sysbus.io.gpu), - GpioInfo => { - println!("GPIO: {:#?}", self.gba.sysbus.cartridge.get_gpio()); - } + GpioInfo => println!("GPIO: {:#?}", self.gba.sysbus.cartridge.get_gpio()), Step(count) => { for _ in 0..count { self.gba.cpu.step(&mut self.gba.sysbus);