Codebase Map
This page is a guide to the games/tbs/src/ folder of the Alchemy project. It
describes the source tree of Golden Sun: The Broken Seal and locates the code
behind every part of the game.
Everything that makes up the game lives under games/tbs/. Inside it, src/
holds the C source, assembly routines, maps, and graphics, while include/
holds shared headers. Localised dialogue and UI copy live in text/, and
sound/ holds the MIDI songs and WAV samples.
The first section below is a lookup guide for tracing anything seen on screen
back to its code. The directory table then covers all thirteen folders under
src/, and the last section explains how the build packs them 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 itsmsgctxtentry, which gives its symbol, such asMsgValeYouGuysAreSoLuckyGaret. -
A search of
games/tbs/src/for that symbol finds the scene or UI file that uses it (for example,scene/vale.c):{ CUE_TALK, ACTOR_GARETS_SISTER, CONDITION_ALWAYS, MSGNO(MsgValeYouGuysAreSoLuckyGaret) },
The method applies equally to dialogue, menus, item descriptions, and battle messages. For everything else:
| To find | Open |
|---|---|
| A town's NPCs, lines, and cutscenes | Its overlay in src/scene/, e.g. scene/vale.c |
| The inside of a house | Follow the town's exit row to its rooms map, e.g. CottageRoomsC |
| Item, ability, enemy, class, Djinni, or summon stats | Its row in src/game/*_table.c |
| What a town shop sells | shop/shop_stock.c |
| How a spell or unleash animates | Its src/battle_effect/battle_effect_*.c file (opening comment lists its abilities) |
| A sprite, monster, tileset, or UI picture | A PNG under src/graphics/ |
| A song or sound effect | A MIDI or WAV file under sound and rules in field/music_rules.s |
| A map's tiles, heights, or chests | src/map/<place>/ (grid_*.tsv, spots.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 |
Execution order from power-on 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, sySynch(), 20-slot events, heaps, OAM and VRAM caches, matrices, decompressors, overlays, flash saving, link cable, ROM header, resource directory, and IWRAM mixer |
game/ | RPG Data & Rules | gmMainRoutineRun, all 7 RPG data tables, UNIT stat recalculation, classes, Djinn, levels, 4,096 game flags, rare counters, and shared combat math |
field/ | World, Scenes & Maps | fdEngineRun, 12 field requests, 64 actors and SC_* scripts, collision, field Psynergy, the World Map, random encounters, Lucky Dice, and Lucky Wheels |
scene/ | World, Scenes & Maps | 93 gameplay scene overlays (entry.s 6-stub table), cues, exits, entrances, cutscenes, Title, File Screen, Clear Data passwords, and Battle Arena |
map/ | World, Scenes & Maps | 182 .tsv metatile map folders, height shapes, treasure spots, tileset animations, and blends |
battle/ | Battle & Effects | btRun, 380 formations, turn order, two-phase enemy AI, action building, staging, and resolution, playback queue, zoomed backgrounds, spoils, auto-battle, and link battles |
battle_effect/ | Battle & Effects | 128×128 brightness canvas, palette ramps, VBlank trail decay, blitters, motes, and weapon, Psynergy, Djinni, and summon animations |
window/ | Dialogue, Menus & Shops | mnWindowSystemUpdate (12 JA, 8 intl windows), Huffman decoding, text typing and render backends, Pause menu, save UI, and shared battle and debug screens |
menu/ | Dialogue, Menus & Shops | Call-stack field menu (Psynergy, Djinn, Item, Status), live-copy Djinn preview, Flint tutorial, title_intro.c, and credits.c |
shop/ | Dialogue, Menus & Shops | Weapon, armour, and item shops (shop_stock.c), sanctums, inns, and the full-pack item picker |
graphics/ | Graphics & Sound | Indexed PNGs and .tsv tables for sprites, monsters, tilesets, battle backgrounds, effects, fonts, and UI |
sound/ | Graphics & Sound | sySoundPlay, BGM volume ramps, post-jingle fade-back, and stubs (over games/common/sdk/sound/ and games/tbs/sound/) |
debug/ | Debug Mode | 3 debug overlays covering 10 test rooms (TEST0–TEST7, GET_ITEM, MENU) |
How the files are cut
- 14 resident modules (
ld_script.ld): Always-mapped Thumb code sits at fixed ROM addresses so modules can grow without shifting their neighbours. Small modules live beside related code. For instance, the title intro and credits are standalone modules insidemenu/. Cross-module calls jump through 8-byte*Stubthunks (stubs.s), except module 0 (system/), which resident modules call directly. - Objects and parts: Functions stay in ROM order inside each translation
unit. Very large units (such as
battle/battle.cat ~13,000 lines,system/system.c, orshop/shop.c)#includesibling*_*.cparts in ROM order so the source stays readable while compiling into one matching.o. - 96 compressed overlays: Each
.cfile inscene/ordebug/linksscene/entry.s(6 stubs) and a build-generated import table (system/overlay/imports.inc), then packs into the 1,000-row resource directory. - Headers, C, and assembly: Every module exports its declarations in
include/<folder>/<file>.h. The entire system library exposes one umbrella header,system.h, mirroring SGL'ssgl.h. Almost all logic is written in C. Assembly.sfiles mostly place assets and tables, plus a handful of hand-written ARM and IWRAM routines for IRQs, math, audio mixing, and decompression. - Compilers and naming: Thumb C compiles with Alchemy GCC (
xgcc -O2, a July 2000 GCC 2.96 snapshot) and-fcall-used-r4. ARM C compiles with GCC 2.95.2, and the reconstructed flash and audio routines ingames/common/sdk/useold_agbcc. Functions take two-letter owner prefixes (sy,gm,fd,sc,bt,mn,db), types areUPPER_SNAKE_CASE, globals arePascalCase, and locals and fields arecamelCase(CONTRIBUTING.md).