-
Notifications
You must be signed in to change notification settings - Fork 0
/
chip8.h
81 lines (48 loc) · 1.25 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "screen.h"
#define FONTSET_SIZE 80
#define MEMORY_SIZE 4096
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <assert.h>
struct Chip8St{
// 2 Bytes words opcodes
unsigned short opcode;
// Memory of 4 KiB with 1 Byte words.
unsigned char memory[MEMORY_SIZE];
// 16 registers of 1 Bytes.
unsigned char V[16];
// memory index and PC, 0x000 - 0xFFF (0 to 4095)
unsigned short I;
unsigned short pc;
// screen
unsigned char gfx[HEIGHT * WIDTH];
// interrupt timers
unsigned char delay_timer;
unsigned char sound_timer;
// stack
unsigned short stack[16];
unsigned short sp;
// keyboard
unsigned char key[16];
// draw againg?
bool draw;
// ROM size
long size_ROM;
};
typedef struct Chip8St * Chip8;
Chip8 create_chip8();
Chip8 destroy_chip8(Chip8 emu);
void relase_keys(Chip8 emu);
void load_fontset(Chip8 emu);
void clear_stack(Chip8 emu);
void clear_regs(Chip8 emu);
void clear_memory(Chip8 emu);
void init_chip8(Chip8 emu);
void fetch_opcode(Chip8 emu);
void increment_pc(Chip8 emu);
void skip_instruction(Chip8 emu);
void decode_and_execute_opcode(Chip8 emu);
void update_timers(Chip8 emu);
void emulation_cycle(Chip8 emu);
bool load_ROM(Chip8 emu, const char * filename);