From 5a4856ec82e40bb9289a153f7fb3e9e4a7016c38 Mon Sep 17 00:00:00 2001 From: MeirGavish Date: Thu, 11 Dec 2025 03:13:59 +0200 Subject: [PATCH] Refactor - removed tile_mem obj charblock index magic number (#293) --- include/graphic_utils.h | 6 ++++++ source/blind.c | 8 ++++++-- source/card.c | 2 +- source/joker.c | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/graphic_utils.h b/include/graphic_utils.h index c1a6e88..6571774 100644 --- a/include/graphic_utils.h +++ b/include/graphic_utils.h @@ -58,6 +58,12 @@ */ #define TILE_SIZE 8 +/** + * @def TILE_MEM_OBJ_CHARBLOCK0_IDX + * @brief The index for the first charblock of the object memory in tonc's tile_mem + */ +#define TILE_MEM_OBJ_CHARBLOCK0_IDX 4 + /** @} */ /** diff --git a/source/blind.c b/source/blind.c index 024fa09..b2fdffe 100644 --- a/source/blind.c +++ b/source/blind.c @@ -107,8 +107,12 @@ static void s_blind_gfx_init(enum BlindType type) { // TODO: Re-add grit copy. You need to decouple the blind graphics first. // This will allow this function to change the boss graphics info - // GRIT_CPY(&tile_mem[4][_blind_type_map[type].pal_info.tid], tiles); + // GRIT_CPY(&tile_mem[TILE_MEM_OBJ_CHARBLOCK0_IDX][_blind_type_map[type].pal_info.tid], tiles); BlindGfxInfo* p_gfx = &_blind_type_map[type].gfx_info; - memcpy32(&tile_mem[4][p_gfx->tid], p_gfx->tiles, BLIND_SPRITE_COPY_SIZE); + memcpy32( + &tile_mem[TILE_MEM_OBJ_CHARBLOCK0_IDX][p_gfx->tid], + p_gfx->tiles, + BLIND_SPRITE_COPY_SIZE + ); memcpy16(&pal_obj_bank[p_gfx->pb], p_gfx->palette, PAL_ROW_LEN); } diff --git a/source/card.c b/source/card.c index cbfc2d6..b7c91da 100644 --- a/source/card.c +++ b/source/card.c @@ -90,7 +90,7 @@ void card_object_set_sprite(CardObject* card_object, int layer) { int tile_index = CARD_TID + (layer * CARD_SPRITE_OFFSET); memcpy32( - &tile_mem[4][tile_index], + &tile_mem[TILE_MEM_OBJ_CHARBLOCK0_IDX][tile_index], &deck_gfxTiles [_card_sprite_lut[card_object->card->suit][card_object->card->rank] * TILE_SIZE], TILE_SIZE * CARD_SPRITE_OFFSET diff --git a/source/joker.c b/source/joker.c index fbc8cbf..1abd115 100644 --- a/source/joker.c +++ b/source/joker.c @@ -150,7 +150,7 @@ JokerObject* joker_object_new(Joker* joker) s_joker_pb_add_sprite_user(joker_pb); memcpy32( - &tile_mem[4][tile_index], + &tile_mem[TILE_MEM_OBJ_CHARBLOCK0_IDX][tile_index], &joker_gfxTiles[joker_spritesheet_idx][joker_idx * TILE_SIZE * JOKER_SPRITE_OFFSET], TILE_SIZE * JOKER_SPRITE_OFFSET );