Alchemy

menu

games/tbs/src/menu on GitHub

The Menus guide explains this folder.

Folders

clear.c

games/tbs/src/menu/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.

Line 135

Clear_LoadBackground

static void Clear_LoadBackground(void)

Loads the Golden Sun logo, maps its tiles and resets background scroll.

Used by SaveMenu_Run.

Line 146

Clear_UpdateBlend

static void Clear_UpdateBlend(void)

Advances the logo blend every two frames and removes itself at completion.

Used by SaveMenu_Run.

Line 195

Clear_CheckButtonCodes

static void Clear_CheckButtonCodes(void)

Tracks two hidden key sequences, requiring a full release after each key.

Used by SaveMenu_Run.

Line 238

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.

Line 283

Clear_GetSaveRecoveryBlockMask

static s32 Clear_GetSaveRecoveryBlockMask(void)

Returns -1 when the flagged saved scene blocks recovery, otherwise zero.

Used by SaveMenu_Run.

Line 341

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.

Line 372

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.

Line 855

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.

Line 885

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.

Line 946

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.

Line 1155

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.

Line 1207

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.

FieldDeclared as
unk000u8 unk000[0x100]
word100s32 word100frames

Used by SaveMenu_Run.

Line 356

SaveLinkGreeting

struct SaveLinkGreeting

A linked console's signature: four letters naming its language and game.

FieldDeclared as
codeu16 code[4]
reservedu8 reserved[16]

Used by SaveMenu_Run.

Line 362

PasswordStats

struct PasswordStats

A party member's base stats, which the password clamps and packs.

FieldDeclared as
baseHps16 baseHp
basePps16 basePp
unk14u8 unk14[4]
baseAttacku16 baseAttack
baseDefenseu16 baseDefense
baseAgilityu16 baseAgility
baseLucku8 baseLuck

Used by Clear_PackPasswordData.

Line 921

PasswordOwner

struct PasswordOwner

A party member as the password reads them: their level, base stats, inventory and Djinn.

FieldDeclared as
unk00u8 unk00[0x0f]
levelu8 level
statsstruct PasswordStats stats
unk20u8 unk20[0xb8]
inventoryu16 inventory[15]
unkf6u8 unkf6[2]
djinnAvailableu32 djinnAvailable[4]

Used by Clear_PackPasswordData.

Line 933

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

games/tbs/src/menu/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.

Line 126

LinkLobby_SelectPlacements

s32 LinkLobby_SelectPlacements(void)

Selects the post-link-battle placements for entrances nine and eleven.

Line 144

LinkLobby_PeerSlotMatches

static s32 LinkLobby_PeerSlotMatches(s32 slot)

Checks one language-specific peer signature slot and updates link-side flags.

Line 155

LinkLobby_WriteSlotValue

static void LinkLobby_WriteSlotValue(s32 slot)

Publishes a protocol slot value in the outgoing signature payload.

Line 187

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.

FieldDeclared as
valuess32 values[6]

Used by LinkLobby_PeerSlotMatches.

Line 105

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.

games/tbs/src/menu/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.

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_EXPERIENCE0class, HP, PP and experience
STATUS_PANEL_EQUIP2stats if the item were equipped
STATUS_PANEL_LEARN4the Psynergy a Psynergy item teaches
STATUS_PANEL_CLASS6class, HP and PP
STATUS_PANEL_STATS8Attack, Defense, Agility and Luck

Line 99

DjinnCompareOperation

enum DjinnCompareOperation

The preview loop's four operations, as its confirmation text describes them.

Value=
DJINN_COMPARE_TRADE0
DJINN_COMPARE_GIVE1
DJINN_COMPARE_STANDBY2
DJINN_COMPARE_SET3

Line 140

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.

Line 79

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.

Line 84

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.

Line 86

#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.

Line 89

#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.

Line 92

#define MENU_ITEM_GRID_COLUMNS 5

Inventory icons occupy five columns in the fifteen-slot list.

Used by ItemMenu_HidePageIcons, ItemMenu_RefreshEntry.

Line 95

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.

Line 109

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.

Line 133

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.

Line 137

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.

games/tbs/src/menu/menudata.c

Globals

gUiMenu_CursorBobX

u8 gUiMenu_CursorBobX[9]

The hand cursor's bobbing offsets, indexed by (gFrameCount >> 1) & 7.

Used by UiMenu_PositionCursor.

Line 12

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.

Line 21

gItemMenu_CommandColumnXTable

s32 gItemMenu_CommandColumnXTable[6]

The x of the item command cursor, three columns on each of two rows.

Used by ItemMenu_CommandCursorX.

Line 37

gFourObjectMotion_ResourceIds

s32 gFourObjectMotion_ResourceIds[4]

The resource ids of the four sprites FourObjectMotion shows.

Used by FourObjectMotion_InitializeBottomRow, FourObjectMotion_InitializeTopRow, FourObjectMotion_ReplaceSlot.

Line 55

Also, globals without a comment: gUiMenu_CursorBobY, gMenu_ListOrderMode2, gMenu_ListOrderMode1, gMenu_ListOrderMode0, gCharacterMenu_CursorWidths, gCharacterMenu_CursorWidths, gCharacterMenu_CursorWidths.

title.c

games/tbs/src/menu/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.

Line 55

Title_GetEvents

u8 *Title_GetEvents(void)

The title overlay has no field events.

Line 58

Title_Run

s32 Title_Run(void)

Routes the logo, completion presentation and new-game title entrances.

Line 61

Title_LoadSprites

static void Title_LoadSprites(s32 unused)

Decodes the language-specific title sprites and uploads their palette and tiles.

Used by Title_RevealScreen.

Line 137

Title_UpdateSpriteReveal

static void Title_UpdateSpriteReveal(void)

Reveals successive sprite columns, flickering each newly reached column.

Used by Title_RevealScreen.

Line 171

Title_RevealScreen

static void Title_RevealScreen(s32 unused)

Prepares the logo, reveals its sprites and then opens the screen transition.

Used by Title_Run.

Line 241

Title_LoadBackground

static void Title_LoadBackground(void)

Loads the logo palette and tiles, builds its tilemap and resets scrolling.

Used by Title_RevealScreen.

Line 279

Also, functions without a comment: Title_GetEntrances, SceneData_ReturnZero, Title_GetExits.

Globals, without a comment: gTitleEntrances, gTitleExits, gTitlePlacements, gTitleEvents, gTitleVramBlock.

title.h

games/tbs/src/menu/title.h

Structures

TitleSprite

struct TitleSprite

The title overlay's sprite records, three OAM words each.

FieldDeclared as
attru32 attr[3]

Used by Title_UpdateSpriteReveal, gTitleSprites.

Line 7

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.

Line 22

Also, macros without a comment: LOGO_BGCNT, LOGO_MAP, LOGO_FIRST_TILE, LOGO_TILES.

Globals, without a comment: gTitleRevealFrame, gTitleSprites.

On this page