diff --git a/src/emulator.rs b/src/emulator.rs index 4f8704e..31d8425 100644 --- a/src/emulator.rs +++ b/src/emulator.rs @@ -350,6 +350,18 @@ where trace!("SetSoundTimer"); self.sound_timer = self.registers[vx as usize] } + ProcessorInstruction::AddToIndex(vx) => { + trace!("AddToIndex"); + let (result, overflow) = self + .index_register + .overflowing_add(self.registers[vx as usize] as u16); + self.index_register = result; + if overflow { + self.registers[0xF] = 1 + } else { + self.registers[0xF] = 0 + } + } _ => { warn!("Unknown instruction: {:04x}, skipping.", instruction); } diff --git a/src/instruction.rs b/src/instruction.rs index 7d20a20..270c06b 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -68,6 +68,7 @@ pub enum ProcessorInstruction { SetDelayTimer(u8), /// Sets the sound timer to the value in VX. SetSoundTimer(u8), + AddToIndex(u8), /// Unknown instruction UnknownInstruction, } @@ -206,6 +207,7 @@ impl Instruction { (0xF, _, 0x1, 0x8) => { ProcessorInstruction::SetSoundTimer(Self::grab_first_nibble(data)) } + (0xF, _, 0x1, 0xE) => ProcessorInstruction::AddToIndex(Self::grab_first_nibble(data)), // Unknown instruction _ => ProcessorInstruction::UnknownInstruction, }