implement font character instruction

This commit is contained in:
Denis-Cosmin NUTIU 2024-12-07 21:39:43 +02:00
parent 95b0d4656f
commit e3a4c023a3
3 changed files with 10 additions and 1 deletions

Binary file not shown.

View file

@ -362,6 +362,9 @@ where
self.registers[0xF] = 0 self.registers[0xF] = 0
} }
} }
ProcessorInstruction::FontCharacter(vx) => {
self.index_register = 0xF0 + (self.registers[vx as usize] & 0x0F) as u16;
}
_ => { _ => {
warn!("Unknown instruction: {:04x}, skipping.", instruction); warn!("Unknown instruction: {:04x}, skipping.", instruction);
} }

View file

@ -68,7 +68,10 @@ pub enum ProcessorInstruction {
SetDelayTimer(u8), SetDelayTimer(u8),
/// Sets the sound timer to the value in VX. /// Sets the sound timer to the value in VX.
SetSoundTimer(u8), SetSoundTimer(u8),
/// Adds the value of VX to the index register and sets the overflow flag.
AddToIndex(u8), AddToIndex(u8),
/// Sets the index register to the hexadecimal character in VX.
FontCharacter(u8),
/// Unknown instruction /// Unknown instruction
UnknownInstruction, UnknownInstruction,
} }
@ -106,7 +109,7 @@ impl Instruction {
let digit4 = Self::grab_first_nibble(data); let digit4 = Self::grab_first_nibble(data);
match (digit1, digit2, digit3, digit4) { match (digit1, digit2, digit3, digit4) {
// Clear Display // Clear Display
(0, 0, 0xE, 0) => ProcessorInstruction::ClearScreen, (0x0, 0x0, 0xE, 0x0) => ProcessorInstruction::ClearScreen,
// Jump // Jump
(0x1, _, _, _) => { (0x1, _, _, _) => {
// 1NNN // 1NNN
@ -208,6 +211,9 @@ impl Instruction {
ProcessorInstruction::SetSoundTimer(Self::grab_first_nibble(data)) ProcessorInstruction::SetSoundTimer(Self::grab_first_nibble(data))
} }
(0xF, _, 0x1, 0xE) => ProcessorInstruction::AddToIndex(Self::grab_first_nibble(data)), (0xF, _, 0x1, 0xE) => ProcessorInstruction::AddToIndex(Self::grab_first_nibble(data)),
(0xF, _, 0x2, 0x9) => {
ProcessorInstruction::FontCharacter(Self::grab_first_nibble(data))
}
// Unknown instruction // Unknown instruction
_ => ProcessorInstruction::UnknownInstruction, _ => ProcessorInstruction::UnknownInstruction,
} }