Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Emulator::callOpcode(int pos)
- {
- char byte1 = memory[pos];
- char byte2 = memory[pos + 1];
- opcode = (byte1 << 8) | byte2;
- char x;
- char y;
- switch(opcode & 0xF000)
- {
- case(0x0000):
- //Calls RCA 1802 program at address NNN.
- break;
- case(0x1000):
- //Jumps to address NNN.
- opcode_pos = opcode & 0x0FFF;
- break;
- case (0x2000):
- //Calls subroutine at NNN.
- callOpcode(opcode & 0x0FFF);
- break;
- case(0x6000):
- //Sets VX to NN.
- x = opcode & 0x0F00;
- registers[x] = opcode & 0x00FF;
- nextOpCode();
- break;
- case(0x7000):
- //Sets VX to NN.
- x = opcode & 0x0F00;
- registers[x] += (int)opcode &0x00FF;
- nextOpCode();
- break;
- case(0x8000):
- /*
- 8XY0 Sets VX to the value of VY.
- 8XY1 Sets VX to VX or VY.
- 8XY2 Sets VX to VX and VY.
- 8XY3 Sets VX to VX xor VY.
- 8XY4 Adds VY to VX. VF is set to 1 when there's a carry, and to 0 when there isn't.
- 8XY5 VY is subtracted from VX. VF is set to 0 when there's a borrow, and 1 when there isn't.
- 8XY6 Shifts VX right by one. VF is set to the value of the least significant bit of VX before the shift.[2]
- 8XY7 Sets VX to VY minus VX. VF is set to 0 when there's a borrow, and 1 when there isn't.
- */
- x = opcode & 0x0F00;
- y = opcode & 0x00F0;
- char *reg = ®isters[x];
- char *reg2 = ®isters[y];
- switch(opcode & 0x000F)
- {
- case 0x0000:
- *reg = *reg2;
- break;
- case 0x0001:
- *reg = *reg | *reg2;
- break;
- case 0x0002:
- *reg = *reg & *reg2;
- break;
- case 0x0003:
- *reg = *reg ^ *reg2;
- break;
- case 0x0004:
- *reg += *reg2;
- break;
- case 0x0005:
- *reg -= *reg2;
- break;
- case 0x0006:
- *reg = *reg >> 1;
- break;
- case 0x0007:
- *reg = *reg2 - *reg;
- break;
- case 0x0008:
- *reg = *reg << 1;
- break;
- }
- nextOpCode();
- break;
- }
- }
Add Comment
Please, Sign In to add comment