implement timer instructions
This commit is contained in:
parent
dec7183ce7
commit
f8f79bc2e6
2 changed files with 32 additions and 0 deletions
|
@ -277,21 +277,25 @@ where
|
|||
self.program_counter = address + offset as u16
|
||||
}
|
||||
ProcessorInstruction::GenerateRandomNumber(register, data) => {
|
||||
trace!("Generate random number");
|
||||
self.registers[register as usize] = rand::thread_rng().gen_range(0x00..0xFF) & data
|
||||
}
|
||||
ProcessorInstruction::SkipEqualVXData(vx, data) => {
|
||||
trace!("SkipEqualVXData");
|
||||
let vx_data = self.registers[vx as usize];
|
||||
if vx_data == data {
|
||||
self.program_counter += 2
|
||||
}
|
||||
}
|
||||
ProcessorInstruction::SkipNotEqualVXData(vx, data) => {
|
||||
trace!("SkipNotEqualVXData");
|
||||
let vx_data = self.registers[vx as usize];
|
||||
if vx_data != data {
|
||||
self.program_counter += 2
|
||||
}
|
||||
}
|
||||
ProcessorInstruction::SkipEqualVXVY(vx, vy) => {
|
||||
trace!("SkipNotEqualVXData");
|
||||
let vx_data = self.registers[vx as usize];
|
||||
let vy_data = self.registers[vy as usize];
|
||||
if vx_data == vy_data {
|
||||
|
@ -299,12 +303,25 @@ where
|
|||
}
|
||||
}
|
||||
ProcessorInstruction::SkipNotEqualVXVY(vx, vy) => {
|
||||
trace!("SkipNotEqualVXVY");
|
||||
let vx_data = self.registers[vx as usize];
|
||||
let vy_data = self.registers[vy as usize];
|
||||
if vx_data != vy_data {
|
||||
self.program_counter += 2
|
||||
}
|
||||
}
|
||||
ProcessorInstruction::SetVXToDelayTimer(vx) => {
|
||||
trace!("SetVXToDelayTimer");
|
||||
self.registers[vx as usize] = self.delay_timer
|
||||
}
|
||||
ProcessorInstruction::SetDelayTimer(vx) => {
|
||||
trace!("SetDelayTimer");
|
||||
self.delay_timer = self.registers[vx as usize]
|
||||
}
|
||||
ProcessorInstruction::SetSoundTimer(vx) => {
|
||||
trace!("SetSoundTimer");
|
||||
self.sound_timer = self.registers[vx as usize]
|
||||
}
|
||||
_ => {
|
||||
warn!("Unknown instruction: {:04x}, skipping.", instruction);
|
||||
}
|
||||
|
|
|
@ -62,6 +62,12 @@ pub enum ProcessorInstruction {
|
|||
SkipEqualVXVY(u8, u8),
|
||||
/// Skip the next instruction if VX is not equal to VY.
|
||||
SkipNotEqualVXVY(u8, u8),
|
||||
/// Sets the value of the VX instruction to the current value of the delay timer.
|
||||
SetVXToDelayTimer(u8),
|
||||
/// Sets the delay timer to the value in VX.
|
||||
SetDelayTimer(u8),
|
||||
/// Sets the sound timer to the value in VX.
|
||||
SetSoundTimer(u8),
|
||||
/// Unknown instruction
|
||||
UnknownInstruction,
|
||||
}
|
||||
|
@ -201,6 +207,15 @@ impl Instruction {
|
|||
Self::grab_first_nibble(data),
|
||||
Self::grab_middle_nibble(data),
|
||||
),
|
||||
(0xF, _, 0x0, 0x7) => ProcessorInstruction::SetVXToDelayTimer(
|
||||
Self::grab_first_nibble(data)
|
||||
),
|
||||
(0xF, _, 0x1, 0x5) => ProcessorInstruction::SetDelayTimer(
|
||||
Self::grab_first_nibble(data)
|
||||
),
|
||||
(0xF, _, 0x1, 0x8) => ProcessorInstruction::SetSoundTimer(
|
||||
Self::grab_first_nibble(data)
|
||||
),
|
||||
// Unknown instruction
|
||||
_ => ProcessorInstruction::UnknownInstruction,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue