Krolyxon
Commit 4a1855a

Branches

Tags

Refs →

bench51cratesbench51-guisrcpanesmod.rs

68 lines · 2.2 KB · Rust

1//! Tool windows docked around the editor.
2
3mod build;
4mod disasm;
5mod interrupts;
6mod memory;
7mod ports;
8mod project;
9mod registers;
10mod serial;
11mod symbols;
12mod timers;
13
14use bench51_core::session::Session;
15use eframe::egui::{self, Ui};
16
17use crate::editor;
18use crate::layout::Pane;
19use crate::state::State;
20use crate::widgets;
21
22pub fn show(pane: Pane, ui: &mut Ui, st: &mut State) {
23 if pane == Pane::Editor {
24 editor::show(ui, st);
25 return;
26 }
27 egui::Frame::NONE
28 .inner_margin(egui::Margin::symmetric(14, 10))
29 .show(ui, |ui| {
30 ui.set_min_size(ui.available_size());
31 match pane {
32 Pane::Project => project::show(ui, st),
33 Pane::Build => build::show(ui, st),
34 Pane::Registers => with_session(ui, st, registers::show),
35 Pane::Memory => memory::show(ui, st),
36 Pane::Disassembly => disasm::show(ui, st),
37 Pane::Symbols => symbols::show(ui, st),
38 Pane::Serial => serial::show(ui, st),
39 Pane::Ports => with_session(ui, st, ports::show),
40 Pane::Timers => with_session(ui, st, timers::show),
41 Pane::Interrupts => with_session(ui, st, interrupts::show),
42 Pane::Editor => unreachable!(),
43 }
44 });
45}
46
47/// Runs `f` with the active document's session, or shows why there is
48/// nothing to inspect yet.
49fn with_session(ui: &mut Ui, st: &mut State, f: fn(&mut Ui, &mut Session)) {
50 match st.docs.get_mut(st.active) {
51 Some(doc) if doc.session.build.is_some() => f(ui, &mut doc.session),
52 Some(_) => widgets::empty_state(ui, "Not built", "Press F7 to assemble."),
53 None => widgets::empty_state(ui, "No program", "Open or create a source file."),
54 }
55}
56
57/// Whether bit `mask` of SFR `addr` is set, and a click toggles it.
58pub fn sfr_chip(ui: &mut Ui, s: &mut Session, name: &str, addr: u8, mask: u8) {
59 let v = s.sim.sfr(addr);
60 if widgets::bit_chip(ui, name, v & mask != 0).clicked() {
61 s.sim.set_sfr(addr, v ^ mask);
62 }
63}
64
65/// An SFR value differs from the snapshot taken before the last step.
66pub fn sfr_changed(s: &Session, addr: u8) -> bool {
67 s.sim.sfr(addr) != s.prev_sfr[(addr & 0x7F) as usize]
68}