Advertisement
Guest User

My 1-7 opcodes

a guest
May 26th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. switch (opcode & 0xF000) {
  2.  
  3.         // this opcode jumps to address NNN
  4.         case 0x1000:
  5.             PC = opcode & 0x0FFF;
  6.  
  7.             break;
  8.         // this one calls a subroutine and stores the return in the stack
  9.         case 0x2000:
  10.             stack[++SP] = PC;
  11.            
  12.             PC = opcode & 0x0FFF;
  13.             break;
  14.         // If VX == NN then skip the next instruction, the opcode it 0x3XNN
  15.         case 0x3000:
  16.  
  17.             if (V[(opcode & 0x0F00) >>> 8] == (opcode & 0x00FF)) {
  18.                 PC += 4;
  19.             } else {
  20.                 PC += 2;
  21.             }
  22.             break;
  23.         // If VX != NN then skip the next instruction, the opcode is 0x3XNN
  24.         case 0x4000:
  25.  
  26.             if (V[(opcode & 0x0F00) >>> 0x0008] != (opcode & 0x00FF)) {
  27.                 PC += 4;
  28.             } else {
  29.                 PC += 2;
  30.             }
  31.             break;
  32.         // we are comparing VX and VY, if they match then skip, the opcode is 5XY0
  33.         case 0x5000:
  34.  
  35.             if (V[(opcode & 0x0F00) >>> 0x0008] == V[(opcode & 0x00F0) >>> 0x0004]) {
  36.                 PC += 4;
  37.             } else {
  38.                 PC += 2;
  39.             }
  40.             break;
  41.         // Set register VX to NN, opcode is 6XNN
  42.         case 0x6000:
  43.             V[(opcode & 0x0F00) >>> 0x0008] = (opcode & 0x00FF);
  44.  
  45.             PC += 2;
  46.             break;
  47.  
  48.         // add value NN to register VX, opcode is 7XNN
  49.         case 0x7000:
  50.             V[(opcode & 0x0F00) >>> 8] += (opcode & 0x00FF);
  51.             if ((V[(opcode & 0x0F00) >>> 8] >= 256)) {
  52.                 V[(opcode & 0x0F00) >>> 8] -= 256;
  53.             }
  54.  
  55.             PC += 2;
  56.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement