home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / comm / bye_pc1.zip / BYEXFACE.C < prev    next >
Text File  |  1987-01-03  |  13KB  |  523 lines

  1. /*
  2. **  Program:    <byexface.c>
  3. **
  4. **  Author:    R.E. Starr, Jr.     (10/20/86)
  5. **
  6. **  Revisons:
  7. **
  8. **  (10/20/86)    1.00 - First release
  9. **  (11/01/86)    1.01 - added timeout return status in mdm_putc().
  10. **  (12/20/86)    1.02 - corrected modem get_char() error return.
  11. **               requires BYE-PC version 1.02 or greater.
  12. **
  13. **  Purpose:    Provides interface functions to BYE-PC interrupt 66h
  14. **        for access to the modem controls and status.
  15. **
  16. **  Requirments:    This code will compile directly using the MSC 3.1
  17. **        compiler. It can be compiled in any of the memory
  18. **        models supported by MSC. Once compiled, link the object
  19. **        code with the application modules to add BYE-PC inter-
  20. **        face capabilty to 'C' programs. This code is intended
  21. **        to simplify access to XMODEM and RBBS programs written
  22. **        to work with BYE-PC.
  23. **
  24. */
  25.  
  26. #include    <stdio.h>
  27. #include    <conio.h>
  28. #include    <dos.h>
  29. #include    <process.h>
  30. #include    <time.h>
  31. #include    <ctype.h>
  32. #include    "byexface.h"
  33.  
  34. #define     BYE_VECT     0x66        /* BYE access interrupt vector */
  35. #define     YES     1
  36. #define     NO        0
  37. #define     ON        1
  38. #define     OFF     0
  39.  
  40.  
  41. /*
  42. **  Function:    int check_bye(lver, hver, lrev, hrev)
  43. **
  44. **  Parms:    int lver = lowest version# acceptable
  45. **        int hver = highest version# acceptable
  46. **        int lrev = lowest revision# acceptable
  47. **        int hrev = highest revision# acceptable
  48. **
  49. **  Purpose:    Test to see if BYE-PC is loaded before executing
  50. **        any other functions. Prevents a system crash!!!
  51. **        If you call any other functions that call BYE-PC
  52. **        interrupt 66h, before 'check_bye() == 1' the system
  53. **        will crash. The interrupt vectors are uninitialized
  54. **        and contain null or garbage data. This checks to
  55. **        make sure that BYE-PC has been loaded.
  56. **
  57. **  Return:    0 = BYE-PC loaded and is acceptable version/revision
  58. **        1 = BYE-PC is not loaded yet
  59. **        2 = BYE-PC is loaded but, invalid version#
  60. **        3 = BYE-PC is loaded but, invalid revision#
  61. **
  62. */
  63.  
  64. int check_bye(lver, hver, lrev, hrev)
  65.  
  66.  int lver, hver, lrev, hrev;
  67.     {
  68.     char c;
  69.     char far *addr;
  70.     int ver, rev;
  71.     unsigned long x;
  72.     union REGS inregs, outregs;
  73.     struct SREGS segregs;
  74.  
  75.     inregs.h.ah = 0x35;         /* DOS get vector function */
  76.     inregs.h.al = 0x16;
  77.     int86x(0x21, &inregs, &outregs, &segregs);
  78.     x = (long)segregs.es;
  79.     addr = (char far *)(x << 16 | 0x00000103L);
  80.  
  81.     if (*addr++ != 'B')         /* look for title in code */
  82.     return(1);            /* that interrupt vector  */
  83.     else if (*addr++ != 'Y')        /* is pointing to.          */
  84.     return(1);
  85.     else if (*addr++ != 'E')
  86.     return(1);
  87.  
  88.     x = bye_vers();
  89.     ver = (int)(x >> 8);        /* get version number */
  90.     rev = (int)(x & 0x00FF);        /* get revison level */
  91.     if (ver < lver || ver > hver)   /* version# accpeptable */
  92.     return(2);            /* assume we found BYE-PC */
  93.     if (rev < lrev || rev > hrev)   /* revision# accpeptable */
  94.     return(3);            /* return version error */
  95.     return(0);                /* all was ok */
  96.     }
  97.  
  98.  
  99. /*
  100. **  Function:    unsigned mdm_getc()
  101. **
  102. **  Purpose:    Return character from the modem Rx-queue if available.
  103. **        The function 'rx_size()' can be used to determine if
  104. **        data is available in the Rx-queue.
  105. **
  106. **  Return:    EOF if no character in buffer
  107. **
  108. */
  109.  
  110. unsigned mdm_getc()
  111.  {
  112.  int c;
  113.  union REGS inregs, outregs;
  114.  
  115.  inregs.h.al = 0;            /* load BYE function# */
  116.  int86(BYE_VECT, &inregs, &outregs);    /* perform BYE-PC call INT 66h */
  117.  return((unsigned)outregs.x.ax);    /* character in lsb */
  118.  }
  119.  
  120.  
  121. /*
  122. **  Function:    int mdm_putc()
  123. **
  124. **  Purpose:    Send the character to the modem via BYE-PC. Note
  125. **        that if nulls are in effect that these will not be
  126. **        sent a line feed character. The user must handle any
  127. **        nulls that are needed by 'get_nulls()'.
  128. **
  129. **  Return:    EOF = timeout error
  130. **         0  = Tx ok
  131. **
  132. */
  133.  
  134. int mdm_putc(c)
  135.  
  136.  int c;
  137.     {
  138.     union REGS inregs, outregs;
  139.  
  140.     inregs.h.al = 1;            /* load BYE function# */
  141.     inregs.h.ah = (char)c;        /* load character to send */
  142.     int86(BYE_VECT, &inregs, &outregs); /* perform BYE-PC call INT 66h */
  143.     return((int)outregs.x.ax);        /* character in lsb */
  144.     }
  145.  
  146.  
  147. /*
  148. **  Function:    void mdm_dtr(flag)
  149. **
  150. **  Parms:    flag = 1    DTR/CTS line ON
  151. **        flag = 0    DTR/CTS line OFF
  152. **
  153. **  Purpose:    Toggle the DTR line on the modem to hangup. If the
  154. **        carrier detect status is enabled, the system will
  155. **        hangup and re-boot if this is called with dtr off.
  156. **        The function 'set_cd()' should be used to prevent
  157. **        this is needed.
  158. **
  159. **  Return:    <none>
  160. **
  161. */
  162.  
  163. void mdm_dtr(flag)
  164.  
  165.  int flag;
  166.     {
  167.     union REGS regs;
  168.  
  169.     regs.h.al = 2;            /* load BYE function# */
  170.     regs.h.ah = (char)flag;        /* load character to send */
  171.     int86(BYE_VECT, ®s, ®s);    /* perform BYE-PC call INT 66h */
  172.     }
  173.  
  174.  
  175. /*
  176. **  Function:    int mdm_cd()
  177. **
  178. **  Purpose:    Test for carrier detect status from the modem.
  179. **        Returns a logical TRUE if the modem still has
  180. **        caller on line with carrier.
  181. **
  182. **  Return:    1 = Carrier Detect found
  183. **        0 = Carrier Detect not found
  184. **
  185. */
  186.  
  187. int mdm_cd()
  188.  {
  189.  union REGS inregs, outregs;
  190.  
  191.  inregs.h.al = 3;            /* load BYE function# */
  192.  int86(BYE_VECT, &inregs, &outregs);    /* perform BYE-PC call INT 66h */
  193.  return((int)outregs.x.ax);        /* return Rx-queue size */
  194.  }
  195.  
  196.  
  197. /*
  198. **  Function:    void set_cd(flag)
  199. **
  200. **  Parms:    flag = 0    carrier check disabled
  201. **        flag = 1    carrier check enabled
  202. **
  203. **  Purpose:    Sets a flag in BYE-PC to ignore carrier detect
  204. **        status. This is used before writing to a file to
  205. **        prevent warm booting while writing to disk in the
  206. **        event carrier is lost during disk writes.
  207. **
  208. */
  209.  
  210. void set_cd(flag)
  211.  
  212.  int flag;
  213.     {
  214.     union REGS regs;
  215.  
  216.     regs.h.al = 4;            /* load BYE function# */
  217.     regs.h.ah = (char)flag;        /* load character to send */
  218.     int86(BYE_VECT, ®s, ®s);    /* perform BYE-PC call INT 66h */
  219.     }
  220.  
  221.  
  222. /*
  223. **  Function:    void rx_flush()
  224. **
  225. **  Purpose:    Removes characters waiting in the Rx-queue and
  226. **        resets the Rx-character counter to 0. This is
  227. **        used to reset after a buffer overflow and before
  228. **        starting any data transfers to remove any trash
  229. **        from the Rx-queue.
  230. **
  231. **  Return:    <none>
  232. **
  233. */
  234.  
  235. void rx_flush()
  236.  {
  237.  union REGS regs;
  238.  
  239.  regs.h.al = 5;             /* load BYE function# */
  240.  int86(BYE_VECT, ®s, ®s);     /* perform BYE-PC call INT 66h */
  241.  }
  242.  
  243.  
  244. /*
  245. **  Function:    int rx_size()
  246. **
  247. **  Purpose:    Test for characters waiting in the Rx-queue and
  248. **        returns the number of characters in the queue. If
  249. **        'size' is > 0 and 'mdm_getch()' returns and EOF,
  250. **        a buffer overflow occured and 'rx_flush' must be
  251. **        called to reset counts.
  252. **
  253. **  Return:    Returns the number of characters in the Rx-queue
  254. **
  255. */
  256.  
  257. int rx_size()
  258.  {
  259.  union REGS inregs, outregs;
  260.  
  261.  inregs.h.al = 6;            /* load BYE function# */
  262.  int86(BYE_VECT, &inregs, &outregs);    /* perform BYE-PC call INT 66h */
  263.  return((int)outregs.x.ax);        /* return Rx-queue size */
  264.  }
  265.  
  266.  
  267. /*
  268. **  Function:    int mdm_baud()
  269. **
  270. **  Purpose:    Returns the baud rate of the caller on line.
  271. **
  272. **  Return:    0 = 300 bps
  273. **        1 = 1200 bps
  274. **        2 = 2400 bps
  275. **
  276. */
  277.  
  278. int mdm_baud()
  279.  {
  280.  union REGS inregs, outregs;
  281.  
  282.  inregs.h.al = 7;            /* load BYE function# */
  283.  int86(BYE_VECT, &inregs, &outregs);    /* perform BYE-PC call INT 66h */
  284.  return((int)outregs.x.ax);        /* return Rx-queue size */
  285.  }
  286.  
  287.  
  288. /*
  289. **  Function:    void set_break(flag)
  290. **
  291. **  Parms:  flag =
  292. **
  293. **    CTRL_NOBRK   = 0    remote ^C & ^S break disabled
  294. **    CTRL_BRK     = 1    remote ^C & ^S break enabled
  295. **    CTRL_NOTOUT  = 2    remote ^S timeout disabled
  296. **    CTRL_TOUT    = 3    remote ^S timeout enabled
  297. **    CTRL_NOTRAP  = 4    dont filter out ^C & ^S chars
  298. **    CTRL_TRAP    = 5    allow filter of ^C & ^S chars
  299. **
  300. **  Purpose:    This sets the control/break pause flag for the
  301. **        remote caller only! The local console still has
  302. **        control over breaks/pauses.
  303. **
  304. */
  305.  
  306. void set_break(flag)
  307.  
  308.  int flag;
  309.     {
  310.     union REGS regs;
  311.  
  312.     regs.h.al = 8;            /* load BYE function# */
  313.     regs.h.ah = (char)flag;        /* load character to send */
  314.     int86(BYE_VECT, ®s, ®s);  /* perform BYE-PC call INT 66h */
  315.     }
  316.  
  317.  
  318. /*
  319. **  Function:    int rx_state(flag)
  320. **
  321. **  Parms:    flag = 1 Rx-chars from mdm ignored during keybd input
  322. **        flag = 0 Rx-chars from mdm sent to keybd input
  323. **
  324. **  Purpose:    This is used to temporarily toggle the input from
  325. **        the remote station on/off. The rx-queue is still active
  326. **        and continues to collect data while off. An rx-overflow
  327. **        can ocuur. Users should call Rx-flush before re-starting
  328. **        'rx_state()' to ON.
  329. **
  330. */
  331.  
  332. void rx_state(flag)
  333.  
  334.  int flag;
  335.     {
  336.     union REGS regs;
  337.  
  338.     regs.h.al = 9;            /* load BYE function# */
  339.     regs.h.ah = (char)flag;        /* load character to send */
  340.     int86(BYE_VECT, ®s, ®s);    /* perform BYE-PC call INT 66h */
  341.     }
  342.  
  343.  
  344. /*
  345. **  Function:    void tx_state(flag)
  346. **
  347. **  Parms:    flag = 1 Chars written to console are sent
  348. **        flag = 0 Chars written to console are not sent
  349. **
  350. **  Purpose:    This turns off the output to the remote end temporarily.
  351. **        Data written to the screen will not be sent if the
  352. **        tx_state is off. This allows writting the local screen
  353. **        without the output going to the remote end.
  354. **
  355. */
  356.  
  357. void tx_state(flag)
  358.  
  359.  int flag;
  360.     {
  361.     union REGS regs;
  362.  
  363.     regs.h.al = 10;            /* load BYE function# */
  364.     regs.h.ah = (char)flag;        /* load character to send */
  365.     int86(BYE_VECT, ®s, ®s);    /* perform BYE-PC call INT 66h */
  366.     }
  367.  
  368.  
  369. /*
  370. **  Function:    unsigned bye_vers()
  371. **
  372. **  Purpose:    Returns the currnet version# of BYE-PC running.
  373. **
  374. **  Return:    LSB = Revision Number
  375. **        MSB = Version Number
  376. **
  377. */
  378.  
  379. unsigned bye_vers()
  380.  {
  381.  union REGS inregs, outregs;
  382.  
  383.  inregs.h.al = 11;            /* load BYE function# */
  384.  int86(BYE_VECT, &inregs, &outregs);    /* perform BYE-PC call INT 66h */
  385.  return((unsigned)outregs.x.ax);    /* return version number */
  386.  }
  387.  
  388.  
  389. /*
  390. **  Function:    int get_nulls()
  391. **
  392. **  Purpose:    Returns the # nulls sent after each LF char.
  393. **
  394. */
  395.  
  396. int get_nulls()
  397.  {
  398.  union REGS inregs, outregs;
  399.  
  400.  inregs.h.al = 12;            /* load BYE function# */
  401.  int86(BYE_VECT, &inregs, &outregs);    /* perform BYE-PC call INT 66h */
  402.  return((int)outregs.x.ax);        /* return # of nulls */
  403.  }
  404.  
  405.  
  406. /*
  407. **  Function:    void set_nulls(x)
  408. **
  409. **  Parms:    int x = (0 to 9)
  410. **
  411. **  Purpose:    Sets the # nulls sent after each LF char.
  412. **
  413. */
  414.  
  415. void set_nulls(x)
  416.  int x;
  417.     {
  418.     union REGS regs;
  419.  
  420.     regs.h.al = 13;            /* load BYE function# */
  421.     regs.h.ah = (char)x;        /* load # of nulls */
  422.     int86(BYE_VECT, ®s, ®s);  /* perform BYE-PC call INT 66h */
  423.     }
  424.  
  425.  
  426. /*
  427. **  Function:    void warm_boot()
  428. **
  429. **  Parms:    <none>
  430. **
  431. **  Purpose:    Hangs up the modem and re-boots system. Used by
  432. **        XMDM and RBBS mainly.
  433. **
  434. */
  435.  
  436. void warm_boot()
  437.  {
  438.  union REGS regs;
  439.  
  440.  mdm_cd(OFF);             /* disable carrier detect */
  441.  mdm_dtr(OFF);             /* now hangup the modem */
  442.  regs.h.al = 14;         /* load BYE function# */
  443.  int86(BYE_VECT, ®s, ®s);  /* perform BYE-PC call INT 66h */
  444.  }
  445.  
  446.  
  447. /*
  448. **    The caller status word is a sixteen bit word used by SHELL, XMDM,
  449. **  and other application programs to check for command priorities which
  450. **  are set by an RBBS program before the user can enter DOS. The MSW of
  451. **  the status word bits have been reserved for any applications that
  452. **  may be developed in the future. The LSW bits have the followine
  453. **  meaning:
  454. **
  455. **    CSW (Caller status word):
  456. **
  457. **    {LSW (least significant word)}
  458. **
  459. **    ----MSB----  ----LSB----
  460. **    D7 D6 D5 D4  D3 D2 D1 D0
  461. **    |  |  |  |   |  |  |---|--- Max Drive allowed.
  462. **    |  |  |  |   |  |---------- PATH command allowed.
  463. **    |  |  |  |   |------------- CD command allowed.
  464. **    |  |  |  |----------------- XMDM S {file} allowed.
  465. **    |  |  |-------------------- XMDM R {file} allowed.
  466. **    |  |----------------------- Shell DOS command allowed.
  467. **    |-------------------------- Shell EXIT command allowed.
  468. **
  469. **
  470. **    {MSW (most significant word)}
  471. **
  472. **    ----MSB----  ----LSB----
  473. **    D7 D6 D5 D4  D3 D2 D1 D0        Reserved for
  474. **    {unused}    {unused}      Future application programs
  475. **
  476. **
  477. */
  478.  
  479.  
  480. /*
  481. **  Function:    int get_cstat()
  482. **
  483. **  Parms:    <none>
  484. **
  485. **  Purpose:    Returns the status level from BYE-PC of caller
  486. **        currently on line.
  487. **
  488. */
  489.  
  490. int get_cstat()
  491.  {
  492.  union REGS inregs, outregs;
  493.  
  494.  inregs.h.al = 15;            /* load BYE function# */
  495.  int86(BYE_VECT, &inregs, &outregs);    /* perform BYE-PC call INT 66h */
  496.  return(outregs.x.ax);
  497.  }
  498.  
  499.  
  500. /*
  501. **  Function:    int set_cstat(s)
  502. **
  503. **  Parms:    int s;     caller status level (0-ffffh)
  504. **
  505. **  Purpose:    Set the status level in BYE-PC for the caller
  506. **        currently on line.
  507. **
  508. */
  509.  
  510. void set_cstat(s)
  511.  
  512.  int s;
  513.  {
  514.  union REGS regs;
  515.  
  516.  regs.h.al = 16;         /* load BYE function# */
  517.  regs.x.cx = s;
  518.  int86(BYE_VECT, ®s, ®s);  /* perform BYE-PC call INT 66h */
  519.  }
  520.  
  521.  
  522.  
  523.