8#define HEAP_SLOT_PALBUF 32
11#define COLOR_CHANNEL_COUNT (COLOR_MAX * 3)
19 s32 remainingChannels;
26 sourceChannel = *source;
27 targetChannel = *target;
33 }
while (remainingChannels >= 0);
59 *currentChannel++ += *channelDelta++;
70 s32 blueMask = 0x7c00;
120 }
else if (half == 2) {
129 *dst++ = mode & 0x7c00;
130 *dst++ = (mode & 0x03e0) << 5;
131 *dst++ = (mode & 0x001f) << 10;
137 for (i = 0; i < colorCount; i++) {
139 red = ((color << 11) & 0xf800);
140 green = ((color << 7) & 0x1f000);
141 blue = (color & 0x7c00);
150 for (i = 0; i < colorCount; i++) {
154 red + ((color >> 5) & 31) + ((color >> 10) & 31), 10);
156 blue = color * 3 + 5;
177 for (i = 0; i < colorCount; i++) {
180 green = (color >> 5) & 31;
181 blue = (color >> 10) & 31;
182 if ((red | green | blue) != 0) {
183 red -= (
u32)red >> 1;
198 for (i = 0; i < colorCount; i++) {
201 green = (color >> 5) & 31;
202 blue = (color >> 10) & 31;
226 for (i = 0; i < colorCount; i++) {
231 green = (color >> 5) & 31;
232 blue = (color >> 10) & 31;
234 red = (red >> 1) + mean;
235 green = (green >> 1) + mean;
236 blue = (blue >> 1) + mean;
248 for (i = 0; i < colorCount; i++) {
251 green = (color >> 5) & 31;
252 blue = (color >> 10) & 31;
253 red += ((green >> 3) + (blue >> 3));
264 for (i = 0; i < colorCount; i++) {
267 green = (color >> 5) & 31;
268 blue = (color >> 10) & 31;
269 red -= (
u32)red >> 1;
284 for (i = 0; i < colorCount; i++) {
286 dst[i * 3 + 0] = color & 0x7c00;
287 dst[i * 3 + 1] = (color & 0x03e0) << 5;
288 dst[i * 3 + 2] = (color & 0x001f) << 10;
301 tintGreen = (mode >> 5) & 31;
302 tintBlue = (mode >> 10) & 31;
303 for (i = 0; i < colorCount; i++) {
305 red = ((color << 11) & 0xf800);
306 green = ((color << 7) & 0x1f000);
307 blue = (color & 0x7c00);
309 red = color * tintRed;
310 green = color * tintGreen;
311 blue = color * tintBlue;
330 tintGreen = (mode >> 5) & 31;
331 tintBlue = (mode >> 10) & 31;
332 for (i = 0; i < colorCount; i++) {
336 (red + ((color >> 5) & 31) + ((color >> 10) & 31)) << 4,
337 tintRed + tintGreen + tintBlue);
338 blendedRed =
Iwram_MulQ16(((color * tintRed) >> 4) << 16,
339 (
s32)(tintRed << 16) >> 4);
340 blendedGreen =
Iwram_MulQ16(((color * tintGreen) >> 4) << 16,
341 (
s32)(tintGreen << 16) >> 4);
342 blendedBlue =
Iwram_MulQ16(((color * tintBlue) >> 4) << 16,
343 (
s32)(tintBlue << 16) >> 4);
353 for (i = 0; i < colorCount; i++) {
355 dst[i * 3 + 0] = color & 0x7c00;
356 dst[i * 3 + 1] = (color & 0x03e0) << 5;
357 dst[i * 3 + 2] = (color & 0x001f) << 10;
364 Dma_Set((
const void *)mode, dst,
459#undef HEAP_SLOT_PALBUF
462#undef COLOR_CHANNEL_COUNT
struct BattleEffectBuffers * gPaletteBufferWork
void BattlePalette_StopBlendAndReleaseBuffer(void)
Stops the colour buffer and frees it: removes BattlePalette_UpdateBlend and releases heap slot 32.
void BattleFx_InterpolateBuffers(s16 *source, s16 *target, s16 *step, s32 frames)
Sets each of the 1344 colour channels of step to the amount to add each frame for source to reach tar...
void BattleFx_ApplyColorToTargetBuffer(s32 mode, s32 half)
Sets the colours the buffer moves toward (see BattleFx_BuildBuffer); does nothing without a colour bu...
void BattlePalette_UpdateBlend(void)
Each frame (unless flag 0x152 is set): moves the colour buffer one step toward its target,...
s32 BattleFx_ClampRgb555Component(s32 value)
Clamps a colour channel shifted up 10 bits to at most 31 << 10.
void BattleEffect_InitializeBuffers(void)
Sets up the colour buffer (heap block 32) from the BG and OBJ palettes and starts updating the palett...
void BattleFx_SetPrimaryBufferValue(u32 color)
Sets the buffer's source backdrop colour (BG colour 0 of its palette copy).
void BattleFx_BuildBuffer(u32 mode, u16 *src, u16 *dst, s32 half)
Builds colours for the colour buffer from the palette src into dst, which holds each colour as B,...
#define COLOR_CHANNEL_COUNT
s32 BattleFx_ClampRgb555Channel(s32 value)
Clamps a 5-bit colour channel to 0 to 31.
#define HEAP_SLOT_PALBUF
the colour buffer (gPaletteBufferWork)
void BattleFx_StartBufferInterpolation(s32 frames)
Starts moving the shown colours to the target colours over frames frames: sets work->duration,...
void BattleFx_ApplyColorToSourceBuffer(s32 mode, s32 half)
Sets the colours the buffer shows now (see BattleFx_BuildBuffer).
static __inline__ void Dma_Set(const volatile void *source, volatile void *destination, u32 control, volatile u32 *channel)
Starts a DMA transfer: stores the source, destination and control words into channel's registers with...
#define Dma_Fill32(value, destination, size)
Fills size bytes at destination with the word value by DMA3.
s32 GameFlag_TestFar(s32 flag)
const u16 gBattlePalette_ChannelCurveContrast[32]
const u16 gBattlePalette_ChannelCurveLight[32]
const u16 gBattlePalette_ChannelCurve[32]
Colour channel curves (0 to 31, to channels up to 0x7c00).
void * Runtime_AllocateBlock(s32 kind, s32 size)
As Runtime_AllocateHeapBlock, but tries EWRAM first, for blocks that need room more than speed: the b...
#define IO_WRITE_QUEUE_PUSH(address, value, control)
Disables interrupts to add one register write or DMA to the queue; a write to a full queue is dropped...
static s32 Iwram_CopyWords(volatile void *destination, const volatile void *source, s32 size)
static s32 Iwram_SignedDivide(s32 dividend, s32 divisor)
#define Iwram_MulQ16(left, right)
void Runtime_ReleaseHeapBlock(s32 slot)
What every part of object.c shares: its includes and the macros and types more than one part uses.
@ PALETTE_TRANSFORM_GREY
grey of brightness (2R + 4G + B) / 7
@ PALETTE_TRANSFORM_MUTED
@ PALETTE_TRANSFORM_BLEND
The brightness R + G + B shared out in the proportions of the colour carried.
@ PALETTE_TRANSFORM_PLAIN
each colour unchanged
@ PALETTE_TRANSFORM_FROM_SOURCE
The backdrop colour (palette RAM's first colour) for all.
@ PALETTE_TRANSFORM_SEPIA
@ PALETTE_TRANSFORM_SPLIT
each colour unchanged
@ PALETTE_TRANSFORM_WARM2
half R + 6, two thirds G + 4, B - 6
@ PALETTE_TRANSFORM_FLAGS
From here the TINT, BLEND and SPLIT bits are tested, TINT and BLEND carrying an RGB555 colour in the ...
@ PALETTE_TRANSFORM_TINT
The brightness (2R + 4G + B) times the colour carried.
s32 Scheduler_AddOrUpdateCallback(SchedulerCallback callback, s32 order)
Schedules callback with order, or gives a task already running it the new order, and re-sorts the tab...
s32 Scheduler_RemoveCallback(SchedulerCallback callback)
Unschedules the task running callback: clears its routine and gives it order 0x7fff,...
The colour buffer (heap block 32) that fades the BG and OBJ palettes: the source palette,...
u16 current[0x540]
The shown colours, as B, G and R channels shifted up 10 bits, three a colour.
u16 target[0x540]
the colours current moves toward, as current
u16 packed[2][0x1c0]
Two pages of RGB555 colours: one is built while the other is queued.
u8 page
the packed page queued this frame
s8 duration
frames; 0 when the colours are not moving
u16 palette[0x1c0]
The source palette, RGB555: 224 BG colours, then 224 OBJ colours; palette[0] is the backdrop.
u16 delta[0x540]
added to each current channel each frame