Make peek's format argument optional

This commit is contained in:
pjht 2023-01-24 10:25:59 -06:00
parent ae2c331d84
commit b77f096863
Signed by: pjht
GPG Key ID: E911DEB42C25F8E1
2 changed files with 18 additions and 9 deletions

View File

@ -46,6 +46,7 @@ struct EmuState {
cpu: M68K, cpu: M68K,
symbol_tables: SymbolTables, symbol_tables: SymbolTables,
address_breakpoints: IndexSet<u32>, address_breakpoints: IndexSet<u32>,
last_peek_format: (peek::Format, peek::Size),
} }
/// 68K Backplane Computer Emulator /// 68K Backplane Computer Emulator
@ -75,6 +76,7 @@ fn main() -> Result<(), anyhow::Error> {
cpu: M68K::new(backplane), cpu: M68K::new(backplane),
symbol_tables, symbol_tables,
address_breakpoints: IndexSet::new(), address_breakpoints: IndexSet::new(),
last_peek_format: (peek::Format::Hex, peek::Size::Byte),
}; };
if args.run { if args.run {
let mut out = String::new(); let mut out = String::new();
@ -241,23 +243,30 @@ fn main() -> Result<(), anyhow::Error> {
.arg( .arg(
Arg::new("fmt") Arg::new("fmt")
.short('f') .short('f')
.required(true)
.takes_value(true) .takes_value(true)
.help("The format to print the values in (<fmt><size>)"), .help("The format to print the values in (<fmt><size>)"),
) )
.arg(Arg::new("addr").required(true)) .arg(Arg::new("addr").required(true))
.about("Peek a memory address"), .about("Peek a memory address"),
|args, state| { |args, state| {
let fmt_str = args.get_one::<String>("fmt").unwrap(); let (fmt, size) = if let Some(fmt_str) = args.get_one::<String>("fmt") {
if fmt_str.len() != 2 { if fmt_str.len() != 2 {
return Err(anyhow!("Peek format length must be 2")); return Err(anyhow!("Peek format length must be 2"));
} }
let fmt = peek::Format::try_from(fmt_str.chars().next().unwrap())?; let fmt = peek::Format::try_from(fmt_str.chars().next().unwrap())?;
let size = peek::Size::try_from(fmt_str.chars().nth(1).unwrap())?; let size = peek::Size::try_from(fmt_str.chars().nth(1).unwrap())?;
state.last_peek_format = (fmt, size);
(fmt, size)
} else {
state.last_peek_format
};
let count = parse::<u32>(args.get_one::<String>("count").map_or("1", String::as_str))?; let count = parse::<u32>(args.get_one::<String>("count").map_or("1", String::as_str))?;
let addr = state let addr = state
.symbol_tables .symbol_tables
.parse_location_address(args.get_one::<String>("addr").unwrap())?; .parse_location_address(args.get_one::<String>("addr").unwrap())?;
if (size != peek::Size::Byte) & ((addr & 0x1) != 0) {
return Err(anyhow!("Cannot peek words from a non-aligned address"));
}
let mut data = Vec::new(); let mut data = Vec::new();
let bus = state.cpu.bus_mut(); let bus = state.cpu.bus_mut();
for i in 0..count { for i in 0..count {

View File

@ -1,6 +1,6 @@
use thiserror::Error; use thiserror::Error;
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Format { pub enum Format {
Octal, Octal,
Hex, Hex,
@ -47,7 +47,7 @@ impl TryFrom<char> for Format {
} }
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Size { pub enum Size {
Byte, Byte,
Word, Word,