Prev: 42220 Up: Map Next: 42397
42250: Check Top Score
Used by the routine at CheckSheriffLost.
Called when the last life of the last player has been lost. It works out which player scored most, and if that score beats the top score of the day it shows the "WELL DONE" screen and stores the new top score. Either way the game then goes back to the title screen.
The player states are swapped first so that the first player's score is in the current position.
CheckTopScore 42250 CALL SwapPlayerStates Swap the states of the two players.
This entry point is used by the routine at CheckSheriffLost.
Compare the two scores, most significant byte first.
CheckTopScore_SkipSwap 42253 LD B,3 Set the number of bytes in a score to three.
42255 LD DE,41559 Point DE at Bounty.
42258 LD HL,41578 Point HL at OtherPlayerState.
CheckTopScore_CompareScoresLoop 42261 LD A,(DE) Fetch a byte of the current score.
42262 CP (HL) Compare it with the same byte of the other score.
42263 INC DE Move on to the next byte of each score.
42264 INC HL
42265 JR C,CheckTopScore_SecondPlayer Jump to CheckTopScore_SecondPlayer if the other score is higher.
42267 JR NZ,CheckTopScore_FirstPlayer Jump to CheckTopScore_FirstPlayer if the current score is higher.
42269 DJNZ CheckTopScore_CompareScoresLoop Loop back until all three bytes have been compared.
The other player has the higher score (or the two are equal).
CheckTopScore_SecondPlayer 42271 LD C,1 Set the winner to be player two.
42273 LD DE,41578 Point DE at OtherPlayerState.
Compare the winning score with the top score of the day.
CheckTopScore_CompareWithTopScore 42276 PUSH DE Stash the address of the winning score on the stack.
42277 LD HL,42450 Point HL at TopScore.
42280 LD B,3 Set the number of bytes in a score to three.
CheckTopScore_CompareWithTopScoreLoop 42282 LD A,(DE) Fetch a byte of the winning score.
42283 CP (HL) Compare it with the same byte of the top score.
42284 INC DE Move on to the next byte of each score.
42285 INC HL
42286 JR C,CheckTopScore_NotBeaten Jump to CheckTopScore_NotBeaten if the winning score is lower.
42288 JR NZ,CheckTopScore_Winner Jump to CheckTopScore_Winner if the winning score is higher.
42290 DJNZ CheckTopScore_CompareWithTopScoreLoop Loop back until all three bytes have been compared.
CheckTopScore_NotBeaten 42292 POP DE The top score has not been beaten, so discard the address of the winning score.
42293 JP RestartGame Restart the game from the title screen.
The current player has the higher score.
CheckTopScore_FirstPlayer 42296 LD C,0 Set the winner to be player one.
42298 LD DE,41559 Point DE at Bounty.
42301 JR CheckTopScore_CompareWithTopScore Join in with the comparison with the top score.
The top score has been beaten.
CheckTopScore_Winner 42303 LD A,C Fetch the winning player.
42304 ADD A,49 Convert it to the character for the player number.
42306 LD (42416),A Write it into the "PLAYER" text.
42309 LD E,0 Set the attribute to INK:BLACK, PAPER:BLACK.
42311 CALL SetAttributes Clear the attributes.
42314 CALL ClearScreen Clear the pixels of the screen.
42317 POP DE Retrieve the address of the winning score.
42318 LD HL,42450 Point HL at TopScore.
42321 LD B,3 Set the number of bytes in a score to three.
42323 CALL SwapBytes Swap the two scores, which stores the new top score.
42326 LD DE,42450 Point DE at TopScore.
42329 LD HL,42443 Point HL at ScoreMessages_ScoreDigits.
42332 CALL ConvertDigits Convert the score to digits.
Print the first line.
42335 LD HL,16519 Point HL at 16519 (in the screen buffer).
42338 LD DE,42397 Point DE at ScoreMessages.
42341 CALL PrintLargeText Print it in large letters.
Print the second line.
42344 LD HL,16616 Point HL at 16616 (in the screen buffer).
42347 LD DE,42408 Point DE at ScoreMessages_Player.
42350 CALL PrintLargeText Print it in large letters.
Print the third line.
42353 LD HL,18502 Point HL at 18502 (in the screen buffer).
42356 LD DE,42418 Point DE at ScoreMessages_TodaysTop.
42359 CALL PrintLargeText Print it in large letters.
Print the fourth line.
42362 LD HL,18600 Point HL at 18600 (in the screen buffer).
42365 LD DE,42430 Point DE at ScoreMessages_ScoreIs.
42368 CALL PrintLargeText Print it in large letters.
Print the fifth line.
42371 LD HL,20552 Point HL at 20552 (in the screen buffer).
42374 LD DE,42440 Point DE at ScoreMessages_Score.
42377 CALL PrintLargeText Print it in large letters.
42380 LD DE,45536 Point DE at FanfareTune.
42383 CALL PlayMusic Play the tune.
42386 LD B,4 Set the number of delay loops to four.
42388 LD HL,0 Set the length of each delay loop.
42391 CALL WaitForAWhile Wait for a while.
42394 JP RestartGame Restart the game from the title screen.
Prev: 42220 Up: Map Next: 42397