#ifndef CHIP8_CHIP8_H #define CHIP8_CHIP8_H #include #include #include "display.h" class InstructionHandler; /** * The main Chip8 used to emulate/interpret the Chip8 program */ class Chip8 { private: /** * The memory of the Chip8 program */ unsigned char memory[0xFFF] = {}; /** * The 16 general purpose 8-bit registers, generally used to store memory addresses */ unsigned char v[0x10] = {}; /** * Stack of 16-bit values, used to store addresses the interpreter should return to when finished with a subroutine */ std::stack stack{}; /** * The program counter which holds the currently executing address */ unsigned short pc; /** * The Display object holding information and functions used for the display */ Display display; /** * The instruction handler used to handle instructions */ InstructionHandler* instructionHandler; public: Chip8(); ~Chip8(); /** * Loads a rom in the memory * @param rom The rom to be loaded in the memory */ void loadRom(const std::string& rom); /** * Gets the Display object * @return */ [[nodiscard]] Display getDisplay() const; /** * Cycle to handle the next instruction */ void emulateCycle(); /** * Pops a 16-bit value from the stack * @return a unsigned 16-bit integer */ [[nodiscard]] unsigned short popFromStack(); void pushToStack(unsigned short value); /** * Sets the program counter (PC) to the given value */ void setProgramCounter(unsigned short value); /** * Gets the program counter (PC) * @return */ [[nodiscard]] unsigned short getProgramCounter() const; /** * Gets a value from the register (V) * @param i The index * @return */ unsigned char 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 char value); }; #endif //CHIP8_CHIP8_H