Prev: 28745 Up: Map Next: 28881
28815: Update High Score
Used by the routine at GameOver_ControllerRestart.
Finds the higher of the scores of the two players and, if that is higher than the high score at High_Score, makes it the new high score. The scores are stored as three BCD bytes with the most significant byte first.
UpdateHighScore 28815 LD HL,(24069) HL=the first two bytes of the score of 1UP.
28818 LD DE,(24072) DE=the first two bytes of the score of 2UP.
28822 LD A,L Swap H and L so that the most significant byte is in H.
28823 LD L,H
28824 LD H,A
28825 LD A,E Swap D and E so that the most significant byte is in D.
28826 LD E,D
28827 LD D,A
28828 AND A Compare the first two bytes of the scores.
28829 SBC HL,DE
28831 JR C,UpdateHighScore_2UP Jump to UpdateHighScore_2UP if 2UP has the higher score.
28833 JR NZ,UpdateHighScore_1UP Jump to UpdateHighScore_1UP if 1UP has the higher score.
28835 LD A,(24071) E=the last byte of the score of 1UP.
28838 LD E,A
28839 LD A,(24074) A=the last byte of the score of 2UP.
28842 CP E Compare the last bytes of the scores.
28843 JR C,UpdateHighScore_1UP Jump to UpdateHighScore_1UP if 1UP has the higher score.
UpdateHighScore_2UP 28845 LD HL,24072 HL=2UP_Score_1 (the score of 2UP).
UpdateHighScore_Compare 28848 PUSH HL Stash the pointer to the score on the stack.
28849 LD DE,24064 DE=High_Score (the high score).
28852 LD B,3 Set the byte counter to 3.
UpdateHighScore_Loop 28854 LD A,(DE) Jump to UpdateHighScore_Copy if the high score is lower than the score.
28855 CP (HL)
28856 JR C,UpdateHighScore_Copy
28858 JR NZ,UpdateHighScore_Done Jump to UpdateHighScore_Done if the high score is higher than the score.
28860 INC HL Move onto the next byte of each.
28861 INC DE
28862 DJNZ UpdateHighScore_Loop Decrease the byte counter by one and loop back to UpdateHighScore_Loop until all three bytes have been compared.
UpdateHighScore_Done 28864 POP HL Restore the pointer from the stack.
28865 RET Return.
UpdateHighScore_Copy 28866 POP HL Restore the pointer from the stack.
28867 LD DE,24064 DE=High_Score (the high score).
28870 LD BC,3 BC=3.
28873 LDIR Copy the score to the high score.
28875 RET Return.
UpdateHighScore_1UP 28876 LD HL,24069 HL=1UP_Score_1 (the score of 1UP).
28879 JR UpdateHighScore_Compare Jump to UpdateHighScore_Compare.
Prev: 28745 Up: Map Next: 28881