Migration from TFC3 to Relaunch64

JMP $FCE2
jrubin
Member
Member
Posts: 59
Joined: Sun Jun 29, 2014 8:00 pm
Location: Florida
Contact:

Re: Migration from TFC3 to Relaunch64

Post by jrubin »

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;


jrubin
Member
Member
Posts: 59
Joined: Sun Jun 29, 2014 8:00 pm
Location: Florida
Contact:

Re: Migration from TFC3 to Relaunch64

Post by jrubin »

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.
BOTTOMLINE
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
START
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?
satpro

Re: Migration from TFC3 to Relaunch64

Post by satpro »

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?
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.
jrubin
Member
Member
Posts: 59
Joined: Sun Jun 29, 2014 8:00 pm
Location: Florida
Contact:

Re: Migration from TFC3 to Relaunch64

Post by jrubin »

but the subroutine should end with rts and rts is taking me back to basic. so Im stuck.
satpro

Re: Migration from TFC3 to Relaunch64

Post by satpro »

jrubin wrote:but the subroutine should end with rts and rts is taking me back to basic. so Im stuck.
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.

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)
You can even add this after the above to get a specific keypress...

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
In machine language things happen the way you program them; that is, there is no safety net. BASIC includes a loop that waits for your next keypress. In ml the tradeoff is complete control + freedom/maximum speed vs. having it all done for you + much slower. As you progress, you will find the advantages far outweigh the disadvantages. Try reading the book "Compute's Machine Language Routines for the Commodore 64/128" or "Compute's Programming the Commodore 64: The Definitive Guide". Both are fantastic!

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.
:)
Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 3 guests