core: debugger: Improve info command

Former-commit-id: 534b4907911408f3765825145f14d0b680058dcf
Former-commit-id: 20ed0d130e2fb17b9fc6fb7c1cfc485277a6fb10
This commit is contained in:
Michel Heily 2021-06-10 00:13:17 +03:00
parent 82fa433e26
commit 1545be7b4f
2 changed files with 56 additions and 9 deletions

View file

@ -46,11 +46,17 @@ bitflags! {
} }
} }
#[derive(Debug, PartialEq, Clone)]
pub enum InfoCommand {
Cpu,
Gpu,
Gpio,
Interrupt,
}
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub enum Command { pub enum Command {
Info, Info(InfoCommand),
GpuInfo,
GpioInfo,
Step(usize), Step(usize),
Continue, Continue,
Frame(usize), Frame(usize),
@ -97,7 +103,7 @@ impl Debugger {
use Command::*; use Command::*;
#[allow(unreachable_patterns)] #[allow(unreachable_patterns)]
match command { match command {
Info => { Info(InfoCommand::Cpu) => {
let pc = gba.cpu.pc; let pc = gba.cpu.pc;
if let Some((sym, addr)) = find_nearest_symbol(pc, &self.symbols) { if let Some((sym, addr)) = find_nearest_symbol(pc, &self.symbols) {
println!("PC at {}+{:#x} ({:08x})", sym, addr - pc, pc); println!("PC at {}+{:#x} ({:08x})", sym, addr - pc, pc);
@ -110,8 +116,13 @@ impl Debugger {
// println!("IE={:#?}", gba.io_devs.intc.interrupt_enable); // println!("IE={:#?}", gba.io_devs.intc.interrupt_enable);
// println!("IF={:#?}", gba.io_devs.intc.interrupt_flags); // println!("IF={:#?}", gba.io_devs.intc.interrupt_flags);
} }
GpuInfo => println!("GPU: {:#?}", gba.io_devs.gpu), Info(InfoCommand::Gpu) => println!("{}", gba.io_devs.gpu),
GpioInfo => println!("GPIO: {:#?}", gba.sysbus.cartridge.get_gpio()), 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) => { Step(count) => {
for _ in 0..count { for _ in 0..count {
gba.step_debugger(); gba.step_debugger();
@ -359,9 +370,28 @@ impl Debugger {
}; };
match command.as_ref() { match command.as_ref() {
"i" | "info" => Ok(Command::Info), "i" | "info" => {
"gpuinfo" => Ok(Command::GpuInfo), let usage_err =
"gpio" => Ok(Command::GpioInfo), 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" => { "s" | "step" => {
let count = match args.len() { let count = match args.len() {
0 => 1, 0 => 1,

View file

@ -31,6 +31,9 @@ pub use window::*;
pub mod regs; pub mod regs;
pub use regs::*; pub use regs::*;
#[cfg(feature = "debugger")]
use std::fmt;
#[allow(unused)] #[allow(unused)]
pub mod consts { pub mod consts {
pub use super::VRAM_ADDR; 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)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;