; NAME: Four Way Warp 2
; GAMES: MP3_USA
; EXECUTION: Direct
; PARAM: Space|Destination1
; PARAM: Space|PreviousSpace1
; PARAM: Space|NextSpace1
; PARAM: Space|Destination2
; PARAM: Space|PreviousSpace2
; PARAM: Space|NextSpace2
; PARAM: Space|Destination3
; PARAM: Space|PreviousSpace3
; PARAM: Space|NextSpace3
; PARAM: Space|Destination4
; PARAM: Space|PreviousSpace4
; PARAM: Space|NextSpace4

;====================================================================
; IMPORTANT: This code is an edited version of Airsola's code
;            It will warp you to a different location
;            Depending which Course is active
;
;            Destination is where the player will warp to.
;            PreviousSpace is the space the player will step into if
;            they go in reverse after the warp.
;            NextSpace is the next space that the player will step
;            into if they roll normally.
;			 
;			 Made by Spongyoshi, feel free to use for your boards!
;====================================================================

ADDIU SP SP -80
SW RA 76(SP)
SW S1 72(SP) ;holds the RAM address 1 of Chilly Waters
SW S2 68(SP) ;holds various values
SW S4 64(SP) ;holds current player index

LUI S1 hi(0x800CD096)
ADDIU S1 S1 lo(0x800CD096) ; Loading RAM address 1 of Chilly Waters
LBU S1 0(S1)

JAL GetCurrentPlayerIndex ; Player Index located at V0
NOP

MOVE S4 V0 ; Move Current Player Index to S4

;===Set Player Idle Animation===
LI A0 -1 ; Load Current Player Index
LI A1 -1 ; Set player's idle animation
JAL SetBoardPlayerAnimation
LI A2 2 ; Loop the animation

;SOUND START---------------------------------------------------------
JAL PlaySound 
LI A0 0x107 ; Warp Block Sound Index

ADDIU A0 R0 2 ; Assigns Star Code fade-out
ADDIU A1 R0 10 ; Assigns 10 frames of fade-out
JAL 0x80062050 ; Calls Fade-out
NOP

ADDIU A0 R0 25
JAL SleepProcess ; Sleeps for 25 frames
NOP
;SOUND END-----------------------------------------------------------

;DECISION START------------------------------------------------------
LI S2 1
BEQ S1 S2 WarpTo2 ; If it's Course 1, warp to Destination 2
NOP

LI S2 2
BEQ S1 S2 WarpTo2 ; If it's Course 2, warp to Destination 2
NOP

LI S2 3
BEQ S1 S2 WarpTo3 ; If it's Course 3, warp to Destination 3
NOP

LI S2 4
BEQ S1 S2 WarpTo4 ; If it's Course 4, warp to Destination 4
NOP

LI S2 5
BEQ S1 S2 WarpTo4 ; If it's Course 5, warp to Destination 4
NOP

LI S2 6
BEQ S1 S2 WarpTo3 ; If it's Course 6, warp to Destination 3
NOP

LI S2 7
BEQ S1 S2 WarpTo1 ; If it's Course 7, warp to Destination 1
NOP

LI S2 8
BEQ S1 S2 WarpTo1 ; If it's Course 8, warp to Destination 1
NOP

LI S2 9
BEQ S1 S2 WarpTo3 ; If it's Course 9, warp to Destination 3
NOP

LI S2 10
BEQ S1 S2 WarpTo3 ; If it's Course 10, warp to Destination 3
NOP

LI S2 11
BEQ S1 S2 WarpTo4 ; If it's Course 11, warp to Destination 4
NOP

LI S2 12
BEQ S1 S2 WarpTo4 ; If it's Course 12, warp to Destination 4
NOP

LI S2 13
BEQ S1 S2 WarpTo1 ; If it's Course 13, warp to Destination 1
NOP

LI S2 14
BEQ S1 S2 WarpTo2 ; If it's Course 14, warp to Destination 2
NOP

LI S2 15
BEQ S1 S2 WarpTo1 ; If it's Course 15, warp to Destination 1
NOP

LI S2 16
BEQ S1 S2 WarpTo4 ; If it's Course 16, warp to Destination 4
NOP

LI S2 17
BEQ S1 S2 WarpTo2 ; If it's Course 17, warp to Destination 2
NOP

LI S2 18
BEQ S1 S2 WarpTo4 ; If it's Course 18, warp to Destination 4
NOP

LI S2 19
BEQ S1 S2 WarpTo1 ; If it's Course 19, warp to Destination 1
NOP

LI S2 20
BEQ S1 S2 WarpTo2 ; If it's Course 20, warp to Destination 2
NOP

LI S2 21
BEQ S1 S2 WarpTo3 ; If it's Course 21, warp to Destination 3
NOP

LI S2 22
BEQ S1 S2 WarpTo1 ; If it's Course 22, warp to Destination 1
NOP

LI S2 23
BEQ S1 S2 WarpTo2 ; If it's Course 23, warp to Destination 2
NOP

LI S2 24
BEQ S1 S2 WarpTo3 ; If it's Course 24, warp to Destination 3
NOP
;DECISION END--------------------------------------------------------

;WARP1 START---------------------------------------------------------
WarpTo1:
MOVE A0 S4 ; Move Current Player Index to A0
ADDIU A1 R0 Destination1_chain_index ; Assigns Chain Index to A1
ADDIU A2 R0 Destination1_chain_space_index ; Assigns Space Index to A2
JAL SetPlayerOntoChain
NOP

MOVE A0 S4 ; Move Current Player Index to A0
ADDIU A1 R0 PreviousSpace1_chain_index ; Assigns Chain Index to A1
ADDIU A2 R0 PreviousSpace1_chain_space_index ; Assigns Space Index to A2
JAL SetPrevChainAndSpace
NOP

MOVE A0 S4 ; Move Current Player Index to A0
ADDIU A1 R0 NextSpace1_chain_index ; Assigns Chain Index to A1
ADDIU A2 R0 NextSpace1_chain_space_index ; Assigns Space Index to A2
JAL SetNextChainAndSpace
NOP

J exit
NOP
;WARP1 END-----------------------------------------------------------

;WARP2 START---------------------------------------------------------
WarpTo2:
MOVE A0 S4 ; Move Current Player Index to A0
ADDIU A1 R0 Destination2_chain_index ; Assigns Chain Index to A1
ADDIU A2 R0 Destination2_chain_space_index ; Assigns Space Index to A2
JAL SetPlayerOntoChain
NOP

MOVE A0 S4 ; Move Current Player Index to A0
ADDIU A1 R0 PreviousSpace2_chain_index ; Assigns Chain Index to A1
ADDIU A2 R0 PreviousSpace2_chain_space_index ; Assigns Space Index to A2
JAL SetPrevChainAndSpace
NOP

MOVE A0 S4 ; Move Current Player Index to A0
ADDIU A1 R0 NextSpace2_chain_index ; Assigns Chain Index to A1
ADDIU A2 R0 NextSpace2_chain_space_index ; Assigns Space Index to A2
JAL SetNextChainAndSpace
NOP

J exit
NOP
;WARP2 END-----------------------------------------------------------

;WARP3 START---------------------------------------------------------
WarpTo3:
MOVE A0 S4 ; Move Current Player Index to A0
ADDIU A1 R0 Destination3_chain_index ; Assigns Chain Index to A1
ADDIU A2 R0 Destination3_chain_space_index ; Assigns Space Index to A2
JAL SetPlayerOntoChain
NOP

MOVE A0 S4 ; Move Current Player Index to A0
ADDIU A1 R0 PreviousSpace3_chain_index ; Assigns Chain Index to A1
ADDIU A2 R0 PreviousSpace3_chain_space_index ; Assigns Space Index to A2
JAL SetPrevChainAndSpace
NOP

MOVE A0 S4 ; Move Current Player Index to A0
ADDIU A1 R0 NextSpace3_chain_index ; Assigns Chain Index to A1
ADDIU A2 R0 NextSpace3_chain_space_index ; Assigns Space Index to A2
JAL SetNextChainAndSpace
NOP

J exit
NOP
;WARP3 END-----------------------------------------------------------

;WARP4 START---------------------------------------------------------
WarpTo4:
MOVE A0 S4 ; Move Current Player Index to A0
ADDIU A1 R0 Destination4_chain_index ; Assigns Chain Index to A1
ADDIU A2 R0 Destination4_chain_space_index ; Assigns Space Index to A2
JAL SetPlayerOntoChain
NOP

MOVE A0 S4 ; Move Current Player Index to A0
ADDIU A1 R0 PreviousSpace4_chain_index ; Assigns Chain Index to A1
ADDIU A2 R0 PreviousSpace4_chain_space_index ; Assigns Space Index to A2
JAL SetPrevChainAndSpace
NOP

MOVE A0 S4 ; Move Current Player Index to A0
ADDIU A1 R0 NextSpace4_chain_index ; Assigns Chain Index to A1
ADDIU A2 R0 NextSpace4_chain_space_index ; Assigns Space Index to A2
JAL SetNextChainAndSpace
NOP

J exit
NOP
;WARP4 END-----------------------------------------------------------

;SOUND START---------------------------------------------------------
exit:
ADDIU A0 R0 2 ; Assigns Star Code fade-in
ADDIU A1 R0 10 ; Assigns 10 frames of fade-in
JAL 0x80061FE8 ; Calls Fade-in
NOP

JAL PlaySound 
LI A0 0x107 ; Warp Block Sound Index
;SOUND END-----------------------------------------------------------

LW RA 76(SP)
LW S1 72(SP)
LW S2 68(SP)
LW S4 64(SP)
JR RA
ADDIU SP SP 80