Jump to content
IGNORED

I want to escape from a JSR - RTS loop. Is PLA PLA right?


Recommended Posts

I'm writing a tool (almost ready) ... and the user can abort a certain process by pressing START (hehe, that makes sense... press START to quit hehehe, but ok)

 

But this 'press start' routine is called IN an existing JSR - RTS loop.

 

So the QUIT routine can not end with an RTS...

 

I created a trick for this

 

PLA
PLA 
RTS

 

Is that a bad solution? Or is this rather common? Any other ideas?

 

Thanks

Marius

Link to comment
Share on other sites

If you PLA,PLA you'll remove the first return address and then RTS to the previous address on the stack. If there isn't one, you'll crash.

 

I assume you can't just RTS normally but with some flag set to indicate that START was pressed?

 

Here's a little example (the three dots are where your surrounding opcodes would be):

 


; The calling routine...
 ... 
 ...
 jsr ROUTINE1
 bcc continue
 jmp STARTPRESSED
continue
 ...
 ...



;called routine
ROUTINE1
 ...
 ...
 lda COLSOL
 and #01
 bne no_start
 sec          ;flag START pressed
 rts          ;immediate exit
no_start
 ...
 ...
 ...          ;keep processing
 ...
 ...
 clc          ;flag START not pressed
 rts          ;normal exit 

Edited by Bryan
Link to comment
Share on other sites

If you PLA,PLA you'll remove the first return address and then RTS to the previous address on the stack. If there isn't one, you'll crash.

 

I assume you can't just RTS normally but with some flag set to indicate that START was pressed?

 

That is an option indeed.

 

But... there will definately be a return adress on the stack, since this "exit" routine (with the pla pla) is always called from a jsr-rts loop.

 

When I get you right, you say: set a flag when the START button is presst. And JMP to the EXIT routine BEFORE the JSR-RTS loop is called again.

 

That is the safest indeed.

I'll think it over!

 

Thanks

Marius

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...