HOWTO: Implement I/O functions in various programming languages

    

Prev Up

Article ID: Q400003

The information in this article applies to:

  • Direct I/O, version 4.0, 4.1, 4.2, 4.3, 4.4

SUMMARY

Not all programming languages and compilers have a built-in function set for reading and writing I/O ports. In this article we will try to give some hints how the missing I/O support can be added.

MORE INFORMATION

Delphi

Below you will find the functions needed:

function PortInB(IOAddr : WORD) : BYTE;
begin
	asm
		mov dx,IOAddr
		in al,dx
		mov result,al
	end;
end;

function PortInW(IOAddr : WORD) : WORD;
begin
	asm
		mov dx,IOAddr
		in ax,dx
		mov result,ax
	end;
end;

procedure PortOutB(IOAddr : WORD; Data : BYTE);
begin
	asm
		mov dx,IOAddr
		mov al,Data
		out dx,al
	end;
end;          
procedure PortOutW(IOAddr : WORD; Data : WORD);
begin
	asm
		mov dx,IOAddr
		mov ax,Data
		out dx,ax
	end;
end;          

VisualBasic

Use the functions of the DLL provided here.
Insert the following function prototypes in your source code:

Private Declare Sub vbOut Lib "WIN95IO.DLL" (ByVal nPort As Integer, ByVal nData As Integer)
Private Declare Sub vbOutw Lib "WIN95IO.DLL" (ByVal nPort As Integer, ByVal nData As Integer)
Private Declare Function vbInp Lib "WIN95IO.DLL" (ByVal nPort As Integer) As Integer
Private Declare Function vbInpw Lib "WIN95IO.DLL" (ByVal nPort As Integer) As Integer          

GCC

Include the following macro definitions in your source code:

/* definition of the outpw and inpw functions as macros */
#define outpw(port,value) \
({ __asm__ __volatile__ ( "outw %w0,%w1" :: "a" (value), "d" (port) ); })

#define inpw(port) \
({ unsigned short _v; \
__asm__ __volatile__ ( "inw %w1,%0" : "=a" (_v) : "d" (port) ); \
_v; \
})      

Direct I/O® and Paule® are registrated trademarks of Ingenieurbuero Paule. All other products mentioned are registered trademarks or trademarks of their respective owners.
Questions or problems regarding this web site should be directed to Webmaster.
Copyright © 1998-2018 Ingenieurbuero Paule. All rights reserved. Impressum.
Last modified: 2018-04-24.
Printer friendly