Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ppu-viewer #339

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
[build]: https://github.com/lukexor/tetanes/actions/workflows/ci.yml
[doc status]: https://img.shields.io/docsrs/tetanes?style=plastic
[docs]: https://docs.rs/tetanes/
[codecov]: https://codecov.io/gh/lukexor/tetanes/branch/main/graph/badge.svg?token=AMQJJ7B0LS
[coverage]: https://codecov.io/gh/lukexor/tetanes
[latest version]: https://img.shields.io/crates/v/tetanes?style=plastic
[crates.io]: https://crates.io/crates/tetanes
[downloads]: https://img.shields.io/crates/d/tetanes?style=plastic
Expand Down Expand Up @@ -153,7 +151,8 @@ This will install the latest released version of the `TetaNES` binary to your
`cargo` bin directory located at either `$HOME/.cargo/bin/` on a Unix-like
platform or `%USERPROFILE%\.cargo\bin` on Windows.

Alternatively, if you have [`cargo binstall`](https://crates.io/crates/cargo-binstall/) installed:
Alternatively, if you have [`cargo binstall`](https://crates.io/crates/cargo-binstall/)
installed:

```sh
cargo binstall tetanes
Expand Down
16 changes: 16 additions & 0 deletions tetanes-core/src/control_deck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
cart::{self, Cart},
common::{Clock, NesRegion, Regional, Reset, ResetKind, Sram},
cpu::Cpu,
debug::Debugger,
fs,
genie::{self, GenieCode},
input::{FourPlayer, Joypad, Player},
Expand Down Expand Up @@ -423,6 +424,21 @@ impl ControlDeck {
self.cpu.bus.ppu.emulate_warmup = enabled;
}

/// Adds a debugger callback to be executed any time the debugger conditions
/// match.
pub fn add_debugger(&mut self, debugger: Debugger) {
match debugger {
Debugger::Ppu(debugger) => self.cpu.bus.ppu.debugger = Some(debugger),
}
}

/// Removes a debugger callback.
pub fn remove_debugger(&mut self, debugger: Debugger) {
match debugger {
Debugger::Ppu(_) => self.cpu.bus.ppu.debugger = None,
}
}

/// Returns the name of the currently loaded ROM [`Cart`]. Returns `None` if no ROM is loaded.
#[inline]
#[must_use]
Expand Down
2 changes: 2 additions & 0 deletions tetanes-core/src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ impl Cpu {
if cpu.bus.ppu.bus.chr_rom.is_empty() {
cpu.bus.ppu.bus.chr_rom = std::mem::take(&mut self.bus.ppu.bus.chr_rom);
};
// Doesn't make sense to load a debugger from a previous state
cpu.bus.ppu.debugger = std::mem::take(&mut self.bus.ppu.debugger);
*self = cpu;
}

Expand Down
37 changes: 37 additions & 0 deletions tetanes-core/src/debug.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::ppu::Ppu;
use std::sync::Arc;

#[derive(Debug, Clone, PartialEq)]
#[must_use]
pub enum Debugger {
Ppu(PpuDebugger),
}

impl From<PpuDebugger> for Debugger {
fn from(debugger: PpuDebugger) -> Self {
Self::Ppu(debugger)
}
}

#[derive(Clone)]
#[must_use]
pub struct PpuDebugger {
pub cycle: u32,
pub scanline: u32,
pub callback: Arc<dyn Fn(Ppu) + Send + Sync + 'static>,
}

impl PartialEq for PpuDebugger {
fn eq(&self, other: &Self) -> bool {
self.cycle == other.cycle && self.scanline == other.scanline
}
}

impl std::fmt::Debug for PpuDebugger {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("PpuDebugger")
.field("cycle", &self.cycle)
.field("scanline", &self.scanline)
.finish_non_exhaustive()
}
}
1 change: 1 addition & 0 deletions tetanes-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod action;
pub mod apu;
pub mod bus;
pub mod cart;
pub mod debug;
pub mod fs;
pub mod time;
#[macro_use]
Expand Down
Loading
Loading