Alchemy
Loading...
Searching...
No Matches

blitter.c File Reference

The blitter builder, BattleFx_BuildBlitter. More...

Go to the source code of this file.

Macros

#define BRANCH_FIELD(site, target)
 The 24-bit displacement field of an ARM branch at site to target: in words, counted from the branch plus 8 bytes, as the processor reads two words ahead.
#define BLITTER_PARTIAL_RUN(mode, flags)
 The words of a partial run, one pixel at a time: the mode's one-pixel fragment, read forwards or, mirrored across, backwards.
#define BLITTER_WALK()
 The template walk itself, written once.
#define PUT(word)
#define COPY(n)
#define COPY_FROM(from, n)
#define COPY_TWICE(from, n)
#define PUT_BRANCH(target)
#define MARK(site)
#define PATCH(site)
#define PUT(word)
#define COPY(n)
#define COPY_FROM(from, n)
#define COPY_TWICE(from, n)
#define PUT_BRANCH(target)
#define MARK(site)
#define PATCH(site)

Functions

s32 BattleFx_BuildBlitter (s32 slot, s32 widthShift, s32 heightShift, s32 flags, u32 mode)
 Writes a drawing routine for the canvas into heap slot slot, built from the template BattleFx_Composite for one clip, mirroring and blend mode.

Detailed Description

The blitter builder, BattleFx_BuildBlitter.

Part of effect.c, the battle effect object, compiled only through it. The folder README describes the routine it writes, block by block, under "Blitters"; the fragments' registers and modes are described at the top of battle_effect_composite.s.

Definition in file blitter.c.

Macro Definition Documentation

◆ BRANCH_FIELD

#define BRANCH_FIELD ( site,
target )
Value:
((((u32)(target) - (u32)(site) - 8) >> 2) & 0x00FFFFFF)
unsigned int u32
Definition types.h:15

The 24-bit displacement field of an ARM branch at site to target: in words, counted from the branch plus 8 bytes, as the processor reads two words ahead.

Definition at line 13 of file blitter.c.

◆ BLITTER_PARTIAL_RUN

#define BLITTER_PARTIAL_RUN ( mode,
flags )

The words of a partial run, one pixel at a time: the mode's one-pixel fragment, read forwards or, mirrored across, backwards.

Each walk writes a leading and a trailing run.

Definition at line 19 of file blitter.c.

◆ BLITTER_WALK

#define BLITTER_WALK ( )

The template walk itself, written once.

BattleFx_BuildBlitter expands it twice under two definitions of PUT, COPY, COPY_FROM, COPY_TWICE, PUT_BRANCH, MARK and PATCH: first to count the words, then to write them. It uses the caller's templateWords, flags, mode, widthShift, heightShift, and the branch sites emptyRowsBranch, emptyColumnsBranch, rowLoop, skipBranch, partialRun and fullCellLoop.

Definition at line 58 of file blitter.c.

Referenced by BattleFx_BuildBlitter().

◆ PUT [1/2]

#define PUT ( word)
Value:
wordCount++

◆ COPY [1/2]

#define COPY ( n)
Value:
wordCount += (n); \
templateWords += (n)

◆ COPY_FROM [1/2]

#define COPY_FROM ( from,
n )
Value:
wordCount += (n)

◆ COPY_TWICE [1/2]

#define COPY_TWICE ( from,
n )
Value:
wordCount += (n); \
wordCount += (n)

◆ PUT_BRANCH [1/2]

#define PUT_BRANCH ( target)
Value:
wordCount++

◆ MARK [1/2]

#define MARK ( site)

◆ PATCH [1/2]

#define PATCH ( site)

◆ PUT [2/2]

#define PUT ( word)
Value:
do { \
*codeWords++ = (word); \
} while (0)

◆ COPY [2/2]

#define COPY ( n)
Value:
do { \
Dma_Set(templateWords, codeWords, DMA_COPY_WORDS(n), REG_DMA3); \
codeWords += (n); \
templateWords += (n); \
} while (0)
#define REG_DMA3
Definition io_reg.h:153
#define DMA_COPY_WORDS(n)
Definition io_reg.h:226

◆ COPY_FROM [2/2]

#define COPY_FROM ( from,
n )
Value:
Dma_Set(from, codeWords, DMA_COPY_WORDS(n), REG_DMA3); \
codeWords += (n)

◆ COPY_TWICE [2/2]

#define COPY_TWICE ( from,
n )
Value:
{ \
const u32 *part = (from); \
Dma_Set(part, codeWords, DMA_COPY_WORDS(n), REG_DMA3); \
codeWords += (n); \
Dma_Set(part, codeWords, DMA_COPY_WORDS(n), REG_DMA3); \
codeWords += (n); \
}

◆ PUT_BRANCH [2/2]

#define PUT_BRANCH ( target)
Value:
*codeWords = *templateWords++ + BRANCH_FIELD(codeWords, target); \
codeWords++
#define BRANCH_FIELD(site, target)
The 24-bit displacement field of an ARM branch at site to target: in words, counted from the branch p...
Definition blitter.c:13

◆ MARK [2/2]

#define MARK ( site)
Value:
site = codeWords

◆ PATCH [2/2]

#define PATCH ( site)
Value:
do { \
*(site) |= BRANCH_FIELD(site, codeWords); \
} while (0)

Function Documentation

◆ BattleFx_BuildBlitter()

s32 BattleFx_BuildBlitter ( s32 slot,
s32 widthShift,
s32 heightShift,
s32 flags,
u32 mode )

Writes a drawing routine for the canvas into heap slot slot, built from the template BattleFx_Composite for one clip, mirroring and blend mode.

Called through EFFECT_LOAD_BLITTER by nearly every canvas effect and by BattleFx_FetchRectangleBlitters, directly by the particle streams for a canvas 256 pixels wide, and from other banks through its far stub, BattleEffect_LoadWorkFar (the star field in battle/star_field.c and object/colorfx.c).

It allocates the slot's block (from IWRAM when it fits) at exactly the routine's size. A slot that already holds a block keeps it, whatever its size, and the routine is written over it: callers release the slot first when the new routine may be longer. The caller calls the slot's block as a DrawRectangle.

widthShift, heightShift: the canvas's width and height as powers of two. flags: the COMPOSITE_CLIP_ and COMPOSITE_FLIP_ bits. mode: how source pixels combine with the canvas (COMPOSITE_COPY, COMPOSITE_TRANSPARENT, COMPOSITE_MAX or COMPOSITE_ADDITIVE).

Returns nonzero when the walk ended exactly at gBattleFx_MoteCells, the end of the template; no caller reads it.

Definition at line 281 of file blitter.c.

Referenced by BattleFx_BuildBlitter(), and BattleFx_RunParticleStreams().