Reset instead of setting program counter
This commit is contained in:
parent
3c85ed2b00
commit
01117af411
3 changed files with 6 additions and 22 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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<String, Arc<Mutex<dyn Component>>>,
|
||||
|
|
@ -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::<Intel4004>() {
|
||||
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<CpuState, String> {
|
||||
if let Some(cpu_component) = self.components.get("cpu") {
|
||||
if let Some(cpu) = cpu_component.as_any().downcast_ref::<Intel4004>() {
|
||||
|
|
@ -257,6 +244,7 @@ impl Component for IntelMcs4 {
|
|||
|
||||
fn stop(&mut self) {
|
||||
self.stop();
|
||||
|
||||
}
|
||||
|
||||
fn is_running(&self) -> bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue