12#define DEBUG_SELECT_VALUE 0x18f
14#define DEBUG_SELECT_VALUE 480
20#define BACKGROUND_LEVEL_STEP 1092
24#define BACKGROUND_PLANE_UPPER \
25 (BGCNT_SIZE(1) | BGCNT_SCREEN_BASE(7) | BGCNT_256_COLORS | \
26 BGCNT_CHAR_BASE(2) | BGCNT_PRIORITY(2))
28#define BACKGROUND_PLANE_LOWER \
29 (BGCNT_SIZE(1) | BGCNT_SCREEN_BASE(7) | BGCNT_256_COLORS | \
30 BGCNT_CHAR_BASE(3) | BGCNT_PRIORITY(2))
32#define BACKGROUND_PLANE_OFF \
33 (BGCNT_WRAP | BGCNT_SCREEN_BASE(31) | BGCNT_256_COLORS | \
34 BGCNT_CHAR_BASE(3) | BGCNT_PRIORITY(2))
46 u32 *savedInterruptEnable = &ime;
52 u16 *interruptEnable = (
u16 *)0x04000208;
56 *savedInterruptEnable = *interruptEnable;
57 *interruptEnable = (
u32)interruptEnable;
69 u32 saved = *savedInterruptEnable;
90 if (transition->
mode == 0) {
108 }
else if (fade != 0) {
113 for (colorIndex = 0; colorIndex != 128; colorIndex++) {
114 s32 red = source[colorIndex] & 31;
115 s32 green = (source[colorIndex] >> 5) & 31;
116 s32 blue = (source[colorIndex] >> 10) & 31;
133 destination[colorIndex] = (blue << 10) | (green << 5) | red;
244 if (scale >= 0x10000) {
246 panX = 0x6800 + -(
s16)camera->
yaw * 3;
248 if (scanlines ==
NULL)
257 line = scanlines->
lines[scanlines->
page ^ 1];
260 affine = &scanlines->
affine;
267 affine->
x = ((
x + 0x7fff) >> 8) + offsetX + panX;
268 y = ((
y + 0x7fff) >> 8) + offsetY - 0x1000;
279 for (; scanline < 16; scanline++)
282 if (lowerHalfLine > 136)
284 for (; scanline < lowerHalfLine; scanline++)
286 for (; scanline < 136; scanline++)
288 for (; scanline < 160; scanline++)
290 scanlines->
page ^= 1;
303 s32 span = 0x01fe0000;
310 s32 scale = (zoom << 16) / 100;
312 s32 measuredBounds[3];
342 (120 - measuredBounds[1]) << 8, scale);
362 s32 scale = (zoom << 16) / 100;
364 s32 measuredBounds[3];
366 s32 span = 0x01fe0000;
386 renderBounds[2] = span;
395 (120 - measuredBounds[1]) << 8, scale);
410 s32 firstX = firstObject->
x;
411 s32 secondX = secondObject->
x;
412 s32 firstZ = firstObject->
z;
413 s32 secondZ = secondObject->
z;
414 s32 x = (secondX + firstX) / 2;
415 s32 z = (secondZ + firstZ) / 2;
428 for (alphaStep = 1; alphaStep <= 16; alphaStep += 2) {
442 for (step = 1; step <= 16; step += 2) {
469 CAMELOT_ASM(
"the fixed-register identity store of transform.h")
471 entries[0].
sum = previous + entries[0].
value;
506 return selectedValue;
524 object =
slot->object;
529 record =
object->records;
535 records =
object->records;
557 for (unitIndex = 0; unitIndex < unitCount; unitIndex++) {
558 if (unitIds[unitIndex] != selectedUnitId)
570 for (unitIndex = 0; unitIndex < unitCount; unitIndex++)
593 nextIndex = (rampIndex + 1) & 0xf;
622 if (battle != 0 && mode != 0) {
629 for (unitIndex = 0; unitIndex < unitCount; unitIndex++)
632 if (selectedUnits != 0) {
633 u32 unitId = *selectedUnits;
643 unitId = *selectedUnits++;
653#undef BACKGROUND_LEVEL_STEP
654#undef BACKGROUND_PLANE_UPPER
655#undef BACKGROUND_PLANE_LOWER
656#undef BACKGROUND_PLANE_OFF
void BattlePresentation_InitializeWorkAndResetState(void)
Allocates the perspective plane's scanline work (heap slot 10) cleared, and sets the background's mod...
#define DEBUG_SELECT_VALUE
void BattlePres_SetOtherActorRecordModes(s32 selectedUnitId)
Makes every unit's sprites semi-transparent but selectedUnitId's, which are left as they are; nothing...
void Runtime_ReleaseHeapBlock10(void)
Frees the perspective plane's scanline work (heap slot 10); called by Battle_RunEncounter as the batt...
void BattlePres_ClearAllActorRecordModes(void)
Returns every unit's sprites to OBJ mode 0; called by BattlePres_SetActorModes when the highlight sto...
void BattlePres_SetActorRecordMode(s32 actorId, s32 mode)
Sets the OBJ mode (1 semi-transparent, 0 normal) of every sprite of a unit's battle object,...
void Graphics_SetBlendControl(void)
Sets REG_BLDCNT to lighten every layer by REG_BLDY; nothing calls it.
#define BACKGROUND_PLANE_LOWER
The same map, reading the remaining picture tiles from character block 3.
void BattlePresentation_InitializeTransitionEntries(struct BattleTransitionEntry *entries)
Sets entries to the identity transform, then stores the first word's old value plus its new one in th...
s32 BattlePres_DivideBy16(s32 value)
Nothing calls it.
#define BACKGROUND_LEVEL_STEP
BattlePresentation_SetPaletteLevel's and BattleBackground_Load's darkening step: each level takes 109...
void Graphics_FadeAlphaIn(void)
Fades BG2 in over the backdrop in eight frames, its blend weight rising by 2 a frame from 1,...
void Graphics_AdvancePaletteCycle(void)
Lightens the opaque sprites, the highlighted units, by the next step of gBattleFx_HighlightBlendRamp.
void BattlePres_SetupTransitionAtPairMidpoint(s32 firstUnitId, s32 secondUnitId, s32 zoom)
Points the battle camera, through BattlePres_SetupTransitionScene, at the ground between two units' b...
void Graphics_FadeAlphaOut(void)
Fades BG2 out over the backdrop in eight frames, its blend weight falling by 2 a frame from 15,...
void BattleBackground_Load(s32 mode, s32 resourceId, s32 level)
Loads a battle background: its picture into character blocks 2 and 3, its palette into BattleWork....
#define BACKGROUND_PLANE_UPPER
The perspective plane's BG2CNT for the first 256 picture tiles: a 256 by 256 affine map in screen blo...
s32 Runtime_AdjustDebugValueWithButtons(s32 selectedValue)
A debug aid: while Start is held, edits BattleWork.debugValue with the d-pad (1 left and right,...
void BattlePres_SetupTransitionScene(s32 x, s32 depth, s32 y, s32 zoom)
Points the battle camera at (x, depth, y) with a zoom in percent, and lines the perspective plane up ...
#define BACKGROUND_PLANE_OFF
Lines outside the plane read the padded map in screen block 31.
void(*) BitDecoder(const u8 *source, void *destination)
The bit decoder BattleBackground_Load copies to RAM and runs.
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 BattlePres_SetActorModes(u16 *selectedUnits, s32 mode)
Highlights the units in selectedUnits, a list ended by BATTLE_UNIT_LIST_END, or with mode 0 stops the...
void BattleCamera_SetRange(s32 centerX, s32 centerY, s32 offsetX, s32 offsetY, s32 scale)
Builds the perspective plane's next page for a zoom of scale about centerX and centerY (all 16....
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).
UNUSED void BattlePres_SetupTransitionSceneAtDepth(s32 x, s32 depth, s32 y)
Sets the camera's eye at its stored distance without taking a zoom; nothing in the source calls it.
s32 BattleParty_ListActorIds(s32 sideMask, u16 *unitIds)
Lists the units in the battle's unit lists on the sides in sideMask, party first, skipping those remo...
struct BattleObj * BattleObjGet(s32 unitId)
Returns unitId's battle object, through its place, or null for a unit with no place.
void BattlePresentation_BuildTilemap(void *tilemap)
Builds BG1's flat map of the same picture: rows 0 to 3 0xffff, rows 4 and 5 tile 0x3ff,...
void BattlePres_UpdateHBlankScroll(void)
Shows the perspective plane's finished page each frame while the background is in mode 2: its first l...
void Graphics_BuildSequentialTileTable(void *tilemap)
Builds the perspective plane's 32 by 32 affine map: tiles 0 to 255 in its first eight rows,...
void BitDecoder_DecodeImage(void)
struct BattlePresentationTransition * gTransitionWork
s8 gBattleFx_HighlightBlendRamp[]
struct BattleCamera * gCameraWork
What every part of the battle object shares: its includes, in their original order,...
#define RECORDS_KIND_MASK
#define BATTLE_BG_PALETTE
The battle background's colours: BG palettes 6 to 13, filled from BattleWork.palette,...
#define BATTLE_BG1CNT
BG1 during a battle: 256 colours, priority 3, its map in screen block 31.
#define RECORDS_TABLE_SIZE
@ BATTLE_UNIT_LIST_END
ends the list
struct BattleWork * gBattleWork
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...
#define Dma_Fill32(value, destination, size)
Fills size bytes at destination with the word value by DMA3.
s32 GameFlag_TestFar(s32 flag)
#define FLAG_CHOOSING_COMMANDS
set while the commands are chosen
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...
@ HEAP_SLOT_BATTLE_BACKGROUND
#define WORK_SLOT(n)
Reads slots through their own addresses; adjacent slots are reached by offsets.
void IoWriteQueue_Store16(u32 address, u32 value)
Queues a halfword store.
#define BG_SCREEN_BLOCK(n)
#define BLDCNT_EFFECT_LIGHTEN
towards white by REG_BLDY
#define DMA_COPY_HALFWORDS(n)
#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 DMA_COPY_WORDS(n)
#define BG_PLTT_COLOR(palette, color)
#define BGCNT_WRAP
Affine backgrounds only: wrap around instead of showing the backdrop.
#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.
#define Iwram_MulQ16(left, right)
static s32 Iwram_TransformVector(const void *vector, s32 *result)
static s32 Iwram_ClearWords(void *destination, s32 size)
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.
#define SET_VECTOR(v, x, y, z)
Sets the x, y and z of a three-part vector: a position about to be projected, a per-frame step,...
void Runtime_ReleaseHeapBlock(s32 slot)
struct Projection gProjection
#define RamCode_LoadSlot(slot, code, bytes)
Allocates a work-slot copy; release it with Runtime_ReleaseHeapBlock.
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,...
s32 Graphics_ScaleRgb555Clamped(u16 *source, u16 *destination, s32 scale, s32 count)
Copies count colours from source to destination, each channel scaled by scale (16....
An animated sprite: its image and shadow, scale, rotation, size and up to four animation layers.
struct AnimationSpritePart shadow
struct AnimationSpritePart image
u8 slot
VRAM cache entry holding its tiles.
The battle background's scanline work in heap slot 10: two pages of per-line BG2CNT values,...
u32 page
the page of lines shown; the other one is built
struct BattleAffine affine
The battle background's affine parameters and reference point, copied whole to the BG2PA registers.
The battle background's work slot as the background code reads it: its display mode (2 draws it as an...
s32 mode
2 draws the affine plane; 1 sets BG1's scroll too
s32 busy
while set, BattleCamera_SetRange leaves BG1's scroll
s32 secondMode
1 also sets BG1's scroll; one effect sets it
The battle camera: its eye, the focus it turns about, and its pitch, yaw and distance.
s32 distance
eye to focus, 16.16 fixed-point pixels
s32 pos[3]
the focus, 16.16 fixed-point pixels
s32 eye[3]
The eye, 16.16 fixed-point pixels: written each frame distance behind the focus along the turned view...
A unit's place on the battlefield: its sprite object, resources and animations, its anchor spot and s...
struct MotionObject * object
NULL once released.
What BattlePresentation_InitializeTransitionEntries treats as an array of these; Transform_SetIdentit...
u32 sum
set to the first word's old value plus its new one
u32 value
the first word, read before and after the identity is set
The battle's own work: its enemies, units and their objects, the turn's actions, the spoils,...
u16 highlightStep
index into gBattleFx_HighlightBlendRamp
s32 brightness
the backdrop's brightness, 16.16, 0x10000 full
s32 debugValue
A value Runtime_AdjustDebugValueWithButtons edits with the d-pad while Start is held.
u16 palette[128]
the backdrop's colours, before scaling
u16 highlightMode
nonzero while the units are highlighted
An effect object that moves and draws one sprite: its position, scale, velocity and target,...
s32 z
16.16 fixed-point pixels
u8 recordStorageKind
bits: 3..0 RECORDS_NONE, RECORDS_SINGLE or RECORDS_TABLE
s32 x
16.16 fixed-point pixels
void * Resource_GetTableEntry(s32 index)
Returns the ROM address of resource index from the resource directory.
#define CAMELOT_ASM(proof)