; NAME: Bowser Revolution
; GAMES: MP3_USA
; EXECUTION: Direct
; PARAM: Number|Tax

;====================================================================
; IMPORTANT: This code is specifically designed to give every player
;            a fixed amount of coins except for the player who lands
;            or passes through the space.
;====================================================================
.align 0x10
ADDIU sp, sp, -0x200
SW RA 36(SP)
SW S0 32(SP)
SW S1 28(SP)
SW S2 24(SP)
SW S3 20(SP)
SW S4 16(SP)
SW S5 12(SP)
SW S6 8(SP)
SW S7 4(SP)


;DONT DELETE BELOW-------------------------------------------------------
SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
JAL PlaySound
ADDIU A0 R0 0x29D ; Bowser Growl
LI A0 4 ; Character image (Bowser)
LUI A1 hi(Message)
ADDIU A1 A1 lo(Message) ; This needs to be here to not crash
LI A2 0x0
JAL 0x800EC8EC ; ShowMessage
LI A3 0x0


JAL 0x800EC9DC ; I think these have to be here for messages
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP

LI S6 100 ; High number for accurate division
LI S7 Tax
;FROM PLAYER TO POT----------------------------------------------------
LI S0 0x0 ; Begin with Player 1

START:
NOP

MOVE A0 S0

JAL GetPlayerStruct
NOP
LHU S5, 0x000A (V0); Put into S5
LI T0 100
;MULT S5 T0 ; Test this later
;MFLO S5

LI T0 0x4 ; If all Players have been given coins, stop
BEQ S0 T0 wait
NOP

DIVU S6 S7
MFLO S1 ; This should create divisor for player's coins
NOP
NOP
DIVU S5 S1 ;
MFLO S5 ; This should create amount of coins from player to pot
NOP

;LI T0 100 ;Try to debug this for precise dividing
;DIVU S5 T0 
;MFLO S5 
;NOP

MOVE A0 S0 ; Current Player's Index moved to A0
SUBU A1 R0 S5 ; Amount player loses
JAL AdjustPlayerCoinsGradual ; Changes Player's coin amount
NOP


ADDIU S0 S0 1 ; Add 1 to S0 to check next player
ADDU S3 S3 S5 ; Add to pot

J START
NOP

;WAIT START----------------------------------------------------------
wait:
ADDIU A0 R0 30 ; Amount of frames the game waits for coin handouts
JAL SleepProcess
NOP

;WAIT END------------------------------------------------------------


LI T0 4 
DIVU S3 T0
MFLO S3 ; This should create amount player gets

HandOut:
;FROM POT TO PLAYER------------------------------------------------------
LI S0 0x0 ; Begin with Player 1

STARTAGAIN:
NOP



LI T0 0x4 ; If all Players have been given coins, stop
BEQ S0 T0 waitagain
NOP

MOVE A0 S0 ; Current Player's Index moved to A0
JAL AdjustPlayerCoinsGradual ; Changes Player's coin amount
ADDU A1 R0 S3 ; Amount player gets



ADDIU S0 S0 1 ; Add 1 to S0 to check next player
J STARTAGAIN

Exit:
;WAIT START----------------------------------------------------------
waitagain:
ADDIU A0 R0 30 ; Amount of frames the game waits for coin handouts
JAL SleepProcess
NOP
;WAIT END------------------------------------------------------------

LW S7 4(SP)
LW S6 8(SP)
LW S5 12(SP)
LW S4 16(SP)
LW S3 20(SP)
LW S2 24(SP)
LW S1 28(SP)
LW S0 32(SP)
LW RA 36(SP)
JR RA
ADDIU sp, sp, 0x200

; .ascii is used to output Text. Anything surrounded by " will be 
; displayed in the message (Special characters are not included).
; For those, you must use .byte and the respective byte value.
; Bytes that change text color will change the color of everything
; that is written after it, until another color is used.

.align 10
Message:
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "Everyone must "
.byte 0x0A ; Newline
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "share their"
.byte 0x07 ; Blue font
.ascii " coins"
.byte 0x08 ; White Font
.byte 0xC2 ; Exclamation Mark (!)
.byte 0xFF,0 ; FF=Pause (THIS ALWAYS GOES AT THE END)

; Here's a list of the most common bytes you'll need
; .byte 0x01 ; Black Font
; .byte 0x03 ; Red Font
; .byte 0x04 ; Purple Font
; .byte 0x05 ; Green Font
; .byte 0x06 ; Blue font
; .byte 0x07 ; Yellow Font
; .byte 0x08 ; White Font
; .byte 0x85 ; Period (.)
; .byte 0xC2 ; Exclamation Mark (!)
; .byte 0xC3 ; Question Mark (?)
; .byte 0x82 ; Comma (,)
; .byte 0x0A ; New Line (Writes Below)
; .byte 0x5C ; Apostrophe (')
; .byte 0x29 ; Coin icon
; .byte 0x3D ; - (minus)
; .byte 0x3E ; x (multiply)
; .byte 0xFF,0 ; FF=Pause

; If your message has an image, use this at the start of each line
; .byte 0x1A,0x1A,0x1A,0x1A ; Padding for picture