use bedrock_core::*; use std::time::Instant; macro_rules! yellow { () => { eprint!("\x1b[33m") };} macro_rules! normal { () => { eprint!("\x1b[0m" ) };} pub struct DebugState { pub enabled: bool, last_cycle: usize, last_mark: Instant, } impl DebugState { pub fn new(enabled: bool) -> Self { Self { enabled, last_cycle: 0, last_mark: Instant::now(), } } pub fn print(&self, string: &str) { if self.enabled { println!("{}", string); } } pub fn debug_summary(&mut self, core: &BedrockCore) { eprintln!("\n PC: 0x{:04x} Cycles: {} (+{} in {:.2?})", core.mem.pc, core.cycle, core.cycle.saturating_sub(self.last_cycle), self.last_mark.elapsed(), ); eprint!("WST: "); debug_stack(&core.wst, 0x10); eprint!("RST: "); debug_stack(&core.rst, 0x10); self.last_cycle = core.cycle; self.last_mark = Instant::now(); } } fn debug_stack(stack: &Stack, len: usize) { for i in 0..len { if i == stack.sp as usize { yellow!(); } eprint!("{:02x} ", stack.mem[i]); } normal!(); eprintln!(); }