menu
The Menus guide explains this folder.
Folders
clear.c
The file select overlay: the Golden Sun logo, the start menu (new game, continue, copy and delete), the door to the Battle Arena and the transfer of a save's data, by link or as a password.
Functions
Clear_GetEntrances
u8 *Clear_GetEntrances(void)
The file select overlay's scene tables, for the scene loader: one entrance, the exit, and no placements or events.
Clear_LoadBackground
static void Clear_LoadBackground(void)
Loads the Golden Sun logo, maps its tiles and resets background scroll.
Used by SaveMenu_Run.
Clear_UpdateBlend
static void Clear_UpdateBlend(void)
Advances the logo blend every two frames and removes itself at completion.
Used by SaveMenu_Run.
Clear_CheckButtonCodes
static void Clear_CheckButtonCodes(void)
Tracks two hidden key sequences, requiring a full release after each key.
Used by SaveMenu_Run.
Clear_NameEntryCharacter
static void Clear_NameEntryCharacter(s32 cell, u8 *text)
Converts a six-bit password symbol to the edition's one- or two-byte glyph.
Used by SaveMenu_Run.
Clear_GetSaveRecoveryBlockMask
static s32 Clear_GetSaveRecoveryBlockMask(void)
Returns -1 when the flagged saved scene blocks recovery, otherwise zero.
Used by SaveMenu_Run.
SaveMenu_Run
s32 SaveMenu_Run(void)
Runs new/continue/copy/delete, arena entry and save-data transfer/password menus. Returns zero after choosing a destination; cancellation returns to selection.
SaveMenu_FillTileGrid
UNUSED static void SaveMenu_FillTileGrid(struct UiWindow *window, const void *compressedTiles)
UNUSED: decodes tiles and maps a 16-by-eight window region in VRAM and shadow.
SaveMenu_FillTileBlock
UNUSED static void SaveMenu_FillTileBlock(const struct UiWindow *window)
UNUSED: fills a 16-by-eight region with palette 15 tiles beginning at tile 32.
Clear_PackPasswordData
static s32 Clear_PackPasswordData(s32 unused, s32 mode, u8 *out)
Packs selected flags, levels, Djinn and optional stats/inventories/coins. Clamps the source base stats and levels in place; returns the raw byte count.
Used by SaveMenu_Run.
Clear_EncodePassword
static s32 Clear_EncodePassword(u8 *data, s32 size, u8 *out)
Obscures the packed bytes and emits position-adjusted six-bit password symbols.
Used by SaveMenu_Run.
Clear_ComputePasswordCrc16
static u16 Clear_ComputePasswordCrc16(u32 byteCount, u8 *data)
Runs the original shift/subtract checksum, initially 0xffff, and returns its complemented low 16 bits.
Used by SaveMenu_Run.
Also, functions without a comment: SceneData_ReturnZero, Clear_GetExits, Clear_GetPlacements, Clear_GetEvents.
Structures
SaveMenuSceneState
struct SaveMenuSceneState
A view of the scene state that names its copy of the play time, checked against the loaded game's.
| Field | Declared as | |
|---|---|---|
unk000 | u8 unk000[0x100] | |
word100 | s32 word100 | frames |
Used by SaveMenu_Run.
SaveLinkGreeting
struct SaveLinkGreeting
A linked console's signature: four letters naming its language and game.
| Field | Declared as | |
|---|---|---|
code | u16 code[4] | |
reserved | u8 reserved[16] |
Used by SaveMenu_Run.
PasswordStats
struct PasswordStats
A party member's base stats, which the password clamps and packs.
| Field | Declared as | |
|---|---|---|
baseHp | s16 baseHp | |
basePp | s16 basePp | |
unk14 | u8 unk14[4] | |
baseAttack | u16 baseAttack | |
baseDefense | u16 baseDefense | |
baseAgility | u16 baseAgility | |
baseLuck | u8 baseLuck |
Used by Clear_PackPasswordData.
PasswordOwner
struct PasswordOwner
A party member as the password reads them: their level, base stats, inventory and Djinn.
| Field | Declared as | |
|---|---|---|
unk00 | u8 unk00[0x0f] | |
level | u8 level | |
stats | struct PasswordStats stats | |
unk20 | u8 unk20[0xb8] | |
inventory | u16 inventory[15] | |
unkf6 | u8 unkf6[2] | |
djinnAvailable | u32 djinnAvailable[4] |
Used by Clear_PackPasswordData.
Macros, without a comment: CLEAR_PASSWORD_BUFFER_SIZE, CLEAR_PASSWORD_BUFFER_SIZE, CLEAR_LINK_WINDOW_X, CLEAR_LINK_WINDOW_WIDTH, CLEAR_LINK_WINDOW_X, CLEAR_LINK_WINDOW_WIDTH, CLEAR_LINK_LANGUAGE_TAG, CLEAR_LINK_LANGUAGE_TAG, CLEAR_LINK_LANGUAGE_TAG, CLEAR_LINK_LANGUAGE_TAG, CLEAR_LINK_LANGUAGE_TAG, CLEAR_LINK_LANGUAGE_TAG, CLEAR_LINK_ERROR_WINDOW_X, CLEAR_LINK_ERROR_WINDOW_WIDTH, CLEAR_LINK_ERROR_WINDOW_X, CLEAR_LINK_ERROR_WINDOW_WIDTH, CLEAR_HELP_WINDOW_X, CLEAR_HELP_WINDOW_WIDTH, CLEAR_HELP_WINDOW_X, CLEAR_HELP_WINDOW_WIDTH, CLEAR_PAGE_LABEL_X, CLEAR_PAGE_LABEL_X, CLEAR_MESSAGE_WINDOW_X, CLEAR_MESSAGE_WINDOW_WIDTH, CLEAR_MESSAGE_WINDOW_X, CLEAR_MESSAGE_WINDOW_WIDTH, CLEAR_MESSAGE_WINDOW_X, CLEAR_MESSAGE_WINDOW_WIDTH, PASSWORD_SYMBOLS_PER_PAGE, PASSWORD_SYMBOL_MASK, CLEAR_EXTRA_CODE_HELD, CLEAR_EXTRA_CODE_HELD, CLEAR_SEQUENCE_KEYS, CLEAR_SEQUENCE_KEYS.
Globals, without a comment: gClear_CodeSequence, gClear_ExtraCodeSequence, gClear_Entrances, gClear_Exits, gClear_Placements, gClear_Events, gClear_BlendFrame, gClear_CodeUnlocked, gClear_ExtraCodeUnlocked, gClear_CodeProgress, gClear_ExtraCodeProgress, gClear_CodeHeld, gClear_ExtraCodeHeld, gClear_PasswordMembers, gClear_PasswordFlags, gClear_PasswordKeyItems, gClear_PasswordStackItems.
Declarations, without a comment: __divsi3.
lobby.c
The Battle Arena overlay: the lobby where linked and monster battles start, the exchange of the two parties, the attendant and the records of wins.
Functions
LinkLobby_InitializeSerial
static s32 LinkLobby_InitializeSerial(void)
Reinitializes the serial runtime while interrupts are locked. The original s32 entry produces no defined result; its callers ignore it.
LinkLobby_SelectPlacements
s32 LinkLobby_SelectPlacements(void)
Selects the post-link-battle placements for entrances nine and eleven.
LinkLobby_PeerSlotMatches
static s32 LinkLobby_PeerSlotMatches(s32 slot)
Checks one language-specific peer signature slot and updates link-side flags.
LinkLobby_WriteSlotValue
static void LinkLobby_WriteSlotValue(s32 slot)
Publishes a protocol slot value in the outgoing signature payload.
Also, functions without a comment: LinkLobby_GetEntrances, SceneData_ReturnZero, LinkLobby_GetExits.
Structures
LinkPeer
struct LinkPeer
The partner console's signature as the lobby reads it: a word for each slot column.
| Field | Declared as | |
|---|---|---|
values | s32 values[6] |
Used by LinkLobby_PeerSlotMatches.
Macros, without a comment: LOBBY_UNIT_RECORD_BYTES, LOBBY_RECOVERY_RECORD_BYTES, LOBBY_UNIT_RECORD_COUNT, LOBBY_LINK_READY_MASK, LOBBY_TRANSFER_RETRY_LIMIT, LOBBY_SEND_TIMEOUT_FRAMES, LOBBY_RECEIVE_TIMEOUT_FRAMES, LOBBY_PEER_WAIT_FRAMES, PEER_TAG, LOBBY_NO_RESULT, LOBBY_NO_RESULT.
Globals, without a comment: gLinkLobby_SlotValues, sLinkLobbyWaitFrames.
menu.c
The menu object: the field menu's Psynergy, Djinn, Item and Status screens, the member chooser and item picker that events open, and the pieces they share. menu_internal.h holds what the parts share (includes, macros and types); the code is in the files under menu/, included here in the order it has in the ROM. Camelot's own files are not recoverable: the ROM shows one object, and these parts are ours, cut where one screen ends and the next begins.
README.md in this folder gives the words, prefixes and spellings the parts use, and how to find a screen's code.
menu_internal.h
games/tbs/src/menu/menu_internal.h
Enumerations
StatusPanelKind
enum StatusPanelKind
What Menu_DrawOwnerStatusPanel shows below the name and ailments: the low byte of its mode.
| Value | = | |
|---|---|---|
STATUS_PANEL_EXPERIENCE | 0 | class, HP, PP and experience |
STATUS_PANEL_EQUIP | 2 | stats if the item were equipped |
STATUS_PANEL_LEARN | 4 | the Psynergy a Psynergy item teaches |
STATUS_PANEL_CLASS | 6 | class, HP and PP |
STATUS_PANEL_STATS | 8 | Attack, Defense, Agility and Luck |
DjinnCompareOperation
enum DjinnCompareOperation
The preview loop's four operations, as its confirmation text describes them.
| Value | = | |
|---|---|---|
DJINN_COMPARE_TRADE | 0 | |
DJINN_COMPARE_GIVE | 1 | |
DJINN_COMPARE_STANDBY | 2 | |
DJINN_COMPARE_SET | 3 |
Macros
ACTION_USABLE_IN_FIELD
#define ACTION_USABLE_IN_FIELD 0x40
BattleAct.flags: where an ability or item can be used, as the Psynergy list says ("Usable in the field", "Usable in battle").
Used by Item_ClassifyUseMode, PsynergyMenu_CollectActions, PsynergyMenu_DrawRangePage, PsynergyMenu_IsActionRestricted.
FLAG_MENU_START_PRESSED
#define FLAG_MENU_START_PRESSED 0x150
Game flags of the menus. Start was pressed: every menu screen unwinds and the whole menu closes.
Used by CharacterMenu_SelectCommand, CharacterSelector_RunRearrange, DjinnMenu_ShowCurrentList, ItemMenu_ChooseCommand, ItemMenu_ConfirmDrop, ItemMenu_RunList, ItemMenu_RunOwnerSelection, ItemMenu_SelectGiveQuantity, ItemMenu_SelectItem, ItemMenu_SelectTarget, Menu_CancelSoundReset, Menu_CancelSoundTick, Menu_EnsureCancelSound, Menu_ResolveSelectedAction, Menu_RunActionFlow, Menu_SelectQuantity, PsynergyMenu_RunList, PsynergyMenu_SelectAction, PsynergyMenu_SelectMember, PsynergyMenu_SelectTarget.
FLAG_MENU_INFO_KEPT
#define FLAG_MENU_INFO_KEPT 0x151
The info window holds a message the next selection must not draw over.
Used by InventoryMenu_ShowModalMessage, ItemMenu_SelectTarget, PsynergyMenu_DrawDetailPage, PsynergyMenu_SelectMember, PsynergyMenu_SelectTarget.
MENU_TARGET_WHOLE_PARTY
#define MENU_TARGET_WHOLE_PARTY 9
The target id of Psynergy or an item used on the whole party.
Used by BattleEffect_ApplyToTargets, Menu_ResolveSelectedAction.
MENU_WORK_SIZE
#define MENU_WORK_SIZE 0xa70
The bytes of the menu work, heap block HEAP_SLOT_MENU.
Used by DjinnMenu_Run, ItemMenu_Run, Menu_OpenCharacterSelector, PsynergyMenu_Run, StatusMenu_Run, UiWindow_InitializeWork.
MENU_ITEM_GRID_COLUMNS
#define MENU_ITEM_GRID_COLUMNS 5
Inventory icons occupy five columns in the fifteen-slot list.
Used by ItemMenu_HidePageIcons, ItemMenu_RefreshEntry.
STATUS_PANEL_LOWER_ONLY
#define STATUS_PANEL_LOWER_ONLY 0x100
Keeps the open window, the name and the ailments, and redraws only the part below them.
Used by ItemMenu_DrawEquipPreview, Menu_DrawOwnerStatusPanel.
ICON_SHOWN
#define ICON_SHOWN 1
RenderOutput.active as the menu sets it: shown, or hidden but kept.
Used by CharacterMenu_DrawStatusAilments, CharacterMenu_SelectCommand, CharacterMenu_SelectOwner, DjinnMenu_RunScreen, DjinnMenu_SelectDjinn, DjinnMenu_ShowCurrentList, InventoryMenu_ShowModalMessage, ItemMenu_DrawItemHead, ItemMenu_DrawOwnerStatus, ItemMenu_SelectItem, Menu_SelectQuantity, Menu_SetPageIcons, OwnerAction_RunCompareLoop, PsynergyMenu_RunList, PsynergyMenu_SelectAction, PsynergyMenu_SelectPartySlot, UiIcon_CreateStatChangeArrow, UiIcon_DrawVariantWithTileOffset, UiIcon_PrepareObject.
ICON_SPRITE_16X16
#define ICON_SPRITE_16X16 0x40000000
RenderOutput_CreateFar's sprite attributes for the menu's 16x16 icons.
Used by UiIcon_CreateStatChangeArrow, UiIcon_CreateWithLoadedResource, UiIcon_CreateWithResource, UiIcon_CreateWithResourceVariant, UiIcon_DrawVariantWithTileOffset.
Also, macros without a comment: ACTION_USABLE_IN_BATTLE, STATUS_PANEL_KIND_MASK, MENU_RESET_INFO_WINDOW, MENU_DRAW_INFO_TEXT, MENU_RESET_INFO_WINDOW, MENU_DRAW_INFO_TEXT, MENU_DRAW_STATUS_LABEL, MENU_DRAW_STATUS_LABEL, TEXT_COLOR_LOW_HP, TEXT_COLOR_NO_HP, TEXT_COLOR_NORMAL, ICON_HIDDEN.
Globals, without a comment: IwramCopyWords.
menudata.c
Globals
gUiMenu_CursorBobX
u8 gUiMenu_CursorBobX[9]
The hand cursor's bobbing offsets, indexed by (gFrameCount >> 1) & 7.
Used by UiMenu_PositionCursor.
gMenu_ListOrderDefault
u8 gMenu_ListOrderDefault[11]
The item menu's sort orders (InventoryMenu_SortByListOrder), one item type per byte, 0x80 (LIST_ORDER_EQUIPPED) for only the equipped items of that type, ending with 0xff (LIST_ORDER_END). The item types: 0 usable items, 1 weapons, 2 armor, 3 shields, gloves and armlets, 4 helmets, 5 boots, 6 Psynergy items, 8 rings and 9 shirts.
Used by Menu_CopyListOrder.
gItemMenu_CommandColumnXTable
s32 gItemMenu_CommandColumnXTable[6]
The x of the item command cursor, three columns on each of two rows.
Used by ItemMenu_CommandCursorX.
gFourObjectMotion_ResourceIds
s32 gFourObjectMotion_ResourceIds[4]
The resource ids of the four sprites FourObjectMotion shows.
Used by FourObjectMotion_InitializeBottomRow, FourObjectMotion_InitializeTopRow, FourObjectMotion_ReplaceSlot.
Also, globals without a comment: gUiMenu_CursorBobY, gMenu_ListOrderMode2, gMenu_ListOrderMode1, gMenu_ListOrderMode0, gCharacterMenu_CursorWidths, gCharacterMenu_CursorWidths, gCharacterMenu_CursorWidths.
title.c
The title overlay: the Golden Sun logo and its sprites revealed over the title screen.
Functions
Title_GetPlacements
u8 *Title_GetPlacements(void)
The title overlay has no placed field actors.
Title_GetEvents
u8 *Title_GetEvents(void)
The title overlay has no field events.
Title_Run
s32 Title_Run(void)
Routes the logo, completion presentation and new-game title entrances.
Title_LoadSprites
static void Title_LoadSprites(s32 unused)
Decodes the language-specific title sprites and uploads their palette and tiles.
Used by Title_RevealScreen.
Title_UpdateSpriteReveal
static void Title_UpdateSpriteReveal(void)
Reveals successive sprite columns, flickering each newly reached column.
Used by Title_RevealScreen.
Title_RevealScreen
static void Title_RevealScreen(s32 unused)
Prepares the logo, reveals its sprites and then opens the screen transition.
Used by Title_Run.
Title_LoadBackground
static void Title_LoadBackground(void)
Loads the logo palette and tiles, builds its tilemap and resets scrolling.
Used by Title_RevealScreen.
Also, functions without a comment: Title_GetEntrances, SceneData_ReturnZero, Title_GetExits.
Globals, without a comment: gTitleEntrances, gTitleExits, gTitlePlacements, gTitleEvents, gTitleVramBlock.
title.h
Structures
TitleSprite
struct TitleSprite
The title overlay's sprite records, three OAM words each.
| Field | Declared as | |
|---|---|---|
attr | u32 attr[3] |
Used by Title_UpdateSpriteReveal, gTitleSprites.
Macros
LOGO_BLANK_TILE
#define LOGO_BLANK_TILE 0x1ff
The map entry after each row's 30 visible tiles.
Used by Clear_LoadBackground, Title_LoadBackground.
Also, macros without a comment: LOGO_BGCNT, LOGO_MAP, LOGO_FIRST_TILE, LOGO_TILES.
Globals, without a comment: gTitleRevealFrame, gTitleSprites.