use c-like struct for SkipEqualVXData & SkipNotEqualVXData instruction

This commit is contained in:
Denis-Cosmin Nutiu 2024-12-11 00:22:57 +02:00
parent b2666d4226
commit 4cba27de97
2 changed files with 14 additions and 14 deletions

View file

@ -345,14 +345,14 @@ where
trace!("Generate random number"); trace!("Generate random number");
self.registers[vx as usize] = rand::thread_rng().gen_range(0x00..0xFF) & mask self.registers[vx as usize] = rand::thread_rng().gen_range(0x00..0xFF) & mask
} }
ProcessorInstruction::SkipEqualVXData(vx, data) => { ProcessorInstruction::SkipEqualVXData { vx, data} => {
trace!("SkipEqualVXData"); trace!("SkipEqualVXData");
let vx_data = self.registers[vx as usize]; let vx_data = self.registers[vx as usize];
if vx_data == data { if vx_data == data {
self.program_counter += 2 self.program_counter += 2
} }
} }
ProcessorInstruction::SkipNotEqualVXData(vx, data) => { ProcessorInstruction::SkipNotEqualVXData { vx, data} => {
trace!("SkipNotEqualVXData"); trace!("SkipNotEqualVXData");
let vx_data = self.registers[vx as usize]; let vx_data = self.registers[vx as usize];
if vx_data != data { if vx_data != data {

View file

@ -55,9 +55,9 @@ pub enum ProcessorInstruction {
/// Generates a random number ANDed with the data and stores it in VX. /// Generates a random number ANDed with the data and stores it in VX.
GenerateRandomNumber { vx: u8, mask: u8 }, GenerateRandomNumber { vx: u8, mask: u8 },
/// Skips the next instruction if VX is equal to data. /// Skips the next instruction if VX is equal to data.
SkipEqualVXData(u8, u8), SkipEqualVXData {vx: u8, data: u8},
/// Skip the next instruction if VX is not equal to data. /// Skip the next instruction if VX is not equal to data.
SkipNotEqualVXData(u8, u8), SkipNotEqualVXData {vx: u8, data: u8},
/// Skips the next instruction if VX is equal to VY. /// Skips the next instruction if VX is equal to VY.
SkipEqualVXVY(u8, u8), SkipEqualVXVY(u8, u8),
/// Skip the next instruction if VX is not equal to VY. /// Skip the next instruction if VX is not equal to VY.
@ -205,14 +205,14 @@ impl Instruction {
vx: Self::grab_first_nibble(data), vx: Self::grab_first_nibble(data),
mask: Self::grab_last_byte(data), mask: Self::grab_last_byte(data),
}, },
(0x3, _, _, _) => ProcessorInstruction::SkipEqualVXData( (0x3, _, _, _) => ProcessorInstruction::SkipEqualVXData{
Self::grab_first_nibble(data), vx: Self::grab_first_nibble(data),
Self::grab_last_byte(data), data: Self::grab_last_byte(data),
), },
(0x4, _, _, _) => ProcessorInstruction::SkipNotEqualVXData( (0x4, _, _, _) => ProcessorInstruction::SkipNotEqualVXData {
Self::grab_first_nibble(data), vx: Self::grab_first_nibble(data),
Self::grab_last_byte(data), data: Self::grab_last_byte(data),
), },
(0x5, _, _, 0x0) => ProcessorInstruction::SkipEqualVXVY( (0x5, _, _, 0x0) => ProcessorInstruction::SkipEqualVXVY(
Self::grab_first_nibble(data), Self::grab_first_nibble(data),
Self::grab_middle_nibble(data), Self::grab_middle_nibble(data),
@ -365,7 +365,7 @@ mod tests {
let instruction = Instruction::new([0x3A, 0xBC]); let instruction = Instruction::new([0x3A, 0xBC]);
assert_eq!( assert_eq!(
instruction.processor_instruction, instruction.processor_instruction,
ProcessorInstruction::SkipEqualVXData(0xA, 0xBC) ProcessorInstruction::SkipEqualVXData{vx: 0xA, data: 0xBC}
) )
} }
@ -374,7 +374,7 @@ mod tests {
let instruction = Instruction::new([0x4A, 0xBC]); let instruction = Instruction::new([0x4A, 0xBC]);
assert_eq!( assert_eq!(
instruction.processor_instruction, instruction.processor_instruction,
ProcessorInstruction::SkipNotEqualVXData(0xA, 0xBC) ProcessorInstruction::SkipNotEqualVXData{vx: 0xA, data: 0xBC}
) )
} }