fix binary coded decimal instruction

This commit is contained in:
Denis-Cosmin NUTIU 2024-12-08 12:11:31 +02:00
parent 5818815981
commit 0ce357b8ce
2 changed files with 5 additions and 4 deletions

View file

@ -362,9 +362,10 @@ where
self.index_register = 0xF0 + (self.registers[vx as usize] & 0x0F) as u16; self.index_register = 0xF0 + (self.registers[vx as usize] & 0x0F) as u16;
} }
ProcessorInstruction::BinaryCodedDecimalConversion(vx) => { ProcessorInstruction::BinaryCodedDecimalConversion(vx) => {
self.memory[self.index_register as usize] = vx / 100; let number = self.registers[vx as usize];
self.memory[self.index_register as usize + 1] = (vx / 10) % 10; self.memory[self.index_register as usize] = number / 100;
self.memory[self.index_register as usize + 2] = ((vx) % 100) % 10; 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) => { ProcessorInstruction::LoadMemory(vx) => {
for i in 0..=vx { for i in 0..=vx {

View file

@ -13,7 +13,7 @@ fn main() -> Result<(), anyhow::Error> {
let mut emulator = Emulator::new(RatatuiDisplay::new()); 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(()) Ok(())
} }