49 volatile s32 fillWord;
68 volatile u32 *heldKeys;
69 volatile u32 *repeatedKeys;
117 if (spriteMetadata->
drawKind == 20) {
126 spriteWork.resourceOffset = 0;
127 if (spriteMetadata->
drawKind == 20 && (i & 1) != 0) {
128 spriteWork.resourceOffset = 1;
132 (spriteWork.resourceOffset << 12));
141 spriteWork.flags = &spriteWork.sprite->flags;
142 *spriteWork.flags = shadowsEnabled;
148 if (layers[i].enabled != 0) {
179 if ((*heldKeys &
KEY_UP) != 0) {
188 if ((*repeatedKeys &
KEY_UP) != 0) {
209 sprites->
flags = shadowsEnabled;
218 if (selectedLayer == 1) {
223 if (layers[selectedLayer].animationIndex < 0) {
226 if (selectedLayer == 0) {
235 if (layers[selectedLayer].animationIndex >=
240 if (selectedLayer == 0) {
253 if ((*repeatedKeys &
KEY_L) != 0) {
254 for (i = 0; i < spriteSteps; i++) {
260 if ((*repeatedKeys &
KEY_R) != 0) {
261 for (i = 0; i < spriteSteps; i++) {
271 if (selectedLayer == 0) {
275 if (layers[selectedLayer].enabled != 0) {
279 layers[selectedLayer].colorMode);
281 layers[selectedLayer].animationIndex);
288 if ((*repeatedKeys &
KEY_L) != 0) {
290 if (layers[selectedLayer].priority < 0) {
295 if ((*repeatedKeys &
KEY_R) != 0) {
297 if (layers[selectedLayer].priority > 3) {
305 if (layers[selectedLayer].enabled != 0) {
314 if ((*repeatedKeys &
KEY_L) != 0) {
316 if (layers[selectedLayer].colorMode < 0) {
321 if ((*repeatedKeys &
KEY_R) != 0) {
323 if (layers[selectedLayer].colorMode > 15) {
331 if (layers[selectedLayer].enabled != 0) {
333 layers[selectedLayer].colorMode);
344 if ((*repeatedKeys &
KEY_A) != 0) {
346 if (selectedLayer != 1) {
347 if (layers[selectedLayer].enabled != 0) {
349 layers[selectedLayer].animationIndex);
350 if (selectedLayer == 0) {
356 }
else if (selectedLayer != 0) {
357 layers[selectedLayer].
enabled ^= 1;
359 layers[selectedLayer].enabled != 0
360 ? layers[selectedLayer].priority
370 if ((*heldKeys &
KEY_B) != 0) {
388 spriteId += direction;
400 if (spriteId >= spriteLimit) {
433 switch ((
u32)facingKind) {
435 for (facingIndex = 0; facingIndex < 6; facingIndex++) {
436 angle = (
u32)angle << 16;
437 positions->
x = centerX << 16;
438 angle = (
u32)angle >> 16;
440 positions->
y = centerY << 16;
444 angle = (
s16)(angle + 0x2aaa);
453 for (facingIndex = 0; facingIndex < 8; facingIndex++) {
454 angle = (
u32)angle << 16;
455 positions->
x = centerX << 16;
456 angle = (
u32)angle >> 16;
458 positions->
y = centerY << 16;
462 angle = (
s16)(angle + 0x2000);
471 angle = (
u32)angle << 16;
472 positions->
x = centerX << 16;
473 angle = (
u32)angle >> 16;
475 positions->
y = centerY << 16;
479 angle = (
s16)(angle + 0x1999);
485 initialHeading = angle;
486 angle = (
s16)(initialHeading + 0x4000);
488 pairedPositions = positions;
489 while (facingIndex < 2) {
490 pairedPositions[facingIndex * 2].
x = centerX << 16;
491 pairedPositions[facingIndex * 2].
height = 0;
492 pairedPositions[facingIndex * 2].
y = centerY << 16;
493 angle = (
u32)angle << 16;
494 angle = (
u32)angle >> 16;
497 pairedPositions[facingIndex * 2 + 1].
x = centerX << 16;
500 pairedPositions[facingIndex * 2 + 1].
height = 0;
501 pairedPositions[facingIndex * 2 + 1].
y = centerY << 16;
504 angle = ((
u32)angle + 0x8000) << 16;
512 angle = (
s32)(((
u32)angle << 16) + 0x20000000) >> 16;
513 for (facingIndex = 0; facingIndex < 4; facingIndex++) {
514 angle = (
u32)angle << 16;
515 angle = (
u32)angle >> 16;
516 positions->
x = centerX << 16;
518 positions->
y = centerY << 16;
522 angle = (
s16)(angle + 0x4000);
533#define UI_DEFINE_SET_GRID_COLUMN(name, field) \
534 void name(s32 layerIndex, s32 value) { \
535 struct AnimationObject *spriteGroup = gSpriteObjects; \
538 layerIndex &= ANIMATION_LAYER_COUNT - 1; \
539 for (spriteIndex = 0; spriteIndex < UI_SPRITE_VIEWER_COPY_COUNT; \
541 spriteGroup->entries[layerIndex]->field = value; \
565 s32 initialFrame = 0;
576 entry->
pos = initialFrame;
581 spriteGroup->
rotation = initialFrame;
620 u16 pairedFacingStep = 0;
627 switch (facingKind) {
652 pairedFacingStep = 0x8000;
664 for (spriteIndex = 0; spriteIndex < count; spriteIndex++) {
670 angle += pairedFacingStep;
674#undef UI_DEFINE_SET_GRID_COLUMN
s32 ResourceSlot_Load(u32 slot, u32 *buffer, s32 number, u32 variant)
Loads the frames of animation id number into resource slot slot's buffer: the resource listed for it ...
s32 ResourceMetadata_Register(struct AnimationObject *sprite, s32 id)
Adds a layer of animation id to a sprite, in its first free layer of four.
void Animation_InitWorkFromMetadata(struct AnimationEntry *layer)
Resets one animation layer from its animation's metadata, as Animation_InitializeObjects does for eac...
struct AnimationObject * ResourceObject_Create(s32 id)
Creates a sprite for animation id, taking one of the 64 free sprites and a VRAM cache entry for its t...
#define Dma_Fill32Cell(cell, value, destination, size)
Dma_Fill32 through the caller's own volatile word cell, so a function that fills several blocks keeps...
void Fade_FromBlack(s32 frames)
Fades in from black.
struct AnimationMetadata * Resource_GetMetadataRecordFar(u32 number)
void ObjectSystem_Initialize(s32 controlMode)
Sets up the object system: allocates and zeroes the 64 objects and registers the per-frame updates.
What every part of the field object shares: its includes and the few names more than one part uses.
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
u32 gFrameTick
Counted up by every VBlank.
u8 gDebugMode
Debug builds: Start+Select pauses the frame loop.
const u8 FarCall_ResourceTable[]
struct AnimationObject * gSpriteObjects
const struct SpriteScale gBattle_FormationPlacementScale
The sprite viewer's (x, y) sprite scale, 1.0 each (Q16), which Battle_PlaceActorsByFormationKind read...
void Runtime_InitializeHeap(void)
Empties the heap: clears the 64 words of gWorkSlot (both pool pointers and every named slot) and sets...
void * Runtime_AllocateBlock(s32 kind, s32 size)
As Runtime_AllocateHeapBlock, but tries EWRAM first, for blocks that need room more than speed: the b...
#define WORK_SLOT(n)
Reads slots through their own addresses; adjacent slots are reached by offsets.
#define BLDCNT_EFFECT_BLEND
weighted by REG_BLDALPHA
volatile u32 gKeysHeld
Keys down now.
volatile u32 gKeysPressed
Keys that went down this frame.
volatile u32 gKeysRepeat
Pressed keys, repeating while held: after 19 frames, then every 6.
void Vector_AddPolarOffset(s32 radius, s32 angle, void *position)
Moves the point position by radius in direction angle on the ground plane: x by the cosine,...
#define Ram_MapCellBuffer
#define Ram_ActorSpriteSlots
static s32 * SpritePlacement_Values(struct SpritePlacement *placement)
Returns the placement's values as a writable array.
char ResourceId_ResourceFarCalls
char ResourceId_ResourceFarCallsAlternate
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...
void Scheduler_ResetTaskTable(void)
Empties the task table: every slot gets no routine, order 0xffff (sorted last) and no flags.
void Render_ApplyProjectedPlacement(struct AnimationObject *sprite, const struct SpritePlacement *position, const struct SpriteScale *scale, s32 facing)
Places a sprite for the scrolling camera and queues it for drawing.
s32 Ui_FindNextSpriteWithImage(s32 spriteId, s32 direction)
Returns the next sprite id after spriteId, stepping by direction (1 or -1) and wrapping within 0-511,...
void Ui_SetGridColumnPriority(s32 layerIndex, s32 value)
void Ui_RunIconMonitor(void)
A debug sprite viewer, which never returns.
@ UI_SPRITE_VIEWER_EDIT_PRIORITY
@ UI_SPRITE_VIEWER_EDIT_COLOR
@ UI_SPRITE_VIEWER_EDIT_ANIMATION
@ UI_SPRITE_VIEWER_EDIT_SPRITE
@ UI_SPRITE_VIEWER_EDIT_COUNT
@ UI_SPRITE_VIEWER_COPY_COUNT
@ UI_SPRITE_VIEWER_ANIMATION_LIMIT
@ UI_SPRITE_VIEWER_SPRITE_LIMIT
@ UI_SPRITE_VIEWER_HIDDEN_PRIORITY
void Ui_FillGridColumnFromMetadata(s32 layerIndex, s32 animationIndex)
Starts animationIndex on layerIndex of each of the viewer's ten sprites, each one a frame (16 timer u...
void Map_BuildProbeRing(s32 centerX, s32 centerY, struct SpritePlacement *positions)
Lays out the sprite viewer's ring around pixel (x, z): one position per facing of the first sprite's ...
void Battle_PlaceActorsByFormationKind(void)
Each frame in the sprite viewer: places each copy of the sprite at its ring position,...
void Ui_SetGridColumnParameter(s32 layerIndex, s32 value)
Sets the draw parameter or the priority of one layer of the viewer's ten sprites.
void Ui_SetGridColumnNumber(s32 layerIndex, s32 spriteId)
Sets spriteId on layerIndex of each of the viewer's ten sprites.
#define UI_DEFINE_SET_GRID_COLUMN(name, field)
Defines name(slot, value), which sets field of entry slot (0-3) in each of the first ten sprites to v...
One animation layer of a sprite: its animation id, frames, running script and timer.
u8 frameBase
frame the script chose, before facing; 255 blank
u8 pos
byte offset of the next command in script
u8 ** scripts
the metadata's command scripts, one per animation number
u8 step
taken off timer each frame; 16 is normal speed
u8 * script
the running script; null when stopped (ANIM_CMD_END)
u8 kind
The facing table its frames follow (from the metadata, or ANIM_CMD_SET_KIND); zero marks a free layer...
s16 animId
the sprite id whose metadata and frames it uses
u16 timer
Time left on the current frame in sixteenths of a frame, read signed: each timed command adds its arg...
u8 frame
frame shown, frameBase plus the facing offset; 255 none
An animated sprite: its image and shadow, scale, rotation, size and up to four animation layers.
u16 rotation
1/65536 turns
u8 flags
bits: 1 outlined in ObjectSystemWork's edge and fill colours | 0 shadow drawn (set when created)
u8 width
pixels; zero marks a free sprite
struct AnimationEntry * entries[4]
its layers; empty ones null
A sprite's screen position and its two vertical offsets, in 16.16 pixels.
s32 x
screen x of the sprite's centre
s32 y
screen y at the ground; sets the depth slot
s32 height
how far the image is raised above y
Horizontal and vertical sprite scale; 0x10000 is the original size.
One animation layer the sprite viewer edits.
s8 colorMode
SpriteColorMode; the viewer cycles through 0 to 15.
s16 spriteId
metadata record selected for this layer
s16 animationIndex
script selected from that metadata
u8 enabled
zero hides it by a priority above the drawing range
s8 priority
drawing order, 0 to 3
s32 RuntimeDispatch_ReturnZero(s32 unused0, const u8 *unused1)
An exported stub that ignores its arguments and reports 0.
void VramCache_Reset(void)
Frees every block and every cache entry.