Skip to content

Commit

Permalink
Add get_cpu method to System trait
Browse files Browse the repository at this point in the history
Co-authored-by: Ava Silver <[email protected]>
  • Loading branch information
breqdev and ava-silver committed Dec 30, 2023
1 parent 327cf31 commit 6e3285e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/systems/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ pub struct BasicSystem {
}

impl System for BasicSystem {
fn get_cpu(&self) -> Box<&dyn Cpu> {
Box::new(&self.cpu)
}

fn tick(&mut self) -> Duration {
Duration::from_secs_f64(1.0 / 20_000.0) * self.cpu.tick().into()
}
Expand Down
4 changes: 4 additions & 0 deletions src/systems/c64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ pub struct C64System {
}

impl System for C64System {
fn get_cpu(&self) -> Box<&dyn Cpu> {
Box::new(&self.cpu)
}

fn tick(&mut self) -> Duration {
Duration::from_secs_f64(1.0 / 1_000_000.0) * self.cpu.tick() as u32
}
Expand Down
4 changes: 4 additions & 0 deletions src/systems/easy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ pub struct Easy6502System {
}

impl System for Easy6502System {
fn get_cpu(&self) -> Box<&dyn Cpu> {
Box::new(&self.cpu)
}

fn tick(&mut self) -> Duration {
Duration::from_secs_f64(1.0 / 20_000.0) * self.cpu.tick().into()
}
Expand Down
4 changes: 4 additions & 0 deletions src/systems/klaus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ pub struct KlausSystem {
}

impl System for KlausSystem {
fn get_cpu(&self) -> Box<&dyn Cpu> {
Box::new(&self.cpu)
}

fn tick(&mut self) -> Duration {
self.cpu.tick();
if let Some(pc) = &self.pc {
Expand Down
8 changes: 7 additions & 1 deletion src/systems/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::platform::{PlatformProvider, WindowConfig};
use crate::{
cpu::Cpu,
platform::{PlatformProvider, WindowConfig},
};
use instant::Duration;
use std::sync::Arc;

Expand All @@ -21,6 +24,9 @@ pub trait BuildableSystem<RomRegistry, SystemConfig> {

/// A representation of an emulated system.
pub trait System {
/// Return a mutable reference to the CPU used in this system.
fn get_cpu(&self) -> Box<&dyn Cpu>;

/// Advance the system by one tick.
fn tick(&mut self) -> Duration;

Expand Down
4 changes: 4 additions & 0 deletions src/systems/pet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ pub struct PetSystem {
}

impl System for PetSystem {
fn get_cpu(&self) -> Box<&dyn Cpu> {
Box::new(&self.cpu)
}

fn tick(&mut self) -> Duration {
Duration::from_secs_f64(1.0 / 1_000_000.0) * self.cpu.tick() as u32
}
Expand Down
4 changes: 4 additions & 0 deletions src/systems/vic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ pub struct Vic20System {
}

impl System for Vic20System {
fn get_cpu(&self) -> Box<&dyn Cpu> {
Box::new(&self.cpu)
}

fn tick(&mut self) -> instant::Duration {
Duration::from_secs_f64(1.0 / 1_000_000.0) * self.cpu.tick() as u32
}
Expand Down

0 comments on commit 6e3285e

Please sign in to comment.