diff --git a/src/components/cpu/intel_4004.rs b/src/components/cpu/intel_4004.rs index 32c093d..87dc456 100644 --- a/src/components/cpu/intel_4004.rs +++ b/src/components/cpu/intel_4004.rs @@ -26,7 +26,7 @@ pub struct Intel4004 { accumulator: u8, carry: bool, index_registers: [u8; 16], - program_counter: U12, + pub(crate) program_counter: U12, stack: [U12; 3], stack_pointer: u8, cycle_count: u64, diff --git a/src/components/cpu/mos_6502.rs b/src/components/cpu/mos_6502.rs index 405a479..35fef5b 100644 --- a/src/components/cpu/mos_6502.rs +++ b/src/components/cpu/mos_6502.rs @@ -101,7 +101,7 @@ impl MOS6502 { } } - fn read_data_bus(&self) -> u8 { + fn _read_data_bus(&self) -> u8 { let mut data = 0; for i in 0..8 { diff --git a/src/components/memory/intel_4001.rs b/src/components/memory/intel_4001.rs index 5a89b23..e6b21a8 100644 --- a/src/components/memory/intel_4001.rs +++ b/src/components/memory/intel_4001.rs @@ -352,11 +352,11 @@ impl Intel4001 { self.input_latch } - pub fn get_io_mode(&self) -> IoMode { + fn get_io_mode(&self) -> IoMode { self.io_mode } - pub fn set_io_mode(&mut self, mode: IoMode) { + fn set_io_mode(&mut self, mode: IoMode) { self.io_mode = mode; match mode { IoMode::Input => self.tri_state_io_pins(), diff --git a/src/lib.rs b/src/lib.rs index 9e6567a..77621ba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ pub mod connection; pub mod components; pub mod systems; mod bus; -mod types; +pub mod types; // Re-export commonly used items for easier importing pub use component::{Component, BaseComponent}; diff --git a/src/main.rs b/src/main.rs index 3c0b649..90bb9be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use rusty_emu::types::U12; use rusty_emu::systems::intel_mcs_4::IntelMcs4; use std::thread; use std::time::{Duration, Instant}; @@ -40,7 +41,7 @@ fn main() { } // Set starting program counter - if let Err(e) = mcs4.set_cpu_program_counter(0x000) { + if let Err(e) = mcs4.set_cpu_program_counter(U12::from(0x000)) { eprintln!("Failed to set program counter: {}", e); return; } @@ -58,7 +59,7 @@ fn main() { println!(); // Run the Fibonacci demo - run_fibonacci_demo(&mut mcs4); + run_fibonacci_demo(mcs4); } fn compile_fibonacci_program() -> Vec { @@ -74,7 +75,7 @@ fn compile_fibonacci_program() -> Vec { ] } -fn run_fibonacci_demo(mcs4: &mut IntelMcs4) { +fn run_fibonacci_demo(mcs4: IntelMcs4) { let start_time = Instant::now(); println!("Cycle | Fibonacci | Accumulator | PC"); diff --git a/src/systems/intel_mcs_4.rs b/src/systems/intel_mcs_4.rs index c78002a..3215ccb 100644 --- a/src/systems/intel_mcs_4.rs +++ b/src/systems/intel_mcs_4.rs @@ -9,6 +9,7 @@ use crate::component::Component; use crate::components::memory::intel_4001::Intel4001; use crate::components::memory::intel_4002::Intel4002; use crate::pin::Pin; +use crate::types::U12; pub struct IntelMcs4 { components: HashMap>>, @@ -146,50 +147,43 @@ impl IntelMcs4 { Err("RAM component not found".to_string()) } - - pub fn set_cpu_program_counter(&mut self, address: u16) -> Result<(), String> { - if let Some(cpu_component) = self.components.get("cpu") { - if let Ok(mut cpu) = cpu_component.lock() { - // Downcast to Intel4004 - if let Some(cpu_ref) = cpu.as_any_mut().downcast_mut::() { - cpu_ref.set_program_counter(address); - return Ok(()); - } + pub fn set_cpu_program_counter(&mut self, address: U12) -> Result<(), String> { + if let Some(cpu_component) = self.components.get_mut("cpu") { + if let Some(cpu) = cpu_component.as_any_mut().downcast_mut::() { + cpu.program_counter = address; + Ok(()) + } else { + Err("CPU component is not of type Intel 4004".to_string()) } + } else { + Err("CPU component not found".to_string()) } - - Err("CPU component not found".to_string()) } - pub fn get_cpu_state(&self) -> Result { if let Some(cpu_component) = self.components.get("cpu") { - if let Ok(cpu) = cpu_component.lock() { - if let Some(cpu_ref) = cpu.as_any().downcast_ref::() { - return Ok(CpuState { - program_counter: cpu_ref.get_program_counter(), - accumulator: cpu_ref.get_accumulator(), - carry: cpu_ref.get_carry(), - stack_pointer: cpu_ref.get_stack_pointer(), - cycle_count: cpu_ref.get_cycle_count(), - }); - } + if let Some(cpu) = cpu_component.as_any().downcast_ref::() { + return Ok(CpuState { + program_counter: cpu.get_program_counter(), + accumulator: cpu.get_accumulator(), + carry: cpu.get_carry(), + stack_pointer: cpu.get_stack_pointer(), + cycle_count: cpu.get_cycle_count(), + }); + } else { + Err("CPU component is not of type Intel 4004".to_string()) } + } else { + Err("CPU component not found".to_string()) } - - Err("CPU component not found".to_string()) } - pub fn reset_system(&mut self) { println!("Resetting MCS-4 system..."); - if let Some(cpu_component) = self.components.get("cpu") { - if let Ok(mut cpu) = cpu_component.lock() { - if let Some(cpu_ref) = cpu.as_any_mut().downcast_mut::() { - cpu_ref.reset(); - } + if let Some(cpu_component) = self.components.get_mut("cpu") { + if let Some(cpu) = cpu_component.as_any_mut().downcast_mut::() { + cpu.reset(); } } } - pub fn get_system_info(&self) -> SystemInfo { SystemInfo { cpu_speed: 750_000.0,