Skip to Content
The Alchemy Project

Windows & Text

This page is a guide to the games/tbs/src/window/ folder of the Alchemy project. Its code draws every dialogue box, proportional text line, save menu, and shared battle or debug screen in Golden Sun: The Broken Seal.

At its core is the window system in mnWindowSystemUpdate, paired with a Huffman message decoder and a proportional text typer. It also builds the Pause and Save screens, character name entry, shared battle command menus, and the debug overlays used across the game's engines.

Whenever a villager's portrait slides up beside a zooming border and text types out letter by letter, this code does the work without stalling the game loop. The sections below cover the decoding and typing mechanics, the Pause and Save UI, and a full file map. The conceptual architecture is described in Dialogue, Menus & Shops.

How it works, and decoding

Isaac talks to Garet's sister in Vale: her portrait appears beside a window typing text letter by letter with a bobbing advance arrow
Isaac talks to Garet's sister in Vale: her portrait appears beside a window typing text letter by letter with…
  • Window capacity (window_windows.c): WINDOW_COUNT is 12 in tbs-ja and 8 in international editions. mnWindowSystemUpdate steps border zooms, advances up to 3 active messages per tick, and queues the tilemap without ever calling sySynch().
  • Message decoding (window_decode.c, message_decode.s): Unpacks Huffman strings from text into a 512-entry 16-bit ring buffer (textBuf). As it decodes, it resolves state blanks ({actor_name:2}), reorderable typed arguments ({argument_signed_number}), and European grammar metadata (articles.c, counted_nouns.c, item_genders.c) while passing control codes ({page_break}, {end_wait}) to the typer.
  • Typing and rendering (window_typing.c, window_measure.c, glyph_arm.c): Justifies lines against proportional widths from Graphics Assets, rendering through OAM sprites on the field, a shared sprite-free tile strip in battle, or instant direct-tile blits in menus.

Pause menu and saving UI

Isaac opens the Pause menu by Vale's river, picks Save your quest, chooses slot 1, and sees the save confirmation
Isaac opens the Pause menu by Vale's river, picks Save your quest, chooses slot 1, and sees the save…

window_settings_menu.c implements Save, Sleep, and global Settings (every box shares one palette). screens_save.c drives Save and the File Screen slot list from compact summary headers without reading full save slots (see System library for flash write safety).

File map

File(s)Role
window.c, window_internal.hParent translation unit #includeing the window_*.c parts below in ROM order
window_windows.c, window_borders.c, window_icons.c, window_sprites.cWindow lifecycle, zoom borders, icons, portraits, and cursor sprites
window_decode.c, window_messages.c, window_typing.c, window_measure.cHuffman decoding, message queue, per-tick typing, and right-edge justification
window_glyphs.c, window_text_tiles.c, window_selection.c, window_shortcuts.cGlyph blitting, tile-strip text, list selectors, and shortcut bindings
window_settings_menu.c, screens_save.cPause menu settings, Sleep, Save workflow, and File Screen summaries
screens.c, screens_internal.h, screens_battle_*.cShared battle menus (command row, Psynergy, Djinn, Item, Summon, target cursor, and status)
screens_party_status.c, screens_name_entry.c, screens_icon_menu.c, screens_debug.cParty status panel, name entry, icon menus, joined and link timers, and debug windows
message_decode.s, glyph_arm.c, decompress_4bpp.s, expand_opaque.sFast ARM assembly Huffman decoding and 1bpp-to-4bpp glyph blitting
articles.c, counted_nouns.c, item_genders.c, message_speed.c, keyboard*.tsvEuropean grammar tables, message speeds, debug labels, name-entry keyboards, and stubs.s

Source files

src/window/

FileDescription
articles.cWindow text tables: each edition's articles and possessives, the kana marks and the sprite motion curves.
counted_nouns.cThe German counted nouns, singular and plural, by kind.
debug_labels.cThe debug screens' labels: the flag and destination browsers' colon and hex digits, and the icon browser's headings.
expand_nibble_table.cThe colour map mnGraphicsExpandVRAMTilesByColorTable draws the UI's digits through, and the link battle timer's heading.
file_list_sprites.cThe four Djinn sprites the File Screen shows in a row.
fixed_tile_blocks.cThe window sprites' fixed tile blocks.
glyph_arm.cThe text canvas renderer, which runs as ARM code from a copy in RAM: mnGlyphDraw copies it into RAM for each call (RAM_CODE_LOAD), into IWRAM when the copy fits: its 32-bit bus fetches an ARM instruction in one read, where the cartridge's 16-bit bus takes two.
icon_menu_tables.cThe Djinn menu's element icon offsets and the icon menus' tables: the waits of a choice made for the player to watch, and the field menu's and the File Screen's choices by icon position.
item_genders.cThe grammatical gender of each item's name, by item id, in the German and Italian releases (ITEM_GENDER), which picks the possessive a message writes before the item.
message_speed.cThe message speed tables, indexed by the player's message speed setting (MainRoutineStateWork.msgSpeed, MESSAGE_SPEED).
scales.cSprite scales, motion curves and lookup tables of the window and menu code.
screen_tables.cThe screens' tables from the save summary's level label to the range icons' patterns: the name entry's marks and labels, the Djinn and party sprites, and the window sprites' motions.
screens.cThe menu object of the window module: the screens built on the window system (window.c).
screens_battle_command_row.cThe row of command icons the player picks a command from.
screens_battle_djinn_menu.cThe battle Djinn menu.
screens_battle_djinn_preview.cThe preview of what setting or removing a Djinni changes.
screens_battle_item_menu.cThe battle item menu.
screens_battle_party_commands.cCollecting the party's battle commands.
screens_battle_psynergy_menu.cThe battle Psynergy menu.
screens_battle_status.cThe battle's Status screen, which the Status command opens.
screens_battle_summon_menu.cThe battle summon menu.
screens_battle_targets.cChoosing a battle target.
screens_debug.cThe debug menus (scenes, flags, icon browsers) and the Pause menu's choices.
screens_icon_menu.cThe command icon menus of the field, title and transfer screens.
screens_internal.hWhat every part of the menu object shares: its includes, edition values, macros and the link turn state.
screens_joined.cThe Colosso choice and the joined-party messages.
screens_link_timer.cThe link battle timer and the no-flee check.
screens_menu_titles.cThe pictures the menus show: the headings and command icons, with their bob and pulse, the range icons of the battle lists, the page arrows, icons and portraits loaded into the VRAM cache, the link battle timer's window, and the battle command row's icons on BG1 with its priority.
screens_name_entry.cThe name entry screen.
screens_party_status.cThe party status window.
screens_save.cSaving, loading, copying and erasing the three save files, and the file list the player picks one from: for the file under the cursor, its summary, its party and its Djinn, in that file's own window colours.
screens_window_sprites.cThe sprites that sit on windows: item, Psynergy and command icons and the speakers' portraits beside their messages.
status_tables.cThe Status screen's tables: its cursor stops and its labels.
text_tables.cThe text's tables: each glyph's width, the text colours' pens, and the party status's divider columns.
window.cThe window object: the UI windows drawn into a shared BG tilemap, the messages that type text into them, the message decoder and the formatting behind it, the sprites (window sprites) that windows carry, icons, the selection screen and the option and pause menus.
window_borders.cWindow zoom and borders, and opening and waiting on message windows.
window_decode.cThe message decoder: articles, names and numbers written out.
window_glyphs.cCharacters rendered into tiles, string widths and number formatting.
window_icons.cItem, Psynergy and command icons.
window_internal.hWhat every part of the window object shares: its includes, edition values, macros and the codes of decoded text.
window_measure.cSizing windows to their text and fitting them on the screen.
window_messages.cMessage strings and arguments, symbol decoding and portrait windows.
window_selection.cThe selection screen: a row of icons along the bottom of the screen with the name of the one under the cursor in a window above it, arrows at its ends when the list runs past them, the icons already chosen gathered at the top left, and in battle the spinning cursor over the target.
window_settings_menu.cWindow colours, the settings menu and the Pause menu.
window_shortcuts.cThe area name shown on entering an area, the debug Psynergy shortcut picker and the unused selection state.
window_spans.cThe windows' outline for a screen transition: for each scan line, the left and right edge of the windows on it, read off the UI tilemap by ARM code that mnScanlineWindowFillSpans copies into RAM for each call.
window_sprites.cCharacters drawn into windows, and the per-tick sprite update.
window_text_tiles.cText drawn as tiles, text tile ownership and divider lines.
window_typing.cThe per-tick message update: typing text and running its control codes.
window_windows.cThe window sprite pool, opening and closing windows, starting messages.

include/window/

FileDescription
articles.hThe words messages put before and after a name in each edition (articles, possessives, the German counted nouns), the kana marks and the window sprites' motion curves (window/articles.c).
battle_status.hThe Status screen's cursors and the party status window's flags.
cursor.hThe cursor that approaches its target, shared by shops, the name entry screen and the settings menu.
djinn_preview.hThe Djinn preview's sprites and arrow tiles.
glyph_arm.hThe ARM functions copied to RAM to run: a character drawn into a text window's canvas, and the screen transition's window edges read from the windows' borders (window/glyph_arm.c).
icon_menu.hThe icon menu's entries and state.
menu_list.hThe menus' sprites and cursors, the party status window's layout, and the battle command menus' state, with its remembered page and row.
message_reader.hMESSAGE_READER, a cursor through message text.
message_speed.hThe message speed setting and how fast each speed types a message.
scales.hThe window sprites' and cursors' motion curves, the window colour wheel, the settings and Pause menus' icons and colour presets, and the speakers' portraits (window/scales.c).
screens.hThe functions of window/screens.c and its parts: window sprites and portraits, the party status window, the file list and saving, name entry, the joined-party messages, the battle menus, the icon menus and the debug menus.
select.hThe selection screen's sprites and nodes.
settings_menu.hThe state of the settings menu and the Pause menu.
stubs.hThe window module's stub calls: windows, text and portraits, the menus and screens built from them (Pause menu, File Screen, Yes/No), and the debug selectors.
text_font.hThe kanji glyphs and the text marks drawn with characters.
window.hWindows, the messages that type into them, and the window renderer's state.
window_sprite.hSprites as the windows draw them: a sprite's OAM attributes, and the lists of characters, icons and portraits each window shows as sprites.