Added better error-reporting to the emulator.

This commit is contained in:
jan 2024-12-22 13:17:41 +01:00
parent ed7ca9a227
commit 890c2b7b79
4 changed files with 10 additions and 7 deletions

2
Cargo.lock generated
View File

@ -1813,7 +1813,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]] [[package]]
name = "svc16" name = "svc16"
version = "0.6.0" version = "0.6.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "svc16" name = "svc16"
version = "0.6.0" version = "0.6.1"
edition = "2021" edition = "2021"
authors = ["Jan Neuendorf"] authors = ["Jan Neuendorf"]
description = "An emulator for a simple virtual computer" description = "An emulator for a simple virtual computer"

View File

@ -36,8 +36,8 @@ pub enum EngineError {
#[error("Division by zero")] #[error("Division by zero")]
ZeroDivision, ZeroDivision,
#[error("Invalid instruction")] #[error("Invalid instruction {0}")]
InvalidInstruction, InvalidInstruction(u16),
} }
impl Engine { impl Engine {
@ -216,7 +216,7 @@ impl Engine {
} }
self.advance_inst_ptr(); self.advance_inst_ptr();
} }
_ => return Err(EngineError::InvalidInstruction), _ => return Err(EngineError::InvalidInstruction(opcode)),
} }
Ok(()) Ok(())
} }

View File

@ -87,8 +87,11 @@ fn main() -> Result<()> {
let engine_start = Instant::now(); let engine_start = Instant::now();
while !engine.wants_to_sync() && ipf <= cli.max_ipf && !paused { while !engine.wants_to_sync() && ipf <= cli.max_ipf && !paused {
match engine.step() { match engine.step() {
Err(_) => { Err(e) => {
handle_event_loop_error(&elwt, "Invalid operation"); handle_event_loop_error(
&elwt,
format!("{} (after {} instructions)", e, ipf),
);
return; return;
} }
_ => {} _ => {}