2023-09-09 17:57:57 +00:00
|
|
|
#ifndef CHIP8_INSTRUCTION_HANDLER_H
|
|
|
|
#define CHIP8_INSTRUCTION_HANDLER_H
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include "chip8.h"
|
|
|
|
#include "instruction.h"
|
|
|
|
|
2023-09-09 19:35:24 +00:00
|
|
|
/**
|
|
|
|
* The InstructionHandler class holds the Chip8 instruction set and all handlers
|
|
|
|
*/
|
2023-09-09 17:57:57 +00:00
|
|
|
class InstructionHandler {
|
|
|
|
private:
|
2023-09-09 19:35:24 +00:00
|
|
|
/**
|
|
|
|
* The typedef for the handler functions
|
|
|
|
*/
|
2023-09-09 18:20:10 +00:00
|
|
|
typedef void (*Handler)(Chip8&, Instruction);
|
2023-09-09 19:35:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Map which stores all instructions with their handler
|
|
|
|
*/
|
2023-09-09 17:57:57 +00:00
|
|
|
std::map<unsigned short, Handler> handlers = {};
|
2023-09-09 19:35:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles Chip8 instruction 0x0000, as well as 0x00E0 and 0x00EE
|
|
|
|
*/
|
2023-09-09 18:20:10 +00:00
|
|
|
static void handle0000(Chip8&, Instruction);
|
2023-09-09 19:35:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles Chip8 instruction 0x1000
|
|
|
|
*/
|
|
|
|
static void handle1000(Chip8&, Instruction);
|
2023-09-10 07:42:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles Chip8 instruction 0x2000
|
|
|
|
*/
|
|
|
|
static void handle2000(Chip8&, Instruction);
|
2023-09-10 07:48:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles Chip8 instruction 0x3000
|
|
|
|
*/
|
|
|
|
static void handle3000(Chip8&, Instruction);
|
2023-09-10 07:54:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles Chip8 instruction 0x4000
|
|
|
|
*/
|
|
|
|
static void handle4000(Chip8&, Instruction);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles Chip8 instruction 0x5000
|
|
|
|
*/
|
|
|
|
static void handle5000(Chip8&, Instruction);
|
2023-09-09 17:57:57 +00:00
|
|
|
public:
|
|
|
|
InstructionHandler();
|
2023-09-09 19:35:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempts to handle a chip8 instruction
|
|
|
|
* @param instructionNumber the 16-bit value to determine the instruction
|
|
|
|
* @param chip8 the Chip8 instance
|
|
|
|
* @param instruction the Instruction instance
|
|
|
|
*/
|
|
|
|
void handleInstruction(unsigned short instructionNumber, Chip8& chip8, Instruction instruction);
|
2023-09-09 17:57:57 +00:00
|
|
|
};
|
|
|
|
#endif //CHIP8_INSTRUCTION_HANDLER_H
|