Prev: 46588 Up: Map Next: 46763
46622: Enter High Score
Used by the routine at NewHighScore.
Works out whether a score is high enough to go in the hall of fame. If it is then every entry below it is moved down a place, the score is put in the gap and the player is asked to register their initials (see EnterInitials).
The number of places that the score beat is stored in HighScorePosition, so 1 means that the score only beat the sixth place and 6 means that it is the new top score.
Before After NewHighScore_Enter
enter-high-score-before enter-high-score-after
Input
HL Pointer to the score of the player
NewHighScore_Enter 46622 PUSH DE Stash the score pointers on the stack.
46623 PUSH HL Stash HL on the stack.
We hold six high scores. Start at the sixth one and compare it to the score, moving up while the score is greater.
46624 LD B,6 Set the number of high scores in B to 6.
46626 LD DE,45858 Point DE at the sixth high score at Pos_6_HighScore_1.
NewHighScore_Position_Loop 46629 CALL NewHighScore_Compare Compare the high score with the score of the player.
46632 JR NC,NewHighScore_PositionFound Jump to NewHighScore_PositionFound if the high score is not lower than the score of the player.
46634 CALL NewHighScore_Next Move back to the previous high score.
46637 DJNZ NewHighScore_Position_Loop Decrease the high score counter by one and loop back to NewHighScore_Position_Loop until all of the high scores have been checked.
NewHighScore_PositionFound 46639 LD A,B Fetch the position of the first high score that was not beaten.
46640 CP 6 Jump to NewHighScore_Finish if the score did not beat any of the high scores.
46642 JR Z,NewHighScore_Finish
Move the entries down. The sixth entry moves into the buffer at New_HighScore_1.
46644 LD HL,45858 Point HL at the sixth high score at Pos_6_HighScore_1.
46647 LD DE,45864 Point DE at the new high score buffer at New_HighScore_1.
46650 LD A,B Fetch the position of the first high score that was not beaten.
46651 NEG Negate the position.
46653 ADD A,6 A=A+6 (the number of places beaten).
46655 LD (38587),A Store the result at HighScorePosition.
NewHighScore_Move_Loop 46658 LD BC,6 Set the size of a high score entry in BC to 6.
46661 PUSH HL Stash the pointer to the high score on the stack.
46662 LDIR Copy the high score down one place.
46664 POP DE Restore the pointer to the high score into DE.
46665 LD L,E Copy the pointer into HL.
46666 LD H,D
46667 CALL NewHighScore_Next Move back to the previous high score.
46670 EX DE,HL Swap DE and HL so the pointers are one entry higher.
46671 DEC A Decrease the number of places beaten by one and loop back to NewHighScore_Move_Loop until all of the high scores have been moved down.
46672 JR NZ,NewHighScore_Move_Loop
Write the score into the gap.
46674 POP HL Restore the pointer to the score of the player from the stack.
46675 PUSH HL Stash the pointer to the score of the player on the stack again.
46676 LD BC,3 Set the number of bytes of the score in BC to 3.
46679 LDIR Copy the score into the hall of fame.
46681 PUSH DE Stash the pointer to the initials on the stack.
46682 CALL Score_HI Print the new high score.
46685 LD A,(38586) Jump to NewHighScore_Update_ClearPanel if the hall of fame has already been shown.
46688 AND A
46689 JR NZ,NewHighScore_Update_ClearPanel
46691 INC A Set the hall of fame updated flag.
46692 LD (38586),A Store the flag in HallOfFameUpdated.
46695 LD HL,25030 Point HL at the room data at Room_Special_MainMenu.
46698 CALL DrawRoom Draw the room.
NewHighScore_Update_ClearPanel 46701 CALL HallOfFame_Clear Clear the panel.
Updates the text for the appropriate player number.
46704 LD A,(38558) Fetch the active player from Flag_ActivePlayer.
46707 AND A Is this 1UP or 2UP?
46708 LD A,177 A=177 (ASCII "1"+128).
46710 JR Z,NewHighScore_Update_Player Jump to NewHighScore_Update_Player if the current player is 1UP.
46712 INC A Else, A=178 (ASCII "2"+128).
Overwrite the copy:
Byte Copy
177 "PLAYER 1"
178 "PLAYER 2"
NewHighScore_Update_Player 46713 LD (46979),A Write A to 46979.
Work out which of the HighScore_Suffixes to use.
46716 LD A,(38587) Fetch the number of places beaten from HighScorePosition into B.
46719 LD B,A
46720 LD A,253 A=253 (as 253+3=0 - so the offset is then pointing at the base address).
NewHighScore_Suffix_Loop 46722 ADD A,3 Move onto the next suffix.
46724 DJNZ NewHighScore_Suffix_Loop Decrease the position counter by one and loop back to NewHighScore_Suffix_Loop until the offset has been found.
Fetch the appropriate position suffix.
46726 LD C,A Create an offset in BC.
46727 LD B,0
46729 LD HL,46789 HL=HighScore_Suffixes + offset.
46732 ADD HL,BC
46733 LD DE,47004 DE=47004.
46736 LD BC,3 BC=3 (counter).
Overwrite the copy:
Byte Copy
0 "TODAYS 6TH HIGHEST"
1 "TODAYS 5TH HIGHEST"
2 "TODAYS 4TH HIGHEST"
3 "TODAYS 3RD HIGHEST"
4 "TODAYS 2ND HIGHEST"
46739 LDIR Copy 3 bytes of data from HL to 47004.
Print the messaging to the screen.
46741 LD DE,46933 Point DE at the attributes of the lines of text at NewHighScore_Attributes.
46744 EXX Switch to the shadow registers.
46745 LD HL,46941 Point HL' at the positions of the lines of text at NewHighScore_Position.
46748 LD DE,46957 Point DE' at the lines of text at NewHighScore_Text.
There are eight lines of text.
46751 LD B,8 Set the number of lines of text in the shadow B register to 8.
46753 CALL GameMenu_Loop Print the lines of text.
46756 POP DE Restore the pointer to the initials from the stack.
46757 CALL EnterInitials Let the player enter their initials.
NewHighScore_Finish 46760 POP HL Restore the pointer to the score of the player from the stack.
46761 POP DE Restore DE from the stack.
46762 RET Return.
View the equivalent code in;
Prev: 46588 Up: Map Next: 46763