diff --git a/src/emulator.rs b/src/emulator.rs index 97ff3db..25b721f 100644 --- a/src/emulator.rs +++ b/src/emulator.rs @@ -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 diff --git a/src/instruction.rs b/src/instruction.rs index e57d535..3116267 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -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(