-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpu.h
More file actions
79 lines (71 loc) · 1.39 KB
/
cpu.h
File metadata and controls
79 lines (71 loc) · 1.39 KB
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
#ifndef CPU_H
#define CPU_H
#include <SDL/SDL.h>
enum ERRORS {
ENONE = 0x0,
// pc overflow
EPCOF = 0x1,
// pc underflow
EPCUF = 0x2,
// stack overflow
ESTOF = 0x3,
// stack underflow
ESTUF = 0x4,
// bad opcode
EBDOP = 0x5,
// not implemented
ENIMP = 0x6,
// segmentation fault
ESEGV = 0x7,
// user quit
EUSRQ = 0x8,
};
enum chip8_key {
KEY_1 = 0x0001,
KEY_2 = 0x0002,
KEY_3 = 0x0004,
KEY_C = 0x0008,
KEY_4 = 0x0010,
KEY_5 = 0x0020,
KEY_6 = 0x0040,
KEY_D = 0x0080,
KEY_7 = 0x0100,
KEY_8 = 0x0200,
KEY_9 = 0x0400,
KEY_E = 0x0800,
KEY_A = 0x1000,
KEY_0 = 0x2000,
KEY_B = 0x4000,
KEY_F = 0x8000
};
enum boolean {
b_FALSE = 0,
b_TRUE = 1,
};
typedef struct {
uint8_t registers[16];
uint8_t delay;
uint8_t sound;
uint8_t stack_pointer;
uint16_t pc;
uint16_t stack[16];
uint8_t errno;
uint16_t address;
uint8_t screen[64][32];
uint8_t draw;
uint16_t keypad;
uint8_t* memory;
enum boolean wait;
uint16_t breakpoint;
enum boolean stepping;
} cpu_t;
void dump_state(cpu_t cpu,FILE* logfile);
cpu_t* new_cpu(void);
void free_cpu(cpu_t* cpu);
void heap_dump(cpu_t cpu);
void stack_trace(cpu_t cpu,FILE* logfile);
void step(cpu_t* cpu);
void cpu_load(FILE* from,cpu_t* cpu);
void cpu_run(cpu_t* cpu,SDL_Surface* screen);
void flip(uint8_t screen[64][32],unsigned int frameno);
#endif