-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChip8.hpp
139 lines (71 loc) · 1.65 KB
/
Chip8.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <cstdint>
#include <random>
#include <array>
const unsigned int VIDEO_HEIGHT = 32;
const unsigned int VIDEO_WIDTH = 64;
class Chip8
{
public:
Chip8();
void LoadROM(const std::string& filename);
void Cycle();
std::array <uint8_t, 16> keypad{};
std::array <uint32_t, VIDEO_WIDTH* VIDEO_HEIGHT> video{};
private:
void Table0();
void Table8();
void TableE();
void TableF();
void OP_NULL();
void OP_00E0();
void OP_00EE();
void OP_1nnn();
void OP_2nnn();
void OP_3xkk();
void OP_4xkk();
void OP_5xy0();
void OP_6xkk();
void OP_7xkk();
void OP_8xy0();
void OP_8xy1();
void OP_8xy2();
void OP_8xy3();
void OP_8xy4();
void OP_8xy5();
void OP_8xy6();
void OP_8xy7();
void OP_8xyE();
void OP_9xy0();
void OP_Annn();
void OP_Bnnn();
void OP_Cxkk();
void OP_Dxyn();
void OP_Ex9E();
void OP_ExA1();
void OP_Fx07();
void OP_Fx0A();
void OP_Fx15();
void OP_Fx18();
void OP_Fx1E();
void OP_Fx29();
void OP_Fx33();
void OP_Fx55();
void OP_Fx65();
std::array <uint8_t, 4096> memory{};
std::array <uint8_t, 16> registers{};
uint16_t index{};
uint16_t pc{};
uint8_t delayTimer{};
uint8_t soundTimer{};
std::array <uint16_t, 16> stack{};
uint8_t sp{};
uint16_t opcode{};
std::default_random_engine randGen;
std::uniform_int_distribution<uint16_t> randByte;
using Chip8Func = void (Chip8::*)();
std::array <Chip8Func, 0xF + 1> table{};
std::array <Chip8Func, 0xE + 1> table0{};
std::array <Chip8Func, 0xE + 1> table8{};
std::array <Chip8Func, 0xE + 1> tableE{};
std::array <Chip8Func, 0x65 + 1> tableF{};
};