Skip to content

Commit 1210e0d

Browse files
LeviJacoby1991LeviJacoby1991
authored andcommitted
implemented opcode BNNN
1 parent 56bfbe6 commit 1210e0d

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

chip8.cpp

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

4343
//switch decodes the opcode and then executes it in case body
4444
switch(opcode & 0xF000){
45-
case 0xA000:
45+
case 0xA000: // ANNN: Sets IR to the Adress NNN
46+
//execute
4647
IR = opcode & 0x0FFF;
4748
PC += 2;
4849
break;
50+
case 0xB000: // BNNN: Jumps to adress NNN plus V0;
51+
//execute
52+
PC = V[0] ^ (opcode & 0xFFF);
53+
break;
54+
//in the event we cant rely on the first four bits to see what the opcode means
55+
case 0x0000:
56+
switch(opcode & 0x000F){
57+
case 0x0000: // 0x00E0: Clears the Screen
58+
//execute
59+
PC += 2;
60+
break;
61+
case 0x000E: // 0x00EE: Returns from sub-routine
62+
//execute
63+
PC += 2;
64+
break;
65+
default:
66+
std::cout << "Unkown opcode " << std::hex << opcode;
67+
}
4968
default:
5069
std::cout << "Unkown opcode: " << std::hex << opcode;
5170
}
71+
72+
if(delay_timer > 0)
73+
--delay_timer;
74+
if(sound_timer > 0){
75+
if(sound_timer == 1){
76+
//sound is played
77+
}
78+
--sound_timer;
79+
}
5280
}
5381

5482
void chip8::setKeys(){

0 commit comments

Comments
 (0)