REPL UI changes

Former-commit-id: 6852b86541f967785dbffb6833fc2c11fa5dbef3
This commit is contained in:
Michel Heily 2019-07-04 01:37:47 +03:00
parent 3541779fbf
commit 923032f8cf
2 changed files with 43 additions and 24 deletions

View file

@ -342,7 +342,7 @@ impl fmt::Display for Core {
writeln!(f, "\tCPSR: {}", self.cpsr)?;
writeln!(f, "\tGeneral Purpose Registers:")?;
let reg_normal_style = Style::new().bold();
let reg_dirty_style = Colour::Green.bold().on(Colour::Yellow);
let reg_dirty_style = Colour::Black.bold().on(Colour::Yellow);
let gpr = self.get_registers();
for i in 0..15 {
let mut reg_name = reg_string(i).to_string();
@ -354,7 +354,7 @@ impl fmt::Display for Core {
&reg_normal_style
};
let entry = format!("\t{}\t= 0x{:08x}", reg_name, gpr[i]);
let entry = format!("\t{:-3} = 0x{:08x}", reg_name, gpr[i]);
write!(
f,
@ -363,7 +363,7 @@ impl fmt::Display for Core {
if (i + 1) % 4 == 0 { "\n" } else { "" }
)?;
}
let pc = format!("\tPC\t= 0x{:08x}", self.pc);
let pc = format!("\tPC = 0x{:08x}", self.get_next_pc());
writeln!(f, "{}", reg_normal_style.paint(pc))
}
}

View file

@ -18,7 +18,7 @@ pub enum DisassMode {
#[derive(Debug, PartialEq, Clone)]
pub enum Command {
Info,
SingleStep(bool),
Step(usize),
Continue,
HexDump(Addr, usize),
Disass(DisassMode, Addr, usize),
@ -35,27 +35,36 @@ impl Command {
use Command::*;
match *self {
Info => println!("{}", debugger.cpu),
SingleStep(_cycle) => {
if let Some(bp) = debugger.check_breakpoint() {
println!("hit breakpoint #0x{:08x}!", bp);
debugger.delete_breakpoint(bp);
} else {
match debugger.cpu.step_debugger(&mut debugger.sysbus) {
Ok(insn) => {
println!("{}\n", debugger.cpu);
println!(
"Executed at @0x{:08x}:\t{}",
insn.get_pc(),
Colour::Yellow.italic().paint(format!("{} ", insn))
);
println!("Next instruction at @0x{:08x}", debugger.cpu.get_next_pc())
}
Err(e) => {
println!("{}: {}", "cpu encountered an error".red(), e);
println!("cpu: {:x?}", debugger.cpu)
Step(count) => {
for _ in 0..count {
if let Some(bp) = debugger.check_breakpoint() {
println!("hit breakpoint #0x{:08x}!", bp);
debugger.delete_breakpoint(bp);
} else {
match debugger.cpu.step_debugger(&mut debugger.sysbus) {
Ok(insn) => {
print!(
"{}\t{}",
Colour::Black
.bold()
.italic()
.on(Colour::White)
.paint(format!("Executed at @0x{:08x}:", insn.get_pc(),)),
insn
);
println!("{}", Colour::Purple.dimmed().italic().paint(format!(
"\t\t/// Next instruction at @0x{:08x}",
debugger.cpu.get_next_pc()
)))
}
Err(e) => {
println!("{}: {}", "cpu encountered an error".red(), e);
println!("cpu: {:x?}", debugger.cpu)
}
}
}
}
println!("{}\n", debugger.cpu);
}
Continue => loop {
if let Some(bp) = debugger.check_breakpoint() {
@ -171,8 +180,18 @@ impl Debugger {
match command.as_ref() {
"i" | "info" => Ok(Command::Info),
"s" | "step" => Ok(Command::SingleStep(false)),
"sc" | "stepcycle" => Ok(Command::SingleStep(true)),
"s" | "step" => {
let count = match args.len() {
0 => 1,
1 => self.val_number(&args[0])?,
_ => {
return Err(DebuggerError::InvalidCommandFormat(
"step [count]".to_string(),
))
}
};
Ok(Command::Step(count as usize))
}
"c" | "continue" => Ok(Command::Continue),
"x" | "hexdump" => {
let (addr, n) = match args.len() {