Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/gameboy/video/video.cpp
2 views
1
#include <gameboy/gameboy.hpp>
2
3
#define VIDEO_CPP
4
namespace GameBoy {
5
6
Video video;
7
8
unsigned Video::palette_dmg(unsigned color) const {
9
unsigned R = monochrome[color][0] * 1023.0;
10
unsigned G = monochrome[color][1] * 1023.0;
11
unsigned B = monochrome[color][2] * 1023.0;
12
13
return (R << 20) + (G << 10) + (B << 0);
14
}
15
16
unsigned Video::palette_sgb(unsigned color) const {
17
unsigned R = (3 - color) * 341;
18
unsigned G = (3 - color) * 341;
19
unsigned B = (3 - color) * 341;
20
21
return (R << 20) + (G << 10) + (B << 0);
22
}
23
24
unsigned Video::palette_cgb(unsigned color) const {
25
unsigned r = (color >> 0) & 31;
26
unsigned g = (color >> 5) & 31;
27
unsigned b = (color >> 10) & 31;
28
29
unsigned R = (r * 26 + g * 4 + b * 2);
30
unsigned G = ( g * 24 + b * 8);
31
unsigned B = (r * 6 + g * 4 + b * 22);
32
33
R = min(960, R);
34
G = min(960, G);
35
B = min(960, B);
36
37
return (R << 20) + (G << 10) + (B << 0);
38
}
39
40
void Video::generate(Format format) {
41
if(system.dmg()) for(unsigned n = 0; n < 4; n++) palette[n] = palette_dmg(n);
42
if(system.sgb()) for(unsigned n = 0; n < 4; n++) palette[n] = palette_sgb(n);
43
if(system.cgb()) for(unsigned n = 0; n < (1 << 15); n++) palette[n] = palette_cgb(n);
44
45
if(format == Format::RGB24) {
46
for(unsigned n = 0; n < (1 << 15); n++) {
47
unsigned color = palette[n];
48
palette[n] = ((color >> 6) & 0xff0000) + ((color >> 4) & 0x00ff00) + ((color >> 2) & 0x0000ff);
49
}
50
}
51
52
if(format == Format::RGB16) {
53
for(unsigned n = 0; n < (1 << 15); n++) {
54
unsigned color = palette[n];
55
palette[n] = ((color >> 14) & 0xf800) + ((color >> 9) & 0x07e0) + ((color >> 5) & 0x001f);
56
}
57
}
58
59
if(format == Format::RGB15) {
60
for(unsigned n = 0; n < (1 << 15); n++) {
61
unsigned color = palette[n];
62
palette[n] = ((color >> 15) & 0x7c00) + ((color >> 10) & 0x03e0) + ((color >> 5) & 0x001f);
63
}
64
}
65
}
66
67
Video::Video() {
68
palette = new unsigned[1 << 15];
69
}
70
71
Video::~Video() {
72
delete[] palette;
73
}
74
75
const double Video::monochrome[4][3] = {
76
{ 0.605, 0.734, 0.059 },
77
{ 0.543, 0.672, 0.059 },
78
{ 0.188, 0.383, 0.188 },
79
{ 0.059, 0.219, 0.059 },
80
};
81
82
}
83
84