home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / DLC_TSR.ZIP / TSR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1980-01-04  |  5.2 KB  |  141 lines

  1. /*
  2. In December of 1986 Roy Sherrill, President of Datalight, asked me if I 
  3. could produce a Terminate and Stay Resident (TSR) library function for 
  4. Datalight C.  He explained that a consultant programmer known by him to 
  5. be capable of producing such a library function estimated 4 to 6 months 
  6. effort.  I scoffed at that and produced my first version of a fully 
  7. operational TSR library function over the following weekend.  A 
  8. demonstration copy was forwarded to Datalight and Roy Sherrill 
  9. encouraged me to enhance that version with a screen saver function, all 
  10. the while strongly implying that Datalight wished to use the resultant 
  11. library function as a product.
  12.  
  13. Roy Sherrill was either not serious or is in the progress of reverse 
  14. engineering the .OBJ files he received from me.  In either case, his 
  15. time is up.  I offer the enclosed files to any C programmer who finds 
  16. them useful with no strings or encumberances of any kind.  In other 
  17. words, the enclosed files are offered free and clear to the public 
  18. domain to whomever desires to use them.
  19.  
  20. Anyone desiring the source code for TSR.OBJ should contact me 
  21. personally.
  22.  
  23. John J. Newlin
  24. 4060-288 Rosenda Ct.
  25. San Diego, CA 92122
  26. (619) 455-6225
  27.  
  28. A note to Roy Sherrill:  It won't be Microsoft that treads on 
  29. Datalight's grave - it will be Borland!!!
  30. */
  31.  
  32.  
  33. /* minimum configuration is _stack = 2048 - 470h paragraphs 
  34.    with no screen save */
  35. #include <stdio.h>
  36. int _stack = 6048;
  37. main()
  38. {
  39.   if (check_tsr() == 112)  /* 112 = Alt-F9 */
  40.   /* check_tsr returns an integer equal to the hot key value of any
  41.      Datalight TSR routines currently in memory.  It is used to determine
  42.      if your TSR has already been installed */
  43.   {
  44.      puts("TSR installed in memory\07");
  45.      exit(1);
  46.   }
  47.   puts("DATALIGHT C memory resident demo installed");
  48.   tsr_init(112,0x0500);
  49.   /* tsr_init is called with two integer values.  The first is the 
  50.   extended scan code of the activation ("hot") key.  The second is the 
  51.   amount of memory (in 16 byte paragraphs) needed to support the TSR.
  52.   Memory calculation must be accomplished by the programmer prior to 
  53.   final compilation and linking. */
  54.  
  55. }
  56. tsr_main()
  57. /* tsr_main is the function called by the TSR when the "hot" key is 
  58. sensed.  It MUST have this name.  It may call any other functions and 
  59. acts as the primary gateway between the resident handler and the main 
  60. program code.  Place your desired code here. */
  61.  
  62. { int key,attr;
  63.   char vmode,*msg;
  64.   static char *buffer[4000];
  65.   /* This buffer is used to save the entire screen but it is possible to
  66.      use savescrn and restscrn to save and selected portions of the screen.
  67.      For example, savescrn(10,10,20,8,buffer) would save a rectangular
  68.      portion of the screen with the upper left hand corner at 10,10, a
  69.      width of 20 columns, and a depth of 8 rows.  A buffer on the heap just
  70.      large enough to contain the portion of the screen desired to be saved
  71.      may be employed by using the intrinsic call calloc.  The amount of
  72.      memory required is computed as width * depth * 2.
  73.   */
  74.  
  75.   savecurs();
  76.   /* Saves the position and the type of the current cursor */
  77.  
  78.   savescrn(1,1,80,25,buffer);
  79.   /* This function saves a selected rectangular portion of the screen.  In
  80.      this case the entire screen is saved.  The function declaration
  81.      (restscrn is the same) is:
  82.  
  83.                void savescrn(col,row,width,depth,buffer);
  84.                int col,row,width,depth;
  85.                char *buffer;
  86.  
  87.      where col is the column coordinate of the upper left hand corner of the
  88.      rectangle, row is the row coordinate of the upper left hand corner of
  89.      the rectangle, width is the width of the rectangle in columns, and depth
  90.      is the height of the rectangle in rows (normalized so that the top left 
  91.      corner of the full screen is column 1, row 1)
  92.   */
  93.  
  94.   cls(14); /* clears the entire screen with an attribute of 0Eh.  Declared
  95.               as :
  96.                    void cls(attribute);
  97.                    int attribute;
  98.            */
  99.  
  100.   /*
  101.       The type of video monitor is detected and adjusted for automatically
  102.       upon each call to savescrn.
  103.   */
  104.  
  105.   msg = "TERMINATE & STAY RESIDENT DEMONSTRATION";
  106.  
  107.   gotoxy(21,6);  /* position the cursor - normalized to (1,1) for upper left
  108.                     corner of the full screen.  Declared as :
  109.                          
  110.                            void gotoxy(col,row);
  111.                            int col,row;
  112.                   */
  113.  
  114.   puts(msg);
  115.   msg = "DATALIGHT C";
  116.   gotoxy(35,8);
  117.   puts(msg);
  118.   msg = "by John Newlin";
  119.   gotoxy(33,10);
  120.   puts(msg);
  121.   msg = "Copyright (C) 1987";
  122.   gotoxy(31,12);
  123.   puts(msg);
  124.   msg = "Any key continues";
  125.   gotoxy(32,14);
  126.   puts(msg);
  127.   msg = "End key deinstalls";
  128.   gotoxy(31,16);
  129.   puts(msg);
  130.   key = getkey(); /* my personal keyboard interrogator */
  131.   if (key == 335) 
  132.     { 
  133.       restscrn(1,1,80,25,buffer);  /* restore the saved screen */
  134.       restcurs();  /* restore the saved cursor type and position */
  135.       remove();                   /* remove this TSR */
  136.     }
  137.   restscrn(1,1,80,25,buffer);      /* restore the saved screen */
  138.   restcurs();                     /* restore the cursor type and position */
  139. }
  140.  
  141.