home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_06 / 2n06037a < prev    next >
Text File  |  1991-04-11  |  2KB  |  86 lines

  1.  
  2.                    Listing 2, TSR DEMO Program
  3.                    ---------------------------
  4. /*
  5. **  DEMO.C
  6. **  Sample TSR to demonstrate Non-Intrusive Monitor
  7. **
  8. **  Written in MicroSoft C version 6.00
  9. **  Build String:
  10. **    cl demo.c init.c
  11. **
  12. **  Written By:  John R. Naleszkiewicz
  13. **        Date:  March 15, 1991
  14. **     Version:  1.00
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <dos.h>
  19. #include <process.h>
  20.  
  21. #define  TIMERTICK     0x1c
  22.  
  23. /* The interrupt function's prototype statement */
  24. void _interrupt far timer( void );
  25.  
  26. /* The variable declarations */
  27. void     (_interrupt _far *oldTimer)(void);
  28. int      every_tick = 0;
  29. int      every_sec = 0;
  30. int      every_3_sec = 0;
  31. long     long_every_10_sec = 45000;
  32. char     alphabet = 'A';
  33. char     * special_string = "<empty>";
  34.  
  35. void _interrupt far timer()
  36. {
  37.   oldTimer();  /* invoke the old timer first */
  38.   _enable();   /* enable interrupts */
  39.  
  40.   ++every_tick;                   /* increment with every tick */
  41.  
  42.   if( (every_tick % 18) == 0 ) {  /* increment every second */
  43.     every_sec++;
  44.     if( ++alphabet > 'Z' )
  45.       alphabet = 'A';
  46.     if( every_sec & 2 )
  47.       special_string = "This is one string";
  48.     else
  49.       special_string = "This is the other string";
  50.   }
  51.  
  52.   if( (every_tick % 55) == 0 )    /* increment every 3 seconds */
  53.     every_3_sec++;
  54.  
  55.   if( (every_tick % 182) == 0 )   /* increment every 10 seconds */
  56.     long_every_10_sec++;
  57. }
  58.  
  59.  
  60. main()
  61. {
  62.   /* Save the old interrupt vector */
  63.   oldTimer = _dos_getvect( TIMERTICK );  
  64.  
  65.   /* Set the interrupt vector to the new function */
  66.   _dos_setvect( TIMERTICK, timer );
  67.  
  68.   /* Hook in the TSR Entry Point */
  69.   entry_hook();
  70.  
  71.   printf( "Loading TSR DEMO for the Non-Intrusive Monitor...\n" );
  72.  
  73.   /* Simulate a TSR by reinvoking COMMAND.COM */
  74.   spawnlp( P_WAIT, "COMMAND.COM", "COMMAND.COM", NULL );
  75.  
  76.   /* Unhook the TSR Entry Point */
  77.   entry_unhook();
  78.  
  79.   /* Restore the old interrupt vector before quiting */
  80.   _dos_setvect( TIMERTICK, oldTimer );
  81.  
  82.   printf( "TSR DEMO Removed\n" );
  83. }
  84.  
  85.  
  86.