library direct95;

(* Direct Hardware access library for use under WIN95 and WIN98
DO NOT USE UNDER WINDOWS NT
The method used here is not recommended by Microsoft, since it doesn't use VxD
driver, but it works !
Compile with DELPHI 3 or higher
*)

uses
  SysUtils,
  Classes,
  Windows;

{$I ERR_CODE_IOLIB.PAS}

Var
  DriverActif : Boolean;

Function OpenIOLibrary : Integer; StdCall; Export;

(* No VxD to open : Nothing to do in particular... *)

Begin
  OpenIOLibrary:=NoErr;
  DriverActif:=True;
End;  (* End of OpenIOLibrary function *)

(* ------------------------------------------------------------------------- *)

Function CloseIOLibrary : Integer; StdCall; Export;

(* No VxD to close : Nothing to do in particular... *)

Begin
  CloseIOLibrary:=NoErr;
  DriverActif:=False;
End;  (* End of CloseIOLibrary function *)

(* ------------------------------------------------------------------------- *)

Function GetIOPort (PortAd : Word) : Integer; StdCall; Export;

(* Read byte at PortAd I/O address *)

Begin
  Asm
    mov eax, 0
    mov dx, PortAd
    in al, dx
    mov result, eax
  End;
End;  (* End of GetIOPort function *)

(* ------------------------------------------------------------------------- *)

Procedure WriteIOPort (PortAd, PortDa : Word); StdCall; Export;

(* Write PortDa value (only the low byte) at PortAd I/O address *)

Begin
  Asm
    mov dx, PortAd
    mov ax, PortDa
    out dx, al
  End;
End;  (* End of WriteIOPort function *)

(* ------------------------------------------------------------------------- *)

Exports
  OpenIOLibrary Index 1,
  CloseIOLibrary Index 2,
  GetIOPort Index 3,
  WriteIOPort Index 4;

begin
  DriverActif:=False;
end.
