; NAME: Trivia Quiz (Airsola™)
; GAMES: MP3_USA
; EXECUTION: Direct
; PARAM: +Number|CorrectAnswer
; PARAM: +Number|IncorrectAnswer

;====================================================================
; IMPORTANT: This code is specifically designed to make a quiz for
;            player. If the player answers correctly, they win Coins.
;            If they get it wrong, they lose Coins. There are 6
;            questions total from which the game picks 1 at random.
;===================================================================

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



JAL PlaySound
LI A0 0x4FD ; Lucky 7 Step Sound

;BEGIN INTRODUCTION MESSAGE==========================================
SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 -1 ; Character image (-1 for none)
LUI A1 hi(Introduction)
ADDIU A1 A1 lo(Introduction)
LI A2 0x0
JAL 0x800EC8EC ; ShowMessage
LI A3 0x0

JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP
;END INTRODUCTION MESSAGE============================================

JAL GetRandomByte ; Random Int at V0
NOP

;BEGIN PREPARING BEGINNING OF PROMPT=================================
SW R0 20(SP) ; A4
SW R0 24(SP) ; A5
SW R0 28(SP) ; A6
LI A0 -1 ; Character image (None)
;END PREPARING BEGINNING OF PROMPT===================================

;BEGIN CHOOSING PROMPT QUESTION======================================
LI T0 0x2A
SLT S0 V0 T0 ; Is the number less than 42?
NOP
BNE S0 R0 Question1
NOP

LI T0 0x54
SLT S0 V0 T0 ; Is the number less than 84?
NOP
BNE S0 R0 Question2
NOP

LI T0 0x7F
SLT S0 V0 T0 ; Is the number less than 127?
NOP
BNE S0 R0 Question3
NOP

LI T0 0xAA
SLT S0 V0 T0 ; Is the number less than 170?
NOP
BNE S0 R0 Question4
NOP

LI T0 0xD5
SLT S0 V0 T0 ; Is the number less than 213?
NOP
BNE S0 R0 Question5
NOP

J Question6
NOP
;END CHOOSING PROMPT QUESTION========================================

;BEGIN LOADING PROMPT QUESTION=======================================
Question1:
LUI A1 hi(Question1_Prompt)
ADDIU A1 A1 lo(Question1_Prompt)
LI S4 1 ; The correct answer to Question 1 will be the middle answer
J FinishPrompt
NOP

Question2:
LUI A1 hi(Question2_Prompt)
ADDIU A1 A1 lo(Question2_Prompt)
LI S4 2 ; The correct answer to Question 2 will be the bottom answer
J FinishPrompt
NOP

Question3:
LUI A1 hi(Question3_Prompt)
ADDIU A1 A1 lo(Question3_Prompt)
LI S4 2 ; The correct answer to Question 3 will be the bottom answer
J FinishPrompt
NOP

Question4:
LUI A1 hi(Question4_Prompt)
ADDIU A1 A1 lo(Question4_Prompt)
LI S4 0 ; The correct answer to Question 4 will be the top answer
J FinishPrompt
NOP

Question5:
LUI A1 hi(Question5_Prompt)
ADDIU A1 A1 lo(Question5_Prompt)
LI S4 0 ; The correct answer to Question 5 will be the top answer
J FinishPrompt
NOP

Question6:
LUI A1 hi(Question6_Prompt)
ADDIU A1 A1 lo(Question6_Prompt)
LI S4 1 ; The correct answer to Question 6 will be the middle answer
;END LOADING PROMPT QUESTION=========================================

;BEGIN FINALIZING PROMPT QUESTION====================================
FinishPrompt:
ADDU A2 R0 R0
JAL 0x800EC8EC ; ShowMessage
ADDU A3 R0 R0

; If A0 is a pointer to AI data, AI logic is ran to pick for CPUs.
; If A0 is 0 or 1, the 0th or 1st option is chosen by CPUs.
; If A0 is 2, then the value of A1 is the CPUs option index choice.
J AILogic
NOP
AISelect:
LI A0 2
JAL GetBasicPromptSelection
MOVE A1 S5 ; A1 now has the AI's decision
MOVE S0 V0 ; S0 now has the chosen option index

; Obligatory message box closing/cleanup calls.
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP
;END FINALIZING PROMPT QUESTION======================================

JAL PlaySound
LI A0 0x3EC ; Drumroll

JAL SleepProcess
LI A0 25

JAL PlaySound
LI A0 0x3ED ; Drumroll end

JAL SleepProcess
LI A0 25

; Change the result based on the choice.
BEQ S0 S4 correct
NOP
J incorrect
NOP

;BEGIN CORRECT ANSWER PATH===========================================
correct:
JAL PlaySound
LI A0 0x419 ; Fanfare (Curtain Call)

;BEGIN CONGRATULATORY MESSAGE========================================
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
LI A2 CorrectAnswer

SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 -1 ; Character image (-1 for none)
LUI A1 hi(Congratulations_Message)
ADDIU A1 A1 lo(Congratulations_Message)
LUI A2 hi(coin_string_loc)
ADDIU A2 A2 lo(coin_string_loc)
JAL 0x800EC8EC ; ShowMessage
LI A3 0x0

JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP
;END CONGRATULATORY MESSAGE==========================================

JAL GetCurrentPlayerIndex ; Index at V0
NOP

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

ADDU S1 S1 S3 ; Add result to get current Player's Star address
LBU S2 0(S1) ; Load address value into S2

JAL PlaySound
ADDIU A0 S2 0x2BE ; Mario's Taunt Index

MOVE A0 S4 ; Presumably needs current player's index
LI A1 5 ; Joy Animation
JAL 0x800F2304 ; CueAnimation
LI A2 0

MOVE A0 S4
JAL AdjustPlayerCoinsGradual
LI A1 CorrectAnswer

MOVE A0 S4
JAL ShowPlayerCoinChange
LI A1 CorrectAnswer

JAL SleepProcess
LI A0 30

J exit
NOP
;END CORRECT ANSWER PATH=============================================

;BEGIN INCORRECT ANSWER PATH=========================================
incorrect:
JAL PlaySound
LI A0 0x40F ; Buzzer

;BEGIN INCORRECT MESSAGE=============================================
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
LI A2 IncorrectAnswer

SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 -1 ; Character image (-1 for none)
LUI A1 hi(Incorrect_Message)
ADDIU A1 A1 lo(Incorrect_Message)
LUI A2 hi(coin_string_loc)
ADDIU A2 A2 lo(coin_string_loc)
JAL 0x800EC8EC ; ShowMessage
LI A3 0x0

JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP
;END INCORRECT MESSAGE===============================================

JAL GetCurrentPlayerIndex ; Index at V0
NOP

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

ADDU S1 S1 S3 ; Add result to get current Player's Star address
LBU S2 0(S1) ; Load address value into S2

JAL PlaySound
ADDIU A0 S2 0x287

MOVE A0 S4 ; Presumably needs Current Player Index
LI A1 3 ; Sad/Despair Animation Index
JAL 0x800F2304 ; CueAnimation
LI A2 0 ; ???

MOVE A0 S4
LI T0 IncorrectAnswer
SUBU A1 R0 T0
JAL AdjustPlayerCoinsGradual
NOP


MOVE A0 S4
LI T0 IncorrectAnswer
SUBU A1 R0 T0
JAL ShowPlayerCoinChange
NOP

JAL SleepProcess
LI A0 60
;END INCORRECT ANSWER PATH===========================================



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



percent_d:
.asciiz "%d" ; 0x25640000

coin_string_loc:
.fill 8

.align 16
Introduction:
.ascii "Answer the question correctly to"
.byte 0x0A ; New Line (Writes Below)
.ascii "win some Coins"
.byte 0xC2 ; Exclamation Mark (!)
.ascii " If you get it"
.byte 0x0A ; New Line (Writes Below)
.ascii "wrong"
.byte 0x82 ; Comma (,)
.ascii " you lose Coins"
.byte 0xC2 ; Exclamation Mark (!)
.byte 0xFF,0 ; FF=Pause

.align 16
Question1_Prompt:
.byte 0x0B ; Start the message
.ascii "What image is on the sign"
.byte 0x0A ; New Line (Writes Below)
.ascii "that one of the penguins"
.byte 0x0A ; New Line (Writes Below)
.ascii "in Chilly Waters is holding"
.byte 0xC3 ; Question Mark (?)
.byte 0x0A ; New Line (Writes Below)
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A ; Option indent
.byte 0x0C ; Start option
.ascii "A Snowflake"
.byte 0x0D ; End option
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A ; Option indent
.byte 0x0C ; Start option
.ascii "A Sun"
.byte 0x0D ; End option
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A ; Option indent
.byte 0x0C ; Start option
.ascii "A Fish"
.byte 0x0D ; End option
.byte 0 ; End Prompt

.align 16
Question2_Prompt:
.byte 0x0B ; Start the message
.ascii "What is the yellow crab on the"
.byte 0x82 ; Comma (,)
.byte 0x0A ; New Line (Writes Below)
.ascii "bottom of Deep Bloober Sea holding"
.byte 0xC3 ; Question Mark (?)
.byte 0x0A ; New Line (Writes Below)
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A ; Option indent
.byte 0x0C ; Start option
.ascii "Nothing"
.byte 0x0D ; End option
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A ; Option indent
.byte 0x0C ; Start option
.ascii "A Pearl"
.byte 0x0D ; End option
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A ; Option indent
.byte 0x0C ; Start option
.ascii "A Flag"
.byte 0x0D ; End option
.byte 0 ; End Prompt

.align 16
Question3_Prompt:
.byte 0x0B ; Start the message
.ascii "What is on the bottom"
.byte 0x0A ; New Line (Writes Below)
.ascii "left corner of Spiny Desert"
.byte 0xC3 ; Question Mark (?)
.byte 0x0A ; New Line (Writes Below)
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A ; Option indent
.byte 0x0C ; Start option
.ascii "A Fossil"
.byte 0x0D ; End option
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A ; Option indent
.byte 0x0C ; Start option
.ascii "A Group of Klepto"
.byte 0x0D ; End option
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A ; Option indent
.byte 0x0C ; Start option
.ascii "A Tornado"
.byte 0x0D ; End option
.byte 0 ; End Prompt

.align 16
Question4_Prompt:
.byte 0x0B ; Start the message
.ascii "How many clouds are"
.byte 0x0A ; New Line (Writes Below)
.ascii "shown in Woody Woods"
.byte 0xC3 ; Question Mark (?)
.byte 0x0A ; New Line (Writes Below)
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A ; Option indent
.byte 0x0C ; Start option
.ascii "1"
.byte 0x0D ; End option
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A ; Option indent
.byte 0x0C ; Start option
.ascii "2"
.byte 0x0D ; End option
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A ; Option indent
.byte 0x0C ; Start option
.ascii "3"
.byte 0x0D ; End option
.byte 0 ; End Prompt

.align 16
Question5_Prompt:
.byte 0x0B ; Start the message
.ascii "What board are the group of"
.byte 0x0A ; New Line (Writes Below)
.ascii "Whomp playing on Creepy Cavern"
.byte 0xC3 ; Question Mark (?)
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A ; Option indent
.byte 0x0C ; Start option
.ascii "Rules Land"
.byte 0x0D ; End option
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A ; Option indent
.byte 0x0C ; Start option
.ascii "Mario"
.byte 0x5C ; Apostrophe (')
.ascii "s Rainbow Castle"
.byte 0x0D ; End option
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A ; Option indent
.byte 0x0C ; Start option
.ascii "Chilly Waters"
.byte 0x0D ; End option
.byte 0 ; End Prompt

.align 16
Question6_Prompt:
.byte 0x0B ; Start the message
.ascii "On the top left island of"
.byte 0x0A ; New Line (Writes Below)
.ascii "Waluigi"
.byte 0x5C ; Apostrophe (')
.ascii "s Island"
.byte 0x82 ; Comma (,)
.ascii " what kind of space is"
.byte 0x0A ; New Line (Writes Below)
.ascii "the Piranha Plant biting on"
.byte 0xC3 ; Question Mark (?)
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A ; Option indent
.byte 0x0C ; Start option
.ascii "A Battle Space"
.byte 0x0D ; End option
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A ; Option indent
.byte 0x0C ; Start option
.ascii "A Chance Time Space"
.byte 0x0D ; End option
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A ; Option indent
.byte 0x0C ; Start option
.ascii "A Game Guy Space"
.byte 0x0D ; End option
.byte 0 ; End Prompt

.align 16
Congratulations_Message:
.ascii "Congratulations"
.byte 0xC2 ; Exclamation Mark (!)
.byte 0x0A ; Enter (Writes Below)
.ascii "You got the right answer"
.byte 0xC2 ; Exclamation Mark (!)
.byte 0x0A ; Enter (Writes Below)
.ascii "You win "
.byte 0x06 ; Blue Font
.byte 0x11 ; String #1 (CorrectAnswer)
.ascii " Coins"
.byte 0x08 ; White Font
.byte 0xC2 ; Exclamation Mark (!)
.byte 0xFF,0 ; FF=Pause

.align 16
Incorrect_Message:
.ascii "Oh no"
.byte 0xC2 ; Exclamation Mark (!)
.byte 0x0A ; Enter (Writes Below)
.ascii "You got the wrong answer"
.byte 0xC2 ; Exclamation Mark (!)
.byte 0x0A ; Enter (Writes Below)
.ascii "You lose "
.byte 0x03 ; Red Font
.byte 0x11 ; String #1 (IncorrectAnswer)
.ascii " Coins"
.byte 0x08 ; White Font
.byte 0xC2 ; Exclamation Mark (!)
.byte 0xFF,0 ; FF=Pause

.align 4
AILogic:
JAL GetRandomByte ; at V0
NOP

LI T0 0x55
SLT S0 V0 T0 ; Is the number less than 85?
NOP
BNE S0 R0 Choose1st
NOP

LI T0 0xAA
SLT S0 V0 T0 ; Is the number less than 170?
NOP
BNE S0 R0 Choose2nd
NOP

J Choose3rd
NOP

Choose1st:
LI S5 0
J AISelect
NOP

Choose2nd:
LI S5 1
J AISelect
NOP

Choose3rd:
LI S5 2
J AISelect
NOP