Skip to Content
The Alchemy Project

src/field/script_commands_line_scroll.c

The line scroll: per-line scroll offsets fed by HBlank DMA. More…

Included by script_commands.c.

Macros

NameDescription
#defineLINE_SCROLL_ALL_LAYERS 0LINE_SCROLL_STATE.mode: 0 waves BG1, BG2 and BG3 alike; any other mode waves BG3 alone (Mars Lighthouse's rain ledges).
#defineLINE_SCROLL_WAVE_ENTRIES 256LineScrollWaveSine's entries, a whole cycle: a phase is 16.16 entries.
#defineLINE_SCROLL_WAVE_UNITS 256The sine's units in a pixel: its peak, 4096, is 16 pixels at an amplitude of toFIXED(1).
#defineLINE_SCROLL_WAVE (phase, amplitude)The wave's offset in pixels at phase, for a 16.16 amplitude.

Functions

NameDescription
voidfdLineScrollArmDMA (void)VBlank-pass event for the line scroll: restarts DMA 0 each VBlank to copy the current page's BG1 to BG3 scroll offsets into the scroll registers one scanline at a time, but not while Reveal shows or a battle is due.
voidfdLineScrollBuildPage (void)Event for the line scroll: fills the hidden page with each scanline's BG1, BG2 and BG3 offsets, the scroll plus a sine wave for x and for y (an axis with no step stays flat; outside LINE_SCROLL_ALL_LAYERS only BG3 waves), its phase following BG1's y, then shows that page.
static inline voidfdWaitDMA (volatile DMA_REGISTERS *channel)Waits for a DMA channel to finish.
voidfdLineScrollInitWave (Sint32 mode, Sint32 frequencyX, Sint32 stepX, Sint32 ampX, Sint32 frequencyY, Sint32 stepY, Sint32 ampY)Starts the line scroll: its state (heap slot HEAP_SLOT_LINE_SCROLL) holds the mode and, for x and y, how fast the wave runs from tick to tick, its step from one scanline to the next and its amplitude; two events, one in the vertical blank pass and one in the tick pass, build and send each tick's line offsets.
voidfdLineScrollStop (void)Stops the line scroll: removes its two events and stops DMA 0.

Description

The line scroll: per-line scroll offsets fed by HBlank DMA. Part of script_commands.c.

Macros in detail

LINE_SCROLL_ALL_LAYERS

#define LINE_SCROLL_ALL_LAYERS 0

LINE_SCROLL_STATE.mode: 0 waves BG1, BG2 and BG3 alike; any other mode waves BG3 alone (Mars Lighthouse's rain ledges).

Referenced by fdLineScrollBuildPage().

Definition at line 6 of file script_commands_line_scroll.c.

LINE_SCROLL_WAVE_ENTRIES

#define LINE_SCROLL_WAVE_ENTRIES 256

LineScrollWaveSine's entries, a whole cycle: a phase is 16.16 entries.

Definition at line 8 of file script_commands_line_scroll.c.

LINE_SCROLL_WAVE_UNITS

#define LINE_SCROLL_WAVE_UNITS 256

The sine's units in a pixel: its peak, 4096, is 16 pixels at an amplitude of toFIXED(1).

Definition at line 11 of file script_commands_line_scroll.c.

LINE_SCROLL_WAVE

#define LINE_SCROLL_WAVE(phase, amplitude)

The wave's offset in pixels at phase, for a 16.16 amplitude.

Referenced by fdLineScrollBuildPage().

Definition at line 13 of file script_commands_line_scroll.c.

Functions in detail

fdLineScrollArmDMA

void fdLineScrollArmDMA(void)

VBlank-pass event for the line scroll: restarts DMA 0 each VBlank to copy the current page's BG1 to BG3 scroll offsets into the scroll registers one scanline at a time, but not while Reveal shows or a battle is due.

References syDMAXCopy().

Referenced by fdLineScrollInitWave() and fdLineScrollStop().

Definition at line 22 of file script_commands_line_scroll.c.

fdLineScrollBuildPage

void fdLineScrollBuildPage(void)

Event for the line scroll: fills the hidden page with each scanline's BG1, BG2 and BG3 offsets, the scroll plus a sine wave for x and for y (an axis with no step stays flat; outside LINE_SCROLL_ALL_LAYERS only BG3 waves), its phase following BG1's y, then shows that page.

References BgScrollWork and Sint32.

Referenced by fdLineScrollInitWave() and fdLineScrollStop().

Definition at line 63 of file script_commands_line_scroll.c.

fdWaitDMA

static inline void fdWaitDMA(volatile DMA_REGISTERS *channel)

Waits for a DMA channel to finish.

Referenced by fdLineScrollInitWave().

Definition at line 207 of file script_commands_line_scroll.c.

fdLineScrollInitWave

void fdLineScrollInitWave(Sint32 mode, Sint32 frequencyX, Sint32 stepX, Sint32 ampX, Sint32 frequencyY, Sint32 stepY, Sint32 ampY)

Starts the line scroll: its state (heap slot HEAP_SLOT_LINE_SCROLL) holds the mode and, for x and y, how fast the wave runs from tick to tick, its step from one scanline to the next and its amplitude; two events, one in the vertical blank pass and one in the tick pass, build and send each tick's line offsets.

References fdLineScrollArmDMA(), fdLineScrollBuildPage(), fdWaitDMA(), Sint32, syHeapSlotAllocateEWRAM() and sySetEvent().

Referenced by scMarsLighthouseHallStartRainWave().

Definition at line 219 of file script_commands_line_scroll.c.

fdLineScrollStop

void fdLineScrollStop(void)

Stops the line scroll: removes its two events and stops DMA 0.

References fdLineScrollArmDMA(), fdLineScrollBuildPage() and syCloseEvent().

Definition at line 245 of file script_commands_line_scroll.c.