Pursuing Tom Ram

Game available in Itch.io.

Soruce code in Github.

Programming adventures in VIC-20.


Printing objects

If there are objects in the room, and they are not hidden, I want to tell that to my player.

I made a big mess managing objects in this game. I will tell you my mistakes so you can avoid them.

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.

I have groups all sections related to objects together. So I will not explain you the code to print objects (and the code for the command Inventory) here, but in a following section. Anyway, here you have the code, you can start to read the comments.

  
;-------------------
PrintObjs
        ; Using the Input buffer as temporal storing
        ; for a subroutine
        lda #see_object
        sta INPUT_BUFFER+1

        lda loc
        sta P0_TMP_BYTE

; Inventory command reuse this entry.
Inventory_Entry 
        ; Prepare the callback for the subroutine
        lda #C_Print_Item
        sta P0_TMP_B
        
        jsr F_Search_Object
        rts

; Callback
C_Print_Item
; If an object is found in the loc, 
; this subroutine prints the message in INPUT_BUFFER

        ; Item found in loc
        ; Print item name
        ; Remember, if you store memory addresses, 
        ; you multiply index by 2.
        ; x = (loc*2) 
        
        asl
        pha

        ; Print the string stored in input buffer
        ldy INPUT_BUFFER+1
        lda INPUT_BUFFER
        ; Take care, this subroutine changes the 
        ; three registers
        JSR PRTSTR 
      
        pla
        tax

        ; Prints the name of the object
        ldy obj_list,x+1
        lda obj_list,x 
        JSR PRTSTR
        
        lda #RETURN
        jsr CHROUT

        ; Jump back to the subroutine      
        jmp F_SO_Back