Prev: C000 Up: Map Next: C06E
C00C: Format the score and check the high-score table
Formats the 8-digit BCD 8002 (score_bcd) into an ASCII digit string with leading zeros blanked, then scans the 10-row high-score table at $C408 (33 bytes/row, score string first) to see whether the new score beats or ties an existing entry. Falls through into insert_high_score_entry on a hit, with the beaten row's address left on the stack.
Used by the routines at C000 and run_title_screen.
check_high_score C00C LD HL,$C580 Copy a 13-byte blank row template from $C580 to $C58D
C00F LD DE,$C58D
C012 LD BC,$000D
C015 LDIR
C017 LD BC,$0400 B = 4 BCD bytes to convert; C = 0 (no significant digit seen yet)
C01A LD DE,$8005 DE -> most significant byte of score_bcd
C01D LD HL,$C55F HL -> destination digit string
chs_digit_loop C020 LD A,(DE) A = next BCD byte (two digits)
C021 RLCA Rotate the byte left 4 times so the old high (tens) nibble ends up in the low 4 bits
C022 RLCA
C023 RLCA
C024 RLCA
C025 AND $0F A = tens digit of this byte
C027 JR NZ,chs_digit_nonblank Jump if the digit is non-zero
C029 RLC C Test the "significant digit seen" flag (all-$00 or all-$FF): carry = flag
C02B JR C,chs_digit_nonblank
C02D LD A,$20 Suppressed leading zero -> space
C02F JR chs_store_digit
chs_digit_nonblank C031 LD C,$FF Mark "significant digit seen" for the rest of the score
C033 ADD A,$30 Convert BCD digit to ASCII
chs_store_digit C035 LD (HL),A Store tens digit
C036 INC HL
C037 LD A,(DE) A = same BCD byte again
C038 AND $0F A = units digit of this byte
C03A JR NZ,check_high_score_0 Jump if the digit is non-zero
C03C RLC C Test the flag again
C03E JR C,check_high_score_0
C040 LD A,$20 Suppressed leading zero -> space
C042 JR check_high_score_1
check_high_score_0 C044 LD C,$FF Mark "significant digit seen"
C046 ADD A,$30 Convert BCD digit to ASCII
check_high_score_1 C048 LD (HL),A Store units digit
C049 INC HL
C04A DEC DE Move to the next (less significant) BCD byte
C04B DJNZ chs_digit_loop Loop for all 4 bytes (8 digits total)
chs_row_loop C04D LD DE,$C408 DE -> first row of the 10-row high-score table
C050 LD C,$0A C = 10 rows left to check
check_high_score_2 C052 PUSH DE Save this row's address
C053 LD B,$08 B = 8 digits to compare
C055 LD HL,$C55F HL -> new score's digit string
chs_digit_cmp C058 LD A,(DE) A = table entry's digit
C059 CP (HL) Compare against the new score's digit
C05A JR C,insert_high_score_entry Table digit < new digit -> new score beats this entry
C05C JR NZ,chs_row_beaten Table digit > new digit -> this entry still outranks it
C05E INC HL Digits equal -> compare the next pair
C05F INC DE
C060 DJNZ chs_digit_cmp
C062 JR insert_high_score_entry All 8 digits equal -> treat as beating this entry too
chs_row_beaten C064 POP HL HL = this row's address
C065 LD DE,$0021 Row stride is 33 bytes
C068 ADD HL,DE Advance to the next row
C069 EX DE,HL
C06A DEC C One row fewer to check
C06B JR NZ,check_high_score_2 Loop while rows remain
C06D RET New score doesn't make the top 10 -> return
Prev: C000 Up: Map Next: C06E