c-like struct for AddValueToRegister instruction
This commit is contained in:
parent
ede70d15a0
commit
7f07d3b184
2 changed files with 12 additions and 9 deletions
|
@ -212,9 +212,9 @@ where
|
|||
trace!("Set register {} to data {:04x}", register, data);
|
||||
self.registers[register as usize] = data
|
||||
}
|
||||
ProcessorInstruction::AddValueToRegister(register, data) => {
|
||||
trace!("Add to register {} data {:04x}", register, data);
|
||||
let (result, _) = self.registers[register as usize].overflowing_add(data);
|
||||
ProcessorInstruction::AddValueToRegister { register, value } => {
|
||||
trace!("Add to register {} data {:04x}", register, value);
|
||||
let (result, _) = self.registers[register as usize].overflowing_add(value);
|
||||
self.registers[register as usize] = result;
|
||||
}
|
||||
ProcessorInstruction::SetIndexRegister(data) => {
|
||||
|
|
|
@ -21,7 +21,7 @@ pub enum ProcessorInstruction {
|
|||
/// Sets the register in the first argument to the given value
|
||||
SetRegister { register: u8, data: u8 },
|
||||
/// Adds the value to the register
|
||||
AddValueToRegister(u8, u8),
|
||||
AddValueToRegister { register: u8, value: u8 },
|
||||
/// Sets the index register
|
||||
SetIndexRegister(u16),
|
||||
/// Draws to the screen.
|
||||
|
@ -140,10 +140,10 @@ impl Instruction {
|
|||
// Add value to register
|
||||
(0x7, _, _, _) => {
|
||||
// 7XNN
|
||||
ProcessorInstruction::AddValueToRegister(
|
||||
Self::grab_first_nibble(data),
|
||||
Self::grab_last_byte(data),
|
||||
)
|
||||
ProcessorInstruction::AddValueToRegister {
|
||||
register: Self::grab_first_nibble(data),
|
||||
value: Self::grab_last_byte(data),
|
||||
}
|
||||
}
|
||||
// Set index register
|
||||
(0xA, _, _, _) => ProcessorInstruction::SetIndexRegister(Self::grab_inner_data(data)),
|
||||
|
@ -407,7 +407,10 @@ mod tests {
|
|||
let instruction = Instruction::new([0x71, 0x40]);
|
||||
assert_eq!(
|
||||
instruction.processor_instruction,
|
||||
ProcessorInstruction::AddValueToRegister(0x1, 0x40)
|
||||
ProcessorInstruction::AddValueToRegister {
|
||||
register: 0x1,
|
||||
value: 0x40
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue