Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Graphics/Palette.hpp
1175 views
1
#ifndef PALETTE_H
2
#define PALETTE_H
3
4
namespace RSDK
5
{
6
7
#define PALETTE_BANK_COUNT (0x8)
8
#define PALETTE_BANK_SIZE (0x100)
9
10
union Color {
11
uint8 bytes[4];
12
uint32 color;
13
};
14
15
extern uint16 rgb32To16_R[0x100];
16
extern uint16 rgb32To16_G[0x100];
17
extern uint16 rgb32To16_B[0x100];
18
19
extern uint16 globalPalette[PALETTE_BANK_COUNT][PALETTE_BANK_SIZE];
20
extern uint16 activeGlobalRows[PALETTE_BANK_COUNT];
21
extern uint16 activeStageRows[PALETTE_BANK_COUNT];
22
extern uint16 stagePalette[PALETTE_BANK_COUNT][PALETTE_BANK_SIZE];
23
24
extern uint16 fullPalette[PALETTE_BANK_COUNT][PALETTE_BANK_SIZE];
25
26
extern uint8 gfxLineBuffer[SCREEN_YSIZE]; // Pointers to active palette
27
28
extern int32 maskColor;
29
30
#if RETRO_REV02
31
extern uint16 *tintLookupTable;
32
#else
33
extern uint16 tintLookupTable[0x10000];
34
#endif
35
36
#define RGB888_TO_RGB565(r, g, b) ((b) >> 3) | (((g) >> 2) << 5) | (((r) >> 3) << 11)
37
38
#define PACK_RGB888(r, g, b) RGB888_TO_RGB565(r, g, b)
39
40
#if RETRO_REV02
41
void LoadPalette(uint8 bankID, const char *filePath, uint16 disabledRows);
42
#endif
43
44
inline void SetActivePalette(uint8 newActiveBank, int32 startLine, int32 endLine)
45
{
46
if (newActiveBank < PALETTE_BANK_COUNT)
47
for (int32 l = startLine; l < endLine && l < SCREEN_YSIZE; l++) gfxLineBuffer[l] = newActiveBank;
48
}
49
50
inline uint32 GetPaletteEntry(uint8 bankID, uint8 index)
51
{
52
// 0xF800 = 1111 1000 0000 0000 = R
53
// 0x7E0 = 0000 0111 1110 0000 = G
54
// 0x1F = 0000 0000 0001 1111 = B
55
uint16 clr = fullPalette[bankID & 7][index];
56
57
int32 R = (clr & 0xF800) << 8;
58
int32 G = (clr & 0x7E0) << 5;
59
int32 B = (clr & 0x1F) << 3;
60
return R | G | B;
61
}
62
63
inline void SetPaletteEntry(uint8 bankID, uint8 index, uint32 color)
64
{
65
fullPalette[bankID][index] = rgb32To16_B[(color >> 0) & 0xFF] | rgb32To16_G[(color >> 8) & 0xFF] | rgb32To16_R[(color >> 16) & 0xFF];
66
}
67
68
inline void SetPaletteMask(uint32 color)
69
{
70
maskColor = rgb32To16_B[(color >> 0) & 0xFF] | rgb32To16_G[(color >> 8) & 0xFF] | rgb32To16_R[(color >> 16) & 0xFF];
71
}
72
73
#if RETRO_REV02
74
inline void SetTintLookupTable(uint16 *lookupTable) { tintLookupTable = lookupTable; }
75
76
#if RETRO_USE_MOD_LOADER && RETRO_MOD_LOADER_VER >= 2
77
inline uint16 *GetTintLookupTable() { return tintLookupTable; }
78
#endif
79
80
#else
81
inline uint16 *GetTintLookupTable() { return tintLookupTable; }
82
#endif
83
84
inline void CopyPalette(uint8 sourceBank, uint8 srcBankStart, uint8 destinationBank, uint8 destBankStart, uint8 count)
85
{
86
if (sourceBank < PALETTE_BANK_COUNT && destinationBank < PALETTE_BANK_COUNT) {
87
for (int32 i = 0; i < count; ++i) {
88
fullPalette[destinationBank][destBankStart + i] = fullPalette[sourceBank][srcBankStart + i];
89
}
90
}
91
}
92
93
inline void RotatePalette(uint8 bankID, uint8 startIndex, uint8 endIndex, bool32 right)
94
{
95
if (right) {
96
uint16 startClr = fullPalette[bankID][endIndex];
97
for (int32 i = endIndex; i > startIndex; --i) fullPalette[bankID][i] = fullPalette[bankID][i - 1];
98
fullPalette[bankID][startIndex] = startClr;
99
}
100
else {
101
uint16 startClr = fullPalette[bankID][startIndex];
102
for (int32 i = startIndex; i < endIndex; ++i) fullPalette[bankID][i] = fullPalette[bankID][i + 1];
103
fullPalette[bankID][endIndex] = startClr;
104
}
105
}
106
107
#if RETRO_REV02
108
void BlendColors(uint8 destBankID, uint32 *srcColorsA, uint32 *srcColorsB, int32 blendAmount, int32 startIndex, int32 count);
109
#endif
110
void SetPaletteFade(uint8 destBankID, uint8 srcBankA, uint8 srcBankB, int16 blendAmount, int32 startIndex, int32 endIndex);
111
112
#if RETRO_REV0U
113
#include "Legacy/PaletteLegacy.hpp"
114
#endif
115
116
} // namespace RSDK
117
118
#endif
119
120