| 1 | //! Tool windows docked around the editor. |
| 2 | |
| 3 | mod build; |
| 4 | mod disasm; |
| 5 | mod interrupts; |
| 6 | mod memory; |
| 7 | mod ports; |
| 8 | mod project; |
| 9 | mod registers; |
| 10 | mod serial; |
| 11 | mod symbols; |
| 12 | mod timers; |
| 13 | |
| 14 | use bench51_core::session::Session; |
| 15 | use eframe::egui::{self, Ui}; |
| 16 | |
| 17 | use crate::editor; |
| 18 | use crate::layout::Pane; |
| 19 | use crate::state::State; |
| 20 | use crate::widgets; |
| 21 | |
| 22 | pub 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. |
| 49 | fn 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. |
| 58 | pub 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. |
| 66 | pub fn sfr_changed(s: &Session, addr: u8) -> bool { |
| 67 | s.sim.sfr(addr) != s.prev_sfr[(addr & 0x7F) as usize] |
| 68 | } |