c-like struct for Draw instruction
This commit is contained in:
parent
a464c00836
commit
a9d252f758
2 changed files with 16 additions and 14 deletions
|
@ -221,18 +221,16 @@ where
|
|||
trace!("Set index register to data {:04x}", data);
|
||||
self.index_register = data;
|
||||
}
|
||||
ProcessorInstruction::Draw(vx_register, vy_register, num_rows) => {
|
||||
trace!(
|
||||
"Draw vx_register={vx_register} vy_register={vy_register} pixels={num_rows}"
|
||||
);
|
||||
let x_coordinate = self.registers[vx_register as usize];
|
||||
let y_coordinate = self.registers[vy_register as usize];
|
||||
ProcessorInstruction::Draw { vx, vy, rows } => {
|
||||
trace!("Draw vx_register={vx} vy_register={vy} pixels={rows}");
|
||||
let x_coordinate = self.registers[vx as usize];
|
||||
let y_coordinate = self.registers[vy as usize];
|
||||
|
||||
// Keep track if any pixels were flipped
|
||||
let mut flipped = false;
|
||||
|
||||
// Iterate over each row of our sprite
|
||||
for y_line in 0..num_rows {
|
||||
for y_line in 0..rows {
|
||||
// Determine which memory address our row's data is stored
|
||||
let addr = self.index_register + y_line as u16;
|
||||
let pixels = self.memory[addr as usize];
|
||||
|
|
|
@ -25,7 +25,7 @@ pub enum ProcessorInstruction {
|
|||
/// Sets the index register
|
||||
SetIndexRegister { data: u16 },
|
||||
/// Draws to the screen.
|
||||
Draw(u8, u8, u8),
|
||||
Draw { vx: u8, vy: u8, rows: u8 },
|
||||
/// Call sets PC to the address and saves the return address on the stack
|
||||
Call(u16),
|
||||
/// Pops the stack and sets the PC
|
||||
|
@ -152,11 +152,11 @@ impl Instruction {
|
|||
// Draw on screen
|
||||
(0xD, _, _, _) => {
|
||||
// DXYN
|
||||
ProcessorInstruction::Draw(
|
||||
Self::grab_first_nibble(data),
|
||||
Self::grab_middle_nibble(data),
|
||||
Self::grab_last_nibble(data),
|
||||
)
|
||||
ProcessorInstruction::Draw {
|
||||
vx: Self::grab_first_nibble(data),
|
||||
vy: Self::grab_middle_nibble(data),
|
||||
rows: Self::grab_last_nibble(data),
|
||||
}
|
||||
}
|
||||
(0x0, 0x0, 0xE, 0xE) => ProcessorInstruction::Return,
|
||||
(0x2, _, _, _) => ProcessorInstruction::Call(Self::grab_inner_data(data)),
|
||||
|
@ -529,7 +529,11 @@ mod tests {
|
|||
let instruction = Instruction::new([0xDA, 0xBC]);
|
||||
assert_eq!(
|
||||
instruction.processor_instruction,
|
||||
ProcessorInstruction::Draw(0xA, 0xB, 0xC)
|
||||
ProcessorInstruction::Draw {
|
||||
vx: 0xA,
|
||||
vy: 0xB,
|
||||
rows: 0xC
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue