Fixed borrow issues
This commit is contained in:
parent
f66f4c5d6c
commit
974fa25a3c
6 changed files with 34 additions and 39 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
|
|
|||
|
|
@ -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<u8> {
|
||||
|
|
@ -74,7 +75,7 @@ fn compile_fibonacci_program() -> Vec<u8> {
|
|||
]
|
||||
}
|
||||
|
||||
fn run_fibonacci_demo(mcs4: &mut IntelMcs4) {
|
||||
fn run_fibonacci_demo(mcs4: IntelMcs4) {
|
||||
let start_time = Instant::now();
|
||||
|
||||
println!("Cycle | Fibonacci | Accumulator | PC");
|
||||
|
|
|
|||
|
|
@ -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<String, Arc<Mutex<dyn Component>>>,
|
||||
|
|
@ -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::<Intel4004>() {
|
||||
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::<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 Ok(cpu) = cpu_component.lock() {
|
||||
if let Some(cpu_ref) = cpu.as_any().downcast_ref::<Intel4004>() {
|
||||
if let Some(cpu) = cpu_component.as_any().downcast_ref::<Intel4004>() {
|
||||
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(),
|
||||
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())
|
||||
}
|
||||
|
||||
}
|
||||
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::<Intel4004>() {
|
||||
cpu_ref.reset();
|
||||
if let Some(cpu_component) = self.components.get_mut("cpu") {
|
||||
if let Some(cpu) = cpu_component.as_any_mut().downcast_mut::<Intel4004>() {
|
||||
cpu.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_system_info(&self) -> SystemInfo {
|
||||
SystemInfo {
|
||||
cpu_speed: 750_000.0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue