-
Notifications
You must be signed in to change notification settings - Fork 0
/
chip8.h
61 lines (49 loc) · 1.39 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
61
#ifndef CHIP8_H
#define CHIP8_H
#include <stdint.h>
#include "raylib.h"
typedef struct Chip8{
uint8_t v[16];
uint8_t ram[4096];
uint16_t pc;
uint16_t i;
uint16_t stack[16];
uint8_t sp;
uint8_t delayTimer;
uint8_t soundTimer;
uint8_t display[64][32];
uint8_t keypad[16];
uint16_t opcode;
uint8_t keyPressed;
} Chip8;
const static uint8_t font[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
};
const static int keys[16] = {
KEY_ONE, KEY_TWO, KEY_THREE, KEY_FOUR,
KEY_Q, KEY_W, KEY_E, KEY_R,
KEY_A, KEY_S, KEY_D, KEY_F,
KEY_Z, KEY_X, KEY_C, KEY_V
};
void loadRom(Chip8* chip8, const char* filename);
void init(Chip8* chip8);
void fetch(Chip8* chip8);
void execute(Chip8* chip8);
void updateScreen(Chip8* chip8, int scale);
void processInput(Chip8* chip8);
#endif