-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu.h
100 lines (66 loc) · 1.81 KB
/
cpu.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
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
#ifndef CPU_H
#define CPU_H
#include<cstdint>
#include <fstream>
#include <iostream>
#include <random>
#include <iomanip>
#include <sstream>
#include <string>
#include "logger.h"
#include "SDL2/SDL.h"
class CPU
{
public:
CPU();
int loadRom(char* filePath);
void start_log();
void end_log();
void emulateCycle();
bool isRunning() {return running;}
void handle_key_pressed(SDL_Scancode key_pressed);
void handle_key_released(SDL_Scancode key_released);
bool draw() {return draw_flag;}
void draw_screen();
void shutdown();
private:
unsigned char chip8_fontset[80] =
{
0xF0, 0x90, 0x90, 0x90, 0xF0, // 0
0x20, 0x60, 0x20, 0x20, 0x70, // 1
0xF0, 0x10, 0xF0, 0x80, 0xF0, // 2
0xF0, 0x10, 0xF0, 0x10, 0xF0, // 3
0x90, 0x90, 0xF0, 0x10, 0x10, // 4
0xF0, 0x80, 0xF0, 0x10, 0xF0, // 5
0xF0, 0x80, 0xF0, 0x90, 0xF0, // 6
0xF0, 0x10, 0x20, 0x40, 0x40, // 7
0xF0, 0x90, 0xF0, 0x90, 0xF0, // 8
0xF0, 0x90, 0xF0, 0x10, 0xF0, // 9
0xF0, 0x90, 0xF0, 0x90, 0x90, // A
0xE0, 0x90, 0xE0, 0x90, 0xE0, // B
0xF0, 0x80, 0x80, 0x80, 0xF0, // C
0xE0, 0x90, 0x90, 0x90, 0xE0, // D
0xF0, 0x80, 0xF0, 0x80, 0xF0, // E
0xF0, 0x80, 0xF0, 0x80, 0x80 // F
};
Logger logger;
SDL_Window* window = nullptr;
SDL_Renderer* renderer = nullptr;
SDL_Texture * texture = nullptr;
unsigned char memory[4096];
unsigned short pc;
unsigned char gfx[64* 32];
unsigned short I;
unsigned short stack[16];
unsigned short sp;
unsigned char delay_timer, sound_timer;
unsigned char V[16];
unsigned char keys[16];
unsigned short opcode;
bool running;
bool draw_flag;
void init_ram();
void init_gfx();
void update_timers();
};
#endif // CPU_H