-
Notifications
You must be signed in to change notification settings - Fork 6
/
CookieboyCPU.h
105 lines (84 loc) · 1.94 KB
/
CookieboyCPU.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
#ifndef COOKIEBOYCPU_H
#define COOKIEBOYCPU_H
#include "CookieboyDefs.h"
//#define DEBUG_PRINTCPU
#ifdef DEBUG_PRINTCPU
#define PRINT_INSTRUCTION sprintf_s
#else
#define PRINT_INSTRUCTION(...)
#endif
namespace Cookieboy
{
class Memory;
class GPU;
class DividerTimer;
class TIMATimer;
class Joypad;
class Sound;
class SerialIO;
class Interrupts;
class SpeedSwitcher;
/*
The GameBoy uses a computer chip similar to an Intel 8080. It contains all of the instructions of an 8080
except there are no exchange instructions. In many ways the processor is more similar to the Zilog Z80
processor. Compared to the Z80, some instructions have been added and some have been taken away
*/
class CPU
{
public:
/*
Needed for combined registers i.e. BC, DE
Provides easy way to access individual bytes as well as whole 16-bit register
*/
union WordRegister
{
struct
{
BYTE L;
BYTE H;
} bytes;
WORD word;
};
CPU(const bool &CGB, bool &_CGBDoubleSpeed, SpeedSwitcher &speedSwitcher, Memory &MMU, GPU &GPU, DividerTimer &DIV, TIMATimer &TIMA, Joypad &joypad, Sound &sound, SerialIO &serial, Interrupts &INT);
void Step();
void Reset();
void EmulateBIOS();
friend class Interrupts;
private:
BYTE MemoryRead(WORD addr);
WORD MemoryReadWord(WORD addr);
void MemoryWrite(WORD addr, BYTE value);
void MemoryWriteWord(WORD addr, WORD value);
void INTJump(WORD address);
//CPU Microcode
void StackPushByte(BYTE value);
void StackPushWord(WORD value);
BYTE StackPopByte();
WORD StackPopWord();
const bool &CGB;
bool &CGBDoubleSpeed;
//CPU registers
BYTE A;
BYTE F;//Flags register - ZNHC0000
WordRegister BC;
WordRegister DE;
WordRegister HL;
WORD PC;
WORD SP;
BYTE IME;//Interrupt master enable register
bool Halted;
bool HaltBug;
BYTE DIDelay;
BYTE EIDelay;
SpeedSwitcher &CGBSpeedSwitcher;
Memory &MMU;
GPU &GPU;
DividerTimer ÷
TIMATimer &TIMA;
Joypad &Joypad;
Sound &Sound;
SerialIO &Serial;
Interrupts ∫
};
}
#endif