Skip to content

Commit 232dba4

Browse files
LeviJacoby1991LeviJacoby1991
authored andcommitted
Define opcodes for switch statements
1 parent 7528695 commit 232dba4

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

chip8.cpp

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,45 @@ void chip8::emulateCycle(){
4242

4343
//switch decodes the opcode and then executes it in case body
4444
switch(opcode & 0xF000){
45+
case 0x1000: // 1NNN: Jumps to address NNN
46+
break;
47+
case 0x2000: // 2NNN: Calls subroutine at NNN
48+
break;
49+
case 0x3000: // 3XNN: skips the next instruction if VX == RR
50+
break;
51+
case 0x4000: // 4XNN: skips next instruction if VX != NN
52+
break;
53+
case 0x5000: // 5XY0: skips next instruction if VX == VY
54+
break;
55+
case 0x6000: // 6XNN: sets VX to NN (VX = NN)
56+
break;
57+
case 0x7000: // 7XNN: Adds NN to VX (Carry flag is not changed)
58+
break;
59+
case 0x8000: //8 has multiiple instructions will need inner switch statement
60+
switch(opcode & 0x000F){
61+
case 0x0000: // 8XY0: sets VX to the value of VY
62+
break;
63+
case 0x0001: // 8XY1: set VX to VX or VY (Bitwise OR)
64+
break;
65+
case 0x0002: // 8XY2: set VX to VX and VY (Bitwise AND)
66+
break;
67+
case 0x0003: // 8XY3: sets VX to VX xor VY
68+
break;
69+
case 0x0004: // 8XY4: adds VY to VX and sets VF to 1 if theres a carry and 0 otherwise
70+
break;
71+
case 0x0005: // 8XY5: Subtracts VY from VX VF is set to 0 when theres a borrow and 1 otherwise
72+
break;
73+
case 0x0006: // 8XY6: Store the least significant bit of VX in VF and shift VX to the right by 1
74+
break;
75+
case 0x0007: // 8XY7: Sets VX to VY minus VX. VF is set to 0 when theres a borrow and 1 when there isn't
76+
break;
77+
case 0x000E: // 8XYE: Stores the most significant bit of VX in VF and shifts VX to the left by 1
78+
default:
79+
std::cout << "Unknown opcode " << std::hex << opcode;
80+
}
81+
break;
82+
case 0x9000:
83+
break;
4584
case 0xA000: // ANNN: Sets IR to the Adress NNN
4685
//execute
4786
IR = opcode & 0x0FFF;
@@ -51,7 +90,16 @@ void chip8::emulateCycle(){
5190
//execute
5291
PC = V[0] ^ (opcode & 0xFFF);
5392
break;
54-
//in the event we cant rely on the first four bits to see what the opcode means
93+
case 0xC000: // CXNN: Sets VX to the result of a bitwise AND operation on a random number (0 to 255) and NN
94+
break;
95+
case 0xD000: // DXYN draws a sprite at cord (VX, VY), had width of 8 pixels and height of N pixels see wiki for a more detailed explanation
96+
break;
97+
case 0xE000: // Need inner switch Statement
98+
99+
break;
100+
case 0xF000: // Need inner switch Statement
101+
102+
break;
55103
case 0x0000:
56104
switch(opcode & 0x000F){
57105
case 0x0000: // 0x00E0: Clears the Screen

0 commit comments

Comments
 (0)