1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
unit IOPort;
interface
uses windows;
procedure outport(portid : integer; value : integer);
procedure outportb(portid : integer; value : BYTE);
function inportb(portid : integer) : byte;
function inport(portid : integer) : integer;
function StartUpIoPorts(PortToAccess : integer) : boolean;
implementation
var
bPrivException : boolean;
procedure outport(portid : integer; value : integer);
Begin
asm
mov edx,portid;
mov eax,value;
out dx,ax;
end;
end;
procedure outportb(portid : integer; value : BYTE);
Begin
asm
mov edx,portid
mov al,value
out dx,al
end;
end;
function inportb(portid : integer) : byte;
Var value : byte;
Begin
asm
mov edx,portid
in al,dx
mov value,al
end;
inportb := value;
end;
function inport(portid : integer) : integer;
Var value : integer;
Begin
value := 0;
asm
mov edx,portid
in ax,dx
mov value,eax
end;
inport := value;
end;
function StartUpIoPorts(PortToAccess : integer) : boolean;
Var hUserPort : THandle;
Begin
hUserPort := CreateFile('\\.\UserPort', GENERIC_READ, 0, nil,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
CloseHandle(hUserPort); // Activate the driver
Sleep(100); // We must make a process switch
try
inportb(PortToAccess); // Try to access the given port address
except
MessageBox(0,'fel','fel',MB_OK);
end;
end;
end.
|