From 01117af4113157c6de79c0e766b3bea897ebb170 Mon Sep 17 00:00:00 2001 From: Jan-Peter von Hunnius Date: Wed, 24 Sep 2025 17:39:11 +0200 Subject: [PATCH] Reset instead of setting program counter --- src/components/cpu/intel_4004.rs | 8 ++++---- src/main.rs | 6 +----- src/systems/intel_mcs_4.rs | 14 +------------- 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/components/cpu/intel_4004.rs b/src/components/cpu/intel_4004.rs index 87dc456..468e130 100644 --- a/src/components/cpu/intel_4004.rs +++ b/src/components/cpu/intel_4004.rs @@ -193,7 +193,7 @@ impl Intel4004 { self.program_counter.inc(); // Every 10 cycles, "calculate" next Fibonacci number - if self.cycle_count % 10 == 0 { + if self.cycle_count % 1000 == 0 { // Simple Fibonacci simulation let fib_index = (self.cycle_count / 10) as u8; self.accumulator = self.simulate_fibonacci(fib_index); @@ -207,12 +207,12 @@ impl Intel4004 { _ => { let mut a = 0; let mut b = 1; - for _ in 2..=n { - let next = a + b; + for _ in 2..=n%32 { + let next: u32 = a + b; a = b; b = next; } - b % 16 // Keep it in 4-bit range for demo + (b % 16) as u8 // Keep it in 4-bit range for demo } } } diff --git a/src/main.rs b/src/main.rs index 90bb9be..f14a300 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,11 +40,7 @@ fn main() { return; } - // Set starting program counter - if let Err(e) = mcs4.set_cpu_program_counter(U12::from(0x000)) { - eprintln!("Failed to set program counter: {}", e); - return; - } + mcs4.reset_system(); // Display system information let info = mcs4.get_system_info(); diff --git a/src/systems/intel_mcs_4.rs b/src/systems/intel_mcs_4.rs index 3215ccb..68e9102 100644 --- a/src/systems/intel_mcs_4.rs +++ b/src/systems/intel_mcs_4.rs @@ -9,7 +9,6 @@ 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>>, @@ -147,18 +146,6 @@ impl IntelMcs4 { Err("RAM component not found".to_string()) } - 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()) - } - } pub fn get_cpu_state(&self) -> Result { if let Some(cpu_component) = self.components.get("cpu") { if let Some(cpu) = cpu_component.as_any().downcast_ref::() { @@ -257,6 +244,7 @@ impl Component for IntelMcs4 { fn stop(&mut self) { self.stop(); + } fn is_running(&self) -> bool {