; NAME: RandomShopItemsCurrentVer
; GAMES: MP3_USA
; EXECUTION: Direct

Main:
ADDIU SP SP -0x80
SW a0, 0x50 (sp)
SW a1, 0x54 (sp)
SW a2, 0x58 (sp)
SW a3, 0x5C (sp)
SW v0, 0x60 (sp)
SW RA, 0x64 (sp)
SW s1, 0x68 (sp)
SW v1, 0x6C (sp)
SW s0, 0x70 (sp)
SW t0, 0x74 (sp)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
JAL GetCurrentPlayerIndex
NOP
ADD a0, v0, r0 ;move v0 to a0
ORI a1, r0, 0x0007 ;animation to set, still animation
JAL SetBoardPlayerAnimation
ORI a2, r0, 0x0000
ORI a0, r0, 0xFFFF
LUI a1, hi(WelcomeString) ;where string is
ADDIU a1, a1, lo(WelcomeString)
ADDU A2 R0 R0
SW r0, 0x0010 (sp)
SW r0, 0x0014 (sp)
SW r0, 0x0018 (sp)
JAL 0x800EC8EC ; ShowMessage
ADDU A3 R0 R0
;
ORI a0, r0, 0x0002
JAL GetBasicPromptSelection
ORI a1, r0, 0x0000 ;AIs say yes to items
ADD s0, v0, r0 ;move v0 to s0
JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP
ADD v0, s0, r0 ;move s0 back to v0 (index chosen)
BNEZ v0, endofmain
NOP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
JAL Get3UniqueItems
NOP
LUI s0, hi(ItemIDsChosen)
JAL Sort3Numbers ;sort item IDs
ADDIU s0, s0, lo(ItemIDsChosen)
;
LUI s0, hi(ItemIDsChosen)
JAL FixBooBell
ADDIU s0, s0, lo(ItemIDsChosen)
;
JAL GetItem1Data
NOP
JAL GetItem2Data
NOP
JAL GetItem3Data
NOP
;LUI s0, hi(ShopItemCost)
;JAL Sort3Numbers ;sort item prices
;ADDIU s0, s0, lo(ShopItemCost)
;
;
JAL SetTextColors
NOP
LUI a0, hi(ShopItemCost)
ADDIU a0, a0, lo(ShopItemCost)
JAL CanPlayerAffordShopItems
LB a0, 0x0000 (a0) ;load price of minimum shop item
BEQZ v0, NotEnoughCoinsLabel
NOP
JAL FullItemsCheck
NOP
BEQZ v0, ItemsAreFull
NOP
LI a0, 0x800CD05A ;total turns
LI a1, 0x800CD05B ;current turn
LB t0, 0x0000 (a0)
LB t1, 0x0000 (a1)
BEQ t0, t1, IsLastTurn
NOP
SW r0, 0x0038 (sp) ;terminate with 0
LI a0, 0x800977C0
LUI a1, hi(ShopMenuFormatters2)
ADDIU a1, a1, lo(ShopMenuFormatters2)
JAL sprintf
NOP
MainShopTextbox:
ORI a0, r0, 0xFFFF
LI a1, 0x800977C0 ;where string is
ADDU A2 R0 R0
SW r0, 0x0010 (sp)
SW r0, 0x0014 (sp)
SW r0, 0x0018 (sp)
JAL 0x800EC8EC ; ShowMessage
ADDU A3 R0 R0
JAL DisableUnaffordableOptions
NOP
;test line below
ORI a0, r0, 0x0002
JAL GetBasicPromptSelection
ORI a1, r0, 0x0000 ;AIs choose index 0
ORI v1, r0, 0x0003 ;index of view map option
BEQ v0, v1, ViewMap
NOP
ORI v1, r0, 0x0004 ;index of back option
BEQ v0, v1, ChoseExit
NOP
;it's been 4 months, AIs always select option 0, deal with it
JAL TakeCoinsFromPlayer
ADD a0, v0, r0 ;move v0 to a0
JAL GetItemFromShopIndex
ADD a0, v0, r0 ;move v0 to a0
JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP
;0x0C ; Boo Repellant
;0x0E ; Magic Lamp
;0x0F ; Koopa Kard
;
;sprintf
;a0 		= pointer to store result to
;a1 		= pointer to formatters
;a2 		= string 1
;a3 		= string 2
;0x10 (sp) 	= string 3
;0x14 (sp) 	= string 4, etc.
endofmain:
LW a0, 0x50 (sp)
LW a1, 0x54 (sp)
LW a2, 0x58 (sp)
LW a3, 0x5C (sp)
LW v0, 0x60 (sp)
LW RA, 0x64 (sp)
LW s1, 0x68 (sp)
LW v1, 0x6C (sp)
LW s0, 0x70 (sp)
LW t0, 0x74 (sp)
LW t1, 0x78 (sp)
LW s2, 0x7C (sp)
JR RA
ADDIU SP SP 0x80
NotEnoughCoinsLabel:
ORI a0, r0, 0xFFFF
LUI a1, hi(NotEnoughCoinsString)
ADDIU a1, a1, lo(NotEnoughCoinsString)
ADDU A2 R0 R0
SW r0, 0x0010 (sp)
SW r0, 0x0014 (sp)
SW r0, 0x0018 (sp)
JAL 0x800EC8EC ; ShowMessage
ADDU A3 R0 R0
JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP
J endofmain
NOP
IsLastTurn:
ORI a0, r0, 0xFFFF
LUI a1, hi(LastTurnString)
ADDIU a1, a1, lo(LastTurnString)
ADDU A2 R0 R0
SW r0, 0x0010 (sp)
SW r0, 0x0014 (sp)
SW r0, 0x0018 (sp)
JAL 0x800EC8EC ; ShowMessage
ADDU A3 R0 R0
JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP
J endofmain
NOP
ItemsAreFull:
ORI a0, r0, 0xFFFF
LUI a1, hi(ItemsFullString)
ADDIU a1, a1, lo(ItemsFullString)
ADDU A2 R0 R0
SW r0, 0x0010 (sp)
SW r0, 0x0014 (sp)
SW r0, 0x0018 (sp)
JAL 0x800EC8EC ; ShowMessage
ADDU A3 R0 R0
JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP
J endofmain
NOP
ViewMap:
JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP
JAL ViewBoardMap
NOP
J MainShopTextbox
NOP
ChoseExit:
JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP
J endofmain
NOP


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.align 0x10
ShopMenuFormatters2:
.byte 0x0B ; Start the message
.ascii "Which item would you like to purchase"
.byte 0xC3 ;question mark
.byte 0x0A ;\n
.byte 0x0A ;\n
;
.ascii "%s" ;font color
.byte 0x0E, 0x0E, ;Tab x2
.byte 0x0C ;start option
.ascii "%s" ;Item 1 String
.ascii "%s" ;specific item indentation
.byte 0x08 ; White Font
.byte 0x29 ;coin icon
.byte 0x3E ;x after coin icon
.ascii "%s";Item 1 Cost
.byte 0x0D ; End option
.byte 0x0A ;\n
;
.ascii "%s" ;font color
.byte 0x0E, 0x0E ;Tab x2
.byte 0x0C ;start option
.ascii "%s" ;Item 2 String
.ascii "%s" ;specific item indentation
.byte 0x08 ; White Font
.byte 0x29 ;coin icon
.byte 0x3E ;x after coin icon
.ascii "%s" ;Item 2 Cost
.byte 0x0D ; End option
.byte 0x0A ;\n
;
.ascii "%s" ;font color
.byte 0x0E, 0x0E ;Tab x2
.byte 0x0C ;start option
.ascii "%s" ;Item 3 String
.ascii "%s" ;specific item indentation
.byte 0x08 ; White Font
.byte 0x29 ;coin icon
.byte 0x3E ;x after coin icon
.ascii "%s" ;Item 3 Cost
.byte 0x0D ; End option
.byte 0x0A ;\n
;
.byte 0x08 ;white font
.byte 0x0E, 0x0E ;Tab x2
.byte 0x0C ;start option
.ascii "View Map"
.byte 0x0D ;End option
.byte 0x0A ;\n
;
.byte 0x08 ;white font
.byte 0x0E, 0x0E ;Tab x2
.byte 0x0C ;start option
.ascii "Exit"
.byte 0x0D ;End option
;
.byte 0x00 ;end of text box
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


.align 0x10
ItemsEnum:
.byte 0x00 ; Mushroom
.byte 0x01 ; Skeleton Key
.byte 0x02 ; Poison Mushroom
.byte 0x03 ; Reverse Mushroom
.byte 0x04 ; Cellular Shopper
.byte 0x05 ; Warp Block
.byte 0x06 ; Plunder Chest
.byte 0x07 ; Bowser Phone
.byte 0x08 ; Dueling Glove
.byte 0x09 ; Lucky Lamp
.byte 0x0A ; Golden Mushroom
.byte 0x0B ; Boo Bell
.byte 0x0C ; Boo Repellant
.byte 0x0D ; Bowser Suit
.byte 0x0E ; Magic Lamp
.byte 0x0F ; Koopa Kard
.byte 0x10 ; Barter Box
.byte 0x11 ; Lucky Charm
.byte 0x12 ; Wacky Watch


.align 0x10
ItemChances:
.byte 0x0B ; Mushroom (00-0B) 10%
.byte 0x15 ; Skeleton Key (0C-14) 10%
.byte 0x1B ; Poison Mushroom 6%
.byte 0x21 ; Reverse Mushroom 6%
.byte 0x27 ; Cellular Shopper 6%
.byte 0x2D ; Warp Block 6%
.byte 0x33 ; Plunder Chest 6%
.byte 0x39 ; Bowser Phone 6%
.byte 0x3F ; Dueling Glove 6%
.byte 0x45 ; Lucky Lamp 6%
.byte 0x4B ; Golden Mushroom 6%
.byte 0x51 ; Boo Bell 6%
.byte 0x59 ; Boo Repellant 8%
.byte 0x5F ; Bowser Suit 6%
.byte 0x64 ; Magic Lamp 5%
.byte 0x64 ; Koopa Kard
.byte 0x64 ; Barter Box
.byte 0x64 ; Lucky Charm
.byte 0x64 ; Wacky Watch


.align 0x10
ItemCostsInts:
.byte 0x05 ; Mushroom
.byte 0x00
.byte 0x05 ; Skeleton Key
.byte 0x00
.byte 0x05 ; Poison Mushroom
.byte 0x00
.byte 0x05 ; Reverse Mushroom
.byte 0x00
.byte 0x05 ; Cellular Shopper
.byte 0x00
.byte 0x05 ; Warp Block
.byte 0x00
.byte 0x0A ; Plunder Chest
.byte 0x00
.byte 0x0A ; Bowser Phone
.byte 0x00
.byte 0x0A ; Dueling Glove
.byte 0x00
.byte 0x0A ; Lucky Lamp
.byte 0x00
.byte 0x0A ; Golden Mushroom
.byte 0x00
.byte 0x0F ; Boo Bell
.byte 0x00
.byte 0x0A ; Boo Repellant
.byte 0x00
.byte 0x0A ; Bowser Suit
.byte 0x00
.byte 0x14 ; Magic Lamp
.byte 0x00
.byte 0x32 ; Koopa Kard
.byte 0x00
.byte 0x32 ; Barter Box
.byte 0x00
.byte 0x32 ; Lucky Charm
.byte 0x00
.byte 0x32 ; Wacky Watch
.byte 0x00


.align 0x10
ShopItemCost:
.byte 0xFF ;Item 1
.byte 0xFF ;Item 2
.byte 0xFF ;Item 3


.align 0x10
ItemCostsStrings:
.asciiz " 5"  ; Mushroom
.asciiz " 5"  ; Skeleton Key
.asciiz " 5"  ; Poison Mushroom
.asciiz " 5"  ; Reverse Mushroom
.asciiz " 5"  ; Cellular Shopper
.asciiz " 5"  ; Warp Block
.asciiz "10" ; Plunder Chest
.asciiz "10" ; Bowser Phone
.asciiz "10" ; Dueling Glove
.asciiz "10" ; Lucky Lamp
.asciiz "10" ; Golden Mushroom
.asciiz "15" ; Boo Bell
.asciiz "10" ; Boo Repellant
.asciiz "10" ; Bowser Suit
.asciiz "20" ; Magic Lamp
.asciiz "50" ; Koopa Kard
.asciiz "50" ; Barter Box
.asciiz "50" ; Lucky Charm
.asciiz "50" ; Wacky Watch


.align 0x08
IndentationAfterNameOfItem:
.byte 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x00 	;Mushroom, 0x06 \t
.align 0x08
.byte 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x00 		;Skeleton Key, 0x05 \t
.align 0x08
.byte 0x0E, 0x0E, 0x0E, 0x00 					;Poison Mushroom, 0x03 \t
.align 0x08
.byte 0x0E, 0x0E, 0x00 							;Reverse Mushroom, 0x02 \t
.align 0x08
.byte 0x0E, 0x0E, 0x0E, 0x0E, 0x00 				;Cellular Shopper, 0x04 \t
.align 0x08
.byte 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x00 	;Warp Block, 0x06 \t
.align 0x08
.byte 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x00 		;Plunder Chest, 0x05 \t
.align 0x08
.byte 0x0E, 0x0E, 0x0E, 0x0E, 0x00 				;Bowser Phone, 0x04 \t
.align 0x08
.byte 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x00 		;Dueling Glove, 0x05 \t
.align 0x08
.byte 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x00 		;Lucky Lamp, 0x05 \t
.align 0x08
.byte 0x0E, 0x0E, 0x0E, 0x00 					;Golden Mushroom, 0x03 \t
.align 0x08
.byte 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x00 	;Boo Bell, 0x07 \t
.align 0x08
.byte 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x00 		;Boo Repellant, 0x05 \t
.align 0x08
.byte 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x00 		;Bowser Suit, 0x05 \t
.align 0x08
.byte 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x00 	;Magic Lamp, 0x06 \t
.align 0x08
.byte 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x00 	;Koopa Kard, 0x06 \t
.align 0x08
.byte 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x00 	;Barter Box, 0x06 \t
.align 0x08
.byte 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x00 		;Lucky Charm, 0x05 \t
.align 0x08
.byte 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x00 		;Wacky Watch, 0x05 \t


.align 0x20
ItemStrings:
.asciiz "Mushroom"
.align 0x20
.asciiz "Skeleton Key"
.align 0x20
.asciiz "Poison Mushroom"
.align 0x20
.asciiz "Reverse Mushroom"
.align 0x20
.asciiz "Cellular Shopper"
.align 0x20
.asciiz "Warp Block"
.align 0x20
.asciiz "Plunder Chest"
.align 0x20
.asciiz "Bowser Phone"
.align 0x20
.asciiz "Dueling Glove"
.align 0x20
.asciiz "Lucky Lamp"
.align 0x20
.asciiz "Golden Mushroom"
.align 0x20
.asciiz "Boo Bell"
.align 0x20
.asciiz "Boo Repellant"
.align 0x20
.asciiz "Bowser Suit"
.align 0x20
.asciiz "Magic Lamp"
.align 0x20
.asciiz "Koopa Kard"
.align 0x20
.asciiz "Barter Box"
.align 0x20
.asciiz "Lucky Charm"
.align 0x20
.asciiz "Wacky Watch"


.align 0x10
NotEnoughCoinsString:
.ascii "You do not have enough coins"
.byte 0x0A ;\n
.ascii "to purchase an item"
.byte 0x85 ;period
.byte 0xFF
.byte 0x00


.align 0x10
LastTurnString:
.ascii "It"
.byte 0x5C ;apostrophe
.ascii "s the last turn"
.byte 0x82 ;comma
.ascii " so you"
.byte 0x0A ;\n
.ascii "cannot purchase an item"
.byte 0x85 ;period
.byte 0xFF ;pause
.byte 0x00 ;terminate string


.align 0x10
ItemsFullString:
.ascii "Your items are full"
.byte 0x85 ;comma
.ascii " Visit again"
.byte 0x0A
.ascii "after you use some items"
.byte 0x85 ;period
.byte 0xFF
.byte 0x00


.align 0x10
WelcomeString:
.byte 0x0E, 0x0E
.ascii "Welcome to the shop"
.byte 0xC2 ;exclamation mark
.byte 0x0A ;\n
.byte 0x0E, 0x0E
.ascii "Would you like to purchase an item"
.byte 0xC3 ;question mark
.byte 0x0A ;\n
.byte 0x0E, 0x0E
.byte 0x0C ;start option 0
.ascii "Yes"
.byte 0x0D ;end option 0
.byte 0x0A ;\n
.byte 0x0E, 0x0E
.byte 0x0C ;start option 1
.ascii "No"
.byte 0x0D ;end option 1
.byte 0x00 ;terminate string


.align 0x10
ItemIDsChosen: ;store here and check to prevent duplicate items
.byte 0xFF ;placeholder
.byte 0xFF ;placeholder
.byte 0xFF ;placeholder


.align 0x10
ConvertedStrings: ;allocate space for the converted strings
.fill 1024 ; insert 1024 bytes of 0x00

.align 0x10
ItemColors:
.byte 0xFF ;placeholder
.byte 0x00
.byte 0xFF ;placeholder
.byte 0x00
.byte 0xFF ;placeholder
.byte 0x00


.align 0x10
GetItemStringPtr: ;takes arg a0, ItemID
ADDIU sp, sp, -0x04
SW t0, 0x0000 (sp)
LUI t0, hi(ItemStrings)
ADDIU t0, t0, lo(ItemStrings)
SLL a0, a0, 0x0005 ;multiply by 0x20 (32) because our strings are aligned by 0x20
ADD v0, t0, a0 ;returns pointer to ItemID's string
LW t0, 0x0000 (sp)
JR RA
ADDIU sp, sp, 0x04


GetCoinAmountInt: ;takes arg a0, ItemID, returns on v0
ADDIU sp, sp, -0x04
SW t0, 0x0000 (sp)
LUI t0, hi(ItemCostsInts)
ADDIU t0, t0, lo(ItemCostsInts)
SLL a0, a0, 0x0001 ; multiply by 2 to get offset
ADD v0, a0, t0, ;returns pointer to item cost
LB v0, 0x0000 (v0) ;returns item cost amount
LW t0, 0x0000 (sp)
JR RA
ADDIU sp, sp, 0x04


GetItemStringCost: ;takes arg a0, returns on v0
ADDIU sp, sp, -0x0C
SW t0, 0x0004 (sp)
SW ra, 0x0008 (sp)
LUI t0, hi(ItemCostsStrings)
ADDIU t0, t0, lo(ItemCostsStrings)
;
ORI t1, r0, 0x0003
MULT a0, t1 ;Item ID * 3
MFLO a0
;
;SLL a0, a0, 0x0001 ;shift 1 bit to the left (ItemID * 2)
ADD v0, a0, t0 ;ItemCostStrings(ptr) + (ItemID * 2) = pointer to item cost ascii
LW t0, 0x0004 (sp)
LW ra, 0x0008 (sp)
JR RA
ADDIU sp, sp, 0x0C


GetItemIndentation: ; takes arg a0 (item ID)
ADDIU sp, sp, -0x10
SW t0, 0x0000 (sp)
SW t1, 0x0004 (sp)
SW t2, 0x0008 (sp)
LUI t0, hi(IndentationAfterNameOfItem)
ADDIU t0, t0, lo(IndentationAfterNameOfItem)
ORI t1, r0, 0x0008
MULT t1, a0
MFLO a0
ADD v0, a0, t0 ;add offset + pointer of indentation
;pointer to indentation
LW t0, 0x0000 (sp)
LW t1, 0x0004 (sp)
LW t2, 0x0008 (sp)
JR RA
ADDIU sp, sp, 0x10


GetRandOutOf100: ;returns on v0
ADDIU          SP, SP, -0x20
SW             RA, 0x0014 (SP)
SW             S0, 0x0010 (SP)
SDC1           F20, 0x0018 (SP)
JAL            GetRandomByte
MOV.S          F20, F12
JAL            GetRandomByte
ADDU           S0, V0, R0
ANDI           S0, S0, 0x00FF
SLL            S0, S0, 8
ANDI           V0, V0, 0x00FF
OR             V0, V0, S0
MTC1           V0, F0
NOP            
CVT.S.W        F0, F0
LUI            AT, 0x4780
MTC1           AT, F2
NOP            
DIV.S          F0, F0, F2
MUL.S          F0, F0, F20
TRUNC.W.S      F2, F0
MFC1           V0, F2
LW             RA, 0x0014 (SP)
LW             S0, 0x0010 (SP)
LDC1           F20, 0x0018 (SP)
JR             RA
ADDIU          SP, SP, 0x20


RollForRandomItem:
ADDIU sp, sp, -0x30
SW at, 0x0010 (sp)
SWC1 f12, 0x0014 (sp)
SW s0, 0x0018 (sp)
SW s1, 0x001C (sp)
SW a0, 0x0020 (sp)
SW a1, 0x0024 (sp)
SW t0, 0x0028 (sp)
SW ra, 0x002C (sp)
;
LUI	AT, 0x42C8
MTC1	AT, F12
JAL GetRandOutOf100
ADDU s1, r0, r0
ADD a0, v0, r0 ;move v0 to a0
LUI s0, hi(ItemChances)
ADDIU s0, s0, lo(ItemChances)
ORI v0, r0, 0x0000 ;set v0 to 0 for upcoming loop
RandItemLoop:
;determine which item to give
LB a1, 0x0000 (s0) ;load item chance 1
SLT t0, a0, a1 ;if random byte returned is less than itemchance
BNE t0, r0, loopexit ;if a0 is not smaller than a1
NOP
ADDIU v0, v0, 0x0001
BEQ r0, r0, RandItemLoop
ADDIU s0, s0, 0x0001
;
loopexit:
LW at, 0x0010 (sp)
LWC1 f12, 0x0014 (sp)
LW s0, 0x0018 (sp)
LW s1, 0x001C (sp)
LW a0, 0x0020 (sp)
LW a1, 0x0024 (sp)
LW t0, 0x0028 (sp)
LW ra, 0x002C (sp)
JR RA
ADDIU sp, sp, 0x30


Sort3Numbers: ;provide s0 (where to read numbers from)
ADDIU sp, sp, -0x30
SW t0, 0x0010 (sp)
SW t1, 0x0014 (sp)
SW t2, 0x0018 (sp)
SW v0, 0x001C (sp)
SW s0, 0x0020 (sp)
SW ra, 0x0024 (sp)
;LUI s0, hi(ItemIDsChosen)
;ADDIU s0, s0, lo(ItemIDsChosen)
LB t0, 0x0000 (s0) ;load item a
LB t1, 0x0001 (s0) ;load item b
LB t2, 0x0002 (s0) ;load item c
SLT v0, t2, t0 ;if c is less than a, v0 = 1
BNE v0, r0, swapCandA
NOP
afterCandA:
LB t0, 0x0000 (s0)
LB t1, 0x0001 (s0)
LB t2, 0x0002 (s0)
SLT v0, t1, t0, ;if b is less than a
BNE v0, r0, swapAandB
NOP
afterAandB:
LB t0, 0x0000 (s0)
LB t1, 0x0001 (s0)
LB t2, 0x0002 (s0)
SLT v0, t2, t1 ;if c is less than b
BNE v0, r0, swapBandC
NOP
afterBandC:
LW t0, 0x0010 (sp)
LW t1, 0x0014 (sp)
LW t2, 0x0018 (sp)
LW v0, 0x001C (sp)
LW s0, 0x0020 (sp)
LW ra, 0x0024 (sp)
JR RA
ADDIU sp, sp, 0x30
swapCandA:
SB t0, 0x0002 (s0)
BEQ r0, r0, afterCandA
SB t2, 0x0000 (s0)
swapAandB:
SB t0, 0x0001 (s0)
BEQ r0, r0, afterAandB
SB t1, 0x0000 (s0)
swapBandC:
SB t1, 0x0002 (s0)
BEQ r0, r0, afterBandC
SB t2, 0x0001 (s0)


GetCurrentPlayerCoinCount:
ADDIU sp, sp, -0x20
SW t0, 0x0010 (sp)
SW t1, 0x0014 (sp)
SW ra, 0x0018 (sp)
JAL GetCurrentPlayerIndex
NOP
ADD a0, v0, r0 ;move v0 to a0
JAL GetPlayerStruct
NOP
LH v0, 0x000A (v0) ;load current player's coins into v0
LW t0, 0x0010 (sp)
LW t1, 0x0014 (sp)
LW ra, 0x0018 (sp)
JR RA
ADDIU sp, sp, 0x20


Get3UniqueItems:
ADDIU sp, sp, -0x18
SW ra, 0x0010 (sp)
JAL RollForRandomItem
NOP
LUI t0, hi(ItemIDsChosen)
ADDIU t0, t0, lo(ItemIDsChosen)
SB v0, 0x0000 (t0) ;store itemID to item table to generate
RollAgain1:
JAL RollForRandomItem
NOP
LUI t0, hi(ItemIDsChosen)
ADDIU t0, t0, lo(ItemIDsChosen)
LB v1, 0x0000 (t0)
BEQ v0, v1, RollAgain1
NOP
SB v0, 0x0001 (t0)
RollAgain2:
JAL RollForRandomItem
NOP
LUI t0, hi(ItemIDsChosen)
ADDIU t0, t0, lo(ItemIDsChosen)
LB v1, 0x0001 (t0)
BEQ v0, v1, RollAgain2
NOP
LB v1, 0x0000 (t0)
BEQ v0, v1, RollAgain2
NOP
SB v0, 0x0002 (t0)
LW ra, 0x0010 (sp)
JR RA
ADDIU sp, sp, 0x18


GetItem1Data:
ADDIU sp, sp, -0x18
SW ra, 0x0010 (sp)
LB a0, 0x0000 (t0) ;load item 1 from
JAL GetItemStringPtr ;Mushroom string
NOP
LUI a2, hi(ItemColors)
ADDIU a2, a2, lo(ItemColors)
LB a0, 0x0000 (t0) ;load item 1 from
ADD a3, r0, v0 ;move v0 to a2 (arg 1 for sprintf)
JAL GetItemIndentation
NOP
SW v0, 0x0028 (sp) ;move v0 to a3
LB a0, 0x0000 (t0) ;load item 1
JAL GetItemStringCost
NOP
SW v0, 0x002C (sp)
LB a0, 0x0000 (t0) ;load item 1
JAL GetCoinAmountInt
NOP
LUI ra, hi(ShopItemCost)
ADDIU ra, ra, lo(ShopItemCost) ;use ra since it gets popped very soon after
SB v0, 0x0000 (ra)
LW ra, 0x0010 (sp)
JR RA
ADDIU sp, sp, 0x18


GetItem2Data:
ADDIU sp, sp, -0x18
SW ra, 0x0010 (sp)
LB a0, 0x0001 (t0) ;load item 2
LUI v0, hi(ItemColors)
ADDIU v0, v0, lo(ItemColors)
ADDIU v0, v0, 0x0002
SW v0, 0x0030 (sp) ;store font color
JAL GetItemStringPtr
NOP
SW v0, 0x0034 (sp)
LB a0, 0x0001 (t0) ;load item 2
JAL GetItemIndentation
NOP
SW v0, 0x0038 (sp)
LB a0, 0x0001 (t0) ;load item 2
JAL GetItemStringCost
NOP
SW v0, 0x003C (sp)
LB a0, 0x0001 (t0) ;load item 2
JAL GetCoinAmountInt
NOP
LUI ra, hi(ShopItemCost)
ADDIU ra, ra, lo(ShopItemCost) ;use ra since it gets popped very soon after
SB v0, 0x0001 (ra)
LW ra, 0x0010 (sp)
JR RA
ADDIU sp, sp, 0x18


GetItem3Data:
ADDIU sp, sp, -0x18
SW ra, 0x0010 (sp)
LB a0, 0x0002 (t0) ;load item 3
LUI v0, hi(ItemColors)
ADDIU v0, v0, lo(ItemColors)
ADDIU v0, v0, 0x0004
SW v0, 0x0040 (sp)
JAL GetItemStringPtr
NOP
SW v0, 0x0044 (sp)
LB a0, 0x0002 (t0) ;load item 3
JAL GetItemIndentation
NOP
SW v0, 0x0048 (sp)
LB a0, 0x0002 (t0) ;load item 3
JAL GetItemStringCost
NOP
SW v0, 0x004C (sp)
LB a0, 0x0002 (t0) ;load item 3
JAL GetCoinAmountInt
NOP
LUI ra, hi(ShopItemCost)
ADDIU ra, ra, lo(ShopItemCost) ;use ra since it gets popped very soon after
SB v0, 0x0002 (ra)
LW ra, 0x0010 (sp)
JR RA
ADDIU sp, sp, 0x18


GetItemFromShopIndex: ;a0 = index of item chosen
ADDIU sp, sp, -0x30
SW s0, 0x0010 (sp)
SW a0, 0x0014 (sp)
SW a1, 0x0018 (sp)
SW v0, 0x001C (sp)
SW ra, 0x0020 (sp)
LUI s0, hi(ItemIDsChosen)
ADDIU s0, s0, lo(ItemIDsChosen) ;load ItemIDsFromShop
ADD s0, a0, s0 ;add offset of item + pointer to item list
JAL GetCurrentPlayerIndex
NOP
ADD a0, v0, r0, ;move v0 to a0 (index of current player)
LB a1, 0x0000 (s0) ;load item chosen
JAL GivePlayerItem
NOP
LW s0, 0x0010 (sp)
LW a0, 0x0014 (sp)
LW a1, 0x0018 (sp)
LW v0, 0x001C (sp)
LW ra, 0x0020 (sp)
JR RA
ADDIU sp, sp, 0x30


FixBooBell: ;boo bell breaks logic because of its price
;therefore, we need to move it to the correct location
;Boo Bell is ID 0x0B, and it needs to go after 0x0D
;s0 currently holds a pointer to ItemIDsChosen
ADDIU sp, sp, -0x40
SW t0, 0x0010 (sp)
SW t1, 0x0014 (sp)
SW t2, 0x0018 (sp)
SW t3, 0x001C (sp)
LB t0, 0x0000 (s0);item 1
LB t1, 0x0001 (s0);item 2
LB t2, 0x0002 (s0);item 3
ORI t3, r0, 0x000B ;item ID of Boo Bell
;locate the Boo Bell
BEQ t0, t3, Item1IsBooBell
NOP
BEQ t1, t3, Item2IsBooBell
NOP
BEQ t2, t3, ExitBooBellFunc ;if item 3 is boo bell, it's at the end already
NOP
;No items are boo bell
ExitBooBellFunc:
SB t0, 0x0000 (s0)
SB t1, 0x0001 (s0)
SB t2, 0x0002 (s0)
;
LW t0, 0x0010 (sp)
LW t1, 0x0014 (sp)
LW t2, 0x0018 (sp)
LW t3, 0x001C (sp)
JR RA
ADDIU sp, sp, 0x40
Item1IsBooBell:
SLTI v0, t1, 0x000E ;if item 2 is larger than 0E, do nothing
BEQ v0, r0, ExitBooBellFunc
NOP
LB t0, 0x0001 (s0)
LB t1, 0x0000 (s0)
;we swapped item 1 and 2
Item2IsBooBell:
SLTI v0, t2, 0x000E ;if item 3 is larger than 0E, do nothing
BEQ v0, r0, ExitBooBellFunc
NOP
LB t2, 0x0001 (s0)
J ExitBooBellFunc
LB t1, 0x0002 (s0) ;we swapped the items


GivePlayerItem: ;takes arg a0 player index; a1 item to give
ADDIU sp, sp, -0x50
SW t0, 0x0030 (sp)
SW t1, 0x0034 (sp)
SW v0, 0x0038 (sp)
SW a0, 0x003C (sp)
SW a1, 0x0040 (sp)
SW ra, 0x0044 (sp)
JAL PlayerHasEmptyItemSlot
NOP
SW v0, 0x004C (sp) ;store empty slot index to 0x4C of sp to pull later
;Returns 0xFF if no open slots
LUI t0, 0xFFFF
ORI t0, t0, 0xFFFF
BEQ t0, v0, MaxItems
NOP
;
LI t0, 0x800D1108 ;first player struct
ORI t1, r0, 0x0038 ;length of player structs
MULT t1, a0 ;calculate offset from first player struct
MFLO t1 ;offset from first struct amount
ADD t1, t1, t0 ;add player struct + offset
;t1 now holds pointer to current player struct
ADDIU t1, t1, 0x0018 ;offset for items from player struct
;t1 now holds pointer to current player items
LW v0, 0x004C (sp) ;current empty slot for items index
ADD t1, v0, t1 ;add current player struct + empty slot index
LW a1, 0x0040 (sp) ;load item ID from stack to a1
SB a1, 0x0000 (t1) ;store item to current player
MaxItems:
LW t0, 0x0030 (sp)
LW t1, 0x0034 (sp)
LW v0, 0x0038 (sp)
LW a0, 0x003C (sp)
LW a1, 0x0040 (sp)
LW ra, 0x0044 (sp)
JR RA
ADDIU sp, sp, 0x50


CanPlayerAffordShopItems: ;takes arg a0, coin amount to check aginast
ADDIU sp, sp, -0x20
SW a0, 0x0010 (sp)
SW a1, 0x0014 (sp)
SW s0, 0x0018 (sp)
SW ra, 0x001C (sp)
JAL GetCurrentPlayerIndex
ADD s0, r0, a0 ;move a0 to t1 for later
ADD a0, v0, r0 ;move player index to a0
JAL PlayerHasCoins
ADD a1, s0, r0 ;move coin minimum to a1
;v0 now holds 0 if cant afford, 1 if player can
LW a0, 0x0010 (sp)
LW a1, 0x0014 (sp)
LW s0, 0x0018 (sp)
LW ra, 0x001C (sp)
JR RA
ADDIU sp, sp, 0x20


DisableUnaffordableOptions:
ADDIU sp, sp, -0x38
SW t0, 0x0010 (sp)
SW t1, 0x0014 (sp)
SW s0, 0x0018 (sp)
SW s1, 0x001C (sp)
SW s2, 0x0020 (sp)
SW a0, 0x0024 (sp)
SW a1, 0x0028 (sp)
SW v0, 0x002C (sp)
SW ra, 0x0030 (sp)
LUI a0, 0xFFFF
JAL GetPlayerStruct
ORI a0, a0, 0xFFFF
LH s1, 0x000A (v0) ;load current player coin count to s1
LUI s0, hi(ShopItemCost)
ADDIU s0, s0, lo(ShopItemCost)
ORI s2, r0, 0x0000 ;counter (used for index option to disable)
;
DisableOptionsLoop:
LB t0, 0x0000 (s0) ;load item cost
SLT t1, s1, t0 ;if player coin amount is less than item cost
;t1 = 0 can afford current item
;t1 = 1, cant afford current item
BNEZ t1, DisableOptionsPromptLoop
NOP
ADDIU s0, s0, 0x0001
ADDIU s2, s2, 0x0001
SLTI t0, s2, 0x0003
BNEZ t0, DisableOptionsLoop
NOP
J EndOfDisable
NOP
;Disable current options and options after, hardcoded as 0x03
DisableOptionsPromptLoop:
ORI a0, r0, 0x0002
JAL DisablePromptOption
ADD a1, s2, r0 ;move current option index to a1
ADDIU s2, s2, 0x0001
SLTI t0, s2, 0x0003 ;if current index is less than 0x03
BEQZ t0, EndOfDisable
NOP
J DisableOptionsPromptLoop
NOP
EndOfDisable:
LW t0, 0x0010 (sp)
LW t1, 0x0014 (sp)
LW s0, 0x0018 (sp)
LW s1, 0x001C (sp)
LW s2, 0x0020 (sp)
LW a0, 0x0024 (sp)
LW a1, 0x0028 (sp)
LW v0, 0x002C (sp)
LW ra, 0x0030 (sp)
JR RA
ADDIU sp, sp, 0x38


SetTextColors: ;set color of item string depending on if
;player can afford the item or not
ADDIU sp, sp, -0x40
SW s0, 0x0010 (sp)
SW s1, 0x0014 (sp)
SW s2, 0x0018 (sp)
SW s3, 0x001C (sp)
SW s4, 0x0020 (sp)
SW a0, 0x0024 (sp)
SW t0, 0x0028 (sp)
SW t1, 0x002C (sp)
SW t2, 0x0030 (sp)
SW ra, 0x0034 (sp)
LUI s0, hi(ShopItemCost)
ADDIU s0, s0, lo(ShopItemCost)
LUI s1, hi(ItemColors)
ADDIU s1, s1, lo(ItemColors)
ORI s2, r0, 0x0001 ;black font
ORI s3, r0, 0x0006 ;cyan font
ORI s4, r0, 0x0000 ;counter
;
LUI a0, 0xFFFF
JAL GetPlayerStruct
ORI a0, a0, 0xFFFF
LH t0, 0x000A (v0) ;coin amount
TextColorLoop:
LB t1, 0x0000 (s0) ;ShopItemCost
ADDIU t1, t1, 0xFFFF
SLT t2, t1, t0 ;if ShopItemCost < coin amount player has
BNEZ t2, SetColorBlue
NOP
SetColorBlack:
J AfterColor
SB s2, 0x0000 (s1) ;set color to black
;
SetColorBlue:
SB s3, 0x0000 (s1) ;set color to blue
;
AfterColor:
ADDIU s0, s0, 0x0001 ;increment ShopItemCost ptr
ADDIU s1, s1, 0x0002 ;increment ItemColors ptr
ADDIU s4, s4, 0x0001 ;increment counter
SLTI t3, s4, 0x0003
BNEZ t3, TextColorLoop
NOP
LW s0, 0x0010 (sp)
LW s1, 0x0014 (sp)
LW s2, 0x0018 (sp)
LW s3, 0x001C (sp)
LW s4, 0x0020 (sp)
LW a0, 0x0024 (sp)
LW t0, 0x0028 (sp)
LW t1, 0x002C (sp)
LW t2, 0x0030 (sp)
LW ra, 0x0034 (sp)
JR RA
ADDIU sp, sp, 0x40


TakeCoinsFromPlayer: ;a0 = index of chosen item
ADDIU sp, sp, -0x30
SW a0, 0x0010 (sp)
SW a1, 0x0014 (sp)
SW t0, 0x0018 (sp)
SW ra, 0x001C (sp)
SW s0, 0x0020 (sp)
SW s1, 0x0024 (sp)
SW v0, 0x0028 (sp)
LUI s0, hi(ShopItemCost)
ADDIU s0, s0, lo(ShopItemCost)
ADD s0, a0, s0 ;add index + ShopItemCost ptr
LB s0, 0x0000 (s0)
LUI t0, 0xFFFF
ORI t0, t0, 0xFFFF
XOR a1, t0, s0 ;flip coins to take from positive to negative
ADDIU a1, a1, 0x0001
JAL GetCurrentPlayerIndex
NOP
ADD a0, v0, r0 ;move player index to a0
JAL AdjustPlayerCoinsGradual
NOP
LW a0, 0x0010 (sp)
LW a1, 0x0014 (sp)
LW t0, 0x0018 (sp)
LW ra, 0x001C (sp)
LW s0, 0x0020 (sp)
LW s1, 0x0024 (sp)
LW v0, 0x0028 (sp)
JR RA
ADDIU sp, sp, 0x30


FullItemsCheck: ;returns 0 if items are full, 1 if not
ADDIU sp, sp, -0x20
SW a0, 0x0010 (sp)
SW t0, 0x0014 (sp)
SW ra, 0x0018 (sp)
LUI a0, 0xFFFF
JAL GetPlayerStruct
ORI a0, a0, 0xFFFF
LBU t0, 0x001A (v0) ;load current player item slot 3
ORI t1, r0, 0x00FF
BEQ t0, t1, ItemsNotFull
NOP
ORI v0, r0, 0x0000 ;items are full
ItemCheckExit:
LW a0, 0x0010 (sp)
LW t0, 0x0014 (sp)
LW ra, 0x0018 (sp)
JR RA
ADDIU sp, sp, 0x20
ItemsNotFull:
J ItemCheckExit
ORI v0, r0, 0x0001 ;bool for items not being full


DisplayWelcomeMessage: ;returns 0 for yes, 1 for no
ADDIU sp, sp, -0x28
SW a0, 0x0010 (sp)
SW a1, 0x0014 (sp)
SW a2, 0x0018 (sp)
SW a3, 0x001C (sp)
SW ra, 0x0020 (sp)
SW s0, 0x0024 (sp)
ORI a0, r0, 0xFFFF
LUI a1, hi(0x800977C0) ;where string is
ADDIU a1, a1, lo(0x800977C0)
ADDU A2 R0 R0
JAL 0x800EC8EC ; ShowMessage
ADDU A3 R0 R0
;
JAL GetBasicPromptSelection
NOP
ADD s0, v0, r0 ;move v0 to s0
JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP
ADD v0, s0, r0 ;move s0 back to v0 (index chosen)
LW a0, 0x0010 (sp)
LW a1, 0x0014 (sp)
LW a2, 0x0018 (sp)
LW a3, 0x001C (sp)
LW ra, 0x0020 (sp)
LW s0, 0x0024 (sp)
JR RA
ADDIU sp, sp, 0x28
