home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IOPL32.ZIP / MAIN.C < prev    next >
Text File  |  1992-11-28  |  2KB  |  55 lines

  1. /***************************************************************************
  2. ****  This source demonstrate, how you can access I/O ports with IBM C Set/2.
  3. ****
  4. ****  The IO.ASM source is 16 bit. If you translate it to 32 bit, I/O will be
  5. ****  much faster.
  6. ****
  7. ****  IO.ASM can also used with Microsoft C 6.0.
  8. ****
  9. ****  The MAIN.C must be linked with OS2.LIB from Microsoft C 6.0 which
  10. ****  includes the 16-bit DosPortAccess() funktion.
  11. ****
  12. ****  Example:    I 3F8          Read a byte from I/O address 3F8
  13. ****              O 3F8 0D       Write byte 0D to I/O address 3F8
  14. ****
  15. ****  Thomas Gigge, SKY-NET Inc. Germany, CompuServe 100031,470
  16. ***************************************************************************/
  17.  
  18. #include "os2def.h"
  19.  
  20. #include "stdio.h"
  21.  
  22. APIRET16 APIENTRY16 RPORT(USHORT);
  23. void APIENTRY16 WPORT(USHORT,USHORT);
  24. APIRET16 APIENTRY16 DosPortAccess(USHORT,USHORT,USHORT,USHORT);
  25.  
  26. main()
  27. {
  28.    int base,value,rc;
  29.    char str[80];
  30.  
  31.    setbuf(stdout,NULL);
  32.  
  33.    /* I/O access from 000h to FFFh */
  34.    rc=DosPortAccess(0,0,0x000,0xFFF);
  35.    if (rc) printf("DosPortAccess()=%d\n",rc);
  36.  
  37.    for (;;) {
  38.       printf("[I/O] [ADDRESS] [VALUE] ? ");
  39.       gets(str);
  40.       strupr(str);
  41.  
  42.       switch (str[0]) {
  43.          case 'I':sscanf(&str[1],"%x",&base);
  44.                   value=RPORT(base);
  45.                   printf("%02X\n",value);
  46.                   break;
  47.          case 'O':sscanf(&str[1],"%x %x",&base,&value);
  48.                   WPORT(base,value);
  49.                   break;
  50.          default: printf("What?\n");
  51.                   break;
  52.          }
  53.       }
  54. }
  55.