diff --git a/src/main.rs b/src/main.rs index 0f34e28..b178229 100644 --- a/src/main.rs +++ b/src/main.rs @@ -315,19 +315,9 @@ fn main() -> Result<(), ReplError> { |args, state| { let mut out = String::new(); while !state.cpu.stopped { - let stop_addr = args.get_one::("stop_addr"); - - let stop_addr = stop_addr - .map(|s| { - parse::(s).or_else(|_| { - state - .symbols - .iter() - .find(|sym| &sym.name == s) - .map(|sym| sym.value as u32) - .ok_or(Error::Misc("No such symbol")) - }) - }) + let stop_addr = args + .get_one::("stop_addr") + .map(|s| parse_addr(s, &state.symbols)) .transpose()?; if stop_addr.map(|a| state.cpu.pc() == a).unwrap_or(false) { break; @@ -474,3 +464,13 @@ fn disas_fmt(cpu: &mut M68K, addr: u32) -> (String, Result (format!("0x{:x}: {}\n", addr, e), Err(e)), } } + +fn parse_addr(addr: &str, symbols: &[Symbol]) -> Result { + parse::(addr).or_else(|_| { + symbols + .iter() + .find(|sym| sym.name == addr) + .map(|sym| sym.value as u32) + .ok_or(Error::Misc("No such symbol")) + }) +}