home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUPC / TEST / UPC12ES4.ZIP / UTIL / comm34.c next >
Encoding:
C/C++ Source or Header  |  1993-10-24  |  6.3 KB  |  199 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    c o m m 3 4 . c                                                 */
  3. /*                                                                    */
  4. /*    Set/report communications port addresses                        */
  5. /*                                                                    */
  6. /*    Modified to report addresses and report usage by Andrew H.      */
  7. /*    Derbyshire.  Changes Copyright (c) 1992, Andrew H.              */
  8. /*    Derbyshire.                                                     */
  9. /*--------------------------------------------------------------------*/
  10.  
  11. /*--------------------------------------------------------------------*/
  12. /*                          RCS Information                           */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*
  16.  *    $Id: comm34.c 1.3 1993/10/24 20:58:55 rhg Exp $
  17.  *
  18.  *    Revision history:
  19.  *    $Log: comm34.c $
  20.  * Revision 1.3  1993/10/24  20:58:55  rhg
  21.  * Clean up for MS C 7.0
  22.  *
  23.  * Revision 1.2  1993/04/11  00:33:54  ahd
  24.  * Global edits for year, TEXT, etc.
  25.  *
  26.  * Revision 1.1  1992/11/15  04:29:22  ahd
  27.  * Initial revision
  28.  *
  29.  * Revision 1.2  1992/04/27  00:38:58  ahd
  30.  * Add RCS header
  31.  *
  32.  */
  33.  
  34. static char rcsid[] = "$Id: comm34.c 1.3 1993/10/24 20:58:55 rhg Exp $";
  35.  
  36. /*
  37.  * Compiler: Microsoft C 5.1
  38.  *
  39.  * COM34.C - set COM3 - COM4 addresses
  40.  *
  41.  * This program inserts the addresses specified by argv[1] - argv[2]
  42.  * into the BIOS table at 0040:0004 (COM3 - COM4)
  43.  *
  44.  * Usage: COMM4 xxx yyy
  45.  * where  xxx is COM3 address (hex), yyy is COM4 address (hex)
  46.  */
  47.  
  48. /*--------------------------------------------------------------------*/
  49. /*                      C standard include files                      */
  50. /*--------------------------------------------------------------------*/
  51.  
  52. #include <stdio.h>
  53. #include <stdlib.h>
  54.  
  55. /*--------------------------------------------------------------------*/
  56. /*                    UUPC/extended include files                     */
  57. /*--------------------------------------------------------------------*/
  58.  
  59. #include "lib.h"
  60. #include "timestmp.h"
  61.  
  62. #define MK_FP(seg,ofs)  ((void far *)(((unsigned long)(seg) << 16) | (ofs)))
  63.  
  64. static struct addr far *ports = (struct addr far *) MK_FP(0x40, 0);
  65.  
  66. unsigned htoi( char * buf );
  67. static void status( void );
  68. static void usage( void );
  69.  
  70. struct addr
  71. {
  72.    unsigned com[4];
  73. };
  74.  
  75. /*--------------------------------------------------------------------*/
  76. /*    m a i n                                                         */
  77. /*                                                                    */
  78. /*    Main program                                                    */
  79. /*--------------------------------------------------------------------*/
  80.  
  81. void main(int argc, char **argv)
  82. {
  83.    unsigned htoi();
  84.  
  85. /*--------------------------------------------------------------------*/
  86. /*                        Report our parentage                        */
  87. /*--------------------------------------------------------------------*/
  88.  
  89.    banner( argv );
  90.  
  91.    switch( argc )
  92.    {
  93.       case 3:
  94.          ports->com[3] = htoi(argv[2]);
  95.  
  96.       case 2:
  97.          ports->com[2] = htoi(argv[1]);
  98.          break;
  99.  
  100.       default:
  101.          usage();
  102.    }
  103.  
  104. /*--------------------------------------------------------------------*/
  105. /*                     Report new status and exit                     */
  106. /*--------------------------------------------------------------------*/
  107.  
  108.    status();
  109.    exit( 0 );
  110.  
  111. } /* main */
  112.  
  113. /*--------------------------------------------------------------------*/
  114. /*    s t a t u s                                                     */
  115. /*                                                                    */
  116. /*    Report current serial port status                               */
  117. /*--------------------------------------------------------------------*/
  118.  
  119. static void status( void )
  120. {
  121.    int port = 0;
  122.  
  123.    printf("Communications ports: ");
  124.  
  125.    while( port < 4 )
  126.    {
  127.       if (port)
  128.          printf(", ");
  129.  
  130.       if (ports->com[port])
  131.          printf("COM%d = %x",port+1, ports->com[port] );
  132.       else
  133.          printf("COM%d = (none)",port+1);
  134.  
  135.       port++;
  136.    } /* while */
  137.  
  138.    putchar('\n');
  139.  
  140. } /* status */
  141.  
  142. /*--------------------------------------------------------------------*/
  143. /*    h t o i                                                         */
  144. /*                                                                    */
  145. /*    Convert printable hex to integer                                */
  146. /*--------------------------------------------------------------------*/
  147.  
  148. unsigned htoi(char *buf)
  149. {
  150.    unsigned sum;
  151.    char c;
  152.  
  153.    for (sum = 0; (c = *buf) != '\0'; buf++)
  154.       switch(c)
  155.       {
  156.          case '0': case '1': case '2': case '3': case '4':
  157.          case '5': case '6': case '7': case '8': case '9':
  158.             sum = (sum * 16) + (c - '0');
  159.             break;
  160.  
  161.          case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
  162.             sum = (sum * 16) + (c - 'A' + 10);
  163.             break;
  164.  
  165.          case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
  166.             sum = (sum * 16) + (c - 'a' + 10);
  167.             break;
  168.  
  169.          default:
  170.             printf("Invalid port address %s, program exiting.\n",buf);
  171.             usage();
  172.       }
  173.  
  174.    return(sum);
  175.  
  176. } /* htoi */
  177.  
  178. /*--------------------------------------------------------------------*/
  179. /*    u s a g e                                                       */
  180. /*                                                                    */
  181. /*    Report program usage                                            */
  182. /*--------------------------------------------------------------------*/
  183.  
  184. static void usage( void )
  185. {
  186.    printf(
  187.       "This program alters the BIOS information for COM ports 3 and 4 for\n"
  188.       "use by UUPC/extended, MS-Kermit and other programs, and reports the\n"
  189.       "addresses of all installed COM ports.  Usage:\n\n"
  190.       "\tCOMM34\taddr3 [addr4]\n\n"
  191.       "Where addr3 is the hexadecimal address for port 3 (usually 2E8) and\n"
  192.       "Where addr4 is the optional hexadecimal address for port 4 (usually\n"
  193.       "2E0).\n\n");
  194.  
  195.    status();
  196.  
  197.    exit(1);
  198. }
  199.