use c-like struct for Call instruction
This commit is contained in:
parent
9171b35025
commit
5dd11bc74c
3 changed files with 7 additions and 5 deletions
|
@ -263,7 +263,7 @@ where
|
||||||
trace!("Return to {value:04x}");
|
trace!("Return to {value:04x}");
|
||||||
self.program_counter = value;
|
self.program_counter = value;
|
||||||
}
|
}
|
||||||
ProcessorInstruction::Call(address) => {
|
ProcessorInstruction::Call { address } => {
|
||||||
trace!("Call {address:04x}");
|
trace!("Call {address:04x}");
|
||||||
// Save PC to the stack
|
// Save PC to the stack
|
||||||
self.stack.push(self.program_counter);
|
self.stack.push(self.program_counter);
|
||||||
|
|
|
@ -94,4 +94,4 @@ impl Drop for CrossTermInput {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
disable_raw_mode().expect("failed to disable terminal raw mode.");
|
disable_raw_mode().expect("failed to disable terminal raw mode.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub enum ProcessorInstruction {
|
||||||
/// Draws to the screen.
|
/// Draws to the screen.
|
||||||
Draw { vx: u8, vy: u8, rows: u8 },
|
Draw { vx: u8, vy: u8, rows: u8 },
|
||||||
/// Call sets PC to the address and saves the return address on the stack
|
/// Call sets PC to the address and saves the return address on the stack
|
||||||
Call(u16),
|
Call { address: u16 },
|
||||||
/// Pops the stack and sets the PC
|
/// Pops the stack and sets the PC
|
||||||
Return,
|
Return,
|
||||||
/// Set VX to the value of VY
|
/// Set VX to the value of VY
|
||||||
|
@ -159,7 +159,9 @@ impl Instruction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(0x0, 0x0, 0xE, 0xE) => ProcessorInstruction::Return,
|
(0x0, 0x0, 0xE, 0xE) => ProcessorInstruction::Return,
|
||||||
(0x2, _, _, _) => ProcessorInstruction::Call(Self::grab_inner_data(data)),
|
(0x2, _, _, _) => ProcessorInstruction::Call {
|
||||||
|
address: Self::grab_inner_data(data),
|
||||||
|
},
|
||||||
(0x8, _, _, 0x0) => ProcessorInstruction::Set(
|
(0x8, _, _, 0x0) => ProcessorInstruction::Set(
|
||||||
Self::grab_first_nibble(data),
|
Self::grab_first_nibble(data),
|
||||||
Self::grab_middle_nibble(data),
|
Self::grab_middle_nibble(data),
|
||||||
|
@ -343,7 +345,7 @@ mod tests {
|
||||||
let instruction = Instruction::new([0x2A, 0xBC]);
|
let instruction = Instruction::new([0x2A, 0xBC]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
instruction.processor_instruction,
|
instruction.processor_instruction,
|
||||||
ProcessorInstruction::Call(0xABC)
|
ProcessorInstruction::Call { address: 0xABC }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue