Prev: F345 Up: Map Next: F410
F3BF: 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 (08 = top) or 00 if too low
Walk the eight high-score rows and return the insert rank.
CompareHighScores F3BF LD B,$08 Set a rank counter in B for 08 loops.
F3C1 PUSH DE Stash the score pointer on the stack.
F3C2 LD HL,$5E06 HL=High_Score.
Compare the first byte of the score with the table row.
CompareHighScores_Loop F3C5 LD C,(HL) Fetch the table byte.
F3C6 LD A,(DE) Fetch the score byte.
F3C7 CP C Jump to CompareHighScores_SecondByte if the bytes match.
F3C8 JP Z,CompareHighScores_SecondByte
F3CB JP NC,CompareHighScores_InsertScore Jump to CompareHighScores_InsertScore if the score is higher.
Move the table pointer on to the next row.
F3CE INC HL Advance the table pointer.
CompareHighScores_AdvanceTable F3CF INC HL Advance the table pointer.
CompareHighScores_NextRank F3D0 INC HL Advance the table pointer.
F3D1 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.
F3D3 POP DE Restore the score pointer from the stack.
F3D4 RET Return.
Compare the second bytes when the first bytes match.
CompareHighScores_SecondByte F3D5 INC DE Advance the score pointer.
F3D6 INC HL Advance the table pointer.
F3D7 LD C,(HL) Fetch the table byte.
F3D8 LD A,(DE) Fetch the score byte.
F3D9 CP C Jump to CompareHighScores_ThirdByte if the bytes match.
F3DA JP Z,CompareHighScores_ThirdByte
F3DD JP NC,CompareHighScores_InsertScore Jump to CompareHighScores_InsertScore if the score is higher.
F3E0 DEC DE Rewind the score pointer.
F3E1 JR CompareHighScores_AdvanceTable Jump to CompareHighScores_AdvanceTable.
Compare the third bytes when the second bytes match.
CompareHighScores_ThirdByte F3E3 INC HL Advance the table pointer.
F3E4 INC DE Advance the score pointer.
F3E5 LD C,(HL) Fetch the table byte.
F3E6 LD A,(DE) Fetch the score byte.
F3E7 CP C Jump to CompareHighScores_RewindScore if the bytes match.
F3E8 JR Z,CompareHighScores_RewindScore
F3EA JR NC,CompareHighScores_InsertScore Jump to CompareHighScores_InsertScore if the score is higher.
Rewind the score pointer and try the next row.
CompareHighScores_RewindScore F3EC DEC DE Rewind the score pointer by two bytes.
F3ED DEC DE
F3EE JP CompareHighScores_NextRank Jump to CompareHighScores_NextRank.
Shuffle the table and insert the new score when HighScore_PlayerCopy is set.
CompareHighScores_InsertScore F3F1 LD DE,$5E1E DE=5E1E.
F3F4 POP HL Restore the score pointer from the stack.
F3F5 LD A,($5E74) Fetch HighScore_PlayerCopy.
F3F8 AND A Return if it is zero.
F3F9 RET Z
Work out how many bytes lie below the insert row.
F3FA PUSH BC Stash the rank and score pointer on the stack.
F3FB PUSH HL
F3FC LD HL,$5E1B HL=5E1B.
F3FF LD A,B Copy the rank into A.
F400 SLA A Double it.
F402 ADD A,B Add the original rank.
F403 LD C,A Copy the byte count into C.
F404 LD B,$00 Clear B.
F406 LDDR Shuffle the lower scores down.
Copy the new score into the freed row.
F408 POP HL Restore the score pointer from the stack.
F409 LD BC,$0003 Copy the new 03-byte score into the table.
F40C LDIR
F40E POP BC Restore the rank from the stack.
F40F RET Return.
Prev: F345 Up: Map Next: F410