[comp.os.msdos.programmer] <20416@eagle.lerc.nasa.gov>

don@trsvax.UUCP (10/05/90)

>>I'm attempting to use Microsoft C's _dos_keep function but I 
>>do not know how to calculate the 2'd paramter required by this
>>function.  The 2'd paramter is the desired size in 16 byte paragraphs
>>of the program that you want to remain resident.  Does anybody know how to
>>calculate this, or is there some function call that I can use to get
>>the desired size.  Any help with my problem would be greatly appreciated.

>Well, why don't we let MICROSOFT lend an answer for a change, OK?  Here's
>the Example program that popped up on my screen when I inquired about the
>_dos_keep function in Microsoft Quick C / Quick Assembler v2.51.

>void main( int argc, char **argv )
>{
>    long minute, hour;
>    unsigned tsrsize;

>    /* Initialize stack and bottom of program. */
>    _asm mov  WORD PTR tsrstack[0], sp
>    _asm mov  WORD PTR tsrstack[2], ss
>    FP_SEG( tsrbottom ) = _psp;
>    FP_OFF( tsrbottom ) = 0;

>    /* Program size is:
>     *     top of stack
>     *   - bottom of program (converted to paragraphs)
>     *   + one extra paragraph
>     */
>    tsrsize = ((tsrstack - tsrbottom) >> 4) + 1;

Although the code executes correctly as written, there are some points in it
which may not work under all circumstances.  In picking up the top of the
stack, it is using the current stack location.  This occurs after main()
has already pushed its local parameters on the stack.  What this means is
	1)  you cannot return from main()
	2)  after you TSR, you cannot use the input or local parameters
	    in main().
Although neither of these cases are likely to occur in a well-written high-
level TSR program, I think the person who uses this code should be aware
of that fact.

---------------------------------------------------------------------

The more you drive, the less intelligent you are.
				-- _Repo Man_

Don Subt			The opinions expressed above are
Tandy Corp.			strictly mine, not my employer's.

817-390-2923			don%trsvax@rwsys.lonestar.org...