home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / advos2 / ch14 / c / ports.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-12-12  |  1.6 KB  |  58 lines

  1. /*
  2.     PORTS.C
  3.  
  4.     An OS/2 IOPL demonstration program that reads and displays the
  5.     first 256 I/O ports.  Requires the separate module PORTIO.ASM.
  6.  
  7.     Compile with:  C> cl /c ports.c
  8.     Link with:  C> link ports+portio,ports,,os2,ports
  9.  
  10.     Usage is:  C> ports
  11.  
  12.     Copyright (C) 1988 Ray Duncan
  13. */
  14.  
  15. #include <stdio.h>
  16.  
  17. #define API extern far pascal
  18.  
  19. unsigned API rport(unsigned);           /* function prototypes */
  20. void     API wport(unsigned, unsigned);
  21. void     API DosSleep(unsigned long);
  22. unsigned API DosPortAccess(unsigned, unsigned, unsigned, unsigned);
  23.  
  24.                                 /* parameters for DosPortAccess */
  25. #define REQUEST 0                       /* request port */
  26. #define RELEASE 1                       /* release port */
  27. #define BPORT   0                       /* beginning port */
  28. #define EPORT   255                     /* ending port */
  29.  
  30. main(int argc, char *argv[])
  31. {
  32.     int i;                              /* scratch variable */
  33.  
  34.                                         /* request port access */
  35.     if(DosPortAccess(0, REQUEST, BPORT, EPORT))
  36.     {   
  37.         printf("\nDosPortAccess failed.\n");
  38.         exit(1);
  39.     }
  40.  
  41.     printf("\n      ");                 /* print title line */
  42.     for(i=0; i<16; i++) printf(" %2X", i);
  43.  
  44.     for(i=BPORT; i<=EPORT; i++)         /* loop through all ports */
  45.     {
  46.         if((i & 0x0f)==0)
  47.         {
  48.             printf("\n%04X  ", i);      /* new line needed */
  49.         }
  50.  
  51.     printf(" %02X", rport(i));    /* read and display port */
  52.     }
  53.                                         /* release port access */
  54.     DosPortAccess(0, RELEASE, BPORT, EPORT);
  55. }
  56.  
  57. 
  58.