Skip to Content
The Alchemy Project

src/battle/battle_background.c

The battle background, its palette and modes, the camera's zoom and the units' highlights. More…

Included by battle.c.

Macros

NameDescription
#defineDEBUG_VALUE_SELECT WHEN(DEBUG_VALUE_EDITOR_NEW_SELECT_PRESET, 399, 480)The value Select picks in the debug value editor.
#defineDEBUG_VALUE_COARSE_STEP 100The debug value editor's step for up and down; left and right step by one.
#defineBACKGROUND_PLANE_SCREEN 7The screen block of the zoomed background's 256 by 256 affine map.
#defineBACKGROUND_PLANE_UPPERThe zoomed background's BG2CNT for the first 256 picture tiles: the affine map, 256 colours, priority 2.
#defineBACKGROUND_PLANE_LOWERThe same map, reading the remaining picture tiles from character block 3.
#defineBACKGROUND_PADDED_SCREEN 31Lines outside the plane read the padded map in this screen block.
#defineBACKGROUND_PLANE_OFF
#defineBACKGROUND_PLANE_LINES 136The screen lines the plane covers, 0 to 135, above the status window.
#defineBACKGROUND_PLANE_HIDDEN_LINES 16The plane's top lines, left off except while commands are chosen.
#defineBACKGROUND_UPPER_HALF_LINES 64The picture's lines that BACKGROUND_PLANE_UPPER reads: its first 256 tiles, 32 to a row.
#defineBACKGROUND_PALETTE_BYTES (BATTLE_BACKGROUND_COLORS * 2)A battle background resource: its BATTLE_BACKGROUND_COLORS colours, then its packed picture.
#defineBACKGROUND_PAN_X Q_8_8(8)The fixed background's sideways pan in 8.8 pixels while the zoom is below 1; from 1 on it moves three 8.8 pixels a step of the camera's yaw, so the picture turns with the camera, and is the same when the camera faces the party's actions (YAW_PARTY_ACTION).
#defineHIGHLIGHT_RAMP_HALF 16The steps of each half of BattleHighlightBlendRamp: the first half plays once, then the second over and over.

Typedefs

NameDescription
typedef const Uint8 *(*BIT_DECODER )(const Uint8 *source, void *destination);The bit decoder btBackgroundLoad copies to RAM and runs.

Functions

NameDescription
voidbtBackgroundSetPaletteLevel (Sint32 unused, Sint32 level)Darkens the background by level, 0 for its own colours.
voidbtBackgroundSetMode (Sint32 mode, Sint32 unusedResource, Sint32 fade)Switches the background's display mode, optionally fades its palette by fade, and rebuilds both its maps.
voidbtBackgroundInit (void)Allocates the zoomed background's scanline state.
voidbtBackgroundFree (void)Frees the zoomed background's scanline state.
voidbtBackgroundLoad (Sint32 mode, Sint32 resourceId, Sint32 level)Loads a battle background, its picture, its palette darkened by level (none when negative) and both its maps.
voidbtCameraSetRange ( FIXED centerX, FIXED centerY, Sint32 offsetX, Sint32 offsetY, FIXED scale)Builds the zoomed background's next page for a zoom of scale about centerX and centerY, shifted by offsetX and offsetY, and shows it: below a zoom of 1 the plane lies flat, from 1 it wraps and turns with the camera.
voidbtCameraSetViewAtDepth (Sint32 x, Sint32 depth, Sint32 y)
voidbtCameraSetView (Sint32 x, Sint32 depth, Sint32 y, Sint32 zoom)Points the battle camera at (x, depth, y) with a zoom in percent, and lines the zoomed background up with it.
voidbtCameraSetViewAtPairMidpoint (Sint32 firstUnitId, Sint32 secondUnitId, Sint32 zoom)Points the battle camera at the ground between two units, with a zoom in percent.
voidbtBackgroundFadeAlphaOut (void)Fades BG2 out over the backdrop in eight ticks.
voidbtBackgroundFadeAlphaIn (void)Fades BG2 in over the backdrop in eight ticks.
voidbtBackgroundSetBlendControl (void)Unused: lightens every layer by REG_BLDY.
voidbtMatrixSetUnit (MATRIX matrix)Unused: sets matrix to the unit matrix, then puts its old first element plus toFIXED(1) in its second, where the unit matrix has 0.
Sint32btBackgroundDivideBy16 (Sint32 value)Unused: returns value divided by 16.
Sint32btAdjustDebugValue (Sint32 selectedValue)Unused debug aid: while Start is held, edits a value with the d-pad until A takes it; with Select held, returns DEBUG_VALUE_SELECT.
voidbtHighlightSetSpriteMode (Sint32 unitId, Sint32 mode)Sets the sprite mode of a unit's picture and its shadow.
voidbtHighlightSetOtherSpriteModes (Sint32 selectedUnitId)Unused: makes every unit's sprites semi-transparent but selectedUnitId's.
voidbtHighlightClearAllSpriteModes (void)Returns every unit's sprites to SPRITE_OPAQUE.
voidbtBackgroundStepHighlightBlend (void)Lightens the highlighted units by the next step of the blend ramp: the first sixteen steps once, then the second sixteen over and over.
voidbtHighlightSetModes (Uint16 *selectedUnits, Sint32 mode)Highlights the units in selectedUnits, the others turning semi-transparent, or with HIGHLIGHT_OFF stops the highlight.

Description

The battle background, its palette and modes, the camera's zoom and the units' highlights. Part of battle.c.

Macros in detail

DEBUG_VALUE_SELECT

#define DEBUG_VALUE_SELECT WHEN(DEBUG_VALUE_EDITOR_NEW_SELECT_PRESET, 399, 480)

The value Select picks in the debug value editor.

Referenced by btAdjustDebugValue().

Definition at line 7 of file battle_background.c.

DEBUG_VALUE_COARSE_STEP

#define DEBUG_VALUE_COARSE_STEP 100

The debug value editor's step for up and down; left and right step by one.

Referenced by btAdjustDebugValue().

Definition at line 9 of file battle_background.c.

BACKGROUND_PLANE_SCREEN

#define BACKGROUND_PLANE_SCREEN 7

The screen block of the zoomed background's 256 by 256 affine map.

Referenced by btBackgroundLoad() and btBackgroundSetMode().

Definition at line 12 of file battle_background.c.

BACKGROUND_PLANE_UPPER

#define BACKGROUND_PLANE_UPPER

The zoomed background's BG2CNT for the first 256 picture tiles: the affine map, 256 colours, priority 2.

Referenced by btCameraSetRange().

Definition at line 15 of file battle_background.c.

BACKGROUND_PLANE_LOWER

#define BACKGROUND_PLANE_LOWER

The same map, reading the remaining picture tiles from character block 3.

Referenced by btCameraSetRange().

Definition at line 19 of file battle_background.c.

BACKGROUND_PADDED_SCREEN

#define BACKGROUND_PADDED_SCREEN 31

Lines outside the plane read the padded map in this screen block.

Referenced by btBackgroundLoad() and btBackgroundSetMode().

Definition at line 23 of file battle_background.c.

BACKGROUND_PLANE_OFF

#define BACKGROUND_PLANE_OFF

Referenced by btCameraSetRange().

Definition at line 24 of file battle_background.c.

BACKGROUND_PLANE_LINES

#define BACKGROUND_PLANE_LINES 136

The screen lines the plane covers, 0 to 135, above the status window.

Referenced by btCameraSetRange().

Definition at line 29 of file battle_background.c.

BACKGROUND_PLANE_HIDDEN_LINES

#define BACKGROUND_PLANE_HIDDEN_LINES 16

The plane's top lines, left off except while commands are chosen.

Referenced by btCameraSetRange().

Definition at line 31 of file battle_background.c.

BACKGROUND_UPPER_HALF_LINES

#define BACKGROUND_UPPER_HALF_LINES 64

The picture's lines that BACKGROUND_PLANE_UPPER reads: its first 256 tiles, 32 to a row.

Referenced by btCameraSetRange().

Definition at line 34 of file battle_background.c.

BACKGROUND_PALETTE_BYTES

#define BACKGROUND_PALETTE_BYTES (BATTLE_BACKGROUND_COLORS * 2)

A battle background resource: its BATTLE_BACKGROUND_COLORS colours, then its packed picture.

Referenced by btBackgroundLoad().

Definition at line 38 of file battle_background.c.

BACKGROUND_PAN_X

#define BACKGROUND_PAN_X Q_8_8(8)

The fixed background's sideways pan in 8.8 pixels while the zoom is below 1; from 1 on it moves three 8.8 pixels a step of the camera's yaw, so the picture turns with the camera, and is the same when the camera faces the party's actions (YAW_PARTY_ACTION).

Referenced by btCameraSetRange().

Definition at line 44 of file battle_background.c.

HIGHLIGHT_RAMP_HALF

#define HIGHLIGHT_RAMP_HALF 16

The steps of each half of BattleHighlightBlendRamp: the first half plays once, then the second over and over.

Referenced by btBackgroundStepHighlightBlend().

Definition at line 48 of file battle_background.c.

Typedefs in detail

BIT_DECODER

typedef const Uint8 *(*BIT_DECODER)(const Uint8 *source, void *destination);

The bit decoder btBackgroundLoad copies to RAM and runs. It returns the source after the last halfword it read.

Referenced by btBackgroundLoad().

Definition at line 52 of file battle_background.c.

Functions in detail

btBackgroundSetPaletteLevel

void btBackgroundSetPaletteLevel(Sint32 unused, Sint32 level)

Darkens the background by level, 0 for its own colours.

References btGraphicsScaleRGB555Clamped(), Sint32, syDMAXCopy(), syIRQLock() and syIRQUnlock().

Referenced by btBackgroundRestorePalette().

Definition at line 55 of file battle_background.c.

btBackgroundSetMode

void btBackgroundSetMode(Sint32 mode, Sint32 unusedResource, Sint32 fade)

Switches the background's display mode, optionally fades its palette by fade, and rebuilds both its maps.

References btBackgroundShowZoomedPage(), btTransitionBuildAffineTilemap(), btTransitionBuildFlatTilemap(), Sint32, syDMAXCopy() and sySetEvent().

Referenced by btElementGlowPlay(), btProcessTurnEnd() and btStagingDispatchAction().

Definition at line 83 of file battle_background.c.

btBackgroundInit

void btBackgroundInit(void)

Allocates the zoomed background's scanline state.

References syHeapSlotAllocateEWRAM().

Referenced by btRun().

Definition at line 161 of file battle_background.c.

btBackgroundFree

void btBackgroundFree(void)

Frees the zoomed background's scanline state.

References syHeapSlotRelease().

Referenced by btRun().

Definition at line 173 of file battle_background.c.

btBackgroundLoad

void btBackgroundLoad(Sint32 mode, Sint32 resourceId, Sint32 level)

Loads a battle background, its picture, its palette darkened by level (none when negative) and both its maps.

References BitDecoderSize, btBackgroundShowZoomedPage(), btBitDecoderDecodeImage(), btGraphicsScaleRGB555Clamped(), btTransitionBuildAffineTilemap(), btTransitionBuildFlatTilemap(), Sint32, syDMAXCopy(), syHeapSlotRelease(), syResourceGetTableEntry(), sySetEvent() and syWordsClear().

Referenced by btRun().

Definition at line 180 of file battle_background.c.

btCameraSetRange

void btCameraSetRange( FIXED centerX, FIXED centerY, Sint32 offsetX, Sint32 offsetY, FIXED scale)

Builds the zoomed background's next page for a zoom of scale about centerX and centerY, shifted by offsetX and offsetY, and shows it: below a zoom of 1 the plane lies flat, from 1 it wraps and turns with the camera.

References BgScrollWork, gmFlagGetStub(), line, Sint32, syDivFX() and syMulFX().

Referenced by btCameraSetCommandView(), btCameraSetView(), btCameraSetViewAtDepth(), btCameraUpdate() and btRun().

Definition at line 226 of file battle_background.c.

btCameraSetViewAtDepth

void btCameraSetViewAtDepth(Sint32 x, Sint32 depth, Sint32 y)

References btCameraSetRange(), ProjectionWork, Sint32, syCalcPoint(), syConvert3Dto2D(), syDivFX(), syInitMatrix(), syLookAtLoad(), syMatrixTranslateVector(), syRotX(), syRotY() and sySetScreenDist().

Definition at line 307 of file battle_background.c.

btCameraSetView

void btCameraSetView(Sint32 x, Sint32 depth, Sint32 y, Sint32 zoom)

Points the battle camera at (x, depth, y) with a zoom in percent, and lines the zoomed background up with it.

References btCameraSetRange(), ProjectionWork, Sint32, syCalcPoint(), syConvert3Dto2D(), syDivFX(), syInitMatrix(), syLookAtLoad(), syMatrixTranslateVector(), syRotX(), syRotY() and sySetScreenDist().

Referenced by btAutoBattleRunPsynergy(), btCameraSetViewAtPairMidpoint(), btRun(), btStagingRunAttack(), btStagingRunFullScreen(), btTransitionAdvanceOpening() and btTransitionRun().

Definition at line 362 of file battle_background.c.

btCameraSetViewAtPairMidpoint

void btCameraSetViewAtPairMidpoint(Sint32 firstUnitId, Sint32 secondUnitId, Sint32 zoom)

Points the battle camera at the ground between two units, with a zoom in percent.

References btCameraSetView(), btObjectGet() and Sint32.

Referenced by btStagingRunAttack().

Definition at line 415 of file battle_background.c.

btBackgroundFadeAlphaOut

void btBackgroundFadeAlphaOut(void)

Fades BG2 out over the backdrop in eight ticks.

References Sint32 and sySynch().

Definition at line 432 of file battle_background.c.

btBackgroundFadeAlphaIn

void btBackgroundFadeAlphaIn(void)

Fades BG2 in over the backdrop in eight ticks.

References Sint32 and sySynch().

Definition at line 446 of file battle_background.c.

btBackgroundSetBlendControl

void btBackgroundSetBlendControl(void)

Unused: lightens every layer by REG_BLDY.

Definition at line 459 of file battle_background.c.

btMatrixSetUnit

void btMatrixSetUnit(MATRIX matrix)

Unused: sets matrix to the unit matrix, then puts its old first element plus toFIXED(1) in its second, where the unit matrix has 0.

References syUnitMatrix().

Definition at line 466 of file battle_background.c.

btBackgroundDivideBy16

Sint32 btBackgroundDivideBy16(Sint32 value)

Unused: returns value divided by 16.

References Sint32.

Definition at line 475 of file battle_background.c.

btAdjustDebugValue

Sint32 btAdjustDebugValue(Sint32 selectedValue)

Unused debug aid: while Start is held, edits a value with the d-pad until A takes it; with Select held, returns DEBUG_VALUE_SELECT.

References PerData, PerPush, PerRepeat, Sint32 and sySynch().

Definition at line 482 of file battle_background.c.

btHighlightSetSpriteMode

void btHighlightSetSpriteMode(Sint32 unitId, Sint32 mode)

Sets the sprite mode of a unit's picture and its shadow.

References btObjectGet() and Sint32.

Referenced by btAutoBattleRunPsynergy(), btHighlightClearAllSpriteModes(), btHighlightSetModes(), btHighlightSetOtherSpriteModes(), btStagingRunFullScreen() and btTransitionRun().

Definition at line 515 of file battle_background.c.

btHighlightSetOtherSpriteModes

void btHighlightSetOtherSpriteModes(Sint32 selectedUnitId)

Unused: makes every unit's sprites semi-transparent but selectedUnitId's.

References btHighlightSetSpriteMode(), btUnitListIds() and Sint32.

Definition at line 555 of file battle_background.c.

btHighlightClearAllSpriteModes

void btHighlightClearAllSpriteModes(void)

Returns every unit's sprites to SPRITE_OPAQUE.

References btHighlightSetSpriteMode(), btUnitListIds() and Sint32.

Referenced by btHighlightSetModes().

Definition at line 570 of file battle_background.c.

btBackgroundStepHighlightBlend

void btBackgroundStepHighlightBlend(void)

Lightens the highlighted units by the next step of the blend ramp: the first sixteen steps once, then the second sixteen over and over.

References BattleHighlightBlendRamp and Sint32.

Referenced by btHighlightSetModes().

Definition at line 582 of file battle_background.c.

btHighlightSetModes

void btHighlightSetModes(Uint16 *selectedUnits, Sint32 mode)

Highlights the units in selectedUnits, the others turning semi-transparent, or with HIGHLIGHT_OFF stops the highlight.

References btBackgroundStepHighlightBlend(), btHighlightClearAllSpriteModes(), btHighlightSetSpriteMode(), btUnitListIds(), Sint32, syCloseEvent(), syIOWriteQueueStore16(), sySetEvent() and sySynch().

Referenced by btActionRunBuild(), btStagingDispatchAction(), btStagingRunAttack(), btStagingRunFlee(), btStagingRunFullScreen(), btStagingRunItem(), btStagingRunMessages(), btStagingRunPlainAttack() and btStagingRunPsynergyCast().

Definition at line 607 of file battle_background.c.