Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Graphics/Palette.cpp
1162 views
1
#include "RSDK/Core/RetroEngine.hpp"
2
3
using namespace RSDK;
4
5
#if RETRO_REV0U
6
#include "Legacy/PaletteLegacy.cpp"
7
#endif
8
9
uint16 RSDK::rgb32To16_R[0x100];
10
uint16 RSDK::rgb32To16_G[0x100];
11
uint16 RSDK::rgb32To16_B[0x100];
12
13
uint16 RSDK::globalPalette[PALETTE_BANK_COUNT][PALETTE_BANK_SIZE];
14
uint16 RSDK::activeGlobalRows[PALETTE_BANK_COUNT];
15
uint16 RSDK::activeStageRows[PALETTE_BANK_COUNT];
16
uint16 RSDK::stagePalette[PALETTE_BANK_COUNT][PALETTE_BANK_SIZE];
17
18
uint16 RSDK::fullPalette[PALETTE_BANK_COUNT][PALETTE_BANK_SIZE];
19
20
uint8 RSDK::gfxLineBuffer[SCREEN_YSIZE];
21
22
int32 RSDK::maskColor = 0;
23
#if RETRO_REV02
24
uint16 *RSDK::tintLookupTable = NULL;
25
#else
26
uint16 RSDK::tintLookupTable[0x10000];
27
#endif
28
29
#if RETRO_REV02
30
void RSDK::LoadPalette(uint8 bankID, const char *filename, uint16 disabledRows)
31
{
32
char fullFilePath[0x80];
33
sprintf_s(fullFilePath, sizeof(fullFilePath), "Data/Palettes/%s", filename);
34
35
FileInfo info;
36
InitFileInfo(&info);
37
if (LoadFile(&info, fullFilePath, FMODE_RB)) {
38
for (int32 r = 0; r < 0x10; ++r) {
39
if (!(disabledRows >> r & 1)) {
40
for (int32 c = 0; c < 0x10; ++c) {
41
uint8 red = ReadInt8(&info);
42
uint8 green = ReadInt8(&info);
43
uint8 blue = ReadInt8(&info);
44
fullPalette[bankID][(r << 4) + c] = rgb32To16_B[blue] | rgb32To16_G[green] | rgb32To16_R[red];
45
}
46
}
47
else {
48
Seek_Cur(&info, 0x10 * (3 * sizeof(uint8)));
49
}
50
}
51
52
CloseFile(&info);
53
}
54
}
55
56
void RSDK::BlendColors(uint8 destBankID, uint32 *srcColorsA, uint32 *srcColorsB, int32 blendAmount, int32 startIndex, int32 count)
57
{
58
if (destBankID >= PALETTE_BANK_COUNT || !srcColorsA || !srcColorsB)
59
return;
60
61
blendAmount = CLAMP(blendAmount, 0x00, 0xFF);
62
63
uint8 blendA = 0xFF - blendAmount;
64
uint16 *paletteColor = &fullPalette[destBankID][startIndex];
65
for (int32 i = startIndex; i < startIndex + count; ++i) {
66
int32 r = blendAmount * ((*srcColorsB >> 0x10) & 0xFF) + blendA * ((*srcColorsA >> 0x10) & 0xFF);
67
int32 g = blendAmount * ((*srcColorsB >> 0x08) & 0xFF) + blendA * ((*srcColorsA >> 0x08) & 0xFF);
68
int32 b = blendAmount * ((*srcColorsB >> 0x00) & 0xFF) + blendA * ((*srcColorsA >> 0x00) & 0xFF);
69
70
*paletteColor = PACK_RGB888((uint8)(r >> 8), (uint8)(g >> 8), (uint8)(b >> 8));
71
72
srcColorsA++;
73
srcColorsB++;
74
++paletteColor;
75
}
76
}
77
#endif
78
79
void RSDK::SetPaletteFade(uint8 destBankID, uint8 srcBankA, uint8 srcBankB, int16 blendAmount, int32 startIndex, int32 endIndex)
80
{
81
if (destBankID >= PALETTE_BANK_COUNT || srcBankA >= PALETTE_BANK_COUNT || srcBankB >= PALETTE_BANK_COUNT)
82
return;
83
84
blendAmount = CLAMP(blendAmount, 0x00, 0xFF);
85
endIndex = MIN(endIndex, 0x100);
86
87
if (startIndex >= endIndex)
88
return;
89
90
uint32 blendA = 0xFF - blendAmount;
91
uint16 *paletteColor = &fullPalette[destBankID][startIndex];
92
for (int32 i = startIndex; i <= endIndex; ++i) {
93
uint32 clrA = GetPaletteEntry(srcBankA, i);
94
uint32 clrB = GetPaletteEntry(srcBankB, i);
95
96
int32 r = blendAmount * ((clrB >> 0x10) & 0xFF) + blendA * ((clrA >> 0x10) & 0xFF);
97
int32 g = blendAmount * ((clrB >> 0x08) & 0xFF) + blendA * ((clrA >> 0x08) & 0xFF);
98
int32 b = blendAmount * ((clrB >> 0x00) & 0xFF) + blendA * ((clrA >> 0x00) & 0xFF);
99
100
*paletteColor = PACK_RGB888((uint8)(r >> 8), (uint8)(g >> 8), (uint8)(b >> 8));
101
102
++paletteColor;
103
}
104
}
105