Flexible Collision Behavior command (0x12)


This is a custom behavior script command which detects the model ID used by an object and assigns the right collision pointer from a pointer list in the ROM.


Usage:

12 00 00 00 [07 00 10 00]    ;  Argument = segmented address to start of collision pointer list.

.ORG AnywhereYouWant

ADDIU SP, SP, 0xFFE0
SW RA, 0x0014 (SP)
LUI T6, 0x8036
LW T6, 0x1164 (T6)       ; Pointer to current behavior command
LW A0, 0x0004 (T6)       ; A0 = segmented base address for ROM pointer list

ADDIU T7, R0, 0x0001     ; initializes   for { i = 1; i < 0x100; i++ } loop
ADDIU AT, R0, 0x0100
 
Loop:
SLL T8, T7, 0x2          ; i * 4
LUI T4, 0x8033              
LW T4, 0xDDC4 (T4)       ; T4 = Pointer to beggining of Graphic Pointer list (generated from 0x22 command values)
ADDU T6, T4, T8          ; T6 = T4 + (i * 4)
LW T4, 0x0000 (T6)       ; T4 = value from T6
LUI T9, 0x8036
LW T9, 0x1160 (T9)       ; Pointer for RAM Object
LW T9, 0x0014 (T9)       ; Load value from 0x14 = Graphic Pointer

BEQ T4, T9, LoadCollision ; if ( Obj->0x14 == Graphic Pointer List->(i*4) )
NOP

BNE T7, AT, Loop
ADDIU T7, T7, 0x0001      ; i++;
 
BEQ R0, R0, End
NOP

LoadCollision:
JAL 0x80277F50           ; segmented_to_virtual (convert A0 into RAM pointer)
SW T8, 0x001C (SP)       ; store  T8 (i *4) in stack because the function above uses it
LW T8, 0x001C (SP)       ; restore  
ADDU T6, V0, T8          ; V0 = virtual memory value of A0. Adds (i * 4) to get the right collision pointer.
JAL 0x80277F50
LW A0, 0x0000 (T6)       ; A0 = load segmented collision pointer and convert it
LUI T8, 0x8036
LW T8, 0x1160 (T8)       ; Get RAM obect pointer again
SW V0, 0x0218 (T8)       ; store final virtual memory collision pointer in offset 0x218.

End:
LUI T9, 0x8036
LW T9, 0x1164 (T9)
ADDIU T0, T9, 0x0008     ; current behavior position += 8;
LUI AT, 0x8036
SW T0, 0x1164 (AT)
LW RA, 0x0014 (SP)
JR RA
ADDIU SP, SP, 0x0020

; Assembled

27BDFFE0
AFBF0014
3C0E8036
8DCE1164
8DC40004
240F0001
24010100
000FC080
3C0C8033
8D8CDDC4
01987021
8DCC0000
3C198036
8F391160
8F390014
132C0005
24000000
142FFFF5
25EF0001
1000000A
24000000
0C09DFD4
AFB8001C
8FB8001C
00587021
0C09DFD4
8DC40000
3C188036
8F181160
AF020218
3C198036
8F391164
27280008
3C018036
AC281164
8FBF0014
03E00008
27BD0020
Comments