-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathscript_commands.s
More file actions
1075 lines (937 loc) · 23.9 KB
/
Copy pathscript_commands.s
File metadata and controls
1075 lines (937 loc) · 23.9 KB
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; Naming convention: any script command that starts with the word "check" will hold script
; execution until a particular condition becomes true, ie. "checknoenemies" holds
; execution until there are no enemies.
.MACRO scriptend
.db $00
.ENDM
.MACRO scriptjump
.db (\1)>>8
.db (\1)&$ff
.ENDM
; Set the value of the Interaction.state variable.
.MACRO setstate
.db $80, \1
.ENDM
; Increment the Interaction.state variable.
.MACRO incstate
.db $80, $ff
.ENDM
; Set the value of the Interaction.substate variable.
.MACRO setsubstate
.db $81, \1
.ENDM
; $82: not a real command
; Loads a script to wBigBuffer ($c300, up to 256 bytes) and runs the script there.
; param1: Script to load and jump to
.MACRO loadscript
.IF NARGS == 2
.db $83, \1
.dw \2
.ELSE
.db $83, :\1
.dw \1
.ENDIF
.ENDM
; Spawns an interaction.
; param1: The ID of the interaction
; param2: The SubID of the interaction
; param3: The interaction's Y position
; param4: The interaction's X position
.MACRO spawninteraction
.db $84
.if NARGS == 3
.db (\1)>>8, (\1)&$ff
.db \2, \3
.else
.db \1, \2
.db \3, \4
.endif
.ENDM
; Spawns an enemy.
; param1: The ID of the enemy
; param2: The SubID of the enemy
; param3: The enemy's Y position
; param4: The enemy's X position
.MACRO spawnenemy
.db $85
.if NARGS == 3
.db (\1)>>8, (\1)&$ff
.db \2, \3
.else
.db \1, \2
.db \3, \4
.endif
.ENDM
; Generates a secret, which can later be displayed in a textbox. Only works for secrets which are
; "outgoing" for this game (ie. can't generate a linked seasons secret in ages).
;
; param1: The index of the secret (see constants/common/secrets.s or wShortSecretIndex).
.MACRO generatesecret
.ifdef ROM_AGES
.IF \1 < $10
.FAIL
.ENDIF
.IF \1 >= $20
.FAIL
.ENDIF
.else; ROM_SEASONS
.IF \1 < $30
.FAIL
.ENDIF
.IF \1 >= $40
.FAIL
.ENDIF
.endif
.db $86, \1
.ENDM
; Brings up a text prompt to input a secret. Only works for secrets which are "incoming" for this
; game (ie. can't ask for a linked ages secret in ages).
;
; param1: The index of the secret (see constants/common/secrets.s or wShortSecretIndex).
; If $ff, it asks for and accepts any valid secret (used with farore).
.MACRO askforsecret
.IF \1 == $ff
.ELSE
.ifdef ROM_AGES
.IF \1 >= $10
.FAIL
.ENDIF
.else; ROM_SEASONS
.IF \1 < $20
.FAIL
.ENDIF
.IF \1 >= $30
.FAIL
.ENDIF
.endif
.ENDIF
.db $86, \1
.ENDM
; Uses the given memory address as an index for a jump table immediately after the
; opcode. After this opcode you can do as many .dw statements and you like,
; each indicating an index's location to jump to.
;
; param1[16]: Memory address to use as the index for the table
; (memory address $dyxx, where y corresponds to this object)
.MACRO jumptable_memoryaddress
.db $87
.dw \1
.ENDM
; Set the X and Y coordinates of the interaction. If only 1 parameter is
; passed, it is read as $YX (4 bits each) and are equivalent to $Y8 $X8. if
; 2 parameters are passed, they are read as $YY $XX (8 bits each).
;
; param1: Y-position
; param2: X-position
.MACRO setcoords
.db $88
.IF NARGS == 2
.db \1
.db \2
.ELSE
.db ((\1)&$f0) | 8
.db (((\1)&$0f)<<4) | 8
.ENDIF
.ENDM
; param1: Value for Interaction.angle
.MACRO setangle
.db $89, \1
.ENDM
; Make an object face link.
.MACRO turntofacelink
.db $8a
.ENDM
; param1: Value for Interaction.speed (see constants/common/objectSpeeds.s)
.MACRO setspeed
.db $8b, \1
.ENDM
; Writes the given value to Interaction.counter2. Then, the script holds execution for
; that many frames while the object's speed is applied.
;
; param1: The number of frames to wait. (for some reason this parameter is
; optional? If it's not passed, it just waits for counter2 to reach 0...)
.MACRO applyspeed
.IF NARGS == 1
.db $8c, \1
.ELSE
.db $d8
.ENDIF
.ENDM
; Set an object's collision box.
; param1: Y collision radius
; param2: X collision radius
.MACRO setcollisionradii
.db $8d, \1, \2
.ENDM
; Write a byte to the object's memory. Script execution resumes next frame.
; param1: Low byte of address to set (should be Interaction.something)
; param2: Byte value to write to the address
.MACRO writeobjectbyte
.db $8e, \1, \2
m_verify_object_byte \1, "writeobjectbyte"
.ENDM
; Calls interactionSetAnimation with the specified value.
; param1: Animation index
.MACRO setanimation
.db $8f, \1
.if \1 >= $fe
.PRINTT "SCRIPT ERROR: argument to 'setanimation' too high.\n"
.FAIL
.endif
.ENDM
; Calls interactionSetAnimation using one of the interaction's variables.
.MACRO setanimationfromobjectbyte
.db $8f, $fe, \1
m_verify_object_byte \1, "setanimationfromobjectbyte"
.ENDM
; Sets the interaction's animation based on its angle.
.MACRO setanimationfromangle
.db $8f, $ff
.ENDM
; Compares the interaction's x-position to link's x-position and stores the
; result in the given address (result is $00 if this.x >= link.x, otherwise
; it's $01)
; param1: Low byte of address to store the result
.MACRO cplinkx
.db $90, \1
m_verify_object_byte \1, "cplinkx"
.ENDM
; Write a byte to an address in memory.
; param1[16]: Address to write to
; param2: Byte to write to the address
.MACRO writememory
.db $91
.dw \1
.db \2
.ENDM
; Bitwise OR a byte with an address in memory.
; param1[16]: Address to OR with and store result into.
; param2: Byte to OR with.
.MACRO ormemory
.db $92
.dw \1
.db \2
.ENDM
; Get a random number, store it into an interaction address.
; param1: Low byte of interaction address to store result into
; param2: Value to bitwise AND with the random number before storing it.
.MACRO getrandombits
.db $93
.db \1, \2
m_verify_object_byte \1, "getrandombits"
.ENDM
; Add a byte with an interaction address.
; param1: Low byte of interaction address to add with.
; param2: Value to add.
.MACRO addobjectbyte
.db $94
.db \1 \2
m_verify_object_byte \1, "addobjectbyte"
.ENDM
; Sets the interaction's vertical speed (z axis).
; param1[16]: Vertical speed
.MACRO setzspeed
.db $95
.dw \1
.ENDM
; Sets the object's moving direction and matching animation.
; param1: The object's angle ($00-$1f)
.MACRO setangleandanimation
.db $96
.db \1
.ENDM
; Set Interaction.textID to the given value and jump to a generic npc script; the object
; will display text when A is pressed. Only use this when Interaction.useTextID is zero
; (default); otherwise use rungenericnpclowindex.
;
; param1[16]: The text index to show when talked to
.MACRO rungenericnpc
.db $97
.db (\1)>>8, (\1)&$ff
.ENDM
; Set Interaction.textID to the given value. Only use this when Interaction.useTextID is
; nonzero; otherwise use rungenericnpc.
;
; param1: The text index to show when talked to
.MACRO rungenericnpclowindex
.db $97
.db \1
.ENDM
; Displays the text index given. Only use this when Interaction.useTextID is zero
; (default); otherwise use showtextlowindex.
;
; param1[16]: The low byte of the text index to display.
.MACRO showtext
.db $98
.db (\1)>>8, (\1)&$ff
.ENDM
; Displays the text index with high byte [Interaction.textID] and the low
; byte given. Only use this when Interaction.useTextID is nonzero; otherwise
; use showtext.
;
; param1: The low byte of the text index to display.
.MACRO showtextlowindex
.db $98
.db \1
.ENDM
; Hold script execution until text is no longer being displayed.
.MACRO checktext
.db $99
.ENDM
; Displays the text index given, being non-exitable by user input. Only use this when
; Interaction.useTextID is zero (default); otherwise use showtextnonexitablelowindex.
;
; param1[16]: The text index to display.
.MACRO showtextnonexitable
.db $9a
.db (\1)>>8, (\1)&$ff
.ENDM
; Displays the text index given, being non-exitable by user input. Only use this when
; Interaction.useTextID is zero (default); otherwise use showtextnonexitablelowindex.
;
; param1: The low byte of the text index to display.
.MACRO showtextnonexitablelowindex
.db $9a
.db \1
.ENDM
; Adds the object to wAButtonSensitiveObjectList; this allows the "checkabutton" command
; to work.
.MACRO makeabuttonsensitive
.db $9b
.ENDM
; Set the Interaction.textID variable. This text ID can later be shown with
; showloadedtext.
;
; param1[16] Text ID
.MACRO settextid
.db $9c
.dw \1
.ENDM
; Show the text id corresponding to the Interaction.textID variable (set by "settextid").
.MACRO showloadedtext
.db $9d
.ENDM
; Hold script execution until the A button is pressed while link is next to the
; interaction. Use to wait for npc dialog, etc.
; You must use either "initcollisions" or "makeabuttonsensitive" before you can use this.
.MACRO checkabutton
.db $9e
.ENDM
; Shows a certain text id depending if the game is linked or unlinked
; param1: the text to show for unlinked games.
; param2: the text to show for linked games.
.MACRO showtextdifferentforlinked
.db $9f
.db (\1)>>8, (\1)&$ff, (\2)&$ff
.if (\1)>>8 != (\2)>>8
.PRINTT "SCRIPT ERROR: in 'showtextdifferentforlinked' opcode, the text indices were in different groups.\n"
.FAIL
.endif
.ENDM
; Holds execution until the given bit of address $cfc0 is set.
; param1: Bit to check (0-7)
.MACRO checkcfc0bit
.db $a0 | (\1)
.ENDM
; Xors the given bit in address $cfc0.
; param1: Bit to xor (0-7)
.MACRO xorcfc0bit
.db $a8 | (\1)
.ENDM
; Jumps to the specified address if the specified flag(s) in the room are set.
; When the script is loaded into wBigBuffer, this will only work if the
; destination to jump to is already loaded into the buffer.
;
; param1: Value to AND with the room flags for the check
; param2[16]: Destination address to jump to if the result is nonzero
.MACRO jumpifroomflagset
.db $b0, \1
.dw \2
.ENDM
; OR the room flags with the given value. Used to mark if an event has occured,
; and if so, you can skip it with the "jumpifroomflagset" opcode.
.MACRO orroomflag
.db $b1, \1
.ENDM
; B2: no command
; Jumps to the specified address if a specified address ($c6xx) AND the given
; value is nonzero.
; When the script is loaded into wBigBuffer, this will only work if the
; destination to jump to is already loaded into the buffer.
;
; param1: The low byte of the address to read (ie. if address is "$75",
; corresponding to "<wNumSmallKeys", it will read from $c675.)
; param2: Value to AND with the address for the check
; param3[16]: Destination address to jump to if the result is nonzero
.MACRO jumpifc6xxset
.db $b3
.db \1, \2
.dw \3
.ENDM
; Write the given value to an address at $c6xx.
; param1: Low byte of the address to write to
; param2: Value to write to the address
.MACRO writec6xx
.db $b4
.db \1, \2
.ENDM
; Jump to the specified address if the given global flag is set.
; A list of global flags can be found in "constants/common/globalFlags.s".
;
; param1: The global flag to check
; param2[16]: Destination address to jump to if the flag is set
.MACRO jumpifglobalflagset
.db $b5, \1
.dw \2
.ENDM
; Sets the specified global flag.
; A list of global flags can be found in "constants/common/globalFlags.s".
;
; param1: The global flag to set
.MACRO setglobalflag
.db $b6, \1
.ENDM
; Unsets the specified global flag.
; A list of global flags can be found in "constants/common/globalFlags.s".
;
; param1: The global flag to unset
.MACRO unsetglobalflag
.db $b6, (\1) | $80
.ENDM
; $B7: no command
; Set the variable wDisabledObjects to $91. Disables Link, items, and enemies?
.MACRO setdisabledobjectsto91
.db $b8
.ENDM
; Set the variable wDisabledObjects to $00, re-enabling all objects.
.MACRO enableallobjects
.db $b9
.ENDM
; Set the variable wDisabledObjects to $11. Disables Link and items?
.MACRO setdisabledobjectsto11
.db $ba
.ENDM
.MACRO disablemenu
.db $bb
.ENDM
.MACRO enablemenu
.db $bc
.ENDM
; Disables link movement and the menu.
.MACRO disableinput
.db $bd
.ENDM
; Enables link movement and the menu.
.MACRO enableinput
.db $be
.ENDM
; $BF: no command
; Call another script. Only works 1 level deep?
; param1[16]: Script to call
.MACRO callscript
.db $c0
.dw \1
.ENDM
; Return from a script after a callscript command.
.MACRO retscript
.db $c1
.ENDM
; $C2: no command
; Jump to the specified address if [wSelectedTextOption] equals the given value.
;
; param1: The value to compare [wSelectedTextOption] with.
; param2[16]: Destination address to jump to if the values are equal.
.MACRO jumpiftextoptioneq
.db $c3
.db \1
.dw \2
.ENDM
; Takes two addresses, and randomly chooses one to jump to.
; DOESN'T WORK IN AGES. Rather, it just jumps to the first address, but is never used
; anyway?
;
; param1: First choice of address to jump to.
; param2: Second choice.
.MACRO jumprandom
.ifdef ROM_AGES
.PRINTT "Can't use 'jumprandom' script opcode in ages."
.FAIL
.endif
.db $c4
.dw \1, \2
.ENDM
; $C5: no command
; Uses a byte in the object's memory as an index for a jump table immediately after the
; opcode. After this opcode you can do as many .dw statements and you like, each
; indicating an index's location to jump to.
;
; param1: Low byte of the address to use as the index for the table
.MACRO jumptable_objectbyte
.db $c6, \1
m_verify_object_byte \1, "jumptable_objectbyte"
.ENDM
; Jump to somewhere if the given memory address AND the given value is nonzero.
; param1[16]: Address to AND with
; param2: Byte to AND the address with
; param3: Address to jump to if the result is nonzreo
.MACRO jumpifmemoryset
.db $c7
.dw \1
.db \2
.dw \3
.ENDM
; Jump somewhere if the trade item equals a certain value.
;
; param1: Value to check for the trade item. (For some reason this is subtracted by
; one... but that's adjusted for here, so one can use defines from
; "constants/common/tradeitems.s" just fine.)
; param2[16]: Destination to jump to
.MACRO jumpiftradeitemeq
.db $c8, \1+1
.dw \2
.ENDM
; Jump somewhere if (wNumEnemies) is zero.
; param1[16]: Destination to jump to
.MACRO jumpifnoenemies
.db $c9
.dw \1
.ENDM
; Jump somewhere if one of link's variables (d0xx) does not equal the given
; value.
; param1: The low byte of the address to compare with (d0xx)
; param2: Value to compare with
; param3[16]: Destination to jump to
.MACRO jumpiflinkvariableneq
.db $ca
.db \1, \2
.dw \3
.ENDM
; Jump somewhere if the given memory address equals a certain value.
; param1[16]: Memory address to check
; param2: Value to compare with memory address
; param3: Address to jump to if values are equal
.MACRO jumpifmemoryeq
.db $cb
.dw \1
.db \2
.dw \3
.ENDM
; Jump somewhere if the given interaction byte equals a certain value.
; param1: Interaction byte to check
; param2: Value to compare with memory address
; param3: Address to jump to
.MACRO jumpifobjectbyteeq
.db $cc
.db \1
.db \2
.dw \3
m_verify_object_byte \1, "jumpifobjectbyteeq"
.ENDM
; Stops execution of the script if the room's item flag (aka ROOMFLAG_ITEM aka bit 5) is set.
.MACRO stopifitemflagset
.db $cd
.ENDM
; Stops execution of the script if ROOMFLAG_40 is set for this room.
.MACRO stopifroomflag40set
.db $ce
.ENDM
; Stops execution of the script if ROOMFLAG_80 is set for this room.
.MACRO stopifroomflag80set
.db $cf
.ENDM
; Holds execution until link and the interaction collide, and link is on the ground. It
; may be necessary to do "initcollisions" before this.
.MACRO checkcollidedwithlink_onground
.db $d0
.ENDM
; Holds execution until the palettes are done fading in or out.
.MACRO checkpalettefadedone
.db $d1
.ENDM
; Holds execution until [wNumEnemies] equals zero.
.MACRO checknoenemies
.db $d2
.ENDM
; Holds execution until a "flag" (a bit in memory) is set. Uses the checkFlag
; function.
; param1: The index of the flag to check (not a bitmask)
; param2: The starting address of the flags (ie wGlobalFlags)
.MACRO checkflagset
.db $d3
.db \1
.dw \2
.ENDM
; Holds execution until the given byte in the object's memory equals the given value.
;
; param1: The low byte of the address to check (xx in $dyxx)
; param2: The value to check for equality with
.MACRO checkobjectbyteeq
.db $d4
.db \1, \2
m_verify_object_byte \1, "checkobjectbyteeq"
.ENDM
; Holds execution until the given memory address equals the given value.
;
; param1: The address to check
; param2: The value to check for equality with
.MACRO checkmemoryeq
.db $d5
.dw \1
.db \2
.ENDM
; Holds execution until link and the interaction are not colliding. You may
; need to do "initcollisions" before this.
.MACRO checknotcollidedwithlink_ignorez
.db $d6
.ENDM
; Sets Interaction.counter1 to the given value. Script execution holds until it reaches
; zero.
; For custom scripts, use the "wait" pseudo-opcode instead of this.
.MACRO setcounter1
.db $d7, \1
.ENDM
; Command $d8: see applyspeed
; Holds execution until the heart display on the HUD is fully updated after
; gaining or losing hearts.
.MACRO checkheartdisplayupdated
.db $d9
.ENDM
; Holds execution until the rupee display on the HUD is fully updated after
; gaining or losing rupees.
.MACRO checkrupeedisplayupdated
.db $da
.ENDM
; Holds execution until link and the interaction collide, ignoring their
; respective Z positions. It may be necessary to do "initcollisions" before
; this.
.MACRO checkcollidedwithlink_ignorez
.db $db
.ENDM
; $DC: no command
; Spawn an item at the interaction's coordinates.
; param1: High byte of ID (see constants/common/treasure.s)
; param2: Low byte of ID
.MACRO spawnitem
.db $dd
.if NARGS == 1
.db (\1)>>8, (\1)&$ff
.else
.db \1, \2
.endif
.ENDM
; Spawn an item at link's coordinates. In most cases this will cause link to
; grab it instantly.
;
; There are two ways you can use this command:
;
; - Option A: giveitem TREASURE_SWORD $01
; - Option B: giveitem TREASURE_OBJECT_SWORD_01
;
; Option A (2 parameters) specifies the treasure index and subid number manually.
;
; Option B (1 parameter) uses the TREASURE_OBJECT constant as defined in
; "data/{game}/treasureObjectData.s".
;
; param1: High byte of ID (see constants/common/treasure.s)
; param2: Low byte of ID
.MACRO giveitem
.db $de
.if NARGS == 1
.db (\1)>>8, (\1)&$ff
.else
.db \1, \2
.endif
.ENDM
; Jump if an item is obtained (see constants/common/treasure.s).
; param1: The item to check
; param2[16]: Where to jump to
.MACRO jumpifitemobtained
.db $df \1
.dw \2
.ENDM
; Call an assembly function in bank $15 at the specified address.
;
; param1: Address of the assembly to run (bank $15)
; param2[opt]: Value to set the 'a' and 'e' registers to before calling the asm
.MACRO asm15
.IF NARGS == 1
.db $e0
.dw \1
.ELSE
.db $e1
.dw \1
.db \2
.ENDIF
.ENDM
; Create a puff at this interaction's position. Script execution resumes next frame.
.MACRO createpuff
.db $e2
.ENDM
; Play the sound effect specified (see constants/common/music.s)
; param1: The sound effect to play
.MACRO playsound
.db $e3
.db \1
.ENDM
; Set the music (see constants/common/music.s)
; param1: The music to play.
.MACRO setmusic
.db $e4
.db \1
.ENDM
.MACRO resetmusic
.db $e4 $ff
.ENDM
; Set wDisabledObjects to the specified value.
; param1: The value to write to wDisabledObjects.
.MACRO setdisabledobjects
.db $e5
.db \1
.ENDM
; Spawn an enemy at this interaction's position.
; param1: The ID of the enemy to spawn (see constants/common/enemies.s)
; param2: The Subid of the enemy to spawn
.MACRO spawnenemyhere
.db $e6
.if NARGS == 1
.db (\1)>>8, (\1)&$ff
.else
.db \1, \2
.endif
.ENDM
; Set the tile on the map at the specified position to the specified value.
; param1: The position to change (YX)
; param2: The tile index to set it to
.MACRO settileat
.db $e7
.db \1, \2
.ENDM
; Set the tile at this interaction's position to the specified value.
; param1: The tile index to set it to
.MACRO settilehere
.db $e8
.db \1
.ENDM
; Save link's current position as the place to respawn after falling in a hole
; or things like that.
.MACRO updatelinkrespawnposition
.db $e9
.ENDM
; Shake the screen horizontally by setting wScreenShakeCounterX.
; param1: The value to set wScreenShakeCounterX to.
.MACRO shakescreen
.db $ea
.db \1
.ENDM
; Initialize the collisionRadiusY/X variables to $06 and add this object to
; wAButtonSensitiveObjectList, allowing you to use checkabutton.
;
; Equivalent to these two opcodes:
; setcollisionradii $06 $06
; makeabuttonsensitive
.MACRO initcollisions
.db $eb
.ENDM
; Moves an npc a set distance. Use the "setspeed" command prior to this.
; param1: Number of frames to move
.MACRO moveup
.db $ec, \1
.ENDM
.MACRO moveright
.db $ed, \1
.ENDM
.MACRO movedown
.db $ee, \1
.ENDM
.MACRO moveleft
.db $ef, \1
.ENDM
; Wait for a set number of frames by setting counter1. The parameter passed is not the
; amount of frames to wait, but an index for a table.
;
; For custom scripts, it's recommended to use "wait" instead of this.
;
; param1: Number of frames to wait. The parameter corresponds to these values:
; 0: 1 frame
; 1: 4 frames
; 2: 8 frames
; 3: 10 frames
; 4: 15 frames
; 5: 20 frames
; 6: 30 frames
; 7: 40 frames
; 8: 60 frames
; 9: 90 frames
; 10: 120 frames
; 11: 180 frames
; 12: 240 frames
.MACRO delay
.IF \1 > 12
.PRINTT "SCRIPT ERROR: delay takes a value from $00-$0c.\n"
.FAIL
.ENDIF
.IF \1 < 0
.PRINTT "SCRIPT ERROR: delay takes a value from $00-$0c.\n"
.FAIL
.ENDIF
.db $f0 + \1
.ENDM
; pseudo-ops
; Alternative to "delay"; takes a frame value as the parameter instead of the arbitrary
; lengths "delay" works with. Falls back to using "setcounter1" if it would take 2 bytes.
;
; param1: Number of frames to wait
.MACRO wait
.if \1 >= 256
.redefine M_RESULT (-1)
.rept 13 INDEX M_COUNT
m_get_delay_value M_COUNT
m_get_delay_index \1-M_DELAY_VALUE
.if M_DELAY_INDEX != -1
.redefine M_RESULT M_DELAY_VALUE
.endif
.endr
.if M_RESULT == -1
wait 240
wait \1-240
.else
wait M_RESULT
wait \1-M_RESULT
.endif
.else ; \1 < 256
m_get_delay_index \1
.if M_DELAY_INDEX != -1
delay M_DELAY_INDEX
.else
setcounter1 \1
.endif
.endif
.ENDM
; Helper macros for the above macro
.MACRO m_get_delay_value
.redefine M_DELAY_VALUE (-1)
.if \1 == 12
.redefine M_DELAY_VALUE 240
.endif
.if \1 == 11
.redefine M_DELAY_VALUE 180
.endif
.if \1 == 10
.redefine M_DELAY_VALUE 120
.endif
.if \1 == 9
.redefine M_DELAY_VALUE 90
.endif
.if \1 == 8
.redefine M_DELAY_VALUE 60
.endif
.if \1 == 7
.redefine M_DELAY_VALUE 40
.endif
.if \1 == 6
.redefine M_DELAY_VALUE 30
.endif
.if \1 == 5
.redefine M_DELAY_VALUE 20
.endif
.if \1 == 4
.redefine M_DELAY_VALUE 15
.endif
.if \1 == 3
.redefine M_DELAY_VALUE 10
.endif
.if \1 == 2
.redefine M_DELAY_VALUE 8
.endif
.if \1 == 1
.redefine M_DELAY_VALUE 4
.endif
.if \1 == 0
.redefine M_DELAY_VALUE 1
.endif
.ENDM
.MACRO m_get_delay_index
.redefine M_DELAY_INDEX (-1)
.if \1 == 240
.redefine M_DELAY_INDEX 12
.endif
.if \1 == 180
.redefine M_DELAY_INDEX 11
.endif
.if \1 == 120
.redefine M_DELAY_INDEX 10
.endif
.if \1 == 90
.redefine M_DELAY_INDEX 9
.endif
.if \1 == 60
.redefine M_DELAY_INDEX 8
.endif
.if \1 == 40
.redefine M_DELAY_INDEX 7
.endif
.if \1 == 30
.redefine M_DELAY_INDEX 6
.endif
.if \1 == 20
.redefine M_DELAY_INDEX 5