; NAME: Give Current Player Specific Item [NoItemIfFull] (Airsola™)
; GAMES: MP2_USA
; EXECUTION: Direct

;====================================================================
; IMPORTANT: This code is specifically designed to give the landing
;            or passing player an item of your choice. If they have
;            no space to carry the item, they will receive nothing.
;===================================================================

ADDIU SP SP -40
SW RA 36(SP)
SW S1 32(SP)
SW S2 28(SP)
SW S0 24(SP)



;FIND CURRENT PLAYER START-------------------------------------------
JAL GetCurrentPlayerIndex ; Current Player Index at V0
NOP

LI S0 0x0 ; Start with Player 1 
LUI S1 hi(p1_item)
ADDIU S1 S1 lo(p1_item) ; S1 is the address of Player 1's Item

START:
BEQ S0 V0 checkslots
NOP

ADDIU S0 S0 1 ; Add 1 to check the next Player
ADDIU S1 S1 0x34 ; This makes it load the next Player's Item
J START
NOP
;FIND CURRENT PLAYER END---------------------------------------------

;CHECK ITEM SLOTS START----------------------------------------------
checkslots:
ADDIU S0 R0 0xFF ; 0xFF = No Item Value
LBU S2 0(S1) ; S2 is the value of the item in the Item slot
BEQ S0 S2 itemmessage ; Go to itemmessage if the Item slot is empty
NOP
;CHECK ITEM SLOTS END------------------------------------------------

;NO ITEM MESSAGE DISPLAY START---------------------------------------
SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 -1 ; Character image (-1 for none)
LUI A1 hi(noitem)
ADDIU A1 A1 lo(noitem) ; This loads "noitem" into the Textbox
LI A2 0
JAL 0x80056368 ; ShowMessage???
LI A3 0

; The rest here perform the "wait for confirmation"
; and probably messagebox teardown.
JAL 0x80056144
NOP
JAL 0x80056168
NOP

J exit ; Player got no item, exit
NOP
;NO ITEM MESSAGE DISPLAY END-----------------------------------------

;GOT ITEM MESSAGE DISPLAY START--------------------------------------
itemmessage:
SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 -1 ; Character image (-1 for none)
LUI A1 hi(gotitem)
ADDIU A1 A1 lo(gotitem) ; This loads "gotitem" into the Textbox
LI A2 0
JAL 0x80056368 ; ShowMessage???
LI A3 0

; The rest here perform the "wait for confirmation"
; and probably messagebox teardown.
JAL 0x80056144
NOP
JAL 0x80056168
NOP

;GOT ITEM MESSAGE DISPLAY END----------------------------------------

;GIVE ITEM START-----------------------------------------------------
LI S0 0x00 ; S0 contains Mushroom Value
SB S0 0(S1) ; Place Mushroom on empty Item slot

; 00 Mushroom
; 01 Skeleton Key
; 02 Plunder Chest
; 03 Bowser Bomb
; 04 Dueling Glove
; 05 Warp Block
; 06 Golden Mushroom
; 07 Boo Bell
; 08 Bowser Suit
; 09 Magic Lamp
;GIVE ITEM END-------------------------------------------------------



exit:
LW S1 32(SP)
LW S2 28(SP)
LW S0 24(SP)
LW RA 36(SP)
JR RA
ADDIU SP SP 40

; .ascii is used to output Text. Anything surrounded by " will be 
; displayed in the message (Special characters are not included).
; For those, you must use .byte and the respective byte value.
; Bytes that change text color will change the color of everything
; that is written after it, until another color is used.

.align 16
gotitem:
.ascii "You got a"
.byte 0x07 ; Yellow Font
.ascii " Mushroom"
.byte 0x08 ; White Font
.byte 0xC2 ; Exclamation Mark (!)
.byte 0xFF,0 ; FF=Pause

.align 16
noitem:
.ascii "You have no space to hold this"
.byte 0x07 ; Yellow Font
.ascii " Mushroom"
.byte 0x08 ; White Font
.byte 0x85 ; Period (.)
.byte 0xFF,0 ; FF=Pause

; Here's a list of the most common bytes you'll need
; .byte 0x01 ; Black Font
; .byte 0x03 ; Red Font
; .byte 0x04 ; Purple Font
; .byte 0x05 ; Green Font
; .byte 0x06 ; Blue font
; .byte 0x07 ; Yellow Font
; .byte 0x08 ; White Font
; .byte 0x85 ; Period (.)
; .byte 0xC2 ; Exclamation Mark (!)
; .byte 0xC3 ; Question Mark (?)
; .byte 0x82 ; Comma (,)
; .byte 0x0A ; New Line (Writes Below)
; .byte 0x5C ; Apostrophe (')
; .byte 0x29 ; Coin icon
; .byte 0x3D ; - (minus)
; .byte 0x3E ; x (multiply)
; .byte 0xFF,0 ; FF=Pause

; If your message has an image, use this at the start of each line
; .byte 0x1A,0x1A,0x1A,0x1A ; Padding for picture