3#include "affine_background_gfx.h"
4#include "affine_main_menu_background_gfx.h"
7#define ANIMATION_SPEED_DIVISOR 16
12static IWRAM_CODE
void s_affine_background_prep_bgaff_arr();
14static BG_AFFINE s_bgaff_arr[SCREEN_HEIGHT + 1];
15static AFF_SRC_EX s_asx = {0};
17static uint s_timer = 0;
28 vu16 vcount = REG_VCOUNT;
30 if ((vcount >= SCREEN_HEIGHT))
41 if (REG_IE & IRQ_HBLANK)
43 s_affine_background_prep_bgaff_arr();
52 s_asx.sx = ((lu_sin(s_timer * 100)) >> 8) + 256;
54 s_asx.sy = ((lu_sin(s_timer * 100 + 0x4000)) >> 8) + 256;
57 bg_rotscale_ex(&s_bgaff_arr[0], &s_asx);
72 clr_rgbscale(&pal_bg_mem[
AFFINE_BG_PB] + i, affine_background_gfxPal + i, 1, color);
83 if (s_background == new_bg)
88 s_background = new_bg;
93 REG_BG2CNT &= ~BG_AFF_32x32;
94 REG_BG2CNT |= BG_AFF_16x16;
98 (u32*)&tile8_mem[AFFINE_BG_CBB],
99 (
const u32*)affine_main_menu_background_gfxTiles,
100 affine_main_menu_background_gfxTilesLen / 4,
103 GRIT_CPY(&se_mem[AFFINE_BG_SBB], affine_main_menu_background_gfxMap);
107 REG_BG2CNT &= ~BG_AFF_16x16;
108 REG_BG2CNT |= BG_AFF_32x32;
109 REG_IE &= ~IRQ_HBLANK;
112 (u32*)&tile8_mem[AFFINE_BG_CBB],
113 (
const u32*)affine_background_gfxTiles,
114 affine_background_gfxTilesLen / 4,
117 GRIT_CPY(&se_mem[AFFINE_BG_SBB], affine_background_gfxMap);
125static IWRAM_CODE
void s_affine_background_prep_bgaff_arr()
127 for (u16 vcount = 0; vcount < SCREEN_HEIGHT; vcount++)
129 const s32 timer_s32 = s_timer << 8;
130 const s32 vcount_s32 = vcount << 8;
131 const s16 vcount_s16 = vcount;
132 const s32 vcount_sine = lu_sin(vcount_s32 + timer_s32 / ANIMATION_SPEED_DIVISOR);
134 s_asx.scr_x = (SCREEN_WIDTH / 2);
136 s_asx.scr_y = vcount_s16 - (SCREEN_HEIGHT / 2);
137 s_asx.tex_x = (1000 * 1000) + (vcount_sine);
138 s_asx.tex_y = (1000 * 1000);
141 s_asx.alpha = vcount_sine + (timer_s32 / ANIMATION_SPEED_DIVISOR);
143 bg_rotscale_ex(&s_bgaff_arr[vcount], &s_asx);
150 s_bgaff_arr[SCREEN_HEIGHT] = s_bgaff_arr[0];
Utilities for affine background on GBA.
void affine_background_set_color(COLOR color)
Update the affine background color.
void affine_background_init()
Initialize resources for affine background rendering.
IWRAM_CODE void affine_background_update()
Per-frame update of the affine background.
#define AFFINE_BG_IDX
The index of the affine background BGCNT register etc.
AffineBackgroundID
An ID to specify background rendering types.
@ AFFINE_BG_GAME
Display background for game play.
@ AFFINE_BG_NONE
Display background for the initial splash screen.
@ AFFINE_BG_MAIN_MENU
Display background for main menu.
void affine_background_change_background(enum AffineBackgroundID new_bg)
Update the background id.
#define AFFINE_BG_PAL_LEN
Number of u16 colors available in the palette.
IWRAM_CODE void affine_background_hblank()
Interrupt routine to update display on HBLANK.
void affine_background_load_palette(const u16 *src)
Set the background palette.
#define AFFINE_BG_PB
The starting index of the background palette.
Graphic utility functions.
void memcpy32_tile8_with_palette_offset(u32 *dst, const u32 *src, uint wcount, u8 palette_offset)
Copies 32 bit data from src to dst, applying a palette offset to the data.