[net.micro.pc] An answer and a question

stiber@zeus.cs.ucla.edu (Michael D Stiber) (08/01/86)

I ran across an example of a C program that terminates & stays
resident, which answers one of my previous questions and might be of
interest to others.  Here it is (very short - for MS & IBM compilers):

#include <dos.h>
main()
{
  extern unsigned int _psp;    /* Library variable Program Segment Prefix*/
  unsigned int far *sizeptr;   /* Pointer to top of memory pointer */
  unsigned int sizeinpara;     /* Size of program in paragraphs */
  union REGS inregs;

  FP_SEG(sizeptr) = _psp;      /* Point to top of memory pointer */
  FP_OFF(sizeptr) = 2;         /* at offset 2 of PSP */
  sizeinpara = *sizeptr - _psp; /* memory top - base */
  printf("\nSize = %d paragraphs, %d bytes\n",sizeinpara,sizeinpara*16);
  inregs.x.ax = 0x3100;
  inregs.x.dx = sizeinpara;
  intdos(&inregs,&inregs);
}

Note that you must use the /ZE option to enable the "far" keyword.
Then use EXEMOD's /MAX option to cut the allocated storage down to a
reasonable size (the last is optional).

I'm still looking for some information about how to use a C function
as an interrupt routine.  If I don't get any responses, then I guess
I'll have to figure it out for myself (and we all know how painful
that can be).

Also, thanks to Hants White for answering my SHELL question.

                     Michael Stiber
                     ARPANET: stiber@ucla-locus.arpa
                     USENET:  ...{ucbvax,ihpn4}!ucla-cs!stiber