Pursuing Tom Ram

Game available in Itch.io.

Soruce code in Github.

Programming adventures in VIC-20.


Printing things

As you now, there is a very good print routine in the BASIC Rom, so problem solved. But, how can I know in which location is the player and which is the text to print? With an index.

In the code, “loc” is the memory address where I store the location of the player.

If you look at the end of the code, you will find that I store all the descriptions of the locations in a vector (called desc_list). When I access this vector with the index (loc “variable”), I have the description of the location.

What I really store in the vector is the memory address of the description. Each memory address has two bytes (in almost every 8 bit computers and, of course, in all commodore computers). So, I have to multiply the index by two to obtain the proper index (description for loc 0 is in 0, 1 positions, description of the loc 1 is in 2, 3 positions, description of loc 2 is in 4, 5 positions, etc.).

One more thing. Commodore computers (and almost every 8 bit computer) is little endian. This means that they store first the lower byte of a memory address. Therefore, memory address $1E00 is stores 00, 1E in memory.

For that reason, the first byte I read goes into a, and the second one goes into y

  
;-------------------
PrintLoc
        ; clear screen
        jsr CLEAR

        ; print 'you are in the '
        lda #you_are
        JSR PRTSTR

        ; Search position ind escription vector 
        ; for current loc
        lda loc
        ; Multiply loc by 2 to obtain index
        ; x = (loc*2)
        asl
        tax
        ; Remembre.
        ; Before calling prntstr, low byte goes in a
        ; High byte goes in y.
        lda desc_list,x
        ldy desc_list,x+1
        JSR PRTSTR

        ; Descriptions are stored without carryage return
        ; So I print the carryage return character
        lda #RETURN
        jsr PRINT_CHAR
        rts

  

Remember this section because I will use vectors with memory address more times in the future.