feat: support new instruction and fix bug
This commit is contained in:
parent
cf7807945c
commit
398e6946df
1 changed files with 15 additions and 5 deletions
20
src/main.rs
20
src/main.rs
|
@ -42,7 +42,7 @@ const WIDTH: usize = 64;
|
|||
#[allow(dead_code)]
|
||||
struct Machine {
|
||||
memory: [u8; 4096],
|
||||
key_inputs: [i32; 16],
|
||||
key_inputs: [u8; 16],
|
||||
display_buffer: [[i32; WIDTH]; HEIGHT],
|
||||
gpio: [u8; 16],
|
||||
index: u16,
|
||||
|
@ -147,7 +147,11 @@ impl Machine {
|
|||
self.gpio[0xf] = 0;
|
||||
}
|
||||
|
||||
self.gpio[vx] -= self.gpio[vy];
|
||||
//let tmp: i32 = (self.gpio[vx] - self.gpio[vy]) as i32;
|
||||
//self.gpio[vx] = (tmp & 0x00ff) as u8;
|
||||
//self.gpio[vx] = self.gpio[vy];
|
||||
let (t, _) = self.gpio[vx].overflowing_sub(self.gpio[vy]);
|
||||
self.gpio[vx] = t;
|
||||
},
|
||||
6 => {
|
||||
if self.gpio[vx].trailing_ones() > 0 {
|
||||
|
@ -210,7 +214,7 @@ impl Machine {
|
|||
}
|
||||
},
|
||||
0xE => {
|
||||
let x = (opcode & 0x0f00) >> 8;
|
||||
//let x = (opcode & 0x0f00) >> 8;
|
||||
match opcode & 0x00ff {
|
||||
0x9E => {
|
||||
if self.key_inputs[self.gpio[vx] as usize] == 1 {
|
||||
|
@ -234,7 +238,11 @@ impl Machine {
|
|||
0x18 => println!("LD F 18"),
|
||||
0x1E => self.index += self.gpio[vx] as u16,
|
||||
0x29 => self.index = (self.gpio[vx] as u16) * 5, // self.index = self.gpio[x] * 5) & 0x0fff
|
||||
0x33 => println!("LD F 3"),
|
||||
0x33 => {
|
||||
self.memory[self.index as usize] = self.gpio[vx] / 100 as u8;
|
||||
self.memory[(self.index + 1) as usize] = (self.gpio[vx] % 100) /10 as u8;
|
||||
self.memory[(self.index + 2) as usize] = self.gpio[vx] % 10 as u8;
|
||||
},
|
||||
0x55 =>
|
||||
{
|
||||
//let mut j: usize = self.index as usize;
|
||||
|
@ -409,7 +417,9 @@ fn main() {
|
|||
//println!("{:?}", t.memory);
|
||||
t.init();
|
||||
//t.loadRom(Path::new("15PUZZLE"));
|
||||
t.loadRom(Path::new("BLITZ"));
|
||||
t.loadRom(Path::new("BLINKY"));
|
||||
//t.loadRom(Path::new("GUESS"));
|
||||
//t.loadRom(Path::new("BLITZ"));
|
||||
|
||||
//println!("\n\n{:?}", t.memory);
|
||||
|
||||
|
|
Loading…
Reference in a new issue