Lode Runner: Apple II reverse engineering

7. High scores#

For this routine, we have two indexes. The first is stored in HI_SCORE_INDEX and is the high score number, from 1 to 10. The second is stored in HI_SCORE_OFFSET and keeps our place in the actual high score data table stored at HI_SCORE_OFFSET.

There are ten slots in the high score table, each with eight bytes. The first three bytes are for the player initials, the fourth byte is the level – or zero if the row should be empty – and the last four bytes are the BCD-encoded score, most significant byte first.

⟨defines [314]⟩+=
HI_SCORE_INDEX      EQU     $55     ; aliased with TMP_GUARD_COL
HI_SCORE_OFFSET     EQU     $56     ; aliased with TMP_GUARD_ROW
Used in ⟨*⟩
Defines HI_SCORE_INDEX, HI_SCORE_OFFSET
⟨tables [316]⟩+=
    ORG     $1F00
HI_SCORE_DATA:
    HEX     D2 CC D0 06 00 03 10 75 A0 A0 A0 05 00 02 81 25
    HEX     A0 A0 A0 02 00 01 74 25 A0 A0 A0 01 00 00 54 25
    HEX     A0 A0 A0 01 00 00 19 75 A0 A0 A0 01 00 00 15 00
    HEX     00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    HEX     00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    HEX     00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    HEX     00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    HEX     00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    HEX     00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    HEX     00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    HEX     00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    HEX     00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    HEX     00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    HEX     00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    HEX     00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    HEX     00 00 00 00 CC CF C4 C5 A0 D2 D5 CE CE C5 D2 FF
Used in ⟨*⟩
Defines HI_SCORE_DATA
⟨construct and display high score screen [318]⟩=
Defines HI_SCORE_SCREEN
⟨draw high score table header [320]⟩=
    ; "    LODE RUNNER HIGH SCORES\r"
    ; "\r"
    ; "\r"
    ; "    INITIALS LEVEL  SCORE\r"
    ; "    -------- ----- --------\r"
    JSR     PUT_STRING
    HEX     A0 A0 A0 A0 CC CF C4 C5 A0 D2 D5 CE CE C5 D2 A0
    HEX     C8 C9 C7 C8 A0 D3 C3 CF D2 C5 D3 8D 8D 8D A0 A0
    HEX     A0 A0 C9 CE C9 D4 C9 C1 CC D3 A0 CC C5 D6 C5 CC
    HEX     A0 A0 D3 C3 CF D2 C5 8D A0 A0 A0 A0 AD AD AD AD
    HEX     AD AD AD AD A0 AD AD AD AD AD A0 AD AD AD AD AD
    HEX     AD AD AD 8D 00
⟨draw high score rows [322]⟩=
⟨draw high score row number [324]⟩=
    CMP     #$0A
    BNE     .display_0_to_9
    LDA     #1
    JSR     PUT_DIGIT
    LDA     #0
    JSR     PUT_DIGIT
    JMP     .rest_of_row_number

.display_0_to_9:
    LDA     #$A0
    JSR     PUT_CHAR        ; space
    LDA     HI_SCORE_INDEX
    JSR     PUT_DIGIT

.rest_of_row_number:
    ; ".    "
    JSR     PUT_STRING
    HEX     AE A0 A0 A0 A0 00
⟨tables [326]⟩+=
    ORG     $79A2
    ; Because table indices are 1-based, there's an extra 00
    ; at the beginning that never gets used.
HI_SCORE_TABLE_OFFSETS:
    HEX     00 00 08 10 18 20 28 30 38 40 48
Used in ⟨*⟩
Defines HI_SCORE_TABLE_OFFSETS
⟨draw high score initials [328]⟩=
    LDX     HI_SCORE_INDEX
    LDY     HI_SCORE_TABLE_OFFSETS,X
    STY     HI_SCORE_OFFSET
    LDA     HI_SCORE_DATA+3,Y
    BNE     .draw_initials
    JMP     .next_high_score_row
.draw_initials:
    LDY     HI_SCORE_OFFSET
    LDA     HI_SCORE_DATA,Y
    JSR     PUT_CHAR
    LDY     HI_SCORE_OFFSET
    LDA     HI_SCORE_DATA+1,Y
    JSR     PUT_CHAR
    LDY     HI_SCORE_OFFSET
    LDA     HI_SCORE_DATA+2,Y
    JSR     PUT_CHAR

    ; "    "
    JSR     PUT_STRING
    HEX     A0 A0 A0 A0 00
⟨draw high score level [330]⟩=
    LDY     HI_SCORE_OFFSET
    LDA     HI_SCORE_DATA+3,Y
    JSR     TO_DECIMAL3
    LDA     HUNDREDS
    JSR     PUT_DIGIT
    LDA     TENS
    JSR     PUT_DIGIT
    LDA     UNITS
    JSR     PUT_DIGIT

    ; "  "
    JSR     PUT_STRING
    HEX     A0 A0 00
⟨draw high score [332]⟩=
⟨next high score row [334]⟩=
.next_high_score_row:
    JSR     NEWLINE
    INC     HI_SCORE_INDEX
    LDA     HI_SCORE_INDEX
    CMP     #11
    BCS     .end
    JMP     .loop
⟨defines [336]⟩+=
TXTPAGE2                EQU     $C055
Used in ⟨*⟩
Defines TXTPAGE2
⟨show high score page [338]⟩=
.end:
    STA     TXTPAGE2        ; Flip to page 2
    LDA     #$20
    STA     DRAW_PAGE       ; Set draw page to 1
    RTS