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:
-
A search of
en.pofor a few words of the line finds its entry, whosemsgctxtgives its symbol, such asMsgFieldISawABrightLightIn. -
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 find | Open |
|---|---|
| A town's NPCs, lines, and cutscenes | Its overlay in src/scene/, e.g. scene/daila.c |
| The inside of a house | Follow the town's exit row to its rooms map, e.g. scene/champa_rooms.c |
| Item, ability, enemy, class, Djinni, or summon stats | Its row in src/game/*_table.c |
| Shop inventories & Sunshine's Forge recipes | shop/shop_tables.c |
| How a spell, unleash, or 3D summon animates | Its src/battle_effect/battle_effect_*.c file (or render_*.s for 3D kernels) |
| A sprite, monster, tileset, or UI picture | A PNG under src/graphics/ |
| A song, SFX, or music rule | sound, field/music_rules.s, and EncounterBattleMusic in field/battle_music.c |
| A map's tiles, terrain flags, heights, or items | src/map/<place>/ (grid_*.tsv, shape_grid.tsv, points.tsv) |
| Numeric IDs for flags, sounds, scenes, items, or sprites | include: 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
| Folder | Division | Owns |
|---|---|---|
system/ | The system library | Boot, 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 & Rules | gmMainRoutineRun, 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 & Maps | fdEngineRun (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 & Maps | 109 gameplay scene overlays (entry.s 7-stub table adding scPrepareMap), cues, EXIT_FLAG_NONE exits, cutscenes, Clear Data transfer, Battle Arena |
map/ | World, Scenes & Maps | 301 .tsv metatile map folders (4 grids per map), height shapes, anchor points, tileset animations, blends |
battle/ | Battle & Effects | btRun, 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 & Effects | 128×128 brightness canvas, palette ramps, VBlank trail decay, blitters, motes, 29 summons, and IWRAM 3D software-rasterised polygon models |
window/ | Dialogue, Menus & Shops | mnWindowSystemUpdate 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 & Shops | Paginated 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 & Shops | Shops and General Stores (shop_tables.c), sanctums, inns, Sunshine's Forge (shop_forge.c), item picker (reused by Naribwe's fortune teller) |
graphics/ | Graphics & Sound | Indexed PNGs and .tsv tables (sprites, monsters, tilesets, standalone palettes, battle backgrounds, summon textures, fonts, UI) |
sound/ | Graphics & Sound | sySoundPlay (700+ BGM, heard-track bitfield, 4-player SFX fallback), BGM ramps, debug sound test, plus TLA driver overrides in sound/sdk/ |
debug/ | Debug Mode | 5 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, andshop) shift base addresses slightly per language edition. Cross-module calls jump through 8-byte*Stubthunks (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, andshop/shop.c)#includesibling*_*.cparts in ROM order so each compiles into one matching.o. - 114 compressed overlays (
-Os): Built fromscene/*.canddebug/*.cwith a 7-stub entry table (scene/entry.s, addingscPrepareMap) 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 ingames/common/sdk/useold_agbcc. - Headers, heap slots, and naming: Subsystem heap slots sit at a fixed
address accessed through
RamHeapSlots(such asRamHeapSlots->fieldState), and all system declarations are insystem.h. Functions take two-letter prefixes (sy,gm,fd,sc,bt,mn,db), types useUPPER_SNAKE_CASE, globals usePascalCase, and locals and fields usecamelCase(CONTRIBUTING.md).