From 6363613f15d125f9997687ebb0bbc59bf4b59db7 Mon Sep 17 00:00:00 2001 From: cellos51 Date: Fri, 8 Aug 2025 10:44:55 -0400 Subject: [PATCH] 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