implement add to index instruction.rs
This commit is contained in:
parent
cbb5c2db78
commit
95b0d4656f
2 changed files with 14 additions and 0 deletions
|
@ -350,6 +350,18 @@ where
|
||||||
trace!("SetSoundTimer");
|
trace!("SetSoundTimer");
|
||||||
self.sound_timer = self.registers[vx as usize]
|
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);
|
warn!("Unknown instruction: {:04x}, skipping.", instruction);
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,7 @@ pub enum ProcessorInstruction {
|
||||||
SetDelayTimer(u8),
|
SetDelayTimer(u8),
|
||||||
/// Sets the sound timer to the value in VX.
|
/// Sets the sound timer to the value in VX.
|
||||||
SetSoundTimer(u8),
|
SetSoundTimer(u8),
|
||||||
|
AddToIndex(u8),
|
||||||
/// Unknown instruction
|
/// Unknown instruction
|
||||||
UnknownInstruction,
|
UnknownInstruction,
|
||||||
}
|
}
|
||||||
|
@ -206,6 +207,7 @@ impl Instruction {
|
||||||
(0xF, _, 0x1, 0x8) => {
|
(0xF, _, 0x1, 0x8) => {
|
||||||
ProcessorInstruction::SetSoundTimer(Self::grab_first_nibble(data))
|
ProcessorInstruction::SetSoundTimer(Self::grab_first_nibble(data))
|
||||||
}
|
}
|
||||||
|
(0xF, _, 0x1, 0xE) => ProcessorInstruction::AddToIndex(Self::grab_first_nibble(data)),
|
||||||
// Unknown instruction
|
// Unknown instruction
|
||||||
_ => ProcessorInstruction::UnknownInstruction,
|
_ => ProcessorInstruction::UnknownInstruction,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue