Chip8-CPP/include/chip8.h

100 lines
2.1 KiB
C
Raw Permalink Normal View History

2023-09-09 17:57:57 +00:00
#ifndef CHIP8_CHIP8_H
#define CHIP8_CHIP8_H
#include <string>
#include <stack>
#include "display.h"
2023-09-09 17:57:57 +00:00
class InstructionHandler;
/**
* The main Chip8 used to emulate/interpret the Chip8 program
*/
2023-09-09 17:57:57 +00:00
class Chip8 {
private:
/**
* The memory of the Chip8 program
*/
2023-09-09 17:57:57 +00:00
unsigned char memory[0xFFF] = {};
/**
* The 16 general purpose 8-bit registers, generally used to store memory addresses
*/
2023-09-09 17:57:57 +00:00
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<unsigned short> stack{};
/**
* The program counter which holds the currently executing address
*/
2023-09-09 17:57:57 +00:00
unsigned short pc;
/**
* The Display object holding information and functions used for the display
*/
Display display;
/**
* The instruction handler used to handle instructions
*/
2023-09-09 17:57:57 +00:00
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
*/
2023-09-09 17:57:57 +00:00
void emulateCycle();
/**
* Pops a 16-bit value from the stack
* @return a unsigned 16-bit integer
*/
[[nodiscard]] unsigned short popFromStack();
2023-09-10 07:42:00 +00:00
void pushToStack(unsigned short value);
/**
* Sets the program counter (PC) to the given value
*/
void setProgramCounter(unsigned short value);
2023-09-10 07:42:00 +00:00
/**
* Gets the program counter (PC)
* @return
*/
[[nodiscard]] unsigned short getProgramCounter() const;
2023-09-10 07:48:26 +00:00
/**
* Gets a value from the register (V)
* @param i The index
* @return
*/
unsigned char getRegister(unsigned char i);
2023-09-15 19:24:13 +00:00
/**
* 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);
2023-09-09 17:57:57 +00:00
};
#endif //CHIP8_CHIP8_H