-
Notifications
You must be signed in to change notification settings - Fork 2
/
dialog.c
304 lines (295 loc) · 7.74 KB
/
dialog.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#include "audio.h"
#include "continuegame.h"
#include "dialog.h"
#include "fbox.h"
#include "main.h"
#include "mplay_stuff.h"
#include "rbox.h"
#include "save.h"
#include "text.h"
#include "uncategorized.h"
#ifndef NO_RAM
// 03003E50
u32 textflags;
#endif
struct dialog dialogs[32];
// 08005680
bool text_is_it_time_to_continue() {
if (textflags & TEXT_AUTO_CONTINUE)
return text_is_it_time_to_continue_autopilot();
if (super.buttons_new_remapped & (KEYPAD_A|KEYPAD_B)) {
audio_play(sound_generic_clink);
return true;
}
return false;
}
// 08005790
uint dialog_update(struct dialog *dialog) {
struct typesetter *tys = &dialog->tys;
struct dialogsub *dsub = &dialog->sub;
switch (dialog->mode) {
// Parse mode
case 0u:
if (super.buttons_held_remapped & (KEYPAD_B|KEYPAD_A)) {
if (dsub->user_can_skip)
dialog->wait_frames = 0;
}
if (!dialog->wait_frames || dialog->text_speed_inv == 0) {
if ( textflags & 4 )
dialog->wait_frames = 1;
else
dialog->wait_frames = dialog->text_speed_inv;
int c = *tys->ccursor++;
switch ( c )
{
case 0xFE: // Line break
tys->cursor_x = tys->reset_x;
tys->cursor_y += tys->stride_y + fboxes_ptr[tys->fbox_id].x;
return 2;
case 0xFD: // Variable (?)
tys->ccursor++;
return 2;
case 0xFC: // Special control
c = *tys->ccursor++;
switch ( c )
{
// cases 0x01..0x18
case 1: // Color foreground
tys->color1 = *tys->ccursor++;
font_lookup_table_calc(tys->color1, tys->color2, tys->color3);
return 2;
case 2: // Color background
tys->color2 = *tys->ccursor++;
font_lookup_table_calc(tys->color1, tys->color2, tys->color3);
return 2;
case 3: // Color shadow
tys->color3 = *tys->ccursor++;
font_lookup_table_calc(tys->color1, tys->color2, tys->color3);
return 2;
case 4: // Color fg and bg and shadow
tys->color1 = *tys->ccursor++;
tys->color2 = *tys->ccursor++;
tys->color3 = *tys->ccursor++;
font_lookup_table_calc(tys->color1, tys->color2, tys->color3);
return 2;
case 5: // Nop
tys->ccursor++;
return 2;
case 6: // Select font
dsub->ft_lo = *tys->ccursor++;
return 2;
case 7: // Nop (but stay)
return 2;
case 8: // Pause
dialog->wait_frames = *tys->ccursor++;
dialog->mode = 6;
return 2;
case 9: // Wait for key
dialog->mode = 1;
if ( textflags & 4 ) {
dsub->frames_visible_counter &= 0xff00;
}
return 3;
case 0xA: // Wait for audio
dialog->mode = 5;
return 3;
case 0xB: { // Play song
u8 lo = *tys->ccursor++;
u8 hi = *tys->ccursor++;
if (prev_quest_mode < 2 || prev_quest_mode >= 4)
song_play_for_text((hi << 8) | lo);
return 2;
}
case 0x10: { // Play sound
u8 lo = *tys->ccursor++;
u8 hi = *tys->ccursor++;
audio_play((hi << 8) | lo);
return 2;
}
case 0xC: // Escape
c = *tys->ccursor++;
break;
case 0xD: // Set x
tys->cursor_x = tys->reset_x + *tys->ccursor++;
return 2;
case 0xE: // Set y
tys->cursor_y = tys->reset_y + *tys->ccursor++;
return 2;
case 0xF: // Clear
rboxid_clear_pixels(
tys->rbox_id,
(tys->color2 << 4) | tys->color2);
return 2;
case 0x17: // Pause music
MPlayStop_rev01(&mplay_te_03007300);
return 2;
case 0x18: // Resume music
m4aMPlayContinue(&mplay_te_03007300);
return 2;
case 0x11: { // ???
int t = *tys->ccursor++;
if ( t <= 0 )
return 2;
tys->cursor_x += t;
return 0;
}
case 0x12: // ???
tys->cursor_x = tys->reset_x + *tys->ccursor++;
return 2;
case 0x13: { // ???
int t = tys->reset_x + *tys->ccursor++;
t = t - tys->cursor_x;
if ( t <= 0 )
return 2;
tys->cursor_x += t;
return 0;
}
case 0x14: // ???
dialog->field_20 = *tys->ccursor++;
return 2;
case 0x15: // Japanese on (Spread text)
dialog->japanese = 1;
return 2;
case 0x16: // Japanese off (default)
dialog->japanese = 0;
return 2;
default:
break;
}
break;
case 0xFB: // Next page
dialog->mode = 2;
dialog_80054C8(dialog);
return 3;
case 0xFA: // Scroll line
dialog->mode = 3;
dialog_80054C8(dialog);
return 3;
case 0xF9: // Allows you to select characters from a second page
c = *tys->ccursor++ | 0x100;
break;
case 0xF8: {
int t = *tys->ccursor++;
byte_3003E20 = font_render_F8(
tys->rbox_id,
t,
tys->cursor_x,
tys->cursor_y);
tys->cursor_x += byte_3003E20 + tys->stride_x;
return 0;
}
case 0xFF: // End
return 1;
default:
break;
}
switch (dsub->ft_lo)
{
case 0:
font_render_tiny_en_jp(c, dialog->japanese);
break;
case 1:
font_render_other_en_jp(c, dialog->japanese);
break;
case 2:
font_render_black_en_jp(c, dialog->japanese);
break;
case 3:
sub_8006724(c, dialog->japanese);
break;
case 4:
font_render_blue_en_jp(c, dialog->japanese);
break;
case 5:
font_render_red_en_jp(c, dialog->japanese);
break;
default:
break;
}
sub_8003014(dialog);
char new_x = tys->cursor_x;
if ( dialog->field_20 ) {
tys->cursor_x += byte_3003E20;
int t = dialog->field_20 - byte_3003E20;
if ( t <= 0 )
return 0;
nullsub_2();
new_x += byte_3003E20 + t;
} else {
new_x += byte_3003E20;
if (dialog->japanese) {
new_x += tys->stride_x;
}
}
tys->cursor_x = new_x;
return 0;
}
--dialog->wait_frames;
if ( textflags & 1 ) {
if ( super.buttons_new_remapped & 3 ) {
dsub->user_can_skip = 0;
dialog->wait_frames = 0;
}
}
return 3;
case 1u:
if (dialog_is_it_time_to_continue(dialog))
dialog->mode = 0;
return 3;
case 2u:
if ( dialog_is_it_time_to_continue_plus_80054F8(dialog) << 16 ) {
rboxid_clear_pixels(
tys->rbox_id,
(tys->color2 << 4) | tys->color2);
tys->cursor_x = tys->reset_x;
tys->cursor_y = tys->reset_y;
dialog->mode = 0;
}
return 3;
case 3u:
if ( dialog_is_it_time_to_continue_plus_80054F8(dialog) << 16 ) {
sub_80055D4(dialog);
dialog->remaining_scroll_lines = tys->stride_y + fboxes_ptr[tys->fbox_id].x;
tys->cursor_x = tys->reset_x;
dialog->mode = 4;
}
return 3;
case 4u: {
uint rlines = dialog->remaining_scroll_lines;
u8 speed_index = saveblock2_trainerdata->options_text_speed_maybe & 7;
if (rlines > 0) {
if (rlines >= text_speeds[speed_index]) {
rboxid_vertical_scroll(
tys->rbox_id,
0,
text_speeds[speed_index],
(tys->color2 << 4) | tys->color2);
dialog->remaining_scroll_lines -= text_speeds[speed_index];
} else {
rboxid_vertical_scroll(
tys->rbox_id,
0,
rlines,
(tys->color2 << 4) | tys->color2);
dialog->remaining_scroll_lines = 0;
}
rboxid_upload_a(tys->rbox_id, 2u);
} else {
dialog->mode = 0;
}
return 3;
}
case 5u:
if ( !mplay_has_finished_maybe() )
dialog->mode = 0;
return 3;
case 6u:
if ( dialog->wait_frames )
--dialog->wait_frames;
else
dialog->mode = 0;
return 3;
default:
return 1;
}
}