diff --git a/src/bus.rs b/src/bus.rs index 2201d39..9b4b0de 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -303,7 +303,7 @@ impl Component for ActiveBus { while self.is_running() { self.update(); - thread::sleep(Duration::from_micros(1)); + thread::sleep(Duration::from_micros(10)); } } @@ -389,13 +389,44 @@ mod tests { #[test] fn test_active_bus_pattern() { let mut active_bus = ActiveBus::new("ACTIVE_BUS".to_string()); + + // Start the bus in a new thread + let bus_arc = std::sync::Arc::new(std::sync::Mutex::new(bus)); + let bus_clone = bus_arc.clone(); + + let handle = std::thread::spawn(move || { + let mut bus = bus_clone.lock().unwrap(); + bus.start().unwrap(); + // Bus runs in this thread + }); + + // Give the thread a moment to start + std::thread::sleep(std::time::Duration::from_millis(10)); + + // Check if bus is running + { + let bus = bus_arc.lock().unwrap(); + assert!(bus.is_running()); + } + let pattern = vec![PinValue::High, PinValue::Low, PinValue::High, PinValue::Low]; - active_bus.set_test_pattern(pattern); + active_bus.set_test_pattern(pattern.clone()); active_bus.set_pattern_interval(Duration::from_millis(10)); + // Give the thread a moment to start + std::thread::sleep(std::time::Duration::from_millis(100)); + // Test that active bus can drive patterns active_bus.drive_pattern(); - assert!(active_bus.is_running()); + assert!(active_bus.test_pattern.eq(&pattern)); + + // Clean up - stop the bus and join the thread + { + let mut bus = bus_arc.lock().unwrap(); + bus.stop().unwrap(); + } + + handle.join().unwrap(); } } \ No newline at end of file diff --git a/src/components/cpu/cpu_traits.rs b/src/components/cpu/cpu_traits.rs index 7af67d8..2734e18 100644 --- a/src/components/cpu/cpu_traits.rs +++ b/src/components/cpu/cpu_traits.rs @@ -1,6 +1,6 @@ use crate::component::Component; -use crate::components::cpu::cmos_65c02::CMOS65C02; -use crate::components::cpu::mos_6502::{Registers, MOS6502}; +use crate::components::cpu::mos_6502::MOS6502; +use crate::components::cpu::WDC65C02; pub trait CPU: Component { fn reset(&mut self); @@ -71,7 +71,7 @@ impl MOS6502Family for MOS6502 { // Implement other methods... } -impl CPU for CMOS65C02 { +impl CPU for WDC65C02 { fn reset(&mut self) { todo!() } @@ -97,9 +97,9 @@ impl CPU for CMOS65C02 { } } -impl MOS6502Family for CMOS65C02 { +impl MOS6502Family for WDC65C02 { fn lda(&mut self, value: u8) { - self.base_6502.lda(value) + self.base.lda(value) } fn sta(&mut self, address: u16) { @@ -113,7 +113,7 @@ impl MOS6502Family for CMOS65C02 { // Implement other methods... } -impl CMOS65C02Extensions for CMOS65C02 { +impl CMOS65C02Extensions for WDC65C02 { fn bra(&mut self, address: u16) { self.bra(address) } diff --git a/src/components/cpu/mod.rs b/src/components/cpu/mod.rs index 87bfb03..bdfd300 100644 --- a/src/components/cpu/mod.rs +++ b/src/components/cpu/mod.rs @@ -2,6 +2,7 @@ pub mod mos_6502; pub mod wdc_65c02; pub mod intel_4004; +mod cpu_traits; // Re-export the CPU types pub use mos_6502::MOS6502; diff --git a/src/components/cpu/wdc_65c02.rs b/src/components/cpu/wdc_65c02.rs index f55c475..f727e46 100644 --- a/src/components/cpu/wdc_65c02.rs +++ b/src/components/cpu/wdc_65c02.rs @@ -7,7 +7,7 @@ use crate::pin::Pin; /// WDC 65C02 - CMOS version of 6502 with additional instructions pub struct WDC65C02 { - base: MOS6502, + pub(crate) base: MOS6502, // 65C02-specific state stop_mode: bool, wait_mode: bool, diff --git a/src/components/memory/generic_ram.rs b/src/components/memory/generic_ram.rs index 08d3099..31da983 100644 --- a/src/components/memory/generic_ram.rs +++ b/src/components/memory/generic_ram.rs @@ -289,7 +289,7 @@ impl Component for GenericRam { while self.is_running() { self.update(); - thread::sleep(Duration::from_micros(1)); + thread::sleep(Duration::from_micros(10)); } } diff --git a/src/components/memory/generic_rom.rs b/src/components/memory/generic_rom.rs index fedb49b..efffc12 100644 --- a/src/components/memory/generic_rom.rs +++ b/src/components/memory/generic_rom.rs @@ -253,7 +253,7 @@ impl Component for GenericRom { while self.base.is_running() { self.update(); - thread::sleep(Duration::from_micros(1)); // Small delay to prevent busy waiting + thread::sleep(Duration::from_micros(10)); // Small delay to prevent busy waiting } } diff --git a/src/components/memory/intel_4001.rs b/src/components/memory/intel_4001.rs index e6b21a8..93fcab5 100644 --- a/src/components/memory/intel_4001.rs +++ b/src/components/memory/intel_4001.rs @@ -313,7 +313,7 @@ impl Component for Intel4001 { while self.is_running() { self.update(); - thread::sleep(Duration::from_micros(1)); + thread::sleep(Duration::from_micros(10)); } } diff --git a/src/components/memory/intel_4002.rs b/src/components/memory/intel_4002.rs index 7a768ad..79c86e0 100644 --- a/src/components/memory/intel_4002.rs +++ b/src/components/memory/intel_4002.rs @@ -327,7 +327,7 @@ impl Component for Intel4002 { while self.is_running() { self.update(); - thread::sleep(Duration::from_micros(1)); + thread::sleep(Duration::from_micros(10)); } }