Mirror

Read and write I/O ports (Views: 710)


Problem/Question/Abstract:

Read and write I/O ports

Answer:

In Borland Pascal and Delphi 1, there is a predefined pseudo variable Port.

In the 32bit versions of Delphi you need 2 lines of assembler code..


function InPort(PortAddr: word): byte;
{$IFDEF WIN32}
assembler; stdcall;
asm
  mov dx,PortAddr
  in al,dx
end;
{$ELSE}
begin
  Result := Port[PortAddr];
end;
{$ENDIF}

<< Back to main page