-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu.h
62 lines (50 loc) · 1.13 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
#ifndef CPU_H
#define CPU_H
#include "utils/type_alias.h"
#include "utils/string.h"
#include "utils/stack.h"
#include "renderer.h"
#include "keyboard.h"
#include "speaker.h"
#include <stdbool.h>
typedef enum {
CPU_NO_ERROR,
CPU_ERROR_INVALID_SELF,
CPU_ERROR_INVALID_INSTRUCTION,
CPU_ERROR_INVALID_PROGRAM,
} Cpu_Error;
typedef struct Cpu Cpu;
typedef struct {
bool (*run)(Cpu* cpu, u16 opcode);
} Cpu_Instruction;
typedef struct Cpu {
struct {
u8* memory;
u8* registers;
u16 i;
u16 delay_timer;
u16 sound_timer;
u16 pc; // program counter
Stack stack;
bool paused;
u8 speed;
};
bool valid;
bool has_valid_rom;
i32 error;
Cpu_Instruction* instructions;
u16 current_instruction;
Renderer* renderer;
Keyboard* keyboard;
Speaker* speaker;
} Cpu;
Cpu
Cpu_init(Renderer* renderer, Keyboard* keyboard, Speaker* speaker, u8 speed);
void
Cpu_load_program(Cpu* self, u8* program, size_t program_size);
// it will abort if invalid instruction found
void
Cpu_cycle(Cpu* self);
void
Cpu_deinit(Cpu* self);
#endif // CPU_H