; NAME: Bowser Bank [Landing] (Airsola™)
; GAMES: MP3_USA
; EXECUTION: Direct

ADDIU SP SP -64
SW S7 36(SP)
SW S4 40(SP)
SW RA 60(SP)
SW S1 44(SP)
SW S0 48(SP)
SW S2 52(SP)
SW S3 56(SP)


; S1 = Bank address
; S2 = Bank loan value
; S7 = Current Player's Star address

;BEGIN LOADING BANK COINS STRING=====================================
LUI S1 hi(bank_coin_total)
ADDIU S1 S1 lo(bank_coin_total) ; Load Address of Bank Total
LHU S2 0(S1) ; Load the Bank Value into S1

LUI A0 hi(coin_string_loc)
ADDIU A0 A0 lo(coin_string_loc)
LUI A1 hi(percent_d)
ADDIU A1 A1 lo(percent_d)
JAL sprintf
MOVE A2 S2 ; Copy Bank Total Value into A2
;END LOADING BANK COINS STRING=======================================

BNE S2 R0 normalgreeting ; If the loan isn't 0, greet normally
NOP

JAL PlaySound
LI A0 0x2A0 ; Baby Bowser Roar

SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 5 ; Character image (Baby Bowser)
LUI A1 hi(NoLoanGreeting_Message)
ADDIU A1 A1 lo(NoLoanGreeting_Message)
LI A2 0
JAL 0x800EC8EC ; ShowMessage
LI A3 0

JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP

SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 5 ; Character image (Baby Bowser)
LUI A1 hi(NoLoanGoodbye_Message)
ADDIU A1 A1 lo(NoLoanGoodbye_Message)
LI A2 0
JAL 0x800EC8EC ; ShowMessage
LI A3 0

JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP

J exit
NOP

;BEGIN GREETING======================================================
normalgreeting:
JAL PlaySound
LI A0 0x2A0 ; Baby Bowser Roar

SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 5 ; Character image (Baby Bowser)
LUI A1 hi(NormalGreeting_Message)
ADDIU A1 A1 lo(NormalGreeting_Message)
LUI A2 hi(coin_string_loc)
ADDIU A2 A2 lo(coin_string_loc)
JAL 0x800EC8EC ; ShowMessage
LI A3 0

JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP
;END GREETING========================================================

;BEGIN Take Coins From Player========================================
JAL GetCurrentPlayerIndex ; Current Player Index at V0
NOP
MOVE S4 V0

LUI S0 hi(p1_coins)
ADDIU S0 S0 lo(p1_coins) ; Load the address of Player 1's Coins
LI T0 0x38 ; This is the distance between each player's Coins
MULT S4 T0 ;  Multiply Current Player Index by T0
MFLO T0 ; Move the result to T0

ADDU S0 S0 T0 ; Add the result to the Coins address
LHU S0 0(S0) ; Load the value of the Player's Coins address into S0

BEQ S0 R0 nocoins
NOP

MOVE A0 S4 ; Current Player's Index moved to A0
JAL AdjustPlayerCoinsGradual ; Changes Player's coin amount
SUBU A1 R0 S2 ; Amount to lose

MOVE A0 S4 ; Current Player's Index moved to A0
JAL ShowPlayerCoinChange ; Displays Player's coin loss on-screen 
SUBU A1 R0 S2 ; Amount to display

LI A0 -1 ; Current Player
LI A1 3 ; Despair Animation Index
JAL SetBoardPlayerAnimation
LI A2 0 ; Don't repeat animation

MOVE A0 S4
JAL getsadvoice ; Sad voice index at V0
NOP

JAL SleepProcess ; Sleeps for 30 frames
LI A0 30

J determinegoodbye
NOP
;END Take Coins From Player==========================================

nocoins:
LUI S7 hi(p1_stars)
ADDIU S7 S7 lo(p1_stars) ; Load the address of Player 1's Stars
LI T0 0x38 ; This is the distance between each player's Stars
MULT S4 T0 ;  Multiply Current Player Index by T0
MFLO T0 ; Move the result to T0

ADDU S7 S7 T0 ; Add the result to the Stars address
LBU S0 0(S7) ; Load the value of the Player's Stars address into S0

BEQ S0 R0 nostars
NOP

SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 5 ; Character image (Baby Bowser)
LUI A1 hi(LoseStar_Message)
ADDIU A1 A1 lo(LoseStar_Message)
LI A2 0
JAL 0x800EC8EC ; ShowMessage
LI A3 0

JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP

LI T0 1
SUBU S0 S0 T0 ; Subtract 1 from the player's Star count
SB S0 0(S7) 

JAL PlayMusic
LI A0 0x6B ; Fail music

LI A0 -1 ; Current Player
LI A1 3 ; Despair Animation Index
JAL SetBoardPlayerAnimation
LI A2 0 ; Don't repeat animation

MOVE A0 S4
JAL getsadvoice ; Sad voice index at V0
NOP

JAL SleepProcess
LI A0 95 ; Sleep 95 Frames

JAL PlayMusic
LI A0 6 ; <--- CHANGE TO CORRECT MUSIC INDEX (Default: Staff Roll)

J emptybank
NOP

nostars:
SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 5 ; Character image (Baby Bowser)
LUI A1 hi(LoseNothing_Message)
ADDIU A1 A1 lo(LoseNothing_Message)
LI A2 0
JAL 0x800EC8EC ; ShowMessage
LI A3 0

JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP

LI A0 -1 ; Current Player
LI A1 5 ; Joy Animation Index
JAL SetBoardPlayerAnimation
LI A2 0 ; Don't repeat animation

MOVE A0 S4
JAL gethappyvoice
NOP

JAL SleepProcess
LI A0 35 ; Sleep 35 frames

J emptybank
NOP

;BEGIN Determine last message========================================
determinegoodbye:
SLT S3 S0 S2 ; S3 = 1 if the player didn't have enough Coins
NOP

BNE S3 R0 insufficientfunds ; Branch if the player didn't have enough
NOP

SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
ADDI A0 R0 0x5 ; Character image (Baby Bowser)
LUI A1 hi(Goodbye_Message)
ADDIU A1 A1 lo(Goodbye_Message)
LI A2 0
JAL 0x800EC8EC ; ShowMessage
LI A3 0

JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP

J emptybank
NOP

insufficientfunds:
SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
ADDI A0 R0 0x5 ; Character image (Baby Bowser)
LUI A1 hi(Insufficientfunds_Message)
ADDIU A1 A1 lo(Insufficientfunds_Message)
LI A2 0
JAL 0x800EC8EC ; ShowMessage
LI A3 0

JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP
;END Determine last message==========================================

emptybank:
LI T0 0
SH T0 0(S1) ; Resets Bank back to 0

LI A0 -1 ; Current Player
LI A1 -1 ; Idle animation
JAL SetBoardPlayerAnimation
LI A2 2 ; Loop



exit:
LW S7 36(SP)
LW S4 40(SP)
LW RA 60(SP)
LW S1 44(SP)
LW S0 48(SP)
LW S2 52(SP)
LW S3 56(SP)
JR RA
ADDIU SP SP 64

getsadvoice:
; a0 = player's index
ADDIU SP SP -32
SW RA 28(SP)

LUI T1 hi(p1_char)
ADDIU T1 T1 lo(p1_char) ; Load Player 1's Character address
LI T0 0x38 ; Distance between each player's Character address
MULT A0 T0 ;  Multiply Current Player Index by T0
MFLO T0 ; Move the result to T0

ADDU T1 T1 T0 ; Add result to get current Player's Character address
LBU T0 0(T1) ; Load address value into T0

ADDIU V0 T0 0x287 ; Mario's Sad Voice Index

JAL PlaySound
MOVE A0 V0 ; Pass the Voice Index to A0

LW RA 28(SP)
JR RA
ADDIU SP SP 32

gethappyvoice:
; a0 = player's index
ADDIU SP SP -24
SW RA 20(SP)

LUI T1 hi(p1_char)
ADDIU T1 T1 lo(p1_char) ; Load Player 1's Character address
LI T0 0x38 ; Distance between each player's Character address
MULT A0 T0 ;  Multiply Current Player Index by T0
MFLO T0 ; Move the result to T0

ADDU T1 T1 T0 ; Add result to get current Player's Character address
LBU T0 0(T1) ; Load address value into T0

ADDIU V0 T0 0x2BE ; Mario's Taunt Voice Index

JAL PlaySound
MOVE A0 V0 ; Pass the Voice Index to A0

LW RA 20(SP)
JR RA
ADDIU SP SP 24



percent_d:
.asciiz "%d" ; 0x25640000

coin_string_loc:
.fill 8

.align 16
NormalGreeting_Message:
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "Welcome"
.byte 0xC2 ; Exclamation Mark (!)
.ascii " Good day to you"
.byte 0xC2 ; Exclamation Mark (!)
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "I"
.byte 0x5C ; Apostrophe (')
.ascii "m afraid that your "
.byte 0x03 ; Red Font
.byte 0x11 ; Coin Amount String
.byte 0x3D ; - (minus)
.ascii "Coin"
.byte 0x08 ; White Font
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "loan is due"
.byte 0xC2 ; Exclamation Mark (!)
.byte 0xFF,0 ; FF=Pause

.align 16
Insufficientfunds_Message:
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "Insufficient funds"
.byte 0xC3,0xC3,0xC3 ; Question Mark (???)
.ascii " Look"
.byte 0x85,0x85,0x85 ; Period (...)
.ascii "We"
.byte 0x5C ; Apostrophe (')
.ascii "re a"
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "business"
.byte 0x85 ; Period (.)
.ascii " We can"
.byte 0x5C ; Apostrophe (')
.ascii "t just hand out"
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "money"
.byte 0xC2 ; Exclamation Mark (!)
.ascii " Don"
.byte 0x5C ; Apostrophe (')
.ascii "t let this happen again"
.byte 0xC2 ; Exclamation Mark (!)
.byte 0xFF,0 ; FF=Pause

.align 16
Goodbye_Message:
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "Thank you very much"
.byte 0xC2 ; Exclamation Mark (!)
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "I hope you"
.byte 0x5C ; Apostrophe (')
.ascii "ll do business with"
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "Bowser Bank again"
.byte 0xC2,0xC2,0xC2 ; Exclamation Mark (!!!)
.byte 0xFF,0 ; FF=Pause

.align 16
NoLoanGreeting_Message:
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "Hello"
.byte 0xC2 ; Exclamation Mark (!)
.ascii " Welcome"
.byte 0xC2 ; Exclamation Mark (!)
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "I"
.byte 0x5C ; Apostrophe (')
.ascii "m sorry"
.byte 0x82 ; Comma (,)
.ascii " but those"
.byte 0x07 ; Yellow Font
.ascii " Coins"
.byte 0x08 ; White Font
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "I lent you are past due"
.byte 0xC2 ; Exclamation Mark (!)
.byte 0xFF,0 ; FF=Pause

.align 16
NoLoanGoodbye_Message:
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "Erm"
.byte 0x85,0x85,0x85 ; Period (...)
.ascii "I"
.byte 0x5C ; Apostrophe (')
.ascii "m sorry"
.byte 0xC2 ; Exclamation Mark (!)
.ascii " There seems"
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "to have been a slight error"
.byte 0xC2 ; Exclamation Mark (!)
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "Umm"
.byte 0x85,0x85,0x85 ; Period (...)
.ascii "Come again"
.byte 0xC2,0xC3,0xC2 ; Exclamation Mark (!?!)
.byte 0xFF,0 ; FF=Pause

.align 16
LoseStar_Message:
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "WHAT"
.byte 0xC3,0xC2,0xC3 ; Question Mark (?!?)
.ascii " You haven"
.byte 0x5C ; Apostrophe (')
.ascii "t ANY Coins"
.byte 0xC3 ; Question Mark (?)
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "Well"
.byte 0x82 ; Comma (,)
.ascii " if you can"
.byte 0x5C ; Apostrophe (')
.ascii "t pay with Coins"
.byte 0x82 ; Comma (,)
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "then I"
.byte 0x5C ; Apostrophe (')
.ascii "ll have to take a"
.byte 0x03 ; Red Font
.ascii " Star"
.byte 0xC2 ; Exclamation Mark (!)
.byte 0xFF,0 ; FF=Pause

.align 16
LoseNothing_Message:
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "WHAAAT"
.byte 0xC2,0xC3,0xC2 ; Exclamation Mark (!?!)
.ascii " You have NO COINS"
.byte 0xC2,0xC3,0xC2 ; Exclamation Mark (!?!)
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "But you signed for it"
.byte 0xC2 ; Exclamation Mark (!)
.ascii " I"
.byte 0x5C ; Apostrophe (')
.ascii "ll get you"
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "for this"
.byte 0xC2 ; Exclamation Mark (!)
.ascii " I"
.byte 0x5C ; Apostrophe (')
.ascii "ll sue"
.byte 0xC2 ; Exclamation Mark (!)
.ascii " Get me a lawyer"
.byte 0xC2,0xC2,0xC2 ; Exclamation Mark (!!!)
.byte 0xFF,0 ; FF=Pause