implement bcd, load, store memory instructions
This commit is contained in:
parent
7e956277ac
commit
5818815981
2 changed files with 14 additions and 3 deletions
|
@ -362,13 +362,21 @@ where
|
||||||
self.index_register = 0xF0 + (self.registers[vx as usize] & 0x0F) as u16;
|
self.index_register = 0xF0 + (self.registers[vx as usize] & 0x0F) as u16;
|
||||||
}
|
}
|
||||||
ProcessorInstruction::BinaryCodedDecimalConversion(vx) => {
|
ProcessorInstruction::BinaryCodedDecimalConversion(vx) => {
|
||||||
todo!("must implement")
|
self.memory[self.index_register as usize] = vx / 100;
|
||||||
|
self.memory[self.index_register as usize + 1] = (vx / 10) % 10;
|
||||||
|
self.memory[self.index_register as usize + 2] = ((vx) % 100) % 10;
|
||||||
}
|
}
|
||||||
ProcessorInstruction::LoadMemory(vx) => {
|
ProcessorInstruction::LoadMemory(vx) => {
|
||||||
todo!("must implement")
|
for i in 0..=vx {
|
||||||
|
let memory_index = (self.index_register + (i as u16)) as usize;
|
||||||
|
self.registers[i as usize] = self.memory[memory_index];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ProcessorInstruction::StoreMemory(vx) => {
|
ProcessorInstruction::StoreMemory(vx) => {
|
||||||
todo!("must implement")
|
for i in 0..=vx {
|
||||||
|
let memory_index = (self.index_register + (i as u16)) as usize;
|
||||||
|
self.memory[memory_index] = self.registers[i as usize];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
warn!("Unknown instruction: {:04x}, skipping.", instruction);
|
warn!("Unknown instruction: {:04x}, skipping.", instruction);
|
||||||
|
|
|
@ -72,8 +72,11 @@ pub enum ProcessorInstruction {
|
||||||
AddToIndex(u8),
|
AddToIndex(u8),
|
||||||
/// Sets the index register to the hexadecimal character in VX.
|
/// Sets the index register to the hexadecimal character in VX.
|
||||||
FontCharacter(u8),
|
FontCharacter(u8),
|
||||||
|
/// Converts the number in VX to 3 digits.
|
||||||
BinaryCodedDecimalConversion(u8),
|
BinaryCodedDecimalConversion(u8),
|
||||||
|
/// Stores the general purpose registers in memory at index register address.
|
||||||
StoreMemory(u8),
|
StoreMemory(u8),
|
||||||
|
/// Loads the general purpose registers from memory at index register address.
|
||||||
LoadMemory(u8),
|
LoadMemory(u8),
|
||||||
/// Unknown instruction
|
/// Unknown instruction
|
||||||
UnknownInstruction,
|
UnknownInstruction,
|
||||||
|
|
Loading…
Reference in a new issue