Prev: BA15 Up: Map Next: BA9B
BA22: Game Over
Used by the routines at SendSparkleAtPlayer, DisplaySunMoonFrame and LoseLife.
Ends the game, whether the player has run out of lives, the forty days have passed or the final sparkles have caught the player. If the game was completed, the message of the potion is shown first. The results screen shows the days that have passed, the percentage of the quest that was completed, the number of charms collected and a rating. The game then returns to the menu when a key is pressed.
Game over screen
game-over
GameOver BA22 LD A,($5BC3) Fetch the flag that is set when the game has been completed from FinalAnimationFlag.
BA25 AND A Test it.
BA26 JP NZ,GameCompleted Show the message of the potion first if the game has been completed.
This entry point is used by the routine at GameCompleted.
Show the results screen.
GameOver_ShowResults BA29 CALL ClearScreenBuffer Clear the screen buffer.
BA2C CALL ClearScreen Clear the screen and make the border black.
BA2F LD DE,$BB4C Point DE at GameOverColours.
BA32 EXX Switch to the alternate registers to keep it there.
BA33 LD HL,$BB52 Point HL at GameOverCoordinates.
BA36 LD DE,$BB5E Point DE at GameOverText.
BA39 LD B,$06 Set the number of lines of text to 06.
BA3B CALL DisplayTextList Print the lines of text.
BA3E LD HL,$E8E2 Point HL at ScreenBuffer_ResultsDays.
BA41 LD DE,$5BB9 Point DE at Days.
BA44 LD B,$01 Set the number of bytes to print to 01.
BA46 CALL PrintBCDNumber Print the number of days.
BA49 CALL PrintPercentageComplete Print the percentage of the quest that was completed.
Work out the rating from the number of rooms visited and from whether the game was completed.
BA4C LD A,($5BC6) Fetch the number of rooms visited, less one from RoomsVisited.
BA4F RLCA Rotate the highest bit round to the lowest.
BA50 AND %11000000 Keep the next two highest bits (the number of rooms divided by 20).
BA52 LD C,A Stash them in C.
BA53 LD A,($5BC3) Fetch the flag that is set when the game has been completed from FinalAnimationFlag.
BA56 AND %00000001 Keep only the lowest bit.
BA58 OR C Combine it with the number of rooms.
BA59 RLCA Rotate the bits into place to make the number of a word.
BA5A RLCA
BA5B RLCA
BA5C AND %00001110 Keep the bits of the number of the word.
BA5E LD L,A Set HL to the number of bytes into the table of ratings.
BA5F LD H,$00
BA61 LD BC,$BBB7 Point BC at RatingTable.
BA64 ADD HL,BC Point HL at the entry for the rating.
BA65 LD E,(HL) Fetch the low byte of the address of the text of the rating.
BA66 INC HL Move on to the high byte.
BA67 LD D,(HL) Fetch the high byte.
BA68 LD HL,$2758 Set HL to the position of the rating.
BA6B CALL PrintTextStandardFont Print the rating.
Print the number of charms collected, which is the number of objects that were put into the cauldron.
BA6E LD DE,$5BBB Point DE at Charms.
BA71 LD A,(DE) Fetch the number of charms.
BA72 SUB $0A Take off 0A to see if the number is in double digits.
BA74 JR C,GameOver_PrintCharms Jump to GameOver_PrintCharms if it is not.
BA76 OR %00010000 Convert it to a BCD number between 10 and 14.
BA78 LD (DE),A Store the BCD number.
GameOver_PrintCharms BA79 LD HL,$E2EA Point HL at the position of the charms in the screen buffer, ScreenBuffer_ResultsCharms.
BA7C LD B,$01 Set the number of bytes to print to 01.
BA7E CALL PrintBCDNumber Print the number of charms collected.
BA81 CALL PrintBorder Draw the border.
BA84 CALL UpdateScreen Copy the screen buffer to the display.
Play the tune, wait for a key to be pressed and then go back to the menu.
GameOver_WaitForKeyRelease BA87 XOR A Select all the half-rows of the keyboard.
BA88 CALL ReadKeyboardPort Read the keyboard.
BA8B JR NZ,GameOver_WaitForKeyRelease Jump to GameOver_WaitForKeyRelease until all the keys are released.
BA8D LD DE,$B218 Point DE at GameOverTune.
BA90 CALL PlayMusic_WaitKey Play the tune, until a key is pressed.
BA93 LD B,$08 Set the number of times to wait to 08.
BA95 CALL WaitForKeyPress Wait for a key to be pressed, up to a limit.
BA98 JP RestartGame Go back to the menu, to start another game.
Prev: BA15 Up: Map Next: BA9B