How gbalatro/balatro-gba works
1. What this repo is
- A self-contained Game Boy Advance homebrew ROM: a demake of Balatro.
- There is no backend, network layer, or persistent service dependency; the whole app runs on the GBA runtime and local assets.
2. Build and delivery boundary
- The project is built with make using the devkitPro/devkitARM toolchain, with Docker and GitHub Actions used to standardize builds.
- The final artifact is a .gba ROM in build/.
- CI also runs formatting, unit tests, and Doxygen docs, and there are release workflows for tagged/nightly builds.
3. Program entry and top-level control
- source/main.c is the entrypoint.
- The runtime is organized as a game loop/state-machine architecture centered around game.c and include/game.h, with state metadata in def_state_info_table.h.
- splash_screen.c handles startup before the main game flow.
4. Core game domain
- The gameplay model is split into focused domain modules:
- card.c for playing cards and card state
- blind.c for round/blind progression
- joker.c and joker_effects.c for joker inventory and effect resolution
- hand_analysis.c for evaluating poker hands and scoring logic
- game_variables.h and related headers for global game state/configuration
- This is the main simulation layer that drives round/shop progression and score calculation.
5. Input and selection/UI flow
- Player input comes from GBA buttons and is handled through UI-oriented modules rather than a generic event system.
- button.c abstracts button behavior, while selection_grid.c and include/selection_grid.h manage focus, cursor movement, and selection across cards/jokers/menu items.
- source/game/common_ui.c and its header provide shared UI behavior used across shop/round screens.
- The README’s controls map directly onto these modules: D-pad navigation, A/B selection, L/R actions, and hold-A swap behavior.
6. Rendering pipeline
- Rendering is split into reusable graphics primitives and screen-specific assets:
- sprite.c, graphic_utils.c, and affine_background.c provide low-level drawing helpers
- font.c manages text rendering
- Backgrounds and cards/jokers are stored as preprocessed assets under graphics/
- The .grit files indicate assets are converted into GBA-friendly sprite/tile data during the build.
- def_joker_gfx_table.h and joker_gfx.h suggest table-driven mapping from joker IDs to art assets.
7. Audio subsystem
- audio_utils.c is the audio runtime boundary.
- Audio assets live in audio/ and include short WAV effects plus the main_theme.xm tracker music.
- Sound effects and music are treated as local ROM assets, likely streamed or played through the GBA audio hardware via helper code rather than an external middleware stack.
8. Shared utilities and data structures
- The repo includes custom low-level utilities instead of relying on libc-heavy abstractions:
- bitset.c / bitset.h
- list.c / list.h
- pool.c / pool.h
- util.c
- def_balatro_mempool.h and the test-specific mempool headers indicate a custom fixed-memory allocation strategy, which is important on GBA hardware with tight RAM limits.
9. Game object composition
- Game entities are structured around reusable types in headers such as card.h, joker.h, blind.h, button.h, and sprite.h.
- These are likely composed by the higher-level game state rather than managed by a heavyweight engine.
- The architecture is object-like in C, but still hardware-oriented and memory-conscious.
10. Asset and code generation pipeline
- scripts/generate_font.py suggests font assets are generated rather than hand-authored.
- scripts/get_hash.py, scripts/get_memory_map.sh, and scripts/save_build.sh support build metadata, reproducibility, and artifact handling.
- The graphics/ and audio/ folders are source assets; the build transforms them into ROM-ready data.
11. Tests and quality boundaries
- Tests are separate, small, module-level executables under tests/.
- Current coverage focuses on foundational utilities: bitset, list, pool, and util.
- That matches the repo’s architecture: verify core data structures independently of the full GBA runtime.
12. Documentation and developer tooling
- Doxygen is a first-class part of the repo, with custom styling under doxygen/ and an automated doc deployment workflow.
- Formatting is enforced via clang-format CI.
- The repository is therefore structured to support both embedded build correctness and readable API documentation.
13. Practical diagram shape
- A good architecture diagram would show:
- Input: GBA buttons
- Game logic: state machine in game.c, domain rules in card/joker/blind/hand-analysis modules
- UI/rendering: selection grid, common UI, sprites, backgrounds, font
- Audio: effect/music playback helpers
- Assets: compiled graphics/audio/font data feeding render/audio subsystems
- Support systems: pools/lists/bitsets/utilities underneath game logic
- Build/test/docs: Makefile, Docker, CI, unit tests, Doxygen as external development infrastructure
Main entry points: game.c Game Loop · main.c Main · joker.c Jokers · run_tests.sh Unit Tests
Components 19
Game Runtime
GBA entrypoint, state machine, core gameplay, input, UI, and rendering.
- Main · ROM entry and startup handoff into the game flow.
source/main.c - Game Loop · Top-level runtime control and state transitions.
source/game.c - State Table · Maps game states to their handlers and metadata.
include/def_state_info_table.h - Splash Screen · Startup presentation before entering the main game loop.
source/splash_screen.c - Button Input · Button behavior and action handling for GBA controls.
source/button.c - Selection Grid · Focus, movement, and selection across cards and menu items.
source/selection_grid.c - Common UI · Reusable UI behavior shared across shop and round screens.
source/game/common_ui.c - Cards · Playing card state and card-level behavior.
source/card.c - Blinds · Round and blind progression logic.
source/blind.c - Jokers · Joker collection and joker state management.
source/joker.c - Joker Effects · Resolves joker-triggered effects during scoring and play.
source/joker_effects.c - Hand Analysis · Evaluates poker hands and computes score logic.
source/hand_analysis.c
Assets
Source art, audio, and generated font data packed into the ROM.
Core Support
Shared utilities and memory structures used by the simulation and UI.
- Utilities · Bitsets, lists, pools, and utility helpers for memory-conscious code.
source/util.c
Build & Quality
Build, CI, tests, docs, and release automation around the ROM.
- Build System · Make/Docker-based ROM build and release packaging.
Makefile - Unit Tests · Module-level tests for core data structures and utilities.
tests/run_tests.sh - CI & Docs · GitHub Actions, clang-format, Doxygen, and release workflows.
.github/workflows/build_ci_workflow.yml
Connections 18
- Main → Game Loop: starts · Program entry hands off to the main runtime.
- Main → Splash Screen: shows · Startup flow enters the splash screen before gameplay.
- Game Loop → State Table: uses · State machine consults state metadata for dispatch.
- Game Loop → Button Input: reads · Main loop consumes button actions.
- Game Loop → Selection Grid: drives · Gameplay UI uses cursor and focus navigation.
- Game Loop → Common UI: shares · Screens reuse common UI behaviors.
- Game Loop → Cards: updates · Game flow mutates card state during play.
- Game Loop → Blinds: advances · Round progression is controlled through blind logic.
- Game Loop → Jokers: manages · Game state owns joker inventory.
- Jokers → Joker Effects: triggers · Joker inventory feeds effect resolution.
- Game Loop → Hand Analysis: scores · Scoring and hand evaluation drive outcomes.
- Game Loop → Graphics: renders · Gameplay and UI draw through the graphics helpers.
- Game Loop → Font: prints · Screens render text via the font subsystem.
- Game Loop → Audio: plays · Events trigger effects and music playback.
- Game Loop → Utilities: depends on · Core runtime relies on shared low-level utilities.
- Build System → CI & Docs: automates · Build tooling is exercised and packaged by CI and docs workflows.
- Unit Tests → Utilities: verifies · Tests cover foundational utility modules.
- CI & Docs → Unit Tests: runs · CI includes unit testing as part of quality checks.