home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / hamradio / wattcp.zip / PCINTR.C < prev    next >
C/C++ Source or Header  |  1991-11-12  |  2KB  |  73 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <wattcp.h>
  4.  
  5. /*
  6.  * pcintr - add interrupt based processing, improve performance
  7.  *          during disk slowdowns
  8.  *
  9.  * wintr_init()     - call once
  10.  * wintr_shutdown() - called automatically
  11.  * wintr_enable()   - enable interrupt based calls
  12.  * wintr_disable()  - diable interrupt based calls (default)
  13.  * (*wintr_chain)() - a place to chain in your own calls, must live
  14.  *                    within something like 1K stack
  15.  *
  16.  */
  17.  
  18.  
  19. #define TIMER 0x08
  20. void (*wintr_chain)() = NULL;
  21.  
  22. static byte locstack[ 2048 ];
  23. static word on = 0;
  24. static word inside = 0;
  25. static word oldss, oldsp;
  26. static void interrupt (*oldint)();
  27. static void interrupt newint(void)
  28. {
  29.     (*oldint)();
  30.     if ( !sem_up( &inside )) {
  31.         if ( on ) {
  32.             disable();
  33.             oldss = _SS;
  34.             oldsp = _SP;
  35.             _SS = _DS;
  36.             _SP = FP_OFF( &locstack[ sizeof( locstack ) - 4 ]);
  37.             enable();
  38.  
  39.             if ( wintr_chain )
  40.                 (*wintr_chain)();
  41.             tcp_tick( NULL );
  42.  
  43.             disable();
  44.             _SS = oldss;
  45.             _SP = oldsp;
  46.             enable();
  47.         }
  48.         inside = 0;
  49.     }
  50. }
  51.  
  52. void wintr_enable(void)
  53. {
  54.     on = 1;
  55. }
  56.  
  57. void wintr_disable(void)
  58. {
  59.     on = 0;
  60. }
  61.  
  62. void wintr_shutdown(void)
  63. {
  64.     setvect( TIMER, oldint );
  65. }
  66. void wintr_init(void)
  67. {
  68.     atexit( wintr_shutdown );
  69.     oldint = getvect( TIMER );
  70.     setvect( TIMER, newint );
  71. }
  72.  
  73.