From 0ce357b8cecf5c9bbd550bcf1aa10317f1a755e7 Mon Sep 17 00:00:00 2001 From: Denis-Cosmin NUTIU Date: Sun, 8 Dec 2024 12:11:31 +0200 Subject: [PATCH] fix binary coded decimal instruction --- src/emulator.rs | 7 ++++--- src/main.rs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/emulator.rs b/src/emulator.rs index 861298b..3d1aa3a 100644 --- a/src/emulator.rs +++ b/src/emulator.rs @@ -362,9 +362,10 @@ where self.index_register = 0xF0 + (self.registers[vx as usize] & 0x0F) as u16; } ProcessorInstruction::BinaryCodedDecimalConversion(vx) => { - self.memory[self.index_register as usize] = vx / 100; - self.memory[self.index_register as usize + 1] = (vx / 10) % 10; - self.memory[self.index_register as usize + 2] = ((vx) % 100) % 10; + let number = self.registers[vx as usize]; + self.memory[self.index_register as usize] = number / 100; + self.memory[self.index_register as usize + 1] = (number / 10) % 10; + self.memory[self.index_register as usize + 2] = ((number) % 100) % 10; } ProcessorInstruction::LoadMemory(vx) => { for i in 0..=vx { diff --git a/src/main.rs b/src/main.rs index b1ead3f..25672e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ fn main() -> Result<(), anyhow::Error> { let mut emulator = Emulator::new(RatatuiDisplay::new()); - emulator.emulate(String::from("./roms/1-chip8-logo.ch8"))?; + emulator.emulate(String::from("./roms/3-corax+.ch8"))?; Ok(()) }