From 712012e0ad9e073e2e106c898366dd1d256fb91c Mon Sep 17 00:00:00 2001 From: Brooke Chalmers Date: Fri, 29 Dec 2023 18:03:23 -0800 Subject: [PATCH] Remove SystemBuilder structs, refactor trait into BuildableSystem Co-authored-by: Ava Silver --- src/main.rs | 20 ++++++++++---------- src/systems/basic.rs | 7 ++----- src/systems/c64/mod.rs | 7 ++----- src/systems/easy.rs | 6 ++---- src/systems/klaus.rs | 10 ++++------ src/systems/mod.rs | 4 ++-- src/systems/pet/mod.rs | 7 ++----- src/systems/vic/mod.rs | 7 ++----- 8 files changed, 26 insertions(+), 42 deletions(-) diff --git a/src/main.rs b/src/main.rs index eefbab9b..a3f7814a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,10 +4,10 @@ use libnoentiendo::{ platform::{SyncPlatform, TextPlatform, WinitPlatform}, roms::DiskLoadable, systems::{ - basic::BasicSystemBuilder, c64::C64SystemBuilder, c64::C64SystemConfig, c64::C64SystemRoms, - easy::Easy6502SystemBuilder, klaus::KlausSystemBuilder, pet::PetSystemBuilder, - pet::PetSystemConfig, pet::PetSystemRoms, vic::Vic20SystemBuilder, vic::Vic20SystemConfig, - vic::Vic20SystemRoms, SystemBuilder, + basic::BasicSystem, c64::C64System, c64::C64SystemConfig, c64::C64SystemRoms, + easy::Easy6502System, klaus::KlausSystem, pet::PetSystem, pet::PetSystemConfig, + pet::PetSystemRoms, vic::Vic20System, vic::Vic20SystemConfig, vic::Vic20SystemRoms, + BuildableSystem, }, }; @@ -75,9 +75,9 @@ fn main() { }; let system = match args.system { - SystemArg::Basic => BasicSystemBuilder::build(romfile.unwrap(), (), platform.provider()), - SystemArg::Easy => Easy6502SystemBuilder::build(romfile.unwrap(), (), platform.provider()), - SystemArg::Klaus => KlausSystemBuilder::build( + SystemArg::Basic => BasicSystem::build(romfile.unwrap(), (), platform.provider()), + SystemArg::Easy => Easy6502System::build(romfile.unwrap(), (), platform.provider()), + SystemArg::Klaus => KlausSystem::build( romfile.unwrap(), KlausSystemConfig { pc_report: None, @@ -85,12 +85,12 @@ fn main() { }, platform.provider(), ), - SystemArg::Pet => PetSystemBuilder::build( + SystemArg::Pet => PetSystem::build( PetSystemRoms::from_disk(), PetSystemConfig { mapping }, platform.provider(), ), - SystemArg::Vic => Vic20SystemBuilder::build( + SystemArg::Vic => Vic20System::build( Vic20SystemRoms::from_disk(match romfile { Some(_) => Some(args.rom_path.as_str()), None => None, @@ -98,7 +98,7 @@ fn main() { Vic20SystemConfig { mapping }, platform.provider(), ), - SystemArg::C64 => C64SystemBuilder::build( + SystemArg::C64 => C64System::build( C64SystemRoms::from_disk(), C64SystemConfig { mapping }, platform.provider(), diff --git a/src/systems/basic.rs b/src/systems/basic.rs index b5fc1cdb..10f7d63f 100644 --- a/src/systems/basic.rs +++ b/src/systems/basic.rs @@ -8,7 +8,7 @@ use crate::memory::{ActiveInterrupt, Memory}; use crate::memory::{BlockMemory, BranchMemory}; use crate::platform::{PlatformProvider, WindowConfig}; use crate::roms::RomFile; -use crate::systems::{System, SystemBuilder}; +use crate::systems::{BuildableSystem, System}; use std::io::Write; use std::sync::Arc; @@ -68,10 +68,7 @@ impl Memory for MappedStdIO { } } -/// A factory for creating a BasicSystem. -pub struct BasicSystemBuilder; - -impl SystemBuilder for BasicSystemBuilder { +impl BuildableSystem for BasicSystem { fn build(rom: RomFile, _config: (), platform: Arc) -> Box { let ram = BlockMemory::ram(0x4000); let io = MappedStdIO::new(platform); diff --git a/src/systems/c64/mod.rs b/src/systems/c64/mod.rs index b49ed032..5aefcfe7 100644 --- a/src/systems/c64/mod.rs +++ b/src/systems/c64/mod.rs @@ -30,7 +30,7 @@ use self::{ vic_ii::{VicIIChip, VicIIChipIO}, }; -use super::SystemBuilder; +use super::BuildableSystem; /// Port A on the first CIA chip on the C64 deals with setting the keyboard row being scanned. struct C64Cia1PortA { @@ -204,10 +204,7 @@ pub struct C64SystemConfig { pub mapping: KeyMappingStrategy, } -/// A factory for creating a Commodore 64 system. -pub struct C64SystemBuilder; - -impl SystemBuilder for C64SystemBuilder { +impl BuildableSystem for C64System { fn build( roms: C64SystemRoms, config: C64SystemConfig, diff --git a/src/systems/easy.rs b/src/systems/easy.rs index 2652d84e..1edf220e 100644 --- a/src/systems/easy.rs +++ b/src/systems/easy.rs @@ -8,7 +8,7 @@ use crate::keyboard::KeyPosition; use crate::memory::{ActiveInterrupt, BlockMemory, BranchMemory, Memory}; use crate::platform::{Color, PlatformProvider, WindowConfig}; use crate::roms::RomFile; -use crate::systems::{System, SystemBuilder}; +use crate::systems::{BuildableSystem, System}; use std::sync::Arc; const WIDTH: u32 = 32; @@ -61,9 +61,7 @@ impl Memory for EasyIO { } /// A factory for the Easy6502 system. -pub struct Easy6502SystemBuilder; - -impl SystemBuilder for Easy6502SystemBuilder { +impl BuildableSystem for Easy6502System { fn build(rom: RomFile, _config: (), platform: Arc) -> Box { platform.request_window(WindowConfig::new(WIDTH, WIDTH, SCALE as f64)); diff --git a/src/systems/klaus.rs b/src/systems/klaus.rs index 9e8a9d60..9be407a1 100644 --- a/src/systems/klaus.rs +++ b/src/systems/klaus.rs @@ -12,7 +12,7 @@ use std::cell::Cell; use std::rc::Rc; use std::sync::Arc; -use super::SystemBuilder; +use super::BuildableSystem; pub struct KlausSystemConfig { pub pc_report: Option>>, @@ -20,9 +20,7 @@ pub struct KlausSystemConfig { } /// A factory for creating a system that runs Klaus Dormann's 6502 CPU test suite. -pub struct KlausSystemBuilder; - -impl SystemBuilder for KlausSystemBuilder { +impl BuildableSystem for KlausSystem { fn build( rom: RomFile, config: KlausSystemConfig, @@ -77,7 +75,7 @@ mod tests { let platform = TextPlatform::new(); let pc = Rc::new(Cell::new(0)); - let mut system = KlausSystemBuilder::build( + let mut system = KlausSystem::build( roms, KlausSystemConfig { pc_report: Some(pc.clone()), @@ -99,7 +97,7 @@ mod tests { let platform = TextPlatform::new(); let pc = Rc::new(Cell::new(0)); - let mut system = KlausSystemBuilder::build( + let mut system = KlausSystem::build( roms, KlausSystemConfig { pc_report: Some(pc.clone()), diff --git a/src/systems/mod.rs b/src/systems/mod.rs index ad2c1537..d27f2a79 100644 --- a/src/systems/mod.rs +++ b/src/systems/mod.rs @@ -9,8 +9,8 @@ pub mod klaus; pub mod pet; pub mod vic; -pub trait SystemBuilder { - /// Create a new system from the given roms, configuration, and with I/O provided by the given +pub trait BuildableSystem { + /// Instantiate this system from the given roms, configuration, and with I/O provided by the given /// platform provider. fn build( roms: RomRegistry, diff --git a/src/systems/pet/mod.rs b/src/systems/pet/mod.rs index b07371c4..72c9ac7c 100644 --- a/src/systems/pet/mod.rs +++ b/src/systems/pet/mod.rs @@ -6,7 +6,7 @@ use crate::keyboard::{KeyAdapter, KeyMappingStrategy, SymbolAdapter}; use crate::memory::mos652x::{Pia, Via}; use crate::memory::{BlockMemory, BranchMemory, NullMemory, NullPort, Port}; use crate::platform::{Color, PlatformProvider, WindowConfig}; -use crate::systems::{System, SystemBuilder}; +use crate::systems::{BuildableSystem, System}; use instant::Instant; use std::cell::Cell; use std::rc::Rc; @@ -151,10 +151,7 @@ pub struct PetSystemConfig { pub mapping: KeyMappingStrategy, } -/// A factory for the Commodore PET. -pub struct PetSystemBuilder; - -impl SystemBuilder for PetSystemBuilder { +impl BuildableSystem for PetSystem { fn build( roms: PetSystemRoms, config: PetSystemConfig, diff --git a/src/systems/vic/mod.rs b/src/systems/vic/mod.rs index f0aca798..e1461d84 100644 --- a/src/systems/vic/mod.rs +++ b/src/systems/vic/mod.rs @@ -34,7 +34,7 @@ use wasm_bindgen::JsCast; #[cfg(target_arch = "wasm32")] use js_sys::Uint8Array; -use super::SystemBuilder; +use super::BuildableSystem; /// The set of ROM files required to run a VIC-20 system. pub struct Vic20SystemRoms { @@ -249,10 +249,7 @@ pub struct Vic20SystemConfig { pub mapping: KeyMappingStrategy, } -/// A factory for creating a VIC-20 system. -pub struct Vic20SystemBuilder; - -impl SystemBuilder for Vic20SystemBuilder { +impl BuildableSystem for Vic20System { fn build( roms: Vic20SystemRoms, config: Vic20SystemConfig,