slu4_minimal/src/computer.rs
Trevor Merritt 533b519d15 Initial commit
Start of the project
2025-06-12 14:31:53 -04:00

53 lines
1.1 KiB
Rust

use std::time::{Duration, Instant};
use log::debug;
use crate::adder::Adder;
use crate::memory::Memory;
use crate::register::Register;
pub struct Computer {
last_updated: Instant,
current_input: String,
adder: Adder,
register: Register,
memory: Memory
}
impl Computer {
pub fn new() -> Self {
debug!("Created new CPU");
Computer {
last_updated: Instant::now(),
current_input: String::from(""),
adder: Adder::default(),
register: Register::default(),
memory: Memory::default()
}
}
pub fn reset(mut self) {
self = Computer::new();
}
pub fn update(&mut self) {
let now = Instant::now();
if now.duration_since(self.last_updated).as_millis() > 10 {
debug!("Time to update cpu.");
self.last_updated = now;
// Rising Edge
// High State
// Falling Edge
// Low State
}
}
pub fn input(&mut self, c: char) {
self.current_input = format!("{}{}", self.current_input, c);
}
}