79 for (sparkIndex = 0; sparkIndex < 16; sparkIndex++) {
80 spark = &work->
sparks[sparkIndex];
87 (spark->
pos[1] >> 8) * (spark->
pos[1] >> 8) +
88 (spark->
pos[2] >> 8) * (spark->
pos[2] >> 8));
89 if (distance <= 0xfff) {
94 axisPosition = spark->
pos;
95 for (axis = 2; axis >= 0; axis--) {
96 coordinate = *axisPosition;
100 axisPosition[3] - (axisPosition[3] >> 7) + acceleration;
101 *axisPosition = coordinate + axisPosition[3];
109 if (life == 0 && work->
frames <= 24) {
112 halfRadius = radius >> 1;
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];
120 spark->
pos[3] = (-spark->
pos[0] >> 7) + (spark->
pos[1] >> 8);
121 spark->
pos[4] = (-spark->
pos[1] >> 7) + (-spark->
pos[0] >> 8);
123 life = spark->
life = (radius >> 13) + 1;
128 x = (spark->
pos[0] >> 10) + 64;
129 y = (spark->
pos[1] >> 10) + 64;
137 x - (size >> 1),
y - (size >> 1), size, size);
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;
174 if (work->
ready != 0) {
182#define STAR_FIELD_UPDATE_CALLBACK BattleFx_UpdateStarField
183#define STAR_FIELD_UPLOAD_CALLBACK BattleFx_UploadStarField
185#define STAR_FIELD_UPDATE_CALLBACK ((SchedulerCallback)BattleFx_UpdateStarField)
186#define STAR_FIELD_UPLOAD_CALLBACK ((SchedulerCallback)BattleFx_UploadStarField)
221 for (effectIndex = 0; effectIndex < 16; effectIndex++) {
224 u32 halfRadius = radius >> 1;
226 spark = &work->
sparks[effectIndex];
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];
234 spark->
pos[3] = (-spark->
pos[0] >> 7) + (spark->
pos[1] >> 8);
235 spark->
pos[4] = (-spark->
pos[1] >> 7) + (-spark->
pos[0] >> 8);
237 spark->
life = (radius >> 13) + 1;
239 for (effectIndex = 0; effectIndex < 3; effectIndex++) {
243 ring = &work->
rings[effectIndex];
244 angle = effectIndex * 0x5555;
335 red = pixel & redMask;
336 green = pixel & greenMask;
337 blue = blueMask & pixel;
341 pixel = ((red >> 16) & redMask) | ((green >> 16) & greenMask);
342 pixel |= (blue >> 16) & blueMask;
343 *destination = pixel;
347 }
while (remaining != 0);
404 for (frame = 0, projectedPosition = &position; frame <= 44; frame++) {
410 *brightness = 0x10000 - frame * 1092, 128);
421 }
else if (mode == 1) {
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,
436 effectWork->trackedCanvas.origin.unk_08 = 1;
440 }
else if (mode == 2) {
void BattlePresentation_ConfigurePaletteFade(s32 mode, s32 unusedResource, s32 fade)
Switches the background's display mode, optionally sets its palette, and rebuilds both its maps.
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).
s32 gBattleFx_RingFrameOffsets[]
s32 gBattleFx_StarWorkOffsets[]
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...
static s32 * EffectPosition_Coordinates(struct EffectPosition *position)
Returns the position's three coordinates as an array.
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.
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...
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
void * Runtime_AllocateBlock(s32 kind, s32 size)
As Runtime_AllocateHeapBlock, but tries EWRAM first, for blocks that need room more than speed: the b...
void * Runtime_AllocateHeapBlock(s32 kind, s32 size)
Returns heap slot kind's block, first allocating size bytes for it (rounded up to words),...
@ HEAP_SLOT_BATTLE_EFFECT
@ HEAP_SLOT_BLITTER_ALTERNATE
@ HEAP_SLOT_BATTLE_CANVAS
void IoWriteQueue_Store16(u32 address, u32 value)
Queues a halfword store.
#define Q_8_8(n)
The BG2/BG3 affine matrix entries are signed 8.8 fixed point: texels stepped per screen pixel.
#define BGCNT_CHAR_BASE(block)
@ DISPCNT_MODE_1
BG0 and BG1 text, BG2 affine.
#define BLDCNT_EFFECT_BLEND
weighted by REG_BLDALPHA
#define BLEND_ALPHA(top, bottom)
A REG_BLDALPHA value: top and bottom are the two targets' weights, out of 16.
#define BGCNT_SCREEN_BASE(block)
#define DMA_COPY_WORDS(n)
#define WIN_RANGE(start, end)
A REG_WINxH or REG_WINxV value: the window covers start up to, but not including, end.
#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.
static s32 Iwram_RatioMulQ14(s32 divisor, s32 value)
All calls go through this layer.
static s32 Iwram_CopyWords(volatile void *destination, const volatile void *source, s32 size)
#define Iwram_MulQ16(left, right)
static s32 Iwram_ClearWords(void *destination, s32 size)
u32 Random16(void)
Advances the game's random number generator (the C library's classic linear congruential one),...
s32 FixedSqrt(s32 value)
Square root of a 16.16 fixed-point value, in 16.16.
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...
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.
s32 Resource_DecodeType01(const void *source, void *destination)
Decodes a type-01 resource and returns its unpacked byte count.
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...
s32 Scheduler_RemoveCallback(SchedulerCallback callback)
Unschedules the task running callback: clears its routine and gives it order 0x7fff,...
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.
s32 Graphics_ResetVramBlockAndReleaseHeapBlocks(s32 unused)
Ends a star field: clears BG2's tiles in character block 1, frees its blitters, canvas and work,...
s32 BattleFx_InitializeStarField(s32 mode)
Starts a star field of the element mode (0 to 3, enum Element order): sixteen sparks on random rings ...
void BattlePres_RestorePalette(void)
Copies the background's saved palette back undarkened, as the star field of BattleFx_PlayUnitElementE...
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.
s32 Graphics_ScaleRgb555Clamped(u16 *source, u16 *destination, s32 scale, s32 count)
Copies count colours from source to destination, each channel scaled by scale (16....
#define STAR_FIELD_UPDATE_CALLBACK
u32 BattleFx_UploadStarField(void)
void Runtime_RemoveIrqHandlerSlot2(void)
Removes the VCount interrupt's handler, as BattlePres_RunEntryTransition installs one; nothing calls ...
#define STAR_FIELD_UPLOAD_CALLBACK
s32 BattleFx_UpdateStarField(void)
#define STATIC_ASSERT(condition)
C89 permits repeated extern declarations of the same array.
#define offsetof(type, member)
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,...
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.
One of the star field's three rings, moving outward on the effect canvas.
s32 velY
1/1024 canvas pixels per frame
s32 y
1/1024 canvas pixels
s32 x
1/1024 canvas pixels
s32 velX
1/1024 canvas pixels per frame
The star field's work: its sprite sheet, 16 sparks and 3 rings.
s32 ready
1 when a drawn frame waits for BattleFx_UploadStarField
u8 sheet[0x11c0]
The blue ring sheet's pictures, decoded: the sparks' sizes at gBattleFx_StarWorkOffsets,...
struct BattleCanvasOrigin canvasOrigin
Where BG2 shows the 128 by 128 canvas: BattleFx_PlayUnitElementEffect keeps it on the unit,...
s32 frames
frames drawn; new sparks start only in the first 25
One of the star field's sparks, drawn inward to the centre.
s32 pos[6]
x, y, z, then their velocities, in 1/1024 canvas pixels
void * Resource_GetTableEntry(s32 index)
Returns the ROM address of resource index from the resource directory.