Make peek's format argument optional

This commit is contained in:
pjht 2023-01-24 10:25:59 -06:00
parent a52442493a
commit f69ade25e9
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,
symbol_tables: SymbolTables,
address_breakpoints: IndexSet<u32>,
last_peek_format: (peek::Format, peek::Size),
}
/// 68K Backplane Computer Emulator
@ -75,6 +76,7 @@ fn main() -> Result<(), anyhow::Error> {
cpu: M68K::new(backplane),
symbol_tables,
address_breakpoints: IndexSet::new(),
last_peek_format: (peek::Format::Hex, peek::Size::Byte),
};
if args.run {
let mut out = String::new();
@ -241,23 +243,30 @@ fn main() -> Result<(), anyhow::Error> {
.arg(
Arg::new("fmt")
.short('f')
.required(true)
.takes_value(true)
.help("The format to print the values in (<fmt><size>)"),
)
.arg(Arg::new("addr").required(true))
.about("Peek a memory address"),
|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 {
return Err(anyhow!("Peek format length must be 2"));
}
let fmt = peek::Format::try_from(fmt_str.chars().next().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 addr = state
.symbol_tables
.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 bus = state.cpu.bus_mut();
for i in 0..count {

View File

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