home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / dos_ency / 6 / cdvutl.c next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  7.8 KB  |  236 lines

  1. /* cdvutl.c - COMDVR Utility
  2.  *     Jim Kyle - 1987
  3.  *     for use with COMDVR.SYS Device Driver
  4.  */
  5.  
  6. #include <stdio.h>                 /* i/o definitions      */
  7. #include <conio.h>                 /* special console i/o  */
  8. #include <stdlib.h>                /* misc definitions     */
  9. #include <dos.h>                   /* defines intdos()     */
  10.  
  11. /*       the following define the driver status bits       */
  12.  
  13. #define HWINT 0x0800           /* MCR, first word, HW Ints gated */
  14. #define o_DTR 0x0200           /* MCR, first word, output DTR    */
  15. #define o_RTS 0x0100           /* MCR, first word, output RTS    */
  16.  
  17. #define m_PG  0x0010           /* LCR, first word, parity ON     */
  18. #define m_PE  0x0008           /* LCR, first word, parity EVEN   */
  19. #define m_XS  0x0004           /* LCR, first word, 2 stop bits   */
  20. #define m_WL  0x0003           /* LCR, first word, wordlen mask  */
  21.  
  22. #define i_CD  0x8000           /* MSR, 2nd word, Carrier Detect  */
  23. #define i_RI  0x4000           /* MSR, 2nd word, Ring Indicator  */
  24. #define i_DSR 0x2000           /* MSR, 2nd word, Data Set Ready  */
  25. #define i_CTS 0x1000           /* MSR, 2nd word, Clear to Send   */
  26.  
  27. #define l_SRE 0x0040           /* LSR, 2nd word, Xmtr SR Empty   */
  28. #define l_HRE 0x0020           /* LSR, 2nd word, Xmtr HR Empty   */
  29. #define l_BRK 0x0010           /* LSR, 2nd word, Break Received  */
  30. #define l_ER1 0x0008           /* LSR, 2nd word, FrmErr          */
  31. #define l_ER2 0x0004           /* LSR, 2nd word, ParErr          */
  32. #define l_ER3 0x0002           /* LSR, 2nd word, OveRun          */
  33. #define l_RRF 0x0001           /* LSR, 2nd word, Rcvr DR Full    */
  34.  
  35. /*           now define CLS string for ANSI.SYS            */
  36. #define CLS    "\033[2J"
  37.  
  38. FILE * dvp;
  39. union REGS rvs;
  40. int iobf [ 5 ];
  41.  
  42. main ()
  43. { cputs ( "\nCDVUTL - COMDVR Utility Version 1.0 - 1987\n" );
  44.   disp ();                         /* do dispatch loop           */
  45. }
  46.  
  47. disp ()                            /* dispatcher; infinite loop  */
  48. { int c,
  49.     u;
  50.   u = 1;
  51.   while ( 1 )
  52.     { cputs ( "\r\n\tCommand (? for help): " );
  53.       switch ( tolower ( c = getche ()))   /* dispatch           */
  54.         {
  55.         case '1' :                 /* select port 1              */
  56.           fclose ( dvp );
  57.           dvp = fopen ( "ASY1", "rb+" );
  58.              u = 1;
  59.           break;
  60.  
  61.         case '2' :                 /* select port 2              */
  62.           fclose ( dvp );
  63.           dvp = fopen ( "ASY2", "rb+" );
  64.           u = 2;
  65.           break;
  66.  
  67.         case 'b' :                 /* set baud rate              */
  68.           if ( iobf [ 4 ] == 300 )
  69.             iobf [ 4 ] = 1200;
  70.           else
  71.             if ( iobf [ 4 ] == 1200 )
  72.               iobf [ 4 ] = 2400;
  73.           else
  74.             if ( iobf [ 4 ] == 2400 )
  75.               iobf [ 4 ] = 9600;
  76.           else
  77.             iobf [ 4 ] = 300;
  78.           iocwr ();
  79.           break;
  80.  
  81.         case 'e' :                 /* set parity even            */
  82.           iobf [ 0 ] |= ( m_PG + m_PE );
  83.           iocwr ();
  84.           break;
  85.  
  86.         case 'f' :                 /* toggle flow control        */
  87.           if ( iobf [ 3 ] == 1 )
  88.             iobf [ 3 ] = 2;
  89.           else
  90.             if ( iobf [ 3 ] == 2 )
  91.               iobf [ 3 ] = 4;
  92.           else
  93.             if ( iobf [ 3 ] == 4 )
  94.               iobf [ 3 ] = 0;
  95.           else
  96.             iobf [ 3 ] = 1;
  97.           iocwr ();
  98.           break;
  99.  
  100.         case 'i' :                 /* initialize MCR/LCR to 8N1 : */
  101.           iobf [ 0 ] = ( HWINT + o_DTR + o_RTS + m_WL );
  102.           iocwr ();
  103.           break;
  104.  
  105.         case '?' :                 /* this help list              */
  106.           cputs ( CLS )            /* clear the display           */
  107.           center ( "COMMAND LIST \n" );
  108. center ( "1 = select port 1           L = toggle word LENGTH  " );
  109. center ( "2 = select port 2           N = set parity to NONE  " );
  110. center ( "B = set BAUD rate           O = set parity to ODD   " );
  111. center ( "E = set parity to EVEN      R = toggle error REPORTS" );
  112. center ( "F = toggle FLOW control     S = toggle STOP bits    " );
  113. center ( "I = INITIALIZE ints, etc.   Q = QUIT                " );
  114.          continue;
  115.  
  116.         case 'l' :                  /* toggle word length         */
  117.           iobf [ 0 ] ^= 1;
  118.           iocwr ();
  119.           break;
  120.  
  121.         case 'n' :                  /* set parity off             */
  122.           iobf [ 0 ] &=~ ( m_PG + m_PE );
  123.           iocwr ();
  124.           break;
  125.  
  126.         case 'o' :                  /* set parity odd             */
  127.           iobf [ 0 ] |= m_PG;
  128.           iobf [ 0 ] &=~ m_PE;
  129.           iocwr ();
  130.           break;
  131.  
  132.         case 'r' :                  /* toggle error reports       */
  133.           iobf [ 2 ] ^= 1;
  134.           iocwr ();
  135.           break;
  136.  
  137.         case 's' :                  /* toggle stop bits           */
  138.           iobf [ 0 ] ^= m_XS;
  139.           iocwr ();
  140.           break;
  141.  
  142.         case 'q' :
  143.           fclose ( dvp );
  144.           exit ( 0 );               /* break the loop, get out    */
  145.         }
  146.       cputs ( CLS );                /* clear the display          */
  147.       center ( "CURRENT COMDVR STATUS" );
  148.       report ( u, dvp );            /* report current status      */
  149.     }
  150. }
  151.  
  152. center ( s ) char * s;              /* centers a string on CRT    */
  153. { int i ;
  154.   for ( i = 80 - strlen ( s ); i > 0; i -= 2 )
  155.     putch ( ' ' );
  156.   cputs ( s );
  157.   cputs ( "\r\n" );
  158. }
  159.  
  160. iocwr ()                            /* IOCTL Write to COMDVR      */
  161. { rvs . x . ax = 0x4403;
  162.   rvs . x . bx = fileno ( dvp );
  163.   rvs . x . cx = 10;
  164.   rvs . x . dx = ( int ) iobf;
  165.   intdos ( & rvs, & rvs );
  166. }
  167.  
  168. char * onoff ( x ) int x ;
  169. { return ( x ? " ON" : " OFF" );
  170. }
  171.  
  172. report ( unit ) int unit ;
  173. { char temp [ 80 ];
  174.   rvs . x . ax = 0x4402;
  175.   rvs . x . bx = fileno ( dvp );
  176.   rvs . x . cx = 10;
  177.   rvs . x . dx = ( int ) iobf;
  178.   intdos ( & rvs, & rvs );         /* use IOCTL Read to get data */
  179.   sprintf ( temp, "\nDevice ASY%d\t%d BPS, %d-c-%c\r\n\n",
  180.            unit, iobf [ 4 ],           /* baud rate              */
  181.            5 + ( iobf [ 0 ] & m_WL ),  /* word length            */
  182.            ( iobf [ 0 ] & m_PG ?
  183.              ( iobf [ 0 ] & m_PE ? 'E' : 'O' ) : 'N' ),
  184.            ( iobf [ 0 ] & m_XS ? '2' : '1' )); /* stop bits      */
  185.   cputs ( temp );
  186.  
  187.   cputs ( "Hardware Interrupts are" );
  188.   cputs ( onoff ( iobf [ 0 ] & HWINT ));
  189.   cputs ( ", Data Terminal Rdy" );
  190.   cputs ( onoff ( iobf [ 0 ] & o_DTR ));
  191.   cputs ( ", Rqst To Send" );
  192.   cputs ( onoff ( iobf [ 0 ] & o_RTS ));
  193.   cputs ( ".\r\n" );
  194.  
  195.   cputs ( "Carrier Detect" );
  196.   cputs ( onoff ( iobf [ 1 ] & i_CD ));
  197.   cputs ( ", Data Set Rdy" );
  198.   cputs ( onoff ( iobf [ 1 ] & i_DSR ));
  199.   cputs ( ", Clear to Send" );
  200.   cputs ( onoff ( iobf [ 1 ] & i_CTS ));
  201.   cputs ( ", Ring Indicator" );
  202.   cputs ( onoff ( iobf [ 1 ] & i_RI ));
  203.   cputs ( ".\r\n" );
  204.  
  205.   cputs ( l_SRE & iobf [ 1 ] ? "Xmtr SR Empty, " : "" );
  206.   cputs ( l_HRE & iobf [ 1 ] ? "Xmtr HR Empty, " : "" );
  207.   cputs ( l_BRK & iobf [ 1 ] ? "Break Received, " : "" );
  208.   cputs ( l_ER1 & iobf [ 1 ] ? "Framing Error, " : "" );
  209.   cputs ( l_ER2 & iobf [ 1 ] ? "Parity Error, " : "" );
  210.   cputs ( l_ER3 & iobf [ 1 ] ? "Overrun Error, " : "" );
  211.   cputs ( l_RRF & iobf [ 1 ] ? "Rcvr DR Full, " : "" );
  212.   cputs ( "\b\b.\r\n" );
  213.  
  214.   cputs ( "Reception errors " );
  215.   if ( iobf [ 2 ] == 1 )
  216.     cputs ( "are encoded as graphics in buffer" );
  217.   else
  218.     cputs ( "set failure flag" );
  219.   cputs ( ".\r\n" );
  220.  
  221.   cputs ( "Outgoing Flow Control " );
  222.   if ( iobf [ 3 ] & 4 )
  223.     cputs ( "by XON and XOFF" );
  224.   else
  225.     if ( iobf [ 3 ] & 2 )
  226.       cputs ( "by RTS and CTS" );
  227.   else
  228.     if ( iobf [ 3 ] & 1 )
  229.       cputs ( "by DTR and DSR" );
  230.   else
  231.     cputs ( "disabled" );
  232.   cputs ( ".\r\n" );
  233. }
  234.  
  235. /*end of cdvutl.c */
  236.