Scripts Take Rom as Arg (#512)

* initial

* suggestions for get_memory_map.sh

* CONTRIBUTING.md suggestions

* save_build.sh suggestions

* rerun

* env variable

* add to env

* print usage and remove redundant qoutes
This commit is contained in:
Elliot Tester
2026-06-11 06:23:47 +02:00
committed by GitHub
parent 4cbdd6c004
commit 35c7a29cc5
4 changed files with 60 additions and 25 deletions
+23 -17
View File
@@ -2,30 +2,36 @@
set -euo pipefail
ELF_FILE="${ELF_FILE-./build/balatro-gba.elf}"
POOL_DEF_FILE="${POOL_DEF_FILE-./include/def_balatro_mempool.h}"
READELF="${READELF-/opt/devkitpro/devkitARM/bin/arm-none-eabi-readelf}"
usage() {
echo "Usage: $(basename "$0") <elf-file> [pool-def-file]"
echo " <elf-file> Path to the built .elf file (e.g. build/balatro-gba.elf)"
echo " [pool-def-file] Path to the mempool definition header"
echo " (default: ./include/def_balatro_mempool.h)"
exit 1
}
if [ $# -lt 1 ]; then
usage
fi
ELF_FILE="$1"
POOL_DEF_FILE="${2-./include/def_balatro_mempool.h}"
READELF="${READELF:-arm-none-eabi-readelf}"
TOTAL_BYTES=0
if [ ! -f "$POOL_DEF_FILE" ]; then
echo "Mempool definition file not found: $POOL_DEF_FILE"
echo "You can set your mempool definition file with:"
echo " POOL_DEF_FILE=<mempool-def-file> $(basename $0)"
exit 1
echo "Mempool definition file not found: $POOL_DEF_FILE"
usage
fi
if [ ! -f "$ELF_FILE" ]; then
echo "elf file not found: $ELF_FILE"
echo "You can set your elf file with:"
echo " ELF_FILE=<elf-file> $(basename $0)"
exit 1
echo "ELF file not found or is not a regular file: $ELF_FILE"
usage
fi
if [ ! -x "$READELF" ]; then
echo "ERROR: \"$READELF\" is not an executable file."
echo "You can override the file location for 'arm-none-eabi-readelf' with the READELF env variable."
echo " e.g. $ READELF=\"/my/custom/location/arm-none-eabi-readelf\" $(basename $0) <file>"
exit 1
if ! command -v "$READELF" >/dev/null 2>&1; then
echo "ERROR: missing tool: $READELF"
usage
fi
print_line_break() {
@@ -67,7 +73,7 @@ for name in $(get_pool_names); do
pool_size="$(cut -d ' ' -f 3 <<< $output_pool)"
func_size="$(cut -d ' ' -f 3 <<< $output_func)"
bitset_size="$(cut -d ' ' -f 3 <<< $output_bitset)"
TOTAL_BYTES=$(( TOTAL_BYTES + pool_size + func_size + bitset_size ))
printf "%-16s| 0x%8s | %-10u | %-10u | %-10u \n" "$name" "$address" "$pool_size" "$func_size" "$bitset_size"
+25 -6
View File
@@ -5,21 +5,41 @@
set -e
usage() {
echo "Usage: $(basename "$0") <rom-file> [build-label]"
echo " <rom-file> Path to the .gba ROM file (e.g. build/balatro-gba.gba)"
echo " [build-label] Optional label for the saved build directory (default: \"build\")"
exit 1
}
if [ $# -lt 1 ]; then
usage
fi
ROM_FILE="$1"
make
GAME_NAME="${GAME_NAME-balatro-gba}"
if [ ! -f "$ROM_FILE" ]; then
echo "Error: ROM file not found or is not a regular file: $ROM_FILE"
usage
fi
# Derive the game base name from the ROM file (strip directory and .gba extension)
GAME_NAME="$(basename "$ROM_FILE" .gba)"
timestamp=$(date +%Y%m%d_%H%M%S)
arg=${1:-"build"}
arg="${2:-build}"
dir="saved_builds/${arg}_${timestamp}"
mkdir -p "$dir"
failed=0
for fe in elf gba map; do
if [ -f build/"$GAME_NAME".$fe ]; then
cp build/"$GAME_NAME".$fe "$dir/"
src="$(dirname "$ROM_FILE")/${GAME_NAME}.${fe}"
if [ -f "$src" ]; then
cp "$src" "$dir/"
else
echo "Warning: build/$GAME_NAME.$fe not found"
echo "Warning: $src not found"
failed=1
fi
done
@@ -31,4 +51,3 @@ else
fi
exit $failed