Skip to main content

rustynes_core/
debug.rs

1//! Read-only debug snapshots for the frontend's egui debugger UI.
2//!
3//! Plain-data structs the UI can hold for the lifetime of a frame
4//! without borrowing into the emulator. The accessors on [`crate::Nes`]
5//! produce these once per visible frame at 60 Hz; a few KiB of cloning
6//! is cheap compared to actually running a frame.
7//!
8//! Determinism contract: opening the debugger must NOT alter the
9//! emulator's deterministic state. Every method in this module is
10//! read-only.
11
12pub use rustynes_mappers::MapperDebugInfo;
13
14/// Snapshot of CPU register file.
15#[derive(Debug, Clone)]
16pub struct CpuDebugView {
17    /// Accumulator.
18    pub a: u8,
19    /// X index register.
20    pub x: u8,
21    /// Y index register.
22    pub y: u8,
23    /// Stack pointer.
24    pub s: u8,
25    /// Program counter.
26    pub pc: u16,
27    /// Raw status flags.
28    pub p: u8,
29    /// `true` when the CPU is jammed (illegal halt opcode).
30    pub jammed: bool,
31    /// Cumulative CPU cycle count.
32    pub cycles: u64,
33}
34
35/// Snapshot of PPU state.
36#[derive(Debug, Clone)]
37pub struct PpuDebugView {
38    /// Current dot (0..=340).
39    pub dot: u16,
40    /// Current scanline.
41    pub scanline: i16,
42    /// Current frame count.
43    pub frame: u64,
44    /// PPUCTRL ($2000) snapshot.
45    pub ctrl: u8,
46    /// PPUMASK ($2001) snapshot.
47    pub mask: u8,
48    /// PPUSTATUS ($2002) snapshot.
49    pub status: u8,
50    /// OAMADDR ($2003) snapshot.
51    pub oam_addr: u8,
52    /// Loopy `v` register.
53    pub v: u16,
54    /// Loopy `t` register.
55    pub t: u16,
56    /// Fine X scroll.
57    pub fine_x: u8,
58    /// Write toggle (`w`).
59    pub w_toggle: bool,
60    /// 8x16 sprites enabled.
61    pub sprite_size_16: bool,
62    /// Background pattern table base (0 or 0x1000).
63    pub bg_pattern_base: u16,
64    /// Sprite pattern table base (0 or 0x1000).
65    pub sprite_pattern_base: u16,
66    /// NMI line currently asserted.
67    pub nmi_line: bool,
68}
69
70/// Snapshot of APU channel outputs and frame counter.
71#[derive(Debug, Clone)]
72pub struct ApuDebugView {
73    /// Pulse 1 raw output (0..=15).
74    pub pulse1: u8,
75    /// Pulse 2 raw output (0..=15).
76    pub pulse2: u8,
77    /// Triangle raw output (0..=15).
78    pub triangle: u8,
79    /// Noise raw output (0..=15).
80    pub noise: u8,
81    /// DMC output (0..=127).
82    pub dmc: u8,
83    /// v2.1.6 "Expansion Audio" — the most recent RAW on-cart expansion-audio
84    /// sample (VRC6/VRC7/FDS/MMC5/Namco 163/Sunsoft 5B), pre-UI-gain. `0.0`
85    /// when the board has no expansion audio. A read-only display tap for the
86    /// frontend Audio Mixer expansion oscilloscope / VU meter; sampling it does
87    /// not perturb the deterministic mix.
88    pub external: f32,
89    /// Frame counter IRQ pending.
90    pub frame_irq: bool,
91    /// DMC IRQ pending.
92    pub dmc_irq: bool,
93}
94
95/// Snapshot of mapper state — alias for [`rustynes_mappers::MapperDebugInfo`].
96pub type MapperDebugView = MapperDebugInfo;