Alchemy
Loading...
Searching...
No Matches

canvas.c File Reference

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

Go to the source code of this file.

Macros

#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%.

Functions

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.
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.
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).
void Graphics_ApplyWindowBlendRegisters (void)
 Writes the window, display and blend registers the effect keeps in its work, all at once.
void Display_ApplyBg2Reference (void)
 Writes the effect's BG2 reference point (work->bg2x, work->bg2y) to BG2X and BG2Y.
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.
void BattleFx_ClearActorTimers (void)
 Clears every target's flash timer (work->actorTimers).
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.
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.
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.
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.
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.
void BattleFx_HideBg1AndRestoreBackdrop (void)
 Hides BG1 and the windows and starts bringing the backdrop's palette back.
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.
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.

Detailed Description

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

Part of effect.c, the battle effect object, compiled only through it.

Definition in file canvas.c.

Macro Definition Documentation

◆ 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%.

Definition at line 200 of file canvas.c.

Referenced by Palette_StepFadeTransfer().

Function Documentation

◆ 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.

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).

Definition at line 27 of file canvas.c.

Referenced by BattleFx_RunAtalanta(), BattleFx_RunBoreas(), BattleFx_RunJudgment(), BattleFx_RunKirin(), BattleFx_RunNeptune(), BattleFx_RunParticleStreams(), BattleFx_RunRamses(), BattleFx_RunThor(), and BattleFx_WipeCanvas().

◆ 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.

Definition at line 103 of file canvas.c.

Referenced by BattleFx_EndElementStreaks(), BattleFx_ProcessPendingGraphicsTransfer(), BattleFx_RunAnnihilation(), BattleFx_RunAstralBlast(), BattleFx_RunAtalanta(), BattleFx_RunBeamSequence(), BattleFx_RunBind(), BattleFx_RunBoreas(), BattleFx_RunBurstScene(), BattleFx_RunBurstShower(), BattleFx_RunCastingImpact(), BattleFx_RunCondemn(), BattleFx_RunCurse(), 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(), BattleFx_RunShiningStar(), BattleFx_RunSpiderWeb(), BattleFx_RunStatBoost(), BattleFx_RunTargetMotes(), BattleFx_RunTargetStrike(), BattleFx_RunThor(), BattleFx_RunThorn(), BattleFx_RunTriangleStrike(), BattleFx_RunUndeadSword(), BattleFx_RunVolcano(), BattleFx_RunWhirlwind(), BattleFx_StartElementStreaks(), and CastingImpact_EndPrelude().

◆ 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.

Definition at line 158 of file canvas.c.

Referenced by BattleFx_FlushPendingGraphicsTransfer(), and BattleFx_RunParticleStreams().

◆ 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.

Definition at line 207 of file canvas.c.

Referenced by Graphics_ApplyWindowBlendRegisters().

◆ 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.

Definition at line 226 of file canvas.c.

Referenced by Display_ApplyBg2Reference().

◆ 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.

Definition at line 243 of file canvas.c.

Referenced by BattleFx_BeginCanvasLayer(), BattleFx_EndCanvasLayer(), BattleFx_EndElementStreaks(), BattleFx_OpenCanvasLayer(), BattleFx_RunCastingImpact(), BattleFx_RunDjinniEntrance(), BattleFx_RunRingAndSparkScene(), CastingImpact_EndPrelude(), and Palette_StepFadeTransfer().

◆ 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.

Definition at line 262 of file canvas.c.

Referenced by BattleFx_BeginCanvasLayer(), BattleFx_ClearActorTimers(), BattleFx_OpenCanvasLayer(), BattleFx_RunShatteringOpening(), and BattleFx_SetupCanvasTileMap().

◆ 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.

Definition at line 275 of file canvas.c.

Referenced by BattleFx_RunBurstShower(), BattleFx_RunIce(), BattleFx_RunSpiderWeb(), and ObjectGroup_TickMemberTimers().

◆ 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.

Definition at line 314 of file canvas.c.

Referenced by BattleFx_BeginCanvasLayer(), 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(), BattleFx_RunPaletteParticles(), BattleFx_RunPlanetDiver(), BattleFx_RunPlasma(), BattleFx_RunPrism(), BattleFx_RunProcne(), BattleFx_RunProjectileVolley(), BattleFx_RunQuake(), BattleFx_RunRagnarok(), BattleFx_RunRamses(), BattleFx_RunRushingStrike(), BattleFx_RunShiningStar(), BattleFx_RunSparkGroups(), BattleFx_RunSpiderWeb(), BattleFx_RunStatBoost(), BattleFx_RunStreakVolley(), BattleFx_RunSwirlingStars(), BattleFx_RunTargetBursts(), BattleFx_RunTargetMotes(), BattleFx_RunTargetStrike(), BattleFx_RunThorn(), BattleFx_RunTitanBlade(), BattleFx_RunTorch(), BattleFx_RunVenus(), BattleFx_RunVine(), BattleFx_RunVolcano(), BattleFx_RunWhirlwind(), and BattleFx_StartElementStreaks().

◆ 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.

Definition at line 392 of file canvas.c.

Referenced by BattleFx_OpenCanvasLayer().

◆ 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.

Definition at line 463 of file canvas.c.

Referenced by BattleFx_BeginTiledCanvas(), BattleFx_InitTilemapAndFlushQueue(), BattleFx_RunCastingImpact(), BattleFx_RunCondemn(), and BattleFx_RunRay().

◆ 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.

Definition at line 490 of file canvas.c.

Referenced by BattleFx_EndCanvasLayer(), 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(), and BattleFx_RunWhirlwind().

◆ 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.

Definition at line 537 of file canvas.c.

Referenced by BattleFx_HideBg1AndRestoreBackdrop(), BattleFx_RunBeamSequence(), and BattleFx_RunRingAndSparkScene().

◆ 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.

Definition at line 568 of file canvas.c.

Referenced by BattleFx_RunBeamSequence(), BattleFx_RunRingAndSparkScene(), and BattleFx_SetupCanvasTileMap().

◆ 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.

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

Definition at line 632 of file canvas.c.

Referenced by BattleFx_DrawClippedCanvasLine(), BattleFx_DrawStreaks(), and BattleFx_RunNeptune().