From 398e6946df9a33ec672d4a73496b413c5bae90e0 Mon Sep 17 00:00:00 2001 From: rick Date: Wed, 9 Feb 2022 14:37:44 +0100 Subject: [PATCH] feat: support new instruction and fix bug --- src/main.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 14d146a..1713c0a 100644 --- a/src/main.rs +++ b/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);