evolve egui interface
move more control back up to the ComputerManager
This commit is contained in:
@@ -3,6 +3,7 @@ use std::thread;
|
||||
use std::thread::{sleep, JoinHandle, Thread};
|
||||
use std::time::{Duration, Instant};
|
||||
use crate::chip8::computer::Chip8Computer;
|
||||
use crate::chip8::cpu_states::Chip8CpuStates;
|
||||
use crate::chip8::cpu_states::Chip8CpuStates::WaitingForInstruction;
|
||||
|
||||
pub enum ManagerDumpables {
|
||||
@@ -13,10 +14,10 @@ pub enum ManagerDumpables {
|
||||
|
||||
|
||||
pub struct Chip8ComputerManager {
|
||||
pub core_should_run: bool,
|
||||
pub one_step: bool,
|
||||
pub core_cycle_timer: bool,
|
||||
pub core_last_cycle_start: Instant,
|
||||
core_should_run: bool,
|
||||
one_step: bool,
|
||||
core_cycle_timer: bool,
|
||||
core_last_cycle_start: Instant,
|
||||
computer: Chip8Computer
|
||||
}
|
||||
|
||||
@@ -41,11 +42,10 @@ impl Chip8ComputerManager {
|
||||
let core_handle = thread::spawn(move || {
|
||||
loop {
|
||||
let start_time = Instant::now();
|
||||
println!("Core Thread starting at {start_time:?}");
|
||||
|
||||
// println!("Core Thread starting at {start_time:?}");
|
||||
|
||||
let sleep_time = Instant::now().duration_since(start_time).as_millis();
|
||||
println!("Core Thread sleeping for {sleep_time}ms");
|
||||
// println!("Core Thread sleeping for {sleep_time}ms");
|
||||
sleep(Duration::from_millis((16 - sleep_time) as u64));
|
||||
}
|
||||
});
|
||||
@@ -53,16 +53,16 @@ impl Chip8ComputerManager {
|
||||
Chip8ComputerManager::default()
|
||||
}
|
||||
|
||||
pub fn start(managed: &mut Chip8ComputerManager) {
|
||||
managed.core_should_run = true;
|
||||
pub fn start(&mut self) {
|
||||
self.core_should_run = true;
|
||||
}
|
||||
|
||||
pub fn stop(managed: &mut Chip8ComputerManager) {
|
||||
managed.core_should_run = false
|
||||
pub fn stop(&mut self) {
|
||||
self.core_should_run = false
|
||||
}
|
||||
|
||||
pub fn step(managed: &mut Chip8ComputerManager) {
|
||||
managed.one_step = true;
|
||||
pub fn step(&mut self) {
|
||||
self.one_step = true;
|
||||
}
|
||||
|
||||
pub fn state(&mut self) -> &Chip8Computer {
|
||||
@@ -70,11 +70,16 @@ impl Chip8ComputerManager {
|
||||
}
|
||||
|
||||
pub fn tick( &mut self) {
|
||||
println!("STARTING TICK");
|
||||
if self.one_step | self.core_should_run {
|
||||
self.core_last_cycle_start = Instant::now();
|
||||
self.computer.step_system();
|
||||
println!("SYSTEM STEP");
|
||||
// println!("STARTING TICK");
|
||||
if self.one_step | self.core_should_run {
|
||||
match self.computer.state {
|
||||
WaitingForInstruction => {
|
||||
self.core_last_cycle_start = Instant::now();
|
||||
self.computer.step_system();
|
||||
println!("SYSTEM STEP");
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
};
|
||||
if self.one_step {
|
||||
println!("SYSTEM HALTED AFTER 1 STEP");
|
||||
@@ -86,6 +91,9 @@ impl Chip8ComputerManager {
|
||||
|
||||
pub fn press_key(&mut self, key_index: u8) {
|
||||
self.computer.keypad.push_key(key_index);
|
||||
if matches!(self.computer.state, Chip8CpuStates::WaitingForKey) {
|
||||
self.computer.state = WaitingForInstruction
|
||||
}
|
||||
}
|
||||
pub fn release_key(&mut self, key_index: u8) {
|
||||
self.computer.keypad.release_key(key_index);
|
||||
|
||||
Reference in New Issue
Block a user