Subsections

16. The PORTS unit

16.1 Introduction

The ports unit implements the port constructs found in . It uses classes and default array properties to do this.

The unit exists on LINUX, OS/2 and DOS. It is implemented only for compatibility with . It's usage is discouraged, because using ports is not portable programming, and the operating system may not even allow it (for instance WINDOWS).

Under LINUX, your program must be run as root, or the IOPerm call must be set in order to set appropriate permissions on the port access.

16.2 Types,constants and variables

16.2.1 Types

The following types are defined to implement the port access.
tport = class
  protected
    procedure writeport(p : longint;data : byte);
    function  readport(p : longint) : byte;
  public
    property pp[w : longint] : byte read readport write writeport;default;
end;

tportw = class
  protected
    procedure writeport(p : longint;data : word);
    function  readport(p : longint) : word;
  public
    property pp[w : longint] : word read readport write writeport;default;
end;

tportl = class
  Protected
    procedure writeport(p : longint;data : longint);
    function  readport(p : longint) : longint;
  Public
   property pp[w : Longint] : longint read readport write writeport;default;
end;
Each of these types allows access to the ports using respectively, a byte, a word or a longint sized argument.

Since there is a default property for each of this types, a sentence as

  port[221]:=12;
Will result in the byte 12 being written to port 221, if port is defined as a variable of type tport

16.2.2 variables

The following variables are defined:
port,
portb : tport;
portw : tportw;
portl : tportl;
They allow access to the ports in a compatible way.

root
2000-12-20