; NAME: GainOnPassOdds
; 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)

LUI S1 hi(0x800CD09B)
ADDIU S1 S1 lo(0x800CD09B) ; Load Address of Board-Specific RAM
LBU S2 0(S1) ; Load the RAM Value into S1
SUBU S2 S2 S2

JAL GetRandomByte ; Integer at V0
NOP

LI S3 13
SLT S0 V0 S3 ; S0 = 1 if the number is less than 13
NOP
BNE S0 R0 DoubleGain ; Branch if true
NOP

LI S3 26
SLT S0 V0 S3 ; S0 = 1 if the number is less than 26
NOP
BNE S0 R0 DoubleLoss ; Branch if true
NOP

LI S3 52
SLT S0 V0 S3 ; S0 = 1 if the number is less than 52
NOP
BNE S0 R0 SingleGain ; Branch if true
NOP

LI S3 78
SLT S0 V0 S3 ; S0 = 1 if the number is less than 78
NOP
BNE S0 R0 SingleLoss ; Branch if true
NOP

J Exit ; No event if > 78
NOP

DoubleGain:
ADDIU S2 S2 4
SB S2 0(S1)
NOP

J Exit
NOP


DoubleLoss:
ADDIU S2 S2 3
SB S2 0(S1)
NOP

J Exit
NOP

SingleGain:
ADDIU S2 S2 2
SB S2 0(S1)
NOP

J Exit
NOP

SingleLoss:
ADDIU S2 S2 1
SB S2 0(S1)
NOP


Exit:
LW S3 12(SP)
LW S1 4(SP)
LW S2 8(SP)
LW RA 0(SP)
JR RA
ADDIU SP SP 40