From f64b7672745778a5cf99405707a0649e66d889b4 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 19 Oct 2026 21:30:43 +0200 Subject: Use translate_rom_address() for the break mark MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was a leftover from commit 57a15f938556 ("runrom: add support for the MMC3 chip"). As a cherry on top, let's use .get() instead of directly accessing the PRG ROM slice. Signed-off-by: Miquel Sabaté Solà --- lib/vnf/src/lib.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/vnf/src/lib.rs b/lib/vnf/src/lib.rs index 4642afb..7b6dda8 100644 --- a/lib/vnf/src/lib.rs +++ b/lib/vnf/src/lib.rs @@ -1456,21 +1456,16 @@ impl Machine { // The break mark is basically the byte which is in current PC + // 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 = 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 - // bank mapping is done, this is not necessarily true. + // instruction with no break mark or something like that. In + // this case translate_rom_address() will give us a zero value, + // which is good enough. + self.status_register.break_mark = Some(self.translate_rom_address(self.pc + 1)?[0]); + + // The next PC is the advertized IRQ one. This one is picked as + // the last word from PRG-ROM. let len = self.prg_rom.len(); - let high = &(self.prg_rom[len - 1] as usize) << 8; - let low = &(self.prg_rom[len - 2] as usize); + let high = &(*self.prg_rom.get(len - 1).unwrap_or(&0) as usize) << 8; + let low = &(*self.prg_rom.get(len - 2).unwrap_or(&0) as usize); self.pc = high + low; self.skip_pc = true; -- cgit v1.2.3