rgy/
debug.rs

1use crate::cpu::Cpu;
2use crate::device::IoHandler;
3use crate::mmu::{MemRead, MemWrite, Mmu};
4
5/// Debugger interface.
6///
7/// The users of this library can implement this interface to inspect the state of the emulator.
8pub trait Debugger: IoHandler {
9    /// The function is called on the initialization phase.
10    fn init(&mut self, mmu: &Mmu);
11
12    /// The function is called right before the emulator starts executing an instruction. Deprecated.
13    fn take_cpu_snapshot(&mut self, cpu: Cpu);
14
15    /// Decode an instruction.
16    fn on_decode(&mut self, mmu: &Mmu);
17
18    /// Check if the external signal is triggered. Deprecated.
19    fn check_signal(&mut self);
20}
21
22impl dyn Debugger {
23    /// Create an empty debugger.
24    pub fn empty() -> NullDebugger {
25        NullDebugger
26    }
27}
28
29/// Empty debugger which does nothing.
30pub struct NullDebugger;
31
32impl Debugger for NullDebugger {
33    fn init(&mut self, _: &Mmu) {}
34
35    fn take_cpu_snapshot(&mut self, _: Cpu) {}
36
37    fn on_decode(&mut self, _: &Mmu) {}
38
39    fn check_signal(&mut self) {}
40}
41
42impl IoHandler for NullDebugger {
43    fn on_read(&mut self, _: &Mmu, _: u16) -> MemRead {
44        MemRead::PassThrough
45    }
46
47    fn on_write(&mut self, _: &Mmu, _: u16, _: u8) -> MemWrite {
48        MemWrite::PassThrough
49    }
50}