home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / cpgms.zip / DATASCOP.C < prev    next >
C/C++ Source or Header  |  1985-11-17  |  19KB  |  811 lines

  1. #define        DOTS    50    /* sector counting dots per line */
  2. #define     SPS    9500    /* loops per second  */
  3. #define     SECSIZ    0x80
  4. #define        DATMSK 0x7f
  5. #define        BUFSEC    128    /* number of filel sectors to buffer */
  6. #define        BUFSIZ    0x7f80    /* large text buffer (32k - 1 sector) */
  7. #define        ERRMAX 10    /* max errors before abort */
  8. #define        RETMAX 5    /* max retrys before abort */
  9. #define        ERROR    0    /* bad open return */
  10. #define        ERR    -1    /* general char for error */
  11. #define        FALSE    0    /* universal evil  */
  12. #define        TRUE    1    /* universal good  */
  13. #define        NULL    '\0'     /* end of string, etc */
  14. #define        EOF    -1    /* end of file on i/o */
  15.  
  16.  
  17. /***********************************************************************/
  18. /*                                                                     */
  19. /*    The following are specific for the IBM PC.                         */
  20. /*                                                                     */
  21. /***********************************************************************/
  22.  
  23. #define        REVVID    0x70    /* reverse video attribute */
  24. #define        NORM      0x07     /* normal video attribute */
  25.  
  26. /***********************************************************************/
  27. /*                                                                     */
  28. /*    Special characters used in the file transfer-protocol              */
  29. /*                                                                     */
  30. /***********************************************************************/
  31.  
  32. #define        TIMOUT    -1    /* timeout character */
  33. #define        SOH    1    /* start of sector character */
  34. #define        EOT    4    /* end of tranmission char */
  35. #define        ACK    6    /* Acknowledge sector transmission */
  36. #define        NAK    21    /* error in transmission detected */
  37.  
  38.  
  39. /***********************************************************************/
  40. /*                                                                     */
  41. /*    Miscellaneous ASCII characters                                     */
  42. /*                                                                     */
  43. /***********************************************************************/
  44.  
  45. #define        ESC    0x1b    /* escape code */
  46. #define        ENQ 0x05    /* enqueue.  when received, send Hereis string */
  47. #define        TAB    9
  48. #define        LF    10
  49. #define        CR    13
  50. #define        CTRLZ    26    /* eof char */
  51.  
  52. /***********************************************************************/
  53. /*                                                                     */
  54. /*    These defines determine which keys will be interpreted             */
  55. /*        as command characters                                        */
  56. /*                                                                     */
  57. /***********************************************************************/
  58.  
  59. #define        CTRLA    01 
  60. #define        CTRLB    02
  61. #define        CTRLC    03
  62. #define        CTRLE    05
  63. #define        CTRLI    08
  64. #define        CTRLK    11
  65. #define        CTRLL    12
  66. #define        CTRLO    15
  67. #define        CTRLP    16
  68. #define        CTRLQ    17
  69. #define        CTRLR    18
  70. #define        CTRLS    19
  71. #define        CTRLV    22
  72. #define        CTRLX    24
  73. #define        CTRLY    25
  74. #define        CTRLRS    30
  75.   /*  commands */
  76. #define        CMND    CTRLC
  77. #define        BAUD    'B'      /* change the baud rate */
  78. #define        CAPTUR    'C'      /* toggle text capture */
  79. #define        ECHO    CTRLE    /* local echo of keyboard data */
  80. #define        FILEIN    'F'    /* input from a file */
  81. #define     HEREIS  'H'     /* value to return as "hereis" after ENQ */ 
  82. #define        ISCOPE    'I'      /* toggle input data scope */
  83. #define        KEEP    'K'      /* keep text buffer */
  84. #define        LITERL    CTRLL    /* send literal character */
  85. #define        OSCOPE    'O'      /* toggle output data scope */
  86. #define        PRINT    CTRLP    /* echo to printer */
  87. #define        QUIT    'Q'      /* quit */
  88. #define        STAT    'S'      /* status display on screen */
  89. #define        TERMNL    'T'    /* enter terminal mode */
  90. #define       CTRL    CTRLRS    /* cntl char name escape */
  91. #define       SIMCR    '!'        /* Simulate CR  */
  92. #define       SIMCTRL    '^'        /* Simulate control char  */
  93.  
  94.  
  95. char ViewMd, BFlag, KbData, ModDat, Echofl, Showst, TrmMd;
  96. char AscFlg, ShowTr, ShowRc, View, Prntfl;
  97. char Commok, IScope, OScope, Herflg;
  98. char *Bufr, *Sbufr;    /* capture buffer pointers */
  99. char FileNm[15];
  100. char strbuf[20];
  101. char CmdBuf[60];
  102. char Hereisc[21];
  103. char Shstat[13] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',0};
  104. int Fd, PFd, IFd, CRCflg, Batflg;
  105. int _rax, _rdx;
  106. int TxtPtr;
  107. int brate = 1200;
  108. char Infile[15];
  109.  
  110. main(argc,argv)
  111. int argc;
  112. char *argv[];
  113. {
  114.     char ctlnam[4],c,getctl();
  115.     int i, j, datain(), getchar();
  116.  
  117.     AscFlg = ShowRc = ShowTr = BFlag = View = Echofl = TrmMd = FALSE;
  118.     Prntfl = Commok = OScope = IScope = Herflg = Showst = FALSE;
  119.     Fd = PFd = IFd = -1;   /* show file not open */
  120.     TxtPtr = 0;
  121.     ViewMd = KbData = CmdBuf[0] = Infile[0] = Hereisc[0] = NULL;
  122.  
  123.     dismod();    /* set display mode */
  124.  
  125.  
  126.     if ((Sbufr = Bufr = malloc(BUFSIZ)) == ERROR) {                  
  127.         conout("Unable to acquire buffer\n",NORM);         
  128.         getchar();                                         
  129.         return;                                            
  130.     }                                                      
  131.  
  132.     CmdBuf[0] = NULL;
  133.  
  134. /*    get the command line parameters, if any */
  135.     
  136.     i = 0; j = 1;
  137.     while ((argc > j) && (i < 60)) {
  138.         strncpy(&CmdBuf[i], argv[j], 60-i);
  139.         i += strlen(argv[j]) + 1;
  140.         j++;
  141.         CmdBuf[i-1] = ' ';
  142.     }
  143.     if (argc > 1) {
  144.         CmdBuf[i-1] = NULL;    /* set end of string */
  145.         for (i=0; CmdBuf[i] != '\0'; i++) /* cmd is upper */
  146.             CmdBuf[i] = toupper(CmdBuf[i]);
  147.     }
  148.  
  149.     evalcd(CmdBuf);
  150.  
  151.     initmd();
  152.  
  153.     /* the main loop */
  154.     /* while ((dcdrdy() || !Commok) && (CmdBuf[0] != QUIT)) { */
  155.     while (CmdBuf[0] != QUIT) { 
  156.  
  157.         if (!Commok && dcdrdy())  /* we have a connection */
  158.             Commok = TRUE;
  159.  
  160.         if (KbData = datain()) /* get any char at kbd or file */
  161.             switch(KbData) {   /* eval term mode cmds */
  162.             
  163.             case CMND:  
  164.                 TrmMd = FALSE;
  165.                 CmdBuf[0] = NULL;
  166.                 evalcd(CmdBuf);     /* eval cmd mode entry */
  167.                 break;
  168.  
  169.             case LITERL:
  170.                 while (!(KbData = datain()));
  171.                 mcharo(KbData);
  172.                 break;
  173.  
  174.             case PRINT:
  175.                 Prntfl = ~Prntfl;
  176.                 if (Prntfl & (PFd == -1))
  177.                     PFd = fopen("LST:", "w");
  178.                 if (Prntfl)
  179.                     conout("++ Printer ON ++\n",NORM);
  180.                 else
  181.                     conout("++ Printer OFF ++\n",NORM);
  182.                 break;
  183.  
  184.             case ECHO:
  185.                 Echofl = ~Echofl;
  186.                 if (Echofl)
  187.                     conout("++ Echo ON ++\n",NORM);
  188.                 else
  189.                     conout("++ Echo OFF ++\n",NORM);
  190.                 break;
  191.  
  192.             case CTRL:
  193.                 for (i=0; i<3; i++) {
  194.                     while (!(KbData = datain())); /* wait input */
  195.                     ctlnam[i] = toupper(KbData);
  196.                 }
  197.                 ctlnam[3] = NULL;
  198.                 if ((c = getctl(ctlnam)) == ERR)
  199.                     conout("Invalid Ctrl Name\n",NORM);
  200.                 else {
  201.                     mcharo(c); /* output value */    
  202.                 }    
  203.                 break;
  204.  
  205.             default:
  206.                 if ((IFd != -1) && (KbData == SIMCR)) 
  207.                     mcharo(CR);
  208.                 else 
  209.                     mcharo(KbData);
  210.                 break;
  211.             }
  212.         if (minrdy()) {
  213.             ModDat = mchari();
  214.             if (Showst) {     /* display stat in upper right corner */
  215.                 scr_rowcol(0,66);    /* position */
  216.                 conout(Shstat,REVVID);
  217.                 scr_rowcol(23,0);
  218.             }
  219.             if (BFlag && (TxtPtr < BUFSIZ))
  220.                 *(Bufr+(TxtPtr++)) = ModDat;
  221.             else if (BFlag) {
  222.                 conout("Capture Bufr overflow\n",NORM);
  223.                 getchar();
  224.             }
  225.             if (IScope) {
  226.                 showch(ModDat);
  227.                 if (ModDat == CR)
  228.                     conout("\n",NORM);
  229.             }
  230.             if (Herflg && ModDat == ENQ)   
  231.                 for (i=0; Hereisc[i]; i++) {
  232.                     if (Hereisc[i] == '!')
  233.                         mcharo(CR);
  234.                     else
  235.                         mcharo(Hereisc[i]);
  236.                 }
  237.             else if (ModDat == CR)
  238.                     conout("\n",NORM);
  239.             else 
  240.                 if ((ModDat > 0x1f) & (ModDat < 0x7f)) {
  241.                       strbuf[0] = ModDat;
  242.                      strbuf[1] = NULL;
  243.                       conout(strbuf,NORM);
  244.                 }
  245.             if (ModDat == CR)
  246.                 ModDat = '\n';
  247.             if (Prntfl)
  248.                     putc(ModDat, PFd);
  249.         }
  250.     }
  251. }
  252.  
  253.  
  254. evalcd(cbuf)
  255. char *cbuf;
  256. {
  257.     char Cmdchr, option[30], *savcbf;
  258.     int i;
  259.  
  260.     savcbf = cbuf;    /* save start of original buffer */
  261.     Cmdchr = NULL;
  262.  
  263.     while ((Cmdchr != QUIT) && (Cmdchr != TERMNL)) {
  264.  
  265.         if (*cbuf == NULL) {    /* need new cmd input */
  266.             cbuf = savcbf;
  267.             cmdmen();
  268.             getstr(60,cbuf);
  269.             for (i=0; cbuf[i] != '\0'; i++) /* cmd is upper */
  270.                 cbuf[i] = toupper(cbuf[i]);
  271.         }
  272.  
  273.         Cmdchr = *cbuf;
  274.  
  275.         /* skip command in buffer */
  276.         cbuf = skptok(cbuf);
  277.  
  278.         switch(Cmdchr) {   /* eval cmd mode cmds */
  279.             
  280.         case BAUD:
  281.             brate = atoi(cbuf);
  282.             if (brate = baudst(brate))
  283.                 initmd();
  284.             else {
  285.                 conout("Invalid baud rate -- Command terminated.\n",NORM);
  286.                 getchar();
  287.             }
  288.             break;
  289.  
  290.         case CAPTUR:
  291.             BFlag = ~BFlag;
  292.             if (BFlag) 
  293.                 conout("Capture initiated, ",NORM);
  294.             else 
  295.                 conout("Capture terminated, ",NORM);
  296.             itoa(BUFSIZ - TxtPtr,strbuf);
  297.             conout(strbuf,NORM);
  298.             conout(" bytes free\n",NORM);
  299.             if (IFd != -1) 
  300.                 getchar();
  301.             break;
  302.     
  303.         case KEEP:
  304.             if (!TxtPtr) {
  305.                 conout("Nothing to save\n",NORM);
  306.                 if (IFd != -1) 
  307.                     getchar();
  308.             }
  309.             else {
  310.                 if (*cbuf == ' ') {    /* user entered filename */
  311.                     cbuf++;
  312.                     mkstr(15,cbuf,FileNm);
  313.                 }
  314.                 else {
  315.                     conout("Save as what file? \n",NORM);
  316.                     getstr(15,FileNm);
  317.                 }
  318.                 *(Bufr+(TxtPtr)) = CTRLZ;
  319.                 Fd = fopen(FileNm, "w");
  320.                 if (Fd == ERROR) {
  321.                     conout("Cannot create ",NORM);
  322.                     conout(FileNm,NORM);
  323.                     getchar();
  324.                 }
  325.                 else {
  326.                     write(Fd, Bufr,
  327.                         1+TxtPtr);
  328.                     fclose(Fd);
  329.                     BFlag = FALSE;
  330.                     TxtPtr = 0;
  331.                 }
  332.             }
  333.             break;
  334.     
  335.         case FILEIN:
  336.             if (*cbuf == ' ') {    /* user entered filename */
  337.                 cbuf++;
  338.                 mkstr(15,cbuf,Infile);
  339.             }
  340.             else {
  341.                 if (IFd != -1) {
  342.                     fclose(IFd);
  343.                     IFd = -1;
  344.                 }
  345.             }
  346.             IFd = fopen(Infile, "r");
  347.             if (IFd == ERROR) {
  348.                 conout("Cannot open ",NORM);
  349.                 conout(Infile,NORM);
  350.                 getchar();
  351.                 IFd = -1;
  352.             }
  353.             break;
  354.  
  355.         case QUIT:
  356.             hangup();
  357.             break;
  358.  
  359.         case ISCOPE:
  360.             IScope = ~IScope;
  361.             break;
  362.  
  363.         case OSCOPE:
  364.             OScope = ~OScope;
  365.             break;
  366.  
  367.         case HEREIS:
  368.             Herflg = ~Herflg;
  369.             if (*cbuf == ' ') {    /* user entered string */
  370.                 cbuf++;
  371.                 mkstr(21,cbuf,Hereisc);
  372.             }
  373.             else {
  374.                 conout("\nEnter the 'Here-is' string ('!' for CR) ",NORM);
  375.                 getstr(21,Hereisc);
  376.             }
  377.             break;
  378.  
  379.         case STAT:
  380.             Showst = ~Showst;
  381.             break;
  382.     
  383.         case TERMNL:
  384.             TrmMd = TRUE;
  385.             break;
  386.  
  387.         default: 
  388.             conout("Invalid Command, try again\n",NORM);
  389.             getchar();
  390.         }
  391.     for(;(*cbuf != ';') && (*cbuf != '\n') && (*cbuf != '\0') && (*cbuf != CR)
  392.                                             ;cbuf++)
  393.                 ;      /* skip this command */
  394.     }
  395.     clrscr();
  396.     return;
  397. }
  398.  
  399. int datain()
  400. {
  401.     int nc, c, kbdin();
  402.     unsigned i;
  403.  
  404.     if (IFd != -1) {
  405.         if ((c = kbdin()) == CMND) {
  406.             conout("\nFile Abort from Console \n",NORM);
  407.             fclose(IFd);
  408.             IFd = -1;
  409.             getchar();
  410.             return(c);
  411.         }
  412.         if ((c = getc(IFd)) == EOF) {
  413.             conout("\nEnd of File on ",NORM);
  414.             conout(Infile,NORM);
  415.             fclose(IFd);
  416.             IFd = -1;
  417.             return(kbdin());
  418.         }
  419.         else {
  420.             if (TrmMd) {
  421.                 if (c == SIMCTRL) {
  422.                     if ((nc = getc(IFd)) == EOF) {
  423.                         conout("\nPremature End of File on ",NORM);
  424.                         conout(Infile,NORM);
  425.                         fclose(IFd);
  426.                         IFd = -1;
  427.                         return(kbdin());
  428.                     }
  429.                     if (nc != c)
  430.                         c = 0xbf & nc;    /* convert to control character */
  431.                 }
  432.                 for (i=0; i <10000; i++) ;
  433.             }
  434.             return(c);
  435.         }
  436.     }
  437.     else
  438.         return(kbdin());
  439. }
  440.  
  441. int kbdin()
  442. {
  443.     char scr_csts();
  444.     return((int)scr_csts());
  445. }
  446.  
  447.  
  448. skptok(cbuf)
  449. char *cbuf;
  450. {
  451.         /* skip token in buffer */
  452.     for(;(*cbuf != ' ') && (*cbuf != ';') && (*cbuf != '\0');cbuf++)
  453.         ;
  454.     return (cbuf);
  455. }
  456.  
  457.  
  458. cmdmen()
  459. {
  460.     char OnOff[4];
  461.     char Filenam[16];
  462.     int i;
  463.  
  464.     clrscr();  /* clear screen */
  465.     
  466.     conout("                                C Modem\n",NORM);
  467.     conout("\nCommand Mode Commands\n",NORM);
  468.     conout("Baud [rate]      (",NORM);
  469.     itoa(brate,strbuf);
  470.     conout(strbuf,NORM);
  471.     conout(")                  Set baud rate\n",NORM);
  472.  
  473.     if (BFlag)
  474.         strcpy(OnOff,"On ");
  475.     else
  476.         strcpy(OnOff,"Off");
  477.     conout("Capture          (",NORM);
  478.     conout(OnOff,NORM);
  479.     conout(")                  Capture received data to buffer\n",NORM);
  480.  
  481.     if (IFd != -1)
  482.         strcpy(Filenam,Infile);
  483.     else
  484.         strcpy(Filenam,"Kybd       ");
  485.     conout("From [filename]: (",NORM);
  486.     conout(Filenam,NORM);
  487.     conout(")          Input Source\n",NORM);  
  488.  
  489.     if (IScope)
  490.         strcpy(OnOff,"On ");
  491.     else
  492.         strcpy(OnOff,"Off");
  493.     conout("Inp Scope        (",NORM);
  494.     conout(OnOff,NORM);
  495.     conout(")                  Input Datascope Toggle\n",NORM);  
  496.  
  497.     conout("Keep [drive/filename]                   Save captured data\n",NORM);
  498.  
  499.     if (OScope)
  500.         strcpy(OnOff,"On ");
  501.     else
  502.         strcpy(OnOff,"Off");
  503.     conout("Out Scope        (",NORM);
  504.     conout(OnOff,NORM);
  505.     conout(")                  Output Datascope Toggle\n",NORM);  
  506.  
  507.     if (Showst)
  508.         strcpy(OnOff,"On ");
  509.     else
  510.         strcpy(OnOff,"Off");
  511.     conout("Status Display   (",NORM);
  512.     conout(OnOff,NORM);
  513.     conout(")                  Line and Modem Status\n",NORM);  
  514.  
  515.     conout("Here-is string   (",NORM);
  516.     conout(Hereisc,NORM);
  517.     conout(")",NORM);
  518.     for (i=0; i < (21 - strlen(Hereisc)); i++)
  519.         conout(" ",NORM);
  520.     conout("Output Datascope Toggle\n",NORM);  
  521.  
  522.     conout("Quit                                    Exit program\n",NORM);
  523.     conout("Terminal                                Enter terminal mode\n",NORM);
  524.     
  525.     conout("\nTerminal Mode Commands\n",NORM);
  526.     conout("      ^C                    Enter command mode\n",NORM);
  527.  
  528.     if (Echofl)
  529.         strcpy(OnOff,"On ");
  530.     else
  531.         strcpy(OnOff,"Off");
  532.     conout("      ^E    (",NORM);
  533.     conout(OnOff,NORM);
  534.     conout(")           Echo On/Off\n",NORM);
  535.     conout("      ^L                    Send next char as-is\n",NORM);
  536.  
  537.     if (Prntfl)
  538.         strcpy(OnOff,"On ");
  539.     else
  540.         strcpy(OnOff,"Off");
  541.     conout("      ^P    (",NORM);
  542.     conout(OnOff,NORM);
  543.     conout(")           Printer On/Off\n",NORM);
  544.  
  545.     conout("\n       Command:  ",NORM);
  546.  
  547.     return;
  548. }
  549.  
  550.  
  551. getstr(maxlen, str)
  552. int maxlen;
  553. char *str;
  554. {
  555.     int c;
  556.     int datain();
  557.  
  558.     while ((--maxlen) > 0) {
  559.         c = datain();
  560.         while ((c == NULL) || (c == '\n'))
  561.             c = datain();
  562.         if ((c > 0x1f) & (c < 0x7f)) {
  563.               strbuf[0] = c;
  564.              strbuf[1] = NULL;
  565.               conout(strbuf,NORM);
  566.             *str++ = c;
  567.         }
  568.         else if (c == '\b') {        /* if backspace, then */
  569.             *str-- = ' ';            /* get rid of unwanted char */
  570.             maxlen++;        /* and fool loop counter */
  571.               putchar(c); 
  572.         }
  573.         else 
  574.             *str++ = c;
  575.  
  576.         if ((c  == '\n') || (c == CR)) {
  577.             str--;
  578.             break;
  579.         }
  580.         if (c  == SIMCR)            /* handle simulated CR */ 
  581.             if (str[-2] == CR) {    /* is it a real exclamation point? */
  582.                 *str-- = ' ';
  583.                 str[-1] = SIMCR;
  584.             }
  585.         else
  586.             str[-1] = CR;
  587.     }
  588.     *str = '\0';
  589. }
  590.  
  591.  
  592.  
  593. /*************************************************************************/
  594. /*                                                                       */
  595. /*    The following functions may be hardware dependent.  These are        */
  596. /*    set up for the Hayes Smartmodem 1200 using the IBM serial            */
  597. /*    card.                                                                */
  598. /*                                                                       */
  599. /*************************************************************************/
  600.  
  601.  
  602. /*   port definitions  */
  603.  
  604. #define    mstat    0x3fe    /* modem status port */
  605. #define mcntl    0x3fc    /* modem data port   */
  606. #define lnesta  0x3fd    /* line status port  */
  607. #define rxbuf   0x3f8    /* receive data port */
  608. #define txbuf   0x3f8    /* transmit data port */
  609.  
  610. /* status bit masks  */
  611.  
  612. #define rxrdy    0x01    /* receive char ready */
  613. #define txrdy   0x20    /* transmit buffer empty */
  614. #define mdcd    0x80    /* modem carrier detect */
  615. #define mcts    0x10    /* modem clear to send */
  616. #define errpar    0x04    /* parity error detected */
  617. #define errovr    0x02    /* overrun error detected */
  618. #define errfrm    0x08    /* framing error detected */
  619. #define mdtr    0x01    /* data terminal ready */
  620. #define mrts    0x02    /* request to send */
  621.  
  622. int baudrt = 04;  /* index for 1200 baud (baudtb[4]=1200) */
  623.  
  624. baudst(baudin)
  625. int baudin;
  626. {
  627.     static baudtb[] = {110,150,300,600,1200,
  628.         2400,4800,9600};
  629.     static int indx;
  630.     static char baudst[5];
  631.  
  632.     while (baudin == 0) {
  633.         conout("\n\t 110,150,300,600,1200",NORM);
  634.         conout("\n\t 2400,4800,9600",NORM);
  635.         conout("\nEnter the required baud rate ",NORM);
  636.         getstr(5,baudst);
  637.         baudin = atoi(baudst);
  638.     }
  639.  
  640.     for (indx=0; indx<(sizeof(baudtb)/sizeof(baudtb[1])); indx++) 
  641.         if (baudin == baudtb[indx]) {
  642.             baudrt = indx;
  643.             return baudin;
  644.         }
  645.     return FALSE;
  646. }
  647.  
  648. dismod()
  649. {
  650.     scr_setup();
  651.     return;
  652. }
  653.  
  654.  
  655.  
  656. clrscr()
  657. {
  658.     scr_clr();
  659. }
  660.  
  661.  
  662. conout(s,attr)
  663. char *s;
  664. int attr;
  665. {
  666.     scr_aputs(s,attr);
  667. }
  668.  
  669.  
  670. initmd()
  671. {
  672.     sioint(baudrt);
  673.     prglne();
  674. }
  675.  
  676. prglne()
  677. {
  678.     while (minrdy())    /* while there are characters... */
  679.         mchari();    /* gobble them  */
  680. }
  681.  
  682. mchari()
  683. {
  684.     while (!(lstatus() & rxrdy));
  685.     return inp(rxbuf);
  686. }
  687.  
  688. mcharo(c)
  689. char c;
  690. {
  691.     outp(mcntl,(cstatus() | mrts));            /* turn on rts */
  692.     while(!(lstatus() & txrdy));
  693.     outp(txbuf,c);
  694.     outp(mcntl,(cstatus() & (0xff - mrts)));   /* turn off rts */
  695.     if (Echofl)
  696.         kbecho(c);
  697. }
  698.  
  699. motrdy()
  700. {
  701.     return ((lstatus() & txrdy) > 0);
  702. }
  703.  
  704. lstatus()
  705. {
  706.     char lstat;
  707.     lstat = inp(lnesta);
  708.     if (Showst) {
  709.         if (lstat & rxrdy)
  710.             Shstat[0] = 'R';
  711.         else
  712.             Shstat[0] = '.';
  713.         if (lstat & txrdy)
  714.             Shstat[1] = 'T';
  715.         else
  716.             Shstat[1] = '.';
  717.         if (lstat & errpar)
  718.             Shstat[6] = 'P';
  719.         else
  720.             Shstat[6] = '.';
  721.         if (lstat & errovr)
  722.             Shstat[7] = 'O';
  723.         else
  724.             Shstat[7] = '.';
  725.         if (lstat & errfrm)
  726.             Shstat[8] = 'F';
  727.         else
  728.             Shstat[8] = '.';
  729.     }
  730.     return (lstat);
  731. }
  732.  
  733. mstatus()
  734. {
  735.     char msta;
  736.     msta = inp(mstat);
  737.     if (Showst) {
  738.         if (msta & mdcd)
  739.             Shstat[3] = 'C';
  740.         else
  741.             Shstat[3] = '.';
  742.         if (msta & mcts)
  743.             Shstat[4] = 'C';
  744.         else
  745.             Shstat[4] = '.';
  746.     }
  747.     return (msta);
  748. }
  749.  
  750. cstatus()
  751. {
  752.     char mctl;
  753.     mctl = inp(mcntl);
  754.     if (Showst) {
  755.         if (mctl & mdtr)
  756.             Shstat[10] = 'D';
  757.         else
  758.             Shstat[10] = '.';
  759.         if (mctl & mrts)
  760.             Shstat[11] = 'R';
  761.         else
  762.             Shstat[11] = '.';
  763.     }
  764.     return (mctl);
  765. }
  766.  
  767. minrdy()
  768. {
  769.     return ((lstatus() & rxrdy) > 0);
  770. }
  771.  
  772. dcdrdy()
  773. {
  774.     return ((mstatus() & mdcd) > 0);
  775. }
  776.  
  777. hangup()
  778. {
  779.     outp(mcntl,(cstatus() & (0xff - mdtr)));
  780.             /* clear data term ready to make
  781.                the smartmodem hang up   */
  782. }
  783. inp(port)
  784. int port;
  785. {
  786.     return(_inb(port));
  787. }
  788.  
  789. outp(port, val)
  790. int port, val;
  791. {
  792.     _outb(val,port);
  793.     return;
  794. }
  795.  
  796. sioint(baud)
  797. int baud;
  798. {
  799.     int intparm;
  800.  
  801.     /* set given baud rate, no parity, 1 sto bit, 8 bits/char */
  802.     intparm = baud << 5;        /* correct pos for interrupt */
  803.     intparm = intparm | 2;        /* 7 bits/char (7-5=2) */
  804.     intparm = intparm | 24;     /* even parity  */
  805.     _rdx = 0;                    /* select com1 port */
  806.     _rax=intparm;
  807.     _doint(0x14);
  808.     outp(mcntl,(cstatus() | mdtr));            /* turn on dtr */
  809.     return;
  810. }
  811.