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 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),
};

View file

@ -40,7 +40,7 @@ pub struct Cartridge {
pub header: CartridgeHeader,
bytes: Box<[u8]>,
size: usize,
gpio: Gpio,
gpio: Option<Gpio>,
symbols: Option<SymbolTable>, // TODO move it somewhere else
pub(in crate) backup: BackupMedia,
}
@ -49,7 +49,7 @@ impl Cartridge {
pub fn get_symbols(&self) -> &Option<SymbolTable> {
&self.symbols
}
pub fn get_gpio(&self) -> &Gpio {
pub fn get_gpio(&self) -> &Option<Gpio> {
&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

View file

@ -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);