|
Article ID: Q400003 The information in this article applies to:
SUMMARYNot 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 INFORMATIONDelphiBelow 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; VisualBasicUse the functions of the DLL provided here. 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 GCCInclude 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; \ }) |
|