home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_05 / 3n05024a < prev    next >
Text File  |  1992-01-31  |  2KB  |  45 lines

  1. #include <dos.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <malloc.h>
  5. /*
  6. ******************************************************************
  7. Title:      TSR.C - DOS Component of TSR Interface
  8. Author:     Thomas W. Olsen
  9. Version:    3.0
  10. Compiler:   Microsoft C 6.0
  11.             cl /AS /Zi tsr.c
  12. ******************************************************************
  13. */
  14. void   (interrupt far *OldIntHandler)();
  15.  
  16. void (interrupt _far IntHandler)(int es, int ds, int di, int si, int bp,
  17.                                  int sp, int bx, int dx, int cx, int ax,
  18.                                  int ip, int cs, int flags)
  19. {
  20.     static char _far *buffer = {"These are the contents of the TSR buffer!"};
  21.  
  22.     if (ax != 0xBEEF)                       /* If Multiplex Handle doesn't */
  23.         _chain_intr(OldIntHandler);         /*  match ... forward the interrupt */
  24.  
  25.     dx = FP_SEG(buffer);                    /* DX:AX = Buffer address */
  26.     ax = FP_OFF(buffer);
  27.     cx = _fstrlen(buffer);                  /* CX    = Max. buffer length */
  28. }
  29.  
  30. int main(int argc, char *argv[])                /* Here's the TSR format: */
  31. {                                               /*         CODE        */
  32.     extern unsigned end;                        /*      STATIC DATA    */
  33.     unsigned _far *upperLimit;                  /*         STACK       */
  34.     unsigned paragraphs, actual, stackSize;     /*         HEAP        */
  35.  
  36.     upperLimit = &end;                          /* top of static data */
  37.     stackSize  = ((stackavail() + 2048) / 2048) * 2048; /* compute stack size */
  38.     paragraphs = (FP_SEG(upperLimit) - _psp) + (FP_OFF(upperLimit) + stackSize) / 16 + 1;
  39.     OldIntHandler = _dos_getvect(0x2F);   /* get old INT 2Fh vector */
  40.     _dos_setvect(0x2F, IntHandler);       /* set INT 2Fh vector to our handler */
  41.     _dos_setblock(paragraphs, _psp, &actual);   /* relinquish unused heap */
  42.     _dos_keep(0, paragraphs);                   /* terminate & stay resident */
  43.     return(-1);                                 /* error must have occurred */
  44. }
  45.