Main menu uses HBLANK and the game uses standard affine background

This commit is contained in:
cellos51
2025-08-28 23:00:27 -04:00
parent f4d8fc9097
commit d0d83eb236
+21 -4
View File
@@ -8,7 +8,6 @@
BG_AFFINE bgaff_arr[SCREEN_HEIGHT + 1];
BG_AFFINE bgaff;
AFF_SRC_EX asx = {0};
enum AffineBackgroundID background = AFFINE_BG_MAIN_MENU;
@@ -30,12 +29,11 @@ IWRAM_CODE void affine_background_prep_bgaff_arr()
{
for (u16 vcount = 0; vcount < SCREEN_HEIGHT; vcount++)
{
AFF_SRC_EX asx = {32<<8, 64<<8, 120, 80, 0x0100, 0x0100, 0};
const s32 timer_s32 = timer << 8;
const s32 vcount_s32 = vcount << 8;
const s16 vcount_s16 = vcount;
const s32 vcount_sine = lu_sin(vcount_s32 + timer_s32 / ANIMATION_SPEED_DIVISOR); // dividing the timer by 16 to make the animation slower
asx.scr_x = (SCREEN_WIDTH / 2); // 128 on x and y is an offset used to center the rotation
asx.scr_y = vcount_s16 - (SCREEN_HEIGHT / 2); // scr_y must equal vcount otherwise the background will have no vertical difference
asx.tex_x = (1000 * 1000) + (vcount_sine);
@@ -69,7 +67,24 @@ IWRAM_CODE void affine_background_hblank()
void affine_background_update()
{
affine_background_prep_bgaff_arr();
if (REG_IE & IRQ_HBLANK) // High quality mode with HBLANK interrupt
{
affine_background_prep_bgaff_arr();
}
else // Low quality mode without HBLANK interrupt
{
asx.scr_x = 0;
asx.scr_y = 0;
asx.tex_x += 5;
asx.tex_y += 12;
asx.sx = ((lu_sin(timer * 100)) >> 8) + 256; // Scale the sine value to fit in a s16
asx.sy = ((lu_sin(timer * 100 + 0x4000)) >> 8) + 256; // Scale the sine value to fit in a s16
asx.alpha = 0;
bg_rotscale_ex(&bgaff_arr[0], &asx);
REG_BG_AFFINE[AFFINE_BG_IDX] = bgaff_arr[0];
}
timer++;
}
@@ -96,6 +111,7 @@ void affine_background_change_background(enum AffineBackgroundID new_bg)
case AFFINE_BG_MAIN_MENU:
REG_BG2CNT &= ~BG_AFF_32x32;
REG_BG2CNT |= BG_AFF_16x16;
REG_IE |= IRQ_HBLANK; // Enable HBLANK
memcpy32_tile8_with_palette_offset((u32*)&tile8_mem[AFFINE_BG_CBB], (const u32*)affine_main_menu_background_gfxTiles, affine_main_menu_background_gfxTilesLen/4, AFFINE_BG_PB);
GRIT_CPY(&se_mem[AFFINE_BG_SBB], affine_main_menu_background_gfxMap);
@@ -104,6 +120,7 @@ void affine_background_change_background(enum AffineBackgroundID new_bg)
case AFFINE_BG_GAME:
REG_BG2CNT &= ~BG_AFF_16x16;
REG_BG2CNT |= BG_AFF_32x32;
REG_IE &= ~IRQ_HBLANK; // Disable HBLANK
memcpy32_tile8_with_palette_offset((u32*)&tile8_mem[AFFINE_BG_CBB], (const u32*)affine_background_gfxTiles, affine_background_gfxTilesLen/4, AFFINE_BG_PB);
GRIT_CPY(&se_mem[AFFINE_BG_SBB], affine_background_gfxMap);