Alchemy

canvas.c

The canvas layer: transfers, opening and closing, tile maps, lines.

games/tbs/src/effect/parts/canvas.c on GitHub

The canvas layer: transfers, opening and closing, tile maps, lines. Part of effect.c, the battle effect object, compiled only through it.

Functions

BattleFx_WipeCanvas

void BattleFx_WipeCanvas(s32 mode, s32 value)

Wipes the whole canvas to one colour with a ragged edge: each row (or column) lags a random 0 to 63 pixels behind the front, which speeds up as it goes. Returns when the wipe is done, a frame at a time: 23 frames across, 15 down.

Called by the summons and scenes that open on a wiped canvas: Boreas, Thor, Atalanta, Neptune, Kirin, Ramses, the particle streams and Judgment. Writes the canvas and sets work->transferPending each frame; the caller's transfer callback must already be running.

mode : 1 sweeps left to right; anything else sweeps top to bottom. value : 0 wipes to colour 1, 1 wipes to colour 0 (clears the canvas).

Used by BattleFx_RunAtalanta, BattleFx_RunBoreas, BattleFx_RunJudgment, BattleFx_RunKirin, BattleFx_RunNeptune, BattleFx_RunParticleStreams, BattleFx_RunRamses, BattleFx_RunThor.

Line 28

BattleFx_ProcessPendingGraphicsTransfer

void BattleFx_ProcessPendingGraphicsTransfer(void)

Copies the canvas to VRAM once the effect has finished drawing a frame (transferPending): the 128x128 canvas into BG2's character block 1, the way transferMode says, leaving the canvas cleared, faded, darkened or brightened for the next frame.

Runs each frame as a scheduler callback that nearly every canvas effect adds, most through EFFECT_START_TRANSFER, and removes before its blocks are freed (EFFECT_FINISH_CANVAS). Clears work->transferPending after a copy, and counts work->framesSinceTransfer: 1 on a frame that copied, one more on each frame that did not. No effect reads that count; object/colorfx.c keeps the same count for its own transfer.

Used by BattleFx_EndElementStreaks, BattleFx_RunAnnihilation, BattleFx_RunAstralBlast, BattleFx_RunAtalanta, BattleFx_RunBeamSequence, BattleFx_RunBind, BattleFx_RunBoreas, BattleFx_RunBurstScene, BattleFx_RunBurstShower, BattleFx_RunCastingImpact, BattleFx_RunCondemn, BattleFx_RunCybele, BattleFx_RunDeathPlunge, BattleFx_RunDjinnBeams, BattleFx_RunDjinniEntrance, BattleFx_RunDouse, BattleFx_RunElementBurst, BattleFx_RunElementPillar, BattleFx_RunFire, BattleFx_RunFlare, BattleFx_RunFlashingStrike, BattleFx_RunFrost, BattleFx_RunGaia, BattleFx_RunGatheringLights, BattleFx_RunHaunt, BattleFx_RunHealingMotes, BattleFx_RunIce, BattleFx_RunImpactBurst, BattleFx_RunJudgment, BattleFx_RunKirin, BattleFx_RunNeptune, BattleFx_RunNereid, BattleFx_RunOrbitingSkulls, BattleFx_RunOrbitingSpirals, BattleFx_RunPaletteParticles, BattleFx_RunParticleStreams, BattleFx_RunProjectileVolley, BattleFx_RunRamses, BattleFx_RunRingAndSparkScene, BattleFx_RunShatteringOpening and 14 more.

Line 106

BattleFx_FlushPendingGraphicsTransfer

void BattleFx_FlushPendingGraphicsTransfer(void)

Copies a full-screen picture to VRAM once the effect has finished drawing a frame: the 0x7800 bytes of Ram_MapCellBuffer into BG character block 2 (0x06008000), the way transferMode says (modes 0 to 3; brightening is not offered).

Runs each frame as a scheduler callback added by BattleFx_RunParticleStreams, which removes it before it returns. Clears work->transferPending after a copy; unlike the canvas transfer it keeps no frame count.

Used by BattleFx_RunParticleStreams.

Line 161

Graphics_ApplyWindowBlendRegisters

void Graphics_ApplyWindowBlendRegisters(void)

Writes the window, display and blend registers the effect keeps in its work, all at once.

Nothing in the build calls it or takes its address. Writes WIN0H to BLDALPHA from the work block's copies.

Line 210

Display_ApplyBg2Reference

void Display_ApplyBg2Reference(void)

Writes the effect's BG2 reference point (work->bg2x, work->bg2y) to BG2X and BG2Y.

Nothing in the build calls it or takes its address; BattleFx_AdvanceBg2OnInterval (display.c) writes the same pair itself.

Line 229

Palette_StepFadeTransfer

void Palette_StepFadeTransfer(void)

Darkens the battle backdrop while the canvas is open: for fadeFrames frames, writes the backdrop's colours one CANVAS_FADE_STEP darker each frame into background palettes 6 to 13, so the effect stands out.

Runs each frame as a scheduler callback added by BattleFx_BeginCanvasLayer and BattleFx_OpenCanvasLayer, and by BattleFx_RunRingAndSparkScene; BattleFx_EndCanvasLayer and BattleFx_EndElementStreaks remove it. It does nothing until the effect sets work->fadeFrames, which it counts down while counting work->fadeStep up.

Used by BattleFx_BeginCanvasLayer, BattleFx_EndCanvasLayer, BattleFx_EndElementStreaks, BattleFx_OpenCanvasLayer, BattleFx_RunCastingImpact, BattleFx_RunDjinniEntrance, BattleFx_RunRingAndSparkScene, CastingImpact_EndPrelude.

Line 246

BattleFx_ClearActorTimers

void BattleFx_ClearActorTimers(void)

Clears every target's flash timer (work->actorTimers).

Called as the canvas opens, by BattleFx_BeginCanvasLayer, BattleFx_OpenCanvasLayer and BattleFx_SetupCanvasTileMap, and by BattleFx_RunShatteringOpening, which opens its own.

Used by BattleFx_BeginCanvasLayer, BattleFx_OpenCanvasLayer, BattleFx_RunShatteringOpening, BattleFx_SetupCanvasTileMap.

Line 265

ObjectGroup_TickMemberTimers

void ObjectGroup_TickMemberTimers(void)

Counts down each target's flash timer, which ObjectGroup_UpdateMembers starts; when one runs out, the target gets its own palette back. Timer n belongs to effect->actors[n].

Called once a frame by nearly every effect, most through EFFECT_END_FRAME. Changes work->actorTimers and, through ObjectGroup_UpdateMembers, the colour of a target whose timer ends.

Used by BattleFx_RunBurstShower, BattleFx_RunIce, BattleFx_RunSpiderWeb.

Line 278

BattleFx_BeginCanvasLayer

void BattleFx_BeginCanvasLayer(s32 bgControl)

Opens the canvas layer: starts the background palette fade, makes BG2 the canvas, alpha-blended over the battle, inside the effect windows, and clears the canvas. It also stops any shake and saves BG1's scroll, which BattleFx_EndCanvasLayer restores.

Called at the start of nearly every canvas effect, most often through EFFECT_BEGIN_NARROW_CANVAS, and by BattleFx_BeginTiledCanvas. Waits five frames of its own. Writes BLDCNT, BLDALPHA, BG2CNT and BG2's affine registers, the windows, WININ and WINOUT, and queues DISPCNT; writes BG2's map in screen block 7, clears the canvas in its slot and in character block 1; adds Palette_StepFadeTransfer with work->fadeFrames 0, so the backdrop keeps its colours until the effect sets a count; sets gBgScroll[1].y to 32, clears work->actorTimers and work->shakeFrames, and saves gBgScroll[1] in work->savedBg1X and savedBg1Y.

bgControl : added to BG2CNT, the layer's priority (0 to 3) and so on.

Used by BattleFx_BeginTiledCanvas, BattleFx_RunAnnihilation, BattleFx_RunAstralBlast, BattleFx_RunBind, BattleFx_RunBolt, BattleFx_RunBoreas, BattleFx_RunBreak, BattleFx_RunBurstScene, BattleFx_RunBurstShower, BattleFx_RunCastingImpact, BattleFx_RunDeathPlunge, BattleFx_RunDjinnBeams, BattleFx_RunDjinnHeal, BattleFx_RunDjinniEntrance, BattleFx_RunDragonCloud, BattleFx_RunDrain, BattleFx_RunElementBurst, BattleFx_RunElementPillar, BattleFx_RunEruption, BattleFx_RunFire, BattleFx_RunFlare, BattleFx_RunFlashingStrike, BattleFx_RunFroth, BattleFx_RunGaia, BattleFx_RunGatheringLights, BattleFx_RunGround, BattleFx_RunGrowingColumns, BattleFx_RunHail, BattleFx_RunHaunt, BattleFx_RunHealingMotes, BattleFx_RunJupiter, BattleFx_RunKirin, BattleFx_RunKite, BattleFx_RunLobbedShells, BattleFx_RunMars, BattleFx_RunMercury, BattleFx_RunMirroredWall, BattleFx_RunMoteFountain, BattleFx_RunNeptune, BattleFx_RunNereid and 27 more.

Line 317

BattleFx_OpenCanvasLayer

void BattleFx_OpenCanvasLayer(s32 bgControl)

Opens the canvas layer as BattleFx_BeginCanvasLayer does, but with the windows off until the end, the backdrop palette starting half faded, and a 24-frame fade. It neither saves BG1's scroll nor resets the shake.

Nothing in the build calls it or takes its address. Writes the same registers, map and canvas as BattleFx_BeginCanvasLayer and sets work->fadeFrames to 24.

bgControl : added to BG2CNT, the layer's priority (0 to 3) and so on.

Line 395

BattleFx_BeginTiledCanvas

void BattleFx_BeginTiledCanvas(s32 bgControl)

Opens the canvas layer with BG2 a wrapping 256x256 map: each row of the map is the canvas's 16 tiles followed by 16 of tile 0, so the canvas repeats across the screen with gaps.

Called by BattleFx_RunRay, BattleFx_RunCondemn, BattleFx_RunCastingImpact and BattleFx_InitTilemapAndFlushQueue. Opens the layer through BattleFx_BeginCanvasLayer, then rewrites BG2CNT and BG2's map in screen block 7.

bgControl : added to BG2CNT, the layer's priority (0 to 3) and so on.

Used by BattleFx_InitTilemapAndFlushQueue, BattleFx_RunCastingImpact, BattleFx_RunCondemn, BattleFx_RunRay.

Line 466

BattleFx_EndCanvasLayer

void BattleFx_EndCanvasLayer(void)

Closes the canvas layer: plays the closing sound, restores BG1's scroll and the projection centre, clears the canvas tiles, stops the palette fade and brings the backdrop's palette back from level 21 to 0 over 8 frames, then shows BG2 again and hides BG1.

Called at the end of nearly every canvas effect, most through EFFECT_FINISH_CANVAS, after the transfer callback is removed. Takes 11 frames. Writes gBgScroll[1], gProjection's centre, BG2CNT (priority 3) and BLDCNT, clears character block 1, removes Palette_StepFadeTransfer and queues two DISPCNT values.

Used by BattleFx_InitTilemapAndFlushQueue, BattleFx_RunAnnihilation, BattleFx_RunBind, BattleFx_RunBoreas, BattleFx_RunBurstScene, BattleFx_RunCondemn, BattleFx_RunCybele, BattleFx_RunDjinnBeams, BattleFx_RunElementBurst, BattleFx_RunElementPillar, BattleFx_RunFire, BattleFx_RunFlare, BattleFx_RunFlashingStrike, BattleFx_RunFrost, BattleFx_RunGaia, BattleFx_RunGatheringLights, BattleFx_RunHaunt, BattleFx_RunIce, BattleFx_RunKite, BattleFx_RunNereid, BattleFx_RunOrbitingSpirals, BattleFx_RunPaletteParticles, BattleFx_RunParticleStreams, BattleFx_RunSpiderWeb, BattleFx_RunStatBoost, BattleFx_RunTargetMotes, BattleFx_RunTargetStrike, BattleFx_RunThor, BattleFx_RunTriangleStrike, BattleFx_RunUndeadSword, BattleFx_RunVolcano, BattleFx_RunWhirlwind.

Line 493

BattleFx_HideBg1AndRestoreBackdrop

void BattleFx_HideBg1AndRestoreBackdrop(void)

Hides BG1 and the windows and starts bringing the backdrop's palette back.

Called by BattleFx_RunBeamSequence and BattleFx_RunRingAndSparkScene (beams.c). Sets the background view's secondMode to 1, queues DISPCNT for two frames later, starts the battle's palette fade (mode 2) and waits two frames.

Used by BattleFx_RunBeamSequence, BattleFx_RunRingAndSparkScene.

Line 540

BattleFx_SetupCanvasTileMap

void BattleFx_SetupCanvasTileMap(void)

Shows the canvas on BG1 instead of BG2, at its own size: BG1 becomes a 256-colour layer whose map points 16 rows of 16 tiles at the canvas (tiles 0x100 onwards, which at 64 bytes a tile start at character block 1, where the canvas lives), with blank tile 0xff to the right, blended over the rest inside the effect windows. Also clears the canvas. The full-screen Ram_MapCellBuffer effects use BattleFx_FlushPendingGraphicsTransfer instead.

Called by BattleFx_RunBeamSequence and BattleFx_RunRingAndSparkScene (beams.c). Clears work->actorTimers, starts the battle's palette fade (mode 2), clears tile 0xff of character block 0 and writes BG1's map in screen block 31; writes DISPCNT, BG1CNT, BLDCNT, BLDALPHA, the windows, WININ and WINOUT directly; sets gBgScroll[1].y to 32 and the background view's secondMode to 0; clears the canvas and character block 1.

Used by BattleFx_RunBeamSequence, BattleFx_RunRingAndSparkScene.

Line 571

BattleFx_DrawClippedCanvasLine

void BattleFx_DrawClippedCanvasLine(s32 x0, s32 y0, s32 x1, s32 y1, s32 color)

Draws a line on the 128x128 8bpp canvas (16 tiles across), keeping the brighter colour where it crosses what is already drawn. The ends' y is kept on the canvas; x is not. The line steps a pixel at a time along its longer axis, following the other in 8-bit fixed point, and leaves out its last pixel on that axis.

Called by BattleFx_DrawStreaks (death_plunge.c) and BattleFx_RunNeptune. Writes only the canvas, and only while the caller keeps x within 0 to 127: any other x wraps into a neighbouring row of tiles, or off the canvas from its first or last row of tiles.

x0, y0 : the start, in pixels x1, y1 : the end, in pixels color : the colour index

Used by BattleFx_DrawStreaks, BattleFx_RunNeptune.

Line 637

Macros

CANVAS_FADE_STEP

#define CANVAS_FADE_STEP 1092

One step of the background palette fade, in 1/65536ths of full brightness: 24 steps take it from full to 60%.

Used by Palette_StepFadeTransfer.

Line 203

On this page