home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / MSDOS / WATTCP / NEWWATCP.ZIP / SRC / PCINTR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-15  |  1.5 KB  |  74 lines

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