home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR2 / DIGIPROG.ZIP / DEMOB.C < prev    next >
Text File  |  1991-09-10  |  3KB  |  185 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8. /*    Compiled under TurboC 2.0
  9.  
  10.     The purpose of this code is to demonstrate how to use the DigiBoard
  11.     DOS driver INT 14h interface in a simple manner.
  12.  
  13.     This program will monitor the DigiBoard for received data using the DOS
  14.     Driver's Character Ready Flags. If any data is present, it will be fetched
  15.     using INT 14h function 2 and printed to the console. If the User types
  16.     data on the console keyboard, it will be sent to the DigiBoard using
  17.     INT 14h function 1. Press ESC to quit.
  18.  
  19.     Each DigiBoard channel has a Character Ready Flag stored in the driver's
  20.     memory space. When receive data is present on a given channel, it's flag
  21.     is set to hex FF, otherwise, its set to 0. In order for the flag's value
  22.     to be valid, the DigiBoard must    be configured for an IRQ and the Character
  23.     Ready Flag option must be selected using XIDOSCFG.EXE. The flags location
  24.     can be determined using INT 14h function 0D hex.
  25.  
  26.  
  27. */
  28.  
  29.  
  30. #include <dos.h>
  31. #include <stdio.h>
  32.  
  33. #define        ESC        0x1b
  34. #define        TRUE    1
  35. #define        FALSE    0
  36.  
  37.  
  38. struct REGPACK  sregs;
  39. union  REGS        regs;
  40.  
  41.  
  42.  
  43. unsigned char far *get_ch_rdy_ptr(chnl)
  44. int    chnl;
  45. {
  46.  
  47. /*
  48.     This function returns a far pointer to the Character Ready Flag for the
  49.     channel passed to it as an argument.
  50. */
  51.  
  52.     struct SREGS    sregs;
  53.  
  54.     regs.h.ah = 0x0D;                    /* set ah = 0Dh */
  55.     regs.x.dx = chnl;                      /* set channel number */
  56.     int86x(0x14,®s,®s,&sregs);    /* make INT 14h call */
  57.                                         /* return far pointer to flag */
  58.     return(MK_FP(sregs.es,regs.x.bx));
  59.  
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. data_ready(ptr)
  69. unsigned char far * ptr;
  70. {
  71.  
  72.  
  73. /*
  74.     This function takes the character ready flag pointer passed to it and
  75.     returns a value based on the state of the character ready flag.
  76.  
  77.     If the flag's value is 0FFh, then data is present, and 1 is returned.
  78.     Otherwise, there is no receive data present and 0 is returned.
  79.  
  80. */
  81.  
  82.  
  83.  
  84.     if(*ptr == 0xff) return(TRUE);
  85.     else return(FALSE);
  86.  
  87. }
  88.  
  89.  
  90.  
  91. unsigned char get_data(chnl)
  92. int    chnl;
  93. {
  94.  
  95.  
  96. /*
  97.  
  98.     This function returns data from the specified channel.
  99.  
  100. */
  101.  
  102.  
  103.  
  104.     regs.h.ah = 0x02;                /* set ah = 02h */
  105.     regs.x.dx = chnl;                /* set channel number */
  106.     int86(0x14,®s,®s);        /* make INT 14h call */
  107.     return(regs.h.al);                /* return character from AL */
  108.  
  109. }
  110.  
  111.  
  112.  
  113. send_data(chnl,ch)
  114. int        chnl;
  115. char    ch;
  116. {
  117.  
  118.  
  119. /*
  120.  
  121.     This function sends a byte of data to the specified channel.
  122.  
  123. */
  124.  
  125.  
  126.     regs.h.ah = 0x01;                /* set ah = 01h */
  127.     regs.h.al = ch;                    /* set al to send character */
  128.     regs.x.dx = chnl;                /* set channel number */
  129.     int86(0x14,®s,®s);        /* make INT 14h call */
  130. }
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139. main()
  140. {
  141.  
  142.     int    x,dx;
  143.     unsigned char    far *chrdy,ch;
  144.  
  145.  
  146.     /* Let the user specify the DigiBoard channel to use. */
  147.  
  148.     printf("\nEnter DX : ");
  149.     scanf("%d",&dx); while(kbhit()) getch();
  150.  
  151.  
  152.     /* get pointer to character ready flag */
  153.  
  154.     chrdy = get_ch_rdy_ptr(dx);
  155.  
  156.  
  157.  
  158.     /* Look for data to send or receive until the user wants to quit */
  159.  
  160.  
  161.     while(1)
  162.     {
  163.  
  164.         /* Print received data, if there is any. */
  165.  
  166.         if( data_ready(chrdy) )
  167.         {
  168.  
  169.             printf("%c",get_data(dx));
  170.  
  171.         }
  172.  
  173.  
  174.         /* If the User enters data, Send It */
  175.  
  176.         if(kbhit())
  177.         {
  178.  
  179.             if( (ch = getch()) == ESC) break;    /* The User wants to Quit */
  180.             send_data(dx,ch);                    /* Send User's Data */
  181.  
  182.         }
  183.     }
  184. }
  185.