rust_chip8_opengl/errors.rs
1use std::fmt;
2
3/// Error that is returned when the processor encounters an invalid opcode
4#[derive(Debug, Clone)]
5pub struct OpcodeError {
6 /// The invalid opcode that was encountered
7 opcode: u16,
8 /// The program conuter at the moment the invalid opcode was encountered
9 pc: u8,
10}
11
12impl OpcodeError {
13 pub fn new(opcode: u16, pc: u8) -> OpcodeError {
14 OpcodeError { opcode, pc }
15 }
16}
17
18impl fmt::Display for OpcodeError {
19 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20 write!(
21 f,
22 "Invalid opcode {:x} encountered at PC = {:x}",
23 self.opcode, self.pc
24 )
25 }
26}