Alchemy
Loading...
Searching...
No Matches

display.c

Go to the documentation of this file.
1/// @file
2/// Display, scroll and window HBlank DMA helpers.
3/// Part of effect.c, the battle effect object, compiled only through it.
4
6
7/// Puts the battle screen back into the display state every effect starts
8/// from and ends with: no blending, window 0 and window 1 both covering the
9/// battle view (lines 16 to 135), and the effect display mode queued.
10///
11/// Called at the start and end of the handlers that change the display
12/// themselves: Ice and Douse (falling.c), the beam sequence, and the summons
13/// and scenes from Boreas to Judgment. Writes BLDCNT, BLDALPHA, the window
14/// registers and WININ and WINOUT, queues DISPCNT for two frames later and
15/// waits one frame.
17 REG_BLDCNT = 0;
18 // 14/16 of the top layer over all of the bottom, for when blending is on.
19 REG_BLDALPHA = BLEND_ALPHA(14, 16);
21 // Window 1 starts as window 0 without BG1.
25 // A delay of two frames (the queue's control word is delay << 16).
27 WaitFrames(1);
28}
29
30/// Scrolls BG1 by (scrollStepX, scrollStepY) once every scrollInterval
31/// frames.
32///
33/// Runs each frame as a scheduler callback added by BattleFx_RunAtalanta and
34/// BattleFx_RunThor, which set the work block's scroll fields first and
35/// remove it before they return. Counts work->scrollTimer and moves
36/// gBgScroll[1].
39 u32 *timer = (u32 *)&work->scrollTimer;
40
41 (*timer)++;
42 if (*timer == work->scrollInterval) {
43 gBgScroll[1].x += work->scrollStepX;
44 gBgScroll[1].y += work->scrollStepY;
45 *timer = 0;
46 }
47}
48
49/// Slides the affine BG2 in steps: once every scrollInterval frames, writes
50/// the work block's reference point (bg2x, bg2y) to BG2X and BG2Y, then moves
51/// it by (scrollStepX, scrollStepY).
52///
53/// Runs each frame as a scheduler callback added by
54/// BattleFx_RunParticleStreams, which removes it before it returns. Counts
55/// work->scrollTimer.
57 s32 timer;
58 struct BattleEffectWork *work;
59
61 timer = work->scrollTimer + 1;
62 work->scrollTimer = timer;
63 if (timer == work->scrollInterval) {
64 // The reference shown is the one before this step's move.
65 REG_BG2X = work->bg2x;
66 REG_BG2Y = work->bg2y;
67 work->bg2x += work->scrollStepX;
68 work->bg2y += work->scrollStepY;
69 work->scrollTimer = 0;
70 }
71}
72
73/// Restarts DMA 0 as an HBlank transfer of one WIN0H value a line from
74/// PARTICLES (Ram_MapCellBuffer), so window 0's edges follow the per-line
75/// table the effect drew there.
76///
77/// Runs each frame as a scheduler callback added by BattleFx_RunIce and
78/// BattleFx_RunDouse, which remove it before they return. Stopping the
79/// channel first makes each frame's transfer start again from the table's
80/// first line.
82 volatile u16 *channel = REG_DMA0;
83
84 Dma_Stop(channel);
86 (volatile u32 *)channel);
87}
void BattleFx_ConfigureEffectDisplay(void)
Puts the battle screen back into the display state every effect starts from and ends with: no blendin...
Definition display.c:16
void BattleFx_AdvanceBg2OnInterval(void)
Slides the affine BG2 in steps: once every scrollInterval frames, writes the work block's reference p...
Definition display.c:56
void BattleFx_ArmWin0HBlankDma(void)
Restarts DMA 0 as an HBlank transfer of one WIN0H value a line from PARTICLES (Ram_MapCellBuffer),...
Definition display.c:81
void BattleFx_AdvanceScrollOnInterval(void)
Scrolls BG1 by (scrollStepX, scrollStepY) once every scrollInterval frames.
Definition display.c:37
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...
Definition dma.h:62
What every part of the battle effect object shares: its includes, macros and frame-loop helpers.
static void Dma_Stop(volatile u16 *channel)
Stops a DMA channel: clears its repeat and start timing bits, then its enable bit,...
#define EFFECT_WINOUT
Outside the battle view: BG0 and blending only.
#define EFFECT_DISPCNT
The battle screen's display mode while an effect plays: background mode 1 with BG0 to BG2,...
#define EFFECT_SET_BATTLE_WINDOWS()
Windows 0 and 1 both cover the battle view: the full width, lines 16 to.
#define EFFECT_WIN0_LAYERS
Window 0, the battle view, shows BG0 to BG2, sprites and blending.
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
@ HEAP_SLOT_BATTLE_EFFECT
Definition heap_state.h:42
#define WORK_SLOT(n)
Reads slots through their own addresses; adjacent slots are reached by offsets.
Definition heap_state.h:14
#define REG_WININ
Definition io_reg.h:81
#define DMA_HBLANK_HALFWORD_PER_LINE
Definition io_reg.h:228
#define REG_DMA0
Definition io_reg.h:151
#define REG_WIN0H
Definition io_reg.h:74
#define WININ_WIN1_BG0
Definition io_reg.h:93
#define WININ_WIN1_CLR
Definition io_reg.h:98
#define REG_BG2X
Definition io_reg.h:65
#define REG_DISPCNT
Definition io_reg.h:9
#define REG_BG2Y
Definition io_reg.h:66
#define BLEND_ALPHA(top, bottom)
A REG_BLDALPHA value: top and bottom are the two targets' weights, out of 16.
Definition io_reg.h:145
#define REG_BLDALPHA
Definition io_reg.h:142
#define REG_WINOUT
Definition io_reg.h:82
#define WININ_WIN1_OBJ
Definition io_reg.h:97
#define REG_BLDCNT
Definition io_reg.h:119
#define WININ_WIN1_BG2
Definition io_reg.h:95
#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...
struct BgScroll gBgScroll[]
The running battle effect's work: its canvas image, 64 particles, the display registers it stages and...
s32 bg2x
BG2's reference point, written to BG2X and BG2Y by Display_ApplyBg2Reference and BattleFx_AdvanceBg2O...
s32 scrollStepY
added to BG1 or BG2 y at each step
s32 scrollTimer
frames since the last interval scroll step
s32 scrollStepX
added to BG1 or BG2 x at each step
s32 scrollInterval
frames between interval scroll steps
u16 y
pixels
Definition map_scroll.h:65
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
unsigned short u16
Definition types.h:13
#define PARTICLES
The map cell buffer (gMapCellBuffer), which the effects borrow, has two views here: Ram_MapCellBuffer...
Definition effect.h:221