-
Notifications
You must be signed in to change notification settings - Fork 0
/
chip8.h
60 lines (50 loc) · 1.15 KB
/
chip8.h
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
#ifndef CHIP8_H
#define CHIP8_H
#include <stdint.h>
#include <istream>
#include <random>
#include <tuple>
#include "memory.h"
#include "audio.h"
class Chip8
{
struct
{
uint16_t PC = 0x200;
uint16_t I;
uint8_t V[16];
uint8_t timerD, timerS;
uint8_t SP = 0;
uint8_t hp_48_flags[8];
} reg;
Memory<0x1000> memory; // 4KB
Audio audio;
static const unsigned int width = 64;
static const unsigned int height = 32;
static const unsigned int extWidth = width*2;
static const unsigned int extHeight = height*2;
uint8_t display[height][width];
uint8_t extDisplay[extHeight][extWidth];
bool extendedMode = false;
char *rom_file_name;
std::mt19937 rng;
void execute(uint16_t instruction);
void update_timers();
void print_registers();
void print_screen();
public:
Chip8() {
// TODO is this needed here?
rng.seed(std::random_device()());
}
void loadProgram(char *rom);
void reset();
void run();
void step();
std::tuple<unsigned int, unsigned int, uint8_t*> get_display();
unsigned int instructions_per_step = 10;
unsigned int scaleFactor = 20;
bool keys[16];
bool muted = false;
};
#endif