From d2b66e9cb524df635e44b9853785c3e59857273e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com> Date: Sat, 18 Jun 2022 19:33:14 +0100 Subject: [PATCH] feat: initial instruction processing --- src/chip8_neo.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/chip8_neo.rs b/src/chip8_neo.rs index ab88193..3683ef2 100644 --- a/src/chip8_neo.rs +++ b/src/chip8_neo.rs @@ -59,7 +59,28 @@ impl Chip8Neo { } pub fn tick(&mut self) { + // fetches the current instruction and increments + // the PC (program counter) accordingly + let instruction = + (self.ram[self.pc as usize] as u16) << 8 | self.ram[self.pc as usize + 1] as u16; self.pc += 0x2; + + let opcode = instruction & 0xf000; + let address = instruction & 0x0fff; + let nibble = ((instruction & 0x0f00) >> 8) as u8; + let byte = (instruction & 0x00ff) as u8; + + match opcode { + 0x0000 => match byte { + 0xe0 => self.clear_screen(), + _ => println!("unimplemented instruction"), + }, + 0x1000 => self.pc = address, + 0x6000 => { + self.registers[nibble as usize] = byte; + } + _ => println!("unimplemented instruction"), + } } pub fn load_rom(&mut self, rom: &[u8]) { @@ -73,4 +94,8 @@ impl Chip8Neo { fn load_default_font(&mut self) { self.load_font(0, &FONT_SET); } + + fn clear_screen(&mut self) { + self.vram = [0u8; DISPLAY_WIDTH * DISPLAY_HEIGHT]; + } } -- GitLab