Prev: 62270 Up: Map Next: 62399
62277: Insert High Score
Open a slot in the name table at HallOfFame_Names, copy the new 3-letter name from HallOfFame_Name, then insert the matching score into High_Score.
If the other player also made the table, rank their score too and start name entry for them.
DE is the byte after the name table and HL is three bytes before that, so copying backwards moves each byte on by three bytes, which is one name row.
InsertHighScore 62277 LD DE,24120 DE=HallOfFame_NameEnd.
62280 LD HL,24117 HL=HallOfFame_LastName.
Work out how many bytes lie from the insert row down. HighScorePosition holds 8 minus the rank, so this gives back the row count that CompareHighScores returned in B (8 is first place).
62283 LD A,(24183) Fetch HighScorePosition.
62286 NEG Negate it.
62288 ADD A,8 Add 8.
62290 LD B,A Copy the row count into B.
62291 SLA A Double it.
62293 ADD A,B Add the original count.
62294 LD C,A Copy the byte count into C.
62295 LD B,0 Clear B.
Move the names from the insert row down one row. The old last name is overwritten, and DE is left pointing at the freed slot.
62297 LDDR Shuffle the table down.
Copy the new name into the freed slot.
62299 LD HL,24184 HL=HallOfFame_Name.
62302 LD BC,3 Copy the new 3-byte name into the table.
62305 LDIR
Note which player is being ranked. This also acts as the insert flag for CompareHighScores, as it is never zero for 1UP or 2UP.
62307 LD A,(24177) Fetch HighScore_Player.
62310 LD (24180),A Write it to HighScore_PlayerCopy.
Pick the score of the player who has just entered a name.
62313 CP 1 Jump to InsertHighScore_1UP if this is 1UP.
62315 JR Z,InsertHighScore_1UP
62317 LD DE,24162 DE=2UP_Score_1.
62320 JR InsertHighScore_Compare Jump to InsertHighScore_Compare.
InsertHighScore_1UP 62322 LD DE,24159 DE=1UP_Score_1.
Insert the score into the table at the rank found by CompareHighScores.
InsertHighScore_Compare 62325 CALL CompareHighScores Call CompareHighScores.
Check whether the other player also needs a name. HighScore_OtherPlayer holds the number of the other player, or zero if there is nobody else waiting.
62328 LD A,(24178) Fetch HighScore_OtherPlayer.
62331 AND A Jump to ReturnToRestart if the other player is not pending.
62332 JP Z,ReturnToRestart
Send 2UP to its own handling, otherwise it is 1UP.
62335 CP 2 Jump to InsertHighScore_2UPPending if the other player is 2UP.
62337 JP Z,InsertHighScore_2UPPending
Switch to the pending 1UP score and compare it with the table.
62340 LD (24177),A Write it to HighScore_Player.
62343 XOR A Write 0 to HighScore_OtherPlayer.
62344 LD (24178),A
Clearing HighScore_PlayerCopy means that CompareHighScores only returns the rank and leaves the table alone. The score is inserted later, once this player has entered a name.
62347 LD DE,24159 DE=1UP_Score_1.
62350 LD (24180),A Write 0 to HighScore_PlayerCopy.
62353 CALL CompareHighScores Call CompareHighScores.
Restart if the score is too low, otherwise start name entry.
62356 LD A,B Jump to ReturnToRestart if the score is not high enough.
62357 AND A
62358 JP Z,ReturnToRestart
62361 CALL PrepareNameEntry Call PrepareNameEntry.
62364 JP StartNameEntry Jump to StartNameEntry.
Switch to the pending 2UP score and compare it with the table.
InsertHighScore_2UPPending 62367 LD (24177),A Write it to HighScore_Player.
62370 XOR A Write 0 to HighScore_OtherPlayer.
62371 LD (24178),A
As above, only rank the score; it is inserted after name entry.
62374 LD DE,24162 DE=2UP_Score_1.
62377 LD (24180),A Write 0 to HighScore_PlayerCopy.
62380 CALL CompareHighScores Call CompareHighScores.
Restart if the score is too low.
62383 LD A,B Jump to ReturnToRestart if the score is not high enough.
62384 AND A
62385 JP Z,ReturnToRestart
Make 2UP the active player and start name entry.
62388 LD A,1 Write 1 to Flag_ActivePlayer.
62390 LD (24165),A
62393 CALL PrepareNameEntry Call PrepareNameEntry.
62396 JP StartNameEntry Jump to StartNameEntry.
Prev: 62270 Up: Map Next: 62399