diff --git a/include/card.h b/include/card.h index 63f4ea7..ee02419 100644 --- a/include/card.h +++ b/include/card.h @@ -72,4 +72,4 @@ void card_object_set_selected(CardObject* card_object, bool selected); bool card_object_is_selected(CardObject* card_object); Sprite* card_object_get_sprite(CardObject* card_object); -#endif // CARD_H +#endif // CARD_H \ No newline at end of file diff --git a/scripts/get_memory_map.sh b/scripts/get_memory_map.sh index c685022..6b0f03a 100755 --- a/scripts/get_memory_map.sh +++ b/scripts/get_memory_map.sh @@ -1,20 +1,29 @@ #!/usr/bin/env bash +set -euo pipefail + POOL_DEF_FILE='./include/pools.def' -ELF_FILE='./build/balatro.elf' +ELF_FILE="${1-./build/balatro-gba.elf}" READELF='/opt/devkitpro/devkitARM/bin/arm-none-eabi-readelf' TOTAL_BYTES=0 -get_pool_names() { - grep POOL_ENTRY "$POOL_DEF_FILE" | sed -n 's@.*(\(.*\)).*@\1@p' | sed 's@,@@g' | cut -d ' ' -f 1 -} +if [ ! -f "$ELF_FILE" ]; then + echo "elf file not found: $ELF_FILE" + echo "You can pass your elf file with:" + echo " $(basename $0) " + exit 1 +fi print_line_break() { echo "--------------------------------------------------------------------" } +get_pool_names() { + grep POOL_ENTRY "$POOL_DEF_FILE" | sed -n 's@.*(\(.*\)).*@\1@p' | sed 's@,@@g' | cut -d ' ' -f 1 +} + print_line_break -printf "%-16s| %-10s | %-10s | %-10s | %-10s \n" "Object" "location" "pool size" "func size" "bitmap size" +printf "%-16s| %-10s | %-10s | %-10s | %-10s \n" "Object" "address" "pool size" "func size" "bitmap size" print_line_break for name in $(get_pool_names); do @@ -34,14 +43,14 @@ for name in $(get_pool_names); do )" - location="$(cut -d ' ' -f 2 <<< $output_pool)" + address="$(cut -d ' ' -f 2 <<< $output_pool)" pool_size="$(cut -d ' ' -f 3 <<< $output_pool)" func_size="$(cut -d ' ' -f 3 <<< $output_func)" bm_size=16 #always gonna be 16, 4 * sizeof(u32) TOTAL_BYTES=$(( TOTAL_BYTES + pool_size + func_size + bm_size )) - printf "%-16s| 0x%8s | %-10u | %-10u | %-10u \n" "$name" "$location" "$pool_size" "$func_size" "$bm_size" + printf "%-16s| 0x%8s | %-10u | %-10u | %-10u \n" "$name" "$address" "$pool_size" "$func_size" "$bm_size" done print_line_break diff --git a/source/joker.c b/source/joker.c index e9447f1..63b71bd 100644 --- a/source/joker.c +++ b/source/joker.c @@ -50,7 +50,7 @@ static bool used_layers[MAX_JOKER_OBJECTS] = {false}; // Track used layers for j // Maps the spritesheet index to the palette bank index allocated to it. // Spritesheets that were not allocated are -static int joker_spritesheet_pb_map[128]; +static int joker_spritesheet_pb_map[MAX_SPRITES]; static int joker_pb_num_sprite_users[JOKER_LAST_PB - JOKER_BASE_PB + 1] = { 0 }; static int get_num_spritesheets() diff --git a/source/pool.c b/source/pool.c index e2f150e..363b715 100644 --- a/source/pool.c +++ b/source/pool.c @@ -5,7 +5,7 @@ void pool_bm_clear_idx(PoolBitmap *bm, int idx) // Divide by 32 to get the word index u32 i = idx >> 5; // Get last 5-bits, same as a modulo (% 32) operation on positive numbers - u32 b = idx & 31; + u32 b = idx & 0x1F; bm->w[i] &= ~((u32)1 << b); } @@ -15,7 +15,7 @@ int pool_bm_get_free_idx(PoolBitmap *bm) { u32 inv = ~bm->w[i]; - // guard so we don't cal `ctz` with 0, since __builtin_ctz(0) is undefined + // guard so we don't call `ctz` with 0, since __builtin_ctz(0) is undefined // https://gcc.gnu.org/onlinedocs/gcc/Bit-Operation-Builtins.html#index-_005f_005fbuiltin_005fctz // // By using the bitwise inverse of the word, you can skip words that are full @@ -38,6 +38,5 @@ int pool_bm_get_free_idx(PoolBitmap *bm) #define POOL_ENTRY(name, capacity) \ POOL_DEFINE_TYPE(name, capacity); -#include "sprite.h" #include "pools.def" #undef POOL_ENTRY