; NAME: GainOnPassEffect
; GAMES: MP3_USA
; EXECUTION: Direct

ADDIU SP SP -40
SW RA 0(SP)
SW S1 4(SP)
SW S2 8(SP)
SW S3 12(SP)
SW S4 16(SP)
SW S5 20(SP)
SW S6 24(SP)
SW S7 28(SP)

JAL GetCurrentPlayerIndex
NOP

MOVE S4 V0 ; Copy Player's Index to S4 

LUI S1 hi(0x800CD09B) ; Checks if gain on pass or not
ADDIU S1 S1 lo(0x800CD09B) ; Load Address of Board-Specific RAM
LBU S2 0(S1) ; Load the RAM Value into S1

LUI S3 hi(0x800D41C0) ; Moves remaining
ADDIU S3 S3 lo(0x800D41C0) 


LI S7 1
SLT S0 S2 S7 ; S0 = 1 if the number is less than 1
NOP
BNE S0 R0 No ; Branch if true
NOP

LI S7 2
SLT S0 S2 S7 ; S0 = 1 if the number is less than 26
NOP
BNE S0 R0 SingleLoss ; Branch if true
NOP

LI S7 3
SLT S0 S2 S7 ; S0 = 1 if the number is less than 52
NOP
BNE S0 R0 SingleGain ; Branch if true
NOP

LI S7 4
SLT S0 S2 S7 ; S0 = 1 if the number is less than 78
NOP
BNE S0 R0 DoubleLoss ; Branch if true
NOP

LI S7 5
SLT S0 S2 S7 ; S0 = 1 if the number is less than 78
NOP
BNE S0 R0 DoubleGain ; Branch if true
NOP


DoubleGain:
LW S5 0(S3) ; Load address value into T0
ADDU S5 S5 S5
J Exit
NOP


DoubleLoss:
LW S5 0(S3) ; Load address value into T0
LW S6 0(S3)
SUBU S5 R0 S5 ;Make coin amount 0
SUBU S5 R0 S6 ;Make coin amount -1x moves remaining
SUBU S5 S5 S6 ;;Make coin amount -2x moves remaining
J Exit
NOP

SingleGain:
LW S5 0(S3) ; Load address value into T0
J Exit
NOP

SingleLoss:
LW S5 0(S3) ; Load address value into T0
LW S6 0(S3)
SUBU S5 R0 S5 ;Make coin amount 0
SUBU S5 R0 S6 ;Make coin amount -1x moves remaining
J Exit
NOP

Exit:
MOVE A0 S4 ; Pass Player's Index, from whatever register it's on
JAL AdjustPlayerCoinsGradual
MOVE A1 S5 ; Copy value into A1


; Display the coin change by the player stats
JAL GetCurrentPlayerIndex
NOP

LW T0 0(S3) ; Load address value into T0
MOVE A0 S4 ; Pass Player's Index, from whatever register it's on
JAL ShowPlayerCoinChange
MOVE A1 S5 ; Copy value into A1

; Sleep for 30 frames to let coin change take effect
JAL SleepProcess
ADDIU A0 R0 30

No:
LW S7 28(SP)
LW S5 20(SP)
LW S6 24(SP)
LW S4 16(SP)
LW S3 12(SP)
LW S1 4(SP)
LW S2 8(SP)
LW RA 0(SP)
JR RA
ADDIU SP SP 40