unit WDMIO; interface function _InPortB(hDevice, Address: LongWord): Word; function _InPort(hDevice, Address: LongWord): Word; function _InPortL(hDevice, Address: LongWord): LongWord; function _OutPortB(hDevice, Address: LongWord; Value: Byte): Word; function _OutPort(hDevice, Address: LongWord; Value: Word): Word; function _OutPortL(hDevice, Address: LongWord; Value: LongWord): Word; function _InMemB(hDevice, Address: LongWord): Word; function _InMem(hDevice, Address: LongWord): Word; function _InMemL(hDevice, Address: LongWord): LongWord; function _OutMemB(hDevice, Address: LongWord; Value: Byte): Word; function _OutMem(hDevice, Address: LongWord; Value: Word): Word; function _OutMemL(hDevice, Address: LongWord; Value: LongWord): Word; implementation uses Windows; const METHOD_BUFFERED = 0; FILE_READ_ACCESS = 1; FILE_WRITE_ACCESS = 2; FILE_DEVICE_KRNLDRVR = $80FF; IOCTL_PORT_IN = LongWord((FILE_DEVICE_KRNLDRVR shl 16) or ($820 shl 2) or (METHOD_BUFFERED) or (FILE_READ_ACCESS shl 14)); IOCTL_PORT_OUT = LongWord((FILE_DEVICE_KRNLDRVR shl 16) or ($822 shl 2) or (METHOD_BUFFERED) or (FILE_WRITE_ACCESS shl 14)); IOCTL_MEM_IN = LongWord((FILE_DEVICE_KRNLDRVR shl 16) or ($824 shl 2) or (METHOD_BUFFERED) or (FILE_READ_ACCESS shl 14)); IOCTL_MEM_OUT = LongWord((FILE_DEVICE_KRNLDRVR shl 16) or ($826 shl 2) or (METHOD_BUFFERED) or (FILE_WRITE_ACCESS shl 14)); pofRelative = $01; type TPortOp = record Addr: Word; Flags: Byte; Size: Byte; Data: LongWord; end; TMemOp = record Addr: LongWord; Padding0: Word; Flags: Byte; Size: Byte; Data: LongWord; end; function _InPortB(hDevice, Address: LongWord): Word; var DataBuffer: TPortOp; cbRet: LongWord; begin with DataBuffer do begin Addr := Address; Flags := pofRelative; Size := 1; end; if DeviceIoControl(hDevice, IOCTL_PORT_IN, @DataBuffer, sizeof(DataBuffer), @DataBuffer, sizeof(DataBuffer), cbRet, nil) then Result := DataBuffer.Data and $FF else Result := $AA55 ; end; function _InPort(hDevice, Address: LongWord): Word; var DataBuffer: TPortOp; cbRet: LongWord; begin with DataBuffer do begin Addr := Address; Flags := pofRelative; Size := 2; end; if DeviceIoControl(hDevice, IOCTL_PORT_IN, @DataBuffer, sizeof(DataBuffer), @DataBuffer, sizeof(DataBuffer), cbRet, nil) then Result := DataBuffer.Data and $FFFF else Result := $AA55 ; end; function _InPortL(hDevice, Address: LongWord): LongWord; var DataBuffer: TPortOp; cbRet: LongWord; begin with DataBuffer do begin Addr := Address; Flags := pofRelative; Size := 4; end; if DeviceIoControl(hDevice, IOCTL_PORT_IN, @DataBuffer, sizeof(DataBuffer), @DataBuffer, sizeof(DataBuffer), cbRet, nil) then Result := DataBuffer.Data else Result := $AA55 ; end; function _OutPortB(hDevice, Address: LongWord; Value: BYTE): Word; var DataBuffer: TPortOp; cbRet: LongWord; begin with DataBuffer do begin Addr := Address; Flags := pofRelative; Size := 1; Data := Value; end; if DeviceIoControl(hDevice, IOCTL_PORT_OUT, @DataBuffer, sizeof(DataBuffer), @DataBuffer, sizeof(DataBuffer), cbRet, nil) then Result := 0 else Result := $AA55 ; end; function _OutPort(hDevice, Address: LongWord; Value: Word): Word; var DataBuffer: TPortOp; cbRet: LongWord; begin with DataBuffer do begin Addr := Address; Flags := pofRelative; Size := 2; Data := Value; end; if DeviceIoControl(hDevice, IOCTL_PORT_OUT, @DataBuffer, sizeof(DataBuffer), @DataBuffer, sizeof(DataBuffer), cbRet, nil) then Result := 0 else Result := $AA55 ; end; function _OutPortL(hDevice, Address: LongWord; Value: LongWord): Word; var DataBuffer: TPortOp; cbRet: LongWord; begin with DataBuffer do begin Addr := Address; Flags := pofRelative; Size := 4; Data := Value; end; if DeviceIoControl(hDevice, IOCTL_PORT_OUT, @DataBuffer, sizeof(DataBuffer), @DataBuffer, sizeof(DataBuffer), cbRet, nil) then Result := 0 else Result := $AA55 ; end; function _InMemB(hDevice, Address: LongWord): Word; var DataBuffer: TMemOp; cbRet: LongWord; begin with DataBuffer do begin Addr := Address; Flags := 0; Size := 1; end; if DeviceIoControl(hDevice, IOCTL_MEM_IN, @DataBuffer, sizeof(DataBuffer), @DataBuffer, sizeof(DataBuffer), cbRet, nil) then Result := DataBuffer.Data and $FF else Result := $AA55 ; end; function _InMem(hDevice, Address: LongWord): Word; var DataBuffer: TMemOp; cbRet: LongWord; begin with DataBuffer do begin Addr := Address; Flags := 0; Size := 2; end; if DeviceIoControl(hDevice, IOCTL_MEM_IN, @DataBuffer, sizeof(DataBuffer), @DataBuffer, sizeof(DataBuffer), cbRet, nil) then Result := DataBuffer.Data and $FFFF else Result := $AA55 ; end; function _InMemL(hDevice, Address: LongWord): LongWord; var DataBuffer: TMemOp; cbRet: LongWord; begin with DataBuffer do begin Addr := Address; Flags := 0; Size := 4; end; if DeviceIoControl(hDevice, IOCTL_MEM_IN, @DataBuffer, sizeof(DataBuffer), @DataBuffer, sizeof(DataBuffer), cbRet, nil) then Result := DataBuffer.Data else Result := $AA55 ; end; function _OutMemB(hDevice, Address: LongWord; Value: BYTE): Word; var DataBuffer: TMemOp; cbRet: LongWord; begin with DataBuffer do begin Addr := Address; Flags := 0; Size := 1; Data := Value; end; if DeviceIoControl(hDevice, IOCTL_MEM_OUT, @DataBuffer, sizeof(DataBuffer), @DataBuffer, sizeof(DataBuffer), cbRet, nil) then Result := 0 else Result := $AA55 ; end; function _OutMem(hDevice, Address: LongWord; Value: Word): Word; var DataBuffer: TMemOp; cbRet: LongWord; begin with DataBuffer do begin Addr := Address; Flags := 0; Size := 2; Data := Value; end; if DeviceIoControl(hDevice, IOCTL_MEM_OUT, @DataBuffer, sizeof(DataBuffer), @DataBuffer, sizeof(DataBuffer), cbRet, nil) then Result := 0 else Result := $AA55 ; end; function _OutMemL(hDevice, Address: LongWord; Value: LongWord): Word; var DataBuffer: TMemOp; cbRet: LongWord; begin with DataBuffer do begin Addr := Address; Flags := 0; Size := 4; Data := Value; end; if DeviceIoControl(hDevice, IOCTL_MEM_OUT, @DataBuffer, sizeof(DataBuffer), @DataBuffer, sizeof(DataBuffer), cbRet, nil) then Result := 0 else Result := $AA55 ; end; end.