commit 0a7f71f87659d462e65e5bd93676f449a510572d from: Witcher01 date: Sun Aug 1 17:18:06 2021 UTC added instruction CALL commit - 0867526a43a25c34561967b854d40ce32ab6d174 commit + 0a7f71f87659d462e65e5bd93676f449a510572d blob - 57d0136c7ccfbf290ae6c5a25dbe8272db144dbb blob + 5eb4797855ab2813d2ab84f03f306b91fc948005 --- src/chip8.rs +++ src/chip8.rs @@ -45,8 +45,9 @@ impl Chip8 { /// Execute a given instruction. pub fn execute(&mut self, instruction: u16) -> Result<(), String> { + let nnn = instruction & 0x0FFF; match instruction & 0xF000 { - 0x0 => match instruction & 0x0FFF { + 0x0 => match nnn { // CLS 0x0E0 => { self.video_driver.clear(); @@ -66,8 +67,13 @@ impl Chip8 { }, // JP 0x1 => { - self.pc = instruction & 0x0FFF; + self.pc = nnn; }, + // CALL + 0x2 => { + self.stack.push(self.pc + 1); + self.pc = nnn; + }, _ => { return Err(format!("{:#06x}: not an instruction", instruction)); }