%
%   $Id$
%   This file is part of the FPC documentation.
%   Copyright (C) 1997, by Michael Van Canneyt
%
%   The FPC documentation is free text; you can redistribute it and/or
%   modify it under the terms of the GNU Library General Public License as
%   published by the Free Software Foundation; either version 2 of the
%   License, or (at your option) any later version.
%
%   The FPC Documentation is distributed in the hope that it will be useful,
%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%   Library General Public License for more details.
%
%   You should have received a copy of the GNU Library General Public
%   License along with the FPC documentation; see the file COPYING.LIB.  If not,
%   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
%   Boston, MA 02111-1307, USA.
%
\chapter{The PORTS unit}

\section{Introduction}
The ports unit implements the \var{port} constructs found in \tp. 
It uses classes and default array properties to do this.

The unit exists on \linux, \ostwo and \dos. It is implemented only for
compatibility with \tp. 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 \var{IOPerm} call
must be set in order to set appropriate permissions on the port access.

\section{Types,constants and variables}

\subsection{Types}
The following types are defined to implement the port access.
\begin{verbatim}
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;
\end{verbatim}
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
\begin{verbatim}
  port[221]:=12;
\end{verbatim}
Will result in the byte 12 being written to port 221, if port is defined
as a variable of type \var{tport}
\subsection{variables}       
The following variables are defined:
\begin{verbatim}
port,
portb : tport;
portw : tportw;
portl : tportl;
\end{verbatim}
They allow access to the ports in a \tp compatible way.
