I think ive made sense of this, i ws looking at LINE from a more modern approach as
function LINE {
bla bla;
return
}
and expecting it to function like this. Its just how most are wired to program and its difficult to work
in a different fashion
Ill give it another go and see what I get ill post my results
return many thanks;
Migration from TFC3 to Relaunch64
Re: Migration from TFC3 to Relaunch64
Melon wrote:Code is executed in a specific order, from top to bottom. In your example below, your RTS and the end of your LINE routeing ReTurns from Subroutine and this is why your being dropped back to basic. TSTLINE is never reached as there are no JSR TSTLINE included in your code, Jump SubRoutine.
STARTBOTTOMLINE
ldy #$0 ; Y coordunate for cursor
ldx #$14 ; X coordinate for cursor
clc ; carry
jsr $fff0 ; move cursor
ldx #$00 ; let X=0
LINE
lda #$64
jsr $ffd2
inx ; X=X+1
cpx #$28 ; does X = hex 28
bne LINE ; branch to LINE of not 28
rts
TSTLINE
ldy #$0 ; Y coordunate for cursor
ldx #$8 ; X coordinate for cursor
clc ; carry
jsr $fff0 ; move cursor
ldx #$00 ; let X=0
jsr LINE
END
rts
ldy #$00 ; Y coordunate for cursor
ldx #$14 ; X coordinate for cursor
clc ; carry
jsr $fff0 ; move cursor
ldx #$00 ; let X=0
jsr line
ldy #$00 ; Y coordunate for cursor
ldx #$08 ; X coordinate for cursor
clc ; carry
jsr $fff0 ; move cursor
ldx #$00 ; let X=0
jsr LINE
rts
LINE
lda #$64
jsr $ffd2
inx ; X=X+1
cpx #$28 ; does X = hex 28
bne LINE ; branch to LINE of not 28
rts
What if I wanted to use the LINE code later and jump to it, then continue the code from where it was called, wouldnt rts do that if the code was called from JSR and put its location on the stack?
Re: Migration from TFC3 to Relaunch64
That sounds right. LINE is then commonly called a subroutine. It's the ideal way to use a piece of code many times. I may have missed it in all the posted code, so please forgive me if I'm late on this, but it is important to note the the kernal plot call ($FFF0) is reversed with its X and Y coordinates relative to how we normally work with screen coordinates. X is Y and Y is X.What if I wanted to use the LINE code later and jump to it, then continue the code from where it was called, wouldnt rts do that if the code was called from JSR and put its location on the stack?
Re: Migration from TFC3 to Relaunch64
but the subroutine should end with rts and rts is taking me back to basic. so Im stuck.
Re: Migration from TFC3 to Relaunch64
You want to end every subroutine with an rts. What might be happening here is that your code is executing properly (all the way through) and you need it to stop somehow.jrubin wrote:but the subroutine should end with rts and rts is taking me back to basic. so Im stuck.
Try adding this right before the end of the main part of your program. It calls a kernal routine to get a keypress. You can actually insert something like this anywhere you need things to stop and wait for some input. You can trap more than one key by adding additional comparisons in the same way.
Code: Select all
GetaKey jsr $ffe4 ;call kernal GETIN
beq GetaKey ;returns when a key is pressed
;rts (put this here if no other comparisons are done)
Code: Select all
cmp #32 ;wait until <space> is pressed
bne GetaKey ;if not a <space> it goes back to the wait loop
rts ;finally exits when <space> is pressed
Attached below is a subroutine that waits for a keypress from the first book I mentioned. It explains what it does very well. BTW, the addresses for GETIN and the others are in decimal, but GETIN = $FFE4. one thing I very seldom do is clear location 198 like they do, but doing so prevents errant keypresses from showing up (too fast for you to catch) before you are ready.
Who is online
Users browsing this forum: No registered users and 2 guests