home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / hamradio / wattcp.zip / NETBACK.C < prev    next >
C/C++ Source or Header  |  1992-02-11  |  939b  |  47 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <tcp.h>
  4. #include <elib.h>
  5.  
  6. static char tempstack[ 4096 ];
  7. static int oldss, oldsp;
  8. static void interrupt (*oldinterrupt)();
  9. static void (*userroutine)() = NULL;
  10. static int inside = 0;
  11.  
  12. static void interrupt newinterrupt()
  13. {
  14.     (*oldinterrupt)();
  15.     disable();
  16.     if (!sem_up( &inside )) {
  17.         oldss = _SS;
  18.         oldsp = _SP;
  19.         _SP = FP_OFF( &tempstack[ sizeof( tempstack ) - 4 ] );
  20.         _SS = FP_SEG( tempstack );
  21.         enable();
  22.         if (userroutine) (*userroutine)();
  23.         tcp_tick( NULL );
  24.         disable();
  25.         _SP = oldsp;
  26.         _SS = oldss;
  27.         inside = 0;
  28.     }
  29.     enable();
  30. }
  31.  
  32. void backgroundon(void)
  33. {
  34.     oldinterrupt = getvect( 0x08 );
  35.     setvect( 0x08, newinterrupt );
  36. }
  37. void backgroundoff(void)
  38. {
  39.     setvect( 0x08, oldinterrupt );
  40. }
  41.  
  42. void backgroundfn( void (*fn)() )
  43. {
  44.     userroutine = fn;
  45. }
  46.  
  47.