Skip to content

Commit

Permalink
Merge pull request #131 from sevonj/bsod
Browse files Browse the repository at this point in the history
bsod
  • Loading branch information
sevonj authored Apr 1, 2024
2 parents fec3617 + 7c6be89 commit 7c165b8
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct Config {
pub workdir: PathBuf,

// --- Emulator
pub emu_cpuspeedmul: FreqMagnitude,
pub emu_speed_mag: FreqMagnitude,
pub emu_speed: f32,

// --- Memory Explorer
Expand Down Expand Up @@ -50,7 +50,7 @@ impl Default for Config {
workdir: current_dir().unwrap(),

emu_speed: 10.,
emu_cpuspeedmul: FreqMagnitude::Hz,
emu_speed_mag: FreqMagnitude::Hz,

memview_visible: true,
memview_follow_pc: true,
Expand Down
35 changes: 21 additions & 14 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ pub(crate) mod cpuview;
pub(crate) mod graphicsview;
pub(crate) mod legacytermview;
mod emutoolbar;
mod emubsod;

use egui::{Align, Button, Color32, Context, DragValue, Frame, Layout, Modifiers, OpenUrl, RichText, TopBottomPanel, Ui};
use egui::{Align, Button, CentralPanel, Color32, Context, DragValue, Frame, Layout, Modifiers, OpenUrl, RichText, TopBottomPanel, Ui};
use crate::config::Config;
use crate::gui::emubsod::EmuBSODView;

#[derive(PartialEq)]
pub enum GuiMode {
Expand All @@ -37,7 +39,7 @@ impl Radix {
}
}

/// Same as above, but expects usize and only adds 16 bits worth of leading zeros.
/// Same as above, but expects usize and doesn't add leading zeros.
pub fn format_addr(&self, value: usize) -> String {
match self {
Radix::Bin => format!("{value:#b}"),
Expand Down Expand Up @@ -89,12 +91,12 @@ pub const SHORTCUT_DEBUG_GUI: egui::KeyboardShortcut =
egui::KeyboardShortcut::new(Modifiers::COMMAND.plus(Modifiers::ALT), egui::Key::D);

impl TitoApp {
pub fn gui_main(&mut self, ctx: &egui::Context) {
egui::CentralPanel::default().show(ctx, |ui| {
pub fn gui_main(&mut self, ctx: &Context) {
CentralPanel::default().show(ctx, |ui| {
self.consume_shortcuts(ctx, ui);

// Toolbar
egui::TopBottomPanel::top("toolbar")
TopBottomPanel::top("toolbar")
.exact_height(32.0)
.show(ctx, |ui| {
ui.with_layout(Layout::left_to_right(Align::Center), |ui| {
Expand All @@ -119,7 +121,7 @@ impl TitoApp {
});
});
// Bottom bar
egui::TopBottomPanel::bottom("bottombar")
TopBottomPanel::bottom("bottombar")
.exact_height(24.0)
.show(ctx, |ui| {
ui.with_layout(Layout::left_to_right(Align::Center), |ui| {
Expand All @@ -146,7 +148,7 @@ impl TitoApp {
});
});

egui::CentralPanel::default().show(ctx, |ui| {
CentralPanel::default().show(ctx, |ui| {
if self.guimode == GuiMode::Emulator {
self.emulator_panel(ctx, ui);
} else {
Expand Down Expand Up @@ -220,27 +222,27 @@ impl TitoApp {
.speed(0.1)
.clamp_range(1..=9999),
);
match self.config.emu_cpuspeedmul {
match self.config.emu_speed_mag {
crate::FreqMagnitude::Hz => ui.label("Hz"),
crate::FreqMagnitude::KHz => ui.label("KHz"),
crate::FreqMagnitude::MHz => ui.label("MHz"),
}
});
ui.with_layout(Layout::left_to_right(Align::TOP), |ui| {
if ui
.radio_value(&mut self.config.emu_cpuspeedmul, crate::FreqMagnitude::Hz, "Hz")
.radio_value(&mut self.config.emu_speed_mag, crate::FreqMagnitude::Hz, "Hz")
.clicked()
{
self.send_settings();
}
if ui
.radio_value(&mut self.config.emu_cpuspeedmul, crate::FreqMagnitude::KHz, "KHz")
.radio_value(&mut self.config.emu_speed_mag, crate::FreqMagnitude::KHz, "KHz")
.clicked()
{
self.send_settings();
}
if ui
.radio_value(&mut self.config.emu_cpuspeedmul, crate::FreqMagnitude::MHz, "MHz")
.radio_value(&mut self.config.emu_speed_mag, crate::FreqMagnitude::MHz, "MHz")
.clicked()
{
self.send_settings();
Expand Down Expand Up @@ -343,12 +345,17 @@ impl TitoApp {
}
}
pub fn emulator_panel(&mut self, ctx: &Context, _: &mut Ui) {
// BSOD
if self.emu_thread_crashed {
EmuBSODView::new().show(ctx);
return;
}

// Refresh cached regs and memory
let _ = self.tx_ctrl.send(CtrlMSG::GetState);
let _ = self.tx_ctrl.send(CtrlMSG::GetMem(self.memoryview.get_view_cache_range()));

egui::CentralPanel::default().show(ctx, |_| {

CentralPanel::default().show(ctx, |_| {
// Status Panel
egui::SidePanel::right("register_panel")
.frame(Frame::none())
Expand Down Expand Up @@ -376,7 +383,7 @@ impl TitoApp {
});

// Main Panel
egui::CentralPanel::default()
CentralPanel::default()
.frame(Frame::none())
.show(ctx, |ui| {
self.graphicsview.ui(ui, &mut self.config, &self.tx_ctrl);
Expand Down
48 changes: 48 additions & 0 deletions src/gui/emubsod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-FileCopyrightText: 2024 sevonj
//
// SPDX-License-Identifier: MPL-2.0

//! Emu-BSOD: Ideally no user will ever see this. Run tab will show this if emu thread crashes.
//!
use egui::{CentralPanel, FontFamily, RichText};
use egui::Color32;
use egui::Context;
use egui::Frame;

const COLOR_BG: Color32 = Color32::from_rgb(0x39, 0x3C, 0x51);
const COLOR_FG: Color32 = Color32::WHITE;

/// EmuBSODView is the GUI panel for registers.
pub(crate) struct EmuBSODView {}

impl EmuBSODView {
pub fn new() -> Self {
EmuBSODView {}
}
pub(crate) fn show(&mut self, ctx: &Context) {
let frame = Frame::none()
.fill(COLOR_BG);

CentralPanel::default()
.frame(frame)
.show(ctx, |ui| {
ui.vertical_centered(|ui| {
ui.add_space(128.0);
ui.label(
RichText::from(" titomachine \n")
.background_color(COLOR_FG)
.color(COLOR_BG)
.monospace()
);
ui.label(
RichText::from(
"Emulator thread has crashed. You can still save your work in the editor."
)
.color(COLOR_FG)
.monospace()
);
});
});
}
}
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub struct TitoApp {
#[serde(skip)] emu_playing: bool,
#[serde(skip)] emu_turbo: bool,
#[serde(skip)] emu_achieved_speed: f32,
#[serde(skip)] emu_thread_crashed: bool,

// GUI Panels
#[serde(skip)] editor: Editor,
Expand Down Expand Up @@ -110,6 +111,7 @@ impl Default for TitoApp {
emu_playing: false,
emu_achieved_speed: 0.,
emu_turbo: false,
emu_thread_crashed: false,

editor: Editor::default(),
graphicsview: GraphicsView::new(rx_devdisplay),
Expand Down Expand Up @@ -187,12 +189,12 @@ impl TitoApp {
}

fn send_settings(&mut self) {
let speed = match self.config.emu_cpuspeedmul {
let speed = match self.config.emu_speed_mag {
FreqMagnitude::Hz => self.config.emu_speed,
FreqMagnitude::KHz => self.config.emu_speed * 1000.,
FreqMagnitude::MHz => self.config.emu_speed * 1000000.,
};
let _ = self.tx_ctrl.send(CtrlMSG::SetRate(speed));
self.emu_thread_crashed = self.tx_ctrl.send(CtrlMSG::SetRate(speed)).is_err();
}

fn stop_emulation(&mut self) {
Expand Down

0 comments on commit 7c165b8

Please sign in to comment.