Alchemy
Loading...
Searching...
No Matches

icon_menu.c

Go to the documentation of this file.
1/// @file
2/// The command icon menus of the field, title and transfer screens.
3/// Part of battle_command.c, the menu object, compiled only through it.
4
6
7#if LANGUAGE == LANGUAGE_GERMAN
8#define TRANSFER_MODE_DRAW_HELP UiText_DrawCharacterAtOffset
9#define TRANSFER_PASSWORD_HELP_X 32
10#define TRANSFER_PASSWORD_HELP_FIRST_Y 8
11#define TRANSFER_PASSWORD_HELP_LAST_Y 24
12#define TRANSFER_CABLE_HELP_FIRST_Y 0
13#define TRANSFER_CABLE_HELP_LAST_Y 32
14#else
15#define TRANSFER_MODE_DRAW_HELP UiText_DrawResource
16#define TRANSFER_PASSWORD_HELP_X PASSWORD_HELP_X
17#define TRANSFER_PASSWORD_HELP_FIRST_Y 4
18#define TRANSFER_PASSWORD_HELP_LAST_Y 16
19#define TRANSFER_CABLE_HELP_FIRST_Y 4
20#define TRANSFER_CABLE_HELP_LAST_Y 28
21#endif
22
23/// One line's horizontal window edges: window 0's and window 1's, each
24/// (left << 8 | right).
25struct WindowLine {
28};
29
30/// A page of the display transition's window edges: WININ and WINOUT, then
31/// each of the 160 lines' edges.
34 struct WindowLine lines[160];
35};
36
37/// Draws the resource-menu icons, pulsing the selected icon with one affine
38/// matrix, and updates the horizontal window spans to reveal the active icon
39/// row.
41 // UB: native pointers traverse scalar link/span fields into adjacent fields
42 // and records. Use their real owners under UBFIX. Plain OAM field accesses
43 // and indexed scanlines each shrink the EN body from 0x348 to 0x344 bytes.
44 struct ResourceMenuWork *menu;
45 struct ResourceMenuEntry *entry;
46 struct AffineTransform transform;
47 s32 pulseScale;
48 s32 affineIndex;
49 s32 packedSpan;
50
51 s32 spriteY;
52 u32 lastLine;
53 u32 index;
54#ifndef UBFIX
55 u16 *spanCursor;
56#endif
57 struct DisplayTransitionState *transition;
58
59 menu = gMenuSelectWork;
60 entry = menu->entries;
61 pulseScale = gUi_BounceScales[(gFrameCount * 2) & 31];
62 pulseScale = (pulseScale - 256) / 4 + 304;
63 transform.scaleX = pulseScale;
64 transform.scaleY = pulseScale;
65 transform.angle = 0;
66 affineIndex = AffineMatrix_BuildForEffect(&transform);
67 // Pulse only the selection; the other icons keep their normal OAM shape.
68 for (index = 0; index < menu->count; index++, entry++) {
69#ifndef UBFIX
70 u32 *nativeAttributes;
71#endif
72 s32 drawLayer;
73 s32 x;
74
75 x = entry->x;
76 if (x == 0)
77 continue;
78 if (index == menu->selection) {
79 s32 left = x + pulseScale * 7 / 512 - 20;
80
81 if (entry->y != 0)
82 spriteY = entry->y + pulseScale * 3 / 256 - 20;
83 else
84 spriteY = (pulseScale * 15 / 256 - 30) & 255;
85#ifdef UBFIX
86 entry->link = 0;
87 entry->attr01 = (affineIndex << 25) | spriteY | (left << 16) | 0x80002300;
88 entry->attr2 = gVramBlockCache[entry->slot].offset >> 5;
89#else
90 nativeAttributes = &entry->link;
91 *nativeAttributes++ = 0;
92 *nativeAttributes++ =
93 (affineIndex << 25) | spriteY | (left << 16) | 0x80002300;
94 *nativeAttributes = gVramBlockCache[entry->slot].offset >> 5;
95#endif
96 drawLayer = 246;
97 } else {
98 u32 vramOffset;
99 u32 packedAttributes;
100
101#ifndef UBFIX
102 nativeAttributes = &entry->link;
103 /* FAKEMATCH: needed to match: reading the y halfword through attr
104 * keeps the attribute-pointer copy before its load; sprite->y
105 * moves the copy two instructions later. */
106 spriteY = ((s16 *)nativeAttributes)[7];
107 *nativeAttributes++ = 0;
108#else
109 spriteY = entry->y;
110 entry->link = 0;
111#endif
112 packedAttributes = spriteY | (x << 16) | 0x80002000;
113 vramOffset = gVramBlockCache[entry->slot].offset;
114#ifdef UBFIX
115 entry->attr01 = packedAttributes;
116 entry->attr2 = vramOffset >> 5;
117#else
118 *nativeAttributes++ = packedAttributes;
119 *nativeAttributes = vramOffset >> 5;
120#endif
121 drawLayer = 245;
122 }
123 Runtime_PushSlotEntry(entry, drawLayer);
124 }
125 // The top and bottom rows reveal opposite sides of the selected icon.
126 if (menu->row == 0) {
127 struct WindowBuffer *page;
128
129 s32 halfWidth;
130
131 transition = (struct DisplayTransitionState *)gDisplayTransition;
132 if (transition == 0 || menu->count == 0)
133 return;
134 page = (struct WindowBuffer *)transition->pages[transition->page];
135 packedSpan = menu->entries[menu->selection].x;
136 halfWidth = (pulseScale * 12 - 2817) / 256;
137 packedSpan =
138 ((packedSpan - halfWidth) << 8) + (packedSpan + halfWidth) + 23;
139 lastLine = menu->entries[menu->selection].y + 24;
140 lastLine += (pulseScale * 32 - 7937) / 512 + 1;
141#ifndef UBFIX
142 spanCursor = &page->lines[24].span;
143#endif
144 index = 24;
145 if (index < lastLine) {
146 do {
147#ifdef UBFIX
148 page->lines[index].span = (page->lines[index].span & 0xff) | packedSpan;
149#else
150 *spanCursor = (*spanCursor & 0xff) | packedSpan;
151#endif
152 index++;
153#ifndef UBFIX
154 spanCursor += 2;
155#endif
156 } while (index < lastLine);
157 }
158 packedSpan = menu->entries[0].x;
159 if (menu->selection == 0)
160 packedSpan -= (pulseScale * 12 - 2817) / 256;
161 packedSpan <<= 8;
162#ifndef UBFIX
163 spanCursor = &page->lines[0].span;
164#endif
165 for (index = 0; index <= 23; index++) {
166#ifdef UBFIX
167 page->lines[index].span = (page->lines[index].span & 0xff) | packedSpan;
168#else
169 *spanCursor = (*spanCursor & 0xff) | packedSpan;
170#endif
171#ifndef UBFIX
172 spanCursor += 2;
173#endif
174 }
175 } else {
176 struct WindowBuffer *page;
177 s32 firstLine;
178
179 s32 halfWidth;
180
181 transition = (struct DisplayTransitionState *)gDisplayTransition;
182 if (transition == 0 || menu->count == 0)
183 return;
184 page = (struct WindowBuffer *)transition->pages[transition->page];
185 packedSpan = menu->entries[menu->selection].x;
186 halfWidth = (pulseScale * 12 - 2817) / 256;
187 packedSpan =
188 ((packedSpan - halfWidth) << 8) + (packedSpan + halfWidth) + 23;
189 firstLine = menu->entries[menu->selection].y;
190 firstLine -= (pulseScale * 32 - 7937) / 512 + 1;
191#ifndef UBFIX
192 spanCursor = &page->lines[firstLine].span;
193#endif
194 index = firstLine;
195 if (index <= 135) {
196 do {
197#ifdef UBFIX
198 page->lines[index].span = (page->lines[index].span & 0xff) | packedSpan;
199#else
200 *spanCursor = (*spanCursor & 0xff) | packedSpan;
201#endif
202 index++;
203#ifndef UBFIX
204 spanCursor += 2;
205#endif
206 } while (index <= 135);
207 }
208 packedSpan = menu->entries[0].x;
209 if (menu->selection == 0)
210 packedSpan -= (pulseScale * 12 - 2817) / 256;
211 packedSpan <<= 8;
212#ifndef UBFIX
213 spanCursor = &page->lines[136].span;
214#endif
215 for (index = 136; index <= 159; index++) {
216#ifdef UBFIX
217 page->lines[index].span = (page->lines[index].span & 0xff) | packedSpan;
218#else
219 *spanCursor = (*spanCursor & 0xff) | packedSpan;
220#endif
221#ifndef UBFIX
222 spanCursor += 2;
223#endif
224 }
225 }
226}
227
228/// Allocates and clears the resource-menu state, then schedules its icon pulse.
230 // The matching allocation size is the complete six-entry work block.
231 void *work;
232 work = Runtime_AllocateBlock(58, 152);
233 Dma_Fill32(0, work, 152);
235 return work;
236}
237
238/// Stops the icon pulse, closes the label window and releases each loaded icon
239/// before freeing the resource-menu state.
241 struct UiWindow *labelWindow;
242 s32 i;
243 struct ResourceMenuWork *work;
244
245 work = gMenuSelectWork;
247 labelWindow = work->window;
248 if (labelWindow != 0) {
249 UiWork_Finalize(labelWindow, 2);
250 }
251 for (i = 0; i < work->count; i++) {
253 }
255 WaitFrames(1U);
256}
257
258/// Selects an icon position with wrapped directional input. A returns the
259/// position; B or Start returns -1. Redraws the label only after a move.
261 struct ResourceMenuWork *work = gMenuSelectWork;
262 s32 resource;
263
264 work->selection = initial;
265redraw:
267 if (work->resourceBase != 0)
268 resource = work->resourceBase + work->selection;
269 else
270 resource = work->resourceIds[work->selection] + MsgCommandName;
271 UiText_DrawCharacterAtOffset(resource, work->window, 0, 0);
272 for (;;) {
273 WaitFrames(1);
274 if (gKeysPressed & KEY_A) {
276 return work->selection;
277 }
278 if (gKeysPressed & KEY_B) {
280 return -1;
281 }
282 if (gKeysPressed & KEY_START) {
284 return -1;
285 }
286 if ((gKeysRepeat & KEY_LEFT) || (gKeysRepeat & KEY_UP)) {
288 work->selection--;
289 if (work->selection < 0)
290 work->selection = work->count - 1;
291 } else if ((gKeysRepeat & KEY_RIGHT) || (gKeysRepeat & KEY_DOWN)) {
293 work->selection++;
294 if (work->selection >= work->count)
295 work->selection = 0;
296 } else
297 continue;
298 goto redraw;
299 }
300}
301
302/// Returns the distance between lhs and rhs, reusing their supplied difference.
303static inline s32 AbsoluteDifference(s32 diff, s32 lhs, s32 rhs) {
304 if (diff >= 0)
305 return diff;
306 return rhs - lhs;
307}
308
309/// Animates a cursor from start to goal with table-driven delays. Draws each
310/// intervening label, pauses at the destination, and returns its position.
314 s32 diff;
315 s32 resourceId;
316 s32 distance;
317 s32 position;
318 s32 step;
319 s32 delay;
320 const u8 *stepDelays;
321 struct ResourceMenuWork *state;
322
323 state = gMenuSelectWork;
324 step = 1;
325 delay = 12;
326 state->selection = start;
327 if (goal < start)
328 step = -1;
329 position = start;
330
331 for (;;) {
333 resourceBase = state->resourceBase;
334 if (resourceBase != 0) {
335 resourceId = resourceBase + state->selection;
336 } else {
337 resourceId = state->resourceIds[state->selection] + MsgCommandName;
338 }
339 UiText_DrawCharacterAtOffset(resourceId, state->window, 0, 0);
340
341 selection = state->selection;
342 stepDelays = gMenu_SelectionStepDelays;
343 diff = selection - goal;
344 distance = AbsoluteDifference(diff, selection, goal);
345 WaitFrames(stepDelays[distance] + delay);
346
347 if (position == goal)
348 break;
349
350 state->selection += step;
352 delay = 0;
353 position += step;
354 }
355
356 WaitFrames(48);
358 return goal;
359}
360
361/// Decodes one command-icon table entry into the requested VRAM cache slot.
362void Menu_LoadResourceSlot(s32 slot, s32 index) {
363 s32 size = 1024;
364 void *buffer = MemAlloc(size);
366
367 Resource_DecodeByteLz((void *)((u32)offsetTable + offsetTable[index]),
368 buffer);
369 VramCache_Load(slot, size, buffer);
370 MemFree(buffer);
371}
372
373/// Appends a command icon if fewer than six are present. Its initial position
374/// is on the bottom icon row; a layout routine places the final row.
376 struct ResourceMenuWork *work;
377 struct ResourceMenuEntry *entry;
378 s16 index;
379 s32 slot;
380 s32 y;
381
382 work = gMenuSelectWork;
383 index = work->count;
384 if (index <= 5) {
385 work->count++;
386 entry = &work->entries[index];
389 entry->x = index * 24 + 32;
390 y = 136;
391 entry->y = y;
392 entry->slot = slot;
393 work->resourceIds[index] = icon;
394 }
395}
396
397/// Centers the icons and their label window together on the given tile row.
398/// A nonzero resourceBase supplies labels; otherwise command-name IDs do.
399void Menu_CenterResourceEntries(s32 row, s32 width, s32 resourceBase) {
400 struct ResourceMenuWork *menu = gMenuSelectWork;
401 s32 x;
402 s32 i;
403 s32 count;
404
405 menu->width = width + 2;
407 menu->row = row;
408 count = menu->count;
409 x = 15 - (count * 3 + menu->width * 2 / 3) / 2;
410 for (i = 0; i < menu->count; i++) {
411 struct ResourceMenuEntry *entry = &menu->entries[i];
412
413 entry->x = x * 8;
414 entry->y = row * 8;
415 x += 3;
416 }
417 menu->window = UiWindow_Create(x, row, menu->width, 3, 2);
418}
419
420/// Places icons at three-tile intervals from (x, y), then creates their label
421/// window immediately to the right. Coordinates and label width are in tiles.
422void Menu_LayoutResourceEntries(s32 x, s32 y, s32 width, s32 resourceBase) {
423 struct ResourceMenuWork *work;
424 s32 i;
425 struct ResourceMenuEntry *entry;
426
427 work = gMenuSelectWork;
428 work->width = width + 2;
429 work->resourceBase = resourceBase;
430 work->row = y;
431 for (i = 0; i < work->count; i++) {
432 entry = &work->entries[i];
433 entry->y = y << 3;
434 entry->x = x << 3;
435 x += 3;
436 }
437 work->window = UiWindow_Create(x, y, work->width, 3, 2);
438}
439
440/// Reads the signed command-position mapping used by the top resource menu.
441static __inline__ s32 ResourceMenu_ReadCommandPosition(s8 *table, s32 index) {
442 return table[index];
443}
444
445/// Builds the field command menu, omitting Djinn when none are owned.
446/// Translates between command IDs and visible icon positions using the two
447/// lookup rows.
449 s32 group = 0;
450 s32 offset;
451 s32 groupTriple;
452 s32 result;
453 s8 *commandPositions;
454
455 if (Party_SumDjinnCountsFar(-1) == 0) {
456 group = 1;
457 }
458
459 groupTriple = group * 3;
460 commandPositions = gMenu_TopEntryPositionByCommand;
461 offset = groupTriple << 1;
462 selection =
463 ResourceMenu_ReadCommandPosition(commandPositions, selection + offset) -
464 1;
465 if (selection < 0) {
466 selection = 0;
467 }
468
471 if (group == 0) {
473 }
477 result = Menu_RunResourceSelectionLoop(selection);
479
480 if (result >= 0) {
481 result = gMenu_TopEntryCommandByPosition[result + offset + 1];
482 }
483
484 return result;
485}
486
487#if TBS_PATCH_1
488#define ANIMATE_ENTRIES_ROW 7
489#else
490#define ANIMATE_ENTRIES_ROW 5
491#endif
492
493/// Opens the field command menu and animates from start to the command's icon.
494/// Returns the final icon position after closing the menu.
503 command = Menu_SelectResource(start, command - 1);
506 return command;
507}
508
509/// Builds the title menu from the save summaries and optional send flags.
510/// Translates the chosen visible position back to its save-action code.
512 s32 fileState;
513 s32 result;
514 s32 initial;
515 u32 group;
516
517 group = 0;
518 initial = 0;
519 fileState = SaveState_ScanRecordFlags();
520 if (fileState < 0) {
521 return -1;
522 }
523 if (fileState == 0) {
524 return 0;
525 }
526 if (fileState == 3) {
527 group = 1;
528 } else if (fileState == 0x67) {
529 group = 2;
530 } else if (fileState > 0x64) {
531 group = 3;
532 } else {
533 initial = 1;
534 }
536 if ((group == 0) || (group == 3)) {
538 }
539 if (group <= 1U) {
541 }
542 if ((group == 0) || (group == 3)) {
544 }
546 if ((*(s16 *)gTitleExtraOptionEnabled) != 0) {
548 }
549 if (gTitleSendOptionEnabled != 0) {
551 }
553 result = Menu_RunResourceSelectionLoop(initial);
555 if (result >= 0) {
556 result = gMenu_SaveSlotActionByPosition[result + (group * 6)];
557 }
558 return result;
559}
560
561#if TBS_PATCH_1
562#define MODE_LABEL_X 18
563#define MODE_LABEL_RIGHT 144
564#else
565#define MODE_LABEL_X 8
566#define MODE_LABEL_RIGHT 80
567#endif
568
569/// Redraws the password-level explanation when the selected level changes.
571 struct ResourceMenuWork *state = gMenuSelectWork;
572
573 if (state->previousMode != state->selection) {
574 state->previousMode = state->selection;
576 80);
577
578 switch (state->selection) {
579 case 0: {
580 s32 text = MsgPasswordLevel;
581
584 48);
586 56);
588 64);
589 text += 4;
591 break;
592 }
593 case 1: {
594 s32 text = MsgPasswordLevel;
595
598 48);
599 text += 2;
601 break;
602 }
603 case 2:
604 default: {
605 s32 text = MsgPasswordLevel;
606
608 40);
610 break;
611 }
612 }
613 }
614}
615
616#if TBS_PATCH_1
617#define PASSWORD_HELP_X 16
618#else
619#define PASSWORD_HELP_X 0
620#endif
621
622#if (LANGUAGE == LANGUAGE_FRENCH)
623
624/// Redraws password/cable transfer help when the chosen method changes.
625/// The French layout keeps its distinct line splitting and redraw path.
626void Menu_DrawModeIndicator(void) {
627 struct ResourceMenuWork *state = gMenuSelectWork;
628
629 if (state->previousMode != state->selection) {
630 if (state->selection == 0) {
632 UiText_DrawResource(MsgPasswordTransferHelp, state->lowerWindow, 16, 4);
633 UiText_DrawResource(MsgPasswordTransferHelp + 1, state->lowerWindow, 16,
634 16);
635 } else if (state->previousMode == 0) {
637 UiText_DrawResource(MsgCableTransferHelp, state->lowerWindow, 0, 4);
638 UiText_DrawResource(MsgCableTransferHelp + 1, state->lowerWindow, 0, 16);
639 UiText_DrawResource(MsgCableTransferHelp + 2, state->lowerWindow, 0, 28);
640 }
641 state->previousMode = state->selection;
642 }
643}
644#else
646 struct ResourceMenuWork *state = gMenuSelectWork;
647 s16 *shown = &state->previousMode;
648 s16 *current = &state->selection;
649
650 if (*shown != *current) {
651 *shown = *current;
653 if (*current == 0) {
654 TRANSFER_MODE_DRAW_HELP(MsgPasswordTransferHelp, state->lowerWindow,
657 TRANSFER_MODE_DRAW_HELP(MsgPasswordTransferHelp + 1, state->lowerWindow,
660 } else {
661 TRANSFER_MODE_DRAW_HELP(MsgCableTransferHelp, state->lowerWindow, 0,
663 TRANSFER_MODE_DRAW_HELP(MsgCableTransferHelp + 1, state->lowerWindow, 0,
664 16);
665 TRANSFER_MODE_DRAW_HELP(MsgCableTransferHelp + 2, state->lowerWindow, 0,
667 }
668 }
669}
670#endif
671
672/// Selects either the transfer method (mode 0) or password level. Schedules the
673/// appropriate help redraw while the icon menu is active, then closes both
674/// help windows and the icon menu.
676 struct ResourceMenuWork *work;
677 struct UiWindow *window;
678 s32 message;
679 struct UiWindow **upper;
680 s32 result;
681
683 work = gMenuSelectWork;
684 if (mode == 0) {
687 } else {
691#if (LANGUAGE == LANGUAGE_SPANISH)
693#endif
694 }
695#if (LANGUAGE == LANGUAGE_ENGLISH) || (LANGUAGE == LANGUAGE_GERMAN) || \
696 (LANGUAGE == LANGUAGE_ITALIAN)
698#elif (LANGUAGE == LANGUAGE_SPANISH)
699#elif (LANGUAGE == LANGUAGE_FRENCH)
701#else
703#endif
704 if (mode != 0) {
706 work->previousMode = 0xffff;
709 message = MsgPasswordSelection;
710 upper = &work->upperWindow;
711 *upper = window;
712 UiText_DrawResource(message, window, 0, 4);
713#if TBS_PATCH_1
716 work->lowerWindow = window;
717 UiText_DrawResource(message + 1, window, 8, 0);
718 UiText_DrawResource(message + 2, work->lowerWindow, 8, 11);
719 message += 3;
720 UiText_DrawResource(message, work->lowerWindow, 8, 22);
721#else
722 window = UiWindow_Create(5, 4, 21, 12, 2);
723 work->lowerWindow = window;
724 UiText_DrawResource(message + 1, window, 0, 4);
725 message += 2;
726 UiText_DrawResource(message, work->lowerWindow, 0, 16);
727#endif
728 } else {
730 work->previousMode = 0xffff;
733 upper = &work->upperWindow;
734 *upper = window;
735 UiText_DrawResource(MsgTransferMethod, window, TRANSFER_METHOD_LABEL_X, 4);
738 }
740 if (mode != 0)
742 else
746 UiWork_Finalize(*upper, 2);
748 WaitFrames(1);
750 return result;
751}
752
753// Command icons arranged in a row to choose from, such as Yes and No.
754// Icon numbers refer to ResourceId_CommandIcons.
755// Each shows the name of the icon under the cursor in a window.
756
757/// Selects a shop command, icons 0x11-0x14 (Buy, Sell, Artifacts, Repair),
758/// centered on row 17.
759/// selection: initial position; returns the selected position.
761 s32 result;
762
769 result = Menu_RunResourceSelectionLoop(selection);
771 return result;
772}
773
774/// Selects a sanctum service, icons 0x19-0x1c (Revive, Cure Poison, Repel
775/// Evil, Remove Curse), centered on row 17.
777 s32 result;
778
785 result = Menu_RunResourceSelectionLoop(selection);
787 return result;
788}
789
790/// Selects Yes/No (icons 5/6); canceling returns 1 (No).
791/// bottom: 0 places the menu on row 0; otherwise row 17.
792/// message: first name message, or 0 for command names.
793/// labelWidth: name window width, or 0 for width 3.
794/// selection: initial position
795s32 Menu_RunConfirmSelection(s32 bottom, s32 message, s32 labelWidth,
796 s32 selection) {
797 s32 row;
798
799 row = 0;
800
802
803 if (labelWidth == 0) {
804 labelWidth = 3;
805 }
806 if (bottom != 0) {
807 row = 17;
808 }
809
812 Menu_CenterResourceEntries(row, labelWidth, message);
813
814 selection = Menu_RunResourceSelectionLoop(selection);
816 if (selection == -1) {
817 selection = 1;
818 }
819 return selection;
820}
821
822/// Selects Yes/No at (x, y); canceling returns 1 (No).
824 s32 message = MsgCommandYes;
825
829 Menu_LayoutResourceEntries(x, y, 3, message);
830 selection = Menu_RunResourceSelectionLoop(selection);
832 if (selection == -1) {
833 selection = 1;
834 }
835 return selection;
836}
837
838// Name window width for each edition
839#if !TBS_PATCH_1
840#define PAIR_WIDTH 7
841#elif (LANGUAGE == LANGUAGE_FRENCH || LANGUAGE == LANGUAGE_ITALIAN)
842#define PAIR_WIDTH 10
843#else
844#define PAIR_WIDTH 9
845#endif
846
847/// Selects icons 0x20 and 0x21 (Coins, Lucky Medals) centered on row 17.
848/// selection: initial position; returns the selected position.
850 s32 result;
851
856 result = Menu_RunResourceSelectionLoop(selection);
858 return result;
859}
What every part of the menu object shares: its includes, edition values, macros and the link round st...
#define ENTRY11_COMMAND_LABEL_WIDTH
#define RESOURCE_MODE0_WINDOW_X
#define RESOURCE_MODE1_WINDOW_X
#define TRANSFER_METHOD_LABEL_X
#define RESOURCE_MODE1_WINDOW_WIDTH
#define TRANSFER_HELP_WINDOW_WIDTH
#define TRANSFER_HELP_WINDOW_X
#define ENTRY19_COMMAND_LABEL_WIDTH
#define TRANSFER_METHOD_WINDOW_X
#define TRANSFER_METHOD_WINDOW_WIDTH
#define RESOURCE_MODE0_WINDOW_WIDTH
#define Dma_Fill32(value, destination, size)
Fills size bytes at destination with the word value by DMA3.
Definition dma.h:30
s32 Party_SumDjinnCountsFar(s32 index)
void AudioCommand_PlayFar(s32 id)
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
volatile u32 gFrameCount
Frames WaitFrames has finished.
struct DisplayTransitionState * gDisplayTransition
Slot 31.
void * MemAlloc(s32 size)
Allocates size bytes (rounded up to words) with no slot, from IWRAM when they fit and EWRAM otherwise...
Definition heap.c:115
void * Runtime_AllocateBlock(s32 kind, s32 size)
As Runtime_AllocateHeapBlock, but tries EWRAM first, for blocks that need room more than speed: the b...
Definition heap.c:80
void Menu_LoadResourceSlot(s32 slot, s32 index)
Decodes one command-icon table entry into the requested VRAM cache slot.
Definition icon_menu.c:362
static __inline__ s32 ResourceMenu_ReadCommandPosition(s8 *table, s32 index)
Reads the signed command-position mapping used by the top resource menu.
Definition icon_menu.c:441
void Menu_DrawModeIndicator(void)
Definition icon_menu.c:645
s32 Menu_SelectCoinsOrMedals(s32 selection)
Selects icons 0x20 and 0x21 (Coins, Lucky Medals) centered on row 17.
Definition icon_menu.c:849
void Menu_CenterResourceEntries(s32 row, s32 width, s32 resourceBase)
Centers the icons and their label window together on the given tile row.
Definition icon_menu.c:399
s32 Menu_RunResourceSelectionLoop(s32 initial)
Selects an icon position with wrapped directional input.
Definition icon_menu.c:260
s32 Menu_SelectSanctumService(s32 selection)
Selects a sanctum service, icons 0x19-0x1c (Revive, Cure Poison, Repel Evil, Remove Curse),...
Definition icon_menu.c:776
#define TRANSFER_PASSWORD_HELP_X
Definition icon_menu.c:16
void Menu_EndResourceSelection(void)
Stops the icon pulse, closes the label window and releases each loaded icon before freeing the resour...
Definition icon_menu.c:240
s32 Menu_RunConfirmSelection(s32 bottom, s32 message, s32 labelWidth, s32 selection)
Selects Yes/No (icons 5/6); canceling returns 1 (No).
Definition icon_menu.c:795
s32 Menu_SelectResourceLayout(s32 mode)
Selects either the transfer method (mode 0) or password level.
Definition icon_menu.c:675
s32 Menu_RunConfirmSelectionAt(s32 x, s32 y, s32 selection)
Selects Yes/No at (x, y); canceling returns 1 (No).
Definition icon_menu.c:823
s32 Menu_SelectResource(s32 start, s32 goal)
Animates a cursor from start to goal with table-driven delays.
Definition icon_menu.c:311
s32 Menu_SelectTopEntry(s32 selection)
Builds the field command menu, omitting Djinn when none are owned.
Definition icon_menu.c:448
#define TRANSFER_CABLE_HELP_FIRST_Y
Definition icon_menu.c:19
#define MODE_LABEL_RIGHT
Definition icon_menu.c:563
s32 Menu_SelectSaveSlotAction(void)
Builds the title menu from the save summaries and optional send flags.
Definition icon_menu.c:511
#define TRANSFER_CABLE_HELP_LAST_Y
Definition icon_menu.c:20
static s32 AbsoluteDifference(s32 diff, s32 lhs, s32 rhs)
Returns the distance between lhs and rhs, reusing their supplied difference.
Definition icon_menu.c:303
#define TRANSFER_MODE_DRAW_HELP
Definition icon_menu.c:15
s32 Menu_AnimateSelectionToEntry(s32 start, s32 command)
Opens the field command menu and animates from start to the command's icon.
Definition icon_menu.c:495
#define ANIMATE_ENTRIES_ROW
Definition icon_menu.c:488
#define PAIR_WIDTH
Definition icon_menu.c:844
#define TRANSFER_PASSWORD_HELP_LAST_Y
Definition icon_menu.c:18
void Menu_AppendResourceEntry(s32 icon)
Appends a command icon if fewer than six are present.
Definition icon_menu.c:375
#define MODE_LABEL_X
Definition icon_menu.c:562
#define TRANSFER_PASSWORD_HELP_FIRST_Y
Definition icon_menu.c:17
void * AffineEffect_InitializeWork(void)
Allocates and clears the resource-menu state, then schedules its icon pulse.
Definition icon_menu.c:229
void Menu_LayoutResourceEntries(s32 x, s32 y, s32 width, s32 resourceBase)
Places icons at three-tile intervals from (x, y), then creates their label window immediately to the ...
Definition icon_menu.c:422
void AffineEffect_UpdateFrame(void)
Draws the resource-menu icons, pulsing the selected icon with one affine matrix, and updates the hori...
Definition icon_menu.c:40
void Menu_DrawModeLabel(void)
Redraws the password-level explanation when the selected level changes.
Definition icon_menu.c:570
s32 Menu_SelectShopCommand(s32 selection)
Selects a shop command, icons 0x11-0x14 (Buy, Sell, Artifacts, Repair), centered on row 17.
Definition icon_menu.c:760
@ KEY_UP
Definition io_reg.h:249
@ KEY_B
Definition io_reg.h:244
@ KEY_LEFT
Definition io_reg.h:248
@ KEY_START
Definition io_reg.h:246
@ KEY_RIGHT
Definition io_reg.h:247
@ KEY_A
Definition io_reg.h:243
@ KEY_DOWN
Definition io_reg.h:250
volatile u32 gKeysPressed
Keys that went down this frame.
volatile u32 gKeysRepeat
Pressed keys, repeating while held: after 19 frames, then every 6.
void Runtime_ReleaseHeapBlock(s32 slot)
void MemFree(void *buffer)
s8 gMenu_TopEntryCommandByPosition[]
s8 gMenu_TopEntryPositionByCommand[]
s8 gMenu_SaveSlotActionByPosition[]
u8 gMenu_SelectionStepDelays[]
u8 gTitleExtraOptionEnabled[]
s32 AffineMatrix_BuildForEffect(struct AffineTransform *source)
Hands out the next OAM affine matrix for a sprite drawn with source's scale and rotation and fills it...
Definition render.c:27
void Runtime_PushSlotEntry(void *slotEntry, s32 slot)
Links a sprite entry into depth slot slot (clamped to 0..255) for this frame.
Definition render.c:79
char ResourceId_CommandIcons
struct ResourceMenuWork * gMenuSelectWork
s32 Resource_DecodeByteLz(const void *source, void *destination)
Decodes a byte-oriented LZ resource and returns its unpacked byte count.
Definition decompress.c:37
s16 gTitleSendOptionEnabled
const u16 gUi_BounceScales[32]
A sprite's pulse, as a scale where 256 is its normal size: it swells to 1.5 times and back over 32 st...
Definition scales.c:10
s32 Scheduler_AddOrUpdateCallback(SchedulerCallback callback, s32 order)
Schedules callback with order, or gives a task already running it the new order, and re-sorts the tab...
Definition scheduler.c:102
s32 Scheduler_RemoveCallback(SchedulerCallback callback)
Unschedules the task running callback: clears its routine and gives it order 0x7fff,...
Definition scheduler.c:146
void UiWork_CloseAndRelease(void)
Closes the window kept in heap block 16 and frees the block.
Definition selection.c:1389
void UiWindow_OpenMode1AndWaitFrame(void)
Opens the field menu's window and waits a frame.
Definition selection.c:1383
#define SE_MENU_CANCEL
Definition songs.h:106
#define SE_MENU_CURSOR_MOVE
Definition songs.h:104
#define SE_MENU_CONFIRM
Definition songs.h:105
A sprite's rotation and scale: scales in 8.8 fixed point (0x100 is full size), the angle in 1/65536 t...
Definition affine.h:13
u16 angle
1/65536 turns
Definition affine.h:16
u16 scaleY
8.8 fixed point, read signed
Definition affine.h:15
u16 scaleX
8.8 fixed point, read signed: negative mirrors the sprite
Definition affine.h:14
The display transition state (heap block 31): two pages of window edges for every line,...
u8 page
the pages entry shown; the next is built in the other
u16 pages[2][322]
Window edges, two pages: WININ and WINOUT, then a WIN0H and WIN1H pair, each (left << 8 | right),...
A command icon of the resource menu: its OAM attributes, its place and its VRAM cache slot.
s16 y
screen pixels
s16 x
screen pixels
The resource menu: up to six command icons in a row, the windows of their labels, the icons' resource...
struct ResourceMenuEntry entries[6]
struct UiWindow * lowerWindow
struct UiWindow * upperWindow
struct UiWindow * window
A window: a framed rectangle of the tilemap with its sprite outputs, its opening or closing animation...
Definition uiwindow.h:11
u16 y
tiles
Definition uiwindow.h:16
u16 x
tiles
Definition uiwindow.h:15
u16 offset
bytes from the start of OBJ VRAM
Definition vram_tab.h:25
A page of the display transition's window edges: WININ and WINOUT, then each of the 160 lines' edges.
Definition icon_menu.c:32
u8 unk000[4]
Definition icon_menu.c:33
struct WindowLine lines[160]
Definition icon_menu.c:34
One line's horizontal window edges: window 0's and window 1's, each (left << 8 | right).
Definition icon_menu.c:25
void * Resource_GetTableEntry(s32 index)
Returns the ROM address of resource index from the resource directory.
Definition system.c:150
#define TYPE_MENU_WIDTH
Definition tbs_edition.h:77
#define SELECT_MENU_WIDTH
Definition tbs_edition.h:76
void UiText_DrawResource(s32 message, struct UiWindow *window, s32 x, s32 y)
Decodes a message and draws it into a text canvas window at pixel (x, y).
Definition text_tiles.c:538
void UiText_DrawCharacterAtOffset(s32 message, const struct UiWindow *window, u32 offsetX, u32 offsetY)
Decodes a message and draws it as tiles in a window at pixel (offsetX, offsetY) of its interior.
Definition text_tiles.c:552
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
signed char s8
Definition types.h:10
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11
s32 Resource_ResetEntry(u32 no)
Frees cache entry no: its blocks go back and the entry is marked free (offset 0xffff).
Definition vram_cache.c:106
s32 Resource_FindFreeEntry(void)
Returns the number of the first free cache entry, or VRAM_CACHE_ENTRY_COUNT when all are taken.
Definition vram_cache.c:211
s32 VramCache_Load(u32 no, u32 size, const void *src)
Gives cache entry no size bytes of sprite VRAM and copies src there.
Definition vram_cache.c:143
struct VramBlockCacheEntry gVramBlockCache[]
s32 SaveState_ScanRecordFlags(void)
Loads the save file summaries for the title menu and returns how many files there are: plus 100 when ...
Definition save.c:111
void RenderOutput_PrepareForRedraw(struct UiWindow *window)
Clears a window's contents: redraws its empty frame and releases the render outputs it carries.
Definition windows.c:392
void UiWork_Finalize(struct UiWindow *window, s32 instant)
Closes a window: clears its contents and remembers its last rectangle.
Definition windows.c:349
void RenderOutput_ClearList(void *outputs)
Releases every render output in a list and empties it.
Definition windows.c:406
void UiWindow_ClearInteriorTiles(const struct UiWindow *window, u32 left, u32 top, u32 right, u32 bottom)
Clears an area of a window's interior to the window fill.
Definition windows.c:428
struct UiWindow * UiWindow_Create(s32 x, s32 y, s32 width, s32 height, s32 attrs)
Opens a window at tile (x, y) of width by height tiles in the first free window slot,...
Definition windows.c:279