Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- switch (opcode & 0xF000) {
- // this opcode jumps to address NNN
- case 0x1000:
- PC = opcode & 0x0FFF;
- break;
- // this one calls a subroutine and stores the return in the stack
- case 0x2000:
- stack[++SP] = PC;
- PC = opcode & 0x0FFF;
- break;
- // If VX == NN then skip the next instruction, the opcode it 0x3XNN
- case 0x3000:
- if (V[(opcode & 0x0F00) >>> 8] == (opcode & 0x00FF)) {
- PC += 4;
- } else {
- PC += 2;
- }
- break;
- // If VX != NN then skip the next instruction, the opcode is 0x3XNN
- case 0x4000:
- if (V[(opcode & 0x0F00) >>> 0x0008] != (opcode & 0x00FF)) {
- PC += 4;
- } else {
- PC += 2;
- }
- break;
- // we are comparing VX and VY, if they match then skip, the opcode is 5XY0
- case 0x5000:
- if (V[(opcode & 0x0F00) >>> 0x0008] == V[(opcode & 0x00F0) >>> 0x0004]) {
- PC += 4;
- } else {
- PC += 2;
- }
- break;
- // Set register VX to NN, opcode is 6XNN
- case 0x6000:
- V[(opcode & 0x0F00) >>> 0x0008] = (opcode & 0x00FF);
- PC += 2;
- break;
- // add value NN to register VX, opcode is 7XNN
- case 0x7000:
- V[(opcode & 0x0F00) >>> 8] += (opcode & 0x00FF);
- if ((V[(opcode & 0x0F00) >>> 8] >= 256)) {
- V[(opcode & 0x0F00) >>> 8] -= 256;
- }
- PC += 2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement