There are several parameter passing options on the 6502, but no single obvious standard.
Here are some samples.
I assume a 2byte scratch variable "tmp" in zero page. As you've noticed, a pointer variable needs to be in zero page to use "lda (tmp),y".
Load the A, X, & Y registers with parameters before doing the jsr:
Code:
doSomething: ; expects a pointer in YA (hi byte in Y, lo byte in A)
sta 0+tmp ;save the pointer in a direct page temp variable
sty 1+tmp
ldy #0 ;access 1st byte of pointed-to data
lda (tmp),y
...
rts
-----
lda #<dat1
ldy #>dat1
jsr doSomething
...
dat1: .byte $12,$23,$34,$45
Inline data after the jsr:
Code:
doSomething: ; expects inline data
pla ;tmp=rts_address popped from the stack
sta 0+tmp ; the rts address points to the last byte of the jsr
pla
sta 1+tmp
; tsx ;or stack entries can be accessed withuot popping them
; lda $101,x ;tmp=rts_addr
; sta 0+tmp
; lda $102,x
; sta 1+tmp
ldy #1 ;access 1st byte of pointed-to data
lda (tmp),y
...
; return, skipping the inline data
clc
lda 0+tmp
adc #4
tay
lda 1+tmp
adc #0
pha
tya
pha
rts
------
jsr doSomething
.byte $12,$23,$34,$45
jsr doSomething
.byte $23,$34,$45,$56
Pushing parameters on the stack before the jsr:
Code:
doSomething: ; expects a pointer on the stack
;stack layout:
; .word param1
; .word rts_addr
; S -->
tsx ;tmp=param1
lda $103,x
sta 0+tmp
lda $104,x
sta 1+tmp
lda #0 ;access 1st byte of data pointed-to by param1
lda (tmp),y
...
rts
-----
lda #>dat1 ;push pointer to dat1
pha
lda #<dat1
pha
jsr doSomething
pla ;clean up stack
pla
...
lda #>dat2 ;push pointer to dat2
pha
lda #<dat2
pha
jsr doSomething
pla ;clean up stack
pla
...
dat1: .byte $12,$23,$34,$45
dat2: .byte $23,$34,$45,$56
Using predefined variables:
Code:
doSomething: ; expects pointer in direct page location parm1
ldy #0 ;access 1st byte of data pointed-to by param
lda (parm1),y
...
rts
-----
lda #<dat1 ;parm1=&dat1
sta 0+parm1
lda #>dat1
sta 1+parm1
jsr doSomething
...
lda #>dat2 ;parm1=&dat2
sta 0+parm1
lda #<dat2
sta 1+parm1
jsr doSomething
...
dat1: .byte $12,$23,$34,$45
dat2: .byte $23,$34,$45,$56
Using a parameter software stack (borrowed from Forth):
Code:
doSomething: ; expects a pointer to data on the parameter stack
ldx ParmStkPtr
lda 0+ParmStk,x ;tmp=top of parameter stack
sta 0+tmp
lda 1+ParmStk,x
sta 1+tmp
inx ;pop parameter stack
inx
stx ParmStkPtr
ldy #0 ;access 1st byte of data pointed-to by param
lda (tmp),y
...
rts
-----
lda #>dat1 ;push &dat1 on ParmStk
ldy #<dat1
ldx ParmStkPtr
dex
dex
sta 0+ParmStk,x
sty 1+ParmStk,x
jsr doSomething
...
dat1: .byte $12,$23,$34,$45
And I'm sure there are more possibilities.