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