Skip to Content
The Alchemy Project

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:

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

  2. 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 findOpen
A town's NPCs, lines, and cutscenesIts overlay in src/scene/, e.g. scene/vale.c
The inside of a houseFollow the town's exit row to its rooms map, e.g. CottageRoomsC
Item, ability, enemy, class, Djinni, or summon statsIts row in src/game/*_table.c
What a town shop sellsshop/shop_stock.c
How a spell or unleash animatesIts src/battle_effect/battle_effect_*.c file (opening comment lists its abilities)
A sprite, monster, tileset, or UI pictureA PNG under src/graphics/
A song or sound effectA MIDI or WAV file under sound and rules in field/music_rules.s
A map's tiles, heights, or chestssrc/map/<place>/ (grid_*.tsv, spots.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

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

FolderDivisionOwns
system/The system libraryBoot, 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 & RulesgmMainRoutineRun, all 7 RPG data tables, UNIT stat recalculation, classes, Djinn, levels, 4,096 game flags, rare counters, and shared combat math
field/World, Scenes & MapsfdEngineRun, 12 field requests, 64 actors and SC_* scripts, collision, field Psynergy, the World Map, random encounters, Lucky Dice, and Lucky Wheels
scene/World, Scenes & Maps93 gameplay scene overlays (entry.s 6-stub table), cues, exits, entrances, cutscenes, Title, File Screen, Clear Data passwords, and Battle Arena
map/World, Scenes & Maps182 .tsv metatile map folders, height shapes, treasure spots, tileset animations, and blends
battle/Battle & EffectsbtRun, 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 & Effects128×128 brightness canvas, palette ramps, VBlank trail decay, blitters, motes, and weapon, Psynergy, Djinni, and summon animations
window/Dialogue, Menus & ShopsmnWindowSystemUpdate (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 & ShopsCall-stack field menu (Psynergy, Djinn, Item, Status), live-copy Djinn preview, Flint tutorial, title_intro.c, and credits.c
shop/Dialogue, Menus & ShopsWeapon, armour, and item shops (shop_stock.c), sanctums, inns, and the full-pack item picker
graphics/Graphics & SoundIndexed PNGs and .tsv tables for sprites, monsters, tilesets, battle backgrounds, effects, fonts, and UI
sound/Graphics & SoundsySoundPlay, BGM volume ramps, post-jingle fade-back, and stubs (over games/common/sdk/sound/ and games/tbs/sound/)
debug/Debug Mode3 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 inside menu/. Cross-module calls jump through 8-byte *Stub thunks (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.c at ~13,000 lines, system/system.c, or shop/shop.c) #include sibling *_*.c parts in ROM order so the source stays readable while compiling into one matching .o.
  • 96 compressed overlays: Each .c file in scene/ or debug/ links scene/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's sgl.h. Almost all logic is written in C. Assembly .s files 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 in games/common/sdk/ use old_agbcc. Functions take two-letter owner prefixes (sy, gm, fd, sc, bt, mn, db), types are UPPER_SNAKE_CASE, globals are PascalCase, and locals and fields are camelCase (CONTRIBUTING.md).