Skip to Content
The Alchemy Project

Codebase Map

This page is a guide to the games/tla/src/ folder of the Alchemy project. It holds the C source, assembly routines, map grids, and graphics of Golden Sun: The Lost Age.

Inside games/tla/, the material is divided among four top-level folders. This src/ tree contains the game code, town scripts, maps, and artwork, while include/ holds shared headers, text/ carries every localised line of dialogue, and sound/ stores the MIDI songs and WAV samples.

This page serves a reader tracing a cutscene in Daila, checking a Psynergy formula, or studying how The Lost Age grew onto a 16 MB cartridge with an eight-member party. It gives a method for locating any screen in the game, a map of all 13 subfolders, and notes on how the build splits code into modules and overlays.

Finding the code for something in the game

The text is the starting point. Every line the game displays has a unique symbol that leads to the code showing it:

  1. A search of en.po for a few words of the line finds its entry, whose msgctxt gives its symbol, such as MsgFieldISawABrightLightIn.

  2. A search of games/tla/src/ for that symbol finds the scene or UI file that uses it (for example, scene/daila.c):

    {CUE_TALK, ACTOR_MAN_WHO_SAW_A_LIGHT, CONDITION_ALWAYS, MSGNO(MsgFieldISawABrightLightIn)},

The same method applies to dialogue, menus, item descriptions, and battle messages alike. Everything else is found as follows:

To findOpen
A town's NPCs, lines, and cutscenesIts overlay in src/scene/, e.g. scene/daila.c
The inside of a houseFollow the town's exit row to its rooms map, e.g. scene/champa_rooms.c
Item, ability, enemy, class, Djinni, or summon statsIts row in src/game/*_table.c
Shop inventories & Sunshine's Forge recipesshop/shop_tables.c
How a spell, unleash, or 3D summon animatesIts src/battle_effect/battle_effect_*.c file (or render_*.s for 3D kernels)
A sprite, monster, tileset, or UI pictureA PNG under src/graphics/
A song, SFX, or music rulesound, field/music_rules.s, and EncounterBattleMusic in field/battle_music.c
A map's tiles, terrain flags, heights, or itemssrc/map/<place>/ (grid_*.tsv, shape_grid.tsv, points.tsv)
Numeric IDs for flags, sounds, scenes, items, or spritesinclude: flags.h, sounds.h, scene_ids.h, item_ids.h, ability_ids.h, sprite_ids.h

Read in execution order from power-on, the game begins at syInit in system/system_start_up.c, which hands off to gmMainRoutineRun in game/main_routine.c.

Directory map

FolderDivisionOwns
system/The system libraryBoot, caller-stack sySynch(), 24-slot swapped-pass events, RamHeapSlots, system_flags.c, OAM and VRAM, matrices, overlays, 12 KB flash saving, link cable, 2,048-row resource directory, 528-sample-per-frame IWRAM mixer
game/RPG Data & RulesgmMainRoutineRun, expanded RPG data tables (516 items, 734 abilities, 380 enemies, 244 classes, 72 named Djinn, 29 summons), UNIT recalculation, 8-member party, rare counters, shared combat math
field/World, Scenes & MapsfdEngineRun (step and push before battle), carrier-rider physics, movement-mode scripts, 12 new field Psynergies, World Map and Lemurian Ship, encounters, Lucky Dice, Lucky Wheels, and Super Lucky Dice
scene/World, Scenes & Maps109 gameplay scene overlays (entry.s 7-stub table adding scPrepareMap), cues, EXIT_FLAG_NONE exits, cutscenes, Clear Data transfer, Battle Arena
map/World, Scenes & Maps301 .tsv metatile map folders (4 grids per map), height shapes, anchor points, tileset animations, blends
battle/Battle & EffectsbtRun, 660 formations, 8-member Switch and reserve swap-in, two-phase and multi-action enemy AI, action building, staging, and resolution, playback queue, zoomed backgrounds, spoils, per-action link battles
battle_effect/Battle & Effects128×128 brightness canvas, palette ramps, VBlank trail decay, blitters, motes, 29 summons, and IWRAM 3D software-rasterised polygon models
window/Dialogue, Menus & ShopsmnWindowSystemUpdate and mnWindowSystemUpdateBattle (12 windows in all editions), context-Huffman decoding, text typing and backends, Pause menu and save-lock flags, shared battle and debug screens
menu/Dialogue, Menus & ShopsPaginated 8-member field menu with convenience shortcuts, live-copy Djinn preview, Echo tutorial, title_intro.c, credits.c (prologue crawl and ending scroll)
shop/Dialogue, Menus & ShopsShops and General Stores (shop_tables.c), sanctums, inns, Sunshine's Forge (shop_forge.c), item picker (reused by Naribwe's fortune teller)
graphics/Graphics & SoundIndexed PNGs and .tsv tables (sprites, monsters, tilesets, standalone palettes, battle backgrounds, summon textures, fonts, UI)
sound/Graphics & SoundsySoundPlay (700+ BGM, heard-track bitfield, 4-player SFX fallback), BGM ramps, debug sound test, plus TLA driver overrides in sound/sdk/
debug/Debug Mode5 debug overlays covering 12 test rooms (TEST0–TEST7, level.c, shop_test.c, psynergy_test.c, psynergy_test_2.c)

How the files are cut

  • 15 resident modules (ld_script.ld): Always-mapped Thumb code spans the 16 MB ROM, adding Super Lucky Dice as its own module. Four modules (game, field_engine, menu, and shop) shift base addresses slightly per language edition. Cross-module calls jump through 8-byte *Stub thunks (stubs.s), except module 0 (system/), which other resident modules call directly.
  • Objects and parts: Large translation units (battle/battle.c, battle_effect/battle_effect.c, and shop/shop.c) #include sibling *_*.c parts in ROM order so each compiles into one matching .o.
  • 114 compressed overlays (-Os): Built from scene/*.c and debug/*.c with a 7-stub entry table (scene/entry.s, adding scPrepareMap) and a build-generated import table (system/overlay/imports.inc), all compressed into the 2,048-row resource directory.
  • Compilers: Main-image Thumb C compiles with Alchemy GCC (-O2 -mtune=gba -fcall-used-r4, emitting 4-byte inline indirect calls). Overlay-only C uses -Os, ARM C uses GCC 2.95.2, and the reconstructed flash and audio routines in games/common/sdk/ use old_agbcc.
  • Headers, heap slots, and naming: Subsystem heap slots sit at a fixed address accessed through RamHeapSlots (such as RamHeapSlots->fieldState), and all system declarations are in system.h. Functions take two-letter prefixes (sy, gm, fd, sc, bt, mn, db), types use UPPER_SNAKE_CASE, globals use PascalCase, and locals and fields use camelCase (CONTRIBUTING.md).