-
Notifications
You must be signed in to change notification settings - Fork 0
/
gb.h
108 lines (95 loc) · 1.45 KB
/
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
#pragma once
#include <cstdlib>
using namespace std;
typedef unsigned int u32;
typedef unsigned short u16;
typedef unsigned char u8;
typedef short i16;
typedef int i32;
typedef char i8;
typedef unsigned long long u64;
#ifdef _WIN32
void logf(char const* const format, ...);
#else
#define logf printf
#endif
//http://bgb.bircd.org/pandocs.htm
struct GB
{
//cpu state
struct {
union {
struct {
struct {
union {
struct {
u8 top : 4;
bool z : 1, n : 1, h : 1, c : 1;
};
u8 flags;
};
} f;
u8 a;
};
u16 af;
};
};
struct {
union {
struct {
u8 c, b;
};
u16 bc;
};
};
struct {
union {
struct {
u8 e, d;
};
u16 de;
};
};
struct {
union {
struct {
u8 l, h;
};
u16 hl;
};
};
u16 nn;
u16 sp, pc;
u8 memory[0x10000];
//hardware i/o state
struct Interrupt {
union {
u8 value;
struct {
bool vBlank : 1;
bool lcdStat : 1;
bool timer : 1;
bool serial : 1;
bool joypad : 1;
};
};
};
Interrupt interruptReg, interruptFlag;
bool interruptsEnabled;
//gpu state
struct GPU {
u8 lcdcStatus;
u8 mode;
u8 scanline;
u8 scanlinecompare;
u8 dmaRegister;
u16 modeclock;
u32 framebuffer[160 * 144];
} gpu;
//joypad input
u8 joypadInput;
bool stopped;
} extern gb;
const char* GB_disasm(u16 loc, u8& opcode, u16& nn, u8& opcodeLength);
void GB_load(u8* rom, u32 romLength);
bool GB_tick(i32& ticksElapsed);