Return bus errors from cpu.step() instead of panicking
This commit is contained in:
parent
077050fb2b
commit
d32a46b93b
10
src/disas.rs
10
src/disas.rs
@ -62,14 +62,14 @@ pub fn disasm<T>(
|
||||
#[derive(Debug)]
|
||||
pub enum DisassemblyError<T> {
|
||||
InvalidInstruction,
|
||||
ReadError(u32, T),
|
||||
ReadError(T),
|
||||
}
|
||||
|
||||
impl<T: Display> Display for DisassemblyError<T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::InvalidInstruction => f.write_str("Invalid instruction"),
|
||||
Self::ReadError(addr, e) => f.write_fmt(format_args!("Read error at {} ({})", addr, e)),
|
||||
Self::ReadError(e) => f.write_fmt(format_args!("{}", e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -926,11 +926,9 @@ impl<T> Disasm<'_, T> {
|
||||
}
|
||||
|
||||
fn read_prog_word(&mut self) -> Result<u16, DisassemblyError<T>> {
|
||||
let word = ((self.byte_read)(self.pc)
|
||||
.map_err(|e| DisassemblyError::ReadError(self.pc, e))? as u16)
|
||||
let word = ((self.byte_read)(self.pc).map_err(|e| DisassemblyError::ReadError(e))? as u16)
|
||||
<< 8
|
||||
| ((self.byte_read)(self.pc + 1)
|
||||
.map_err(|e| DisassemblyError::ReadError(self.pc + 1, e))? as u16);
|
||||
| ((self.byte_read)(self.pc + 1).map_err(|e| DisassemblyError::ReadError(e))? as u16);
|
||||
self.pc += 2;
|
||||
Ok(word)
|
||||
}
|
||||
|
540
src/m68k.rs
540
src/m68k.rs
File diff suppressed because it is too large
Load Diff
12
src/main.rs
12
src/main.rs
@ -18,7 +18,7 @@ mod term;
|
||||
use crate::{
|
||||
backplane::Backplane,
|
||||
location::Location,
|
||||
m68k::{BusError, M68K},
|
||||
m68k::{DetailedBusError, M68K},
|
||||
};
|
||||
use anyhow::anyhow;
|
||||
use clap::Parser;
|
||||
@ -79,7 +79,13 @@ fn main() -> Result<(), anyhow::Error> {
|
||||
if args.run {
|
||||
let mut out = String::new();
|
||||
while !state.cpu.stopped {
|
||||
state.cpu.step();
|
||||
match state.cpu.step() {
|
||||
Ok(()) => (),
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
state.cpu.stopped = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
out += &format!("{}\n", state.cpu);
|
||||
let pc = state.cpu.pc();
|
||||
@ -458,7 +464,7 @@ fn disas_fmt(
|
||||
cpu: &mut M68K,
|
||||
addr: u32,
|
||||
symbol_tables: &SymbolTables,
|
||||
) -> (String, Result<u32, DisassemblyError<BusError>>) {
|
||||
) -> (String, Result<u32, DisassemblyError<DetailedBusError>>) {
|
||||
let addr_fmt = if let Some((table, symbol, offset)) = symbol_tables.address_to_symbol(addr) {
|
||||
format!("{}:{} + {} (0x{:x})", table, symbol, offset, addr)
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user