Alchemy
Loading...
Searching...
No Matches

color.c File Reference

The colour buffer: palettes moved toward target colours. More...

Go to the source code of this file.

Macros

#define HEAP_SLOT_PALBUF   32
 the colour buffer (gPaletteBufferWork)
#define COLOR_MAX   448
#define COLOR_HALF   224
#define COLOR_CHANNEL_COUNT   (COLOR_MAX * 3)

Functions

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 target in frames frames; with frames 0 or less step is left as it was.
void BattlePalette_UpdateBlend (void)
 Each frame (unless flag 0x152 is set): moves the colour buffer one step toward its target, packs it into RGB555 and queues it for the BG and OBJ palettes.
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, G and R channels shifted up 10 bits.
void BattleEffect_InitializeBuffers (void)
 Sets up the colour buffer (heap block 32) from the BG and OBJ palettes and starts updating the palettes from it each frame.
void BattlePalette_StopBlendAndReleaseBuffer (void)
 Stops the colour buffer and frees it: removes BattlePalette_UpdateBlend and releases heap slot 32.
void BattleFx_ApplyColorToTargetBuffer (s32 mode, s32 half)
 Sets the colours the buffer moves toward (see BattleFx_BuildBuffer); does nothing without a colour buffer.
void BattleFx_ApplyColorToSourceBuffer (s32 mode, s32 half)
 Sets the colours the buffer shows now (see BattleFx_BuildBuffer).
void BattleFx_SetPrimaryBufferValue (u32 color)
 Sets the buffer's source backdrop colour (BG colour 0 of its palette copy).
void BattleFx_StartBufferInterpolation (s32 frames)
 Starts moving the shown colours to the target colours over frames frames: sets work->duration, clears work->step and fills work->delta.
s32 BattleFx_ClampRgb555Channel (s32 value)
 Clamps a 5-bit colour channel to 0 to 31.
s32 BattleFx_ClampRgb555Component (s32 value)
 Clamps a colour channel shifted up 10 bits to at most 31 << 10.

Variables

u16 gBattlePalette_ChannelCurve []
 Colour channel curves (0 to 31, to channels up to 0x7c00).
u16 gBattlePalette_ChannelCurveLight []
u16 gBattlePalette_ChannelCurveContrast []

Detailed Description

The colour buffer: palettes moved toward target colours.

Part of object.c, the field object, compiled only through it.

Definition in file color.c.

Macro Definition Documentation

◆ HEAP_SLOT_PALBUF

#define HEAP_SLOT_PALBUF   32

the colour buffer (gPaletteBufferWork)

Definition at line 8 of file color.c.

Referenced by BattleEffect_InitializeBuffers(), and BattlePalette_StopBlendAndReleaseBuffer().

◆ COLOR_MAX

#define COLOR_MAX   448

Definition at line 9 of file color.c.

Referenced by BattleFx_BuildBuffer(), and BattlePalette_UpdateBlend().

◆ COLOR_HALF

#define COLOR_HALF   224

◆ COLOR_CHANNEL_COUNT

#define COLOR_CHANNEL_COUNT   (COLOR_MAX * 3)

Definition at line 11 of file color.c.

Referenced by BattleFx_InterpolateBuffers(), and BattlePalette_UpdateBlend().

Function Documentation

◆ BattleFx_InterpolateBuffers()

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 target in frames frames; with frames 0 or less step is left as it was.

Called by BattleFx_StartBufferInterpolation and by the weather effects (psynergy_effects/weather.c).

Definition at line 17 of file color.c.

Referenced by BattleFx_ClearRandomParticles(), BattleFx_InterpolateBuffers(), BattleFx_StartBufferBlend(), BattleFx_StartBufferInterpolation(), and FieldFx_StartLightning().

◆ BattlePalette_UpdateBlend()

void BattlePalette_UpdateBlend ( void )

Each frame (unless flag 0x152 is set): moves the colour buffer one step toward its target, packs it into RGB555 and queues it for the BG and OBJ palettes.

The packed colours are double-buffered: work->page names the page the queued DMA reads, and the other is written. Registered by BattleEffect_InitializeBuffers as a scheduler callback; the menus clear and set flag 0x152 around it (menu/common.c).

Definition at line 43 of file color.c.

Referenced by BattleEffect_InitializeBuffers(), BattleFx_ClearRandomParticles(), BattlePalette_StopBlendAndReleaseBuffer(), and BattlePalette_UpdateBlend().

◆ BattleFx_BuildBuffer()

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, G and R channels shifted up 10 bits.

mode below 0x8000 is one colour for all; PALETTE_TRANSFORM_FROM_SOURCE the backdrop colour; the other PALETTE_TRANSFORM_* values transform each colour; any other value is the address of a ready buffer to copy. half: 0 for all 448 colours, 1 for the BG's 224, 2 for the OBJ's 224. Called by the ApplyColorTo functions below, BattleEffect_InitializeBuffers and the weather effects (psynergy_effects/weather.c).

Definition at line 108 of file color.c.

Referenced by BattleEffect_InitializeBuffers(), BattleFx_ApplyColorToSourceBuffer(), BattleFx_ApplyColorToTargetBuffer(), BattleFx_BuildBuffer(), BattleFx_ClearRandomParticles(), BattleFx_StartBufferBlend(), and FieldFx_StartLightning().

◆ BattleEffect_InitializeBuffers()

void BattleEffect_InitializeBuffers ( void )

Sets up the colour buffer (heap block 32) from the BG and OBJ palettes and starts updating the palettes from it each frame.

Called by Field_RunScene on scene load; allocates heap slot 32 (gPaletteBufferWork) and registers BattlePalette_UpdateBlend at priority 0xc8f.

Definition at line 373 of file color.c.

Referenced by BattleEffect_InitializeBuffers(), BattleFx_ClearRandomParticles(), and Field_RunScene().

◆ BattlePalette_StopBlendAndReleaseBuffer()

void BattlePalette_StopBlendAndReleaseBuffer ( void )

Stops the colour buffer and frees it: removes BattlePalette_UpdateBlend and releases heap slot 32.

Reached only through a bare far-call veneer; no ☀️ code names it.

Definition at line 389 of file color.c.

Referenced by BattleFx_ClearRandomParticles(), and BattlePalette_StopBlendAndReleaseBuffer().

◆ BattleFx_ApplyColorToTargetBuffer()

void BattleFx_ApplyColorToTargetBuffer ( s32 mode,
s32 half )

Sets the colours the buffer moves toward (see BattleFx_BuildBuffer); does nothing without a colour buffer.

Called by the field Psynergy effects, the scene transitions, the shop cursor, and scene overlays as Engine_ColorBufferApplyTarget.

Definition at line 398 of file color.c.

Referenced by BattleEffect_InitializeSharedScene(), BattleFx_ApplyColorToTargetBuffer(), BattleFx_ClearRandomParticles(), BattleFx_PrepareBufferInterpolation(), DisplayTransition_Finish(), Field_RunScene(), FieldFx_RunReveal(), FieldFx_UpdateLightning(), FieldFx_UpdateMindReadWave(), ResetSceneTransitionEffect(), and RunSceneTransitionEffect().

◆ BattleFx_ApplyColorToSourceBuffer()

void BattleFx_ApplyColorToSourceBuffer ( s32 mode,
s32 half )

Sets the colours the buffer shows now (see BattleFx_BuildBuffer).

Called by Reveal, the leader's steps (step.c), the transitions, and scene overlays as Engine_ColorBufferApplySource.

Definition at line 409 of file color.c.

Referenced by BattleFx_ApplyColorToSourceBuffer(), BattleFx_ClearRandomParticles(), BattleParty_ApplyHealthDelta(), BattleParty_ApplyStatusDamage(), DisplayTransition_Start(), FieldFx_RunReveal(), and ResetSceneTransitionEffect().

◆ BattleFx_SetPrimaryBufferValue()

void BattleFx_SetPrimaryBufferValue ( u32 color)

Sets the buffer's source backdrop colour (BG colour 0 of its palette copy).

Called by the transitions (transition.c).

Definition at line 419 of file color.c.

Referenced by BattleFx_ClearRandomParticles(), BattleFx_SetPrimaryBufferValue(), and DisplayTransition_Start().

◆ BattleFx_StartBufferInterpolation()

void BattleFx_StartBufferInterpolation ( s32 frames)

Starts moving the shown colours to the target colours over frames frames: sets work->duration, clears work->step and fills work->delta.

Called after BattleFx_ApplyColorToTargetBuffer by the same callers, and by scene overlays as Engine_ColorBufferInterpolate.

Definition at line 431 of file color.c.

Referenced by BattleEffect_InitializeSharedScene(), BattleFx_ClearRandomParticles(), BattleFx_PrepareBufferInterpolation(), BattleFx_StartBufferInterpolation(), BattleParty_ApplyHealthDelta(), BattleParty_ApplyStatusDamage(), DisplayTransition_Finish(), DisplayTransition_Start(), FieldFx_RunReveal(), FieldFx_UpdateMindReadWave(), ResetSceneTransitionEffect(), and RunSceneTransitionEffect().

◆ BattleFx_ClampRgb555Channel()

s32 BattleFx_ClampRgb555Channel ( s32 value)

Clamps a 5-bit colour channel to 0 to 31.

Definition at line 443 of file color.c.

Referenced by BattleFx_BuildBuffer(), BattleFx_ClampRgb555Channel(), and BattleFx_ClearRandomParticles().

◆ BattleFx_ClampRgb555Component()

s32 BattleFx_ClampRgb555Component ( s32 value)

Clamps a colour channel shifted up 10 bits to at most 31 << 10.

Definition at line 452 of file color.c.

Referenced by BattleFx_BuildBuffer(), BattleFx_ClampRgb555Component(), and BattleFx_ClearRandomParticles().

Variable Documentation

◆ gBattlePalette_ChannelCurve

u16 gBattlePalette_ChannelCurve[]
extern

Colour channel curves (0 to 31, to channels up to 0x7c00).

Definition at line 140 of file fxdata.c.

Referenced by BattleFx_BuildBuffer().

◆ gBattlePalette_ChannelCurveLight

u16 gBattlePalette_ChannelCurveLight[]
extern

Definition at line 147 of file fxdata.c.

Referenced by BattleFx_BuildBuffer().

◆ gBattlePalette_ChannelCurveContrast

u16 gBattlePalette_ChannelCurveContrast[]
extern

Definition at line 154 of file fxdata.c.

Referenced by BattleFx_BuildBuffer().