home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / FOSSIL.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  11KB  |  468 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*           This module was originally written by Bob Hartman              */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                  BinkleyTerm FOSSIL version 5 module                     */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  27. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  28. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  29. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  30. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /* You can contact Bit Bucket Software Co. at any one of the following      */
  34. /* addresses:                                                               */
  35. /*                                                                          */
  36. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n343.z1.fidonet.org         */
  40. /*                                                                          */
  41. /* Please feel free to contact us at any time to share your comments about  */
  42. /* our software and/or licensing policies.                                  */
  43. /*                                                                          */
  44. /*--------------------------------------------------------------------------*/
  45.  
  46. /* Include this file before any other includes or defines! */
  47.  
  48. #include "includes.h"
  49.  
  50. #ifdef OS_2
  51.  
  52. void fossil_ver (void)
  53. {
  54.    extern int old_fossil;
  55.    old_fossil = 0;
  56. }
  57.  
  58. /* get_key () - P. Fitzsimmons */
  59. int get_key (void)
  60. {
  61.     int c = getch ();
  62.  
  63.     if (!c || c == 0xE0)   /* OS/2 returns 0xE0 if one of the *
  64.                             * grey edit keys are hit          */
  65.         c = getch () << 8;
  66.     return (c);
  67. }
  68.  
  69. #else /* ifdef OS_2 */
  70.  
  71. int Port = 0;
  72.  
  73. int FailSafeTimer = 0;
  74.  
  75. void fill_buffer (void);
  76.  
  77. void fossil_ver ()
  78. {
  79.    union REGS r;
  80.    struct SREGS s;
  81.  
  82.    char far *q;
  83.  
  84.    q = (char far *) &fossil_info;
  85.  
  86.    r.x.cx = sizeof (struct finfo);
  87.  
  88.    segread (&s);
  89.    s.es = s.ds = FP_SEG (q);
  90.  
  91.    r.x.di = r.x.si = FP_OFF (q);
  92.  
  93.    r.x.dx = Port;
  94.    r.x.ax = 0x1b00;
  95.  
  96.    (void) int86x (0x14, &r, &r, &s);
  97.  
  98.    if ((fossil_info.curr_fossil > 0) && !rev3)
  99.       old_fossil = 0;
  100. }
  101.  
  102. void com_kick ()
  103. {
  104.    XON_DISABLE ();                               /* Uncork the transmitter */
  105.    XON_ENABLE ();
  106. }
  107.  
  108. unsigned int Com_ (char request, byte parm1)
  109. {
  110.    union REGS r;
  111.  
  112.    r.h.ah = request;
  113.    r.h.al = parm1;
  114.    r.x.dx = Port;
  115.  
  116.    return int86 (0x14, &r, &r);
  117. }
  118.  
  119. int ComInit (int WhichPort, int failsafe)
  120. {
  121.    union REGS r;
  122.    struct SREGS s;
  123.    char far *ptr = &ctrlc_ctr;
  124.    int ret;
  125.  
  126.    fossil_fetch_pointer = fossil_buffer;
  127.    fossil_count = 0;
  128.  
  129.    r.h.ah = 4;
  130.    r.x.dx = (Port = WhichPort);
  131.    r.x.bx = 0x4f50;
  132.  
  133.    segread (&s);
  134.  
  135.    s.es = s.ds = FP_SEG (ptr);
  136.    r.x.cx = FP_OFF (ptr);
  137.  
  138.    ret = int86x (0x14, &r, &r, &s);
  139.  
  140.    if (ret == 0x1954)
  141.       {
  142.       FailSafeTimer = failsafe;
  143.       r.x.ax = 0x0f01;
  144.       r.x.dx = Port;
  145.       (void) int86 (0x14, &r, &r);
  146.       }
  147.    return (ret);
  148. }
  149.  
  150. int modem_in (void)
  151. {
  152.    unsigned char c;
  153.  
  154.    while (fossil_count == 0)
  155.       {
  156.       fill_buffer ();
  157.       if (fossil_count == 0)
  158.           time_release ();
  159.       }
  160.    --fossil_count;
  161.    c = (unsigned char) *fossil_fetch_pointer++;
  162.    return ((int)c);
  163. }
  164.  
  165. int peekbyte (void)
  166. {
  167.    unsigned char c;
  168.  
  169.    if (fossil_count == 0)
  170.       {
  171.       fill_buffer ();
  172.       if (fossil_count == 0)
  173.          return (-1);
  174.       }
  175.    c = (unsigned char) *fossil_fetch_pointer;
  176.    return ((int)c);
  177. }
  178.  
  179. void fill_buffer (void)
  180. {
  181.    union REGS r;
  182.    struct SREGS s;
  183.    char far *ptr = (char far *)fossil_buffer;
  184.    int ret;
  185.  
  186.    if (fossil_count != 0)
  187.       return;
  188.  
  189.    fossil_fetch_pointer = fossil_buffer;
  190.  
  191.    if (old_fossil == 0)
  192.       {
  193.       r.x.cx = 127;
  194.       r.x.dx = Port;
  195.  
  196.       segread (&s);
  197.  
  198.       r.x.di = r.x.si = FP_OFF (ptr);
  199.       s.es = s.ds = FP_SEG (ptr);
  200.  
  201.       r.x.ax = 0x1800;
  202.  
  203.       fossil_count = int86x (0x14, &r, &r, &s);
  204.       }
  205.    else
  206.       {
  207.       r.x.ax = 0x0c00;
  208.       r.x.dx = Port;
  209.  
  210.       ret = int86 (0x14, &r, &r);
  211.  
  212.       if (ret != -1)
  213.          {
  214.          fossil_count = 1;
  215.          *fossil_fetch_pointer = (char)ret;
  216.          r.x.ax = 0x0200;
  217.          (void) int86 (0x14, &r, &r);
  218.          }
  219.       }
  220. }
  221.  
  222. void clear_inbound (void)
  223. {
  224.    union REGS r;
  225.  
  226.    fossil_fetch_pointer = fossil_buffer;
  227.    fossil_count = 0;
  228.  
  229.    r.x.ax = 0x0a00;
  230.    r.x.dx = Port;
  231.  
  232.    (void) int86 (0x14, &r, &r);
  233. }
  234.  
  235.  
  236. void clear_outbound (void)
  237. {
  238.    union REGS r;
  239.  
  240.    out_send_pointer = out_buffer;
  241.    out_count = 0;
  242.  
  243.    r.x.ax = 0x0900;
  244.    r.x.dx = Port;
  245.  
  246.    (void) int86 (0x14, &r, &r);
  247. }
  248.  
  249. int modem_status (void)
  250. {
  251.    union REGS r;
  252.    int ret;
  253.  
  254.    r.x.ax = 0x0300;
  255.    r.x.dx = Port;
  256.  
  257.    ret = int86 (0x14, &r, &r);
  258.  
  259.    if (fossil_count != 0)
  260.       ret |= 256;
  261.  
  262.    return (ret);
  263. }
  264.  
  265. void do_break (int on_off)
  266. {
  267.    union REGS r;
  268.  
  269.    r.h.al = (char) on_off;
  270.    r.h.ah = 0x1a;
  271.    r.x.dx = Port;
  272.  
  273.    (void) int86 (0x14, &r, &r);
  274. }
  275.  
  276. void mdm_enable (unsigned int mask)
  277. {
  278.    union REGS r;
  279.  
  280.    CLEAR_INBOUND ();
  281.  
  282.    r.h.al = (byte) (mask | comm_bits | parity | stop_bits);
  283.    r.h.ah = 0;
  284.    r.x.dx = Port;
  285.  
  286.    (void) int86 (0x14, &r, &r);
  287. }
  288.  
  289. void mdm_disable (void)
  290. {
  291.    union REGS r;
  292.  
  293.    fossil_fetch_pointer = fossil_buffer;
  294.    fossil_count = 0;
  295.  
  296.    r.x.ax = 0x0500;
  297.    r.x.dx = Port;
  298.  
  299.    (void) int86 (0x14, &r, &r);
  300. }
  301.  
  302. void unbuffer_bytes (void)
  303. {
  304.    if (out_count == 0)
  305.       return;
  306.  
  307.    SENDCHARS ((char far *)out_buffer, out_count, 1);
  308.  
  309.    out_send_pointer = out_buffer;
  310.    out_count = 0;
  311. }
  312.  
  313. void buffer_byte (char c)
  314. {
  315.    if (out_count == 128)
  316.       unbuffer_bytes ();
  317.  
  318.    out_count++;
  319.    *out_send_pointer++ = c;
  320. }
  321.  
  322. void sendbyte (unsigned char c)
  323. {
  324.    union REGS r;
  325.    int done = 0;
  326.  
  327.    if (out_count != 0)
  328.       unbuffer_bytes ();
  329.  
  330.    while (done == 0)
  331.       {
  332.       r.h.ah = 0x0b;
  333.       r.h.al = c;
  334.       r.x.dx = Port;
  335.  
  336.       done = int86 (0x14, &r, &r);
  337.       if (done == 0)
  338.          {
  339.          (void) peekbyte (); /* Waiting for output, try to get input */
  340.          time_release ();
  341.          }
  342.       }
  343. }
  344.  
  345. void sendchars (char far *str, unsigned len, int dcd)
  346. {
  347.    union REGS r1, r2;
  348.    struct SREGS s;
  349.    long timer = 0L;
  350.    int sent;
  351.  
  352.    if (old_fossil)
  353.       {
  354.       r1.x.ax = 0x0b00;
  355.       r1.x.dx = Port;
  356.  
  357.       while (len != 0)
  358.          {
  359.          r1.h.al = *str;
  360.          if (int86 (0x14, &r1, &r2) != 0)
  361.             {
  362.             str++;
  363.             len--;
  364.             }
  365.          else
  366.             {
  367.             if (FailSafeTimer)
  368.                {
  369.                if (timer == 0L)
  370.                   timer = timerset (FailSafeTimer);
  371.                else
  372.                   {
  373.                   if (timeup (timer))
  374.                      {
  375.                      clear_outbound ();
  376.                      LOWER_DTR ();
  377.                      return;
  378.                      }
  379.                   }
  380.                }
  381.  
  382.             (void) peekbyte (); /* Waiting for output, try to get input */
  383.             time_release ();
  384.             if (dcd && !CARRIER)
  385.                return;
  386.             }
  387.          }
  388.       return;
  389.       }
  390.  
  391.    r1.x.ax = 0x1900;
  392.    r1.x.dx = Port;
  393.  
  394.    segread (&s);
  395.  
  396.    s.es = s.ds = FP_SEG (str);
  397.  
  398.    while (len != 0)
  399.       {
  400.       r1.x.cx = len;
  401.       r1.x.si = r1.x.di = FP_OFF (str);
  402.       sent = int86x (0x14, &r1, &r2, &s);
  403.       if (sent == (int)len)
  404.          return;
  405.  
  406.       len -= sent;
  407.       str += sent;
  408.  
  409.       if (FailSafeTimer)
  410.          {
  411.          if (timer == 0L)
  412.             timer = timerset (FailSafeTimer);
  413.          else
  414.             {
  415.             if (timeup (timer))
  416.                {
  417.                clear_outbound ();
  418.                LOWER_DTR ();
  419.                return;
  420.                }
  421.             }
  422.          }
  423.  
  424.       (void) peekbyte (); /* Waiting for output, try to get input */
  425.       time_release ();
  426.       if (dcd && !CARRIER)
  427.          return;
  428.       }
  429. }
  430.  
  431. void fossil_gotoxy (int col, int row)
  432. {
  433.    union REGS r;
  434.  
  435.    r.h.dh = (char) row;
  436.    r.h.dl = (char) col;
  437.    r.x.ax = 0x1100;
  438.  
  439.    (void) int86 (0x14, &r, &r);
  440. }
  441.  
  442. int fossil_whereami (void)
  443. {
  444.    union REGS r;
  445.    r.x.ax = 0x1200;
  446.    (void) int86 (0x14, &r, &r);
  447.    return r.x.dx;
  448. }
  449.  
  450. int fossil_wherey (void)
  451. {
  452.    union REGS r;
  453.    r.x.ax = 0x1200;
  454.    (void) int86 (0x14, &r, &r);
  455.    return (int) r.h.dh;
  456. }
  457.  
  458. int fossil_wherex (void)
  459. {
  460.    union REGS r;
  461.    r.x.ax = 0x1200;
  462.    (void) int86 (0x14, &r, &r);
  463.    return (int) r.h.dl;
  464. }
  465.  
  466. #endif
  467.  
  468.