Jump to content
IGNORED

Assembler and Basic USR and return to Basic.


Recommended Posts

This question is about using assembler programs with the use of the USR command within turbo basic.

 

So i did get this to work when my assembler program was simpler. When using a USR command :example (K=USR (35000). then you have to use one PLA in the assembler program for the stack.

 

When one needs go back to basic, A RTS command with no attachments should bring the program back to Basic at the line after of the USR command that where issued in Basic.

 

It worked at first but now my Assembler program seem to get to complicated so a RTS wont bring it back to basic.

i tried som PLA,s but that doesnt work. So when using USR does this put a return adress on the stack

so that when using RTS in assembler this is how it knows where to return to in Basic ?.

Maybe my assembler program messes up the stack somehow. Is there a way to find out exacly witch adress is put on the stack by

Basic and the somehow Manually push that adress onto the stack when needed ?

 

Would a CRC command remove the Basic return info from the stack. I tried tracing my program buts it seems very difficult to resolve the issue.

Edited by Grevle
Link to comment
Share on other sites

Debugger in emulation can be helpful here.

 

The first PLA in your program pulls a number which is = the number of extra parameters that are on the stack, this number will always be present whether you've supplied extra parameters or not.

Careful programs will check this and pull everything and only everything needed (each parameter is 2 extra bytes to PLA from the stack) but most only do what they need to.

 

The only time Basic ever directly manipulates the Stack pointer is when it starts up. Otherwise the changing of the stack pointer is just as would be expected from JSR/RTS/PHA/PLA etc.

 

The operative thing for your assembler routine is that it should always do at least 1 PLA. If extra parameters are present then there's 2 PLAs for each of those.

Whether your program puts in the effort to check the right number of parameters are present is up to you. But so long as your Basic program and assembly routine are doing things such that the stack level isn't corrupted then you should be OK.

 

If you're really paranoid about it, this would be a bit of a kludge but you could do something like:

  PLA ; get # of parameters
  STA PARMS
  TSX
  STX SAVESP ; retain stack level
;
; rest of routine here
;
  LDX SAVESP
  TXS
  RTS ; back to Basic
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...