From 8315d6a42c73a4409ad45a6d00a9f32fd0837720 Mon Sep 17 00:00:00 2001 From: Elliptical <70788102+cellos51@users.noreply.github.com> Date: Sat, 2 Aug 2025 10:29:26 -0400 Subject: [PATCH 01/13] Switching to a boss blind now changes the background palette --- source/game.c | 8 ++++++++ source/main.c | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/source/game.c b/source/game.c index 6f3d8de..939382f 100644 --- a/source/game.c +++ b/source/game.c @@ -18,6 +18,7 @@ #include "background_gfx.h" #include "background_shop_gfx.h" #include "background_blind_select_gfx.h" +#include "affine_background_gfx.h" #include "soundbank.h" @@ -419,6 +420,13 @@ void change_background(int id) else if (current_blind == BOSS_BLIND) { main_bg_se_copy_rect(BOSS_BLIND_TITLE_SRC_RECT, TOP_LEFT_BLIND_TITLE_POINT); + u16 palette[5] = {}; + palette[0] = blind_get_color(current_blind, BLIND_BACKGROUND_SECONDARY_COLOR_INDEX); + palette[1] = blind_get_color(current_blind, BLIND_SHADOW_COLOR_INDEX); + palette[2] = blind_get_color(current_blind, BLIND_BACKGROUND_SHADOW_COLOR_INDEX); + palette[3] = blind_get_color(current_blind, BLIND_MAIN_COLOR_INDEX); + palette[4] = blind_get_color(current_blind, BLIND_TEXT_COLOR_INDEX); + memcpy16(&pal_bg_mem[16 * 15], palette, 5); } bg_copy_current_item_to_top_left_panel(); diff --git a/source/main.c b/source/main.c index bd7b046..2cb29fc 100644 --- a/source/main.c +++ b/source/main.c @@ -33,7 +33,7 @@ void init_map() // Temp function derived from libtonc example // Actually for future reference, each number seems to equate to an XY on the palette, so 0xF0F0F0F0 would just push everything down 15 colors, since the second number isn't set. } - memcpy(&tile8_mem[AFFINE_BG_CBB], correctedTiles, affine_background_gfxTilesLen); + memcpy16(&tile8_mem[AFFINE_BG_CBB], correctedTiles, affine_background_gfxTilesLen); GRIT_CPY(&se_mem[AFFINE_BG_SBB], affine_background_gfxMap); memcpy16(&pal_bg_mem[16 * 15], affine_background_gfxPal, 5); From dcff3267302935718a760ee334c3582467e9fd0d Mon Sep 17 00:00:00 2001 From: Elliptical <70788102+cellos51@users.noreply.github.com> Date: Sat, 2 Aug 2025 14:54:08 -0400 Subject: [PATCH 02/13] Refactor to make it just change the brightness of a chosen color. I will make a seperate .h/.c file for the affine background when I get home. --- source/game.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/source/game.c b/source/game.c index 939382f..68720f3 100644 --- a/source/game.c +++ b/source/game.c @@ -420,13 +420,23 @@ void change_background(int id) else if (current_blind == BOSS_BLIND) { main_bg_se_copy_rect(BOSS_BLIND_TITLE_SRC_RECT, TOP_LEFT_BLIND_TITLE_POINT); - u16 palette[5] = {}; - palette[0] = blind_get_color(current_blind, BLIND_BACKGROUND_SECONDARY_COLOR_INDEX); - palette[1] = blind_get_color(current_blind, BLIND_SHADOW_COLOR_INDEX); - palette[2] = blind_get_color(current_blind, BLIND_BACKGROUND_SHADOW_COLOR_INDEX); - palette[3] = blind_get_color(current_blind, BLIND_MAIN_COLOR_INDEX); - palette[4] = blind_get_color(current_blind, BLIND_TEXT_COLOR_INDEX); - memcpy16(&pal_bg_mem[16 * 15], palette, 5); + + const int palette_length = 5; + memcpy16(&pal_bg_mem[16 * 15], affine_background_gfxPal, palette_length); + for (int i = 0; i < palette_length; i++) + { + COLOR old_color = 0; + memcpy16(&old_color, &pal_bg_mem[16 * 15] + i, 1); // Copy the color from the background palette + + int r, g, b; + r = (old_color >> 10) & 0b11111; // Extract red component + g = (old_color >> 5) & 0b11111; // Extract green component + b = old_color & 0b11111; // Extract blue component + + COLOR new_color = blind_get_color(BOSS_BLIND, BLIND_MAIN_COLOR_INDEX); + int brightness = (r + g + b) / 3; // Calculate brightness + clr_adj_brightness(&pal_bg_mem[16 * 15] + i, &new_color, 1, float2fx(-0.6f + (brightness * 0.05f))); // Adjust brightness for the palette colors + } } bg_copy_current_item_to_top_left_panel(); From 592d7ae8bcfcf59bb73f19ab71e901ed75a236f4 Mon Sep 17 00:00:00 2001 From: cellos51 Date: Tue, 5 Aug 2025 14:35:52 -0400 Subject: [PATCH 03/13] Add affine background color functionality and integrate into game loop --- graphics/affine_background_gfx.png | Bin 2983 -> 2959 bytes include/affine_background.h | 16 ++++++++ source/affine_background.c | 63 +++++++++++++++++++++++++++++ source/game.c | 19 ++------- source/main.c | 45 ++------------------- 5 files changed, 85 insertions(+), 58 deletions(-) create mode 100644 include/affine_background.h create mode 100644 source/affine_background.c diff --git a/graphics/affine_background_gfx.png b/graphics/affine_background_gfx.png index 7a567dc88ab88fa6a85a61877c8a4ab43c2946fd..4abff4b34d35f12f2434af43a1683347f104c73b 100644 GIT binary patch literal 2959 zcmajh4Nwzj8VB&jQ%O-U_N1tYinQWKJv#+N#JC3$BRYs6$bd?uy(20WXaVsO$XW@0 zE2Gw)UuCsaK|G)*h!uoY)Z?I%6%jDDB%)}5gl=#NNno>k@0;}QnBnL#!)*4=vmbf# z%m3NK8#joYon|^A2;v;Nc6B6zIDnT92yY_TZ2h7r5$>f$ih>N}T~gdW$J0Q!8$~>Z$*@ixhhp1CE=zPWWl4WEHQjWqgbKLz532Ul4j;2+ z@o?Iod1Vb^*SaJ%!$eze@AA&V2lRZk_D53Oj4uv0`>J9+v(9^?m>-sS@O!_8X3x)> z@^Io5>LYwsEj;d&K)E!L;)i&w=d2o0k4Igz%va7jv5$D2`b~}To)@#%{YVm37(MrK z8+An{IBWK;lrQbj-J1;Wd+-H$;IZ^cZ!YQ{tP5Q%XIrhRYTCp3vKy=4@a(#oVZaS` z;R2bk`#3r?n0iUmWxZrXSDUuLAVcRwXUSPtYe4z^?5bp6xvr}Dp;jwy!plv|sdlms ztCDZ-w^(A{YA3S-h01IqE^Gq_L^C_B`Sce=PC75+~AyUTeEYa_QJK z94AWABP8r7IA57A4_p=W6`V>pQ~+)%!-`JJ|Gza6;8IoWf>rQ)Xd%C}zIPGlRBX3J z3C@cZe{eRRVwfcJ6#ogW^fx%>!CkI=A*}@;@3qGI316VGSlVey>S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>*Ct?nBC0SQ<5!LM@Qt(o9 zqXD8p(;Z$SMQfrsB3$*>0D)b`QmwLsdwAZ=(QY&teWw34A1!Qhi_#A{dZL~+F(6Cp zrv1HHw7Ul2@=p-XVpCgjm^s-J3u=TZqib6&L!Xh7I9ce^q-0v?Yehe|(6<%|FPK48 z4>Hptn)EwnJyDh|q;lp0axNg}0y1$fApb`JNz>0Bj(i)eD_a8ogrUf-F=6$b1Nnad DhT-E# diff --git a/include/affine_background.h b/include/affine_background.h new file mode 100644 index 0000000..31440c0 --- /dev/null +++ b/include/affine_background.h @@ -0,0 +1,16 @@ +#ifndef AFFINE_BACKGROUND_H +#define AFFINE_BACKGROUND_H + +#include + +#include "graphic_utils.h" + +#define AFFINE_BG_PAL_LEN 5 +#define AFFINE_BG_PB (PAL_ROW_LEN * 15) // This isn't really a palette bank, just the starting index of the palette +#define AFFINE_BG_DEFAULT_COLOR 0x3E4B + +void affine_background_init(); +void affine_background_update(); +void affine_background_set_color(COLOR color); + +#endif // AFFINE_BACKGROUND_H \ No newline at end of file diff --git a/source/affine_background.c b/source/affine_background.c new file mode 100644 index 0000000..6752be2 --- /dev/null +++ b/source/affine_background.c @@ -0,0 +1,63 @@ +#include "affine_background.h" +#include "affine_background_gfx.h" + +#include "graphic_utils.h" + +BG_AFFINE bgaff; +AFF_SRC_EX asx = {32<<8, 64<<8, 120, 80, 0x0100, 0x0100, 0}; + +void affine_background_init() +{ + unsigned int correctedTiles[affine_background_gfxTilesLen / 4]; + + for (int i = 0; i < affine_background_gfxTilesLen / 4; i++) + { + correctedTiles[i] = affine_background_gfxTiles[i] | 0xF0F0F0F0; + } + + memcpy16(&tile8_mem[AFFINE_BG_CBB], correctedTiles, affine_background_gfxTilesLen/2); + GRIT_CPY(&se_mem[AFFINE_BG_SBB], affine_background_gfxMap); + memcpy16(&pal_bg_mem[AFFINE_BG_PB], affine_background_gfxPal, AFFINE_BG_PAL_LEN); + + bgaff = bg_aff_default; + + affine_background_set_color(AFFINE_BG_DEFAULT_COLOR); +} + +void affine_background_update() +{ + static uint timer = 0; + timer++; + + // 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 + bg_rotscale_ex(&bgaff, &asx); + REG_BG_AFFINE[2] = bgaff; +} + +void affine_background_set_color(COLOR color) +{ + memcpy16(&pal_bg_mem[AFFINE_BG_PB], affine_background_gfxPal, AFFINE_BG_PAL_LEN); + for (int i = 0; i < AFFINE_BG_PAL_LEN; i++) + { + COLOR old_color; + memcpy16(&old_color, &pal_bg_mem[AFFINE_BG_PB] + i, 1); // Copy the color from the background palette + + int r, g, b; + r = (old_color >> 10) & 0b11111; // Extract red component + g = (old_color >> 5) & 0b11111; // Extract green component + b = old_color & 0b11111; // Extract blue component + + int brightness = (r + g + b) / 3; // Calculate brightness + + const float brightness_divergence = 0.03f; // The difference in brightness between each color in the palette + const float brightness_modifier = -0.4f; // The overall brightness modifier for the palette + + clr_adj_brightness(&pal_bg_mem[AFFINE_BG_PB] + i, &color, 1, float2fx(brightness_modifier + (brightness * brightness_divergence))); // Adjust brightness for the palette colors + } +} \ No newline at end of file diff --git a/source/game.c b/source/game.c index e1e4e82..0f74e88 100644 --- a/source/game.c +++ b/source/game.c @@ -11,6 +11,7 @@ #include "hand_analysis.h" #include "blind.h" #include "joker.h" +#include "affine_background.h" #include "graphic_utils.h" #include "tonc_video.h" #include "audio_utils.h" @@ -430,22 +431,7 @@ void change_background(int id) { main_bg_se_copy_rect(BOSS_BLIND_TITLE_SRC_RECT, TOP_LEFT_BLIND_TITLE_POINT); - const int palette_length = 5; - memcpy16(&pal_bg_mem[16 * 15], affine_background_gfxPal, palette_length); - for (int i = 0; i < palette_length; i++) - { - COLOR old_color = 0; - memcpy16(&old_color, &pal_bg_mem[16 * 15] + i, 1); // Copy the color from the background palette - - int r, g, b; - r = (old_color >> 10) & 0b11111; // Extract red component - g = (old_color >> 5) & 0b11111; // Extract green component - b = old_color & 0b11111; // Extract blue component - - COLOR new_color = blind_get_color(BOSS_BLIND, BLIND_MAIN_COLOR_INDEX); - int brightness = (r + g + b) / 3; // Calculate brightness - clr_adj_brightness(&pal_bg_mem[16 * 15] + i, &new_color, 1, float2fx(-0.6f + (brightness * 0.05f))); // Adjust brightness for the palette colors - } + affine_background_set_color(blind_get_color(BOSS_BLIND, BLIND_SHADOW_COLOR_INDEX)); } bg_copy_current_item_to_top_left_panel(); @@ -2004,6 +1990,7 @@ void game_round_end() tte_erase_rect_wrapper(BLIND_REWARD_RECT); tte_erase_rect_wrapper(BLIND_REQ_TEXT_RECT); obj_hide(playing_blind_token->obj); + affine_background_set_color(AFFINE_BG_DEFAULT_COLOR); state = 5; timer = 0; } diff --git a/source/main.c b/source/main.c index 2cb29fc..76abc07 100644 --- a/source/main.c +++ b/source/main.c @@ -7,6 +7,7 @@ #include "game.h" #include "blind.h" #include "joker.h" +#include "affine_background.h" #include "graphic_utils.h" // Graphics @@ -17,29 +18,6 @@ #include "soundbank.h" #include "soundbank_bin.h" -#define MAP_AFF_SIZE 0x0100 -BG_AFFINE bgaff; -AFF_SRC_EX asx = {32<<8, 64<<8, 120, 80, 0x0100, 0x0100, 0}; - - -void init_map() // Temp function derived from libtonc example -{ - // Grit is fucking garbage and doesn't allow you to have a palette offset, they all get loaded at 0x0000. I have to manually change each tile's palette bank - - unsigned int correctedTiles[affine_background_gfxTilesLen / 4]; - for (int i = 0; i < affine_background_gfxTilesLen / 4; i++) - { - correctedTiles[i] = affine_background_gfxTiles[i] | 0xF0F0F0F0; // I brute forced this. I have no idea how this would and does work, but it does. We'll just leave this here for now. - // Actually for future reference, each number seems to equate to an XY on the palette, so 0xF0F0F0F0 would just push everything down 15 colors, since the second number isn't set. - } - - memcpy16(&tile8_mem[AFFINE_BG_CBB], correctedTiles, affine_background_gfxTilesLen); - GRIT_CPY(&se_mem[AFFINE_BG_SBB], affine_background_gfxMap); - memcpy16(&pal_bg_mem[16 * 15], affine_background_gfxPal, 5); - - bgaff = bg_aff_default; -} - void init() { irq_init(NULL); @@ -93,9 +71,8 @@ void init() REG_DISPCNT = DCNT_MODE1 | DCNT_OBJ_1D | DCNT_BG0 | DCNT_BG1 | DCNT_BG2 | DCNT_OBJ | DCNT_WIN0 | DCNT_WIN1; - init_map(); // Initialize the map for the background - // Initialize subsystems + affine_background_init(); sprite_init(); card_init(); blind_init(); @@ -103,24 +80,9 @@ void init() game_init(); } -void background_update() // This needs to be called before update() and draw() because setting REG_BG_AFFINE during an HBlank can cause issues -{ - static uint timer = 0; - timer++; - - // 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 - bg_rotscale_ex(&bgaff, &asx); - REG_BG_AFFINE[2]= bgaff; -} - void update() { + affine_background_update(); game_update(); } @@ -138,7 +100,6 @@ int main() VBlankIntrWait(); mmFrame(); key_poll(); - background_update(); update(); draw(); } From d0ca4a483d1019239e6450e8d0be1f1a7f67b313 Mon Sep 17 00:00:00 2001 From: cellos51 Date: Tue, 5 Aug 2025 14:42:37 -0400 Subject: [PATCH 04/13] Fix indentation in affine_background.c for consistency --- source/affine_background.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/affine_background.c b/source/affine_background.c index 6752be2..da09b7f 100644 --- a/source/affine_background.c +++ b/source/affine_background.c @@ -15,11 +15,11 @@ void affine_background_init() correctedTiles[i] = affine_background_gfxTiles[i] | 0xF0F0F0F0; } - memcpy16(&tile8_mem[AFFINE_BG_CBB], correctedTiles, affine_background_gfxTilesLen/2); + memcpy16(&tile8_mem[AFFINE_BG_CBB], correctedTiles, affine_background_gfxTilesLen/2); GRIT_CPY(&se_mem[AFFINE_BG_SBB], affine_background_gfxMap); memcpy16(&pal_bg_mem[AFFINE_BG_PB], affine_background_gfxPal, AFFINE_BG_PAL_LEN); - bgaff = bg_aff_default; + bgaff = bg_aff_default; affine_background_set_color(AFFINE_BG_DEFAULT_COLOR); } @@ -37,7 +37,7 @@ void affine_background_update() 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 bg_rotscale_ex(&bgaff, &asx); - REG_BG_AFFINE[2] = bgaff; + REG_BG_AFFINE[2] = bgaff; } void affine_background_set_color(COLOR color) From 9be6a31dce70336989263400b8db336ab9b301c7 Mon Sep 17 00:00:00 2001 From: cellos51 Date: Thu, 7 Aug 2025 23:31:23 -0400 Subject: [PATCH 05/13] Use tonc defines for getting colors --- source/affine_background.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/affine_background.c b/source/affine_background.c index da09b7f..c530bb8 100644 --- a/source/affine_background.c +++ b/source/affine_background.c @@ -49,9 +49,9 @@ void affine_background_set_color(COLOR color) memcpy16(&old_color, &pal_bg_mem[AFFINE_BG_PB] + i, 1); // Copy the color from the background palette int r, g, b; - r = (old_color >> 10) & 0b11111; // Extract red component - g = (old_color >> 5) & 0b11111; // Extract green component - b = old_color & 0b11111; // Extract blue component + r = (old_color & RED_MASK) >> RED_SHIFT; // Extract red component + g = (old_color & GREEN_MASK) >> GREEN_SHIFT; // Extract green component + b = (old_color & BLUE_MASK) >> BLUE_SHIFT; // Extract blue component int brightness = (r + g + b) / 3; // Calculate brightness From bebe2237e48500aa369a79b0f82b2b3586321ffa Mon Sep 17 00:00:00 2001 From: cellos51 Date: Fri, 8 Aug 2025 00:00:20 -0400 Subject: [PATCH 06/13] Add memcpy16_tile8_with_palette_offset function and update affine_background_init to use it --- include/graphic_utils.h | 5 +++++ source/affine_background.c | 9 +-------- source/graphic_utils.c | 11 +++++++++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/include/graphic_utils.h b/include/graphic_utils.h index 2791791..695c388 100644 --- a/include/graphic_utils.h +++ b/include/graphic_utils.h @@ -120,4 +120,9 @@ void tte_erase_rect_wrapper(Rect rect); */ void update_text_rect_to_right_align_num(Rect* rect, int num, int overflow_direction); +/*Copies 16 bit data from src to dst, applying a palette offset to the data. + * This is intended solely for use with tile8/8bpp data for dst and src. + */ +void memcpy16_tile8_with_palette_offset(void* dst, const void* src, uint hwcount, u8 palette_offset); + #endif //GRAPHIC_UTILS_H \ No newline at end of file diff --git a/source/affine_background.c b/source/affine_background.c index c530bb8..b51ecda 100644 --- a/source/affine_background.c +++ b/source/affine_background.c @@ -8,14 +8,7 @@ AFF_SRC_EX asx = {32<<8, 64<<8, 120, 80, 0x0100, 0x0100, 0}; void affine_background_init() { - unsigned int correctedTiles[affine_background_gfxTilesLen / 4]; - - for (int i = 0; i < affine_background_gfxTilesLen / 4; i++) - { - correctedTiles[i] = affine_background_gfxTiles[i] | 0xF0F0F0F0; - } - - memcpy16(&tile8_mem[AFFINE_BG_CBB], correctedTiles, affine_background_gfxTilesLen/2); + memcpy16_tile8_with_palette_offset(&tile8_mem[AFFINE_BG_CBB], affine_background_gfxTiles, affine_background_gfxTilesLen/2, AFFINE_BG_PB); GRIT_CPY(&se_mem[AFFINE_BG_SBB], affine_background_gfxMap); memcpy16(&pal_bg_mem[AFFINE_BG_PB], affine_background_gfxPal, AFFINE_BG_PAL_LEN); diff --git a/source/graphic_utils.c b/source/graphic_utils.c index 5311711..890cb33 100644 --- a/source/graphic_utils.c +++ b/source/graphic_utils.c @@ -168,3 +168,14 @@ void update_text_rect_to_right_align_num(Rect* rect, int num, int overflow_direc } } +void memcpy16_tile8_with_palette_offset(void* dst, const void* src, uint hwcount, u8 palette_offset) +{ + u16* dst16 = (u16*)dst; + const u16* src16 = (const u16*)src; + + for (int i = 0; i < hwcount; i++) + { + // Copying u8 data twice across u16 data + dst16[i] = src16[i] + (((palette_offset) << 8) | (palette_offset)); + } +} \ No newline at end of file From dbe8585c0af01951b4dc8ff5d7886c9911fe63ec Mon Sep 17 00:00:00 2001 From: cellos51 Date: Fri, 8 Aug 2025 00:08:28 -0400 Subject: [PATCH 07/13] Refactor affine_background_set_color to simplify brightness adjustment logic --- source/affine_background.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/source/affine_background.c b/source/affine_background.c index b51ecda..fd4a718 100644 --- a/source/affine_background.c +++ b/source/affine_background.c @@ -38,19 +38,6 @@ void affine_background_set_color(COLOR color) memcpy16(&pal_bg_mem[AFFINE_BG_PB], affine_background_gfxPal, AFFINE_BG_PAL_LEN); for (int i = 0; i < AFFINE_BG_PAL_LEN; i++) { - COLOR old_color; - memcpy16(&old_color, &pal_bg_mem[AFFINE_BG_PB] + i, 1); // Copy the color from the background palette - - int r, g, b; - r = (old_color & RED_MASK) >> RED_SHIFT; // Extract red component - g = (old_color & GREEN_MASK) >> GREEN_SHIFT; // Extract green component - b = (old_color & BLUE_MASK) >> BLUE_SHIFT; // Extract blue component - - int brightness = (r + g + b) / 3; // Calculate brightness - - const float brightness_divergence = 0.03f; // The difference in brightness between each color in the palette - const float brightness_modifier = -0.4f; // The overall brightness modifier for the palette - - clr_adj_brightness(&pal_bg_mem[AFFINE_BG_PB] + i, &color, 1, float2fx(brightness_modifier + (brightness * brightness_divergence))); // Adjust brightness for the palette colors + clr_rgbscale(&pal_bg_mem[AFFINE_BG_PB] + i, &pal_bg_mem[AFFINE_BG_PB] + i, 1, color); } } \ No newline at end of file From 3c79a35b92189b172d06aa3554cd735be80a9cda Mon Sep 17 00:00:00 2001 From: cellos51 Date: Fri, 8 Aug 2025 00:22:04 -0400 Subject: [PATCH 08/13] Redefined affinge background default color to use RGB15 and reverted grayscale of background image --- graphics/affine_background_gfx.png | Bin 2959 -> 2983 bytes include/affine_background.h | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/graphics/affine_background_gfx.png b/graphics/affine_background_gfx.png index 4abff4b34d35f12f2434af43a1683347f104c73b..7a567dc88ab88fa6a85a61877c8a4ab43c2946fd 100644 GIT binary patch literal 2983 zcmeH}e@qi+7{?ETP%$77(E&qjaQ*-k9U}$-FBYUAf`Tl9h(ESPL^nYJ3#IEJmLKAv z+1zB4;^7(wk(JINbAt7hO;O`G5urkaA~+8yLQAQ%<$AaGXtt4M0G{z?eS6G4y(l=6lkC~G|gjU0fWOY~N(XqQDt&DROatCF16 zBYw0&3DZ-C-?Zjwm2gTsIH()Ek|`jylmw&9(`neW3ZcnY1bkEIOHIR+0BOTfI!B}1 zttU40C-~p<5(jJ@Aml@0M}tvq^0F3EO%&@Ciq*rMenPIEUG@zj_J)z&g$ew&>%|7C zte7OfG6(vLh<@DedEhZ2b(xYhI^T5QXR_pjzk{B*EBl7~Xsu&k={Xd;082v?++MV^ zeM`kC_66(}n$XPgaB1mrxqxCNu$1$ZU-~#mBvT$HNf*-9sim*^O9kg?Zuxl>IY|$M zS5>Q`rkXZr#}Z76Ou4&1P?-}?tK2#2n7UQMG?pw#W-z8qrM!A@EkLx-pzt{;AJFOW zQT#ld+g13;9Sack-606H6P4Yo#>FjiGg-?BhVY9nW4$@t!Sc4CCId+}7#pVC2t65V z;1Oc)%`m;48oiAbu6LtNigu>K9rPt3L07>9xycyl2h*kIXpd8Sc-tD6$%3l)ED}=9 z(^AkU%N#3U%v`-0Mv{@mC}U{}j_+4`f+lh`{hj7NHDa(orJk!bg2_|}9Y(M9ljPKE zF3w~6Ca=9cDFEB~1-rhc_To56>I@qj=PPxUD6)(phJbbzp`QJ3~}P zBcUgXHA0!B&mPB-RHV#KdnT=S`0B=AiJy~rd@bXc6Z?i`h#nye494++9pjFD_9x?6 z<97p(IBRsO`{+fsul>Z38+i*yxCmeLgWj#0$4Zj7^LNYx zu9!O9{+j7eO6Ic$I0Ot>qA&hvvXm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(Jarh0$S@MisTL~J|r?8o% zNLTyP6fnVU0JE8M_T)6Zm29>HB=H&cqHyj_&|K;eFwu?+>;wTkIHix^SOzxuOO{C3 zor_lgesB?h*T~MYNJuqb`YP|h<7zM*uMee7yKS^AVAP}tLJPr^`c%Bs{kWzoIUQym zt Date: Fri, 8 Aug 2025 00:32:30 -0400 Subject: [PATCH 09/13] Removed default color for affine background and changed to load palette from image instead --- include/affine_background.h | 2 +- source/affine_background.c | 9 ++++++--- source/game.c | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/affine_background.h b/include/affine_background.h index 12865d8..bb98067 100644 --- a/include/affine_background.h +++ b/include/affine_background.h @@ -7,10 +7,10 @@ #define AFFINE_BG_PAL_LEN 5 #define AFFINE_BG_PB (PAL_ROW_LEN * 15) // This isn't really a palette bank, just the starting index of the palette -#define AFFINE_BG_DEFAULT_COLOR RGB15(11, 18, 15) // 0x3E4B void affine_background_init(); void affine_background_update(); void affine_background_set_color(COLOR color); +void affine_background_load_palette(const void *src); #endif // AFFINE_BACKGROUND_H \ No newline at end of file diff --git a/source/affine_background.c b/source/affine_background.c index fd4a718..66ddb3f 100644 --- a/source/affine_background.c +++ b/source/affine_background.c @@ -10,11 +10,9 @@ void affine_background_init() { memcpy16_tile8_with_palette_offset(&tile8_mem[AFFINE_BG_CBB], affine_background_gfxTiles, affine_background_gfxTilesLen/2, AFFINE_BG_PB); GRIT_CPY(&se_mem[AFFINE_BG_SBB], affine_background_gfxMap); - memcpy16(&pal_bg_mem[AFFINE_BG_PB], affine_background_gfxPal, AFFINE_BG_PAL_LEN); + affine_background_load_palette(affine_background_gfxPal); bgaff = bg_aff_default; - - affine_background_set_color(AFFINE_BG_DEFAULT_COLOR); } void affine_background_update() @@ -40,4 +38,9 @@ void affine_background_set_color(COLOR color) { clr_rgbscale(&pal_bg_mem[AFFINE_BG_PB] + i, &pal_bg_mem[AFFINE_BG_PB] + i, 1, color); } +} + +void affine_background_load_palette(const void *src) +{ + memcpy16(&pal_bg_mem[AFFINE_BG_PB], src, AFFINE_BG_PAL_LEN); } \ No newline at end of file diff --git a/source/game.c b/source/game.c index f14c4ae..05f7a94 100644 --- a/source/game.c +++ b/source/game.c @@ -1994,7 +1994,7 @@ void game_round_end() tte_erase_rect_wrapper(BLIND_REWARD_RECT); tte_erase_rect_wrapper(BLIND_REQ_TEXT_RECT); obj_hide(playing_blind_token->obj); - affine_background_set_color(AFFINE_BG_DEFAULT_COLOR); + affine_background_load_palette(affine_background_gfxPal); state = 5; timer = 0; } From ecbfd97de175c55e0c3af3d8452bbbd03580ffa4 Mon Sep 17 00:00:00 2001 From: MeirGavish Date: Fri, 8 Aug 2025 14:47:45 +0300 Subject: [PATCH 10/13] Added some documentation to memcpy16_tile8_with_palette_offset() --- include/graphic_utils.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/graphic_utils.h b/include/graphic_utils.h index 695c388..8160d81 100644 --- a/include/graphic_utils.h +++ b/include/graphic_utils.h @@ -122,7 +122,11 @@ void update_text_rect_to_right_align_num(Rect* rect, int num, int overflow_direc /*Copies 16 bit data from src to dst, applying a palette offset to the data. * This is intended solely for use with tile8/8bpp data for dst and src. + * The palette offset allows the tiles to use a different location in the palette + * memory + * This is useful because grit always loads the palette to the beginning of + * pal_bg_mem[] */ void memcpy16_tile8_with_palette_offset(void* dst, const void* src, uint hwcount, u8 palette_offset); -#endif //GRAPHIC_UTILS_H \ No newline at end of file +#endif //GRAPHIC_UTILS_H From 31ba1f166ca29d9888ac102a217e91c1bb3ebab5 Mon Sep 17 00:00:00 2001 From: MeirGavish Date: Fri, 8 Aug 2025 15:03:18 +0300 Subject: [PATCH 11/13] Added some documentation for affine_background_load_palette() --- include/affine_background.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/affine_background.h b/include/affine_background.h index bb98067..1b9ca4e 100644 --- a/include/affine_background.h +++ b/include/affine_background.h @@ -11,6 +11,7 @@ void affine_background_init(); 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 void affine_background_load_palette(const void *src); -#endif // AFFINE_BACKGROUND_H \ No newline at end of file +#endif // AFFINE_BACKGROUND_H From 650c09af287ee6bacc9c53681bf83051350eedc8 Mon Sep 17 00:00:00 2001 From: cellos51 Date: Fri, 8 Aug 2025 09:54:24 -0400 Subject: [PATCH 12/13] Converted void to u16 in functions --- include/affine_background.h | 2 +- include/graphic_utils.h | 2 +- source/affine_background.c | 4 ++-- source/graphic_utils.c | 7 ++----- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/include/affine_background.h b/include/affine_background.h index 1b9ca4e..8e5f78f 100644 --- a/include/affine_background.h +++ b/include/affine_background.h @@ -12,6 +12,6 @@ void affine_background_init(); 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 -void affine_background_load_palette(const void *src); +void affine_background_load_palette(const u16 *src); #endif // AFFINE_BACKGROUND_H diff --git a/include/graphic_utils.h b/include/graphic_utils.h index 8160d81..79e0c61 100644 --- a/include/graphic_utils.h +++ b/include/graphic_utils.h @@ -127,6 +127,6 @@ void update_text_rect_to_right_align_num(Rect* rect, int num, int overflow_direc * This is useful because grit always loads the palette to the beginning of * pal_bg_mem[] */ -void memcpy16_tile8_with_palette_offset(void* dst, const void* src, uint hwcount, u8 palette_offset); +void memcpy16_tile8_with_palette_offset(u16* dst, const u16* src, uint hwcount, u8 palette_offset); #endif //GRAPHIC_UTILS_H diff --git a/source/affine_background.c b/source/affine_background.c index 66ddb3f..08ab9ee 100644 --- a/source/affine_background.c +++ b/source/affine_background.c @@ -8,7 +8,7 @@ AFF_SRC_EX asx = {32<<8, 64<<8, 120, 80, 0x0100, 0x0100, 0}; void affine_background_init() { - memcpy16_tile8_with_palette_offset(&tile8_mem[AFFINE_BG_CBB], affine_background_gfxTiles, affine_background_gfxTilesLen/2, AFFINE_BG_PB); + memcpy16_tile8_with_palette_offset((u16*)tile8_mem[AFFINE_BG_CBB], (const u16*)affine_background_gfxTiles, affine_background_gfxTilesLen/2, AFFINE_BG_PB); GRIT_CPY(&se_mem[AFFINE_BG_SBB], affine_background_gfxMap); affine_background_load_palette(affine_background_gfxPal); @@ -40,7 +40,7 @@ void affine_background_set_color(COLOR color) } } -void affine_background_load_palette(const void *src) +void affine_background_load_palette(const u16 *src) { memcpy16(&pal_bg_mem[AFFINE_BG_PB], src, AFFINE_BG_PAL_LEN); } \ No newline at end of file diff --git a/source/graphic_utils.c b/source/graphic_utils.c index 890cb33..931f674 100644 --- a/source/graphic_utils.c +++ b/source/graphic_utils.c @@ -168,14 +168,11 @@ void update_text_rect_to_right_align_num(Rect* rect, int num, int overflow_direc } } -void memcpy16_tile8_with_palette_offset(void* dst, const void* src, uint hwcount, u8 palette_offset) +void memcpy16_tile8_with_palette_offset(u16* dst, const u16* src, uint hwcount, u8 palette_offset) { - u16* dst16 = (u16*)dst; - const u16* src16 = (const u16*)src; - for (int i = 0; i < hwcount; i++) { // Copying u8 data twice across u16 data - dst16[i] = src16[i] + (((palette_offset) << 8) | (palette_offset)); + dst[i] = src[i] + (((palette_offset) << 8) | (palette_offset)); } } \ No newline at end of file From 6363613f15d125f9997687ebb0bbc59bf4b59db7 Mon Sep 17 00:00:00 2001 From: cellos51 Date: Fri, 8 Aug 2025 10:44:55 -0400 Subject: [PATCH 13/13] Added & back to the tile8_mem in affine_background_init() and changed memcpy16 to 32 --- include/graphic_utils.h | 9 +++++++++ source/affine_background.c | 2 +- source/graphic_utils.c | 13 ++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/graphic_utils.h b/include/graphic_utils.h index 79e0c61..8f75cf3 100644 --- a/include/graphic_utils.h +++ b/include/graphic_utils.h @@ -129,4 +129,13 @@ void update_text_rect_to_right_align_num(Rect* rect, int num, int overflow_direc */ void memcpy16_tile8_with_palette_offset(u16* dst, const u16* src, uint hwcount, u8 palette_offset); +/*Copies 32 bit data from src to dst, applying a palette offset to the data. + * This is intended solely for use with tile8/8bpp data for dst and src. + * The palette offset allows the tiles to use a different location in the palette + * memory + * This is useful because grit always loads the palette to the beginning of + * pal_bg_mem[] + */ +void memcpy32_tile8_with_palette_offset(u32* dst, const u32* src, uint hwcount, u8 palette_offset); + #endif //GRAPHIC_UTILS_H diff --git a/source/affine_background.c b/source/affine_background.c index 08ab9ee..f9e15e7 100644 --- a/source/affine_background.c +++ b/source/affine_background.c @@ -8,7 +8,7 @@ AFF_SRC_EX asx = {32<<8, 64<<8, 120, 80, 0x0100, 0x0100, 0}; void affine_background_init() { - memcpy16_tile8_with_palette_offset((u16*)tile8_mem[AFFINE_BG_CBB], (const u16*)affine_background_gfxTiles, affine_background_gfxTilesLen/2, AFFINE_BG_PB); + 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); affine_background_load_palette(affine_background_gfxPal); diff --git a/source/graphic_utils.c b/source/graphic_utils.c index 931f674..1d5bcb2 100644 --- a/source/graphic_utils.c +++ b/source/graphic_utils.c @@ -170,9 +170,20 @@ void update_text_rect_to_right_align_num(Rect* rect, int num, int overflow_direc void memcpy16_tile8_with_palette_offset(u16* dst, const u16* src, uint hwcount, u8 palette_offset) { + const u16 offset = (((palette_offset) << 8) | (palette_offset)); for (int i = 0; i < hwcount; i++) { // Copying u8 data twice across u16 data - dst[i] = src[i] + (((palette_offset) << 8) | (palette_offset)); + dst[i] = src[i] + offset; + } +} + +void memcpy32_tile8_with_palette_offset(u32* dst, const u32* src, uint hwcount, u8 palette_offset) +{ + const u32 offset = (palette_offset << 24) | (palette_offset << 16) | (palette_offset << 8) | palette_offset; + for (int i = 0; i < hwcount; i++) + { + // Copying u8 data 4 times across u32 data + dst[i] = src[i] + offset; } } \ No newline at end of file