aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2026-09-07 16:38:48 +0200
committerMiquel Sabaté Solà <mssola@mssola.com>2026-09-07 16:38:48 +0200
commit2f4caa8e39ac39969522c4a2a285256c9a13b2c6 (patch)
tree35b3b2408472ee47c03ad2f562beff8dd4b0b13f
parent44f98890a6d91cd9f0b64dec743a22a6e0013590 (diff)
downloadtools.nes-2f4caa8e39ac39969522c4a2a285256c9a13b2c6.tar.gz
tools.nes-2f4caa8e39ac39969522c4a2a285256c9a13b2c6.zip
vnf: convert StatusRegister.break_mark to Option<u8>
Instead of assuming a default value, it's safer to just implement it in Rust's native Option<_> type. Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
-rw-r--r--lib/vnf/src/lib.rs18
-rw-r--r--tests/vnf-tests/src/main.rs8
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(())