[cpu] Implement Conditional execution instructions
This commit is contained in:
@@ -15,7 +15,7 @@ pub struct Device {
|
||||
pub timer: Timer,
|
||||
pub stack: Vec<u16>,
|
||||
pub frame_buffer: Arc<Mutex<Box<[bool; 64 * 32]>>>,
|
||||
pub super_chip8_mode: bool
|
||||
pub super_chip8_mode: bool,
|
||||
}
|
||||
|
||||
impl Device {
|
||||
@@ -32,7 +32,7 @@ impl Device {
|
||||
frame_buffer: fb,
|
||||
stack: Vec::with_capacity(16),
|
||||
timer,
|
||||
super_chip8_mode: false
|
||||
super_chip8_mode: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,8 +66,6 @@ impl Device {
|
||||
|
||||
let instruction = Instruction::decode_instruction(instr_slice);
|
||||
self.execute_instruction(instruction);
|
||||
|
||||
|
||||
}
|
||||
/// convert the 2 indices into one
|
||||
fn get_framebuffer_index(x: usize, y: usize) -> usize {
|
||||
@@ -105,7 +103,7 @@ impl Device {
|
||||
let y = self.registers.v[regy] as usize;
|
||||
let toggle_state = self.draw_sprite_at_location(x, y, n);
|
||||
self.set_flag_register(toggle_state);
|
||||
},
|
||||
}
|
||||
Instruction::JumpAndLink(jump_location) => {
|
||||
self.stack.push(self.registers.pc);
|
||||
self.registers.pc = jump_location;
|
||||
@@ -115,10 +113,26 @@ impl Device {
|
||||
self.registers.pc = old_pc;
|
||||
}
|
||||
|
||||
Instruction::ConditionalEqSkipNext(_, _) => {}
|
||||
Instruction::ConditionalInEqSkipNext(_, _) => {}
|
||||
Instruction::ConditionalEqRegisterSkipNext(_, _) => {}
|
||||
Instruction::ConditionalInEqRegisterSkipNext(_, _) => {}
|
||||
Instruction::ConditionalEqSkipNext(regx, num) => {
|
||||
if self.registers.v[regx] == num {
|
||||
self.registers.pc += 2;
|
||||
}
|
||||
}
|
||||
Instruction::ConditionalInEqSkipNext(regx, num) => {
|
||||
if self.registers.v[regx] != num {
|
||||
self.registers.pc += 2;
|
||||
}
|
||||
}
|
||||
Instruction::ConditionalEqRegisterSkipNext(regx, regy) => {
|
||||
if self.registers.v[regx] == self.registers.v[regy] {
|
||||
self.registers.pc += 2;
|
||||
}
|
||||
}
|
||||
Instruction::ConditionalInEqRegisterSkipNext(regx, regy) => {
|
||||
if self.registers.v[regx] != self.registers.v[regy] {
|
||||
self.registers.pc += 2;
|
||||
}
|
||||
}
|
||||
Instruction::JumpWithOffset(_, _) => {}
|
||||
Instruction::RandomAnd(dest, n) => {
|
||||
self.registers.v[dest] = random::<u8>() & n;
|
||||
|
||||
Reference in New Issue
Block a user