home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_02 / 2n02040a < prev    next >
Text File  |  1990-12-27  |  2KB  |  68 lines

  1. /*-
  2.  *  -------------------------------------------------------
  3.  *  File:       PORTIO.C
  4.  *  Creator:    Blake Miller
  5.  *  Version:    01.00.00            October 1990
  6.  *  Language:   Microsoft Quick C   Version 2.0
  7.  *  Purpose:    80X86 IN and OUT Instruction C Interface
  8.  *              Similar to MSC inp and outp instructions.
  9.  *  -------------------------------------------------------
  10.  */
  11.  
  12. void chp_portwt (int d_port, unsigned char d_byte);
  13. void chp_portrd (int d_port, unsigned char *d_byte);
  14.  
  15. /*- Byte Get ---------------------------------**
  16.  *  Read a byte from one of the 80X86 ports.
  17.  *  Duplicates the library function inp()
  18.  */
  19. void chp_portrd (int d_port, unsigned char *d_byte)
  20.     {
  21.     unsigned char   t_byte = 0; /* temporary byte   */
  22.  
  23.     /*  set port address
  24.      *  get data into AL
  25.      *  store data into temporary variable
  26.      *  Note: Use temporary variable because ASM has no idea
  27.      *  what a pointer to an unsigned char is!
  28.      */
  29.     _asm    {
  30.         PUSH    AX
  31.         PUSH    DX
  32.  
  33.         MOV     DX, d_port
  34.         IN      AL, DX          ; get byte into AL
  35.         MOV     t_byte, AL      ; transfer data to C
  36.  
  37.         POP     DX
  38.         POP     AX
  39.         }
  40.  
  41.     *d_byte = t_byte;   /* transfer data to caller  */
  42.     }
  43.  
  44. /*- Byte Put ---------------------------------**
  45.  *  Write a byte to one of the 80X86 ports.
  46.  *  Duplicates the library function outp()
  47.  */
  48. void chp_portwt (int d_port, unsigned char d_byte)
  49.     {
  50.     _asm    {
  51.         PUSH    AX
  52.         PUSH    DX
  53.  
  54.         MOV     DX, d_port
  55.         MOV     AL, d_byte
  56.         OUT     DX, AL
  57.  
  58.         POP     DX
  59.         POP     AX
  60.         }
  61.     }
  62.  
  63. /*-
  64.  *  -------------------------------------------------------
  65.  *  END PORTIO.C Source File
  66.  *  -------------------------------------------------------
  67.  */
  68.