From 1545be7b4f54042bfc0bc86841434cfa1c44aa67 Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Thu, 10 Jun 2021 00:13:17 +0300 Subject: [PATCH] core: debugger: Improve info command Former-commit-id: 534b4907911408f3765825145f14d0b680058dcf Former-commit-id: 20ed0d130e2fb17b9fc6fb7c1cfc485277a6fb10 --- core/src/debugger/command.rs | 48 +++++++++++++++++++++++++++++------- core/src/gpu/mod.rs | 17 +++++++++++++ 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/core/src/debugger/command.rs b/core/src/debugger/command.rs index 9fa3895..f53824c 100644 --- a/core/src/debugger/command.rs +++ b/core/src/debugger/command.rs @@ -46,11 +46,17 @@ bitflags! { } } +#[derive(Debug, PartialEq, Clone)] +pub enum InfoCommand { + Cpu, + Gpu, + Gpio, + Interrupt, +} + #[derive(Debug, PartialEq, Clone)] pub enum Command { - Info, - GpuInfo, - GpioInfo, + Info(InfoCommand), Step(usize), Continue, Frame(usize), @@ -97,7 +103,7 @@ impl Debugger { use Command::*; #[allow(unreachable_patterns)] match command { - Info => { + Info(InfoCommand::Cpu) => { let pc = gba.cpu.pc; if let Some((sym, addr)) = find_nearest_symbol(pc, &self.symbols) { println!("PC at {}+{:#x} ({:08x})", sym, addr - pc, pc); @@ -110,8 +116,13 @@ impl Debugger { // println!("IE={:#?}", gba.io_devs.intc.interrupt_enable); // println!("IF={:#?}", gba.io_devs.intc.interrupt_flags); } - GpuInfo => println!("GPU: {:#?}", gba.io_devs.gpu), - GpioInfo => println!("GPIO: {:#?}", gba.sysbus.cartridge.get_gpio()), + Info(InfoCommand::Gpu) => println!("{}", gba.io_devs.gpu), + Info(InfoCommand::Interrupt) => { + println!("IME: {:?}", gba.io_devs.intc.interrupt_master_enable); + println!("IE: {:#?}", gba.io_devs.intc.interrupt_enable); + println!("IF: {:#?}", gba.io_devs.intc.interrupt_flags.get()); + } + Info(InfoCommand::Gpio) => println!("GPIO: {:#?}", gba.sysbus.cartridge.get_gpio()), Step(count) => { for _ in 0..count { gba.step_debugger(); @@ -359,9 +370,28 @@ impl Debugger { }; match command.as_ref() { - "i" | "info" => Ok(Command::Info), - "gpuinfo" => Ok(Command::GpuInfo), - "gpio" => Ok(Command::GpioInfo), + "i" | "info" => { + let usage_err = + DebuggerError::InvalidCommandFormat(String::from("info cpu|gpu|irq|gpio")); + match args.len() { + 1 => { + if let Value::Identifier(what) = &args[0] { + match what.as_ref() { + "cpu" => Ok(Command::Info(InfoCommand::Cpu)), + "gpu" => Ok(Command::Info(InfoCommand::Gpu)), + "irq" => Ok(Command::Info(InfoCommand::Interrupt)), + "gpio" => Ok(Command::Info(InfoCommand::Gpio)), + _ => Err(DebuggerError::InvalidArgument(String::from( + "invalid argument", + ))), + } + } else { + Err(usage_err) + } + } + _ => Err(usage_err), + } + } "s" | "step" => { let count = match args.len() { 0 => 1, diff --git a/core/src/gpu/mod.rs b/core/src/gpu/mod.rs index d3bd610..ba65ff3 100644 --- a/core/src/gpu/mod.rs +++ b/core/src/gpu/mod.rs @@ -31,6 +31,9 @@ pub use window::*; pub mod regs; pub use regs::*; +#[cfg(feature = "debugger")] +use std::fmt; + #[allow(unused)] pub mod consts { pub use super::VRAM_ADDR; @@ -531,6 +534,20 @@ impl DebugRead for Gpu { } } +#[cfg(feature = "debugger")] +impl fmt::Display for Gpu { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + use ansi_term::Style; + writeln!(f, "{}", Style::new().bold().paint("GPU Status:"))?; + writeln!(f, "\tVCOUNT: {}", self.vcount)?; + writeln!(f, "\tDISPCNT: {:?}", self.dispcnt)?; + writeln!(f, "\tDISPSTAT: {:?}", self.dispstat)?; + writeln!(f, "\tWIN0: {:?}", self.win0)?; + writeln!(f, "\tWIN1: {:?}", self.win1)?; + Ok(()) + } +} + #[cfg(test)] mod tests { use super::*;