implement set index register
This commit is contained in:
parent
f47228bf8c
commit
c3a17f0b47
2 changed files with 14 additions and 1 deletions
|
@ -146,6 +146,10 @@ where
|
||||||
trace!("Add to register {} data {:04x}", register, data);
|
trace!("Add to register {} data {:04x}", register, data);
|
||||||
self.registers[register as usize] += 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) => {
|
ProcessorInstruction::Draw(vx_register, vy_register, num_rows) => {
|
||||||
trace!("Draw vx_register={vx_register} vy_register={vy_register} pixels={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 x_coordinate = self.registers[vx_register as usize];
|
||||||
|
@ -158,7 +162,7 @@ where
|
||||||
for y_line in 0..num_rows {
|
for y_line in 0..num_rows {
|
||||||
// Determine which memory address our row's data is stored
|
// Determine which memory address our row's data is stored
|
||||||
let addr = self.index_register + y_line as u16;
|
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
|
// Iterate over each column in our row
|
||||||
for x_line in 0..8 {
|
for x_line in 0..8 {
|
||||||
// Use a mask to fetch current pixel's bit. Only flip if a 1
|
// Use a mask to fetch current pixel's bit. Only flip if a 1
|
||||||
|
|
|
@ -22,8 +22,11 @@ pub enum ProcessorInstruction {
|
||||||
SetRegister(u8, u8),
|
SetRegister(u8, u8),
|
||||||
/// Adds the value to the register
|
/// Adds the value to the register
|
||||||
AddValueToRegister(u8, u8),
|
AddValueToRegister(u8, u8),
|
||||||
|
/// Sets the index register
|
||||||
|
SetIndexRegister(u16),
|
||||||
/// Draws to the screen.
|
/// Draws to the screen.
|
||||||
Draw(u8, u8, u8),
|
Draw(u8, u8, u8),
|
||||||
|
/// Unknown instruction
|
||||||
UnknownInstruction,
|
UnknownInstruction,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +77,7 @@ impl Instruction {
|
||||||
Self::grab_last_byte(data),
|
Self::grab_last_byte(data),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
// Add value to register
|
||||||
(0x7, _, _, _) => {
|
(0x7, _, _, _) => {
|
||||||
// 7XNN
|
// 7XNN
|
||||||
ProcessorInstruction::AddValueToRegister(
|
ProcessorInstruction::AddValueToRegister(
|
||||||
|
@ -81,6 +85,11 @@ impl Instruction {
|
||||||
Self::grab_last_byte(data),
|
Self::grab_last_byte(data),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
// Set index register
|
||||||
|
(0xA, _, _, _) => {
|
||||||
|
ProcessorInstruction::SetIndexRegister(Self::grab_inner_data(data))
|
||||||
|
},
|
||||||
|
// Draw on screen
|
||||||
(0xD, _, _, _) => {
|
(0xD, _, _, _) => {
|
||||||
// DXYN
|
// DXYN
|
||||||
ProcessorInstruction::Draw(
|
ProcessorInstruction::Draw(
|
||||||
|
|
Loading…
Reference in a new issue