home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 342_01 / chipfn02.c < prev    next >
Text File  |  1991-02-26  |  1KB  |  48 lines

  1. /*-
  2.  *  ----------------------------------------------------------------------
  3.  *  File        :   CHIPFN02.C
  4.  *  Creator     :   Blake Miller
  5.  *  Version     :   01.00.00            February 1991
  6.  *  Language    :   Microsoft Quick C   Version 2.0
  7.  *  Purpose     :   Intel 8255 Compatible Digital IO Functions
  8.  *              :   80X86 IN Instruction Function
  9.  *  ----------------------------------------------------------------------
  10.  */
  11.  
  12. void chp_portrd (int d_port, unsigned char *d_byte);
  13.  
  14. /*- CHIP : Byte Get --------------------------**
  15.  *  Read a byte from one of the 80X86 ports.
  16.  *  Duplicates the library function inp()
  17.  */
  18. void chp_portrd (int d_port, unsigned char *d_byte)
  19.     {
  20.     unsigned char   t_byte = 0; /* temporary byte   */
  21.  
  22.     /*  set port address
  23.      *  get data into AL
  24.      *  store data into temporary variable
  25.      *  Note: Use temporary variable because ASM has no idea
  26.      *  what a pointer to an unsigned char is!
  27.      */
  28.     _asm    {
  29.         PUSH    AX
  30.         PUSH    DX
  31.  
  32.         MOV     DX, d_port
  33.         IN      AL, DX          ; get byte into AL
  34.         MOV     t_byte, AL      ; transfer data to C temporary
  35.  
  36.         POP     DX
  37.         POP     AX
  38.         }
  39.  
  40.     *d_byte = t_byte;   /* transfer data back to C  */
  41.     }
  42.  
  43. /*-
  44.  *  ----------------------------------------------------------------------
  45.  *  END CHIPFN02.C Source File
  46.  *  ----------------------------------------------------------------------
  47.  */
  48.