I/O Port Access in Microsoft Visual C++

Microsoft Visual C/C++ provides access to the I/O ports on the 80x86 CPU via the predefined functions _inp / _inpw and _outp / _outpw.

       int _inp(unsigned portid); /* returns a byte read from the I/O port portid */

 unsigned _inpw(unsigned portid); /* returns a word read from the I/O port portid */

      int _outp(unsigned portid,  /* writes the byte value to the I/O port portid */
                int value);       /* returns the data actually written            */

unsigned _outpw(unsigned portid,  /* writes the word value to the I/O port portid */
                unsigned value);  /* returns the data actually written            */

portid can be any unsigned integer in the range 0-65535

#include <conio.h> /* required only for function declarations */

#define Data    0x378
#define Status  0x379
#define Control 0x37a

int Bits,      /* 0 <= Bits <= 255 */ Dummy; Dummy = _outp(Data,Bits); /* output data */ Bits = _inp(Status); /* input data */ 

Here's my Digital Joystick example


[ Back to Reading & Writing Data ]


last updated: 13-Mar-97 Ian Harries <ih@doc.ic.ac.uk>