Files
damn_simple_architecture/src/emulator/ui/stack_inspector.rs
T

71 lines
2.0 KiB
Rust

use crate::{
common::instructions::Register,
emulator::{system::model::State, ui::interface::Component},
};
pub struct StackInspector {
visible: bool,
}
impl Default for StackInspector {
fn default() -> Self {
Self::new()
}
}
impl StackInspector {
#[must_use]
pub const fn new() -> Self {
Self { visible: false }
}
}
impl Component for StackInspector {
fn visible(&mut self) -> &mut bool {
&mut self.visible
}
fn name(&self) -> &'static str {
"Stack Inspector"
}
fn category(&self) -> super::interface::Category {
super::interface::Category::Memory
}
fn render(&mut self, state: &mut State, ui: &mut egui::Ui, _ctx: &egui::Context) {
ui.vertical(|ui| {
ui.heading("Stack Inspector");
egui::ScrollArea::vertical()
.id_salt("stack_inspector_scroll")
.show(ui, |ui| {
egui::Grid::new("stack_grid")
.num_columns(2)
.spacing([40.0, 4.0])
.striped(true)
.show(ui, |ui| {
ui.label("Address");
ui.label("Value");
ui.end_row();
for (i, value) in (0u32..).zip(state.stack_view.iter().take(32)) {
ui.label(format!(
"{} [{}]",
i,
state.reg_file.get(Register::Spr) - i * 4
));
ui.label(format!("0x{value:08X} ({value})"));
ui.end_row();
}
if state.stack_view.is_empty() {
ui.label("(empty)");
ui.label("-");
ui.end_row();
}
});
});
});
}
}