Skip to Content
The Alchemy Project

src/battle/battle_transition.c

How the screen goes into a battle: the mosaic fade to black, then the curtain that opens from the middle of the screen as the camera swings round to the party, or the Doom Dragon's shattering opening; and the zoomed background's maps and HBlank scroll they show. More…

Included by battle.c.

Macros

NameDescription
#defineTRANSITION_CURTAIN_FIRST_TILE 128The curtain's first tile in BG character block 1.
#defineTRANSITION_CURTAIN_ENTRY (n)The curtain's map entries: its tile n, WINDOW_PALETTE.
#defineTRANSITION_CURTAIN_SCREEN 12The screen block of the curtain's map, and its middle row, from which it opens a row up and a row down every eight ticks for TRANSITION_OPEN_TICKS.
#defineTRANSITION_CURTAIN_MIDDLE_ROW 13
#defineTRANSITION_CURTAIN_LAST_ROW 20
#defineTRANSITION_OPEN_TICKS 80
#defineCURTAIN_TILE (n)The curtain's tile n in BG character block 1.
#defineTRANSITION_CURTAIN_COLOR 3The closed curtain's colour, which fills its first tile.
#defineTRANSITION_CURTAIN_VARIANTS 8Eight variants of the curtain's first tile, a new one every four ticks (btTransitionUploadTileVariant).
#defineTRANSITION_VARIANT_TICKS 4
#defineTRANSITION_BG0_BAND 32BG0's top 32 lines, which roll down into place as the curtain opens: BG0 starts scrolled up by as many, and the VCount interrupt at the band's bottom clears the scroll for the lines below.
#defineTRANSITION_TURN_SPEED 360The camera turns 360 of TRIG_TURN's 65,536 a tick (about 2 degrees) as the curtain opens, ending at DEGtoANG(45) as the zoom ends.
#defineTRANSITION_START_YAW
#defineCOPY_CURTAIN_TILE (n)Copies BattleTransitionCurtainTiles' tile n - 1, by DMA, into the curtain's tile n.
#defineMOSAIC_SIZE_MAX 15REG_MOSAIC's largest block size, 16 pixels: each of its sizes is a four-bit field holding the size less one.
#defineAFFINE_MAP_ENTRIES (first, second, third, fourth)Four affine map entries side by side, a byte each, written a word at a time.
#defineBACKGROUND_TILE_ROWS 15The battle background's image: 32 by 15 tiles of 256 colours, 256 by 120 pixels.
#defineBACKGROUND_TILES (BG_SCREEN_WIDTH * BACKGROUND_TILE_ROWS)
#defineBACKGROUND_UPPER_TILES (BG_CHAR_SIZE / TILE_SIZE_8BPP)
#defineBACKGROUND_LOWER_TILES (BACKGROUND_TILES - BACKGROUND_UPPER_TILES)
#defineBACKGROUND_AFFINE_MAP_BYTES (32 * 32)The zoomed background's affine map: 32 by 32 tiles, a byte each.
#defineBACKGROUND_BG1_FIRST_TILE (2 * BG_CHAR_SIZE / TILE_SIZE_8BPP)The picture's first tile on BG1 (BATTLE_BG1CNT), numbered from BG1's character base 0: character block 2.
#defineBG1_EDGE_TILE TILE_NUMBER_MASKThe last tile, which BG1's flat map shows in the rows around the picture: it lies in the last row of the map's own screen block, which btBackgroundLoad leaves clear.

Functions

NameDescription
Sint32btTransitionRunMosaicFadeOut (void)Fades the screen to black over sixteen ticks as every background's mosaic grows, then shows no layer.
voidbtTransitionBuildAffineTilemap (void *tilemap)Builds the zoomed background's 32 by 32 affine map, in which the background picture's two halves come from character blocks 2 and 3: the upper half's tiles numbered from 0, the lower half's from 0 again, then tile 255 for the rest.
voidbtTransitionBuildFlatTilemap (Sint32 *dest)Builds BG1's flat map of the same picture, in screen block 31: four rows of blank entries, two of BG1_EDGE_TILE, the picture's tiles in order on rows 6 to 20, then BG1_EDGE_TILE down to the last row, which btBackgroundLoad clears.
voidbtBackgroundShowZoomedPage (void)Copies this tick's BG2CNT word and starts the HBlank DMA of the BG2 lines and the affine block, while the battle background is zoomed.
voidbtTransitionUploadTileVariant (void)Unused: steps the curtain's solid tile through its variants (BattleTransitionCurtainVariants) while the transition timer runs from 1.
voidbtTransitionAdvanceOpening (void)Advances the curtain opening by a tick: BG0 slides into place as the camera turns round to the party and zooms out.
voidbtTransitionDrawRows (void)Draws the curtain opening from the middle of the screen, one row up and one down every eight ticks.
voidbtTransitionResetBg0Scroll (void)Clears BG0's scroll from the line the VCount interrupt fires on.
voidbtTransitionRun (Sint32 enemyCount, Sint32 formationId)Opens the battle against formation formationId with enemyCount enemies: the curtain opening, then the enemies announced (Karst and Agatio's battles wait a second instead); for the Doom Dragon's the shattering opening over the Serpent's stars.

Description

How the screen goes into a battle: the mosaic fade to black, then the curtain that opens from the middle of the screen as the camera swings round to the party, or the Doom Dragon's shattering opening; and the zoomed background's maps and HBlank scroll they show. Part of battle.c.

Macros in detail

TRANSITION_CURTAIN_FIRST_TILE

#define TRANSITION_CURTAIN_FIRST_TILE 128

The curtain's first tile in BG character block 1.

Definition at line 7 of file battle_transition.c.

TRANSITION_CURTAIN_ENTRY

#define TRANSITION_CURTAIN_ENTRY(n)

The curtain's map entries: its tile n, WINDOW_PALETTE.

Referenced by btTransitionDrawRows() and btTransitionRun().

Definition at line 9 of file battle_transition.c.

TRANSITION_CURTAIN_SCREEN

#define TRANSITION_CURTAIN_SCREEN 12

The screen block of the curtain's map, and its middle row, from which it opens a row up and a row down every eight ticks for TRANSITION_OPEN_TICKS.

Referenced by btTransitionDrawRows() and btTransitionRun().

Definition at line 13 of file battle_transition.c.

TRANSITION_CURTAIN_MIDDLE_ROW

#define TRANSITION_CURTAIN_MIDDLE_ROW 13

Referenced by btTransitionDrawRows().

Definition at line 14 of file battle_transition.c.

TRANSITION_CURTAIN_LAST_ROW

#define TRANSITION_CURTAIN_LAST_ROW 20

Referenced by btTransitionDrawRows() and btTransitionRun().

Definition at line 15 of file battle_transition.c.

TRANSITION_OPEN_TICKS

#define TRANSITION_OPEN_TICKS 80

Referenced by btTransitionAdvanceOpening(), btTransitionDrawRows() and btTransitionRun().

Definition at line 16 of file battle_transition.c.

CURTAIN_TILE

#define CURTAIN_TILE(n)

The curtain's tile n in BG character block 1.

Referenced by btTransitionRun() and btTransitionUploadTileVariant().

Definition at line 18 of file battle_transition.c.

TRANSITION_CURTAIN_COLOR

#define TRANSITION_CURTAIN_COLOR 3

The closed curtain's colour, which fills its first tile.

Referenced by btTransitionRun().

Definition at line 21 of file battle_transition.c.

TRANSITION_CURTAIN_VARIANTS

#define TRANSITION_CURTAIN_VARIANTS 8

Eight variants of the curtain's first tile, a new one every four ticks (btTransitionUploadTileVariant).

Referenced by btTransitionUploadTileVariant().

Definition at line 24 of file battle_transition.c.

TRANSITION_VARIANT_TICKS

#define TRANSITION_VARIANT_TICKS 4

Referenced by btTransitionUploadTileVariant().

Definition at line 25 of file battle_transition.c.

TRANSITION_BG0_BAND

#define TRANSITION_BG0_BAND 32

BG0's top 32 lines, which roll down into place as the curtain opens: BG0 starts scrolled up by as many, and the VCount interrupt at the band's bottom clears the scroll for the lines below.

Referenced by btTransitionAdvanceOpening() and btTransitionRun().

Definition at line 29 of file battle_transition.c.

TRANSITION_TURN_SPEED

#define TRANSITION_TURN_SPEED 360

The camera turns 360 of TRIG_TURN's 65,536 a tick (about 2 degrees) as the curtain opens, ending at DEGtoANG(45) as the zoom ends.

Referenced by btTransitionAdvanceOpening().

Definition at line 32 of file battle_transition.c.

TRANSITION_START_YAW

#define TRANSITION_START_YAW

Referenced by btTransitionAdvanceOpening().

Definition at line 33 of file battle_transition.c.

COPY_CURTAIN_TILE

#define COPY_CURTAIN_TILE(n)

Copies BattleTransitionCurtainTiles' tile n - 1, by DMA, into the curtain's tile n.

Referenced by btTransitionRun().

Definition at line 38 of file battle_transition.c.

MOSAIC_SIZE_MAX

#define MOSAIC_SIZE_MAX 15

REG_MOSAIC's largest block size, 16 pixels: each of its sizes is a four-bit field holding the size less one.

Referenced by btTransitionRunMosaicFadeOut().

Definition at line 46 of file battle_transition.c.

AFFINE_MAP_ENTRIES

#define AFFINE_MAP_ENTRIES(first, second, third, fourth)

Four affine map entries side by side, a byte each, written a word at a time.

Referenced by btTransitionBuildAffineTilemap().

Definition at line 49 of file battle_transition.c.

BACKGROUND_TILE_ROWS

#define BACKGROUND_TILE_ROWS 15

The battle background's image: 32 by 15 tiles of 256 colours, 256 by 120 pixels. The first 256 tiles fill character block 2 and the rest block 3.

Referenced by btTransitionBuildFlatTilemap().

Definition at line 53 of file battle_transition.c.

BACKGROUND_TILES

#define BACKGROUND_TILES (BG_SCREEN_WIDTH * BACKGROUND_TILE_ROWS)

Referenced by btTransitionBuildAffineTilemap().

Definition at line 54 of file battle_transition.c.

BACKGROUND_UPPER_TILES

#define BACKGROUND_UPPER_TILES (BG_CHAR_SIZE / TILE_SIZE_8BPP)

Referenced by btTransitionBuildAffineTilemap().

Definition at line 55 of file battle_transition.c.

BACKGROUND_LOWER_TILES

#define BACKGROUND_LOWER_TILES (BACKGROUND_TILES - BACKGROUND_UPPER_TILES)

Referenced by btTransitionBuildAffineTilemap().

Definition at line 56 of file battle_transition.c.

BACKGROUND_AFFINE_MAP_BYTES

#define BACKGROUND_AFFINE_MAP_BYTES (32 * 32)

The zoomed background's affine map: 32 by 32 tiles, a byte each.

Referenced by btTransitionBuildAffineTilemap().

Definition at line 58 of file battle_transition.c.

BACKGROUND_BG1_FIRST_TILE

#define BACKGROUND_BG1_FIRST_TILE (2 * BG_CHAR_SIZE / TILE_SIZE_8BPP)

The picture's first tile on BG1 (BATTLE_BG1CNT), numbered from BG1's character base 0: character block 2.

Referenced by btTransitionBuildFlatTilemap().

Definition at line 61 of file battle_transition.c.

BG1_EDGE_TILE

#define BG1_EDGE_TILE TILE_NUMBER_MASK

The last tile, which BG1's flat map shows in the rows around the picture: it lies in the last row of the map's own screen block, which btBackgroundLoad leaves clear.

Referenced by btTransitionBuildFlatTilemap().

Definition at line 65 of file battle_transition.c.

Functions in detail

btTransitionRunMosaicFadeOut

Sint32 btTransitionRunMosaicFadeOut(void)

Fades the screen to black over sixteen ticks as every background's mosaic grows, then shows no layer. Sets REG_BLDCNT to darken the backgrounds, leaves REG_MOSAIC at its largest and REG_DISPCNT in mode 1 with every layer off; the four BGxCNT are put back as they were. It draws four random numbers a tick, which only advances the random number generator. Returns 0.

References Sint32, syRandom(), syScreenFadeToBlack() and sySynch().

Definition at line 72 of file battle_transition.c.

btTransitionBuildAffineTilemap

void btTransitionBuildAffineTilemap(void *tilemap)

Builds the zoomed background's 32 by 32 affine map, in which the background picture's two halves come from character blocks 2 and 3: the upper half's tiles numbered from 0, the lower half's from 0 again, then tile 255 for the rest.

References syWordsFill().

Referenced by btBackgroundLoad() and btBackgroundSetMode().

Definition at line 120 of file battle_transition.c.

btTransitionBuildFlatTilemap

void btTransitionBuildFlatTilemap(Sint32 *dest)

Builds BG1's flat map of the same picture, in screen block 31: four rows of blank entries, two of BG1_EDGE_TILE, the picture's tiles in order on rows 6 to 20, then BG1_EDGE_TILE down to the last row, which btBackgroundLoad clears.

References Sint32 and syWordsFill().

Referenced by btBackgroundLoad() and btBackgroundSetMode().

Definition at line 145 of file battle_transition.c.

btBackgroundShowZoomedPage

void btBackgroundShowZoomedPage(void)

Copies this tick's BG2CNT word and starts the HBlank DMA of the BG2 lines and the affine block, while the battle background is zoomed.

References syDMAXCopy().

Referenced by btBackgroundLoad() and btBackgroundSetMode().

Definition at line 167 of file battle_transition.c.

btTransitionUploadTileVariant

void btTransitionUploadTileVariant(void)

Unused: steps the curtain's solid tile through its variants (BattleTransitionCurtainVariants) while the transition timer runs from 1.

References BattleTransitionCurtainVariants, Sint32 and syDMAXCopy().

Definition at line 188 of file battle_transition.c.

btTransitionAdvanceOpening

void btTransitionAdvanceOpening(void)

Advances the curtain opening by a tick: BG0 slides into place as the camera turns round to the party and zooms out.

References BgScrollWork, btCameraSetView() and Sint32.

Referenced by btTransitionRun().

Definition at line 202 of file battle_transition.c.

btTransitionDrawRows

void btTransitionDrawRows(void)

Draws the curtain opening from the middle of the screen, one row up and one down every eight ticks.

References Sint32.

Referenced by btTransitionRun().

Definition at line 234 of file battle_transition.c.

btTransitionResetBg0Scroll

void btTransitionResetBg0Scroll(void)

Clears BG0's scroll from the line the VCount interrupt fires on.

Referenced by btTransitionRun().

Definition at line 266 of file battle_transition.c.

btTransitionRun

void btTransitionRun(Sint32 enemyCount, Sint32 formationId)

Opens the battle against formation formationId with enemyCount enemies: the curtain opening, then the enemies announced (Karst and Agatio's battles wait a second instead); for the Doom Dragon's the shattering opening over the Serpent's stars.

References BgScrollWork, btActorSpawnObjectsForList(), btCameraSetView(), btEffectRunShatteringOpeningStub(), btHighlightSetSpriteMode(), btIntroAnnounceEncounter(), btObjectGet(), btPartyPrepareMembers(), btPartyPrepareReserveOwners(), btTransitionAdvanceOpening(), btTransitionDrawRows(), btTransitionResetBg0Scroll(), btUnitListIds(), gmUnitGet(), mnPartyStatusCreateWindowStub(), Sint32, syCloseEvent(), syHeapSlotAllocate(), syHeapSlotRelease(), syIntFunction(), syIOWriteQueueClearBits16(), syIOWriteQueueSetBits16(), syIOWriteQueueStore16(), sySetEvent() and sySynch().

Referenced by btRun().

Definition at line 275 of file battle_transition.c.