diff --git a/.github/workflows/build_ci_workflow.yml b/.github/workflows/build_ci_workflow.yml index f2285d2..cb28935 100644 --- a/.github/workflows/build_ci_workflow.yml +++ b/.github/workflows/build_ci_workflow.yml @@ -67,7 +67,11 @@ jobs: echo "GID=$(id -g)" >> "$GITHUB_ENV" - name: Build the project - run: docker compose -f docker-compose.yml run --rm gbalatro sh -c "make -j$(nproc) && ./scripts/get_memory_map.sh" + run: | + docker compose -f docker-compose.yml run --rm \ + -e PATH=/opt/devkitpro/devkitARM/bin:/opt/devkitpro/tools/bin:$PATH \ + gbalatro \ + sh -c "make -j\$(nproc) && ./scripts/get_memory_map.sh build/balatro-gba.elf" - name: 'Upload Artifact' if: ${{ inputs.upload-build-artifact }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 74d65bd..39fadbe 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -138,7 +138,13 @@ In the repo we use custom scripts located in the [`scripts`](https://github.com/ - **get_hash.py**: Get git hash from ROM. - **generate_font.py**: Generate a font manually. - **get_memory_map.sh**: Print the memory map of the pre-allocated pools. -- **save_build.sh**: Save a timestamped copy of build outputs (.elf, .gba, .map). +- **save_build.sh**: Save a timestamped copy of build outputs (`.elf`, `.gba`, `.map`). + # Minimal usage + ./scripts/save_build.sh build/balatro-gba.gba + + # With optional build label + ./scripts/save_build.sh build/balatro-gba.gba my-feature + ``` ## Debugging It's recommended to use [mGBA](https://mgba.io/) for ROM testing and debugging. As it provides a [`gdbserver`](https://en.wikipedia.org/wiki/Gdbserver) via the `-g` flag `mgba -g build/balatro-gba.gba`. You can connect via `gdb` or here is a [great guide for vscode](https://felixjones.co.uk/mgba_gdb/vscode.html). diff --git a/scripts/get_memory_map.sh b/scripts/get_memory_map.sh index ad3e349..6b3cb6c 100755 --- a/scripts/get_memory_map.sh +++ b/scripts/get_memory_map.sh @@ -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") [pool-def-file]" + echo " 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= $(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= $(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) " - 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" diff --git a/scripts/save_build.sh b/scripts/save_build.sh index 06b51f0..39a797a 100755 --- a/scripts/save_build.sh +++ b/scripts/save_build.sh @@ -5,21 +5,41 @@ set -e +usage() { + echo "Usage: $(basename "$0") [build-label]" + echo " 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 -