From e08895d35dc170314b28c2d14e99871b01416950 Mon Sep 17 00:00:00 2001 From: Tiger Date: Sun, 10 Sep 2023 09:54:54 +0200 Subject: [PATCH] Implemented 0x4XKK and 0x5XY0 --- include/instruction_handler.h | 10 ++++++++++ src/instruction_handler.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/instruction_handler.h b/include/instruction_handler.h index af82804..200f3dc 100644 --- a/include/instruction_handler.h +++ b/include/instruction_handler.h @@ -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(); diff --git a/src/instruction_handler.cpp b/src/instruction_handler.cpp index 4a27605..eb29375 100644 --- a/src/instruction_handler.cpp +++ b/src/instruction_handler.cpp @@ -6,6 +6,7 @@ InstructionHandler::InstructionHandler() { this->handlers[0x1000] = handle1000; this->handlers[0x2000] = handle2000; this->handlers[0x3000] = handle3000; + this->handlers[0x4000] = handle4000; } /** @@ -81,4 +82,30 @@ void InstructionHandler::handle3000(Chip8& chip8, Instruction instruction) { if (chip8.getRegister(instruction.x()) == instruction.kk()) { 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); + } } \ No newline at end of file