Skip to Content
The Alchemy Project

src/field/field_engine_screen_transition.c

How a scene fades in and out: from or to black or the backdrop colour, through windows that open or close over the screen line by line, from or to the centre line, or by a dissolve, which no scene uses. More…

Included by field_engine.c.

Macros

NameDescription
#defineTRANSITION_NOISE_EDGE_MAX 255The widest a line's window reaches from the left edge in WINDOW_TRANSITION_NOISE: WIN0H's right edge is a byte.
#defineTRANSITION_ELLIPSE_RISE 16How far above its point on the field an ellipse about the leader or WINDOW_TRANSITION_RIPPLE's point centres, in pixels, and how far WINDOW_TRANSITION_LEADER_LOW's does.
#defineTRANSITION_LOW_ELLIPSE_RISE 8
#defineTRANSITION_RADIUS_STEP 5The pixels the circle's and the ellipses' radius grows a step of the value.
#defineTRANSITION_EDGE_OFFSETS 32ScreenTransitionEdgeOffsets' entries, the ripple's period in lines.
#defineCENTER_LINE_HIDDEN_FIRST 200Where the centre-line transition puts its two lines once they meet: below the screen, so no switch happens.
#defineCENTER_LINE_HIDDEN_SECOND 250
#defineDISSOLVE_COVER_COLOR 15The colour the dissolve covers the screen in, the window palette's last.
#defineCLAMP_EDGES_TO_SCREEN (left, right)Keeps a line's window edges on the screen, 0 to DISPLAY_WIDTH.

Enumerations

NameDescription
enumSCREEN_TRANSITION_IRQ_PHASE { DISPLAY_TRANSITION_IRQ_WAIT_SCREEN, DISPLAY_TRANSITION_IRQ_W … }Where the centre-line transition's HBlank interrupt is in the tick.

Functions

NameDescription
voidfdScreenTransitionStartWindowHBlankDMA (void)Each VBlank, before drawing: turns windows 0 and 1 on, writes the first four values of the shown page into WININ, WINOUT, WIN0H and WIN1H, and has DMA 0 copy the rest into WIN0H and WIN1H one word each HBlank, so that every line of the screen gets its own window edges.
voidfdScreenTransitionUpdateScanlineTable (void)Each tick of a window transition: advances its value toward its end (and at the end turns the windows off, or moves to the next mode), then builds the next page of window edges, WININ and WINOUT first and then a (left << 8 | right) pair for each of the 160 lines.
voidfdScreenTransitionStartHeldWindow (Sint32 mode)Starts window transition mode at value 0, with no duration: the caller moves it.
voidfdScreenTransitionSuspendCallbacks (void)Unused: suspends the window transition's two events.
SCREEN_TRANSITION_STATE *fdScreenTransitionAllocateAndClearState (void)Allocates the screen transition state (HEAP_SLOT_SCREEN_TRANSITION) and clears it.
voidfdScreenTransitionStart (Sint32 mode, Sint32 ticks)Fades the screen in over ticks ticks. mode is a SCENE_TRANSITION: its high byte an SCREEN_TRANSITION_STYLE (from black, from the backdrop colour, a window transition whose low byte is an WINDOW_TRANSITION_MODE, a dissolve, or opening from the centre line, which a non-zero low byte makes flicker).
voidfdScreenTransitionFinish (Sint32 mode, Sint32 ticks)Fades the screen out over ticks ticks, as fdScreenTransitionStart fades it in.
voidfdScreenTransitionHideBackgrounds (Sint32 clearBg3, Sint32 clearBg2, Sint32 clearBg1)Clears the map's display-control bits for backgrounds 3, 2 and 1 (DISPCNT_BG3_ON, DISPCNT_BG2_ON and DISPCNT_BG1_ON) for each argument that is set.
voidfdScreenTransitionUpdate (void)Each tick of the centre-line transition: moves the value toward its end and sets the two lines where the screen switches between shown and blank.
voidfdScreenTransitionUpdateFromCenter (void)As fdScreenTransitionUpdate, but the lines flicker every other tick.
voidfdScreenTransitionUpdateScanline (void)The HBlank interrupt of the centre-line transition: switches the display to DISPCNT_MODE_2 (nothing shown) at the first line and back to DISPCNT_MODE_0 at the second.
voidfdScreenTransitionUpdateDissolve (void)Unused, as no scene dissolves.
voidfdScreenTransitionFillTilemapAndColorTile (Sint32 color)Unused, as the dissolve is: fills background screen block 4 with tile 0 in WINDOW_PALETTE and, unless color is -1, makes tile 0 solid color.
voidfdScreenTransitionStartDissolveHeld (Sint32 mode)Unused: nothing calls it, by name or through its stub.

Description

How a scene fades in and out: from or to black or the backdrop colour, through windows that open or close over the screen line by line, from or to the centre line, or by a dissolve, which no scene uses. Part of field_engine.c.

Macros in detail

TRANSITION_NOISE_EDGE_MAX

#define TRANSITION_NOISE_EDGE_MAX 255

The widest a line's window reaches from the left edge in WINDOW_TRANSITION_NOISE: WIN0H's right edge is a byte.

Referenced by fdScreenTransitionUpdateScanlineTable().

Definition at line 10 of file field_engine_screen_transition.c.

TRANSITION_ELLIPSE_RISE

#define TRANSITION_ELLIPSE_RISE 16

How far above its point on the field an ellipse about the leader or WINDOW_TRANSITION_RIPPLE's point centres, in pixels, and how far WINDOW_TRANSITION_LEADER_LOW's does.

Referenced by fdScreenTransitionUpdateScanlineTable().

Definition at line 14 of file field_engine_screen_transition.c.

TRANSITION_LOW_ELLIPSE_RISE

#define TRANSITION_LOW_ELLIPSE_RISE 8

Referenced by fdScreenTransitionUpdateScanlineTable().

Definition at line 15 of file field_engine_screen_transition.c.

TRANSITION_RADIUS_STEP

#define TRANSITION_RADIUS_STEP 5

The pixels the circle's and the ellipses' radius grows a step of the value.

Referenced by fdScreenTransitionUpdateScanlineTable().

Definition at line 17 of file field_engine_screen_transition.c.

TRANSITION_EDGE_OFFSETS

#define TRANSITION_EDGE_OFFSETS 32

ScreenTransitionEdgeOffsets' entries, the ripple's period in lines.

Referenced by fdScreenTransitionUpdateScanlineTable().

Definition at line 19 of file field_engine_screen_transition.c.

CENTER_LINE_HIDDEN_FIRST

#define CENTER_LINE_HIDDEN_FIRST 200

Where the centre-line transition puts its two lines once they meet: below the screen, so no switch happens.

Referenced by fdScreenTransitionUpdate() and fdScreenTransitionUpdateFromCenter().

Definition at line 22 of file field_engine_screen_transition.c.

CENTER_LINE_HIDDEN_SECOND

#define CENTER_LINE_HIDDEN_SECOND 250

Referenced by fdScreenTransitionUpdate() and fdScreenTransitionUpdateFromCenter().

Definition at line 23 of file field_engine_screen_transition.c.

DISSOLVE_COVER_COLOR

#define DISSOLVE_COVER_COLOR 15

The colour the dissolve covers the screen in, the window palette's last.

Referenced by fdScreenTransitionStart() and fdScreenTransitionUpdateDissolve().

Definition at line 25 of file field_engine_screen_transition.c.

CLAMP_EDGES_TO_SCREEN

#define CLAMP_EDGES_TO_SCREEN(left, right)

Keeps a line's window edges on the screen, 0 to DISPLAY_WIDTH.

Referenced by fdScreenTransitionUpdateScanlineTable().

Definition at line 27 of file field_engine_screen_transition.c.

Enumerations in detail

SCREEN_TRANSITION_IRQ_PHASE

enum SCREEN_TRANSITION_IRQ_PHASE

Where the centre-line transition's HBlank interrupt is in the tick.

EnumeratorValueDescription
DISPLAY_TRANSITION_IRQ_WAIT_SCREEN0waits for a line on screen
DISPLAY_TRANSITION_IRQ_WAIT_EITHER1Waits for whichever edge line comes first
DISPLAY_TRANSITION_IRQ_WAIT_SECOND2The first line has passed: waits for the second
DISPLAY_TRANSITION_IRQ_WAIT_FIRST3The second line has passed: waits
DISPLAY_TRANSITION_IRQ_DONE9for the first

Definition at line 887 of file field_engine_screen_transition.c.

Functions in detail

fdScreenTransitionStartWindowHBlankDMA

void fdScreenTransitionStartWindowHBlankDMA(void)

Each VBlank, before drawing: turns windows 0 and 1 on, writes the first four values of the shown page into WININ, WINOUT, WIN0H and WIN1H, and has DMA 0 copy the rest into WIN0H and WIN1H one word each HBlank, so that every line of the screen gets its own window edges.

References state and syDMAXCopy().

Referenced by fdScreenTransitionFinish(), fdScreenTransitionStart(), fdScreenTransitionStartHeldWindow(), fdScreenTransitionSuspendCallbacks() and fdScreenTransitionUpdateScanlineTable().

Definition at line 51 of file field_engine_screen_transition.c.

fdScreenTransitionUpdateScanlineTable

void fdScreenTransitionUpdateScanlineTable(void)

Each tick of a window transition: advances its value toward its end (and at the end turns the windows off, or moves to the next mode), then builds the next page of window edges, WININ and WINOUT first and then a (left << 8 | right) pair for each of the 160 lines.

References fdActorLookup(), fdMapGridScrollStateView(), fdScreenTransitionStartWindowHBlankDMA(), MainRoutineStateWork, memcpy(), mnScanlineWindowFillSpansStub(), ScreenTransitionBarWidths, ScreenTransitionEdgeOffsets, ScreenTransitionShapes, Sint32, state, syCloseEvent(), syIntegerDivide(), syRandom(), sySquartIWRAM() and TickCount.

Referenced by fdScreenTransitionFinish(), fdScreenTransitionStart(), fdScreenTransitionStartHeldWindow() and fdScreenTransitionSuspendCallbacks().

Definition at line 79 of file field_engine_screen_transition.c.

fdScreenTransitionStartHeldWindow

void fdScreenTransitionStartHeldWindow(Sint32 mode)

Starts window transition mode at value 0, with no duration: the caller moves it.

References fdScreenTransitionStartWindowHBlankDMA(), fdScreenTransitionUpdateScanlineTable(), Sint32, state, syHeapSlotAllocateEWRAM() and sySetEvent().

Referenced by fdPsynergyReveal(), scAltmillerCaveInitDarkness(), scBabiPalaceWakeAfterFinals(), scInit() and scTretTreeBranchRevealFades().

Definition at line 549 of file field_engine_screen_transition.c.

fdScreenTransitionSuspendCallbacks

void fdScreenTransitionSuspendCallbacks(void)

Unused: suspends the window transition's two events. Nothing calls it, by name, stub call entry or table.

References fdScreenTransitionStartWindowHBlankDMA(), fdScreenTransitionUpdateScanlineTable() and sySuspendEvent().

Definition at line 565 of file field_engine_screen_transition.c.

fdScreenTransitionAllocateAndClearState

SCREEN_TRANSITION_STATE *fdScreenTransitionAllocateAndClearState(void)

Allocates the screen transition state (HEAP_SLOT_SCREEN_TRANSITION) and clears it.

References state and syHeapSlotAllocateEWRAM().

Referenced by fdScreenTransitionFinish() and fdScreenTransitionStart().

Definition at line 573 of file field_engine_screen_transition.c.

fdScreenTransitionStart

void fdScreenTransitionStart(Sint32 mode, Sint32 ticks)

Fades the screen in over ticks ticks. mode is a SCENE_TRANSITION: its high byte an SCREEN_TRANSITION_STYLE (from black, from the backdrop colour, a window transition whose low byte is an WINDOW_TRANSITION_MODE, a dissolve, or opening from the centre line, which a non-zero low byte makes flicker).

References fdPaletteFadeSetBackdrop(), fdPaletteFadeSetSource(), fdPaletteFadeStartInterpolation(), fdScreenTransitionAllocateAndClearState(), fdScreenTransitionFillTilemapAndColorTile(), fdScreenTransitionStartWindowHBlankDMA(), fdScreenTransitionUpdate(), fdScreenTransitionUpdateDissolve(), fdScreenTransitionUpdateFromCenter(), fdScreenTransitionUpdateScanline(), fdScreenTransitionUpdateScanlineTable(), Sint32, state, syIntFunction(), syScreenFadeFromBlack(), syScreenFadeToBlack(), sySetEvent() and sySynch().

Referenced by fdEngineRun() and fdScriptStartScreenTransition().

Definition at line 587 of file field_engine_screen_transition.c.

fdScreenTransitionFinish

void fdScreenTransitionFinish(Sint32 mode, Sint32 ticks)

Fades the screen out over ticks ticks, as fdScreenTransitionStart fades it in.

References fdPaletteFadeSetTarget(), fdPaletteFadeStartInterpolation(), fdScreenTransitionAllocateAndClearState(), fdScreenTransitionFillTilemapAndColorTile(), fdScreenTransitionStartWindowHBlankDMA(), fdScreenTransitionUpdate(), fdScreenTransitionUpdateDissolve(), fdScreenTransitionUpdateFromCenter(), fdScreenTransitionUpdateScanline(), fdScreenTransitionUpdateScanlineTable(), Sint32, state, syIntFunction(), syScreenFadeFromBlack(), syScreenFadeToBlack(), sySetEvent() and sySynch().

Referenced by fdEngineRun(), fdScriptFinishScreenTransition() and fdStartEncounterTransition().

Definition at line 692 of file field_engine_screen_transition.c.

fdScreenTransitionHideBackgrounds

void fdScreenTransitionHideBackgrounds(Sint32 clearBg3, Sint32 clearBg2, Sint32 clearBg1)

Clears the map's display-control bits for backgrounds 3, 2 and 1 (DISPCNT_BG3_ON, DISPCNT_BG2_ON and DISPCNT_BG1_ON) for each argument that is set.

References Sint32 and state.

Definition at line 773 of file field_engine_screen_transition.c.

fdScreenTransitionUpdate

void fdScreenTransitionUpdate(void)

Each tick of the centre-line transition: moves the value toward its end and sets the two lines where the screen switches between shown and blank.

References Sint32, state, syCloseEvent(), syIntegerDivide() and syIntFunction().

Referenced by fdScreenTransitionFinish() and fdScreenTransitionStart().

Definition at line 799 of file field_engine_screen_transition.c.

fdScreenTransitionUpdateFromCenter

void fdScreenTransitionUpdateFromCenter(void)

As fdScreenTransitionUpdate, but the lines flicker every other tick.

References Sint32, state, syCloseEvent(), syIntegerDivide(), syIntFunction() and TickCount.

Referenced by fdScreenTransitionFinish() and fdScreenTransitionStart().

Definition at line 841 of file field_engine_screen_transition.c.

fdScreenTransitionUpdateScanline

void fdScreenTransitionUpdateScanline(void)

The HBlank interrupt of the centre-line transition: switches the display to DISPCNT_MODE_2 (nothing shown) at the first line and back to DISPCNT_MODE_0 at the second.

References state.

Referenced by fdScreenTransitionFinish() and fdScreenTransitionStart().

Definition at line 902 of file field_engine_screen_transition.c.

fdScreenTransitionUpdateDissolve

void fdScreenTransitionUpdateDissolve(void)

Unused, as no scene dissolves. Each tick of the dissolve: moves the value toward its end and sets two more of the solid tile's 64 pixels, in the order of ScreenTransitionDitherTable: to colour 0 while the screen opens (values up to TRANSITION_OPEN clear the cover fdScreenTransitionStart filled with DISSOLVE_COVER_COLOR), and to DISSOLVE_COVER_COLOR while it closes (values after it fill the clear tile fdScreenTransitionFinish starts from).

References ScreenTransitionDitherTable, Sint32, state, syCloseEvent() and syIntegerDivide().

Referenced by fdScreenTransitionFinish(), fdScreenTransitionStart() and fdScreenTransitionStartDissolveHeld().

Definition at line 958 of file field_engine_screen_transition.c.

fdScreenTransitionFillTilemapAndColorTile

void fdScreenTransitionFillTilemapAndColorTile(Sint32 color)

Unused, as the dissolve is: fills background screen block 4 with tile 0 in WINDOW_PALETTE and, unless color is -1, makes tile 0 solid color.

References Sint32, state and syDMAXCopy().

Referenced by fdScreenTransitionFinish(), fdScreenTransitionStart() and fdScreenTransitionStartDissolveHeld().

Definition at line 1013 of file field_engine_screen_transition.c.

fdScreenTransitionStartDissolveHeld

void fdScreenTransitionStartDissolveHeld(Sint32 mode)

Unused: nothing calls it, by name or through its stub. Starts a dissolve of the given mode, its value held at 0, and waits two seconds.

References fdScreenTransitionFillTilemapAndColorTile(), fdScreenTransitionUpdateDissolve(), Sint32, state, syHeapSlotAllocateEWRAM(), sySetEvent() and sySynch().

Definition at line 1038 of file field_engine_screen_transition.c.