Prev: 62277 Up: Map Next: 62480
62399: Compare High Scores
Compare the 3-byte score in DE against the table at High_Score and return the insert rank in B.
Input
DE Pointer to the 3-byte score to test
Output
B Rows from the insert point (8 = top) or 0 if too low
Walk the eight high-score rows and return the insert rank.
CompareHighScores 62399 LD B,8 Set a rank counter in B for 8 loops.
62401 PUSH DE Stash the score pointer on the stack.
62402 LD HL,24070 HL=High_Score.
Compare the first byte of the score with the table row.
CompareHighScores_Loop 62405 LD C,(HL) Fetch the table byte.
62406 LD A,(DE) Fetch the score byte.
62407 CP C Jump to CompareHighScores_SecondByte if the bytes match.
62408 JP Z,CompareHighScores_SecondByte
62411 JP NC,CompareHighScores_InsertScore Jump to CompareHighScores_InsertScore if the score is higher.
Move the table pointer on to the next row.
62414 INC HL Advance the table pointer.
CompareHighScores_AdvanceTable 62415 INC HL Advance the table pointer.
CompareHighScores_NextRank 62416 INC HL Advance the table pointer.
62417 DJNZ CompareHighScores_Loop Decrease the rank by one and jump back to CompareHighScores_Loop until it is zero.
Return with B zero as the score is too low.
62419 POP DE Restore the score pointer from the stack.
62420 RET Return.
Compare the second bytes when the first bytes match.
CompareHighScores_SecondByte 62421 INC DE Advance the score pointer.
62422 INC HL Advance the table pointer.
62423 LD C,(HL) Fetch the table byte.
62424 LD A,(DE) Fetch the score byte.
62425 CP C Jump to CompareHighScores_ThirdByte if the bytes match.
62426 JP Z,CompareHighScores_ThirdByte
62429 JP NC,CompareHighScores_InsertScore Jump to CompareHighScores_InsertScore if the score is higher.
62432 DEC DE Rewind the score pointer.
62433 JR CompareHighScores_AdvanceTable Jump to CompareHighScores_AdvanceTable.
Compare the third bytes when the second bytes match.
CompareHighScores_ThirdByte 62435 INC HL Advance the table pointer.
62436 INC DE Advance the score pointer.
62437 LD C,(HL) Fetch the table byte.
62438 LD A,(DE) Fetch the score byte.
62439 CP C Jump to CompareHighScores_RewindScore if the bytes match.
62440 JR Z,CompareHighScores_RewindScore
62442 JR NC,CompareHighScores_InsertScore Jump to CompareHighScores_InsertScore if the score is higher.
Rewind the score pointer and try the next row.
CompareHighScores_RewindScore 62444 DEC DE Rewind the score pointer by two bytes.
62445 DEC DE
62446 JP CompareHighScores_NextRank Jump to CompareHighScores_NextRank.
Shuffle the table and insert the new score when HighScore_PlayerCopy is set.
CompareHighScores_InsertScore 62449 LD DE,24094 DE=24094.
62452 POP HL Restore the score pointer from the stack.
62453 LD A,(24180) Fetch HighScore_PlayerCopy.
62456 AND A Return if it is zero.
62457 RET Z
Work out how many bytes lie below the insert row.
62458 PUSH BC Stash the rank and score pointer on the stack.
62459 PUSH HL
62460 LD HL,24091 HL=24091.
62463 LD A,B Copy the rank into A.
62464 SLA A Double it.
62466 ADD A,B Add the original rank.
62467 LD C,A Copy the byte count into C.
62468 LD B,0 Clear B.
62470 LDDR Shuffle the lower scores down.
Copy the new score into the freed row.
62472 POP HL Restore the score pointer from the stack.
62473 LD BC,3 Copy the new 3-byte score into the table.
62476 LDIR
62478 POP BC Restore the rank from the stack.
62479 RET Return.
Prev: 62277 Up: Map Next: 62480