From fc7ad01cc047406d24025116d25bd465cabcabd4 Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Sun, 18 Oct 2020 08:32:44 -0700 Subject: [PATCH] Forgot to restore scheduler pointers when restoring savestate :) Former-commit-id: c6968e6767f0aa996a908a1444ce63bafd8b427d Former-commit-id: ce636212835f50745c7edeb32e1fed925850b7c8 --- core/src/dma.rs | 8 +++++++- core/src/gba.rs | 10 ++++------ core/src/gpu/mod.rs | 12 +++++++----- core/src/iodev.rs | 10 ++++++++++ core/src/sched.rs | 4 ++++ core/src/sound/mod.rs | 10 ++++++---- core/src/sysbus.rs | 12 +++++++----- core/src/timer.rs | 8 +++++++- 8 files changed, 52 insertions(+), 22 deletions(-) diff --git a/core/src/dma.rs b/core/src/dma.rs index d63a228..d6fdb5a 100644 --- a/core/src/dma.rs +++ b/core/src/dma.rs @@ -2,7 +2,7 @@ use super::arm7tdmi::memory::{MemoryAccess, MemoryInterface}; use super::cartridge::BackupMedia; use super::interrupt::{self, Interrupt, InterruptConnect, SharedInterruptFlags}; use super::iodev::consts::{REG_FIFO_A, REG_FIFO_B}; -use super::sched::{EventType, Scheduler, SharedScheduler}; +use super::sched::{EventType, Scheduler, SchedulerConnect, SharedScheduler}; use super::sysbus::SysBus; use num::FromPrimitive; @@ -206,6 +206,12 @@ impl InterruptConnect for DmaController { } } +impl SchedulerConnect for DmaController { + fn connect_scheduler(&mut self, scheduler: SharedScheduler) { + self.scheduler = scheduler; + } +} + impl DmaController { pub fn new(interrupt_flags: SharedInterruptFlags, scheduler: SharedScheduler) -> DmaController { DmaController { diff --git a/core/src/gba.rs b/core/src/gba.rs index 359b1a4..dc7e280 100644 --- a/core/src/gba.rs +++ b/core/src/gba.rs @@ -11,7 +11,7 @@ use super::dma::DmaController; use super::gpu::*; use super::interrupt::*; use super::iodev::*; -use super::sched::{EventType, Scheduler, SharedScheduler}; +use super::sched::{EventType, Scheduler, SchedulerConnect, SharedScheduler}; use super::sound::SoundController; use super::sysbus::SysBus; use super::timer::Timers; @@ -134,8 +134,7 @@ impl GameBoyAdvance { let mut cartridge = decoded.cartridge; cartridge.set_rom_bytes(rom); io_devs.connect_irq(interrupts.clone()); - io_devs.gpu.set_scheduler(scheduler.clone()); - io_devs.sound.set_scheduler(scheduler.clone()); + io_devs.connect_scheduler(scheduler.clone()); let mut sysbus = Shared::new(SysBus::new_with_memories( scheduler.clone(), io_devs.clone(), @@ -194,9 +193,8 @@ impl GameBoyAdvance { self.sysbus.set_ewram(decoded.ewram); // Redistribute shared pointers self.io_devs.connect_irq(self.interrupt_flags.clone()); - self.io_devs.gpu.set_scheduler(self.scheduler.clone()); - self.io_devs.sound.set_scheduler(self.scheduler.clone()); - self.sysbus.set_scheduler(self.scheduler.clone()); + self.io_devs.connect_scheduler(self.scheduler.clone()); + self.sysbus.connect_scheduler(self.scheduler.clone()); self.sysbus.set_io_devices(self.io_devs.clone()); self.sysbus.cartridge.update_from(decoded.cartridge); self.sysbus.init(self.cpu.weak_ptr()); diff --git a/core/src/gpu/mod.rs b/core/src/gpu/mod.rs index 5c8b096..0ef4ec9 100644 --- a/core/src/gpu/mod.rs +++ b/core/src/gpu/mod.rs @@ -183,7 +183,7 @@ pub struct Gpu { pub state: GpuState, interrupt_flags: SharedInterruptFlags, - /// When deserializing this struct using serde, make sure to call Gpu:::set_scheduler + /// When deserializing this struct using serde, make sure to call connect_scheduler #[serde(skip)] #[serde(default = "Scheduler::new_shared")] scheduler: SharedScheduler, @@ -228,6 +228,12 @@ impl InterruptConnect for Gpu { } } +impl SchedulerConnect for Gpu { + fn connect_scheduler(&mut self, scheduler: SharedScheduler) { + self.scheduler = scheduler; + } +} + impl Gpu { pub fn new(mut scheduler: SharedScheduler, interrupt_flags: SharedInterruptFlags) -> Gpu { scheduler.push_gpu_event(GpuEvent::HDraw, CYCLES_HDRAW); @@ -268,10 +274,6 @@ impl Gpu { } } - pub fn set_scheduler(&mut self, scheduler: SharedScheduler) { - self.scheduler = scheduler; - } - pub fn write_dispcnt(&mut self, value: u16) { let new_dispcnt = DisplayControl(value); let old_mode = self.dispcnt.mode(); diff --git a/core/src/iodev.rs b/core/src/iodev.rs index c70112c..748cea0 100644 --- a/core/src/iodev.rs +++ b/core/src/iodev.rs @@ -6,6 +6,7 @@ use super::gpu::regs::WindowFlags; use super::gpu::*; use super::interrupt::{InterruptConnect, InterruptController, SharedInterruptFlags}; use super::keypad; +use super::sched::{SchedulerConnect, SharedScheduler}; use super::sound::SoundController; use super::sysbus::SysBusPtr; use super::timer::Timers; @@ -77,6 +78,15 @@ impl InterruptConnect for IoDevices { } } +impl SchedulerConnect for IoDevices { + fn connect_scheduler(&mut self, scheduler: SharedScheduler) { + self.gpu.connect_scheduler(scheduler.clone()); + self.sound.connect_scheduler(scheduler.clone()); + self.dmac.connect_scheduler(scheduler.clone()); + self.timers.connect_scheduler(scheduler.clone()); + } +} + impl Bus for IoDevices { fn read_16(&mut self, addr: Addr) -> u16 { let io = self; diff --git a/core/src/sched.rs b/core/src/sched.rs index d5d27f6..598bf07 100644 --- a/core/src/sched.rs +++ b/core/src/sched.rs @@ -212,6 +212,10 @@ impl Scheduler { } } +pub trait SchedulerConnect { + fn connect_scheduler(&mut self, scheduler: SharedScheduler); +} + #[cfg(test)] mod test { diff --git a/core/src/sound/mod.rs b/core/src/sound/mod.rs index 9cbea0c..cb80463 100644 --- a/core/src/sound/mod.rs +++ b/core/src/sound/mod.rs @@ -105,6 +105,12 @@ pub struct SoundController { output_buffer: Vec>, } +impl SchedulerConnect for SoundController { + fn connect_scheduler(&mut self, scheduler: SharedScheduler) { + self.scheduler = scheduler; + } +} + impl SoundController { pub fn new(mut scheduler: SharedScheduler, audio_device_sample_rate: f32) -> SoundController { let resampler = CosineResampler::new(32768_f32, audio_device_sample_rate); @@ -143,10 +149,6 @@ impl SoundController { } } - pub fn set_scheduler(&mut self, scheduler: SharedScheduler) { - self.scheduler = scheduler; - } - pub fn handle_read(&self, io_addr: u32) -> u16 { let value = match io_addr { REG_SOUNDCNT_X => cbit(7, self.mse), diff --git a/core/src/sysbus.rs b/core/src/sysbus.rs index 897071f..c439fad 100644 --- a/core/src/sysbus.rs +++ b/core/src/sysbus.rs @@ -7,7 +7,7 @@ use super::bus::*; use super::cartridge::Cartridge; use super::dma::DmaNotifer; use super::iodev::{IoDevices, WaitControl}; -use super::sched::Scheduler; +use super::sched::*; use super::util::{Shared, WeakPointer}; pub mod consts { @@ -158,6 +158,12 @@ pub struct SysBus { pub type SysBusPtr = WeakPointer; +impl SchedulerConnect for SysBus { + fn connect_scheduler(&mut self, scheduler: SharedScheduler) { + self.scheduler = scheduler; + } +} + impl SysBus { pub fn new_with_memories( scheduler: Shared, @@ -212,10 +218,6 @@ impl SysBus { &self.iwram } - pub fn set_scheduler(&mut self, s: Shared) { - self.scheduler = s; - } - pub fn set_io_devices(&mut self, io_devs: Shared) { self.io = io_devs; } diff --git a/core/src/timer.rs b/core/src/timer.rs index af65710..df59f67 100644 --- a/core/src/timer.rs +++ b/core/src/timer.rs @@ -1,7 +1,7 @@ use super::dma::DmaController; use super::interrupt::{self, Interrupt, InterruptConnect, SharedInterruptFlags}; use super::iodev::consts::*; -use super::sched::{EventType, Scheduler, SharedScheduler}; +use super::sched::{EventType, Scheduler, SchedulerConnect, SharedScheduler}; use super::sound::SoundController; use num::FromPrimitive; @@ -109,6 +109,12 @@ impl InterruptConnect for Timers { } } +impl SchedulerConnect for Timers { + fn connect_scheduler(&mut self, scheduler: SharedScheduler) { + self.scheduler = scheduler; + } +} + impl std::ops::Index for Timers { type Output = Timer; fn index(&self, index: usize) -> &Self::Output {