home *** CD-ROM | disk | FTP | other *** search
- //****************************************************************
- //
- // FOSSIL overhead program
- // Prevents short-time carrier losses on bad phone lines
- // Known bug: no check for multiple loading as TSR
- //
- # if !defined(__TCPLUSPLUS__) || !defined(__LARGE__)
- # error assumed borland C++, large memory model
- # endif
-
- # pragma inline
- # pragma option -N-
- # pragma option -r-
-
- static char _C_[] = "$RCSfile: nohup.~cc $ (C) Business Console Ltd. $Author: Bell $";
-
- # include <alloc.h>
- # include <dos.h>
-
- static void hand_com();
- static void interrupt (*saved_com)(...);
-
- //----------------------------------------------------------------
-
- int main()
- {
- const int intr_com = 0x14; // steal FOSSIL interrupt
- saved_com = getvect(intr_com);
- setvect(intr_com, (void interrupt (*)(...)) hand_com);
-
- freemem(((int*) MK_FP(_psp, 0x2c))[0]); // gentlemen should always
- // free environment space
-
- keep(0, FP_SEG(sbrk(0)) - _psp + 1); // compute program size
- // by sbrk and psp
-
- setvect(intr_com, saved_com); // can we ever get here ?
- return 1;
- }
-
- //----------------------------------------------------------------
-
- // You can rewrite codes below more precisely, but I don't care
-
- # define PUSH asm pushf; asm push ax; asm push dx; \
- asm push bx; asm push es; asm push ds; \
- asm mov ax, DGROUP; asm mov ds, ax;
- # define POP asm pop ds; asm pop es; asm pop bx; \
- asm pop dx; asm pop ax; asm popf;
- # define RET asm mov sp, bp; asm pop bp; asm ret 2;
-
- void hand_com()
- {
- const int carrier_bit = 0x80;
- static int online = -1;
- static int timeout;
- int* const timer = (int*) 0x0000046cL; // timer in BIOS data area
- const int delay = 100; // 100 ticks = 5 sec
-
- char ah = _AH;
- int ax = _AX;
- PUSH;
- void (interrupt* fun)(...) = saved_com; // copy old vector in stack
- POP;
- fun(); // all registers restored
- int ret = _AX;
- PUSH;
- if (ax == 0x600) // subfunction 0x6 (drop DTR)
- online = -1;
- else if (ah != 3) // not subfunction 0x3 (query)
- ;
- else if (ret & carrier_bit) // online
- online = 1;
- else if (online > 0) // carrier just lost
- {
- ret |= carrier_bit;
- timeout = *timer + delay;
- online = 0;
- }
- else if (!online) // still waiting for carrier
- {
- ret |= carrier_bit;
- int delta = *timer - timeout; // seems suspicious,
- if (delta >= 0) // but still valid
- online = -1;
- }
- else // no hope
- ;
- POP;
- _AX = ret;
- RET;
- }
-
-