home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / CEREBRUM / WAT9609.ZIP / SRC / PCINTR.C < prev    next >
Text File  |  1994-11-28  |  2KB  |  76 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)(void) = 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)(void);
  28.  
  29. static void interrupt newint( void )
  30. {
  31.     (*oldint)();
  32.     if ( !sem_up( &inside )) {
  33.         if ( on ) {
  34.             disable();
  35.             oldss = _SS;
  36.             oldsp = _SP;
  37.             _SS = _DS;
  38.             _SP = FP_OFF( &locstack[ sizeof( locstack ) - 4 ]);
  39.             enable();
  40.  
  41.             if ( wintr_chain )
  42.                 (*wintr_chain)();
  43.             tcp_tick( NULL );
  44.  
  45.             disable();
  46.             _SS = oldss;
  47.             _SP = oldsp;
  48.             enable();
  49.         }
  50.         inside = 0;
  51.     }
  52. }
  53.  
  54. void wintr_enable( void )
  55. {
  56.     on = 1;
  57. }
  58.  
  59. void wintr_disable( void )
  60. {
  61.     on = 0;
  62. }
  63.  
  64. void wintr_shutdown( void )
  65. {
  66.     setvect( TIMER, oldint );
  67. }
  68.  
  69. void wintr_init( void )
  70. {
  71.     atexit( wintr_shutdown );
  72.     oldint = getvect( TIMER );
  73.     setvect( TIMER, newint );
  74. }
  75.  
  76.