-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchip8.hpp
122 lines (92 loc) · 3.01 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
/**
MIT License
Copyright (c) 2021 Matthieu Le Gallic
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef CHIP8_HPP_INCLUDED
#define CHIP8_HPP_INCLUDED
#include <string>
#define CHIP_W 64
#define CHIP_H 32
#define CHIP_WH 2048
#define SCHIP_W 128
#define SCHIP_H 64
#define SCHIP_WH 8192
#define MAXSIZE 65024
class Chip8 {
public:
//Opcode
uint16_t opcode;
//Memory
uint8_t memory[65535];
//Registers
uint8_t v[16];
uint16_t I;
uint16_t pc;
//Graphics bitplanes
bool gfx[2][SCHIP_WH];
uint8_t bitPlane;
//Color palette
uint8_t palette[4][3];
//Timers
uint8_t delayTimer;
uint8_t soundTimer;
//XO-Chip audio buffer
uint8_t audioBuffer[16];
//Stack
uint16_t stck[16];
uint8_t sp;
//SCHIP user flags
uint8_t userFlags[8];
//Keys
bool keys[16];
uint8_t waitRegister = 0;
bool waiting = false;
//SCHIP hi-res mode
bool hiRes;
//Interpreter stopped
bool stopped;
//ROM loaded
bool loaded;
//CHIP-8 font sprites
uint8_t *fontSet;
//CHIP extensions quirks
bool loadStoreQuirk; //FX55 FX65 behavior
bool shiftQuirk; //Shift instructions behavior
bool hiresClearQuirk; //Clear screen on resolution change (SCHIP and XOCHIP only)
bool wrapQuirk; //Sprites wrap around screen boundariess
//Game information
uint32_t tickRate = 100;
Chip8();
void initialize();
void unknownOpcode(uint16_t);
uint8_t loadROM(std::string);
uint8_t loadPalette(std::string);
uint8_t checkKeys();
void updateTimers();
uint8_t nextByte();
uint16_t nextWord();
void skipNextInstruction();
void scrollLeft(uint8_t);
void scrollRight(uint8_t);
void scrollUp(uint8_t);
void scrollDown(uint8_t);
void pixel(uint8_t, uint8_t, uint8_t);
void emulateInstruction();
void printInstruction(uint16_t, uint16_t);
};
#endif // CHIP8_HPP_INCLUDED