Commit Diff


commit - 99fe3efb3ea80a426968ccbb29a2e513727e7e83
commit + 0867526a43a25c34561967b854d40ce32ab6d174
blob - 2626728f30bab72976e1f8c69674f6525d317daf
blob + 57d0136c7ccfbf290ae6c5a25dbe8272db144dbb
--- src/chip8.rs
+++ src/chip8.rs
@@ -45,19 +45,28 @@ impl Chip8 {
 
     /// Execute a given instruction.
     pub fn execute(&mut self, instruction: u16) -> Result<(), String> {
-        match instruction {
-            // CLS
-            0x00E0 => {
-                self.video_driver.clear();
+        match instruction & 0xF000 {
+            0x0 => match instruction & 0x0FFF {
+                // CLS
+                0x0E0 => {
+                    self.video_driver.clear();
+                },
+                // RET
+                0x0EE => {
+                    self.pc = match self.stack.pop() {
+                        Some(s) => s,
+                        None => {
+                            return Err(format!("pop from empty stack"));
+                        }
+                    };
+                },
+                _ => {
+                    return Err(format!("{:#06x}: not an instruction", instruction));
+                }
             },
-            // RET
-            0x00EE => {
-                self.pc = match self.stack.pop() {
-                    Some(s) => s,
-                    None => {
-                        return Err(format!("pop from empty stack"));
-                    }
-                };
+            // JP
+            0x1 => {
+                self.pc = instruction & 0x0FFF;
             },
             _ => {
                 return Err(format!("{:#06x}: not an instruction", instruction));