Alchemy
Loading...
Searching...
No Matches

joined.c

Go to the documentation of this file.
1/// @file
2/// The Colosso choice and the joined-party messages.
3/// Part of battle_command.c, the menu object, compiled only through it.
4
6
7// UB: the joined messages pass five of UiText_QueueRenderEntries' six
8// arguments, so its flags are whatever the stack slot of the sixth holds;
9// UBFIX passes 0, as the window object's own messages do.
10#ifdef UBFIX
11#define JOINED_QUEUE_TEXT(window, entry, x, y, spacing) \
12 UiText_QueueRenderEntries(window, entry, x, y, (u16 *)(spacing), 0)
13#else
14#define JOINED_QUEUE_TEXT(window, entry, x, y, spacing) \
15 UiText_QueueRenderEntries(window, entry, x, y, spacing)
16#endif
17
18#if (LANGUAGE == LANGUAGE_ENGLISH) || (LANGUAGE == LANGUAGE_GERMAN) || \
19 (LANGUAGE == LANGUAGE_FRENCH) || (LANGUAGE == LANGUAGE_ITALIAN)
20#define TALK_WINDOW_X 7
21#define TALK_WINDOW_WIDTH 18
22#elif (LANGUAGE == LANGUAGE_SPANISH)
23#define TALK_WINDOW_X 9
24#define TALK_WINDOW_WIDTH 12
25#else
26#define TALK_WINDOW_X 8
27#define TALK_WINDOW_WIDTH 16
28#endif
29
30/// The Colosso choice of what to do: "Descriptions", "Cheer" or "Nothing",
31/// chosen with a pointing hand. Returns the choice (0-2), or -1 when
32/// cancelled with B.
34 /* FAKEMATCH: the shared cursor union preserves pointer-store ordering; an
35 * equal-size struct changes stack-address construction in all six editions.
36 */
37 struct UiWindow *window;
38 union MenuCursor cursor;
39 s32 slot;
40 s32 row;
41 s32 moved;
42 u16 *palette;
43
44 moved = 1;
46 UiText_DrawCharacterAtOffset(MsgTalkChoice, window, 8, 0);
47 UiText_DrawCharacterAtOffset(MsgTalkChoice + 1, window, 8, 16);
48 UiText_DrawCharacterAtOffset(MsgTalkChoice + 2, window, 8, 32);
50 row = 0;
51 if (slot < VRAM_CACHE_ENTRY_COUNT) {
53 cursor.output = RenderOutput_Create(slot, OUTPUT_SIZE_16X16, window, 0, 0);
54 ShopCursor_SetPositionImmediateFar(&cursor.cursor, window->x * 8 - 3,
55 window->y * 8 + 9);
56 }
57 // The choice under the cursor flashes between palette 15 and palette 14,
58 // a copy of it with colour 4 grey.
59 palette = (u16 *)&BG_PLTT_COLOR(14, 0);
60 Dma_Set((const void *)&BG_PLTT_COLOR(15, 0), palette, DMA_COPY32(8),
61 REG_DMA3);
62 palette[4] = 0x6318;
63 while (1) {
64 UiWindow_SetTileAttributeRect(window, 1, row * 2, TALK_WINDOW_WIDTH - 4, 1,
65 14);
66 WaitFrames(1);
67 UiWindow_SetTileAttributeRect(window, 1, row * 2, TALK_WINDOW_WIDTH - 4, 1,
68 15);
69 if (moved) {
70 moved = 0;
71 Shop_SetCursorFar(&cursor.cursor, window->x * 8 - 3,
72 (window->y + row * 2) * 8 + 9, 3);
73 }
75 if (gKeysRepeat & KEY_UP) {
77 row--;
78 moved = 1;
79 if (row == -1)
80 row = 2;
81 }
82 if (gKeysRepeat & KEY_DOWN) {
84 row++;
85 moved = 1;
86 if (row == 3)
87 row = 0;
88 }
89 if (gKeysRepeat & KEY_B) {
91 row = -1;
92 break;
93 }
94 if (gKeysRepeat & KEY_A) {
96 break;
97 }
98 }
99 UiWork_Finalize(window, 2);
100 WaitFrames(1);
102 return row;
103}
104
105/// Shows that a Djinni joined a member while the join fanfare (sound 81)
106/// plays, until it ends or A, B, L or R is pressed. The message is
107/// `The <element> Djinni <name> joined <member>.`, with the element's Djinni
108/// portrait. `djinn` is the Djinni's number in its element.
109void Djinn_ShowJoinedMessage(s32 member, s32 element, s32 djinn) {
110 struct UiRenderWork *work = (struct UiRenderWork *)*gWindowWork;
111 s32 name;
112 struct UiWindow *window;
113 s32 sprite[3];
114 s32 *entry;
115 s32 palette, handle;
116 s32 id;
117 s32 text;
118 u32 zero;
119 s32 *p;
120
121 window = NULL;
122 zero = 0;
123 name = gDjinn_ElementSprites[element & 3];
124 entry = sprite;
126
127 if (window != NULL) {
128 UiWindow_DrawDividerLine(window, 4, 0, 4, 4);
129
130 work->dirty = 1;
131
133 UiGlyph_LoadEntryWithPalette(id, zero, &handle, &palette, 14, zero);
134
135 // The portrait as a bare OAM entry, pushed onto draw layer 250 each frame:
136 // a link word, attributes 0 and 1 (32x32 at y 12) and attribute 2.
137 p = entry;
138 *p++ = zero;
139 *p++ = 0x8000000c | ((DJINN_JOIN_X * 8 + 4) << 16);
140 *p = palette | 0xe000;
141
142 work->speakerVoiceSound = zero;
143 work->speakerVoiceCountdown = zero;
144
145 // The Djinni's name is ability 300 + 20 * element + djinn.
146 UiWork_PushValueSlot(member, 1);
147 UiWork_PushValueSlot(element * 20 + djinn + 300, 4);
148
149 text = UiText_BuildRenderEntriesMode1(element + MsgVenusDjinnJoined);
150
151 JOINED_QUEUE_TEXT(window, text, 36, 2, zero);
152
154
155 do {
156 Runtime_PushSlotEntry(entry, 250);
157 WaitFrames(1);
158 } while (AudioCommand_GetStateByteFar() != 0 &&
159 (gKeysPressed & (KEY_A | KEY_B | KEYS_SHOULDERS)) == 0);
160
161 UiWork_Finalize(window, 2);
162 WaitFrames(1);
163 Resource_ResetEntry(handle);
164 }
165}
166
167/// Returns the portrait character of party member `member` (0-8): from
168/// gCharacter_ChildSpriteTable during the prologue, from
169/// gCharacter_SpriteTable otherwise; 0 for any other member.
171 if (index > 8) {
172 return 0;
173 }
175 return gCharacter_SpriteTable[index];
176 }
177 return gCharacter_ChildSpriteTable[index];
178}
179
180/// Shows that a member joined the party while the join fanfare (sound 81)
181/// plays, until it ends or A, B, L or R is pressed. The message is
182/// `<member> joined your party.`, with the member's portrait.
184 struct UiRenderWork *work = (struct UiRenderWork *)*gWindowWork;
185 struct UiWindow *window = NULL;
186 s32 sprite[3];
187 s32 *entry = sprite;
188 s32 palette, handle;
189 s32 *p;
190
191 window = UiWindow_Create(2, 1, 26, 5, 0);
192 if (window != NULL) {
193 UiWindow_DrawDividerLine(window, 4, 0, 4, 4);
194 work->dirty = 1;
197 0, &handle, &palette, 14, 0);
198 // The portrait as a bare OAM entry, pushed onto draw layer 250 each frame:
199 // a link word, attributes 0 and 1 (32x32 at y 12) and attribute 2.
200 p = entry;
201 *p++ = 0;
202 *p++ = 0x8000000c | ((2 * 8 + 4) << 16);
203 *p = palette | 0xe000;
204 work->speakerVoiceSound = 0;
205 work->speakerVoiceCountdown = 0;
206 UiWork_PushValueSlot(member, 1);
208 36, 2, 0);
210 do {
211 Runtime_PushSlotEntry(entry, 250);
212 WaitFrames(1);
213 } while (AudioCommand_GetStateByteFar() != 0 &&
214 (gKeysPressed & (KEY_A | KEY_B | KEYS_SHOULDERS)) == 0);
215 UiWork_Finalize(window, 2);
216 WaitFrames(1);
217 Resource_ResetEntry(handle);
218 }
219}
220
221/// Shows that two members joined the party while the join fanfare (sound 81)
222/// plays, until it ends or A, B, L or R is pressed. The message is
223/// `<first> and <second> joined your party.`, with both portraits.
225 u8 *work = gWindowWork[0];
226 struct UiWindow *window;
227 s32 sprite2[3];
228 s32 sprite1[3];
229 s32 *entry1;
230 s32 *entry2;
231 s32 handle1, palette, handle2;
232 u32 zero;
233 s32 *p;
234
235 // The window starts as NULL, though it is assigned before it is read; the
236 // same zero is the style argument below.
237 window = NULL;
238 entry1 = sprite1;
239 window = UiWindow_Create(1, 1, 28, 5, 0);
240 zero = 0;
241
242 if (window != NULL) {
243 UiWindow_DrawDividerLine(window, 8, 0, 4, 4);
244
245 ((struct UiRenderWork *)work)->dirty = 1;
246
249 0, &handle1, &palette, 14, zero);
250 // The portrait as a bare OAM entry, pushed onto draw layer 250 each frame:
251 // a link word, attributes 0 and 1 (32x32 at y 12) and attribute 2.
252 p = entry1;
253 *p++ = zero;
254 *p++ = 0x800c000c;
255 *p = palette | 0xe000;
256
257 entry2 = sprite2;
260 0, &handle2, &palette, 15, zero);
261 p = entry2;
262 *p++ = zero;
263 *p++ = 0x802c000c;
264 *p = palette | 0xf000;
265
266 ((struct UiRenderWork *)work)->speakerVoiceSound = zero;
267 ((struct UiRenderWork *)work)->speakerVoiceCountdown = zero;
268
269 UiWork_PushValueSlot(first, 1);
270 UiWork_PushValueSlot(second, 1);
271
272 JOINED_QUEUE_TEXT(window,
273 UiText_BuildRenderEntriesMode1(MsgPairJoinedParty), 68, 2,
274 zero);
275
277
278 do {
279 Runtime_PushSlotEntry(entry1, 250);
280 Runtime_PushSlotEntry(entry2, 250);
281 WaitFrames(1);
282 } while (AudioCommand_GetStateByteFar() != 0 &&
283 (gKeysPressed & (KEY_A | KEY_B | KEYS_SHOULDERS)) == 0);
284
285 UiWork_Finalize(window, 2);
286 WaitFrames(1);
287 Resource_ResetEntry(handle1);
288 Resource_ResetEntry(handle2);
289 }
290}
291
292#undef JOINED_QUEUE_TEXT
What every part of the menu object shares: its includes, edition values, macros and the link round st...
#define OUTPUT_SIZE_16X16
OAM attribute bits a sprite output is created with: the size field of attribute 1 (bits 30-31 of the ...
static __inline__ void Dma_Set(const volatile void *source, volatile void *destination, u32 control, volatile u32 *channel)
Starts a DMA transfer: stores the source, destination and control words into channel's registers with...
Definition dma.h:62
s32 GameFlag_TestFar(s32 flag)
void Shop_SetCursorFar(struct ShopCursor *cursor, s32 targetX, s32 targetY, s32 kind)
void ShopCursor_SetPositionImmediateFar(struct ShopCursor *cursor, s32 x, s32 y)
void ShopCursor_AdvanceFar(struct ShopCursor *cursor)
void AudioCommand_PlayFar(s32 id)
s32 AudioCommand_GetStateByteFar(void)
#define FLAG_CHILDHOOD
the prologue: Isaac and Garet are children
Definition flags.h:10
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
s16 gDjinn_ElementSprites[]
s16 gCharacter_SpriteTable[]
s16 gCharacter_ChildSpriteTable[]
u8 gResource_FixedBlockBTiles[]
@ KEY_UP
Definition io_reg.h:249
@ KEY_B
Definition io_reg.h:244
@ KEY_A
Definition io_reg.h:243
@ KEY_DOWN
Definition io_reg.h:250
@ KEYS_SHOULDERS
Definition io_reg.h:256
#define REG_DMA3
Definition io_reg.h:153
#define BG_PLTT_COLOR(palette, color)
Definition io_reg.h:158
void Party_ShowJoinedMessage(s32 member)
Shows that a member joined the party while the join fanfare (sound 81) plays, until it ends or A,...
Definition joined.c:183
s32 PartyTalkMenu_Choose(s32 unused)
The Colosso choice of what to do: "Descriptions", "Cheer" or "Nothing", chosen with a pointing hand.
Definition joined.c:33
void Djinn_ShowJoinedMessage(s32 member, s32 element, s32 djinn)
Shows that a Djinni joined a member while the join fanfare (sound 81) plays, until it ends or A,...
Definition joined.c:109
#define JOINED_QUEUE_TEXT(window, entry, x, y, spacing)
Definition joined.c:14
s32 Party_LookupCharacterValueByFlag32(u32 index)
Returns the portrait character of party member member (0-8): from gCharacter_ChildSpriteTable during ...
Definition joined.c:170
#define TALK_WINDOW_X
Definition joined.c:20
#define TALK_WINDOW_WIDTH
Definition joined.c:21
void Party_ShowPairJoinedMessage(s32 first, s32 second)
Shows that two members joined the party while the join fanfare (sound 81) plays, until it ends or A,...
Definition joined.c:224
volatile u32 gKeysPressed
Keys that went down this frame.
volatile u32 gKeysRepeat
Pressed keys, repeating while held: after 19 frames, then every 6.
void UiWindow_SetTileAttributeRect(const struct UiWindow *window, s32 x, s32 y, s32 width, s32 height, u32 palette)
Like UiWindow_SetTileAttributeBitRect, but ORs all of palette into the palette number of each entry (...
Definition name_entry.c:89
struct RenderOutput * RenderOutput_Create(s32 slot, s32 oamFlags, struct UiWindow *window, s32 offsetX, s32 offsetY)
Creates a sprite output for the VRAM cache slot slot and attaches it to window, placed at (offsetX,...
Definition outputs.c:13
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
#define MUS_081
Definition songs.h:80
#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
#define NULL
Definition bilibin.h:6
u8 gWindowWork[]
The window system's work: the windows' tilemap, the windows, the three text channels,...
Definition window.h:19
u16 speakerVoiceCountdown
characters until the next voice blip
Definition window.h:61
u8 dirty
The tilemap's 4-row bands to upload: bit 0 for all, bit n + 1 for band n.
Definition window.h:32
u16 speakerVoiceSound
first of four voice blip sounds; 0 for none
Definition window.h:60
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
#define DJINN_JOIN_X
#define DJINN_JOIN_WIDTH
void UiWindow_DrawDividerLine(struct UiWindow *win, u32 x1, u32 y1, u32 x2, u32 y2)
Draws a straight divider line inside a window from tile (x1, y1) to (x2, y2), horizontal or vertical:...
Definition text_tiles.c:365
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
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11
A menu cursor: its render output, or the cursor that approaches its target.
Definition cursor.h:30
struct ShopCursor cursor
Definition cursor.h:32
#define DMA_COPY32(count)
The DMA control word that copies count words.
Definition window.h:112
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
@ VRAM_CACHE_ENTRY_COUNT
Definition vram_tab.h:12
void UiGlyph_LoadEntryWithPalette(u32 icon, s32 unused, s32 *slot, s32 *tile, s32 palette, s32 reuse)
Loads a 32x32 icon from the icon resource into sprite tile slot *slot (a free slot unless reuse is se...
Definition icons.c:291
s32 Localization_LookupEntryId(u32 value)
Returns the portrait of a character (ids below 20) or another speaker's sprite (128 and up for those)...
Definition messages.c:486
void UiWork_PushValueSlot(u32 value, u32 kind)
Adds a message argument of kind (MSG_ARG_) with value to the first free place of the argument table; ...
Definition messages.c:216
s32 UiText_BuildRenderEntriesMode1(s32 message)
Decodes message and empties the argument table; returns where its decoded text starts.
Definition messages.c:372
void UiWork_Finalize(struct UiWindow *window, s32 instant)
Closes a window: clears its contents and remembers its last rectangle.
Definition windows.c:349
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