Finally got gosub working:
That took a long time to debug... this while statement originally had an issue in that depending on the values of Y and A it might fail to pull one of them from the stack, so the bug appeared depending exactly on the basic code I wrote.
Code: Select all
; while ((NULL != where) && (ERR_NONE == err));
lda err
bne gos_99 ; ERR_NONE == 0 so bne = an error
pla
sta maths1
ply
sty maths1+1 ; where is now in maths1
ora maths1+1 ; NULL?
beq gos_99 ; yup, break
lda maths1 ; Y:A should have 'where'
phy
pha
jmp gos_1
Can't help feeling there's a way to check that Y:A isn't zero without killing one or the other, or as I've done here, used a spare pair of variables. (gos_1 is above this and contains the bit where a line is interpreted by the gosub routine).
It might be that I can refactor the C version to check things in different places...
Neil