Pursuing Tom Ram

Game available in Itch.io.

Soruce code in Github.

Programming adventures in VIC-20.


A problem with the branches

Branch distance has a limit.

So, if you want to jump to a far memory position, you will get an error. That is a good new, because, in other case, you program will have an erratic behaviour when running.

My solution for this issue is (first) trying to reallocate the code (cut & paste), so the branch target is closer.

If I cannot do that, I branch to a jmp instruction. Jump instruct jumps to the subroutine too far from the branch.

Here you can see how the first branch (bcs) just to a jump the subroutine I want to execute.

  
Take_CMD
        ; Name is an item
        jsr Name_Is_Item
        bcs Take_P_Useless 

        ; Item is in current loc
        ;jsr Lda_Obj_Status
        ;cmp loc
        jsr Item_in_Loc
        bne Lbl_No_Item

        ;  I AM NOT SAVING SPECIAL BITS
        lda #LOC_INVENTORY
        sta obj_status,x
        ; Call inventory to confirm
        jsr Inventory_CMD
        rts

Lbl_No_Item
        lda #no_item
        jsr PRTSTR
        rts 


Take_P_Useless
        jmp P_Useless


  

I lose 3 bytes of memory but I have no a better solution so I am eager to listen to alternatives.