diff options
| -rw-r--r-- | lib/vnf/src/lib.rs | 18 | ||||
| -rw-r--r-- | tests/vnf-tests/src/main.rs | 8 |
2 files changed, 14 insertions, 12 deletions
diff --git a/lib/vnf/src/lib.rs b/lib/vnf/src/lib.rs index dfa2f7f..61f117d 100644 --- a/lib/vnf/src/lib.rs +++ b/lib/vnf/src/lib.rs @@ -44,8 +44,8 @@ pub struct StatusRegister { pub zero: bool, pub carry: bool, - /// The byte after a 'brk' instruction. - pub break_mark: u8, + /// The byte after the a 'brk' instruction. + pub break_mark: Option<u8>, } impl Default for StatusRegister { @@ -58,7 +58,7 @@ impl Default for StatusRegister { interrupt: true, zero: false, carry: false, - break_mark: 0, + break_mark: None, } } } @@ -857,7 +857,7 @@ impl Machine { // BRK is always cleared. We also clear the break mark now. self.status_register.brk = false; - self.status_register.break_mark = 0; + self.status_register.break_mark = None; Ok(()) } @@ -1205,10 +1205,12 @@ impl Machine { // 1. If that's not possible, then we have a 'brk' as the last // instruction with no break mark or something like that, which // is just nonsense. - self.status_register.break_mark = *self - .prg_rom - .get(self.pc - 0x8000 + 1) - .expect("you need to reserve a byte for the break mark"); + self.status_register.break_mark = Some( + *self + .prg_rom + .get(self.pc - 0x8000 + 1) + .expect("you need to reserve a byte for the break mark"), + ); // TODO: the next PC is the advertized IRQ one. This one is // picked as the last byte from PRG-ROM, but depending on how diff --git a/tests/vnf-tests/src/main.rs b/tests/vnf-tests/src/main.rs index 96e3b95..1f79655 100644 --- a/tests/vnf-tests/src/main.rs +++ b/tests/vnf-tests/src/main.rs @@ -88,10 +88,10 @@ fn run_break_mark_test(path: &Path) -> Result<(), String> { )); // Before vs after running 'brk'. - assert_eq!(machine.status_register.break_mark, 0); + assert!(machine.status_register.break_mark.is_none()); assert!(!machine.status_register.brk); let _ = machine.next_iteration(); - assert_eq!(machine.status_register.break_mark, 0x42); + assert_eq!(machine.status_register.break_mark.unwrap(), 0x42); assert!(machine.status_register.brk); // Skip instructions we don't care about here. @@ -104,12 +104,12 @@ fn run_break_mark_test(path: &Path) -> Result<(), String> { machine.current_instruction.identifier, InstructionIdentifier::Plp )); - assert_eq!(machine.status_register.break_mark, 0x42); + assert_eq!(machine.status_register.break_mark.unwrap(), 0x42); assert!(machine.status_register.brk); // After running 'plp'. let _ = machine.next_iteration(); - assert_eq!(machine.status_register.break_mark, 0x00); + assert!(machine.status_register.break_mark.is_none()); assert!(!machine.status_register.brk); Ok(()) |
