[comp.sys.atari.8bit] What's the right way...

jrd@STONY-BROOK.SCRC.SYMBOLICS.COM (John R. Dunning) (10/06/87)

to return from a program to DOS?  I always thought the protocol was that
DOS (any DOS) effectively JSR'ed to the start address of the program
once it was loaded; thus the right way to return was just to RTS.
That's always worked for me, using DOS XL.  However, I've gotten some
reports that Kermit-65 sometimes wedges up when one exits from it.  I'm
pretty sure I'm not trashing the stack; it really looks like DOS expects
something other than an RTS.

Anyone got any ideas?  Thanks in advance.

sullivan@marge.math.binghamton.edu (fred sullivan) (10/07/87)

In article <871006122252.4.JRD@GRACKLE.SCRC.Symbolics.COM> jrd@STONY-BROOK.SCRC.SYMBOLICS.COM (John R. Dunning) writes:
>to return from a program to DOS?  I always thought the protocol was that
>DOS (any DOS) effectively JSR'ed to the start address of the program
>once it was loaded; thus the right way to return was just to RTS.
>That's always worked for me, using DOS XL.  However, I've gotten some
>reports that Kermit-65 sometimes wedges up when one exits from it.  I'm
>pretty sure I'm not trashing the stack; it really looks like DOS expects
>something other than an RTS.
>
I have had similar problems with various communications programs,
including a very simple one I wrote years ago in basic.  I formed the
conjecture that there are mysterious problems which arise after turning
on concurrent io mode in an 850 interface.  Does anyone know anything about
this?

Fred Sullivan
Department of Mathematical Sciences
State University of New York at Binghamton
Binghamton, New York  13903
Email: sullivan@marge.math.binghamton.edu

schuster@dasys1.UUCP (Michael Schuster) (10/09/87)

In article <734@bingvaxu.cc.binghamton.edu> sullivan@marge.math.binghamton.edu (fred sullivan) writes:
>In article <871006122252.4.JRD@GRACKLE.SCRC.Symbolics.COM> jrd@STONY-BROOK.SCRC.SYMBOLICS.COM (John R. Dunning) writes:
>>to return from a program to DOS?  

>I have had similar problems with various communications programs,
>including a very simple one I wrote years ago in basic.
>
>Fred Sullivan

-----
Going to DOS from any communications program
that uses the 850 R: handler is big trouble.
DUP.SYS loads right over the handler itself, so
that when you return to the program the R: device
is gone. 
  If you're using OS/A+, DOS XL, or SpartaDOS these
caveats may not apply. But it sure occurs with
Atari DOS 2.X
-----
-----
-----

-- 
l\  /l'   _  Mike Schuster          {sun!hoptoad,cmcl2!phri}!dasys1!schuster
l \/ lll/(_  Big Electric Cat       schuster@dasys1.UUCP
l    lll\(_  New York, NY USA       DELPHI,GEnie:MSCHUSTER  CIS:70346,1745 

hyc@umix.cc.umich.edu (Howard Chu) (10/09/87)

Are you using Action? Action writes object files based off the Init
vector. Unfortunately, it also provides a valid address for the Run vector.
What happens is that an Action program will load, execute, and then DOS
will try to execute it again based on the Run vector. (The two addresses
here aren't identical - the Init vector points to some runtime startup
code, whereas the Run vector points to the actual beginning of the program.)
The solution is simple - Define a global variable at the beginning of
your program, and pre-initialize it to the value $60. As long as the first
byte of your program is an RTS, things should work fine...
-- 
  -- Howard Chu
	"Of *course* it's portable. It's written in C, isn't it?"

hans@umd5.umd.edu (Hans Breitenlohner) (10/22/87)

In article <871006122252.4.JRD@GRACKLE.SCRC.Symbolics.COM> jrd@STONY-BROOK.SCRC.SYMBOLICS.COM (John R. Dunning) writes:
>What's the right way
>to return from a program to DOS?  I always thought the protocol was that
>DOS (any DOS) effectively JSR'ed to the start address of the program
>once it was loaded; thus the right way to return was just to RTS.
>That's always worked for me, using DOS XL.  However, I've gotten some
>reports that Kermit-65 sometimes wedges up when one exits from it.  I'm
>pretty sure I'm not trashing the stack; it really looks like DOS expects
>something other than an RTS.
>


While your way should work usually, here is a different way.  This is what
Turbo-Basic does before returning to DOS:

1. Clear locations $D200-$D207 (audio registers)
2. Close IOCBs 1-7
3. Jump indirect through DOSVEC ($000A).

If you have done interesting things with the screen, it might be even better
to refine step 2:
 
2a: Close all IOCBs.
2b: Open IOCB 0 for screen editor.

Of course you can skip step 1 if you have not done anything with the
audio registers, and it may be that DOS (some DOS) will do the equivalent
of steps 2a and 2b after you return.