Centralize location of memory pools
This commit centralizes the location of memory pools and adds an associated script (scripts/get_memory_map.sh) to read the memory map.
This commit is contained in:
+4
-1
@@ -6,6 +6,9 @@
|
||||
|
||||
#include "sprite.h"
|
||||
|
||||
#define MAX_CARDS (NUM_SUITS * NUM_RANKS)
|
||||
#define MAX_CARDS_ON_SCREEN 16
|
||||
|
||||
#define CARD_TID 0
|
||||
#define CARD_SPRITE_OFFSET 16
|
||||
#define CARD_PB 0
|
||||
@@ -69,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
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
#include "game.h"
|
||||
#include "graphic_utils.h"
|
||||
|
||||
// This won't be more than the number of jokers in your current deck
|
||||
// plus the amount that can fit in the shop, 8 should be fine. For now...
|
||||
#define MAX_ACTIVE_JOKERS 8
|
||||
|
||||
#define JOKER_TID (MAX_HAND_SIZE + MAX_SELECTION_SIZE) * JOKER_SPRITE_OFFSET // Tile ID for the starting index in the tile memory
|
||||
#define JOKER_SPRITE_OFFSET 16 // Offset for the joker sprites
|
||||
#define JOKER_BASE_PB 4 // The starting palette index for the jokers
|
||||
|
||||
+15
-10
@@ -22,8 +22,8 @@ int pool_bm_get_free_idx(PoolBitmap *bm);
|
||||
type * objects; \
|
||||
u32 max_entries; \
|
||||
} type##Pool; \
|
||||
type *pool_get_##type(type##Pool* pool); \
|
||||
void pool_free_##type(type##Pool *pool, type *obj); \
|
||||
type *pool_get_##type(); \
|
||||
void pool_free_##type(type *obj); \
|
||||
void pool_init_##type(type##Pool *pool);
|
||||
|
||||
#define POOL_DEFINE_TYPE(type, capacity) \
|
||||
@@ -38,20 +38,25 @@ int pool_bm_get_free_idx(PoolBitmap *bm);
|
||||
.objects = type##_storage, \
|
||||
.max_entries = capacity, \
|
||||
}; \
|
||||
type * pool_get_##type(type##Pool *pool) \
|
||||
type * pool_get_##type() \
|
||||
{ \
|
||||
int free_offset = pool_bm_get_free_idx(&pool->bm); \
|
||||
int free_offset = pool_bm_get_free_idx(&type##_pool.bm); \
|
||||
if(free_offset == -1) return NULL; \
|
||||
return &pool->objects[free_offset]; \
|
||||
return &type##_pool.objects[free_offset]; \
|
||||
} \
|
||||
void pool_free_##type(type##Pool *pool, type *entry) \
|
||||
void pool_free_##type(type *entry) \
|
||||
{ \
|
||||
if(entry == NULL) return; \
|
||||
int offset = entry - &pool->objects[0]; \
|
||||
pool_bm_clear_idx(&pool->bm, offset); \
|
||||
int offset = entry - &type##_pool.objects[0]; \
|
||||
pool_bm_clear_idx(&type##_pool.bm, offset); \
|
||||
}
|
||||
|
||||
#define POOL_GET(type) pool_get_##type(&type##_pool)
|
||||
#define POOL_FREE(type, obj) pool_free_##type(&type##_pool, obj)
|
||||
#define POOL_GET(type) pool_get_##type()
|
||||
#define POOL_FREE(type, obj) pool_free_##type(obj)
|
||||
|
||||
#define POOL_ENTRY(name, capacity) \
|
||||
POOL_DECLARE_TYPE(name);
|
||||
#include "pools.def"
|
||||
#undef POOL_ENTRY
|
||||
|
||||
#endif // POOL_H
|
||||
|
||||
+4
-1
@@ -5,6 +5,9 @@
|
||||
#include <maxmod.h>
|
||||
|
||||
#define CARD_SPRITE_SIZE 32
|
||||
#define MAX_SPRITES 128
|
||||
#define MAX_SPRITE_OBJECTS 16
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -63,4 +66,4 @@ Sprite* sprite_object_get_sprite(SpriteObject* sprite_object);
|
||||
void sprite_object_set_focus(SpriteObject* sprite_object, bool focus);
|
||||
bool sprite_object_is_focused(SpriteObject* sprite_object);
|
||||
|
||||
#endif // SPRITE_H
|
||||
#endif // SPRITE_H
|
||||
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Run this from the root directory of the project, not the scripts directory
|
||||
POOL_DEF_FILE='./include/pools.def'
|
||||
ELF_FILE='./build/balatro-gba.elf'
|
||||
READELF='/opt/devkitpro/devkitARM/bin/arm-none-eabi-readelf'
|
||||
|
||||
get_pool_names() {
|
||||
grep POOL_ENTRY "$POOL_DEF_FILE" | sed -n 's@.*(\(.*\)).*@\1@p' | sed 's@,@@g' | cut -d ' ' -f 1
|
||||
}
|
||||
|
||||
TOTAL_BYTES=0
|
||||
|
||||
echo "--------------------------------------------"
|
||||
printf "%-16s| %-10s | %s\n" "Object" "location" "size"
|
||||
echo "--------------------------------------------"
|
||||
|
||||
for name in $(get_pool_names); do
|
||||
output="$( \
|
||||
"$READELF" -sW "$ELF_FILE" | \
|
||||
grep "${name}_" | \
|
||||
grep OBJECT | \
|
||||
grep storage | sed -E 's@ +@ @g; s@^ @@' \
|
||||
)"
|
||||
|
||||
location="$(cut -d ' ' -f 2 <<< $output)"
|
||||
size="$(cut -d ' ' -f 3 <<< $output)"
|
||||
TOTAL_BYTES=$(( TOTAL_BYTES + size ))
|
||||
|
||||
printf "%-16s| 0x%s | %-8u\n" "$name" "$location" "$size"
|
||||
done
|
||||
|
||||
echo "--------------------------------------------"
|
||||
echo Total bytes used: $TOTAL_BYTES
|
||||
@@ -11,14 +11,6 @@
|
||||
|
||||
#include "pool.h"
|
||||
|
||||
#define MAX_CARDS_PER_HAND (NUM_SUITS * NUM_RANKS)
|
||||
#define MAX_CARDS_ON_SCREEN 16
|
||||
|
||||
POOL_DECLARE_TYPE(Card);
|
||||
POOL_DEFINE_TYPE(Card, MAX_CARDS_PER_HAND);
|
||||
POOL_DECLARE_TYPE(CardObject);
|
||||
POOL_DEFINE_TYPE(CardObject, MAX_CARDS_ON_SCREEN);
|
||||
|
||||
// Card sprites lookup table. First index is the suit, second index is the rank. The value is the tile index.
|
||||
const static u16 card_sprite_lut[NUM_SUITS][NUM_RANKS] = {
|
||||
{0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192},
|
||||
|
||||
@@ -29,15 +29,6 @@ static const unsigned short *joker_gfxPal[] =
|
||||
#undef DEF_JOKER_GFX
|
||||
};
|
||||
|
||||
// This won't be more than the number of jokers in your current deck
|
||||
// plus the amount that can fit in the shop, 8 should be fine. For now...
|
||||
#define MAX_ACTIVE_JOKERS 8
|
||||
|
||||
POOL_DECLARE_TYPE(Joker)
|
||||
POOL_DEFINE_TYPE(Joker, MAX_ACTIVE_JOKERS)
|
||||
POOL_DECLARE_TYPE(JokerObject)
|
||||
POOL_DEFINE_TYPE(JokerObject, MAX_ACTIVE_JOKERS)
|
||||
|
||||
const static u8 edition_price_lut[MAX_EDITIONS] =
|
||||
{
|
||||
0, // BASE_EDITION
|
||||
|
||||
@@ -34,3 +34,10 @@ int pool_bm_get_free_idx(PoolBitmap *bm)
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
#define POOL_ENTRY(name, capacity) \
|
||||
POOL_DEFINE_TYPE(name, capacity);
|
||||
#include "sprite.h"
|
||||
#include "pools.def"
|
||||
#undef POOL_ENTRY
|
||||
|
||||
@@ -9,19 +9,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <maxmod.h>
|
||||
|
||||
#define MAX_SPRITES 128
|
||||
#define MAX_AFFINES 32
|
||||
#define SPRITE_FOCUS_RAISE_PX 10
|
||||
|
||||
OBJ_ATTR obj_buffer[MAX_SPRITES];
|
||||
OBJ_AFFINE *obj_aff_buffer = (OBJ_AFFINE*)obj_buffer;
|
||||
|
||||
POOL_DECLARE_TYPE(SpriteObject)
|
||||
POOL_DEFINE_TYPE(SpriteObject, MAX_SPRITES)
|
||||
|
||||
POOL_DECLARE_TYPE(Sprite)
|
||||
POOL_DEFINE_TYPE(Sprite, MAX_SPRITES)
|
||||
|
||||
static bool free_affines[MAX_AFFINES] = {false};
|
||||
|
||||
// Sprite methods
|
||||
|
||||
Reference in New Issue
Block a user