-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPU.h
More file actions
76 lines (65 loc) · 1.8 KB
/
Copy pathCPU.h
File metadata and controls
76 lines (65 loc) · 1.8 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
#include <stdint.h>
#include <stdio.h>
#include <SDL2/SDL.h>
#include "MMU.h"
#include "utils.h"
#ifndef CPU_H
#define CPU_H
class CPU {
public:
CPU (MMU* _mmu);
void Clock ();
void Debug ();
void Interrupt (uint8_t ID);
uint32_t ClockCount = 0;
uint32_t InstructionCount = 0;
uint8_t Debugging = 0;
private:
MMU* mmu;
void Execute (uint8_t Instruction);
// Registers
uint16_t reg_AF = 0;
uint8_t* reg_A = ((uint8_t*) ®_AF) + 1;
uint8_t* reg_F = ((uint8_t*) ®_AF); // Flags - Z N H C 0 0 0 0
uint16_t reg_BC = 0;
uint8_t* reg_B = ((uint8_t*) ®_BC) + 1;
uint8_t* reg_C = ((uint8_t*) ®_BC);
uint16_t reg_DE = 0;
uint8_t* reg_D = ((uint8_t*) ®_DE) + 1;
uint8_t* reg_E = ((uint8_t*) ®_DE);
uint16_t reg_HL = 0;
uint8_t* reg_H = ((uint8_t*) ®_HL) + 1;
uint8_t* reg_L = ((uint8_t*) ®_HL);
uint16_t SP = 0;
uint16_t PC = 0;
// Flags - For Convenience
uint8_t flag_Z = 0;
uint8_t flag_N = 0;
uint8_t flag_H = 0;
uint8_t flag_C = 0;
// Temporary Vars
int8_t i8 = 0;
int16_t i16 = 0;
uint8_t u8 = 0;
uint16_t u16 = 0;
// Status
uint8_t Halt = 0;
uint8_t Stopped = 0;
uint8_t EnableInterruptsFlag = 0;
uint8_t InterruptsEnabled = 0;
// Functions - Convenience
uint8_t GetM (); // M = Value in memory pointed by reg_HL
void SetM (uint8_t Value);
// Functions - Stack
void StackPush (uint16_t Value);
uint16_t StackPop ();
// Functions - Flags
void SetZ (uint8_t Value);
void SetN (uint8_t Value);
void SetH (uint8_t Value);
void SetC (uint8_t Value);
uint8_t GetCarry (uint16_t OpA, uint16_t OpB, uint8_t Carry, uint8_t BitNo);
void SetFlagsAdd (uint8_t OpA, uint8_t OpB, uint8_t Carry, uint8_t CarrySetMode);
void SetFlagsSub (uint8_t OpA, uint8_t OpB, uint8_t Carry, uint8_t CarrySetMode);
};
#endif