-
Notifications
You must be signed in to change notification settings - Fork 21
/
aiv_gb.h
125 lines (104 loc) · 3.2 KB
/
aiv_gb.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
typedef unsigned char u8_t;
typedef signed char s8_t;
typedef unsigned short u16_t;
typedef signed short s16_t;
typedef unsigned int u32_t;
typedef unsigned long long u64_t;
#define ZERO 0x80
#define NEG 0x40
#define HALF 0x20
#define CARRY 0x10
#define CARTRIDGE_SIZE 32768
#define VRAM_SIZE 8192
#define RAM_SIZE 8192
#define EXTERNAL_RAM_SIZE 8192
typedef struct aiv_gameboy
{
// AF
union {
u16_t af;
struct
{
u8_t f;
u8_t a;
};
};
// BC
union {
u16_t bc;
struct
{
u8_t c;
u8_t b;
};
};
// DE
union {
u16_t de;
struct
{
u8_t e;
u8_t d;
};
};
// HL
union {
u16_t hl;
struct
{
u8_t l;
u8_t h;
};
};
u16_t pc;
u16_t sp;
u64_t ticks;
// opcodes table, each entry is a pointer to a function
int (*opcodes[256])(struct aiv_gameboy *);
int (*prefix_opcodes[256])(struct aiv_gameboy *);
u8_t (*memory_read[16])(struct aiv_gameboy *, u16_t);
void (*memory_write[16])(struct aiv_gameboy *, u16_t, u8_t);
u8_t cartridge[CARTRIDGE_SIZE];
u8_t vram[VRAM_SIZE];
u8_t external_ram[EXTERNAL_RAM_SIZE];
u8_t ram[RAM_SIZE];
} aiv_gameboy;
u8_t aiv_gb_memory_read8(aiv_gameboy *gb, u16_t address);
void aiv_gb_memory_write8(aiv_gameboy *gb, u16_t address, u8_t value);
u16_t aiv_gb_memory_read16(aiv_gameboy *gb, u16_t address);
void aiv_gb_memory_write16(aiv_gameboy *gb, u16_t address, u16_t value);
void aiv_gb_register_opcodes_00(aiv_gameboy *gb);
void aiv_gb_register_opcodes_10(aiv_gameboy *gb);
void aiv_gb_register_opcodes_20(aiv_gameboy *gb);
void aiv_gb_register_opcodes_30(aiv_gameboy *gb);
void aiv_gb_register_opcodes_40(aiv_gameboy *gb);
void aiv_gb_register_opcodes_50(aiv_gameboy *gb);
void aiv_gb_register_opcodes_60(aiv_gameboy *gb);
void aiv_gb_register_opcodes_70(aiv_gameboy *gb);
void aiv_gb_register_opcodes_80(aiv_gameboy *gb);
void aiv_gb_register_opcodes_90(aiv_gameboy *gb);
void aiv_gb_register_opcodes_a0(aiv_gameboy *gb);
void aiv_gb_register_opcodes_b0(aiv_gameboy *gb);
void aiv_gb_register_opcodes_c0(aiv_gameboy *gb);
void aiv_gb_register_opcodes_d0(aiv_gameboy *gb);
void aiv_gb_register_opcodes_e0(aiv_gameboy *gb);
void aiv_gb_register_opcodes_f0(aiv_gameboy *gb);
void aiv_gb_register_prefix_cb_00(aiv_gameboy *gb);
void aiv_gb_register_prefix_cb_10(aiv_gameboy *gb);
void aiv_gb_register_prefix_cb_20(aiv_gameboy *gb);
void aiv_gb_register_prefix_cb_30(aiv_gameboy *gb);
void aiv_gb_register_prefix_cb_40(aiv_gameboy *gb);
void aiv_gb_register_prefix_cb_50(aiv_gameboy *gb);
void aiv_gb_register_prefix_cb_60(aiv_gameboy *gb);
void aiv_gb_register_prefix_cb_70(aiv_gameboy *gb);
int aiv_gb_tick(aiv_gameboy *gb);
int aiv_gb_loop(aiv_gameboy *gb);
void aiv_gb_init(aiv_gameboy *gb);
void aiv_gb_set_flag(aiv_gameboy *gb, u8_t flag, u8_t value);
u8_t aiv_gb_get_flag(aiv_gameboy *gb, u8_t flag);
void aiv_gb_memory_init(aiv_gameboy *gb);
int aiv_gb_load_cartridge(aiv_gameboy *gb, const char *filename);
void aiv_gb_vram_to_rgb(aiv_gameboy *gb, u8_t *data);