Alchemy
Loading...
Searching...
No Matches

star_field.c

Go to the documentation of this file.
1/// @file
2/// A unit's elemental glow: the star field and the other glows.
3/// Part of battle.c, the battle object, compiled only through it.
4
6
7/// One of the star field's sparks, drawn inward to the centre.
8struct Spark {
9 s32 pos[6]; ///< x, y, z, then their velocities, in 1/1024 canvas pixels
10 s32 life; ///< frames left
11};
12
13/// The star field's work: its sprite sheet, 16 sparks and 3 rings. It lives
14/// in the HEAP_SLOT_BATTLE_EFFECT work slot.
15struct SparkWork {
16 /// The blue ring sheet's pictures, decoded: the sparks' sizes at
17 /// gBattleFx_StarWorkOffsets, the rings' frames at
18 /// gBattleFx_RingFrameOffsets.
19 u8 sheet[0x11c0];
20 struct Spark sparks[16];
21 struct Ring rings[3];
22 s32 frames; ///< frames drawn; new sparks start only in the first 25
23 s32 ready; ///< 1 when a drawn frame waits for BattleFx_UploadStarField
24 /// Where BG2 shows the 128 by 128 canvas: BattleFx_PlayUnitElementEffect
25 /// keeps it on the unit, as an effect's tracked canvas would be.
27};
28
29STATIC_ASSERT(offsetof(struct SparkWork, canvasOrigin) ==
30 offsetof(struct BattleEffectWork, trackedCanvas.origin));
31
32/// A blitter loaded into a work slot: draws a width by height picture at
33/// (x, y) on the canvas.
34typedef void (*DrawFunc)(void *dest, u8 *src, s32 x, s32 y, s32 width,
35 s32 height);
36
37// Draws the star field's next frame on the canvas (HEAP_SLOT_BATTLE_CANVAS):
38// each spark falls towards the centre and is drawn smaller as its life runs
39// out, a spent one starts again on a ring of random radius during the first
40// 25 frames, and the three rings move outward through four frames. Sets
41// SparkWork.ready for BattleFx_UploadStarField. Runs each frame as a
42// scheduler callback added by BattleFx_InitializeStarField.
43// UB: the scheduler invokes a void callback. Plain void changes the native
44// return register from r1 to r0 in tbs-en; matching builds keep the old type.
45#ifdef UBFIX
46void BattleFx_UpdateStarField(void) {
47#else
49#endif
50 s32 ringIndex;
51 s32 frame;
52 u32 size;
53 s32 ringX;
54 s32 ringY;
55 s32 phase;
56 void *canvas;
57 s32 sparkIndex;
58 struct SparkWork *work;
59 DrawFunc draw;
60 struct Spark *spark;
61 struct Ring *ring;
62 s32 *axisPosition;
63 s32 axis;
64 s32 distance;
65 s32 scale;
66 s32 coordinate;
67 s32 acceleration;
68 u32 radius;
69 s32 angle;
70 u32 halfRadius;
71 s32 x;
72 s32 y;
73 s32 life;
74
77 work->ready = 0;
79 for (sparkIndex = 0; sparkIndex < 16; sparkIndex++) {
80 spark = &work->sparks[sparkIndex];
81 life = spark->life;
82 // A live spark ends within 0xfff (4 canvas pixels) of the centre; else
83 // each axis's velocity loses 1/128 and gains a pull of 1.1875 (0x13000)
84 // towards the centre, the axis's share of its distance.
85 if (life != 0) {
86 distance = FixedSqrt((spark->pos[0] >> 8) * (spark->pos[0] >> 8) +
87 (spark->pos[1] >> 8) * (spark->pos[1] >> 8) +
88 (spark->pos[2] >> 8) * (spark->pos[2] >> 8));
89 if (distance <= 0xfff) {
90 spark->life = 0;
91 } else {
92 scale = Iwram_RatioMulQ14(distance, 0x10000);
93 spark->life--;
94 axisPosition = spark->pos;
95 for (axis = 2; axis >= 0; axis--) {
96 coordinate = *axisPosition;
97 acceleration =
98 Iwram_MulQ16(Iwram_MulQ16(-coordinate >> 8, scale), 0x13000);
99 axisPosition[3] =
100 axisPosition[3] - (axisPosition[3] >> 7) + acceleration;
101 *axisPosition = coordinate + axisPosition[3];
102 axisPosition++;
103 }
104 }
105 life = spark->life;
106 }
107 // A spent spark starts again, as BattleFx_InitializeStarField starts
108 // them, while the field is young.
109 if (life == 0 && work->frames <= 24) {
110 angle = Random16();
111 radius = Random16() + 0x10000;
112 halfRadius = radius >> 1;
113 spark->pos[0] = Iwram_MulQ16(Trig_Cos(angle), halfRadius);
114 spark->pos[1] = Iwram_MulQ16(Trig_Sin(angle), halfRadius);
115 if (spark->pos[0] & 1)
116 spark->pos[0] = -spark->pos[0];
117 if (spark->pos[1] & 1)
118 spark->pos[1] = -spark->pos[1];
119 spark->pos[2] = (Random16() + 0x8000) >> 2;
120 spark->pos[3] = (-spark->pos[0] >> 7) + (spark->pos[1] >> 8);
121 spark->pos[4] = (-spark->pos[1] >> 7) + (-spark->pos[0] >> 8);
122 spark->pos[5] = 0;
123 life = spark->life = (radius >> 13) + 1;
124 }
125 // Drawn about the canvas's centre (64, 64), 1 to 4 pixels square by its
126 // life left, 4 from three frames left.
127 if (life != 0) {
128 x = (spark->pos[0] >> 10) + 64;
129 y = (spark->pos[1] >> 10) + 64;
130 frame = life;
131 if (frame < 0)
132 frame = 0;
133 else if (frame > 6)
134 frame = 6;
135 size = gBattleFx_StarSizes[frame];
136 draw(canvas, (u8 *)work + gBattleFx_StarWorkOffsets[frame],
137 x - (size >> 1), y - (size >> 1), size, size);
138 }
139 }
140 // The rings, 32 by 32, with the other blitter: each shows its four frames
141 // eight frames apiece, then is no longer drawn.
143 for (ring = work->rings, ringIndex = 2; ringIndex >= 0; ringIndex--, ring++) {
144 ring->x += ring->velX;
145 ring->y += ring->velY;
146 ringX = ring->x >> 10;
147 ringY = ring->y >> 10;
148 phase = 3 - ring->age / 8;
149 if (phase >= 0) {
150 ring->age++;
151 draw(canvas, (u8 *)work + gBattleFx_RingFrameOffsets[phase], ringX + 48,
152 ringY + 48, 32, 32);
153 }
154 }
155 work->frames++;
156 work->ready = 1;
157}
158
159// Copies the canvas, once a frame is drawn, to BG2's tiles in character block
160// 1 through ColorBuffer_BackupAndScaleThreeQuarters, and clears
161// SparkWork.ready. Runs each frame as a scheduler callback added by
162// BattleFx_InitializeStarField. UB: the scheduler invokes a void callback.
163// Plain void changes the native return register from r1 to r0 in tbs-en;
164// matching builds keep the old type.
165#ifdef UBFIX
166void BattleFx_UploadStarField(void) {
167#else
169#endif
170 void *source = gWorkSlot[HEAP_SLOT_BATTLE_CANVAS];
172
173 if (source != 0) {
174 if (work->ready != 0) {
175 work->ready = 0;
177 }
178 }
179}
180
181#ifdef UBFIX
182#define STAR_FIELD_UPDATE_CALLBACK BattleFx_UpdateStarField
183#define STAR_FIELD_UPLOAD_CALLBACK BattleFx_UploadStarField
184#else
185#define STAR_FIELD_UPDATE_CALLBACK ((SchedulerCallback)BattleFx_UpdateStarField)
186#define STAR_FIELD_UPLOAD_CALLBACK ((SchedulerCallback)BattleFx_UploadStarField)
187#endif
188
189/// Starts a star field of the element mode (0 to 3, enum Element order):
190/// sixteen sparks on random rings and three rings 120 degrees apart.
191/// Allocates the field's work (HEAP_SLOT_BATTLE_EFFECT) and a cleared
192/// 128 by 128 canvas (HEAP_SLOT_BATTLE_CANVAS), decodes the blue ring sheet
193/// into the work, loads the element's 64 colours over the first of BG palette
194/// RAM, sets BG2's affine parameters to no zoom, loads both blitters and adds
195/// BattleFx_UpdateStarField and BattleFx_UploadStarField. Also sets
196/// BattleBackgroundView.mode to 1. Called by BattleFx_PlayUnitElementEffect;
197/// Graphics_ResetVramBlockAndReleaseHeapBlocks undoes it.
199 struct SparkWork *work;
200 struct Spark *spark;
201 struct Ring *ring;
202 s32 effectIndex;
203 u8 *graphics;
204 s32 zero;
205 /* FAKEMATCH(dead): an unused Spark for the frame's 28 bytes; without it, 2
206 * of 246 instructions differ in tbs-en. */
207 UNUSED struct Spark unused;
208
209 // Word 2 of the background's work is BattleBackgroundView.mode.
210 ((s32 *)gTransitionWork)[2] = 1;
213 /* FAKEMATCH(one-pass): an empty one-pass loop, a scheduling barrier that
214 * keeps the multiply routine's address ahead of the spark cursor; without
215 * it, 1 of 246 instructions differ in tbs-en. */
216 do {
217 } while (0);
218 // Each spark at a random angle, half of 1 to 2 (16.16) out, a random height
219 // above, swirling: its velocity points inward and a little sideways. An odd
220 // coordinate is mirrored, and the further out, the longer it lives.
221 for (effectIndex = 0; effectIndex < 16; effectIndex++) {
222 s32 angle = Random16();
223 u32 radius = Random16() + 0x10000;
224 u32 halfRadius = radius >> 1;
225
226 spark = &work->sparks[effectIndex];
227 spark->pos[0] = Iwram_MulQ16(Trig_Cos(angle), halfRadius);
228 spark->pos[1] = Iwram_MulQ16(Trig_Sin(angle), halfRadius);
229 if (spark->pos[0] & 1)
230 spark->pos[0] = -spark->pos[0];
231 if (spark->pos[1] & 1)
232 spark->pos[1] = -spark->pos[1];
233 spark->pos[2] = (Random16() + 0x8000) >> 2;
234 spark->pos[3] = (-spark->pos[0] >> 7) + (spark->pos[1] >> 8);
235 spark->pos[4] = (-spark->pos[1] >> 7) + (-spark->pos[0] >> 8);
236 spark->pos[5] = 0;
237 spark->life = (radius >> 13) + 1;
238 }
239 for (effectIndex = 0; effectIndex < 3; effectIndex++) {
240 s32 radius = 0x1000;
241 s32 angle;
242
243 ring = &work->rings[effectIndex];
244 angle = effectIndex * 0x5555;
245 ring->x = Iwram_MulQ16(Trig_Cos(angle), radius);
246 ring->y = Iwram_MulQ16(Trig_Sin(angle), radius);
247 ring->velX = Iwram_MulQ16(Trig_Cos(angle), 0x200);
248 ring->velY = Iwram_MulQ16(Trig_Sin(angle), 0x200);
249 ring->age = 0;
250 }
251 work->frames = 0;
252 work->ready = 0;
253 work->canvasOrigin.unk_08 = 0;
255 // The sheet's 128 bytes of colours, then its pictures; then the
256 // element's own colours over them.
258 Iwram_CopyWords(BG_PLTT, graphics, 128);
259 graphics += 128;
260 Resource_DecodeType01(graphics, work);
261 switch (mode) {
262 case 0:
264 break;
265 case 1:
267 break;
268 case 2:
270 break;
271 default:
273 break;
274 }
275 Dma_Set(graphics, BG_PLTT, DMA_COPY_WORDS(32), REG_DMA3);
276 /* FAKEMATCH(one-pass): the zero and its stores in a one-pass block, which
277 * keeps the zero ahead of BG2X's address; as plain stores of 0, 1 of 246
278 * instructions differ in tbs-en. */
279 do {
280 zero = 0;
281 REG_BG2X = zero;
282 REG_BG2Y = zero;
283 } while (0);
292}
293
294/// Ends a star field: clears BG2's tiles in character block 1, frees its
295/// blitters, canvas and work, turns BG2 off and removes both callbacks.
296/// Called by BattleFx_PlayUnitElementEffect once the field has played.
307}
308
309/// Copies count colours from source to destination, each channel scaled by
310/// scale (16.16, at most 1), and returns 0.
311/// Called to darken the background's palette by
312/// BattlePresentation_SetPaletteLevel, BattleBackground_Load,
313/// BattleFx_PlayUnitElementEffect, the item staging (staging.c) and the
314/// effects' canvas (canvas.c).
315s32 Graphics_ScaleRgb555Clamped(u16 *source, u16 *destination, s32 scale,
316 s32 count) {
317 s32 remaining;
318 u32 redMask;
319 u32 greenMask;
320 u32 blueMask;
321 u32 pixel;
322 u32 red;
323 u32 green;
324 u32 blue;
325
326 if (scale > 0x10000)
327 scale = 0x10000;
328 if (count > 0) {
329 redMask = 0x1f;
330 greenMask = 0x3e0;
331 blueMask = 0x7c00;
332 remaining = count;
333 do {
334 pixel = *source;
335 red = pixel & redMask;
336 green = pixel & greenMask;
337 blue = blueMask & pixel;
338 red *= scale;
339 green *= scale;
340 blue *= scale;
341 pixel = ((red >> 16) & redMask) | ((green >> 16) & greenMask);
342 pixel |= (blue >> 16) & blueMask;
343 *destination = pixel;
344 source++;
345 destination++;
346 remaining--;
347 } while (remaining != 0);
348 }
349 return 0;
350}
351
352/// Plays a glow of the element about a unit, and returns when it is over.
353/// By mode: 0 the star field gathering on the unit while the background
354/// darkens (a cast), 1 the element streaks, 2 the element pillar at strength
355/// variant (a summon's power boost) and 3 the element burst (a Djinni set).
356/// Called with 0 by BattlePresentation_RunUnitTransition and
357/// BattlePres_RunPsynergyCast, with 1 by the latter, with 2 by
358/// BattleUnit_ProcessTurnEnd and with 3 by Battle_ProcessRoundEnd and
359/// BattleCommand_BuildPlan. Every mode first puts the background in mode 1
360/// and opens window 0 over lines 16 to 135, with BG2 blended over the other
361/// layers; mode 0 leaves the background's palette and BattleWork.brightness
362/// darkened.
363void BattleFx_PlayUnitElementEffect(s32 unitId, s32 element, s32 mode,
364 s32 variant) {
365 /* FAKEMATCH(dead): an unused array for the frame's 40 bytes; without it, 2
366 * of 249 instructions differ in tbs-en. */
367 UNUSED s32 spare[10];
368 struct EffectPosition position;
369 struct EffectPosition position2;
370 struct BattlePresentationWork launch;
371 struct BattlePresentationWork launch2;
372 /* FAKEMATCH(temporary): one variable holds slot 12's address, the battle
373 * work's base and later IME's; as battle = gWorkSlot[9] with ime set only
374 * in the loop, 61 of 249 instructions differ in tbs-en. */
375 volatile u16 *ime = (volatile u16 *)&gWorkSlot[12];
376 struct BattleWork *battle = *(struct BattleWork **)((u8 *)ime - 12);
377 struct SparkWork *work;
378 s32 frame;
379 s32 *brightness;
380 struct EffectPosition *projectedPosition;
381
382 WaitFrames(1);
393 WaitFrames(1);
394 Io_Write16(WIN_RANGE(0, 240), &REG_WIN0H);
395 Io_Write16(WIN_RANGE(16, 136), &REG_WIN0V);
398 if (mode == 0) {
399 // The star field for 45 frames, darkening the background a level a
400 // frame for its first 25 and keeping BG2's canvas centred on the unit
401 // (its origin queued to BG2X and BG2Y with interrupts off).
404 for (frame = 0, projectedPosition = &position; frame <= 44; frame++) {
405 brightness = &battle->brightness;
406 ime = &REG_IME;
408 if (frame <= 24)
410 *brightness = 0x10000 - frame * 1092, 128);
412 unitId, EffectPosition_Coordinates(projectedPosition));
413 work->canvasOrigin.x = (64U - (u32)projectedPosition->x) << 8;
414 work->canvasOrigin.y = (64U - (u32)projectedPosition->y) << 8;
416 DMA_COPY_WORDS(2));
417 work->canvasOrigin.unk_08 = 1;
418 WaitFrames(1);
419 }
421 } else if (mode == 1) {
422 // The streaks for 40 frames, their canvas centred on the unit likewise.
423 struct BattleEffectWork *effectWork;
424
425 // The scene uses its image area to stage the tracked canvas origin.
427 for (frame = 0; frame < 40; frame++) {
430 unitId, EffectPosition_Coordinates(&position2));
431 effectWork->trackedCanvas.origin.x = (64U - (u32)position2.x) << 8;
432 effectWork->trackedCanvas.origin.y = (64U - (u32)position2.y) << 8;
434 (u32)&effectWork->trackedCanvas.origin.x,
435 DMA_COPY_WORDS(2));
436 effectWork->trackedCanvas.origin.unk_08 = 1;
437 WaitFrames(1);
438 }
440 } else if (mode == 2) {
441 // Modes 2 and 3 run an effect with the unit as its actor and only
442 // target.
443 launch.effect.prelude = 0;
444 launch.effect.kind = element;
445 launch.effect.variant = variant;
446 launch.effect.actor = unitId;
447 launch.effect.actors[0] = unitId;
448 launch.effect.firstTarget = unitId;
449 launch.effect.count = 1;
450 launch.effect.range = 1;
452 } else {
453 launch2.effect.kind = element;
454 launch2.effect.prelude = 0;
455 launch2.effect.variant = 0;
456 launch2.effect.actor = unitId;
457 launch2.effect.actors[0] = unitId;
458 launch2.effect.firstTarget = unitId;
459 launch2.effect.count = 1;
460 launch2.effect.range = 1;
462 }
463}
464
465/// Copies the background's saved palette back undarkened, as the star field
466/// of BattleFx_PlayUnitElementEffect leaves it dark.
467/// Called by BattlePresentation_RunUnitTransition and
468/// BattlePres_RunPsynergyCast once the effect has played.
471}
472
473/// Removes the VCount interrupt's handler, as BattlePres_RunEntryTransition
474/// installs one; nothing calls it.
477}
void BattlePresentation_ConfigurePaletteFade(s32 mode, s32 unusedResource, s32 fade)
Switches the background's display mode, optionally sets its palette, and rebuilds both its maps.
Definition background.c:85
void BattlePresentation_SetPaletteLevel(s32 unused, s32 level)
Copies the background's saved palette to BG palettes 6 to 13, darkened by level (0 for none).
Definition background.c:42
s32 gBattleFx_RingFrameOffsets[]
s32 gBattleFx_StarWorkOffsets[]
u8 gBattleFx_StarSizes[]
struct BattlePresentationTransition * gTransitionWork
What every part of the battle object shares: its includes, in their original order,...
#define BATTLE_BG_PALETTE
The battle background's colours: BG palettes 6 to 13, filled from BattleWork.palette,...
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
static s32 * EffectPosition_Coordinates(struct EffectPosition *position)
Returns the position's three coordinates as an array.
Definition effect_step.h:68
void BattleFx_EndElementStreaksFar(void)
void BattleFx_StartElementStreaksFar(s32 element)
void BattleFx_RunElementPillarFar(struct BattleEffectArgument *effect)
void BattleFx_RunElementBurstFar(struct BattleEffectArgument *effect)
s32 BattleEffect_LoadWorkFar(s32 slot, s32 width_shift, s32 height_shift, s32 flags, u32 mode)
Far call to BattleFx_BuildBlitter.
s32 Trig_Cos(s32 angle)
s32 Trig_Sin(s32 angle)
void Runtime_SetIrqHandler(u32 irq, s32 vcount, InterruptHandler handler)
Installs handler for interrupt irq and enables that interrupt, or with a null handler disables it and...
Definition frame.c:37
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
void * Runtime_AllocateBlock(s32 kind, s32 size)
As Runtime_AllocateHeapBlock, but tries EWRAM first, for blocks that need room more than speed: the b...
Definition heap.c:80
void * Runtime_AllocateHeapBlock(s32 kind, s32 size)
Returns heap slot kind's block, first allocating size bytes for it (rounded up to words),...
Definition heap.c:47
@ HEAP_SLOT_BATTLE_EFFECT
Definition heap_state.h:42
@ HEAP_SLOT_BLITTER_ALTERNATE
Definition heap_state.h:47
@ HEAP_SLOT_BLITTER
Definition heap_state.h:46
@ HEAP_SLOT_BATTLE_CANVAS
Definition heap_state.h:43
void IoWriteQueue_Store16(u32 address, u32 value)
Queues a halfword store.
Definition io_queue.c:21
#define Q_8_8(n)
The BG2/BG3 affine matrix entries are signed 8.8 fixed point: texels stepped per screen pixel.
Definition io_reg.h:59
#define WINOUT_WIN01_OBJ
Definition io_reg.h:107
#define BGCNT_CHAR_BASE(block)
Definition io_reg.h:25
#define REG_WININ
Definition io_reg.h:81
#define BGCNT_256_COLORS
Definition io_reg.h:27
#define BLDCNT_TGT1_BG2
Definition io_reg.h:125
#define REG_BG2PD
Definition io_reg.h:64
#define BG_CHAR_BLOCK(n)
Definition io_reg.h:166
#define REG_WIN0H
Definition io_reg.h:74
@ DISPCNT_OBJ_ON
Definition io_reg.h:44
@ DISPCNT_WIN0_ON
Definition io_reg.h:45
@ DISPCNT_BG0_ON
Definition io_reg.h:40
@ DISPCNT_OBJ_1D_MAP
Definition io_reg.h:39
@ DISPCNT_MODE_1
BG0 and BG1 text, BG2 affine.
Definition io_reg.h:37
@ DISPCNT_BG2_ON
Definition io_reg.h:42
@ DISPCNT_BG1_ON
Definition io_reg.h:41
#define REG_BG2PC
Definition io_reg.h:63
#define REG_BG2X
Definition io_reg.h:65
#define REG_DISPCNT
Definition io_reg.h:9
#define BLDCNT_EFFECT_BLEND
weighted by REG_BLDALPHA
Definition io_reg.h:131
#define REG_IME
Definition io_reg.h:308
#define BLDCNT_TGT2_ALL
Definition io_reg.h:140
#define REG_DMA3
Definition io_reg.h:153
#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 BGCNT_SCREEN_BASE(block)
Definition io_reg.h:28
#define REG_BG2CNT
Definition io_reg.h:21
#define DMA_COPY_WORDS(n)
Definition io_reg.h:226
#define REG_BLDALPHA
Definition io_reg.h:142
#define REG_WINOUT
Definition io_reg.h:82
#define WIN_RANGE(start, end)
A REG_WINxH or REG_WINxV value: the window covers start up to, but not including, end.
Definition io_reg.h:80
#define BG_PLTT
Definition io_reg.h:157
#define REG_BG2PB
Definition io_reg.h:62
#define WININ_WIN0_ALL
Definition io_reg.h:92
#define WINOUT_WIN01_BG0
Definition io_reg.h:103
#define REG_BG2PA
Definition io_reg.h:61
#define REG_BLDCNT
Definition io_reg.h:119
#define REG_WIN0V
Definition io_reg.h:76
#define IO_WRITE_QUEUE_PUSH_IME(ime, address, value, control)
Like IO_WRITE_QUEUE_PUSH, but keeps IME's address in the caller's ime variable while disabling and re...
#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...
#define Io_Write16(v, reg)
Writes a value to a 16-bit register or memory location.
Definition iowrite.h:14
@ IRQ_VCOUNT
Definition irq.h:15
static s32 Iwram_RatioMulQ14(s32 divisor, s32 value)
All calls go through this layer.
Definition iwram_call.h:51
static s32 Iwram_CopyWords(volatile void *destination, const volatile void *source, s32 size)
Definition iwram_call.h:85
#define Iwram_MulQ16(left, right)
Definition iwram_call.h:127
static s32 Iwram_ClearWords(void *destination, s32 size)
Definition iwram_call.h:55
u32 Random16(void)
Advances the game's random number generator (the C library's classic linear congruential one),...
Definition math.c:10
s32 FixedSqrt(s32 value)
Square root of a 16.16 fixed-point value, in 16.16.
Definition math.c:149
void Runtime_ReleaseHeapBlock(s32 slot)
s32 BattleMotion_ProjectScaledPosition(s32 unitId, s32 *projected)
Projects the point above unit id where its effects play (its class's height, BattleUnit_GetEffectHeig...
Definition motion.c:310
char ResourceId_VioletPaletteD
char ResourceId_BlueRingSheet
char ResourceId_YellowPaletteB
char ResourceId_RedPaletteC
void ColorBuffer_BackupAndScaleThreeQuarters(u8 *buffer, u8 *backup, u32 bytes)
Scales every pixel to three quarters.
Definition decompress.c:65
s32 Resource_DecodeType01(const void *source, void *destination)
Decodes a type-01 resource and returns its unpacked byte count.
Definition decompress.c:31
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...
Definition scheduler.c:102
s32 Scheduler_RemoveCallback(SchedulerCallback callback)
Unschedules the task running callback: clears its routine and gives it order 0x7fff,...
Definition scheduler.c:146
void * gWorkSlot[]
void(*) DrawFunc(void *dest, u8 *src, s32 x, s32 y, s32 width, s32 height)
A blitter loaded into a work slot: draws a width by height picture at (x, y) on the canvas.
Definition star_field.c:34
s32 Graphics_ResetVramBlockAndReleaseHeapBlocks(s32 unused)
Ends a star field: clears BG2's tiles in character block 1, frees its blitters, canvas and work,...
Definition star_field.c:297
s32 BattleFx_InitializeStarField(s32 mode)
Starts a star field of the element mode (0 to 3, enum Element order): sixteen sparks on random rings ...
Definition star_field.c:198
void BattlePres_RestorePalette(void)
Copies the background's saved palette back undarkened, as the star field of BattleFx_PlayUnitElementE...
Definition star_field.c:469
void BattleFx_PlayUnitElementEffect(s32 unitId, s32 element, s32 mode, s32 variant)
Plays a glow of the element about a unit, and returns when it is over.
Definition star_field.c:363
s32 Graphics_ScaleRgb555Clamped(u16 *source, u16 *destination, s32 scale, s32 count)
Copies count colours from source to destination, each channel scaled by scale (16....
Definition star_field.c:315
#define STAR_FIELD_UPDATE_CALLBACK
Definition star_field.c:185
u32 BattleFx_UploadStarField(void)
Definition star_field.c:168
void Runtime_RemoveIrqHandlerSlot2(void)
Removes the VCount interrupt's handler, as BattlePres_RunEntryTransition installs one; nothing calls ...
Definition star_field.c:475
#define STAR_FIELD_UPLOAD_CALLBACK
Definition star_field.c:186
s32 BattleFx_UpdateStarField(void)
Definition star_field.c:48
#define STATIC_ASSERT(condition)
C89 permits repeated extern declarations of the same array.
#define offsetof(type, member)
Definition stddef.h:19
Two adjacent affine background coordinates, queued together for BG2X/BG2Y.
s32 y
BG2Y, 8 fractional bits.
s32 unk_08
Written after staging the coordinates; no reader has been identified.
s32 x
BG2X, 8 fractional bits.
s32 range
forwarded action range, otherwise initialized to 1
s32 actor
the user's unit id
s32 kind
handler table index; 200 more for a critical hit
s16 actors[8]
the targets' unit ids, count of them
s32 variant
the ability's size, from 0 (Quake, then Earthquake)
s32 count
targets in actors, at least 1
s32 prelude
1 plays a prelude: in some effects a Djinni appears
s32 firstTarget
the action's first target, standing or not
The running battle effect's work: its canvas image, 64 particles, the display registers it stages and...
s32 frame
frame counter some effects keep, from 0
The effect updates its command while the presentation keeps animation state.
struct BattleEffectArgument effect
The battle's own work: its enemies, units and their objects, the turn's actions, the spoils,...
Definition battle_work.h:71
u16 background
the battle background's id
s32 brightness
the backdrop's brightness, 16.16, 0x10000 full
u16 palette[128]
the backdrop's colours, before scaling
A point projected onto the screen, with its depth.
Definition effect_step.h:46
s32 y
screen pixels
Definition effect_step.h:59
s32 x
screen pixels
Definition effect_step.h:58
One of the star field's three rings, moving outward on the effect canvas.
Definition battle.h:79
s32 velY
1/1024 canvas pixels per frame
Definition battle.h:83
s32 age
frames
Definition battle.h:84
s32 y
1/1024 canvas pixels
Definition battle.h:81
s32 x
1/1024 canvas pixels
Definition battle.h:80
s32 velX
1/1024 canvas pixels per frame
Definition battle.h:82
The star field's work: its sprite sheet, 16 sparks and 3 rings.
Definition star_field.c:15
struct Ring rings[3]
Definition star_field.c:21
s32 ready
1 when a drawn frame waits for BattleFx_UploadStarField
Definition star_field.c:23
u8 sheet[0x11c0]
The blue ring sheet's pictures, decoded: the sparks' sizes at gBattleFx_StarWorkOffsets,...
Definition star_field.c:19
struct Spark sparks[16]
Definition star_field.c:20
struct BattleCanvasOrigin canvasOrigin
Where BG2 shows the 128 by 128 canvas: BattleFx_PlayUnitElementEffect keeps it on the unit,...
Definition star_field.c:26
s32 frames
frames drawn; new sparks start only in the first 25
Definition star_field.c:22
One of the star field's sparks, drawn inward to the centre.
Definition star_field.c:8
s32 life
frames left
Definition star_field.c:10
s32 pos[6]
x, y, z, then their velocities, in 1/1024 canvas pixels
Definition star_field.c:9
void * Resource_GetTableEntry(s32 index)
Returns the ROM address of resource index from the resource directory.
Definition system.c:150
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
unsigned short u16
Definition types.h:13
#define UNUSED
Definition types.h:22
unsigned char u8
Definition types.h:11