Battle menu
The battle command menu in bank $C1 ($C1:0785–$C1:1C49, plus BattleMenu_BuildTargetList at
$C1:1F79): the per-PC command windows, the tech and item lists, the input handlers for each
window, the queue of PCs waiting for a command, and the cursor sprites. It runs with M=1, X=0,
DP=0 and DB=$7E, like the rest of the battle.
See also: Battle targeting, Status bar & text, Battle engine.
The rebuild chain
The menu is not redrawn every frame: it rebuilds only on frames where !BattleMenu_Dirty is set.
Three routines gate it the same way: BattleMenu_RefreshIfDirtyL ($C1:10E3, the JSL form),
BattleMenu_RefreshIfDirtyAndTick ($C1:10FA, which also runs a per-frame service tick and is
called after each frame wait of an action) and BattleSys_UpkeepTwoFrames (service 3). Each one
clears the flag and runs the chain:
BattleMenu_DequeueReadyBattler: take the next PC off the ready queue;BattleMenu_UpdateWindows($C1:0C2D): window upkeep by submenu: the main command window (BattleMenu_UpdateMainWindow), the tech window (BattleMenu_UpdateTechWindow, with the MP check of each visible tech inBattleMenu_UpdateTechMpAvail), or the item window;BattleMenu_ProcessInput($C1:1153): the command window's input;BattleMenu_UpdateCursorOverlay($C1:17DD, 828 bytes): draw whichever cursor belongs on screen now: none, the target cursor(s), the tech-list cursor (a 2–3 sprite cluster over the partners for a double or triple tech) or the item-list cursor and scroll arrows.
The ready queue
Services 1 and 2 of the battle's service dispatcher manage the PCs waiting for a command:
BattleMenu_EnqueueReadyBattler ($C1:1B19) marks the PC's command record "waiting for a
command", appends it to !BattleMenu_ReadyQueue and plays sound $42 (inferred: the "turn ready"
cue); BattleMenu_RemoveBattlerFromReady ($C1:1BAA) is its inverse.
BattleMenu_DequeueReadyBattler pops the head (up to 3 deep) into the roster of PCs shown in the
menu. BattleMenu_CycleActivePcPrev / Next switch between the roster's PCs.
Windows and lists
- Command window:
BattleMenu_DrawCommandListandBattleMenu_DrawCommandWindowFrames($C1:0785–$C1:095C) draw each roster PC's commands;BattleMenu_LoadCommandWindowMapcopies the window map from ROM.BattleMenu_CursorUp/Downmove between rows;BattleMenu_ConfirmCommanddispatches row 0 (attack,BattleMenu_ChooseAttack), row 1 (tech,BattleMenu_OpenTechList) and row 2 (item,BattleMenu_OpenItemList). - Tech list (submenu 1):
BattleMenu_RenderTechListRows/RenderTechRowcopy tech names from the tables in bank$CC;BattleMenu_TechListInput($C1:1320) withTechListPrev/Next,TechConfirmandTechListCancel. - Item list (submenu 2):
BattleMenu_RenderItemListRows/RenderItemRow;BattleMenu_ItemListInput($C1:143D) with cursor, page and scroll handlers,ItemConfirmandItemListCancel.
Choosing a target and committing
Confirming an attack, tech or item builds the target list (BattleMenu_BuildTargetList, see
Battle targeting) and switches to target selection, whose input is
BattleMenu_TargetSelectInput ($C1:1561; BattleMenu_TargetNext / Prev cycle the cursor).
Confirming a target runs BattleMenu_CommitAction ($C1:161A): it fills the PC's BattleCmd
record (kind $80 attack, $20 tech, $40 item; the partners; the action id; the first
selected target), consumes the partners of a double or triple tech
(BattleMenu_ConsumePartnerSlot) so they do not act too, decrements the item's quantity,
appends the PC to !Battle_CmdQueue and shows the next roster entry. The battle's turn handler
later runs the command (see Battle engine).
Functions
| Address | Function | Size | Status | Notes |
|---|---|---|---|---|
$C1:0785 | BattleMenu_ | 153 | verified | Draw the command list of PC slot A (6 rows × 7 columns) into the status map at offset slot × 12, from one of two ROM tile tables: !BattleRom_CmdListTech — "Attack", "Tech", "Item" on rows 1/3/5... |
$C1:081E | BattleMenu_ | 84 | verified | Draw the 7×6 command-window frame of every PC in the roster into !BattleMenu_WindowMap, then highlight the shown PC's name and fall into BattleUI_ClearActivePanelColumn. |
$C1:0929 | BattleMenu_ | 52 | verified | Copy one 7-column × 6-row command-window frame (corners, borders and fill) from !BattleRom_CommandWindowFrame into !BattleMenu_WindowMap at !BattleUI_MapOffset. |
$C1:095D | BattleMenu_ | 83 | verified | Renders the 3 visible item-list lines: 1. |
$C1:09B0 | BattleMenu_ | 215 | verified | , then its RTS BattleMenu_RenderItemRow_Exit (1 byte, $0A87) Renders one item-list line for the Item_BattleList record at !BattleMenu_ItemRecOffset into the item map at !BattleMenu_RowMapOffset. |
$C1:0A87 | BattleMenu_ | 1 | verified | |
$C1:0A88 | BattleMenu_ | 75 | verified | Renders 4 tech-list lines (2 per outer loop pass) for the active PC into the tech text buffer (BattleMenu_TechTextTile). |
$C1:0AD3 | BattleMenu_ | 56 | verified | Builds !Tech_ListAvail (20 entries, one per list line) for the active PC's tech list: line code $FB-$FF (blank, header or skip line) → 0, anything else → 1. |
$C1:0B0B | BattleMenu_ | 171 | verified | Renders one tech-list line: blanks the text rows (!BattleMsg_TextTiles / TextTopTiles), fills them by the line code !Tech_ListCode[TechCodeIdx], and copies them into the tech text buffer at... |
$C1:0BB6 | BattleMenu_ | 29 | verified | Blank-line / header exit path of BattleMenu_RenderTechRow: advances !BattleMenu_TechRowNum, blanks the lead cells, then copies 18 lower-row tiles from !BattleMsg_TextTiles into the line from col 3... |
$C1:0BD3 | BattleMenu_ | 45 | verified | Blanks cols 3-5, the lead cells left of the name (which starts at col 6), on both rows of the tech-list line at !BattleMenu_RowMapOffset (blank tile, palette 3). |
$C1:0C00 | BattleMenu_ | 45 | verified | Tech-name exit path of BattleMenu_RenderTechRow (reached by its tail JMP): blanks cols 17-20 (right of the 11-tile name) on both rows of the line (blank tile, palette 3); the mirror of... |
$C1:0C2D | BattleMenu_ | 25 | verified | Per-frame window upkeep dispatcher. |
$C1:0C46 | BattleMenu_ | 3 | verified | |
$C1:0C49 | BattleMenu_ | 58 | verified | Main command-window upkeep (submenu 0): - If !BattleMenu_RosterIdx differs from !BattleMenu_RosterIdxDrawn: reload the command window map and rebuild the status bar. |
$C1:0C83 | BattleMenu_ | 471 | verified | Tech-window refresh (submenu 1, after UpdateTechMpAvail): 1. |
$C1:0E5A | BattleMenu_ | 96 | verified | Clears the cursor columns, then (unless a target is being selected) draws the 2×2 row cursor ($60-$63) at the shown PC's !Pc_TechRow, placed through !BattleRom_TechCursorCell. |
$C1:0EBA | BattleMenu_ | 39 | verified | Blanks cols 1-2 (the row-cursor columns) of all 6 tech-window rows. |
$C1:0EE1 | BattleMenu_ | 348 | verified | Grades the 3 visible tech-list lines (submenu 1) and colours each line in the window map: palette 2 = usable, palette 3 = greyed. |
$C1:103D | BattleMenu_ | 1 | verified | Shared RTS, also the JMP target of BattleMenu_UpdateMainWindow, BattleMenu_DrawTechCursorRow and BattleMenu_UpdateWindows_Exit. |
$C1:10E3 | BattleMenu_ | 23 | verified | JSL-entry twin of BattleMenu_RefreshIfDirtyAndTick, reached via the bank's cross-bank entry-vector table: JSL $C10012 -> JMP $C110E3. |
$C1:10FA | BattleMenu_ | 27 | verified | Same-bank JSR twin of BattleMenu_RefreshIfDirtyL — identical dirty- flag gate and menu rebuild chain, but always follows up with a cross-bank per-frame service tick (BattleSys_FrameTickVec) before... |
$C1:1115 | BattleMenu_ | 62 | verified | Builds OAM sprites 0-3 (BattleOam) for the command cursor over the shown PC: each of the 4 template sprites in BattleRom_CursorSprite is offset by the PC's !Battler_ScreenX/Y, and its palette bits... |
$C1:1153 | BattleMenu_ | 142 | verified | Battle command-window input handler. |
$C1:11E1 | BattleMenu_ | 55 | verified | Left D-pad: step !BattleMenu_RosterIdx back (wrap 0..2), skipping roster entries that are negative. |
$C1:1218 | BattleMenu_ | 56 | verified | Right D-pad: mirror of CycleActivePcPrev — steps !BattleMenu_RosterIdx forward (wrap at 3 back to 0) instead; the same sound 0 and the same cursor-memory handling. |
$C1:1250 | BattleMenu_ | 20 | verified | Up D-pad: step the shown PC's !Pc_MenuRow back (wrap 0..2) and flag the cursor redraw (!BattleUI_PanelRedraw). |
$C1:1264 | BattleMenu_ | 23 | verified | Down D-pad: step the shown PC's !Pc_MenuRow forward (wrap at 3 back to 0) and flag the cursor redraw (!BattleUI_PanelRedraw). |
$C1:127B | BattleMenu_ | 33 | verified | Confirm-button dispatch: sets !BattleUI_UnkA0D7 to $FF (compared by BattleUI_BuildStatusBarFrame with the first selected target), calls BattleFx_SetPtrA2FromTable for the shown PC, then tail-jumps... |
$C1:129C | BattleMenu_ | 32 | verified | Row 0 (Attack) confirm: message call with "none", flags the cursor redraw, sets !BattleTgt_Mode = attack, !BattleMenu_CmdMenu = 0, builds the target list, sets !BattleMenu_TargetMoved (so... |
$C1:12BC | BattleMenu_ | 49 | verified | Row 1 (Tech) confirm: unless !BattleMenu_Lock bit 0 is set, renders the tech list lines, builds !Tech_ListAvail, switches to the tech list (!BattleMenu_Submenu = !BattleMenu_CmdMenu = 1) and... |
$C1:12ED | BattleMenu_ | 51 | verified | Row 2 (Item) confirm: unless !BattleMenu_Lock is non-zero, renders the item list at !BattleMenu_ItemScroll, queues the item map upload, copies the item box frame (!BattleRom_ItemBoxMap) into... |
$C1:1320 | BattleMenu_ | 73 | verified | Per-frame input handler while the tech list is open (submenu 1). |
$C1:1369 | BattleMenu_ | 38 | verified | Confirms the highlighted tech: aborts unless the rows have been graded (!BattleMenu_TechAvailDone) and Tech_CursorEntry.Flags bit 7 is clear. |
$C1:138F | BattleMenu_ | 30 | verified | Closes the tech list: reload the command window, back to the main menu, force a window rebuild, and restore this PC's saved tech-list cursor (!Pc_SavedTechRow / SavedTechScroll -> !Pc_TechRow /... |
$C1:13AD | BattleMenu_ | 71 | verified | Up/Left in the tech list: walks backward from !BattleMenu_TechListIdx to the previous line whose !Tech_ListAvail is non-zero. |
$C1:13F4 | BattleMenu_ | 73 | verified | Down/Right in the tech list: mirror of TechListPrev — walks forward instead of backward, bounded by the list length (!Pc_TechCount) instead of the start of the list, and scrolls down instead of up... |
$C1:143D | BattleMenu_ | 91 | verified | Per-frame input handler while the item list is open (submenu 2). |
$C1:1498 | BattleMenu_ | 67 | verified | Confirms the highlighted item: record offset = (!BattleMenu_ItemScroll + !BattleMenu_ItemRow) * 5 into Item_BattleList (id, target mode, flags, quantity, PC mask). |
$C1:14DB | BattleMenu_ | 17 | verified | Closes the item list: reload the command window, back to the main menu, force a window rebuild, and invalidate the scroll-arrow cache. |
$C1:14EC | BattleMenu_ | 22 | verified | Up/Left in the item list: decrement !BattleMenu_ItemRow, scrolling the list up via ItemListScrollUp when already at the top row. |
$C1:1502 | BattleMenu_ | 26 | verified | Down/Right in the item list: increment !BattleMenu_ItemRow (max 2), scrolling the list down via ItemListScrollDown when already at the bottom row. |
$C1:151C | BattleMenu_ | 27 | verified | Page-down button: page the item list down 3 rows at once, clamped at scroll position $FA. |
$C1:1537 | BattleMenu_ | 20 | verified | Page-up button: page the item list up 3 rows at once, clamped at 0. |
$C1:154B | BattleMenu_ | 22 | verified | Re-renders the item list rows, invalidates both draw caches and clears !BattleMenu_ItemRefresh. |
$C1:1561 | BattleMenu_ | 185 | verified | Per-frame input handler while target selection runs (entered from BattleMenu_ProcessInput when !BattleMenu_TargetSelect != 0). |
$C1:161A | BattleMenu_ | 308 | verified | Confirms the currently-selected target and builds the command record for the shown PC's chosen action (attack/tech/item), then queues it and hands the menu to the next ready PC. |
$C1:174E | BattleMenu_ | 30 | verified | Removes PC slot !BattleMenu_PartnerArg from the ready state as part of committing a double/triple tech: if it's in the roster, decrements !BattleMenu_ReadyCount; either way marks its roster entry... |
$C1:176C | BattleMenu_ | 26 | verified | Right/Down while cycling targets: advance !BattleTgt_Cursor (wrap at 11), skipping empty candidate entries, and select the battler it lands on (!BattleTgt_Selected). |
$C1:1786 | BattleMenu_ | 22 | verified | Left/Up while cycling targets: mirror of TargetNext — steps !BattleTgt_Cursor back (wrap to 10) instead. |
$C1:17A1 | BattleMenu_ | 16 | verified | Scrolls the item list up one row: decrements !BattleMenu_ItemScroll (min 0), then re-renders and invalidates both draw caches (row cursor, arrows). |
$C1:17B1 | BattleMenu_ | 2 | verified | |
$C1:17B3 | BattleMenu_ | 3 | verified | |
$C1:17B6 | BattleMenu_ | 9 | verified | |
$C1:17BF | BattleMenu_ | 18 | verified | Scrolls the item list down one row: increments !BattleMenu_ItemScroll (clamped at $FA), then re-renders and invalidates both draw caches. |
$C1:17D1 | BattleMenu_ | 3 | verified | |
$C1:17D4 | BattleMenu_ | 9 | verified | |
$C1:17DD | BattleMenu_ | 828 | verified | Cursor/overlay refresh at the end of the menu rebuild chain (after ProcessInput), so like it only on frames with !BattleMenu_Dirty set: JSR from BattleMenu_RefreshIfDirtyL... |
$C1:1B19 | BattleMenu_ | 60 | verified | Service 1 of the $C10045 service dispatcher (dispatch table at $C10051: service 0 -> $0023, 1 -> here, 2 -> RemoveBattlerFromReady). |
$C1:1B67 | BattleMenu_ | 67 | verified | Pops the head of !BattleMenu_ReadyQueue (up to 3 deep, count in !BattleMenu_ReadyQueueLen) into the roster: clears its !Battle_Unk9F38, restores its tech-list cursor (!Pc_SavedTechRow /... |
$C1:1BAA | BattleMenu_ | 144 | verified | Service 2 of the $C10045 service dispatcher (dispatch table at $C10051; reached only by same-bank JSR from bank $C1, see BattleMenu_EnqueueReadyBattler). |
$C1:1C3A | BattleMenu_ | 16 | verified | Copies the $180-byte command window map (!BattleRom_CommandWindowMap, bank $D1) into !BattleMenu_WindowMap. |
$C1:1F79 | BattleMenu_ | 100 | verified | Records the requesting PC (!BattleTgt_Caster), resets the selection state (!BattleTgt_Result/CanCycle/TargetAll, two Unk bytes) and blanks !BattleTgt_Candidates and !BattleTgt_Selected (indices... |