← B37A Add the pending score to the displayed score Map B3FD → High-score overtake flag
B396: Add the points to the score and redraw it
Adds this frame's points into the on-screen score and redraws it. Once the live score reaches the top high-score figure, the overtake flag goes up. The stored high-score number is not changed here.
Input
C score increment in units of 10 points
add_points_to_score B396 LD HL,score_units Point at the score's units digit and clear its terminator bit before the edit.
B399 RES 7,(HL)
The score is eight ASCII decimal digits, most significant first. The last digit is never touched and stays '0'. The score is therefore always a multiple of 10, and each point count is worth ten times its value.
score_bump_thousands B39B LD HL,score_thousands Re-point at the thousands digit and bump it once per full hundred taken off C.
B39E LD A,C
B39F SUB $64
B3A1 JR C,score_to_hundreds
B3A3 LD C,A
B3A4 CALL inc_score_digit
B3A7 JR score_bump_thousands
score_to_hundreds B3A9 INC HL Advance to the hundreds place.
score_bump_hundreds B3AA LD A,C Bump the hundreds digit once per full ten taken off C.
B3AB SUB $0A
B3AD JR C,score_to_tens
B3AF LD C,A
B3B0 CALL inc_score_digit
B3B3 JR score_bump_hundreds
score_to_tens B3B5 INC HL Advance to the tens place.
score_bump_tens B3B6 LD A,C Bump the tens digit once per unit taken off C; the units digit stays '0'.
B3B7 OR A
B3B8 JR Z,score_redraw
B3BA SUB $01
B3BC LD C,A
B3BD CALL inc_score_digit
B3C0 JR score_bump_tens
score_redraw B3C2 LD HL,score_units Restore the terminator bit, then print the live score double-height at the score readout.
B3C5 SET 7,(HL)
B3C7 LD HL,loading_screen
B3CA LD DE,score_display
B3CD PUSH DE
B3CE LD C,$47
B3D0 CALL print_string_2x
B3D3 POP DE
QUIRK: during the compare the live score's last digit carries the print terminator flag, which the high-score number's plain digits lack. The last digit is therefore never found equal, and the all-digits-equal exit is unreachable. A tie with the high score counts as an overtake.
B3D4 LD HL,highscore_entries Compare the live score digits against the high-score number, most significant digit first.
B3D7 LD B,$08
score_overtake_loop B3D9 LD A,(DE) Test one digit pair; equal advances, live-below stops, live-above is an overtake.
B3DA CP (HL)
B3DB JR Z,score_overtake_next
B3DD JR NC,score_overtake_set
B3DF XOR A Live score is below the high score: clear the overtake flag and stop.
B3E0 LD (highscore_passed),A
B3E3 RET
score_overtake_next B3E4 INC HL Digits equal so far: advance to the next pair.
B3E5 INC DE
B3E6 DJNZ score_overtake_loop
B3E8 XOR A All 8 digits equal: clear the overtake flag and stop. Unreachable – see the quirk note.
B3E9 LD (highscore_passed),A
B3EC RET
score_overtake_set B3ED LD A,$01 Live score has reached or passed the high score: set the flag and redraw the high-score readout on screen from the live score.
B3EF LD (highscore_passed),A
B3F2 LD HL,score_readout
B3F5 LD DE,score_display
B3F8 LD C,$47
B3FA JP print_string_2x
← B37A Add the pending score to the displayed score Map B3FD → High-score overtake flag
Fork me on GitHub