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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
#include "global.h"
#define BG_PALETTE_BUFFER_SIZE 512
#define BG_PALETTE_BUFFER_CHUNK_SIZE 16
EWRAM_DATA u16 gBGPaletteBuffer[BG_PALETTE_BUFFER_SIZE];
EWRAM_DATA bool8 gBGPaletteUsed[BG_PALETTE_BUFFER_SIZE / BG_PALETTE_BUFFER_CHUNK_SIZE];
extern void CpuCopy(void* src, void* dest, u32 size);
#ifndef NONMATCHING
NAKED
#endif
void InitBGPaletteBuffer(void)
{
#ifdef NONMATCHING
u16 color = 0;
u16* ptr;
u32 i;
bool8 paletteUsed;
u8* p;
ptr = gBGPaletteBuffer;
i = 0x80;
i <<= 2;
do {
*ptr++ = color;
i--;
} while (i);
paletteUsed = TRUE;
p = gBGPaletteUsed;
p += 31;
do
*p-- = paletteUsed;
while ((s32) p >= (s32) &gBGPaletteUsed);
#else
asm_unified("\tpush {lr}\n"
"\tmovs r2, 0\n"
"\tldr r1, =gBGPaletteBuffer\n"
"\tmovs r0, 0x80\n"
"\tlsls r0, 2\n"
"_0800463E:\n"
"\tstrh r2, [r1]\n"
"\tadds r1, 0x2\n"
"\tsubs r0, 0x1\n"
"\tcmp r0, 0\n"
"\tbne _0800463E\n"
"\tldr r1, =gBGPaletteUsed\n"
"\tmovs r2, 0x1\n"
"\tadds r0, r1, 0\n"
"\tadds r0, 0x1F\n"
"_08004650:\n"
"\tstrb r2, [r0]\n"
"\tsubs r0, 0x1\n"
"\tcmp r0, r1\n"
"\tbge _08004650\n"
"\tpop {r0}\n"
"\tbx r0\n"
"\t.align 2, 0\n"
"\t.pool");
#endif
}
#ifndef NONMATCHING
NAKED
#endif
void SetBGPaletteBufferColorRGB(s32 index, u8 *RGBArray, s32 a1, u8 *a2)
{
#ifdef NONMATCHING
if (a1 < 0) {
a1 = 0;
}
if (a1 > 31) {
a1 = 31;
}
gBGPaletteUsed[index / 16] = 1;
if (!a2) {
gBGPaletteBuffer[index] = ((RGBArray[2] * a1 / 256 & 0x1F) << 10) | ((RGBArray[1] * a1 / 256 & 0x1F) << 5) | (RGBArray[0] * a1 / 256 & 0x1F);
}
else
{
gBGPaletteBuffer[index] = ((a2[4 * RGBArray[2] + 2] * a1 / 256 & 0x1F) << 10) | ((a2[4 * RGBArray[1] + 1] * a1 / 256 & 0x1F) << 5) | (a2[4 * RGBArray[0]] * a1 / 256 & 0x1F);
}
#else
asm_unified("\tpush {r4-r7,lr}\n"
"\tadds r4, r0, 0\n"
"\tadds r5, r1, 0\n"
"\tcmp r2, 0\n"
"\tbge _08004670\n"
"\tmovs r2, 0\n"
"_08004670:\n"
"\tcmp r2, 0x1F\n"
"\tble _08004676\n"
"\tmovs r2, 0x1F\n"
"_08004676:\n"
"\tldr r1, =gBGPaletteUsed\n"
"\tadds r0, r4, 0\n"
"\tcmp r4, 0\n"
"\tbge _08004680\n"
"\tadds r0, 0xF\n"
"_08004680:\n"
"\tasrs r0, 4\n"
"\tadds r0, r1\n"
"\tmovs r1, 0x1\n"
"\tstrb r1, [r0]\n"
"\tcmp r3, 0\n"
"\tbne _080046D4\n"
"\tldr r0, =gBGPaletteBuffer\n"
"\tlsls r1, r4, 1\n"
"\tadds r6, r1, r0\n"
"\tldrb r0, [r5, 0x2]\n"
"\tmuls r0, r2\n"
"\tcmp r0, 0\n"
"\tbge _0800469C\n"
"\tadds r0, 0xFF\n"
"_0800469C:\n"
"\tasrs r0, 8\n"
"\tmovs r3, 0x1F\n"
"\tands r0, r3\n"
"\tlsls r4, r0, 10\n"
"\tldrb r0, [r5, 0x1]\n"
"\tmuls r0, r2\n"
"\tcmp r0, 0\n"
"\tbge _080046AE\n"
"\tadds r0, 0xFF\n"
"_080046AE:\n"
"\tasrs r0, 8\n"
"\tands r0, r3\n"
"\tlsls r1, r0, 5\n"
"\torrs r1, r4\n"
"\tldrb r0, [r5]\n"
"\tmuls r0, r2\n"
"\tcmp r0, 0\n"
"\tbge _080046C0\n"
"\tadds r0, 0xFF\n"
"_080046C0:\n"
"\tasrs r0, 8\n"
"\tands r0, r3\n"
"\torrs r1, r0\n"
"\tstrh r1, [r6]\n"
"\tb _08004722\n"
"\t.align 2, 0\n"
"\t.pool\n"
"_080046D4:\n"
"\tldr r1, =gBGPaletteBuffer\n"
"\tlsls r0, r4, 1\n"
"\tadds r7, r0, r1\n"
"\tldrb r0, [r5, 0x2]\n"
"\tlsls r0, 2\n"
"\tadds r0, r3\n"
"\tldrb r0, [r0, 0x2]\n"
"\tmuls r0, r2\n"
"\tcmp r0, 0\n"
"\tbge _080046EA\n"
"\tadds r0, 0xFF\n"
"_080046EA:\n"
"\tasrs r0, 8\n"
"\tmovs r4, 0x1F\n"
"\tands r0, r4\n"
"\tlsls r6, r0, 10\n"
"\tldrb r0, [r5, 0x1]\n"
"\tlsls r0, 2\n"
"\tadds r0, r3\n"
"\tldrb r0, [r0, 0x1]\n"
"\tmuls r0, r2\n"
"\tcmp r0, 0\n"
"\tbge _08004702\n"
"\tadds r0, 0xFF\n"
"_08004702:\n"
"\tasrs r0, 8\n"
"\tands r0, r4\n"
"\tlsls r1, r0, 5\n"
"\torrs r1, r6\n"
"\tldrb r0, [r5]\n"
"\tlsls r0, 2\n"
"\tadds r0, r3\n"
"\tldrb r0, [r0]\n"
"\tmuls r0, r2\n"
"\tcmp r0, 0\n"
"\tbge _0800471A\n"
"\tadds r0, 0xFF\n"
"_0800471A:\n"
"\tasrs r0, 8\n"
"\tands r0, r4\n"
"\torrs r1, r0\n"
"\tstrh r1, [r7]\n"
"_08004722:\n"
"\tpop {r4-r7}\n"
"\tpop {r0}\n"
"\tbx r0\n"
"\t.align 2, 0\n"
"\t.pool");
#endif
}
void SetBGPaletteBufferColorArray(s32 index, u8 *colorArray)
{
gBGPaletteUsed[index / BG_PALETTE_BUFFER_CHUNK_SIZE] = TRUE;
gBGPaletteBuffer[index] = (colorArray[2] >> 3) << 10 | (colorArray[1] >> 3) << 5 | colorArray[0] >> 3;
}
void SetBGPaletteBufferColor(s32 index, u16 *color)
{
gBGPaletteUsed[index / BG_PALETTE_BUFFER_CHUNK_SIZE] = TRUE;
gBGPaletteBuffer[index] = *color;
}
void nullsub_4(void)
{
}
void nullsub_5(void)
{
}
void nullsub_143(void)
{
}
void TransferBGPaletteBuffer(void)
{
u32 i;
s32 paletteBufferIndex;
u16 *dest;
i = 0;
paletteBufferIndex = 0;
dest = (u16 *)PLTT;
do
{
if (gBGPaletteUsed[i])
{
gBGPaletteUsed[i] = 0;
CpuCopy(dest, &gBGPaletteBuffer[paletteBufferIndex], sizeof(u16) * 16);
}
++i;
dest += 16;
paletteBufferIndex += 16;
}
while ( paletteBufferIndex < BG_PALETTE_BUFFER_SIZE );
}
|