From 196336b5f7f65c7a616a7673639df7b3cde3b49b Mon Sep 17 00:00:00 2001 From: Brooke Chalmers Date: Wed, 22 Nov 2023 18:44:11 -0500 Subject: [PATCH 1/3] Add (failing) Klaus test --- src/main.rs | 2 +- src/systems/klaus.rs | 53 +++++++++++++++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 236523a0..d214f350 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,7 +75,7 @@ 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(romfile.unwrap(), (), platform.provider()), + SystemArg::Klaus => KlausSystemBuilder::build(romfile.unwrap(), None, platform.provider()), SystemArg::Pet => PetSystemBuilder::build( PetSystemRoms::from_disk(), PetSystemConfig { mapping }, diff --git a/src/systems/klaus.rs b/src/systems/klaus.rs index 3f90f47c..7388b93c 100644 --- a/src/systems/klaus.rs +++ b/src/systems/klaus.rs @@ -1,10 +1,12 @@ -use instant::{Duration, Instant}; +use instant::Duration; use crate::cpu::Mos6502; use crate::memory::BlockMemory; use crate::platform::{PlatformProvider, WindowConfig}; use crate::roms::RomFile; use crate::systems::System; +use std::cell::Cell; +use std::rc::Rc; use std::sync::Arc; use super::SystemBuilder; @@ -12,33 +14,34 @@ use super::SystemBuilder; /// A factory for creating a system that runs Klaus Dormann's 6502 CPU test suite. pub struct KlausSystemBuilder; -impl SystemBuilder for KlausSystemBuilder { - fn build(rom: RomFile, _config: (), _platform: Arc) -> Box { +impl SystemBuilder>>> for KlausSystemBuilder { + fn build( + rom: RomFile, + config: Option>>, + _platform: Arc, + ) -> Box { let rom = BlockMemory::from_file(0x10000, rom); let mut cpu = Mos6502::new(Box::new(rom)); cpu.registers.pc.load(0x0400); - Box::new(KlausSystem { - cpu, - last_report: Instant::now(), - }) + Box::new(KlausSystem { cpu, pc: config }) } } /// A system used to run Klaus Dormann's 6502 CPU test suite. pub struct KlausSystem { cpu: Mos6502, - last_report: Instant, + pc: Option>>, } impl System for KlausSystem { fn tick(&mut self) -> Duration { - if self.last_report.elapsed().as_secs() > 1 { - println!("PC: {:04x}", self.cpu.registers.pc.address()); - self.last_report = Instant::now(); - }; - Duration::from_secs_f64(1.0 / 1_000_000.0) * self.cpu.tick().into() + self.cpu.tick(); + if let Some(pc) = &self.pc { + pc.set(self.cpu.registers.pc.address()); + } + Duration::ZERO } fn reset(&mut self) { @@ -47,3 +50,27 @@ impl System for KlausSystem { fn render(&mut self, _framebuffer: &mut [u8], _window: WindowConfig) {} } + +#[cfg(test)] +mod tests { + use crate::{ + platform::{Platform, TextPlatform}, + roms::DiskLoadable, + }; + + use super::*; + + #[test] + fn test_klaus() { + let roms = RomFile::from_file("bin/klaus.bin"); + let platform = TextPlatform::new(); + let pc = Rc::new(Cell::new(0)); + let mut system = KlausSystemBuilder::build(roms, Some(pc.clone()), platform.provider()); + + for _ in 0..=100000000 { + system.tick(); + } + + assert_eq!(pc.get(), 0x3469); + } +} From f030d541aa2861521536e7fe435ddbb9832edddb Mon Sep 17 00:00:00 2001 From: Brooke Chalmers Date: Wed, 22 Nov 2023 19:27:47 -0500 Subject: [PATCH 2/3] Make Klaus ROM writeable --- src/memory/block.rs | 7 +++++++ src/systems/klaus.rs | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/memory/block.rs b/src/memory/block.rs index efc3e3b2..95e90353 100644 --- a/src/memory/block.rs +++ b/src/memory/block.rs @@ -57,6 +57,13 @@ impl BlockMemory { writeable: false, } } + + /// Change whether this BlockMemory is writable. + pub fn set_writeable(mut self, writeable: bool) -> Self { + self.writeable = writeable; + + self + } } impl Memory for BlockMemory { diff --git a/src/systems/klaus.rs b/src/systems/klaus.rs index 7388b93c..3a26a000 100644 --- a/src/systems/klaus.rs +++ b/src/systems/klaus.rs @@ -20,7 +20,7 @@ impl SystemBuilder>>> for KlausSystemB config: Option>>, _platform: Arc, ) -> Box { - let rom = BlockMemory::from_file(0x10000, rom); + let rom = BlockMemory::from_file(0x10000, rom).set_writeable(true); let mut cpu = Mos6502::new(Box::new(rom)); cpu.registers.pc.load(0x0400); From cb4c86a96c1f6a8950e52808b2b004efd9f20acc Mon Sep 17 00:00:00 2001 From: Brooke Chalmers Date: Wed, 22 Nov 2023 19:43:58 -0500 Subject: [PATCH 3/3] Add .bin's to version control --- .gitignore | 1 - bin/easy.bin | Bin 0 -> 32768 bytes bin/guessing.bin | Bin 0 -> 32768 bytes bin/klaus.bin | Bin 0 -> 65536 bytes 4 files changed, 1 deletion(-) create mode 100644 bin/easy.bin create mode 100644 bin/guessing.bin create mode 100644 bin/klaus.bin diff --git a/.gitignore b/.gitignore index 0193ec54..d8ccb15b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ /target -/bin /flamegraph.svg /.idea .DS_Store diff --git a/bin/easy.bin b/bin/easy.bin new file mode 100644 index 0000000000000000000000000000000000000000..adf5a7f067c8b0c5f4fe5e66e41c2cdf11a102cf GIT binary patch literal 32768 zcmeIuKT88K9LDk7omLALbN&Iv;ev=*L7arHf>WuJgKJjbMQ+F<2nxDOA!3|v=_`;H zu2Wxx9O{%+1T}pd^3C)lKX{USRLiKIQ5~ZWjrOTc{esPWZl#xY&9B;xxXK z3is2^wysi}XmxJXjZv>gZI?=w>Zly_jQg!GL#I9q8}&ulsZYbM_6vLIY~Lp~)qXj~ zo%tQwCo#%c9b+2fqF;_tt9zrKjdo%zXC0S}^Vw39HQD@W!*nF$X={{^^U!{Of6GE^ z@L~ohrGCn$*CY9`HkDs4?N{x7wcW3Zes%0*??YL6o9IdIV_P`Tjr7Hy425=b>nhHw zL^ru_#o3CUNGH2RU4%r(+Q<0WI}yvhDCJQ2q?CFnK0l|k@A+7;5I_I{1Q0*~0R#|0 z009ILKmY**5I_I{1Q0*~0R#|0009ILKmY**5I_I{1Q0*~0R#|0009ILKmY**5I_I{ z1Q0*~0R#|0009ILKmY**5I_I{1Q0*~0R#|0009ILKmY**5I_I{1Q0*~0R#|0009IL wKmY**5I_I{1Q0*~0R#|0009ILKmY**5I_I{1Q0*~0R#|0009L4kAM;44_GsHYXATM literal 0 HcmV?d00001 diff --git a/bin/guessing.bin b/bin/guessing.bin new file mode 100644 index 0000000000000000000000000000000000000000..be00b1fe1640c06e01733dbdfcd6f5353cb2f6cf GIT binary patch literal 32768 zcmeIuF=_%)5C-4}iimgsE7=@C@CbH_Y;S3rpf*~B5bR!KY2^*Rvsls&{-jS z0=w@O{~Kmt2EM9&NayzLZ&-}-B~7kr+`adUeJ%&NnCG&Si)Eds=v32VYf}A0d_{ae zBmUkqKC3dyUBqwGoJF~bSVgRx$>M*qjq0PBG>hWE>r{Orc?1X$AV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF e5FkK+009C72oNAZfB*pk1PBlyK;R7mIi&~fUp&VE literal 0 HcmV?d00001 diff --git a/bin/klaus.bin b/bin/klaus.bin new file mode 100644 index 0000000000000000000000000000000000000000..c9a35e1d6bd2e7d85844da2abf7034d5ed820e6e GIT binary patch literal 65536 zcmeHOeQZ_tc|P}C`}!EJ?Th&`-%bk2C1IJAl_4P2c*~Lbt_T zeMQ*p#{Tm?0Z()g-^V2T}&JoAW*ZL3DXBbJV~kJ8GUfTt)P@4x7;&bO{uUu*0z$eFawJhq`p?$}4oQ2o+*Te-OqGYq znesqM8A{5~KcWmH%0TmQ0h0s_jdW*wFwlOf4CFJ1#_kl$onr&^&(31`(li-M)5S97 zB#~2toM5^=n_0Yl$Uy>S1`mL#{CVy4R&!+tQQ~m=f|G|`Zrc@>{ zKnR?`Y0tJT-o0dK>D01J(%+HVp7j4Hbu{V!X{y-dKbi8sobvxX<$o>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