Implemented 0x6XKK

main
Tiger 2023-09-15 21:24:13 +02:00
parent e08895d35d
commit 80053eeda7
4 changed files with 30 additions and 1 deletions

View File

@ -87,5 +87,13 @@ public:
* @return * @return
*/ */
unsigned short getRegister(unsigned char i); 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 #endif //CHIP8_CHIP8_H

View File

@ -49,6 +49,11 @@ private:
* Handles Chip8 instruction 0x5000 * Handles Chip8 instruction 0x5000
*/ */
static void handle5000(Chip8&, Instruction); static void handle5000(Chip8&, Instruction);
/**
* Handles Chip8 instruction 0x6000
*/
static void handle6000(Chip8&, Instruction);
public: public:
InstructionHandler(); InstructionHandler();

View File

@ -69,3 +69,7 @@ unsigned short Chip8::getProgramCounter() const {
unsigned short Chip8::getRegister(unsigned char reg) { unsigned short Chip8::getRegister(unsigned char reg) {
return this->v[reg]; return this->v[reg];
} }
void Chip8::setRegister(unsigned char reg, unsigned short value) {
this->v[reg] = value;
}

View File

@ -7,6 +7,8 @@ InstructionHandler::InstructionHandler() {
this->handlers[0x2000] = handle2000; this->handlers[0x2000] = handle2000;
this->handlers[0x3000] = handle3000; this->handlers[0x3000] = handle3000;
this->handlers[0x4000] = handle4000; this->handlers[0x4000] = handle4000;
this->handlers[0x5000] = handle5000;
this->handlers[0x6000] = handle6000;
} }
/** /**
@ -109,3 +111,13 @@ void InstructionHandler::handle5000(Chip8& chip8, Instruction instruction) {
chip8.setProgramCounter(chip8.getProgramCounter() + 2); chip8.setProgramCounter(chip8.getProgramCounter() + 2);
} }
} }
/**
* 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());
}