Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
evt.c
Go to the documentation of this file.
1#include "common.h"
2#include "vars_access.h"
3
4extern u32* gMapFlags;
5extern s32* gMapVars;
6
7extern char evtDebugPrintBuffer[0x100];
9
10Bytecode* evt_find_label(Evt* script, s32 arg1);
11Bytecode* evt_skip_if(Evt* script);
12Bytecode* evt_skip_else(Evt* script);
16
18 if (scriptVar <= EVT_FIXED_CUTOFF) {
19 return EVT_FIXED_TO_FLOAT(scriptVar);
20 } else {
21 return scriptVar;
22 }
23}
24
26 // not equivalent to the FLOAT_TO_FIXED() macro due to the s32 cast
27 // occuring *before* the add here and *after* the add in the macro
28 return (s32)(value * 1024.0f) + -EVT_FIXED_OFFSET;
29}
30
32 kill_script(script);
33 return ApiStatus_FINISH;
34}
35
39
41 script->ptrNextLine = evt_find_label(script, evt_get_variable(script, *script->ptrReadPos));
42 return ApiStatus_DONE2;
43}
44
46 Bytecode* args = script->ptrReadPos;
47 Bytecode var = *args++;
48 s32 loopDepth = ++script->loopDepth;
49
50 ASSERT(loopDepth < 8);
51
52 script->loopStartTable[loopDepth] = (s32)args;
53 script->loopCounterTable[loopDepth] = var;
54
55 return ApiStatus_DONE2;
56}
57
59 s32 loopDepth = script->loopDepth;
60 s32 loopCounter;
61
62 ASSERT(loopDepth >= 0);
63
64 loopCounter = script->loopCounterTable[loopDepth];
65
66 if (loopCounter == 0) {
67 script->ptrNextLine = (Bytecode*)script->loopStartTable[loopDepth];
68 return ApiStatus_DONE2;
69 }
70
71 if (loopCounter >= -10000000) {
72 script->loopCounterTable[loopDepth] = --loopCounter;
73 } else {
74 s32 var = evt_get_variable(script, loopCounter) - 1;
75 evt_set_variable(script, loopCounter, var);
76 loopCounter = var;
77 }
78
79 if (loopCounter != 0) {
80 script->ptrNextLine = (Bytecode*)script->loopStartTable[loopDepth];
81 return ApiStatus_DONE2;
82 } else {
83 script->loopDepth--;
84 return ApiStatus_DONE2;
85 }
86}
87
89 ASSERT(script->loopDepth >= 0);
90 script->ptrNextLine = evt_goto_end_loop(script);
91 script->loopDepth -= 1;
92 return ApiStatus_DONE2;
93}
94
96 Bytecode* ptrReadPos = script->ptrReadPos;
97
98 if (!script->blocked) {
99 script->functionTemp[0] = evt_get_variable(script, *ptrReadPos);
100 script->blocked = 1;
101 }
102
103 if (script->functionTemp[0] == 0) {
104 return ApiStatus_DONE2;
105 }
106
107 script->functionTemp[0] -= 1;
108 return !script->functionTemp[0];
109}
110
112 Bytecode* ptrReadPos = script->ptrReadPos;
113
114 if (!script->blocked) {
115 script->functionTemp[0] = evt_get_float_variable(script, *ptrReadPos) * 30.0f + 0.5;
116 script->blocked = 1;
117 }
118
119 if (script->functionTemp[0] == 0) {
120 return ApiStatus_DONE2;
121 }
122
123 script->functionTemp[0]--;
124 return !script->functionTemp[0];
125}
126
128 Bytecode* args = script->ptrReadPos;
129 s32 val1 = evt_get_variable(script, *args++);
130 s32 val2 = evt_get_variable(script, *args++);
131
132 if (val1 != val2) {
133 script->ptrNextLine = evt_skip_if(script);
134 return ApiStatus_DONE2;
135 }
136 return ApiStatus_DONE2;
137}
138
140 Bytecode* args = script->ptrReadPos;
141 s32 val1 = evt_get_variable(script, *args++);
142 s32 val2 = evt_get_variable(script, *args++);
143
144 if (val1 == val2) {
145 script->ptrNextLine = evt_skip_if(script);
146 return ApiStatus_DONE2;
147 }
148 return ApiStatus_DONE2;
149}
150
152 Bytecode* args = script->ptrReadPos;
153 s32 val1 = evt_get_variable(script, *args++);
154 s32 val2 = evt_get_variable(script, *args++);
155
156 if (val1 >= val2) {
157 script->ptrNextLine = evt_skip_if(script);
158 return ApiStatus_DONE2;
159 }
160 return ApiStatus_DONE2;
161}
162
164 Bytecode* args = script->ptrReadPos;
165 s32 val1 = evt_get_variable(script, *args++);
166 s32 val2 = evt_get_variable(script, *args++);
167
168 if (val1 <= val2) {
169 script->ptrNextLine = evt_skip_if(script);
170 return ApiStatus_DONE2;
171 }
172 return ApiStatus_DONE2;
173}
174
176 Bytecode* args = script->ptrReadPos;
177 s32 val1 = evt_get_variable(script, *args++);
178 s32 val2 = evt_get_variable(script, *args++);
179
180 if (val1 > val2) {
181 script->ptrNextLine = evt_skip_if(script);
182 return ApiStatus_DONE2;
183 }
184 return ApiStatus_DONE2;
185}
186
188 Bytecode* args = script->ptrReadPos;
189 s32 val1 = evt_get_variable(script, *args++);
190 s32 val2 = evt_get_variable(script, *args++);
191
192 if (val1 < val2) {
193 script->ptrNextLine = evt_skip_if(script);
194 return ApiStatus_DONE2;
195 }
196 return ApiStatus_DONE2;
197}
198
200 Bytecode* args = script->ptrReadPos;
201 Bytecode var = *args++;
202
203 if ((evt_get_variable(script, var) & *args++) == 0) {
204 script->ptrNextLine = evt_skip_if(script);
205 return ApiStatus_DONE2;
206 }
207 return ApiStatus_DONE2;
208}
209
211 Bytecode* args = script->ptrReadPos;
212 Bytecode var = *args++;
213
214 if ((evt_get_variable(script, var) & *args++) != 0) {
215 script->ptrNextLine = evt_skip_if(script);
216 return ApiStatus_DONE2;
217 }
218 return ApiStatus_DONE2;
219}
220
222 script->ptrNextLine = evt_skip_else(script);
223 return ApiStatus_DONE2;
224}
225
227 return ApiStatus_DONE2;
228}
229
231 Bytecode* args = script->ptrReadPos;
232 Bytecode value = evt_get_variable(script, *args++);
233 s32 switchDepth = ++script->switchDepth;
234
235 ASSERT(switchDepth < 8);
236
237 script->switchBlockValue[switchDepth] = value;
238 script->switchBlockState[switchDepth] = 1;
239
240 return ApiStatus_DONE2;
241}
242
244 Bytecode* args = script->ptrReadPos;
245 s32 a0 = *args++;
246 s32 switchDepth = ++script->switchDepth;
247
248 ASSERT(switchDepth < 8);
249
250 script->switchBlockValue[switchDepth] = a0;
251 script->switchBlockState[switchDepth] = 1;
252
253 return ApiStatus_DONE2;
254}
255
257 Bytecode* args = script->ptrReadPos;
258 s32 switchDepth = script->switchDepth;
259 s32 var;
260 s32 switchBlockValue;
261
262 ASSERT(switchDepth >= 0);
263
264 var = evt_get_variable(script, *args++);
265 switchBlockValue = script->switchBlockValue[switchDepth];
266
267 if (script->switchBlockState[switchDepth] <= 0) {
268 script->ptrNextLine = evt_goto_end_case(script);
269 return ApiStatus_DONE2;
270 } else if (var != switchBlockValue) {
271 script->ptrNextLine = evt_goto_next_case(script);
272 } else {
273 script->switchBlockState[switchDepth] = 0;
274 }
275
276 return ApiStatus_DONE2;
277}
278
280 Bytecode* args = script->ptrReadPos;
281 s32 switchDepth = script->switchDepth;
282 s32 var;
283 s32 switchBlockValue;
284
285 ASSERT(switchDepth >= 0);
286
287 var = evt_get_variable(script, *args++);
288 switchBlockValue = script->switchBlockValue[switchDepth];
289
290 if (script->switchBlockState[switchDepth] <= 0) {
291 script->ptrNextLine = evt_goto_end_case(script);
292 return ApiStatus_DONE2;
293 } else if (var == switchBlockValue) {
294 script->ptrNextLine = evt_goto_next_case(script);
295 } else {
296 script->switchBlockState[switchDepth] = 0;
297 }
298
299 return ApiStatus_DONE2;
300}
301
303 Bytecode* args = script->ptrReadPos;
304 s32 switchDepth = script->switchDepth;
305 s32 var;
306 s32 switchBlockValue;
307
308 ASSERT(switchDepth >= 0);
309
310 var = evt_get_variable(script, *args++);
311 switchBlockValue = script->switchBlockValue[switchDepth];
312
313 if (script->switchBlockState[switchDepth] <= 0) {
314 script->ptrNextLine = evt_goto_end_case(script);
315 return ApiStatus_DONE2;
316 } else if (var <= switchBlockValue) {
317 script->ptrNextLine = evt_goto_next_case(script);
318 } else {
319 script->switchBlockState[switchDepth] = 0;
320 }
321
322 return ApiStatus_DONE2;
323}
324
326 Bytecode* args = script->ptrReadPos;
327 s32 switchDepth = script->switchDepth;
328 s32 var;
329 s32 switchBlockValue;
330
331 ASSERT(switchDepth >= 0);
332
333 var = evt_get_variable(script, *args++);
334 switchBlockValue = script->switchBlockValue[switchDepth];
335
336 if (script->switchBlockState[switchDepth] <= 0) {
337 script->ptrNextLine = evt_goto_end_case(script);
338 return ApiStatus_DONE2;
339 } else if (var < switchBlockValue) {
340 script->ptrNextLine = evt_goto_next_case(script);
341 } else {
342 script->switchBlockState[switchDepth] = 0;
343 }
344
345 return ApiStatus_DONE2;
346}
347
349 Bytecode* args = script->ptrReadPos;
350 s32 switchDepth = script->switchDepth;
351 s32 var;
352 s32 switchBlockValue;
353
354 ASSERT(switchDepth >= 0);
355
356 var = evt_get_variable(script, *args++);
357 switchBlockValue = script->switchBlockValue[switchDepth];
358
359 if (script->switchBlockState[switchDepth] <= 0) {
360 script->ptrNextLine = evt_goto_end_case(script);
361 return ApiStatus_DONE2;
362 } else if (var >= switchBlockValue) {
363 script->ptrNextLine = evt_goto_next_case(script);
364 } else {
365 script->switchBlockState[switchDepth] = 0;
366 }
367
368 return ApiStatus_DONE2;
369}
370
372 Bytecode* args = script->ptrReadPos;
373 s32 switchDepth = script->switchDepth;
374 s32 var;
375 s32 switchBlockValue;
376
377 ASSERT(switchDepth >= 0);
378
379 var = evt_get_variable(script, *args++);
380 switchBlockValue = script->switchBlockValue[switchDepth];
381
382 if (script->switchBlockState[switchDepth] <= 0) {
383 script->ptrNextLine = evt_goto_end_case(script);
384 return ApiStatus_DONE2;
385 } else if (var > switchBlockValue) {
386 script->ptrNextLine = evt_goto_next_case(script);
387 } else {
388 script->switchBlockState[switchDepth] = 0;
389 }
390
391 return ApiStatus_DONE2;
392}
393
395 Bytecode* args = script->ptrReadPos;
396 s32 switchDepth = script->switchDepth;
397 s32 var;
398 s32 var2;
399 s32 switchBlockValue;
400
401 ASSERT(switchDepth >= 0);
402
403 var = evt_get_variable(script, *args++);
404 var2 = evt_get_variable(script, *args++);
405
406 switchBlockValue = script->switchBlockValue[switchDepth];
407
408 if (script->switchBlockState[switchDepth] <= 0) {
409 script->ptrNextLine = evt_goto_end_case(script);
410 return ApiStatus_DONE2;
411 } else if ((var <= switchBlockValue) && (switchBlockValue <= var2)) {
412 script->switchBlockState[switchDepth] = 0;
413 } else {
414 script->ptrNextLine = evt_goto_next_case(script);
415 }
416
417 return ApiStatus_DONE2;
418}
419
421 s32 switchDepth = script->switchDepth;
422
423 ASSERT(switchDepth >= 0);
424
425 if (script->switchBlockState[switchDepth] <= 0) {
426 script->ptrNextLine = evt_goto_end_case(script);
427 return ApiStatus_DONE2;
428 } else {
429 script->switchBlockState[switchDepth] = 0;
430 }
431
432 return ApiStatus_DONE2;
433}
434
436 Bytecode* args = script->ptrReadPos;
437 s32 switchDepth = script->switchDepth;
438 s32 var;
439 s32 switchBlockValue;
440 s32 switchBlockState;
441
442 ASSERT(switchDepth >= 0);
443
444 var = *args++;
445 switchBlockValue = script->switchBlockValue[switchDepth];
446 switchBlockState = script->switchBlockState[switchDepth];
447
448 if (switchBlockState <= 0) {
449 script->ptrNextLine = evt_goto_end_case(script);
450 return ApiStatus_DONE2;
451 } else if ((var & switchBlockValue) == 0) {
452 script->ptrNextLine = evt_goto_next_case(script);
453 } else {
454 script->switchBlockState[switchDepth] = 0;
455 }
456
457 return ApiStatus_DONE2;
458}
459
461 Bytecode* args = script->ptrReadPos;
462 s32 switchDepth = script->switchDepth;
463 s32 var;
464 s32 switchBlockValue;
465 s32 switchBlockState;
466
467 ASSERT(switchDepth >= 0);
468
469 var = evt_get_variable(script, *args++);
470 switchBlockValue = script->switchBlockValue[switchDepth];
471 switchBlockState = script->switchBlockState[switchDepth];
472
473 if (switchBlockState == 0) {
474 script->ptrNextLine = evt_goto_end_case(script);
475 return ApiStatus_DONE2;
476 } else if (var == switchBlockValue) {
477 script->switchBlockState[switchDepth] = -1;
478 } else if (switchBlockState != -1) {
479 script->ptrNextLine = evt_goto_next_case(script);
480 }
481
482 return ApiStatus_DONE2;
483}
484
486 Bytecode* args = script->ptrReadPos;
487 s32 switchDepth = script->switchDepth;
488 s32 var;
489 s32 switchBlockValue;
490 s32 switchBlockState;
491
492 ASSERT(switchDepth >= 0);
493
494 var = evt_get_variable(script, *args++);
495 switchBlockValue = script->switchBlockValue[switchDepth];
496 switchBlockState = script->switchBlockState[switchDepth];
497
498 if (switchBlockState == 0) {
499 script->ptrNextLine = evt_goto_end_case(script);
500 return ApiStatus_DONE2;
501 } else if (switchBlockState == -2) {
502 script->ptrNextLine = evt_goto_next_case(script);
503 } else if (var == switchBlockValue) {
504 script->switchBlockState[switchDepth] = -1;
505 } else {
506 script->switchBlockState[switchDepth] = -2;
507 script->ptrNextLine = evt_goto_next_case(script);
508 }
509
510 return ApiStatus_DONE2;
511}
512
514 ASSERT(script->switchDepth >= 0);
515
516 if (script->switchBlockState[script->switchDepth] == 0) {
517 script->ptrNextLine = evt_goto_end_case(script);
518 return ApiStatus_DONE2;
519 } else if (script->switchBlockState[script->switchDepth] != -1) {
520 script->switchBlockState[script->switchDepth] = 1;
521 script->ptrNextLine = evt_goto_next_case(script);
522 } else {
523 script->switchBlockState[script->switchDepth] = 0;
524 script->ptrNextLine = evt_goto_end_case(script);
525 }
526
527 return ApiStatus_DONE2;
528}
529
531 ASSERT(script->switchDepth >= 0);
532 script->ptrNextLine = evt_goto_end_case(script);
533 return ApiStatus_DONE2;
534}
535
537 s32 switchDepth = script->switchDepth;
538
539 ASSERT(switchDepth >= 0);
540
541 script->switchBlockState[switchDepth] = 0;
542 script->switchDepth -= 1;
543
544 return ApiStatus_DONE2;
545}
546
548 Bytecode* args = script->ptrReadPos;
549 s32 curPtrReadPos = *args++;
550
551 evt_set_variable(script, curPtrReadPos, evt_get_variable(script, *args++));
552 return ApiStatus_DONE2;
553}
554
556 evt_set_variable(script, *script->ptrReadPos, script->ptrReadPos[1]);
557 return ApiStatus_DONE2;
558}
559
561 Bytecode* args = script->ptrReadPos;
562 Bytecode var = *args++;
563
564 evt_set_float_variable(script, var, evt_get_float_variable(script, *args++));
565 return ApiStatus_DONE2;
566}
567
569 Bytecode* args = script->ptrReadPos;
570 Bytecode var = *args++;
571 s32 result = evt_get_variable(script, *args++);
572 s32 addend = evt_get_variable(script, var);
573
574 result += addend;
575
576 evt_set_variable(script, var, result);
577 return ApiStatus_DONE2;
578}
579
581 Bytecode* args = script->ptrReadPos;
582 Bytecode var = *args++;
583 s32 result = evt_get_variable(script, *args++);
584 s32 minuend = evt_get_variable(script, var);
585
586 result = minuend - result;
587
588 evt_set_variable(script, var, result);
589 return ApiStatus_DONE2;
590}
591
593 Bytecode* args = script->ptrReadPos;
594 Bytecode var = *args++;
595 s32 result = evt_get_variable(script, *args++);
596 s32 multiplier = evt_get_variable(script, var);
597
598 result *= multiplier;
599
600 evt_set_variable(script, var, result);
601 return ApiStatus_DONE2;
602}
603
605 Bytecode* args = script->ptrReadPos;
606 Bytecode var = *args++;
607 s32 result = evt_get_variable(script, *args++);
608 s32 dividend = evt_get_variable(script, var);
609
610 result = dividend / result;
611
612 evt_set_variable(script, var, result);
613 return ApiStatus_DONE2;
614}
615
617 Bytecode* args = script->ptrReadPos;
618 Bytecode var = *args++;
619 s32 result = evt_get_variable(script, *args++) + 0.5;
620 s32 num = evt_get_variable(script, var) + 0.5;
621
622 result = num % result;
623
624 evt_set_variable(script, var, result);
625 return ApiStatus_DONE2;
626}
627
629 Bytecode* args = script->ptrReadPos;
630 Bytecode var = *args++;
631 f32 result = evt_get_float_variable(script, *args++);
632 f32 addend = evt_get_float_variable(script, var);
633
634 result += addend;
635
636 evt_set_float_variable(script, var, result);
637 return ApiStatus_DONE2;
638}
639
641 Bytecode* args = script->ptrReadPos;
642 Bytecode var = *args++;
643 f32 result = evt_get_float_variable(script, *args++);
644 f32 minuend = evt_get_float_variable(script, var);
645
646 result = minuend - result;
647
648 evt_set_float_variable(script, var, result);
649 return ApiStatus_DONE2;
650}
651
653 Bytecode* args = script->ptrReadPos;
654 Bytecode var = *args++;
655 f32 result = evt_get_float_variable(script, *args++);
656 f32 multiplier = evt_get_float_variable(script, var);
657
658 result *= multiplier;
659
660 evt_set_float_variable(script, var, result);
661 return ApiStatus_DONE2;
662}
663
665 Bytecode* args = script->ptrReadPos;
666 Bytecode var = *args++;
667 f32 result = evt_get_float_variable(script, *args++);
668 f32 dividend = evt_get_float_variable(script, var);
669
670 result = dividend / result;
671
672 evt_set_float_variable(script, var, result);
673 return ApiStatus_DONE2;
674}
675
677 Bytecode* args = script->ptrReadPos;
678
679 script->buffer = (s32*) evt_get_variable(script, *args++);
680 return ApiStatus_DONE2;
681}
682
684 Bytecode* args = script->ptrReadPos;
685
686 script->buffer = (s32*) evt_get_variable(script, *args++);
687 return ApiStatus_DONE2;
688}
689
691 Bytecode* args = script->ptrReadPos;
692 Bytecode var;
693
694 var = *args++;
695 evt_set_variable(script, var, *script->buffer++);
696
697 return ApiStatus_DONE2;
698}
699
701 Bytecode* args = script->ptrReadPos;
702 Bytecode var;
703
704 var = *args++;
705 evt_set_variable(script, var, *script->buffer++);
706
707 var = *args++;
708 evt_set_variable(script, var, *script->buffer++);
709
710 return ApiStatus_DONE2;
711}
712
714 Bytecode* args = script->ptrReadPos;
715 Bytecode var;
716
717 var = *args++;
718 evt_set_variable(script, var, *script->buffer++);
719
720 var = *args++;
721 evt_set_variable(script, var, *script->buffer++);
722
723 var = *args++;
724 evt_set_variable(script, var, *script->buffer++);
725
726 return ApiStatus_DONE2;
727}
728
730 Bytecode* args = script->ptrReadPos;
731 Bytecode var;
732
733 var = *args++;
734 evt_set_variable(script, var, *script->buffer++);
735
736 var = *args++;
737 evt_set_variable(script, var, *script->buffer++);
738
739 var = *args++;
740 evt_set_variable(script, var, *script->buffer++);
741
742 var = *args++;
743 evt_set_variable(script, var, *script->buffer++);
744
745 return ApiStatus_DONE2;
746}
747
749 Bytecode* args = script->ptrReadPos;
750 Bytecode var;
751
752 var = *args++;
753 evt_set_variable(script, var, script->buffer[evt_get_variable(script, *args++)]);
754
755 return ApiStatus_DONE2;
756}
757
759 Bytecode* args = script->ptrReadPos;
760 Bytecode var;
761
762 var = *args++;
763 evt_set_float_variable(script, var, evt_get_float_variable(script, *script->buffer++));
764
765 return ApiStatus_DONE2;
766}
767
769 Bytecode* args = script->ptrReadPos;
770 Bytecode var;
771
772 var = *args++;
773 evt_set_float_variable(script, var, evt_get_float_variable(script, *script->buffer++));
774
775 var = *args++;
776 evt_set_float_variable(script, var, evt_get_float_variable(script, *script->buffer++));
777
778 return ApiStatus_DONE2;
779}
780
782 Bytecode* args = script->ptrReadPos;
783 Bytecode var;
784
785 var = *args++;
786 evt_set_float_variable(script, var, evt_get_float_variable(script, *script->buffer++));
787
788 var = *args++;
789 evt_set_float_variable(script, var, evt_get_float_variable(script, *script->buffer++));
790
791 var = *args++;
792 evt_set_float_variable(script, var, evt_get_float_variable(script, *script->buffer++));
793
794 return ApiStatus_DONE2;
795}
796
798 Bytecode* args = script->ptrReadPos;
799 Bytecode var;
800
801 var = *args++;
802 evt_set_float_variable(script, var, evt_get_float_variable(script, *script->buffer++));
803
804 var = *args++;
805 evt_set_float_variable(script, var, evt_get_float_variable(script, *script->buffer++));
806
807 var = *args++;
808 evt_set_float_variable(script, var, evt_get_float_variable(script, *script->buffer++));
809
810 var = *args++;
811 evt_set_float_variable(script, var, evt_get_float_variable(script, *script->buffer++));
812
813 return ApiStatus_DONE2;
814}
815
817 Bytecode* args = script->ptrReadPos;
818 Bytecode var;
819
820 var = *args++;
821 evt_set_float_variable(script, var, script->buffer[evt_get_variable(script, *args++)]);
822
823 return ApiStatus_DONE2;
824}
825
827 script->array = (s32*)evt_get_variable(script, *script->ptrReadPos);
828 return ApiStatus_DONE2;
829}
830
832 script->flagArray = (s32*)evt_get_variable(script, *script->ptrReadPos);
833 return ApiStatus_DONE2;
834}
835
837 Bytecode* args = script->ptrReadPos;
838 s32 size = evt_get_variable(script, *args++);
839 Bytecode var = *args++;
840
841 script->array = (s32*)heap_malloc(size * 4);
842 evt_set_variable(script, var, (s32)script->array);
843 return ApiStatus_DONE2;
844}
845
847 Bytecode* args = script->ptrReadPos;
848 s32 var = *args++;
849 s32 bits = evt_get_variable(script, *args++);
850 s32 prev = evt_get_variable(script, var);
851
852 evt_set_variable(script, var, prev & bits);
853 return ApiStatus_DONE2;
854}
855
857 Bytecode* args = script->ptrReadPos;
858 s32 var = *args++;
859 s32 bits = *args++;
860 s32 prev = evt_get_variable(script, var);
861
862 evt_set_variable(script, var, prev & bits);
863 return ApiStatus_DONE2;
864}
865
867 Bytecode* args = script->ptrReadPos;
868 s32 var = *args++;
869 s32 bits = evt_get_variable(script, *args++);
870 s32 prev = evt_get_variable(script, var);
871
872 evt_set_variable(script, var, prev | bits);
873 return ApiStatus_DONE2;
874}
875
877 Bytecode* args = script->ptrReadPos;
878 s32 var = *args++;
879 s32 bits = *args++;
880 s32 prev = evt_get_variable(script, var);
881
882 evt_set_variable(script, var, prev | bits);
883 return ApiStatus_DONE2;
884}
885
887 Bytecode* args = script->ptrReadPos;
888 s32 isInitialCall;
889 ApiFunc func;
890 ApiStatus ret;
891 EvtCallingLine = script->ptrCurLine;
892
893 if (script->blocked) {
894 isInitialCall = FALSE;
895 func = script->callFunction;
896 ret = func(script, isInitialCall);
897 } else {
898 script->callFunction = (ApiFunc)evt_get_variable(script, *args++);
899 script->ptrReadPos = args;
900 script->curArgc--;
901 script->blocked = TRUE;
902 isInitialCall = TRUE;
903 func = script->callFunction;
904 ret = func(script, isInitialCall);
905 }
906
907 EvtCallingLine = NULL;
908 return ret;
909}
910
912 Bytecode* args = script->ptrReadPos;
913 EvtScript* newSource = (EvtScript*)evt_get_variable(script, *args++);
914 Evt* newScript;
915 s32 i;
916
917 newScript = start_script_in_group(newSource, script->priority, 0, script->groupFlags);
918
919 newScript->owner1 = script->owner1;
920 newScript->owner2 = script->owner2;
921
922 for (i = 0; i < ARRAY_COUNT(script->varTable); i++) {
923 newScript->varTable[i] = script->varTable[i];
924 }
925
926 for (i = 0; i < ARRAY_COUNT(script->varFlags); i++) {
927 newScript->varFlags[i] = script->varFlags[i];
928 }
929
930 newScript->array = script->array;
931 newScript->flagArray = script->flagArray;
932
933 return ApiStatus_DONE2;
934}
935
936
938 Bytecode* args = script->ptrReadPos;
939 EvtScript* newSource = (EvtScript*)evt_get_variable(script, *args++);
940 Bytecode outVar = *args++;
941 Evt* newScript;
942 s32 i;
943
944 newScript = start_script_in_group(newSource, script->priority, 0, script->groupFlags);
945
946 newScript->owner1 = script->owner1;
947 newScript->owner2 = script->owner2;
948
949 for (i = 0; i < ARRAY_COUNT(script->varTable); i++) {
950 newScript->varTable[i] = script->varTable[i];
951 }
952
953 for (i = 0; i < ARRAY_COUNT(script->varFlags); i++) {
954 newScript->varFlags[i] = script->varFlags[i];
955 }
956
957 newScript->array = script->array;
958 newScript->flagArray = script->flagArray;
959
960 evt_set_variable(script, outVar, newScript->id);
961
962 return ApiStatus_DONE2;
963}
964
966 Bytecode* args = script->ptrReadPos;
967 EvtScript* newSource = (EvtScript*)evt_get_variable(script, *args++);
968
969 start_child_script(script, newSource, 0);
971 return ApiStatus_FINISH;
972}
973
975 Bytecode* args = script->ptrReadPos;
976
977 script->ptrFirstLine = (Bytecode*) evt_get_variable(script, *args++);
978 restart_script(script);
979 return ApiStatus_DONE2;
980}
981
983 EvtScript* scriptStart;
984 Evt* script;
985
986 if (trigger->runningScript == NULL) {
987 scriptStart = trigger->onTriggerEvt;
988 if (is_another_trigger_bound(trigger, scriptStart)) {
989 return 0;
990 }
991
992 script = start_script(scriptStart, trigger->priority, EVT_FLAG_RUN_IMMEDIATELY);
993 trigger->runningScript = script;
994 trigger->runningScriptID = script->id;
995 script->varTable[0] = trigger->varTable[0];
996 script->varTable[1] = trigger->varTable[1];
997 script->varTable[2] = trigger->varTable[2];
998 script->owner2.trigger = trigger;
999 }
1000
1001 if (!does_script_exist(trigger->runningScriptID)) {
1002 trigger->runningScript = NULL;
1003 return 0; // stop calling this function
1004 }
1005
1006 return 1; // keep calling this function every frame
1007}
1008
1010 Bytecode* args = script->ptrReadPos;
1011 Trigger* trigger;
1012 Bytecode* triggerScript = (Bytecode*)evt_get_variable(script, *args++);
1013 Bytecode triggerType = *args++;
1014 Bytecode colliderIDVar = *args++;
1015 Bytecode hasInteractPrompt = *args++;
1016 Bytecode triggerOut = *args++;
1018
1019 bp.flags = triggerType | TRIGGER_SCRIPT_BOUND;
1020 bp.colliderID = evt_get_variable(script, colliderIDVar);
1021 bp.varIndex = evt_get_variable_index(script, colliderIDVar);
1022 bp.hasPlayerInteractPrompt = hasInteractPrompt;
1023 bp.tattleMsg = 0;
1025
1026 trigger = create_trigger(&bp);
1027 trigger->onTriggerEvt = (EvtScript*)triggerScript;
1028 trigger->runningScript = NULL;
1029 trigger->priority = script->priority;
1030 trigger->varTable[0] = evt_get_variable(script, script->varTable[0]);
1031 trigger->varTable[1] = evt_get_variable(script, script->varTable[1]);
1032 trigger->varTable[2] = evt_get_variable(script, script->varTable[2]);
1033
1034 if (triggerOut != 0) {
1035 evt_set_variable(script, triggerOut, (s32)trigger);
1036 }
1037
1038 return ApiStatus_DONE2;
1039}
1040
1041API_CALLABLE(DeleteTrigger) {
1042 delete_trigger((Trigger*)evt_get_variable(script, *script->ptrReadPos));
1043 return ApiStatus_DONE2;
1044}
1045
1047 delete_trigger(script->owner2.trigger);
1048 return ApiStatus_DONE2;
1049}
1050
1053 return ApiStatus_DONE2;
1054}
1055
1057 set_script_priority(script, evt_get_variable(script, *script->ptrReadPos));
1058 return ApiStatus_DONE2;
1059}
1060
1065
1067 set_script_group(script, evt_get_variable(script, *script->ptrReadPos));
1068 return ApiStatus_DONE2;
1069}
1070
1075
1080
1082 suspend_group_others(script, evt_get_variable(script, *script->ptrReadPos));
1083 return ApiStatus_DONE2;
1084}
1085
1087 resume_group_others(script, evt_get_variable(script, *script->ptrReadPos));
1088 return ApiStatus_DONE2;
1089}
1090
1095
1098 return ApiStatus_DONE2;
1099}
1100
1102 Bytecode* args = script->ptrReadPos;
1103 s32 scriptID = evt_get_variable(script, *args++);
1104 Bytecode var2 = *args++;
1105
1106 evt_set_variable(script, var2, does_script_exist(scriptID));
1107 return ApiStatus_DONE2;
1108}
1109
1111 if (trigger->runningScript == NULL) {
1112 Evt* newScript = start_script(trigger->onTriggerEvt, trigger->priority, EVT_FLAG_RUN_IMMEDIATELY);
1113 trigger->runningScript = newScript;
1114 trigger->runningScriptID = newScript->id;
1115 newScript->varTable[0] = trigger->varTable[0];
1116 newScript->varTable[1] = trigger->varTable[1];
1117 newScript->varTable[2] = trigger->varTable[2];
1118 newScript->owner2.trigger = trigger;
1119 }
1120
1121 if (!does_script_exist(trigger->runningScriptID)) {
1122 trigger->runningScript = NULL;
1123 trigger->flags &= ~TRIGGER_ACTIVATED;
1124 }
1125}
1126
1128 Bytecode* args = script->ptrReadPos;
1129 Trigger* trigger;
1130 Bytecode* triggerScript = (Bytecode*)evt_get_variable(script, *args++);
1131 Bytecode triggerType = *args++;
1132 Bytecode colliderIDVar = *args++;
1133 s32* itemList = (s32*)evt_get_variable(script, *args++);
1134 Bytecode triggerOut = *args++;
1135 s32 hasInteractPrompt = *args++;
1137
1138 bp.flags = triggerType | TRIGGER_SCRIPT_BOUND;
1139 bp.colliderID = evt_get_variable(script, colliderIDVar);
1140 bp.varIndex = evt_get_variable_index(script, colliderIDVar);
1141 bp.itemList = itemList;
1143 bp.tattleMsg = triggerOut;
1144 bp.hasPlayerInteractPrompt = hasInteractPrompt;
1145
1146 trigger = create_trigger(&bp);
1147 trigger->onTriggerEvt = (EvtScript*)triggerScript;
1148 trigger->runningScript = NULL;
1149 trigger->priority = script->priority;
1150 trigger->varTable[0] = evt_get_variable(script, script->varTable[0]);
1151 trigger->varTable[1] = evt_get_variable(script, script->varTable[1]);
1152 trigger->varTable[2] = evt_get_variable(script, script->varTable[2]);
1153
1154 return ApiStatus_DONE2;
1155}
1156
1158 Evt* newScript;
1159 s32 nargs;
1160 s32 opcode;
1161 s32 i;
1162
1163 // seek end thread opcode
1164 Bytecode* startLine = script->ptrNextLine;
1165 Bytecode* endLine = startLine;
1166 do {
1167 opcode = *endLine++;
1168 nargs = *endLine++;
1169 endLine += nargs;
1170 } while (opcode != EVT_OP_END_THREAD);
1171
1172 script->ptrNextLine = endLine;
1173 newScript = start_script_in_group((EvtScript*)startLine, script->priority, EVT_FLAG_RUN_IMMEDIATELY | EVT_FLAG_THREAD, script->groupFlags);
1174 newScript->owner1.enemyID = script->owner1.enemyID;
1175 newScript->owner2.npcID = script->owner2.npcID;
1176 newScript->array = script->array;
1177 newScript->flagArray = script->flagArray;
1178
1179 for (i = 0; i < ARRAY_COUNT(script->varTable); i++) {
1180 newScript->varTable[i] = script->varTable[i];
1181 }
1182
1183 for (i = 0; i < ARRAY_COUNT(script->varFlags); i++) {
1184 newScript->varFlags[i] = script->varFlags[i];
1185 }
1186
1187 return ApiStatus_DONE2;
1188}
1189
1191 kill_script(script);
1192 return ApiStatus_FINISH;
1193}
1194
1196 Evt* newScript;
1197 s32 nargs;
1198 s32 opcode;
1199 s32 i;
1200
1201 Bytecode* startLine = script->ptrNextLine;
1202 Bytecode* endLine = startLine;
1203 do {
1204 opcode = *endLine++;
1205 nargs = *endLine++;
1206 endLine += nargs;
1207 } while (opcode != EVT_OP_END_CHILD_THREAD);
1208
1209 script->ptrNextLine = endLine;
1210 newScript = func_802C39F8(script, startLine, EVT_FLAG_RUN_IMMEDIATELY | EVT_FLAG_THREAD);
1211 newScript->owner1.enemyID = script->owner1.enemyID;
1212 newScript->owner2.npcID = script->owner2.npcID;
1213 newScript->groupFlags = script->groupFlags;
1214 newScript->array = script->array;
1215 newScript->flagArray = script->flagArray;
1216
1217 return ApiStatus_DONE2;
1218}
1219
1221 kill_script(script);
1222 return ApiStatus_BLOCK;
1223}
1224
1228
1230
1231// TODO: Fake match, seems to be UB for some of the print calls.
1233 Bytecode* args = script->ptrReadPos;
1234 s32 var = *args++;
1235 s32 flagBitPos;
1236
1237 if (var <= EVT_LIMIT) {
1238 sprintf(evtDebugPrintBuffer, "ADDR [%08X]", var);
1239 } else if (var <= EVT_FIXED_CUTOFF) {
1240 sprintf(evtDebugPrintBuffer, "FLOAT [%4.2f]", evt_fixed_var_to_float(var));
1241 } else if (var <= EVT_ARRAY_FLAG_CUTOFF) {
1242 var = EVT_INDEX_OF_ARRAY_FLAG(var);
1243 flagBitPos = var % 32;
1244 sprintf(evtDebugPrintBuffer, "UF(%3d) [%d]", var, script->flagArray[var / 32] & (1 << flagBitPos));
1245 } else if (var <= EVT_ARRAY_VAR_CUTOFF) {
1246 s32 arrayVal;
1247
1248 var = EVT_INDEX_OF_ARRAY_VAR(var);
1249 arrayVal = script->array[var];
1250
1251 if (script->array[var] <= EVT_LIMIT) {
1252 sprintf(evtDebugPrintBuffer, "UW(%3d) [%08X]", arrayVal);
1253 } else if (arrayVal <= EVT_FIXED_CUTOFF) {
1254 sprintf(evtDebugPrintBuffer, "UW(%3d) [%4.2f]", var, evt_fixed_var_to_float(arrayVal));
1255 } else {
1256 sprintf(evtDebugPrintBuffer, "UW(%3d) [%d]", var, arrayVal);
1257 }
1258 } else if (var <= EVT_GAME_BYTE_CUTOFF) {
1259 s32 globalByte;
1260
1261 var = EVT_INDEX_OF_GAME_BYTE(var);
1262 globalByte = get_global_byte(var);
1263
1264 if (globalByte <= EVT_LIMIT) {
1265 sprintf(evtDebugPrintBuffer, "GSW(%3d) [%08X]", globalByte);
1266 } else if (globalByte <= EVT_FIXED_CUTOFF) {
1267 sprintf(evtDebugPrintBuffer, "GSW(%3d) [%4.2f]", var, evt_fixed_var_to_float(globalByte));
1268 } else {
1269 sprintf(evtDebugPrintBuffer, "GSW(%3d) [%d]", var, globalByte);
1270 }
1271 } else if (var <= EVT_AREA_BYTE_CUTOFF) {
1272 s32 areaByte;
1273
1274 var = EVT_INDEX_OF_AREA_BYTE(var);
1275 areaByte = get_area_byte(var);
1276
1277 if (areaByte <= EVT_LIMIT) {
1278 sprintf(evtDebugPrintBuffer, "LSW(%3d) [%08X]", areaByte);
1279 } else if (areaByte <= EVT_FIXED_CUTOFF) {
1280 sprintf(evtDebugPrintBuffer, "LSW(%3d) [%4.2f]", var, evt_fixed_var_to_float(areaByte));
1281 } else {
1282 sprintf(evtDebugPrintBuffer, "LSW(%3d) [%d]", var, areaByte);
1283 }
1284 } else if (var <= EVT_GAME_FLAG_CUTOFF) {
1285 var = EVT_INDEX_OF_GAME_FLAG(var);
1286 sprintf(evtDebugPrintBuffer, "GSWF(%3d)[%d]", var, get_global_flag(var));
1287 } else if (var <= EVT_AREA_FLAG_CUTOFF) {
1288 var = EVT_INDEX_OF_AREA_FLAG(var);
1289 sprintf(evtDebugPrintBuffer, "LSWF(%3d)[%d]", var, get_area_flag(var));
1290 } else if (var <= EVT_MAP_FLAG_CUTOFF) {
1291 var = EVT_INDEX_OF_MAP_FLAG(var);
1292 flagBitPos = var % 32;
1293 sprintf(evtDebugPrintBuffer, "GF(%3d) [%d]", var, gMapFlags[var / 32] & (1 << flagBitPos));
1294 } else if (var <= EVT_LOCAL_FLAG_CUTOFF) {
1295 var = EVT_INDEX_OF_LOCAL_FLAG(var);
1296 flagBitPos = var % 32;
1297 sprintf(evtDebugPrintBuffer, "LF(%3d) [%d]", var, script->varFlags[var / 32] & (1 << flagBitPos));
1298 } else if (var <= EVT_MAP_VAR_CUTOFF) {
1299 s32 mapVar;
1300
1301 var = EVT_INDEX_OF_MAP_VAR(var);
1302 mapVar = gMapVars[var];
1303
1304 if (mapVar <= EVT_LIMIT) {
1305 sprintf(evtDebugPrintBuffer, "GW(%3d) [%08X]", mapVar);
1306 } else if (mapVar <= EVT_FIXED_CUTOFF) {
1307 sprintf(evtDebugPrintBuffer, "GW(%3d) [%4.2f]", var, evt_fixed_var_to_float(mapVar));
1308 } else {
1309 sprintf(evtDebugPrintBuffer, "GW(%3d) [%d]", var, mapVar);
1310 }
1311 } else if (var <= EVT_LOCAL_VAR_CUTOFF) {
1312 s32 tableVar;
1313
1314 var = EVT_INDEX_OF_LOCAL_VAR(var);
1315 tableVar = script->varTable[var];
1316
1317 if (tableVar <= EVT_LIMIT) {
1318 sprintf(evtDebugPrintBuffer, "LW(%3d) [%08X]", tableVar);
1319 } else if (tableVar <= EVT_FIXED_CUTOFF) {
1320 sprintf(evtDebugPrintBuffer, "LW(%3d) [%4.2f]", var, evt_fixed_var_to_float(tableVar));
1321 } else {
1322 sprintf(evtDebugPrintBuffer, "LW(%3d) [%d]", var, tableVar);
1323 }
1324 } else {
1325 sprintf(evtDebugPrintBuffer, " [%d]", var);
1326 }
1327
1328 return ApiStatus_DONE2;
1329}
1330
1332 script->ptrSavedPos = (Bytecode*)*script->ptrReadPos;
1333 return ApiStatus_DONE2;
1334}
1335
1337 return ApiStatus_DONE2;
1338}
1339
1341 s32 i;
1342
1343 for (i = 0; i < MAX_SCRIPTS; i++) {
1344 if (script == get_script_by_index(i)) {
1345 break;
1346 }
1347 }
1348 return ApiStatus_DONE1;
1349}
1350
1352 s32 commandsExecuted = 0;
1353
1354 while (TRUE) {
1355 s32 status = ApiStatus_DONE2;
1356 s32* lines;
1357 s32 nargs;
1358
1359 commandsExecuted++;
1360 ASSERT_MSG(commandsExecuted < 10000, "Script %x is blocking for ages (infinite loop?)", script->ptrFirstLine);
1361
1362 switch (script->curOpcode) {
1364 script->ptrCurLine = script->ptrNextLine;
1365 lines = script->ptrNextLine;
1366 script->curOpcode = *lines++;
1367 nargs = *lines++;
1368 script->ptrReadPos = lines;
1369 script->blocked = FALSE;
1370 script->curArgc = nargs;
1371 lines = &lines[nargs];
1372 script->ptrNextLine = lines;
1373 status = ApiStatus_REPEAT;
1374 break;
1375 case EVT_OP_RETURN:
1376 status = evt_handle_return(script);
1377 break;
1378 case EVT_OP_LABEL:
1379 status = evt_handle_label(script);
1380 break;
1381 case EVT_OP_GOTO:
1382 status = evt_handle_goto(script);
1383 break;
1384 case EVT_OP_LOOP:
1385 status = evt_handle_loop(script);
1386 break;
1387 case EVT_OP_END_LOOP:
1388 status = evt_handle_end_loop(script);
1389 break;
1390 case EVT_OP_BREAK_LOOP:
1391 status = evt_handle_break_loop(script);
1392 break;
1393 case EVT_OP_WAIT_FRAMES:
1394 status = evt_handle_wait(script);
1395 break;
1396 case EVT_OP_WAIT_SECS:
1397 status = evt_handle_wait_seconds(script);
1398 break;
1399 case EVT_OP_IF_EQ:
1400 status = evt_handle_if_equal(script);
1401 break;
1402 case EVT_OP_IF_NE:
1403 status = evt_handle_if_not_equal(script);
1404 break;
1405 case EVT_OP_IF_LT:
1406 status = evt_handle_if_less(script);
1407 break;
1408 case EVT_OP_IF_GT:
1409 status = evt_handle_if_greater(script);
1410 break;
1411 case EVT_OP_IF_LE:
1412 status = evt_handle_if_less_equal(script);
1413 break;
1414 case EVT_OP_IF_GE:
1415 status = evt_handle_if_greater_equal(script);
1416 break;
1417 case EVT_OP_IF_FLAG:
1418 status = evt_handle_if_AND(script);
1419 break;
1420 case EVT_OP_IF_NOT_FLAG:
1421 status = evt_handle_if_not_AND(script);
1422 break;
1423 case EVT_OP_ELSE:
1424 status = evt_handle_else(script);
1425 break;
1426 case EVT_OP_END_IF:
1427 status = evt_handle_end_if(script);
1428 break;
1429 case EVT_OP_SWITCH:
1430 status = evt_handle_switch(script);
1431 break;
1433 status = evt_handle_switch_const(script);
1434 break;
1435 case EVT_OP_CASE_EQ:
1436 status = evt_handle_case_equal(script);
1437 break;
1438 case EVT_OP_CASE_NE:
1439 status = evt_handle_case_not_equal(script);
1440 break;
1441 case EVT_OP_CASE_LT:
1442 status = evt_handle_case_less(script);
1443 break;
1444 case EVT_OP_CASE_LE:
1445 status = evt_handle_case_less_equal(script);
1446 break;
1447 case EVT_OP_CASE_GT:
1448 status = evt_handle_case_greater(script);
1449 break;
1450 case EVT_OP_CASE_GE:
1451 status = evt_handle_case_greater_equal(script);
1452 break;
1454 status = evt_handle_case_default(script);
1455 break;
1457 status = evt_handle_break_case(script);
1458 break;
1459 case EVT_OP_CASE_OR_EQ:
1460 status = evt_handle_case_equal_OR(script);
1461 break;
1463 status = evt_handle_end_case_group(script);
1464 break;
1465 case EVT_OP_CASE_AND_EQ:
1466 status = evt_handle_case_equal_AND(script);
1467 break;
1468 case EVT_OP_CASE_FLAG:
1469 status = evt_handle_case_AND(script);
1470 break;
1471 case EVT_OP_CASE_RANGE:
1472 status = evt_handle_case_range(script);
1473 break;
1474 case EVT_OP_END_SWITCH:
1475 status = evt_handle_end_switch(script);
1476 break;
1477 case EVT_OP_SET:
1478 status = evt_handle_set_var(script);
1479 break;
1480 case EVT_OP_SET_CONST:
1481 status = evt_handle_set_const(script);
1482 break;
1483 case EVT_OP_SETF:
1484 status = evt_handle_set_float(script);
1485 break;
1486 case EVT_OP_ADD:
1487 status = evt_handle_add(script);
1488 break;
1489 case EVT_OP_SUB:
1490 status = evt_handle_subtract(script);
1491 break;
1492 case EVT_OP_MUL:
1493 status = evt_handle_multiply(script);
1494 break;
1495 case EVT_OP_DIV:
1496 status = evt_handle_divide(script);
1497 break;
1498 case EVT_OP_MOD:
1499 status = evt_handle_mod(script);
1500 break;
1501 case EVT_OP_ADDF:
1502 status = evt_handle_addF(script);
1503 break;
1504 case EVT_OP_SUBF:
1505 status = evt_handle_subtractF(script);
1506 break;
1507 case EVT_OP_MULF:
1508 status = evt_handle_multiplyF(script);
1509 break;
1510 case EVT_OP_DIVF:
1511 status = evt_handle_divideF(script);
1512 break;
1513 case EVT_OP_USE_BUF:
1514 status = evt_handle_set_int_buffer_ptr(script);
1515 break;
1516 case EVT_OP_BUF_READ1:
1517 status = evt_handle_get_1_word(script);
1518 break;
1519 case EVT_OP_BUF_READ2:
1520 status = evt_handle_get_2_word(script);
1521 break;
1522 case EVT_OP_BUF_READ3:
1523 status = evt_handle_get_3_word(script);
1524 break;
1525 case EVT_OP_BUF_READ4:
1526 status = evt_handle_get_4_word(script);
1527 break;
1528 case EVT_OP_BUF_PEEK:
1529 status = evt_handle_get_Nth_word(script);
1530 break;
1531 case EVT_OP_USE_FBUF:
1532 status = evt_handle_set_float_buffer_ptr(script);
1533 break;
1534 case EVT_OP_FBUF_READ1:
1535 status = evt_handle_get_1_float(script);
1536 break;
1537 case EVT_OP_FBUF_READ2:
1538 status = evt_handle_get_2_float(script);
1539 break;
1540 case EVT_OP_FBUF_READ3:
1541 status = evt_handle_get_3_float(script);
1542 break;
1543 case EVT_OP_FBUF_READ4:
1544 status = evt_handle_get_4_float(script);
1545 break;
1546 case EVT_OP_FBUF_PEEK:
1547 status = evt_handle_get_Nth_float(script);
1548 break;
1549 case EVT_OP_USE_ARRAY:
1550 status = evt_handle_set_array(script);
1551 break;
1552 case EVT_OP_USE_FLAGS:
1553 status = evt_handle_set_flag_array(script);
1554 break;
1556 status = evt_handle_allocate_array(script);
1557 break;
1558 case EVT_OP_KILL_THREAD:
1559 status = evt_handle_kill(script);
1560 break;
1561 case EVT_OP_BITWISE_AND:
1562 status = evt_handle_AND(script);
1563 break;
1565 status = evt_handle_AND_const(script);
1566 break;
1567 case EVT_OP_BITWISE_OR:
1568 status = evt_handle_OR(script);
1569 break;
1571 status = evt_handle_OR_const(script);
1572 break;
1573 case EVT_OP_CALL:
1574 status = evt_handle_call(script);
1575 break;
1576 case EVT_OP_EXEC:
1577 status = evt_handle_exec1(script);
1578 break;
1580 status = evt_handle_exec1_get_id(script);
1581 break;
1582 case EVT_OP_EXEC_WAIT:
1583 status = evt_handle_exec_wait(script);
1584 break;
1586 status = evt_handle_bind(script);
1587 break;
1588 case EVT_OP_UNBIND:
1589 status = evt_handle_unbind(script);
1590 break;
1592 status = evt_handle_set_priority(script);
1593 break;
1595 status = evt_handle_set_timescale(script);
1596 break;
1597 case EVT_OP_SET_GROUP:
1598 status = evt_handle_set_group(script);
1599 break;
1600 case EVT_OP_JUMP:
1601 status = evt_handle_jump(script);
1602 break;
1604 status = evt_handle_bind_lock(script);
1605 break;
1607 status = evt_handle_suspend_all(script);
1608 break;
1610 status = evt_handle_resume_all(script);
1611 break;
1613 status = evt_handle_suspend_others(script);
1614 break;
1616 status = evt_handle_resume_others(script);
1617 break;
1619 status = evt_handle_suspend(script);
1620 break;
1622 status = evt_handle_resume(script);
1623 break;
1625 status = evt_handle_does_script_exist(script);
1626 break;
1627 case EVT_OP_THREAD:
1628 status = evt_handle_thread(script);
1629 break;
1630 case EVT_OP_END_THREAD:
1631 status = evt_handle_end_thread(script);
1632 break;
1634 status = evt_handle_child_thread(script);
1635 break;
1637 status = evt_handle_end_child_thread(script);
1638 break;
1639 case EVT_OP_DEBUG_LOG:
1640 status = evt_handle_debug_log(script);
1641 break;
1643 status = evt_handle_print_debug_var(script);
1644 break;
1645 case EVT_OP_92:
1646 status = func_802C739C(script);
1647 break;
1648 case EVT_OP_93:
1649 status = func_802C73B0(script);
1650 break;
1651 case EVT_OP_94:
1652 status = func_802C73B8(script);
1653 case EVT_OP_END:
1654 break;
1655 default:
1656 PANIC();
1657 }
1658
1659 if (status == ApiStatus_REPEAT) {
1660 continue;
1661 }
1662
1663 if (status == ApiStatus_FINISH) {
1664 return EVT_CMD_RESULT_YIELD;
1665 }
1666
1667 if (status < 0) {
1668 return EVT_CMD_RESULT_ERROR;
1669 }
1670
1671 // TODO: this may be able to be a switch but I couldn't get it
1672 if (status == ApiStatus_BLOCK) {
1673 // return 0
1674 } else if (status == ApiStatus_DONE1) {
1676 // return 0
1677 } else if (status == ApiStatus_DONE2) {
1680 continue;
1681 }
1682 // return 0
1683 } else {
1684 continue;
1685 }
1687 }
1688}
1689
1690s32 evt_get_variable(Evt* script, Bytecode var) {
1691 s32 wordIdx;
1692 s32 bitIdx;
1693 s32 temp;
1694
1695 if (var <= EVT_LIMIT) {
1696 return var;
1697 } else if (var <= EVT_IGNORE_ARG) {
1698 return var;
1699 } else if (var <= EVT_FIXED_CUTOFF) {
1700 return evt_fixed_var_to_float(var);
1701 } else if (var <= EVT_ARRAY_FLAG_CUTOFF) {
1702 var = EVT_INDEX_OF_ARRAY_FLAG(var);
1703 wordIdx = var / 32;
1704 bitIdx = var % 32;
1705 var = (script->flagArray[wordIdx] & (1 << bitIdx)) != 0;
1706 return var;
1707 } else if (var <= EVT_ARRAY_VAR_CUTOFF) {
1708 var = EVT_INDEX_OF_ARRAY_VAR(var);
1709 var = script->array[var];
1710 if (var > EVT_LIMIT) {
1711 if (var <= EVT_FIXED_CUTOFF){
1712 var = evt_fixed_var_to_float(var);
1713 }
1714 }
1715 } else if (var <= EVT_GAME_BYTE_CUTOFF) {
1716 var = EVT_INDEX_OF_GAME_BYTE(var);
1717 return get_global_byte(var);
1718 } else if (var <= EVT_AREA_BYTE_CUTOFF) {
1719 var = EVT_INDEX_OF_AREA_BYTE(var);
1720 return get_area_byte(var);
1721 } else if (var <= EVT_GAME_FLAG_CUTOFF) {
1722 var = EVT_INDEX_OF_GAME_FLAG(var);
1723 return get_global_flag(var);
1724 } else if (var <= EVT_AREA_FLAG_CUTOFF) {
1725 var = EVT_INDEX_OF_AREA_FLAG(var);
1726 return get_area_flag(var);
1727 } else if (var <= EVT_MAP_FLAG_CUTOFF) {
1728 var = EVT_INDEX_OF_MAP_FLAG(var);
1729 wordIdx = var;
1730 bitIdx = var % 32;
1731 var = (gMapFlags[wordIdx / 32] & (1 << bitIdx)) != 0;
1732 return var;
1733 } else if (var <= EVT_LOCAL_FLAG_CUTOFF) {
1734 var = EVT_INDEX_OF_LOCAL_FLAG(var);
1735 wordIdx = var;
1736 bitIdx = var % 32;
1737 var = (script->varFlags[wordIdx / 32] & (1 << bitIdx)) != 0;
1738 return var;
1739 } else if (var <= EVT_MAP_VAR_CUTOFF) {
1740 var = EVT_INDEX_OF_MAP_VAR(var);
1741 var = gMapVars[var];
1742 if (var > EVT_LIMIT) {
1743 temp = EVT_FIXED_CUTOFF;
1744 if (var <= temp){
1745 var = evt_fixed_var_to_float(var);
1746 }
1747 }
1748 } else if (var <= EVT_LOCAL_VAR_CUTOFF) {
1749 var = EVT_INDEX_OF_LOCAL_VAR(var);
1750 var = script->varTable[var];
1751 if (var > EVT_LIMIT) {
1752 temp = EVT_FIXED_CUTOFF;
1753 if (var <= temp){
1754 var = evt_fixed_var_to_float(var);
1755 }
1756 }
1757 }
1758 return var;
1759}
1760
1761s32 evt_get_variable_index(Evt* script, s32 var) {
1762 if (EVT_LIMIT >= var) {
1763 return var;
1764 }
1765 if (EVT_IGNORE_ARG >= var) {
1766 return var;
1767 }
1768 if (EVT_FIXED_CUTOFF >= var) {
1769 return var;
1770 }
1771 if (EVT_ARRAY_FLAG_CUTOFF >= var) {
1772 return EVT_INDEX_OF_ARRAY_FLAG(var);
1773 }
1774 if (EVT_ARRAY_VAR_CUTOFF >= var) {
1775 return EVT_INDEX_OF_ARRAY_VAR(var);
1776 }
1777 if (EVT_GAME_BYTE_CUTOFF >= var) {
1778 return EVT_INDEX_OF_GAME_BYTE(var);
1779 }
1780 if (EVT_AREA_BYTE_CUTOFF >= var) {
1781 return EVT_INDEX_OF_AREA_BYTE(var);
1782 }
1783 if (EVT_GAME_FLAG_CUTOFF >= var) {
1784 return EVT_INDEX_OF_GAME_FLAG(var);
1785 }
1786 if (EVT_AREA_FLAG_CUTOFF >= var) {
1787 return EVT_INDEX_OF_AREA_FLAG(var);
1788 }
1789 if (EVT_MAP_FLAG_CUTOFF >= var) {
1790 return EVT_INDEX_OF_MAP_FLAG(var);
1791 }
1792 if (EVT_LOCAL_FLAG_CUTOFF >= var) {
1793 return EVT_INDEX_OF_LOCAL_FLAG(var);
1794 }
1795 if (EVT_MAP_VAR_CUTOFF >= var) {
1796 return EVT_INDEX_OF_MAP_VAR(var);
1797 }
1798 if (EVT_LOCAL_VAR_CUTOFF >= var) {
1799 return EVT_INDEX_OF_LOCAL_VAR(var);
1800 }
1801 return var;
1802}
1803
1805 if (EVT_LIMIT >= var) {
1806 return var;
1807 }
1808 if (EVT_IGNORE_ARG >= var) {
1809 return var;
1810 }
1811 if (EVT_FIXED_CUTOFF >= var) {
1812 return var;
1813 }
1814 if (EVT_ARRAY_FLAG_CUTOFF >= var) {
1815 return EVT_INDEX_OF_ARRAY_FLAG(var);
1816 }
1817 if (EVT_ARRAY_VAR_CUTOFF >= var) {
1818 return EVT_INDEX_OF_ARRAY_VAR(var);
1819 }
1820 if (EVT_GAME_BYTE_CUTOFF >= var) {
1821 return EVT_INDEX_OF_GAME_BYTE(var);
1822 }
1823 if (EVT_AREA_BYTE_CUTOFF >= var) {
1824 return EVT_INDEX_OF_AREA_BYTE(var);
1825 }
1826 if (EVT_GAME_FLAG_CUTOFF >= var) {
1827 return EVT_INDEX_OF_GAME_FLAG(var);
1828 }
1829 if (EVT_AREA_FLAG_CUTOFF >= var) {
1830 return EVT_INDEX_OF_AREA_FLAG(var);
1831 }
1832 if (EVT_MAP_FLAG_CUTOFF >= var) {
1833 return EVT_INDEX_OF_MAP_FLAG(var);
1834 }
1835 if (EVT_LOCAL_FLAG_CUTOFF >= var) {
1836 return EVT_INDEX_OF_LOCAL_FLAG(var);
1837 }
1838 if (EVT_MAP_VAR_CUTOFF >= var) {
1839 return EVT_INDEX_OF_MAP_VAR(var);
1840 }
1841 if (EVT_LOCAL_VAR_CUTOFF >= var) {
1842 return EVT_INDEX_OF_LOCAL_VAR(var);
1843 }
1844 return var;
1845}
1846
1847s32 evt_set_variable(Evt* script, Bytecode var, s32 value) {
1848 s32 flagBitPos;
1849 s32 oldValue;
1850
1851 if (var <= EVT_LIMIT) {
1852 return value;
1853 } else if (var <= EVT_FIXED_CUTOFF) {
1854 return evt_fixed_var_to_float(value);
1855 } else if (var <= EVT_ARRAY_FLAG_CUTOFF) {
1856 var = EVT_INDEX_OF_ARRAY_FLAG(var);
1857 flagBitPos = var % 32;
1858 if (value) {
1859 script->flagArray[var / 32] |= 1 << flagBitPos;
1860 } else {
1861 script->flagArray[var / 32] &= ~(1 << flagBitPos);
1862 }
1863 return value;
1864 } else if (var <= EVT_ARRAY_VAR_CUTOFF) {
1865 var = EVT_INDEX_OF_ARRAY_VAR(var);
1866 oldValue = script->array[var];
1867 script->array[var] = value;
1868 return oldValue;
1869 } else if (var <= EVT_GAME_BYTE_CUTOFF) {
1870 var = EVT_INDEX_OF_GAME_BYTE(var);
1871 oldValue = get_global_byte(var);
1872 set_global_byte(var, value);
1873 return oldValue;
1874 } else if (var <= EVT_AREA_BYTE_CUTOFF) {
1875 var = EVT_INDEX_OF_AREA_BYTE(var);
1876 oldValue = get_area_byte(var);
1877 set_area_byte(var, value);
1878 return oldValue;
1879 } else if (var <= EVT_GAME_FLAG_CUTOFF) {
1880 var = EVT_INDEX_OF_GAME_FLAG(var);
1881 oldValue = get_global_flag(var);
1882 if (value) {
1883 set_global_flag(var);
1884 } else {
1885 clear_global_flag(var);
1886 }
1887 return oldValue;
1888 } else if (var <= EVT_AREA_FLAG_CUTOFF) {
1889 var = EVT_INDEX_OF_AREA_FLAG(var);
1890 oldValue = get_area_flag(var);
1891 if (value) {
1892 set_area_flag(var);
1893 } else {
1894 clear_area_flag(var);
1895 }
1896 return oldValue;
1897 } else if (var <= EVT_MAP_FLAG_CUTOFF) {
1898 var = EVT_INDEX_OF_MAP_FLAG(var);
1899 flagBitPos = var % 32;
1900 if (value) {
1901 gMapFlags[var / 32] |= 1 << flagBitPos;
1902 } else {
1903 gMapFlags[var / 32] &= ~(1 << flagBitPos);
1904 }
1905 return value;
1906 } else if (var <= EVT_LOCAL_FLAG_CUTOFF) {
1907 var = EVT_INDEX_OF_LOCAL_FLAG(var);
1908 flagBitPos = var % 32;
1909 if (value) {
1910 script->varFlags[var / 32] |= 1 << flagBitPos;
1911 } else {
1912 script->varFlags[var / 32] &= ~(1 << flagBitPos);
1913 }
1914 return value;
1915 } else if (var <= EVT_MAP_VAR_CUTOFF) {
1916 var = EVT_INDEX_OF_MAP_VAR(var);
1917 oldValue = gMapVars[var];
1918 gMapVars[var] = value;
1919 return oldValue;
1920 } else if (var <= EVT_LOCAL_VAR_CUTOFF) {
1921 var = EVT_INDEX_OF_LOCAL_VAR(var);
1922 oldValue = script->varTable[var];
1923 script->varTable[var] = value;
1924 return oldValue;
1925 } else {
1926 return value;
1927 }
1928}
1929
1931 s32 temp;
1932
1933 if (var <= EVT_LIMIT) {
1934 return var;
1935 } else if (var <= EVT_IGNORE_ARG) {
1936 return var;
1937 } else if (var <= EVT_FIXED_CUTOFF) {
1938 return evt_fixed_var_to_float(var);
1939 } else if (var <= EVT_ARRAY_VAR_CUTOFF) {
1940 var = EVT_INDEX_OF_ARRAY_VAR(var);
1941 return evt_fixed_var_to_float(script->array[var]);
1942 } else if (var <= EVT_GAME_BYTE_CUTOFF) {
1943 var = EVT_INDEX_OF_GAME_BYTE(var);
1945 } else if (var <= EVT_AREA_BYTE_CUTOFF) {
1946 var = EVT_INDEX_OF_AREA_BYTE(var);
1948 } else if (var <= EVT_MAP_FLAG_CUTOFF) {
1949 var = EVT_INDEX_OF_MAP_FLAG(var);
1950 temp = var % 32;
1951 var = gMapFlags[var / 32] & (1 << temp);
1952 if (var) {
1953 return 1.0f;
1954 } else {
1955 return 0.0f;
1956 }
1957 } else if (var <= EVT_LOCAL_FLAG_CUTOFF) {
1958 var = EVT_INDEX_OF_LOCAL_FLAG(var);
1959 temp = var % 32;
1960 var = script->varFlags[var / 32] & (1 << temp);
1961 if (var) {
1962 return 1.0f;
1963 } else {
1964 return 0.0f;
1965 }
1966 } else if (var <= EVT_MAP_VAR_CUTOFF) {
1967 var = EVT_INDEX_OF_MAP_VAR(var);
1968 return evt_fixed_var_to_float(gMapVars[var]);
1969 } else if (var <= EVT_LOCAL_VAR_CUTOFF) {
1970 var = EVT_INDEX_OF_LOCAL_VAR(var);
1971 return evt_fixed_var_to_float(script->varTable[var]);
1972 } else {
1973 return evt_fixed_var_to_float(var);
1974 }
1975}
1976
1977f32 evt_set_float_variable(Evt* script, Bytecode var, f32 value) {
1978 s32 temp;
1979 s32 oldValue;
1980
1981 if (var <= EVT_LIMIT) {
1982 return value;
1983 } else if (var <= EVT_FIXED_CUTOFF) {
1984 return value;
1985 } else if (var <= EVT_ARRAY_VAR_CUTOFF) {
1986 var = EVT_INDEX_OF_ARRAY_VAR(var);
1987 oldValue = script->array[var];
1988 script->array[var] = evt_float_to_fixed_var(value);
1989 return evt_fixed_var_to_float(oldValue);
1990 } else if (var <= EVT_MAP_FLAG_CUTOFF) {
1991 var = EVT_INDEX_OF_MAP_FLAG(var);
1992 temp = var % 32;
1993 if (value) {
1994 gMapFlags[var / 32] |= 1 << temp;
1995 } else {
1996 gMapFlags[var / 32] &= ~(1 << temp);
1997 }
1998 return value;
1999 } else if (var <= EVT_LOCAL_FLAG_CUTOFF) {
2000 var = EVT_INDEX_OF_LOCAL_FLAG(var);
2001 temp = var % 32;
2002 if (value) {
2003 script->varFlags[var / 32] |= 1 << temp;
2004 } else {
2005 script->varFlags[var / 32] &= ~(1 << temp);
2006 }
2007 return value;
2008 } else if (var <= EVT_MAP_VAR_CUTOFF) {
2009 var = EVT_INDEX_OF_MAP_VAR(var);
2010 oldValue = gMapVars[var];
2011 gMapVars[var] = evt_float_to_fixed_var(value);
2012 return evt_fixed_var_to_float(oldValue);
2013 } else if (var <= EVT_LOCAL_VAR_CUTOFF) {
2014 var = EVT_INDEX_OF_LOCAL_VAR(var);
2015 oldValue = script->varTable[var];
2016 script->varTable[var] = evt_float_to_fixed_var(value);
2017 return evt_fixed_var_to_float(oldValue);
2018 } else {
2019 return value;
2020 }
2021}
2022
2023Bytecode* evt_find_label(Evt* script, s32 arg1) {
2024 Bytecode* ret = script->ptrReadPos;
2025 s32 i;
2026
2027 if (arg1 < EVT_LIMIT) {
2028 return (Bytecode*) arg1;
2029 }
2030
2031 for (i = 0; i < ARRAY_COUNT(script->labelIndices); i++) {
2032 if (script->labelIndices[i] == arg1) {
2033 ret = script->labelPositions[i];
2034 break;
2035 }
2036 }
2037
2038 ASSERT(i < ARRAY_COUNT(script->labelIndices));
2039 return ret;
2040}
2041
2043 s32 nestedIfDepth = 0;
2044 Bytecode* pos = script->ptrNextLine;
2045 Bytecode opcode;
2046 s32 nargs;
2047
2048 do {
2049 opcode = *pos++;
2050 nargs = *pos++;
2051 pos += nargs;
2052
2053 switch (opcode) {
2054 case EVT_OP_END:
2055 PANIC();
2056 case EVT_OP_END_IF:
2057 nestedIfDepth--;
2058 if (nestedIfDepth < 0) {
2059 return pos;
2060 }
2061 break;
2062 case EVT_OP_IF_EQ:
2063 case EVT_OP_IF_NE:
2064 case EVT_OP_IF_LT:
2065 case EVT_OP_IF_GT:
2066 case EVT_OP_IF_LE:
2067 case EVT_OP_IF_GE:
2068 case EVT_OP_IF_FLAG:
2069 case EVT_OP_IF_NOT_FLAG:
2070 nestedIfDepth++;
2071 break;
2072 case EVT_OP_ELSE:
2073 if (nestedIfDepth == 0) {
2074 return pos;
2075 }
2076 break;
2077 }
2078 } while (TRUE);
2079}
2080
2082 s32 nestedIfDepth = 0;
2083 Bytecode* pos = script->ptrNextLine;
2084 Bytecode opcode;
2085 s32 nargs;
2086
2087 do {
2088 opcode = *pos++;
2089 nargs = *pos++;
2090 pos += nargs;
2091
2092 switch (opcode) {
2093 case EVT_OP_END:
2094 PANIC();
2095 case EVT_OP_END_IF:
2096 nestedIfDepth--;
2097 if (nestedIfDepth < 0) {
2098 return pos;
2099 }
2100 break;
2101 case EVT_OP_IF_EQ:
2102 nestedIfDepth++;
2103 break;
2104 case EVT_OP_IF_NE:
2105 nestedIfDepth++;
2106 break;
2107 case EVT_OP_IF_LT:
2108 nestedIfDepth++;
2109 break;
2110 case EVT_OP_IF_GT:
2111 nestedIfDepth++;
2112 break;
2113 case EVT_OP_IF_LE:
2114 nestedIfDepth++;
2115 break;
2116 case EVT_OP_IF_GE:
2117 nestedIfDepth++;
2118 break;
2119 case EVT_OP_IF_FLAG:
2120 nestedIfDepth++;
2121 break;
2122 case EVT_OP_IF_NOT_FLAG:
2123 nestedIfDepth++;
2124 break;
2125 }
2126 } while (TRUE);
2127}
2128
2130 s32 switchDepth = 1;
2131 Bytecode* pos = script->ptrNextLine;
2132 s32* opcode;
2133 s32* nargs;
2134
2135 do {
2136 opcode = pos++;
2137 nargs = pos++;
2138 pos += *nargs;
2139
2140 switch (*opcode) {
2141 case EVT_OP_END:
2142 PANIC();
2143 break;
2144 case EVT_OP_SWITCH:
2145 switchDepth++;
2146 break;
2147 case EVT_OP_END_SWITCH:
2148 switchDepth--;
2149 if (switchDepth == 0) {
2150 return opcode;
2151 }
2152 break;
2153 }
2154 } while (TRUE);
2155}
2156
2158 s32 switchDepth = 1;
2159 Bytecode* pos = script->ptrNextLine;
2160 s32* opcode;
2161 s32* nargs;
2162
2163 do {
2164 opcode = pos++;
2165 nargs = pos++;
2166 pos += *nargs;
2167
2168 switch (*opcode) {
2169 case EVT_OP_END:
2170 PANIC();
2171 break;
2172 case EVT_OP_SWITCH:
2173 switchDepth++;
2174 break;
2175 case EVT_OP_END_SWITCH:
2176 switchDepth--;
2177 if (switchDepth == 0) {
2178 return opcode;
2179 }
2180 break;
2181 case EVT_OP_CASE_EQ:
2182 case EVT_OP_CASE_NE:
2183 case EVT_OP_CASE_LT:
2184 case EVT_OP_CASE_GT:
2185 case EVT_OP_CASE_LE:
2186 case EVT_OP_CASE_GE:
2188 case EVT_OP_CASE_OR_EQ:
2189 case EVT_OP_CASE_AND_EQ:
2191 case EVT_OP_CASE_RANGE:
2192 if (switchDepth == 1) {
2193 return opcode;
2194 }
2195 break;
2196 }
2197 } while (TRUE);
2198}
2199
2201 s32 loopDepth = 0;
2202 Bytecode* pos = script->ptrNextLine;
2203 s32 opcode;
2204 s32 nargs;
2205
2206 do {
2207 opcode = *pos++;
2208 nargs = *pos++;
2209 pos += nargs;
2210
2211 switch (opcode) {
2212 case EVT_OP_END:
2213 PANIC();
2214 break;
2215 case EVT_OP_END_LOOP:
2216 loopDepth--;
2217 if (loopDepth < 0) {
2218 return pos;
2219 }
2220 break;
2221 case EVT_OP_LOOP:
2222 loopDepth++;
2223 break;
2224 }
2225 } while (TRUE);
2226}
Bytecode * ptrNextLine
u8 curOpcode
s32 * buffer
s32 loopStartTable[8]
u8 groupFlags
s8 labelIndices[16]
void * labelPositions[16]
Bytecode * ptrReadPos
s32 * flagArray
s32 loopCounterTable[8]
s32 switchBlockValue[8]
s8 switchDepth
s8 loopDepth
s32 * array
union Evt::@8 owner1
Initially -1.
Bytecode * ptrSavedPos
s32 varFlags[3]
Bytecode * ptrCurLine
union Evt::@9 owner2
Initially -1.
ApiStatus(* ApiFunc)(struct Evt *, s32)
s8 switchBlockState[8]
Bytecode EvtScript[]
Bytecode * ptrFirstLine
ApiFunc callFunction
u8 priority
Vec3s pos
Definition demo_api.c:17
#define ASSERT(condition)
@ DEBUG_SCRIPTS_BLOCK_FUNC_DONE
Definition enums.h:4277
@ TRIGGER_SCRIPT_BOUND
Definition enums.h:2691
ApiStatus func_802C739C(Evt *script)
Definition evt.c:1331
ApiStatus evt_handle_OR(Evt *script)
Definition evt.c:866
ApiStatus func_802C73B0(Evt *script)
Definition evt.c:1336
ApiStatus evt_handle_set_int_buffer_ptr(Evt *script)
Definition evt.c:676
ApiStatus evt_handle_break_loop(Evt *script)
Definition evt.c:88
s32 evt_get_variable_index(Evt *script, s32 var)
Definition evt.c:1761
Bytecode * evt_skip_if(Evt *script)
Definition evt.c:2042
ApiStatus evt_handle_AND(Evt *script)
Definition evt.c:846
ApiStatus evt_handle_set_float(Evt *script)
Definition evt.c:560
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1690
ApiStatus evt_handle_switch_const(Evt *script)
Definition evt.c:243
ApiStatus evt_handle_call(Evt *script)
Definition evt.c:886
ApiStatus evt_handle_case_greater(Evt *script)
Definition evt.c:348
ApiStatus evt_handle_end_thread(Evt *script)
Definition evt.c:1190
ApiStatus evt_handle_case_equal_OR(Evt *script)
Definition evt.c:460
ApiStatus evt_handle_get_3_word(Evt *script)
Definition evt.c:713
ApiStatus evt_handle_divideF(Evt *script)
Definition evt.c:664
ApiStatus evt_handle_multiply(Evt *script)
Definition evt.c:592
ApiStatus evt_handle_switch(Evt *script)
Definition evt.c:230
char evtDebugPrintBuffer[0x100]
Definition script_list.c:20
ApiStatus evt_handle_AND_const(Evt *script)
Definition evt.c:856
ApiStatus evt_handle_break_case(Evt *script)
Definition evt.c:530
Bytecode * evt_goto_end_case(Evt *script)
Definition evt.c:2129
ApiStatus evt_handle_jump(Evt *script)
Definition evt.c:974
Bytecode * evt_skip_else(Evt *script)
Definition evt.c:2081
ApiStatus evt_handle_suspend_all(Evt *script)
Definition evt.c:1071
ApiStatus evt_handle_case_less(Evt *script)
Definition evt.c:302
ApiStatus evt_handle_set_timescale(Evt *script)
Definition evt.c:1061
ApiStatus evt_handle_set_const(Evt *script)
Definition evt.c:555
ApiStatus evt_handle_subtract(Evt *script)
Definition evt.c:580
ApiStatus evt_handle_if_greater(Evt *script)
Definition evt.c:163
ApiStatus evt_handle_exec_wait(Evt *script)
Definition evt.c:965
f32 evt_set_float_variable(Evt *script, Bytecode var, f32 value)
Definition evt.c:1977
ApiStatus evt_handle_set_array(Evt *script)
Definition evt.c:826
Bytecode * EvtCallingLine
Definition evt.c:8
Bytecode * evt_goto_next_case(Evt *script)
Definition evt.c:2157
ApiStatus evt_handle_if_less(Evt *script)
Definition evt.c:151
ApiStatus evt_handle_case_default(Evt *script)
Definition evt.c:420
ApiStatus evt_handle_exec1(Evt *script)
Definition evt.c:911
u32 * gMapFlags
Definition script_list.c:9
s32 evt_set_variable(Evt *script, Bytecode var, s32 value)
Definition evt.c:1847
ApiStatus evt_handle_add(Evt *script)
Definition evt.c:568
ApiStatus evt_handle_loop(Evt *script)
Definition evt.c:45
ApiStatus evt_handle_return(Evt *script)
Definition evt.c:31
Bytecode * evt_goto_end_loop(Evt *script)
Definition evt.c:2200
ApiStatus evt_handle_mod(Evt *script)
Definition evt.c:616
ApiStatus evt_handle_thread(Evt *script)
Definition evt.c:1157
s32 evt_get_variable_index_alt(s32 var)
Definition evt.c:1804
s32 evt_trigger_on_activate_lock(Trigger *trigger)
Definition evt.c:1110
ApiStatus evt_handle_case_equal_AND(Evt *script)
Definition evt.c:485
ApiStatus evt_handle_case_range(Evt *script)
Definition evt.c:394
Bytecode evt_float_to_fixed_var(f32 value)
Definition evt.c:25
ApiStatus evt_handle_goto(Evt *script)
Definition evt.c:40
s32 evt_trigger_on_activate_exec_script(Trigger *trigger)
Definition evt.c:982
ApiStatus evt_handle_OR_const(Evt *script)
Definition evt.c:876
ApiStatus evt_handle_bind(Evt *script)
Definition evt.c:1009
ApiStatus evt_handle_print_debug_var(Evt *script)
Definition evt.c:1232
ApiStatus evt_handle_set_var(Evt *script)
Definition evt.c:547
ApiStatus evt_handle_get_4_word(Evt *script)
Definition evt.c:729
ApiStatus evt_handle_unbind(Evt *script)
Definition evt.c:1046
ApiStatus evt_handle_bind_lock(Evt *script)
Definition evt.c:1127
ApiStatus evt_handle_if_not_equal(Evt *script)
Definition evt.c:139
ApiStatus evt_handle_get_1_float(Evt *script)
Definition evt.c:758
ApiStatus evt_handle_if_less_equal(Evt *script)
Definition evt.c:175
ApiStatus evt_handle_end_loop(Evt *script)
Definition evt.c:58
ApiStatus evt_handle_debug_log(Evt *script)
Definition evt.c:1225
ApiStatus func_802C73B8(Evt *script)
Definition evt.c:1340
s32 evt_execute_next_command(Evt *script)
Definition evt.c:1351
ApiStatus evt_handle_get_Nth_word(Evt *script)
Definition evt.c:748
ApiStatus evt_handle_exec1_get_id(Evt *script)
Definition evt.c:937
ApiStatus evt_handle_case_AND(Evt *script)
Definition evt.c:435
ApiStatus evt_handle_subtractF(Evt *script)
Definition evt.c:640
ApiStatus evt_handle_set_flag_array(Evt *script)
Definition evt.c:831
ApiStatus evt_handle_set_float_buffer_ptr(Evt *script)
Definition evt.c:683
ApiStatus evt_handle_end_child_thread(Evt *script)
Definition evt.c:1220
ApiStatus evt_handle_end_case_group(Evt *script)
Definition evt.c:513
ApiStatus evt_handle_get_Nth_float(Evt *script)
Definition evt.c:816
ApiStatus evt_handle_addF(Evt *script)
Definition evt.c:628
ApiStatus evt_handle_get_1_word(Evt *script)
Definition evt.c:690
ApiStatus evt_handle_set_priority(Evt *script)
Definition evt.c:1056
ApiStatus evt_handle_suspend(Evt *script)
Definition evt.c:1091
ApiStatus evt_handle_get_2_float(Evt *script)
Definition evt.c:768
ApiStatus evt_handle_case_less_equal(Evt *script)
Definition evt.c:325
ApiStatus evt_handle_get_2_word(Evt *script)
Definition evt.c:700
ApiStatus evt_handle_end_switch(Evt *script)
Definition evt.c:536
ApiStatus evt_handle_if_greater_equal(Evt *script)
Definition evt.c:187
ApiStatus evt_handle_resume_all(Evt *script)
Definition evt.c:1076
ApiStatus evt_handle_if_equal(Evt *script)
Definition evt.c:127
f32 evt_fixed_var_to_float(Bytecode scriptVar)
Definition evt.c:17
ApiStatus evt_handle_child_thread(Evt *script)
Definition evt.c:1195
f32 evt_get_float_variable(Evt *script, Bytecode var)
Definition evt.c:1930
ApiStatus evt_handle_case_equal(Evt *script)
Definition evt.c:256
ApiStatus evt_handle_get_3_float(Evt *script)
Definition evt.c:781
ApiStatus evt_handle_does_script_exist(Evt *script)
Definition evt.c:1101
Bytecode * evt_find_label(Evt *script, s32 arg1)
Definition evt.c:2023
ApiStatus evt_handle_else(Evt *script)
Definition evt.c:221
ApiStatus evt_handle_set_group(Evt *script)
Definition evt.c:1066
ApiStatus evt_handle_multiplyF(Evt *script)
Definition evt.c:652
ApiStatus evt_handle_resume(Evt *script)
Definition evt.c:1096
ApiStatus evt_handle_if_not_AND(Evt *script)
Definition evt.c:210
ApiStatus evt_handle_end_if(Evt *script)
Definition evt.c:226
ApiStatus evt_handle_kill(Evt *script)
Definition evt.c:1051
ApiStatus evt_handle_resume_others(Evt *script)
Definition evt.c:1086
ApiStatus evt_handle_if_AND(Evt *script)
Definition evt.c:199
ApiStatus evt_handle_wait_seconds(Evt *script)
Definition evt.c:111
ApiStatus evt_handle_wait(Evt *script)
Definition evt.c:95
ApiStatus evt_handle_case_not_equal(Evt *script)
Definition evt.c:279
ApiStatus evt_handle_get_4_float(Evt *script)
Definition evt.c:797
ApiStatus evt_handle_label(Evt *script)
Definition evt.c:36
s32 * gMapVars
Definition script_list.c:10
ApiStatus evt_handle_case_greater_equal(Evt *script)
Definition evt.c:371
ApiStatus evt_handle_suspend_others(Evt *script)
Definition evt.c:1081
ApiStatus evt_handle_allocate_array(Evt *script)
Definition evt.c:836
ApiStatus evt_handle_divide(Evt *script)
Definition evt.c:604
@ EVT_OP_LOOP
Args: number of repeats (0 = infinite)
Definition evt.h:15
@ EVT_OP_EXEC_GET_TID
Args: EvtScript*, container.
Definition evt.h:79
@ EVT_OP_CASE_DEFAULT
Definition evt.h:38
@ EVT_OP_END_IF
Definition evt.h:29
@ EVT_OP_INTERNAL_FETCH
Definition evt.h:10
@ EVT_OP_MOD
Args: container, expression to divide by.
Definition evt.h:53
@ EVT_OP_FBUF_READ2
Args: container.
Definition evt.h:66
@ EVT_OP_94
Definition evt.h:104
@ EVT_OP_93
Definition evt.h:103
@ EVT_OP_UNBIND
Unbinds any triggers bound to this script.
Definition evt.h:82
@ EVT_OP_ADDF
Args: container, expression to increment by.
Definition evt.h:54
@ EVT_OP_FBUF_READ3
Args: container, container.
Definition evt.h:67
@ EVT_OP_SET_PRIORITY
Args: priority.
Definition evt.h:85
@ EVT_OP_DIVF
Args: container, expression to divide by.
Definition evt.h:57
@ EVT_OP_CASE_FLAG
Args: expression to test for.
Definition evt.h:41
@ EVT_OP_ELSE
Definition evt.h:28
@ EVT_OP_DEBUG_LOG
Definition evt.h:100
@ EVT_OP_MULF
Args: container, expression to multiply by.
Definition evt.h:56
@ EVT_OP_SUSPEND_OTHERS
Args: group.
Definition evt.h:91
@ EVT_OP_SUSPEND_THREAD
Args: ScriptID.
Definition evt.h:93
@ EVT_OP_GOTO
Args: index.
Definition evt.h:14
@ EVT_OP_EXEC
Args: EvtScript*.
Definition evt.h:78
@ EVT_OP_USE_ARRAY
Args: *s32.
Definition evt.h:70
@ EVT_OP_MUL
Args: container, expression to multiply by.
Definition evt.h:51
@ EVT_OP_END_CASE_GROUP
Ends the case block of EVT_OP_CASE_OR_EQ condition(s).
Definition evt.h:42
@ EVT_OP_92
Definition evt.h:102
@ EVT_OP_IF_LE
Args: a, b.
Definition evt.h:24
@ EVT_OP_IF_FLAG
Args: a, b.
Definition evt.h:26
@ EVT_OP_WAIT_SECS
Definition evt.h:19
@ EVT_OP_END
Definition evt.h:11
@ EVT_OP_RETURN
Definition evt.h:12
@ EVT_OP_SET
Args: container, expression.
Definition evt.h:46
@ EVT_OP_IF_NE
Args: a, b.
Definition evt.h:21
@ EVT_OP_CASE_EQ
Args: expression to test for.
Definition evt.h:32
@ EVT_OP_BITWISE_OR_CONST
Args: container, value to bitwise OR with.
Definition evt.h:76
@ EVT_OP_BUF_READ1
Definition evt.h:59
@ EVT_OP_USE_FBUF
Identical to USE_BUFFER. Args: f32*.
Definition evt.h:64
@ EVT_OP_SETF
Args: container, expression.
Definition evt.h:48
@ EVT_OP_CHILD_THREAD
Parallel threads are killed as soon as the parent script returns.
Definition evt.h:98
@ EVT_OP_CASE_GE
Args: expression to test for.
Definition evt.h:37
@ EVT_OP_IF_GT
Args: a, b.
Definition evt.h:23
@ EVT_OP_CASE_OR_EQ
Args: expression to test for.
Definition evt.h:39
@ EVT_OP_END_CHILD_THREAD
Definition evt.h:99
@ EVT_OP_END_SWITCH
Definition evt.h:45
@ EVT_OP_DEBUG_PRINT_VAR
Args: expression.
Definition evt.h:101
@ EVT_OP_BUF_READ3
Args: container, container.
Definition evt.h:61
@ EVT_OP_DIV
Integer division. Args: container, expression to divide by.
Definition evt.h:52
@ EVT_OP_EXEC_WAIT
Spawns a script and waits for it to return before continuing. Args: EvtScript*.
Definition evt.h:80
@ EVT_OP_END_LOOP
Definition evt.h:16
@ EVT_OP_BUF_READ4
Args: container, container, container.
Definition evt.h:62
@ EVT_OP_ADD
Args: container, expression to increment by.
Definition evt.h:49
@ EVT_OP_FBUF_READ4
Args: container, container, container.
Definition evt.h:68
@ EVT_OP_BREAK_SWITCH
Definition evt.h:44
@ EVT_OP_SET_TIMESCALE
Args: timescale.
Definition evt.h:86
@ EVT_OP_USE_BUF
Args: s32*.
Definition evt.h:58
@ EVT_OP_BREAK_LOOP
Definition evt.h:17
@ EVT_OP_USE_FLAGS
Args: *s32.
Definition evt.h:71
@ EVT_OP_CASE_RANGE
Args: from, to.
Definition evt.h:43
@ EVT_OP_BITWISE_AND_CONST
Args: container, value to bitwise AND with.
Definition evt.h:74
@ EVT_OP_FBUF_READ1
Definition evt.h:65
@ EVT_OP_SUBF
Args: container, expression to decrement by.
Definition evt.h:55
@ EVT_OP_WAIT_FRAMES
Definition evt.h:18
@ EVT_OP_JUMP
Args: EvtScript*.
Definition evt.h:84
@ EVT_OP_THREAD
Definition evt.h:96
@ EVT_OP_CASE_AND_EQ
Args: expression to test for.
Definition evt.h:40
@ EVT_OP_SWITCH
Args: expression to test against.
Definition evt.h:30
@ EVT_OP_CASE_LE
Args: expression to test for.
Definition evt.h:36
@ EVT_OP_SUB
Args: container, expression to decrement by.
Definition evt.h:50
@ EVT_OP_IF_GE
Args: a, b.
Definition evt.h:25
@ EVT_OP_CALL
Args: *function, ...
Definition evt.h:77
@ EVT_OP_IF_NOT_FLAG
Args: a, b.
Definition evt.h:27
@ EVT_OP_IS_THREAD_RUNNING
Args: ScriptID, container.
Definition evt.h:95
@ EVT_OP_IF_LT
Args: a, b.
Definition evt.h:22
@ EVT_OP_SWITCH_CONST
Args: value to test against.
Definition evt.h:31
@ EVT_OP_CASE_NE
Args: expression to test for.
Definition evt.h:33
@ EVT_OP_SET_CONST
Args: container, value.
Definition evt.h:47
@ EVT_OP_KILL_THREAD
Args: ScriptID.
Definition evt.h:83
@ EVT_OP_LABEL
Args: index.
Definition evt.h:13
@ EVT_OP_RESUME_OTHERS
Args: group.
Definition evt.h:92
@ EVT_OP_RESUME_THREAD
Args: ScriptID.
Definition evt.h:94
@ EVT_OP_BUF_READ2
Args: container.
Definition evt.h:60
@ EVT_OP_END_THREAD
Definition evt.h:97
@ EVT_OP_RESUME_GROUP
Args: group.
Definition evt.h:90
@ EVT_OP_BIND_TRIGGER
Args: EvtScript*, trigger flags, s32 target, 1, Trigger*.
Definition evt.h:81
@ EVT_OP_BITWISE_AND
Args: container, expression to bitwise AND with.
Definition evt.h:73
@ EVT_OP_CASE_GT
Args: expression to test for.
Definition evt.h:35
@ EVT_OP_BITWISE_OR
Args: container, expression to bitwise OR with.
Definition evt.h:75
@ EVT_OP_SET_GROUP
Args: group.
Definition evt.h:87
@ EVT_OP_BIND_PADLOCK
Args: EvtScript*, trigger flags, s32 target, ItemList*, 0, 1.
Definition evt.h:88
@ EVT_OP_SUSPEND_GROUP
Args: group.
Definition evt.h:89
@ EVT_OP_CASE_LT
Args: expression to test for.
Definition evt.h:34
@ EVT_OP_MALLOC_ARRAY
Allocates a new array. Args: length, s32*.
Definition evt.h:72
@ EVT_OP_BUF_PEEK
Args: container, container, container, container.
Definition evt.h:63
@ EVT_OP_IF_EQ
Args: a, b.
Definition evt.h:20
@ EVT_OP_FBUF_PEEK
Args: container, container, container, container.
Definition evt.h:69
s32 ApiStatus
Definition evt.h:115
#define ApiStatus_DONE2
Definition evt.h:118
#define ApiStatus_REPEAT
Definition evt.h:119
s32 Bytecode
Definition evt.h:7
#define ApiStatus_FINISH
Definition evt.h:120
#define ApiStatus_DONE1
Definition evt.h:117
#define ApiStatus_BLOCK
Definition evt.h:116
@ EVT_CMD_RESULT_YIELD
Definition evt.h:123
@ EVT_CMD_RESULT_CONTINUE
Definition evt.h:124
@ EVT_CMD_RESULT_ERROR
Definition evt.h:125
@ EVT_FLAG_RUN_IMMEDIATELY
don't wait for next update_scripts call
Definition evt.h:161
@ EVT_FLAG_THREAD
Definition evt.h:162
void suspend_group_others(Evt *script, s32 groupFlags)
void kill_script(Evt *instanceToKill)
void set_script_group(Evt *script, s32 groupFlags)
Evt * start_child_script(Evt *parentScript, EvtScript *source, s32 initialState)
Evt * get_script_by_index(s32 index)
s32 resume_all_group(s32 groupFlags)
s32 suspend_all_script(s32 id)
s32 is_another_trigger_bound(Trigger *, EvtScript *script)
Definition trigger.c:254
Evt * start_script(EvtScript *source, s32 priority, s32 initialState)
void resume_group_others(Evt *script, s32 groupFlags)
void kill_script_by_ID(s32 id)
Trigger * create_trigger(TriggerBlueprint *def)
Definition trigger.c:55
void set_script_timescale(Evt *script, f32 timescale)
void set_script_priority(Evt *script, s32 priority)
s32 resume_all_script(s32 id)
s32 does_script_exist(s32 id)
void delete_trigger(Trigger *toDelete)
Definition trigger.c:239
Evt * start_script_in_group(EvtScript *source, u8 priority, u8 initialState, u8 groupFlags)
void suspend_all_group(s32 groupFlags)
Evt * restart_script(Evt *script)
void * heap_malloc(s32 size)
Definition heap.c:34
Evt * func_802C39F8(Evt *parentScript, Bytecode *nextLine, s32 newState)
ApiStatus DeleteTrigger(Evt *script, b32 isInitialCall)
Removes a trigger previously bound with BindTrigger.
#define EVT_LOCAL_VAR_CUTOFF
Expressions in EVT instructions should be one of the following types:
Definition macros.h:24
#define EVT_INDEX_OF_AREA_BYTE(v)
Definition macros.h:141
#define EVT_ARRAY_VAR_CUTOFF
Definition macros.h:40
#define EVT_FIXED_OFFSET
Definition macros.h:45
#define MAX_SCRIPTS
Definition macros.h:90
#define EVT_MAP_FLAG_CUTOFF
Definition macros.h:30
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define EVT_FIXED_CUTOFF
Definition macros.h:44
#define EVT_LOCAL_FLAG_CUTOFF
Definition macros.h:28
#define EVT_GAME_FLAG_CUTOFF
Definition macros.h:34
#define EVT_AREA_BYTE_CUTOFF
Definition macros.h:36
#define EVT_INDEX_OF_AREA_FLAG(v)
Definition macros.h:140
#define EVT_INDEX_OF_ARRAY_FLAG(v)
Definition macros.h:144
#define PANIC()
Definition macros.h:55
#define EVT_INDEX_OF_LOCAL_VAR(v)
Definition macros.h:136
#define EVT_INDEX_OF_ARRAY_VAR(v)
Definition macros.h:145
#define EVT_INDEX_OF_GAME_BYTE(v)
Definition macros.h:143
#define EVT_GAME_BYTE_CUTOFF
Definition macros.h:38
#define EVT_IGNORE_ARG
Definition macros.h:46
#define EVT_FIXED_TO_FLOAT(x)
Progammatically converts Float --> f32.
Definition macros.h:54
#define EVT_ARRAY_FLAG_CUTOFF
Definition macros.h:42
#define ASSERT_MSG(condition, msg, args...)
Definition macros.h:66
#define EVT_INDEX_OF_MAP_FLAG(v)
Definition macros.h:139
#define EVT_INDEX_OF_LOCAL_FLAG(v)
Definition macros.h:137
#define EVT_AREA_FLAG_CUTOFF
Definition macros.h:32
#define EVT_INDEX_OF_MAP_VAR(v)
Definition macros.h:138
#define EVT_MAP_VAR_CUTOFF
Definition macros.h:26
#define EVT_INDEX_OF_GAME_FLAG(v)
Definition macros.h:142
#define EVT_LIMIT
Definition macros.h:47
s32(* onActivateFunc)(struct Trigger *)
s32 runningScriptID
EvtScript * onTriggerEvt
struct Evt * runningScript
GameStatus * gGameStatusPtr
Definition main_loop.c:32
s32 set_global_flag(s32 index)
Definition vars_access.c:65
s32 get_global_flag(s32 index)
Definition vars_access.c:89
s32 set_area_flag(s32 index)
s32 get_global_byte(s32 index)
Get value of saved game byte.
s32 clear_area_flag(s32 index)
s32 get_area_flag(s32 index)
s32 get_area_byte(s32 index)
s8 set_area_byte(s32 index, s32 value)
s32 clear_global_flag(s32 index)
Definition vars_access.c:41
s8 set_global_byte(s32 index, s32 value)
Set value of saved game byte.