93 lines
3.4 KiB
Rust
93 lines
3.4 KiB
Rust
use common::prelude::Register;
|
|
use dsa_emulator::EmulatorHandle;
|
|
use dsa_emulator::processor::RunningState;
|
|
use eframe::epaint::Color32;
|
|
use zxq5_egui::buttons::PaddedWidget;
|
|
use crate::ui::ui_helpers::StateWrapper;
|
|
|
|
pub struct Controller {
|
|
emulator: EmulatorHandle,
|
|
}
|
|
|
|
impl Controller {
|
|
pub fn new(state: EmulatorHandle) -> Self {
|
|
Self {
|
|
emulator: state,
|
|
}
|
|
}
|
|
|
|
pub fn ui(&mut self, ui: &mut egui::Ui) {
|
|
|
|
self.emulator.request_update();
|
|
|
|
egui::Frame::new()
|
|
.inner_margin(10.0)
|
|
.show(ui, |ui| {
|
|
ui.horizontal(|ui| {
|
|
use RunningState::*;
|
|
let status = self.emulator.status();
|
|
|
|
match status {
|
|
Paused | Breakpoint(_) =>
|
|
if PaddedWidget::button("▶ Run").color(Color32::GREEN).ui(ui).clicked() {
|
|
self.emulator.request_resume()
|
|
}
|
|
Running | Halted =>
|
|
if PaddedWidget::button("⏸ Pause").color(Color32::YELLOW).ui(ui).clicked() {
|
|
self.emulator.request_pause()
|
|
}
|
|
Shutdown => {
|
|
ui.add_enabled_ui(false, |ui| {
|
|
PaddedWidget::button("▶ Run").color(Color32::GREEN).ui(ui);
|
|
});
|
|
}
|
|
}
|
|
|
|
PaddedWidget::indicator(StateWrapper(status)).ui(ui);
|
|
|
|
if PaddedWidget::button("⟳ Reset All").color(Color32::ORANGE).ui(ui).clicked() {
|
|
self.emulator.when_paused(|emu| emu.reset());
|
|
}
|
|
|
|
// Step
|
|
// if ui.button("Step").clicked() {
|
|
// state
|
|
// .cmd_sender
|
|
// .send(Command::Step(self.step_amount))
|
|
// .unwrap_or_else(|_| {
|
|
// state.error_log.push("Failed to send command".to_string());
|
|
// });
|
|
// }
|
|
|
|
// if ui
|
|
// .text_edit_singleline(&mut self.step_amount_input)
|
|
// .changed()
|
|
// {
|
|
// self.step_amount = if let Ok(amount) = self.step_amount_input.parse() {
|
|
// amount
|
|
// } else {
|
|
// state
|
|
// .error_log
|
|
// .push("Unable to parse step amount".to_string());
|
|
// 1
|
|
// }
|
|
// }
|
|
|
|
ui.separator();
|
|
|
|
let clock = self.emulator.clock();
|
|
PaddedWidget::label(format!("Clock: {clock}")).ui(ui);
|
|
|
|
let pcx = self.emulator.get_register(Register::Pcx);
|
|
PaddedWidget::label( format!("Pcx: 0x{pcx:08X}")).ui(ui);
|
|
|
|
let time = self.emulator.time().as_micros();
|
|
PaddedWidget::label( format!("Elapsed: {} micros", time)).ui(ui);
|
|
|
|
let mips = (clock as u128).checked_div(time).unwrap_or(0);
|
|
PaddedWidget::label(format!("Freq: {}MHz", mips)).ui(ui);
|
|
});
|
|
});
|
|
}
|
|
}
|