Saturday 13 December 2014

Rocket Raid Under the Hood 10: Hall Of Fame (cont.)

This is the tenth part in a series of posts on digging into the code of the Acornsoft side-scrolling arcade game, Rocket Raid.

Displaying the Hall of Fame

In the last post, we looked at the screen which prompts a user to enter their name if they have achieved a high score at the end of a game. This time we will look at the straight-forward code which displays the Hall of Fame chart itself.

For each row in the table, the code logic prints the rank number (1-8) followed by four dots ("....") and then the score. Any leading zeroes in the score are displayed as a dot. Four more dots are placed to separate the name from the score.

The X register is used as an offset for the score and name look-up tables. Since the tables are stored in memory from lowest score to highest, X is initially set to point to the last entry and is decreased to move to the next rank entry.


Hall of Fame screen

BeebDis labels:
hallOfFameText $0486
hallOfFame $0605
printHighScoreTable $0619
printFourDots $06C2
moveDownOneLine $06C4
videoController $1C40

Disassembly:

.hallOfFameText
        EQUS    $16,$07                     ; MODE 7
        EQUS    $1F,$06,$01                 ; Move cursor to (6,1)
        EQUS    $81,$8D                     ; Double-height, red text
        EQUS    "Rocket Raid Hall Of Fame"
        EQUS    $1F,$06,$02                 ; Move cursor to (6,2)
        EQUS    $81,$8D                     ; Double-height, red text
        EQUS    "Rocket Raid Hall Of Fame"
        EQUS    $0A,$0A,$0A                 ; Move down 3 lines
        EQUS    $0D                         ; End of text

.pressSpaceText
        EQUS    $1F,$05,$16                 ; Move cursor to (5,22)
        EQUS    "Press SPACE BAR or Fire Button"
        EQUS    $1F,$0A,$17                 ; Move cursor to (10,23)
        EQUS    "On Joystick To Start"
        EQUS    $0D                         ; End of text

.hallOfFame
        LDX     #$86            ; 
        LDY     #$04            ; Point to hallOfFameText (&0486)
        JSR     printAtomString ; Print Hall of Fame heading

        LDX     #$0A            ; Select video controller register 10

                                ; (controls the cursor format)
        LDA     #$20            ; Want to set bit 6 (hide cursor)
        JSR     videoController ; Equivalent of VDU23,0,10,32;0;0;0

        LDX     #$18            ; Set X=24 (offset to rank 1 of score table)

        LDY     #$01            ;
        STY     temp            ; Set temp=1 (temp holds current rank)
.printHighScoreTable
        LDA     #$20            ; (not needed?)
        JSR     moveDownOneLine ; Move to next line

        LDA     temp            ;

        ORA     #$30            ; A=48+temp (i.e. ASCII value of 1, 2, 3...)
        JSR     OSWRCH          ; Print rank number

        JSR     printFourDots   ; Print four dots


        LDY     #$FF            ; Set leading zero flag

        LDA     scoreLadder+2,X ; Get top byte of score (BCD)
        JSR     printBCDNumber  ; Print highest two digits of score
        LDA     scoreLadder+1,X ; Point to next byte of score (BCD)
        JSR     printBCDNumber  ; Print next-highest digits
        LDA     scoreLadder,X   ; Point to last byte of score (BCD)
        JSR     printBCDNumber  ; Print lowest two digits.

        JSR     printFourDots   ; Print four dots


        TXA                     ;

        PHA                     ; Store current table offset on stack
        LDA     nameLookup+1,X  ;
        TAY                     ; Get MSB of name address from look-up table
                                ; i.e. Y=?(nameLookup+1+X)
        LDA     nameLookup,X    ; Get LSB of name address from look-up table
                                ; i.e. X=?(nameLookup+X)
        TAX                     ; 
        JSR     printAtomString ; Print the name
        PLA                     ;
        TAX                     ; Retrieve current table offset from stack

        LDA     #$0A            ; ASCII 10 = move to next line
        JSR     OSWRCH          ;
        JSR     OSWRCH          ; Move down two lines

        INC     temp            ; Increase rank counter

        DEX                     ;
        DEX                     ;
        DEX                     ; Decrease look-up index to next rank in table
        BNE     printHighScoreTable ; Look back until all ranks printed

        LDX     #$C6            ;

        LDY     #$04            ; Point to pressSpaceText (&04C6)
        JSR     printAtomString ; Print "Press SPACE BAR" text

The above code calls a short routine that affects the video controller hardware (a 6845 chip named Sheila) by passing the appropriate register number and value, in order to turn off the cursor. This is more efficient than calling OSWRCH several times to achieve the same result.

; update video controller (crtc)
; Pass register number in X, register value to set in A
; (equivalent of VDU23;X,A,0;0;0;)
.videocontroller
        STX FE00                 ; write to video controller (register number)
        STA FE01                 ; write to video controller (register value)
        RTS                      


No comments:

Post a Comment