; NAME: Multiple Item Space Helper
; GAMES: MP2_USA
; EXECUTION: Direct

; This event is designed to shift the player's main item to a reserve
; slot if one is open when landing on an Item Space. This way, the
; player can land on an Item Space with an item in their main slot
; and still be able to play the Item Minigame, as long as they still
; have at least one open reserve slot.

ADDIU SP SP -32
SW RA 28(SP)

;===Check Multiple Item Slots Flag===
LUI T0 0x800F ; 0x800F0000
ORI T0 T0 0x8CE2 ; 0x800F8CE2, Multiple Item Slots Flag
LBU T0 0(T0) ; Load flag into T0
BEQZ T0 exit ; If flag is OFF, exit
NOP
; else, check item slots

;===Check Main Item Slot===
JAL GetPlayerStruct
LI A0 -1 ; Get current player struct at V0

LBU T0 0x19(V0) ; Load main item value into T0
LI T1 0xFF ; No item index
BEQ T0 T1 exit ; If main slot is open, exit
NOP
; else, main slot is full

;===Check Reserve Slots===
LBU T2 0x1E(V0) ; Load reserve item value #1 into T2
BEQL T2 T1 MoveItem ; If reseve slot is open, move item
LI T3 0x1E ; Empty slot offset at 0x1E

LBU T2 0x1F(V0) ; Load reserve item value #2 into T2
BNE T2 T1 exit ; If reserve slot isn't open, exit
LI T3 0x1F ; Empty slot offset at 0x1F

;===Move Item===
MoveItem:
ADDU T3 T3 V0 ; Add empty slot offset to player struct
SB T0 0(T3) ; Store main item into empty slot
SB T1 0x19(V0) ; Store no item into main slot

exit:
LW RA 28(SP)
JR RA
ADDIU SP SP 32