Alchemy

window

games/tbs/src/window on GitHub

The Windows guide explains this folder.

Folders

articles.c

games/tbs/src/window/articles.c

Globals

gUiText_ArticleTable

const s8 *const gUiText_ArticleTable[8]

The article of each article class.

Line 25

gUiText_NumberWord0

const u8 gUiText_NumberWord0[]

Counted nouns, each plural before its singular; gUiText_NumberWords (graphics/text/numwords.c) pairs them as {singular, plural}. "K\xe4pfe" is the ROM's spelling of K\xe4mpfe.

Used by gUiText_NumberWords.

Line 34

gUiText_ItemPossessives

const s8 *const gUiText_ItemPossessives[4]

The possessive ("your") for each item gender (gUiText_ItemGenders).

Line 49

gUiText_ArticleTable

const s8 *const gUiText_ArticleTable[5]

The definite article of each article class.

Line 66

gUiText_IndefiniteArticles

const s8 *const gUiText_IndefiniteArticles[5]

The indefinite article of each article class.

Line 76

gUiText_ItemPossessives

const s8 *const gUiText_ItemPossessives[2]

The possessive ("your") for {singular, plural}.

Line 84

gUiText_ArticleTable

const s8 *const gUiText_ArticleTable[8]

The article of each article class.

Line 102

gUiText_ArticleTable

const s8 *const gUiText_ArticleTable[11]

The article of each article class.

Line 125

gUiText_ItemPossessives

const s8 *const gUiText_ItemPossessives[4]

The possessive ("your") for each item gender (gUiText_ItemGenders).

Line 135

gUiText_ArticleTable

const s8 *const gUiText_ArticleTable[8]

The article of each article class.

Line 152

gUiSprite_CursorBobOffsets

const u8 gUiSprite_CursorBobOffsets[80]

The pointing hand's bob: a smooth rise and fall of 8 pixels over 80 frames.

Used by UiWork_AnimateSpriteSlots.

Line 175

gUiSprite_WobbleOffsets

const s8 gUiSprite_WobbleOffsets[40]

A swing along an arc of radius 4, as {x, y} pairs: x runs 0, 4, 0, -4, 0 while y rises at each side.

Used by UiWork_AnimateSpriteSlots.

Line 185

gUiSprite_WobbleTail

const u8 gUiSprite_WobbleTail[16]

Nothing in the game reads these 16 bytes.

Line 194

gUiSprite_BounceOffsets

const u8 gUiSprite_BounceOffsets[16]

A hop of up to 8 pixels over 16 frames.

Used by UiWork_AnimateSpriteSlots.

Line 199

Also, globals without a comment: gUiText_ArticleEmpty, sArticleEin, sArticleEine, sArticleDie, sArticleDas, gUiText_NumberWord1, gUiText_NumberWord2, gUiText_NumberWord3, gUiText_NumberWord4, gUiText_NumberWord5, gUiText_NumberWord6, gUiText_NumberWord7, gUiText_NumberWord8, gUiText_NumberWord9, sPossessiveDein, sPossessiveDeine, gUiText_ArticleEmpty, sArticleEl, sArticleLa, sArticleLos, sArticleLas, sArticleUn, sArticleUna, sArticleUnos, sArticleUnas, sPossessiveTu, sPossessiveTus, gUiText_ArticleEmpty, sArticleLe, sArticleLa, sArticleL, sArticleLes, sArticleUn, sArticleUne, sArticleDes, gUiText_ItemPronoun, gUiText_ArticleEmpty, sArticleIl, sArticleL, sArticleLa, sArticleLo, sArticleLe, sArticleGli, sArticleUn, sArticleUnElided, sArticleUno, sArticleUna, sPossessiveIlTuo, sPossessiveLaTua, gUiText_ArticleEmpty, sArticleA, sArticleAn, sArticleSome, sArticleThe, gUiText_MarkGlyphCodes.

battle_command.c

games/tbs/src/window/battle_command.c

The menu object of the window bank: the screens built on the window system (window.c). It holds the party status window, the save file menu, the name entry screen, the joined-party messages, the command icon row, the Djinn change preview and the status screen, the battle menus (Djinn, summons, items, Psynergy, targets and the party's commands), the command icon menus of the field and title screens, and the debug menus.

battle_command_internal.h holds what every part shares (includes, edition values, macros and the link round state); the code is in the files under battle_command/, 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 family ends and the next begins. README.md in this folder gives the words, prefixes and spellings the parts use. Where to start:

  Party status    party_status.c: UiWindow_CreateWithLayoutBounds,
                  PartyStatusDraw
  Saving          save.c: SaveMenu_SelectSlot, Save_WriteSelectedSlot
  Battle menus    party_commands.c: Battle_CollectPartyCommands, which
                  runs command_row.c: Menu_RunCommandRow and the menus
                  of djinn_menu.c, summon_menu.c, item_menu.c,
                  psynergy_menu.c and targets.c
  Icon menus      icon_menu.c: Menu_SelectTopEntry,
  Menu_SelectSaveSlotAction

battle_command_internal.h

games/tbs/src/window/battle_command_internal.h

Structures

SelectionEntry

struct SelectionEntry

The command icon row's work block and one of its icons: pictures.c loads the icons, command_row.c runs the row.

FieldDeclared as
spritestruct MenuSprite sprite
resource, unusedu16 resource, unused
posX, posYs32 posX, posY
kinds32 kind

Used by Menu_RunCommandRow.

Line 298

SelectionWork

struct SelectionWork

The command icon row's work block: the icons' shared palette, up to six icons, the label window, the pulsing icon's transform and the selection.

FieldDeclared as
palettestruct GlyphPalette palette
entriesstruct SelectionEntry entries[6]
windowstruct UiWindow *window
iconCounts32 iconCount
affinestruct AffineTransform affine
affineIndex, selectedIndex, drawnIndexs32 affineIndex, selectedIndex, drawnIndex
commandKindss32 commandKinds[6]

Used by Menu_RunCommandRow.

Line 307

Macros

OUTPUT_SIZE_16X16

#define OUTPUT_SIZE_16X16 0x40000000

OAM attribute bits a sprite output is created with: the size field of attribute 1 (bits 30-31 of the first word). A square sprite of size 1 is 16x16 pixels, of size 2 32x32.

Used by NameEntry_EditOwnerName, PartyTalkMenu_Choose, RenderOutput_CreateFromResource, RenderOutput_CreateFromTable, RenderOutput_CreateLoaded, RenderOutput_CreateWithTransform, SaveMenu_SelectSlot.

Line 265

Also, macros without a comment: DJINN_PREVIEW_VITALS_X, DJINN_PREVIEW_VITALS_X, DJINN_PREVIEW_STAT_DIGIT_OFFSET, DJINN_PREVIEW_STAT_X, DJINN_PREVIEW_STAT_DIGIT_OFFSET, DJINN_PREVIEW_STAT_X, DJINN_PREVIEW_HELP_X, DJINN_PREVIEW_HELP_X, PSYNERGY_COST_SECOND_TILE, PSYNERGY_COST_SECOND_TILE, OWNER_STATUS_LEVEL_X, OWNER_STATUS_LEVEL_X, SUMMON_MENU_WINDOW_X, SUMMON_MENU_WINDOW_WIDTH, SUMMON_MENU_WINDOW_X, SUMMON_MENU_WINDOW_WIDTH, BATTLE_CLASS_ICON_X, BATTLE_CLASS_ICON_X, BATTLE_COMMAND_NAME_X, BATTLE_COMMAND_NAME_X, BATTLE_SUMMON_ICON_X, BATTLE_SUMMON_ICON_X, BATTLE_SUMMON_WINDOW_WIDTH, BATTLE_SUMMON_WINDOW_WIDTH, BATTLE_SUMMON_ELEMENT_COLUMN, BATTLE_SUMMON_COST_COLUMN, BATTLE_SUMMON_ELEMENT_COLUMN, BATTLE_SUMMON_COST_COLUMN, BATTLE_ITEM_WINDOW_WIDTH, BATTLE_ITEM_WINDOW_WIDTH, RESOURCE_MODE0_WINDOW_X, RESOURCE_MODE0_WINDOW_WIDTH, RESOURCE_MODE0_WINDOW_X, RESOURCE_MODE0_WINDOW_WIDTH, RESOURCE_MODE0_WINDOW_X, RESOURCE_MODE0_WINDOW_WIDTH, RESOURCE_MODE0_WINDOW_X, RESOURCE_MODE0_WINDOW_WIDTH, RESOURCE_MODE1_WINDOW_X, RESOURCE_MODE1_WINDOW_WIDTH, RESOURCE_MODE1_WINDOW_X, RESOURCE_MODE1_WINDOW_WIDTH, TRANSFER_METHOD_WINDOW_X, TRANSFER_METHOD_WINDOW_WIDTH, TRANSFER_METHOD_WINDOW_X, TRANSFER_METHOD_WINDOW_WIDTH, TRANSFER_METHOD_WINDOW_X, TRANSFER_METHOD_WINDOW_WIDTH, TRANSFER_METHOD_WINDOW_X, TRANSFER_METHOD_WINDOW_WIDTH, TRANSFER_METHOD_LABEL_X, TRANSFER_METHOD_LABEL_X, TRANSFER_HELP_WINDOW_X, TRANSFER_HELP_WINDOW_WIDTH, TRANSFER_HELP_WINDOW_X, TRANSFER_HELP_WINDOW_WIDTH, TRANSFER_HELP_WINDOW_X, TRANSFER_HELP_WINDOW_WIDTH, ENTRY11_COMMAND_LABEL_WIDTH, ENTRY11_COMMAND_LABEL_WIDTH, ENTRY11_COMMAND_LABEL_WIDTH, ENTRY19_COMMAND_LABEL_WIDTH, ENTRY19_COMMAND_LABEL_WIDTH, OUTPUT_SIZE_32X32, PORTRAIT_SLOT_COUNT, PORTRAIT_PALETTE, PORTRAIT_SLOT_EMPTY, BATTLE_MENU_MESSAGE_CAPACITY, BATTLE_MENU_MESSAGE_COPY, BATTLE_MENU_MESSAGE_CAPACITY, BATTLE_MENU_MESSAGE_COPY, BATTLE_OK.

Globals, without a comment: gDjinnMenu_BlinkTile, gDjinnMenu_ElementXOffsets, gDjinnMenu_ElementYOffsets.

Declarations, without a comment: UiText_RenderWideStringInWindow.

glyph_arm.c

games/tbs/src/window/glyph_arm.c

Functions

UiText_SetCanvasPixel

static __inline__ void UiText_SetCanvasPixel(u32 windowHeight, u32 x, u32 tileY, u32 doubledPixelRow, u8 *canvas, u32 repeatedColor)

Sets one pixel in the column-major text canvas. windowHeight includes the two frame rows; doubledPixelRow is twice the row within a tile. repeatedColor holds the colour index in all four nibbles.

Used by UiText_DrawGlyphArm.

Line 24

UiText_DrawGlyphArm

s32 UiText_DrawGlyphArm(struct UiWindow *window, u32 character, u32 x, u32 y, const u8 *font)

Draws one character into a window's text canvas with its top-left corner at pixel (x, y) of the window's interior, and returns how far the text advances.

With font set, the character comes from that small font: the 10-row, 1bpp kana and numeral font in Japanese, or an 8x8 two-colour font elsewhere. With no font, it comes from the main font (gUiText_Glyphs, and in Japanese gUiText_KanjiGlyphs for codes from 256), drawn in four passes: the first three draw an outline in colour 5 (offset left, right and down when the window has UI_WINDOW_OUTLINED_TEXT) and the last draws the glyph itself in colour 1. In Japanese, kana marks (codes 222 and 223) sit over the previous character and advance by 0.

Used by UiText_DrawGlyph.

Line 49

Tile_BuildMetatiles

void Tile_BuildMetatiles(u16 *scanlineBounds, u16 *frameTiles)

Builds the hardware window's horizontal extent for each of the screen's 160 scanlines from frameTiles in the UI tilemap (32 tiles a row, 30 shown). Each scanline gets (left << 8) | right, the WINxH format, written to the second halfword of its pair in scanlineBounds. A row without a frame gets 0. The rounded corner tiles trim the first or last scanline of a row by one pixel on that side, so the window follows the frame's rounded corners.

Used by UiWindow_FillFromScene.

Line 286

Macros, without a comment: TEXT_CANVAS_PIXEL_HEIGHT, SCREEN_TILE_ROWS, SCREEN_TILE_COLUMNS.

scales.c

games/tbs/src/window/scales.c

Globals

gUi_BounceScalesTail

const s8 gUi_BounceScalesTail[8]

Nothing in the game reads these eight offsets.

Line 18

gMenu_CursorBobOffsets

const s8 gMenu_CursorBobOffsets[16]

The selection cursor's bob: a 16-step wave of up to 3 pixels each way.

Used by SelectionScreen_Draw.

Line 23

gPaletteGlow_WaveTable

const u8 gPaletteGlow_WaveTable[121]

The window colour wheel: one colour channel's level (0 to 31) over 96 hue steps. Red reads it at the hue, green 32 steps later and blue 64 steps later. Nothing reads the 25 entries after the first 96.

Used by PaletteGlow_Update, WindowColor_ComputeTint.

Line 30

gOptionMenu_SpeedFrames

const s8 gOptionMenu_SpeedFrames[3]

The option screen's sprite frames for each setting's choices: message speed Slow, Normal and Fast; Speech Off and On; Auto-Sleep Off and On.

Used by Menu_RunWorkspaceOptions, OptionMenu_Open.

Line 43

gOptionMenu_HuePresets

const u8 gOptionMenu_HuePresets[6]

The window colour presets SELECT cycles through on the option screen: the colour (hue) and the brightness of each.

Used by Menu_RunWorkspaceOptions.

Line 57

gMenu_WorkspaceIconFrames

const s8 gMenu_WorkspaceIconFrames[8]

The sprite frame of each entry's icon in the system menu (Save your quest, Sleep, Change settings, and the debug entries after them).

Used by Menu_RunWorkspaceSelectionLoop, SystemMenu_Open.

Line 67

gPortrait_CharacterMap

const s16 gPortrait_CharacterMap[20]

{character, portrait} pairs of the playable characters, ending in -1.

Used by Localization_LookupEntryId.

Line 72

gPortrait_SpriteMap

const s16 gPortrait_SpriteMap[100]

{sprite, portrait} pairs of the other speakers, ending in -1: portrait n of this list is portrait 128 + n.

Used by Localization_LookupEntryId.

Line 87

Also, globals without a comment: gUi_BounceScales, gOptionMenu_SpeechFrames, gOptionMenu_SleepFrames, gOptionMenu_BrightnessPresets.

text_speed.c

games/tbs/src/window/text_speed.c

Globals

gUiText_SpeedDelays

const u8 gUiText_SpeedDelays[3]

Frames to wait after each glyph while no button is held.

Used by UiWork_StepChannelScript.

Line 8

gUiText_SpeedSteps

const u8 gUiText_SpeedSteps[3]

Glyphs a message channel draws each frame.

Used by UiWork_StepChannelScript.

Line 10

gUiText_SpeedCueGaps

const u8 gUiText_SpeedCueGaps[3]

Glyphs between two of the speaker's voice blips.

Used by UiWork_StepChannelScript.

Line 12

window.c

games/tbs/src/window/window.c

The window object: the UI windows drawn into a shared BG tilemap, the message channels that type text into them, the message decoder and the formatting behind it, the sprites (render outputs) that windows carry, icons, the selection screen and the option and system menus.

Everything lives in one work block, struct UiRenderWork (heap slot HEAP_SLOT_WINDOW, reached as UI_WORK): the tilemap, the window slots, three message channels, a pool of 64 render outputs and the decoded text.

window_internal.h holds what every part shares (includes, edition values and macros); the code is in the files under window/, 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 family ends and the next begins. README.md in this folder gives the words, prefixes and spellings the parts use. Where to start:

  Windows         windows.c: UiWindow_Create, UiWork_Finalize;
                  frames.c: UiWindow_DrawFrame, UiWork_ProcessDirectWork
  Messages        frames.c: UiText_OpenMessageWindow,
                  UiText_ShowPositionedMessageAndWait; typing.c:
                  UiWork_StepChannelScript; decode.c:
                  UiText_BuildRenderEntries
  Text drawing    sprites.c: UiText_DrawGlyph; text_tiles.c:
                  UiText_RenderStringTiles, UiText_DrawString
  Screens         selection.c: Menu_SelectionLoop, Menu_RunTopSelection;
                  options.c: Menu_RunWorkspaceOptions,
                  Menu_RunWorkspaceSelectionLoop

window_internal.h

games/tbs/src/window/window_internal.h

Macros

NO_GLYPH_RESOURCE

#define NO_GLYPH_RESOURCE 99

A glyph resource id meaning no glyph resource is loaded.

Used by UiText_DrawGlyph, UiWindow_PutGlyph, UiWork_Initialize, UiWork_InitializeWithResourceCounters, UiWork_StepChannelScript.

Line 126

UI_WINDOW_EFFECT_SWELL

#define UI_WINDOW_EFFECT_SWELL 4

The window effect a message can start (TEXT_WINDOW_STATE): the window's frame grows by a tile and its text sprites pulse, for the channel's countdown.

Used by UiWindow_StepSwellEffect, UiWork_AnimateSpriteSlots.

Line 180

TEXT_WORK_BLOCK

#define TEXT_WORK_BLOCK 50

The heap block the message decoder routine is copied into to run.

Used by UiText_DecodeMessage.

Line 187

Also, macros without a comment: ITEM_POSSESSIVE_TEXT_COUNT, ITEM_POSSESSIVE_TEXT_COUNT, TEXT_ARGUMENT_SPACE, TEXT_ARGUMENT_SPACE, UI_SPRITE_SPACE_WIDTH, UI_SPRITE_SPACE_WIDTH, UI_MESSAGE_CHANNEL_COUNT, UI_MESSAGE_LINE_COUNT, UI_TEXT_DEFAULT_COLOUR, UI_TEXT_DEFAULT_LINE_SPACING, UI_TILEMAP_PALETTE, UI_WINDOW_OPEN_FRAMES, UI_WINDOW_CLOSE_FRAMES, UI_PALETTE_SLOT_FREE, UI_CANVAS_BACKGROUND_WORD, UI_NUMBER_BUFFER_SIZE, UI_BYTE_STRING_BUFFER_SIZE, UI_MESSAGE_NAME_HALFWORDS, UI_ARGUMENT_SLOT_COUNT, UI_SELECTION_ENTRY_LIMIT, UI_AREA_NOTICE_FRAMES, TEXT_CODE_MARK_SHIFT, TEXT_CODE_VOICED, TEXT_CODE_SEMIVOICED.

Globals

gGlyphWork

extern GlyphTransfer *gGlyphWork

The glyph transfer work in IWRAM (system/iwram.s), which icons are built in.

Used by ItemIcon_Compose, Ui_PrepareTransferForItem, Ui_PrepareTransferFromTableEntry.

Line 190

Text_MessageContexts

extern const void *const Text_MessageContexts[][2]

Each message context bank's Huffman models and their offsets, which the message catalog built from games/tbs/text defines.

Used by UiText_DecodeSymbol.

Line 194

On this page