chore(interpreter): handle errors during fetch
This commit is contained in:
@@ -22,6 +22,7 @@ use super::{
|
||||
pub enum InterpreterError {
|
||||
InvalidSyscall(Byte),
|
||||
MemoryOutOfBound(Word),
|
||||
FetchError(String),
|
||||
}
|
||||
|
||||
impl fmt::Display for InterpreterError {
|
||||
@@ -36,6 +37,9 @@ impl fmt::Display for InterpreterError {
|
||||
"Attempted memory write out of physical bounds: ({addr:#04x})"
|
||||
)
|
||||
}
|
||||
InterpreterError::FetchError(s) => {
|
||||
write!(f, "Error during fetch phase: {s}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,15 +76,16 @@ impl Interpreter {
|
||||
pub fn interpret(&mut self) -> Result<(), InterpreterError> {
|
||||
while self.ip < self.text.len() {
|
||||
self.disassembler.offset = self.ip;
|
||||
// XXX remove unwrap
|
||||
self.disassembler.decode_instruction().unwrap();
|
||||
self.disassembler
|
||||
.decode_instruction()
|
||||
.map_err(|e| InterpreterError::FetchError(e.to_string()))?;
|
||||
let current_instruction = self.disassembler.instruction.clone();
|
||||
|
||||
log::info!(
|
||||
"{} IP({:04x})\t {:<32}",
|
||||
self.computer,
|
||||
"({:04x}) {:<32} {}",
|
||||
current_instruction.addr,
|
||||
current_instruction.mnemonic.to_string(),
|
||||
self.computer,
|
||||
);
|
||||
|
||||
match current_instruction.mnemonic {
|
||||
@@ -772,7 +777,7 @@ impl Interpreter {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn interpret_interrupt(&self, id: u8) -> Result<(), InterpreterError> {
|
||||
fn interpret_interrupt(&mut self, id: u8) -> Result<(), InterpreterError> {
|
||||
let bx = self.computer.regs.bx.read();
|
||||
|
||||
let mut data = Vec::new();
|
||||
|
||||
Reference in New Issue
Block a user