Implemented 0x4XKK and 0x5XY0

main
Tiger 2023-09-10 09:54:54 +02:00
parent 8de34f6091
commit e08895d35d
2 changed files with 37 additions and 0 deletions

View File

@ -39,6 +39,16 @@ private:
* Handles Chip8 instruction 0x3000
*/
static void handle3000(Chip8&, Instruction);
/**
* Handles Chip8 instruction 0x4000
*/
static void handle4000(Chip8&, Instruction);
/**
* Handles Chip8 instruction 0x5000
*/
static void handle5000(Chip8&, Instruction);
public:
InstructionHandler();

View File

@ -6,6 +6,7 @@ InstructionHandler::InstructionHandler() {
this->handlers[0x1000] = handle1000;
this->handlers[0x2000] = handle2000;
this->handlers[0x3000] = handle3000;
this->handlers[0x4000] = handle4000;
}
/**
@ -82,3 +83,29 @@ void InstructionHandler::handle3000(Chip8& chip8, Instruction instruction) {
chip8.setProgramCounter(chip8.getProgramCounter() + 2);
}
}
/**
* Handles the 0x4XKK Chip8 instruction which is used to skip the next instruction if V[x] != kk.
* This will compare V[x] to kk and increases the program counter by 2 if they are not equal.
*
* @param chip8 The Chip8 instance
* @param instruction The Instruction instance
*/
void InstructionHandler::handle4000(Chip8& chip8, Instruction instruction) {
if (chip8.getRegister(instruction.x()) != instruction.kk()) {
chip8.setProgramCounter(chip8.getProgramCounter() + 2);
}
}
/**
* Handles the 0x5XY0 Chip8 instruction which is used to skip the next instruction if V[x] == V[y].
* This will compare V[x] to V[y] and increases the program counter by 2 if they are equal.
*
* @param chip8 The Chip8 instance
* @param instruction The Instruction instance
*/
void InstructionHandler::handle5000(Chip8& chip8, Instruction instruction) {
if (chip8.getRegister(instruction.x()) == chip8.getRegister(instruction.y())) {
chip8.setProgramCounter(chip8.getProgramCounter() + 2);
}
}