Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Graphics/Legacy/PaletteLegacy.hpp
1188 views
1
2
namespace Legacy
3
{
4
#define LEGACY_PALETTE_COUNT (0x8)
5
#define LEGACY_PALETTE_COLOR_COUNT (0x100)
6
7
struct Color {
8
uint8 r;
9
uint8 g;
10
uint8 b;
11
uint8 a;
12
};
13
14
// Palettes (as RGB565 Colors)
15
extern uint16 fullPalette[LEGACY_PALETTE_COUNT][LEGACY_PALETTE_COLOR_COUNT];
16
extern uint16 *activePalette; // Pointers to the 256 color set thats active
17
18
extern uint8 gfxLineBuffer[SCREEN_YSIZE * 2]; // Pointers to active palette
19
extern int32 GFX_LINESIZE;
20
extern int32 GFX_LINESIZE_MINUSONE;
21
extern int32 GFX_LINESIZE_DOUBLE;
22
extern int32 GFX_FRAMEBUFFERSIZE;
23
extern int32 GFX_FBUFFERMINUSONE;
24
25
extern int32 fadeMode;
26
extern uint8 fadeA;
27
extern uint8 fadeR;
28
extern uint8 fadeG;
29
extern uint8 fadeB;
30
31
extern int32 paletteMode;
32
33
void LoadPalette(const char *filePath, int32 paletteID, int32 startPaletteIndex, int32 startIndex, int32 endIndex);
34
35
inline void SetActivePalette(uint8 newActivePal, int32 startLine, int32 endLine)
36
{
37
if (newActivePal < LEGACY_PALETTE_COUNT)
38
for (int32 l = startLine; l < endLine && l < SCREEN_YSIZE; l++) gfxLineBuffer[l] = newActivePal;
39
40
activePalette = fullPalette[gfxLineBuffer[0]];
41
}
42
43
inline void SetPaletteEntry(uint8 paletteIndex, uint8 index, uint8 r, uint8 g, uint8 b)
44
{
45
if (paletteIndex != 0xFF) {
46
fullPalette[paletteIndex][index] = PACK_RGB888(r, g, b);
47
}
48
else {
49
activePalette[index] = PACK_RGB888(r, g, b);
50
}
51
}
52
53
inline void SetPaletteEntryPacked(uint8 paletteIndex, uint8 index, uint32 color)
54
{
55
fullPalette[paletteIndex][index] = PACK_RGB888((uint8)(color >> 16), (uint8)(color >> 8), (uint8)(color >> 0));
56
}
57
58
inline uint32 GetPaletteEntryPacked(uint8 bankID, uint8 index)
59
{
60
// 0xF800 = 1111 1000 0000 0000 = R
61
// 0x7E0 = 0000 0111 1110 0000 = G
62
// 0x1F = 0000 0000 0001 1111 = B
63
uint16 clr = fullPalette[bankID & 7][index];
64
65
int32 R = (clr & 0xF800) << 8;
66
int32 G = (clr & 0x7E0) << 5;
67
int32 B = (clr & 0x1F) << 3;
68
return R | G | B;
69
}
70
71
inline void CopyPalette(uint8 sourcePalette, uint8 srcPaletteStart, uint8 destinationPalette, uint8 destPaletteStart, uint8 count)
72
{
73
if (sourcePalette < LEGACY_PALETTE_COUNT && destinationPalette < LEGACY_PALETTE_COUNT) {
74
for (int32 i = 0; i < count; ++i) {
75
fullPalette[destinationPalette][destPaletteStart + i] = fullPalette[sourcePalette][srcPaletteStart + i];
76
}
77
}
78
}
79
80
inline void RotatePalette(int32 palID, uint8 startIndex, uint8 endIndex, bool right)
81
{
82
if (right) {
83
uint16 startClr = fullPalette[palID][endIndex];
84
for (int32 i = endIndex; i > startIndex; --i) {
85
fullPalette[palID][i] = fullPalette[palID][i - 1];
86
}
87
fullPalette[palID][startIndex] = startClr;
88
}
89
else {
90
uint16 startClr = fullPalette[palID][startIndex];
91
for (int32 i = startIndex; i < endIndex; ++i) {
92
fullPalette[palID][i] = fullPalette[palID][i + 1];
93
}
94
fullPalette[palID][endIndex] = startClr;
95
}
96
}
97
98
inline void SetFade(uint8 R, uint8 G, uint8 B, uint16 A)
99
{
100
fadeMode = 1;
101
fadeR = R;
102
fadeG = G;
103
fadeB = B;
104
fadeA = A > 0xFF ? 0xFF : A;
105
}
106
107
void SetPaletteFade(uint8 destPaletteID, uint8 srcPaletteA, uint8 srcPaletteB, uint16 blendAmount, int32 startIndex, int32 endIndex);
108
109
namespace v3
110
{
111
112
inline void CopyPalette(uint8 sourcePalette, uint8 destinationPalette)
113
{
114
if (sourcePalette < LEGACY_PALETTE_COUNT && destinationPalette < LEGACY_PALETTE_COUNT) {
115
for (int32 i = 0; i < LEGACY_PALETTE_COLOR_COUNT; ++i) {
116
fullPalette[destinationPalette][i] = fullPalette[sourcePalette][i];
117
}
118
}
119
}
120
121
inline void RotatePalette(uint8 startIndex, uint8 endIndex, bool right)
122
{
123
if (right) {
124
uint16 startClr = activePalette[endIndex];
125
for (int32 i = endIndex; i > startIndex; --i) {
126
activePalette[i] = activePalette[i - 1];
127
}
128
activePalette[startIndex] = startClr;
129
}
130
else {
131
uint16 startClr = activePalette[startIndex];
132
for (int32 i = startIndex; i < endIndex; ++i) {
133
activePalette[i] = activePalette[i + 1];
134
}
135
activePalette[endIndex] = startClr;
136
}
137
}
138
139
void SetLimitedFade(uint8 paletteID, uint8 R, uint8 G, uint8 B, uint16 blendAmount, int32 startIndex, int32 endIndex);
140
} // namespace v3
141
142
} // namespace Legacy
143