From 80053eeda720123123983068dc917e8fc7702f3a Mon Sep 17 00:00:00 2001 From: Tiger Date: Fri, 15 Sep 2023 21:24:13 +0200 Subject: [PATCH] Implemented 0x6XKK --- include/chip8.h | 8 ++++++++ include/instruction_handler.h | 5 +++++ src/chip8.cpp | 4 ++++ src/instruction_handler.cpp | 14 +++++++++++++- 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/include/chip8.h b/include/chip8.h index 4e7e126..56fc41f 100644 --- a/include/chip8.h +++ b/include/chip8.h @@ -87,5 +87,13 @@ public: * @return */ unsigned short getRegister(unsigned char i); + + /** + * Sets a value in the register (V) + * + * @param i The index of the register to set + * @param value The value to be set + */ + void setRegister(unsigned char i, unsigned short value); }; #endif //CHIP8_CHIP8_H diff --git a/include/instruction_handler.h b/include/instruction_handler.h index 200f3dc..f7e253a 100644 --- a/include/instruction_handler.h +++ b/include/instruction_handler.h @@ -49,6 +49,11 @@ private: * Handles Chip8 instruction 0x5000 */ static void handle5000(Chip8&, Instruction); + + /** + * Handles Chip8 instruction 0x6000 + */ + static void handle6000(Chip8&, Instruction); public: InstructionHandler(); diff --git a/src/chip8.cpp b/src/chip8.cpp index 3560831..0f21a5c 100644 --- a/src/chip8.cpp +++ b/src/chip8.cpp @@ -69,3 +69,7 @@ unsigned short Chip8::getProgramCounter() const { unsigned short Chip8::getRegister(unsigned char reg) { return this->v[reg]; } + +void Chip8::setRegister(unsigned char reg, unsigned short value) { + this->v[reg] = value; +} diff --git a/src/instruction_handler.cpp b/src/instruction_handler.cpp index eb29375..e13e415 100644 --- a/src/instruction_handler.cpp +++ b/src/instruction_handler.cpp @@ -7,6 +7,8 @@ InstructionHandler::InstructionHandler() { this->handlers[0x2000] = handle2000; this->handlers[0x3000] = handle3000; this->handlers[0x4000] = handle4000; + this->handlers[0x5000] = handle5000; + this->handlers[0x6000] = handle6000; } /** @@ -108,4 +110,14 @@ 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 +} + +/** + * Handles the 0x6XKK Chip8 instruction which is used to put value KK in register V[x]. + * + * @param chip8 The Chip8 instance + * @param instruction The Instruction instance + */ +void InstructionHandler::handle6000(Chip8& chip8, Instruction instruction) { + chip8.setRegister(instruction.x(), instruction.kk()); +}