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