I/O Port Access in Turbo Pascal

Turbo Pascal provides access to the I/O ports on the 80x86 CPU via two predefined arrays, Port and PortW

var Port:  array[0..65535] of byte;

    PortW: array[0..65534] of word;
The indexed elements of each array match the port at the corresponding I/O address. Assigning a value to an element of the Port or PortW arrays causes that value to be written out to the corresponding port. When an element of the Port or PortW arrays is referenced in an expression, the value is read in from the corresponding port.

Const Data    = $378;
      Status  = Data + 1;
      Control = Data + 2;

var Bits: Byte;

Port[Data] := Bits;  { output data }

Bits := Port[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>