home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / mscwattc / src / pcintr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-13  |  1.8 KB  |  87 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. # define    LOCSTACKSIZE    2048
  23. static byte locstack[ LOCSTACKSIZE ];
  24. static word on = 0;
  25. static word inside = 0;
  26. static word oldss, oldsp;
  27. static void (_interrupt _far *oldint)(void);
  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.         _asm
  39.         {    mov    ax, ss
  40.             mov    oldss, ax
  41.             mov    ax, sp
  42.             mov    oldsp, ax
  43.             mov    ax, ds
  44.             mov    ss, ax
  45.             mov    sp, OFFSET locstack + LOCSTACKSIZE - 4
  46.         }
  47.             enable();
  48.  
  49.             if ( wintr_chain )
  50.                 (*wintr_chain)();
  51.             tcp_tick( NULL );
  52.  
  53.             disable();
  54.  //             _SS = oldss;
  55.  //             _SP = oldsp;
  56.         _asm
  57.         {    mov    ss, oldss
  58.             mov    sp, oldsp
  59.         }
  60.             enable();
  61.         }
  62.         inside = 0;
  63.     }
  64. }
  65.  
  66. void wintr_enable(void)
  67. {
  68.     on = 1;
  69. }
  70.  
  71. void wintr_disable(void)
  72. {
  73.     on = 0;
  74. }
  75.  
  76. void wintr_shutdown(void)
  77. {
  78.     setvect( TIMER, oldint );
  79. }
  80. void wintr_init(void)
  81. {
  82.     atexit( wintr_shutdown );
  83.     oldint = _dos_getvect( TIMER );
  84.     _dos_setvect( TIMER, newint );
  85. }
  86.  
  87.