-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPPU.h
81 lines (70 loc) · 1.25 KB
/
PPU.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
#pragma once
#include <SFML/Graphics.hpp>
#include <cstdint>
#include <array>
namespace Display
{
struct Color {
Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
: r(red), g(green), b(blue), a(alpha)
{}
union {
uint32_t rgba;
struct {
uint8_t a;
uint8_t b;
uint8_t g;
uint8_t r;
};
};
};
enum class Palette {
Shade00,
Shade01,
Shade10,
Shade11,
Transparent
};
Color GetColor(uint8_t data);
Color GetColor(Palette p);
}
struct Obj {
uint8_t y;
uint8_t x;
uint8_t chr;
struct Attribute {
union {
uint8_t raw;
struct {
// Color pallete for CGB mode
unsigned cgb_palette : 3;
// Character bank for CGB mode
unsigned cgb_bank : 1;
// Select OBP0 or OBP1
unsigned palette : 1;
// Flip horizontal
unsigned horizontal_flip : 1;
// Flip vertical
unsigned vertical_flip : 1;
// Display priority flag
// set = BG priority
// clear = OBJ priority
unsigned priority : 1;
};
};
} attr;
};
using FrameBuffer = std::array<uint8_t, 160 * 144 * 4>;
class Bus;
class PPU {
public:
PPU(Bus* b);
void Reset();
void UpdateScreen(uint8_t cycles);
private:
void DrawLine();
private:
Bus* bus;
int16_t scanline_counter;
FrameBuffer* frameBuffer;
};