implement set index register

This commit is contained in:
Denis-Cosmin Nutiu 2024-12-05 09:44:16 +02:00
parent f47228bf8c
commit c3a17f0b47
2 changed files with 14 additions and 1 deletions

View file

@ -146,6 +146,10 @@ where
trace!("Add to register {} data {:04x}", register, data);
self.registers[register as usize] += data
}
ProcessorInstruction::SetIndexRegister(data) => {
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];
@ -158,7 +162,7 @@ where
for y_line in 0..num_rows {
// Determine which memory address our row's data is stored
let addr = self.index_register + y_line as u16;
let pixels = self.memory[0xf0 + addr as usize];
let pixels = self.memory[addr as usize];
// Iterate over each column in our row
for x_line in 0..8 {
// Use a mask to fetch current pixel's bit. Only flip if a 1

View file

@ -22,8 +22,11 @@ pub enum ProcessorInstruction {
SetRegister(u8, u8),
/// Adds the value to the register
AddValueToRegister(u8, u8),
/// Sets the index register
SetIndexRegister(u16),
/// Draws to the screen.
Draw(u8, u8, u8),
/// Unknown instruction
UnknownInstruction,
}
@ -74,6 +77,7 @@ impl Instruction {
Self::grab_last_byte(data),
)
}
// Add value to register
(0x7, _, _, _) => {
// 7XNN
ProcessorInstruction::AddValueToRegister(
@ -81,6 +85,11 @@ impl Instruction {
Self::grab_last_byte(data),
)
}
// Set index register
(0xA, _, _, _) => {
ProcessorInstruction::SetIndexRegister(Self::grab_inner_data(data))
},
// Draw on screen
(0xD, _, _, _) => {
// DXYN
ProcessorInstruction::Draw(