diff --git a/include/affine_background.h b/include/affine_background.h index 8e5f78f..d3f06e8 100644 --- a/include/affine_background.h +++ b/include/affine_background.h @@ -9,6 +9,7 @@ #define AFFINE_BG_PB (PAL_ROW_LEN * 15) // This isn't really a palette bank, just the starting index of the palette void affine_background_init(); +void affine_background_hblank(); void affine_background_update(); void affine_background_set_color(COLOR color); // Must be called with an array of size at least AFFINE_BG_PAL_LEN diff --git a/source/affine_background.c b/source/affine_background.c index f9e15e7..a5c29c5 100644 --- a/source/affine_background.c +++ b/source/affine_background.c @@ -5,6 +5,7 @@ BG_AFFINE bgaff; AFF_SRC_EX asx = {32<<8, 64<<8, 120, 80, 0x0100, 0x0100, 0}; +static uint timer = 0; void affine_background_init() { @@ -15,22 +16,26 @@ void affine_background_init() bgaff = bg_aff_default; } -void affine_background_update() +void affine_background_hblank() { - static uint timer = 0; - timer++; + const s32 timer_s32 = timer << 8; + const s32 vcount_s32 = REG_VCOUNT << 8; + const s16 vcount_s16 = REG_VCOUNT; - // These values are not permament, just the current configuration for the affine background - asx.tex_x += 5; - asx.tex_y += 12; - asx.sx = (lu_sin(timer * 100)) >> 8; // Scale the sine value to fit in a s16 - asx.sx += 256; // Add 256 to the sine value to make it positive - asx.sy = (lu_sin(timer * 100 + 0x4000)) >> 8; // Scale the sine value to fit in a s16 - asx.sy += 256; // Add 256 to the sine value to make it positive + asx.scr_y = vcount_s16 - 128; // 128 on x and y is an offset used to center the rotation + asx.scr_x = 128; + asx.tex_x = lu_sin(timer_s32 + vcount_s32) + timer / 8; + asx.alpha = (vcount_s32 + timer_s32) / 8; + bg_rotscale_ex(&bgaff, &asx); REG_BG_AFFINE[2] = bgaff; } +void affine_background_update() +{ + timer++; +} + void affine_background_set_color(COLOR color) { memcpy16(&pal_bg_mem[AFFINE_BG_PB], affine_background_gfxPal, AFFINE_BG_PAL_LEN); diff --git a/source/main.c b/source/main.c index 76abc07..fa3d2dd 100644 --- a/source/main.c +++ b/source/main.c @@ -22,6 +22,7 @@ void init() { irq_init(NULL); irq_add(II_VBLANK, mmVBlank); + irq_add(II_HBLANK, affine_background_hblank); // Initialize maxmod mmInitDefault((mm_addr)soundbank_bin, 12);