started work on the CHIP-8 interpreter
This commit is contained in:
51
Interpreter.hpp
Normal file
51
Interpreter.hpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "Peripherals.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <stack>
|
||||
|
||||
namespace chocochip8 {
|
||||
|
||||
class Interpreter {
|
||||
public:
|
||||
constexpr static uint16_t scResetVector = 0x0200;
|
||||
constexpr static size_t scMemorySize = 4096;
|
||||
|
||||
private:
|
||||
enum {
|
||||
R_V0, R_V1, R_V2, R_V3, R_V4, R_V5, R_V6, R_V7,
|
||||
R_V8, R_V9, R_VA, R_VB, R_VC, R_VD, R_VE, R_VF,
|
||||
R_COUNT
|
||||
};
|
||||
|
||||
enum {
|
||||
SR_PC, SR_I, SR_T1, SR_T2,
|
||||
SR_COUNT
|
||||
};
|
||||
|
||||
enum class Opcode {
|
||||
SET, ADD, SUB, SUB2, AND, OR, XOR, LSH, RSH, RAND, JEQ, JNEQ, UNIMPL
|
||||
};
|
||||
|
||||
public:
|
||||
Interpreter(unsigned ticksPerSecond, Display &display, Buzzer &buzzer, Keypad &keypad);
|
||||
void tick();
|
||||
void loadProgram(uint16_t where, char const* data, size_t count);
|
||||
|
||||
private:
|
||||
void executeArithmetic(Opcode opcode, int iReg, uint8_t operand);
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> mvMemory;
|
||||
std::stack<uint16_t> mCallStack;
|
||||
Display &mrDisplay;
|
||||
Buzzer &mrBuzzer;
|
||||
Keypad &mrKeypad;
|
||||
const unsigned mcTicksPerSecond;
|
||||
unsigned mvSpecialReg[SR_COUNT];
|
||||
uint8_t mvReg[R_COUNT];
|
||||
}; // class Interpreter
|
||||
|
||||
}; // namespace chocohip8
|
||||
Reference in New Issue
Block a user