Skip to content

Commit

Permalink
Add basic filesystem debug view
Browse files Browse the repository at this point in the history
  • Loading branch information
kelpsyberry committed Apr 4, 2024
1 parent 7641f2d commit d61a942
Show file tree
Hide file tree
Showing 12 changed files with 1,069 additions and 215 deletions.
510 changes: 417 additions & 93 deletions frontend/desktop/src/debug_views.rs

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions frontend/desktop/src/debug_views/audio_channels.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{
common::regs::{bitfield, BitfieldCommand},
BaseView, FrameDataSlot, InstanceableEmuState, InstanceableView, Messages, RefreshType, View,
BaseView, FrameDataSlot, FrameView, FrameViewMessages, InstanceableFrameViewEmuState,
InstanceableView, RefreshType,
};
use crate::ui::window::Window;
use dust_core::{
Expand Down Expand Up @@ -84,7 +85,7 @@ pub struct EmuState {
channel_index: ChannelIndex,
}

impl super::EmuState for EmuState {
impl super::FrameViewEmuState for EmuState {
type InitData = ChannelIndex;
type Message = ChannelIndex;
type FrameData = (ChannelData, Vec<i16>);
Expand Down Expand Up @@ -129,7 +130,7 @@ impl super::EmuState for EmuState {
}
}

impl InstanceableEmuState for EmuState {
impl InstanceableFrameViewEmuState for EmuState {
const ADDITION_TRIGGERS_REFRESH: bool = false;
const DELETION_TRIGGERS_REFRESH: bool = true;
fn visibility_change_triggers_refresh(visible: bool) -> bool {
Expand Down Expand Up @@ -168,7 +169,7 @@ impl BaseView for AudioChannels {
const MENU_NAME: &'static str = "Audio channels";
}

impl View for AudioChannels {
impl FrameView for AudioChannels {
type EmuState = EmuState;

fn new(_window: &mut Window) -> Self {
Expand All @@ -186,13 +187,13 @@ impl View for AudioChannels {
}
}

fn emu_state(&self) -> <Self::EmuState as super::EmuState>::InitData {
fn emu_state(&self) -> <Self::EmuState as super::FrameViewEmuState>::InitData {
self.cur_channel
}

fn update_from_frame_data(
&mut self,
frame_data: &<Self::EmuState as super::EmuState>::FrameData,
frame_data: &<Self::EmuState as super::FrameViewEmuState>::FrameData,
_window: &mut Window,
) {
self.data.channel = frame_data.0.channel;
Expand All @@ -201,7 +202,12 @@ impl View for AudioChannels {
self.data.control = frame_data.0.control;
}

fn draw(&mut self, ui: &imgui::Ui, window: &mut Window, mut messages: impl Messages<Self>) {
fn draw(
&mut self,
ui: &imgui::Ui,
window: &mut Window,
mut messages: impl FrameViewMessages<Self>,
) {
let item_spacing = style!(ui, item_spacing);

let sliders_width = 0.5 * (ui.content_region_avail()[0] - item_spacing[0]);
Expand Down
21 changes: 13 additions & 8 deletions frontend/desktop/src/debug_views/bg_maps_2d.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
common::rgb5_to_rgba8, BaseView, FrameDataSlot, InstanceableEmuState, InstanceableView,
Messages, View,
common::rgb5_to_rgba8, BaseView, FrameDataSlot, FrameView, FrameViewMessages,
InstanceableFrameViewEmuState, InstanceableView,
};
use crate::ui::{
utils::{add2, combo_value, scale_to_fit, sub2s},
Expand Down Expand Up @@ -100,7 +100,7 @@ pub struct EmuState {
selection: Selection,
}

impl super::EmuState for EmuState {
impl super::FrameViewEmuState for EmuState {
type InitData = Selection;
type Message = Selection;
type FrameData = BgMapData;
Expand Down Expand Up @@ -375,7 +375,7 @@ impl super::EmuState for EmuState {
}
}

impl InstanceableEmuState for EmuState {}
impl InstanceableFrameViewEmuState for EmuState {}

pub struct BgMaps2d {
cur_selection: Selection,
Expand All @@ -391,7 +391,7 @@ impl BaseView for BgMaps2d {
const MENU_NAME: &'static str = "2D BG maps";
}

impl View for BgMaps2d {
impl FrameView for BgMaps2d {
type EmuState = EmuState;

fn new(window: &mut Window) -> Self {
Expand Down Expand Up @@ -429,13 +429,13 @@ impl View for BgMaps2d {
window.imgui_gfx.remove_texture(self.tex_id);
}

fn emu_state(&self) -> <Self::EmuState as super::EmuState>::InitData {
fn emu_state(&self) -> <Self::EmuState as super::FrameViewEmuState>::InitData {
self.cur_selection
}

fn update_from_frame_data(
&mut self,
frame_data: &<Self::EmuState as super::EmuState>::FrameData,
frame_data: &<Self::EmuState as super::FrameViewEmuState>::FrameData,
_window: &mut Window,
) {
self.data.bgs = frame_data.bgs;
Expand All @@ -456,7 +456,12 @@ impl View for BgMaps2d {
self.data.palette[..palette_len].copy_from_slice(&frame_data.palette[..palette_len]);
}

fn draw(&mut self, ui: &imgui::Ui, window: &mut Window, mut messages: impl Messages<Self>) {
fn draw(
&mut self,
ui: &imgui::Ui,
window: &mut Window,
mut messages: impl FrameViewMessages<Self>,
) {
if ui.is_window_hovered_with_flags(WindowHoveredFlags::ROOT_AND_CHILD_WINDOWS)
&& ui.is_mouse_clicked(MouseButton::Right)
{
Expand Down
20 changes: 13 additions & 7 deletions frontend/desktop/src/debug_views/cpu_disasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use super::{
disasm::{Addr, DisassemblyView},
RangeInclusive,
},
BaseView, FrameDataSlot, InstanceableEmuState, InstanceableView, Messages, View,
BaseView, FrameDataSlot, FrameView, FrameViewMessages, InstanceableFrameViewEmuState,
InstanceableView,
};
use crate::ui::window::Window;
use dust_core::{
Expand All @@ -28,7 +29,7 @@ pub struct EmuState<const ARM9: bool> {
thumb: bool,
}

impl<const ARM9: bool> super::EmuState for EmuState<ARM9> {
impl<const ARM9: bool> super::FrameViewEmuState for EmuState<ARM9> {
type InitData = RangeInclusive<Addr>;
type Message = (RangeInclusive<Addr>, bool);
type FrameData = DisassemblyResults;
Expand Down Expand Up @@ -87,7 +88,7 @@ impl<const ARM9: bool> super::EmuState for EmuState<ARM9> {
}
}

impl<const ARM9: bool> InstanceableEmuState for EmuState<ARM9> {}
impl<const ARM9: bool> InstanceableFrameViewEmuState for EmuState<ARM9> {}

pub struct CpuDisasm<const ARM9: bool> {
view: DisassemblyView,
Expand All @@ -105,7 +106,7 @@ impl<const ARM9: bool> BaseView for CpuDisasm<ARM9> {
};
}

impl<const ARM9: bool> View for CpuDisasm<ARM9> {
impl<const ARM9: bool> FrameView for CpuDisasm<ARM9> {
type EmuState = EmuState<ARM9>;

fn new(_window: &mut Window) -> Self {
Expand All @@ -127,13 +128,13 @@ impl<const ARM9: bool> View for CpuDisasm<ARM9> {
}
}

fn emu_state(&self) -> <Self::EmuState as super::EmuState>::InitData {
fn emu_state(&self) -> <Self::EmuState as super::FrameViewEmuState>::InitData {
self.last_visible_addrs
}

fn update_from_frame_data(
&mut self,
frame_data: &<Self::EmuState as super::EmuState>::FrameData,
frame_data: &<Self::EmuState as super::FrameViewEmuState>::FrameData,
_window: &mut Window,
) {
self.disasm_results.visible_addrs = frame_data.visible_addrs;
Expand All @@ -146,7 +147,12 @@ impl<const ARM9: bool> View for CpuDisasm<ARM9> {
.extend_from_slice(&frame_data.instrs);
}

fn draw(&mut self, ui: &imgui::Ui, window: &mut Window, mut messages: impl Messages<Self>) {
fn draw(
&mut self,
ui: &imgui::Ui,
window: &mut Window,
mut messages: impl FrameViewMessages<Self>,
) {
let mut emu_state_changed = false;

let _mono_font = ui.push_font(window.imgui.mono_font);
Expand Down
22 changes: 15 additions & 7 deletions frontend/desktop/src/debug_views/cpu_memory.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use super::{BaseView, FrameDataSlot, InstanceableEmuState, InstanceableView, Messages, View};
use super::{
BaseView, FrameDataSlot, FrameView, FrameViewMessages, InstanceableFrameViewEmuState,
InstanceableView,
};
use crate::ui::window::Window;
use dust_core::{
cpu::{self, arm7, arm9, bus},
Expand All @@ -20,7 +23,7 @@ pub struct EmuState<const ARM9: bool> {
visible_addrs: RangeInclusive<Addr>,
}

impl<const ARM9: bool> super::EmuState for EmuState<ARM9> {
impl<const ARM9: bool> super::FrameViewEmuState for EmuState<ARM9> {
type InitData = RangeInclusive<Addr>;
type Message = Message;
type FrameData = MemContents;
Expand Down Expand Up @@ -70,7 +73,7 @@ impl<const ARM9: bool> super::EmuState for EmuState<ARM9> {
}
}

impl<const ARM9: bool> InstanceableEmuState for EmuState<ARM9> {}
impl<const ARM9: bool> InstanceableFrameViewEmuState for EmuState<ARM9> {}

pub struct CpuMemory<const ARM9: bool> {
editor: MemoryEditor,
Expand All @@ -94,7 +97,7 @@ impl<const ARM9: bool> BaseView for CpuMemory<ARM9> {
const MENU_NAME: &'static str = if ARM9 { "ARM9 memory" } else { "ARM7 memory" };
}

impl<const ARM9: bool> View for CpuMemory<ARM9> {
impl<const ARM9: bool> FrameView for CpuMemory<ARM9> {
type EmuState = EmuState<ARM9>;

fn new(_window: &mut Window) -> Self {
Expand All @@ -111,21 +114,26 @@ impl<const ARM9: bool> View for CpuMemory<ARM9> {
}
}

fn emu_state(&self) -> <Self::EmuState as super::EmuState>::InitData {
fn emu_state(&self) -> <Self::EmuState as super::FrameViewEmuState>::InitData {
self.last_visible_addrs
}

fn update_from_frame_data(
&mut self,
frame_data: &<Self::EmuState as super::EmuState>::FrameData,
frame_data: &<Self::EmuState as super::FrameViewEmuState>::FrameData,
_window: &mut Window,
) {
self.mem_contents.data.clear();
self.mem_contents.data.extend_from_slice(&frame_data.data);
self.mem_contents.visible_addrs = frame_data.visible_addrs;
}

fn draw(&mut self, ui: &imgui::Ui, window: &mut Window, mut messages: impl Messages<Self>) {
fn draw(
&mut self,
ui: &imgui::Ui,
window: &mut Window,
mut messages: impl FrameViewMessages<Self>,
) {
let _mono_font = ui.push_font(window.imgui.mono_font);

self.editor.handle_options_right_click(ui);
Expand Down
17 changes: 11 additions & 6 deletions frontend/desktop/src/debug_views/cpu_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{
regs::{bitfield, regs_32, regs_32_default_label, BitfieldCommand},
separator_with_width,
},
BaseView, FrameDataSlot, Messages, SingletonView, View,
BaseView, FrameDataSlot, FrameView, FrameViewMessages, SingletonView,
};
use crate::ui::{utils::combo_value, window::Window};
use dust_core::{
Expand All @@ -26,7 +26,7 @@ pub use bounded::*;

pub struct EmuState<const ARM9: bool>;

impl<const ARM9: bool> super::EmuState for EmuState<ARM9> {
impl<const ARM9: bool> super::FrameViewEmuState for EmuState<ARM9> {
type InitData = ();
type Message = (Bank, RegIndex, u32);
type FrameData = (Regs, Psr);
Expand Down Expand Up @@ -117,7 +117,7 @@ impl<const ARM9: bool> BaseView for CpuState<ARM9> {
const MENU_NAME: &'static str = if ARM9 { "ARM9 state" } else { "ARM7 state" };
}

impl<const ARM9: bool> View for CpuState<ARM9> {
impl<const ARM9: bool> FrameView for CpuState<ARM9> {
type EmuState = EmuState<ARM9>;

fn new(_window: &mut Window) -> Self {
Expand All @@ -127,17 +127,22 @@ impl<const ARM9: bool> View for CpuState<ARM9> {
}
}

fn emu_state(&self) -> <Self::EmuState as super::EmuState>::InitData {}
fn emu_state(&self) -> <Self::EmuState as super::FrameViewEmuState>::InitData {}

fn update_from_frame_data(
&mut self,
frame_data: &<Self::EmuState as super::EmuState>::FrameData,
frame_data: &<Self::EmuState as super::FrameViewEmuState>::FrameData,
_window: &mut Window,
) {
self.reg_values = Some(frame_data.clone());
}

fn draw(&mut self, ui: &imgui::Ui, window: &mut Window, mut messages: impl Messages<Self>) {
fn draw(
&mut self,
ui: &imgui::Ui,
window: &mut Window,
mut messages: impl FrameViewMessages<Self>,
) {
if let Some((reg_values, cpsr)) = self.reg_values.as_mut() {
let _mono_font_token = ui.push_font(window.imgui.mono_font);
let _item_spacing =
Expand Down
Loading

0 comments on commit d61a942

Please sign in to comment.