1 | unit PortsIO;
|
---|
2 |
|
---|
3 | {$MODE Delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | {$INCLUDE Options.inc}
|
---|
8 |
|
---|
9 | function InPort(adr:word):byte;
|
---|
10 | procedure OutPort(adr:word;y:byte);
|
---|
11 | procedure Init;
|
---|
12 |
|
---|
13 | implementation
|
---|
14 |
|
---|
15 | uses
|
---|
16 | LCLIntf, SysUtils {$IFDEF WINDOWS},Windows{$ENDIF}
|
---|
17 | {$IFDEF USE_INPOUT32}
|
---|
18 | , InpOut32
|
---|
19 | {$ENDIF}
|
---|
20 | ;
|
---|
21 |
|
---|
22 | var
|
---|
23 | Initialized: Boolean;
|
---|
24 |
|
---|
25 | function InPort_direct(adr:word):byte; assembler;
|
---|
26 | asm
|
---|
27 | mov dx,adr
|
---|
28 | in al,dx
|
---|
29 | end;
|
---|
30 |
|
---|
31 | procedure OutPort_direct(adr:word;y:byte);
|
---|
32 | begin
|
---|
33 | asm
|
---|
34 | mov dx,adr
|
---|
35 | mov al,y
|
---|
36 | out dx,al
|
---|
37 | end;
|
---|
38 | end;
|
---|
39 |
|
---|
40 | function InPort(adr:word):byte;
|
---|
41 | begin
|
---|
42 | {$IFDEF WINDOWS}
|
---|
43 | {$IFDEF USE_INPOUT32}
|
---|
44 | if Win32Platform = VER_PLATFORM_WIN32_NT then
|
---|
45 | Result:=Inp32(adr) and $ff
|
---|
46 | else
|
---|
47 | Result:=InPort_direct(adr);
|
---|
48 | {$ENDIF}
|
---|
49 |
|
---|
50 | {$IFDEF USE_GIVEIO}
|
---|
51 | Result:=InPort_direct(adr);
|
---|
52 | {$ENDIF}
|
---|
53 | {$ENDIF}
|
---|
54 | end;
|
---|
55 |
|
---|
56 | procedure OutPort(adr:word;y:byte);
|
---|
57 | begin
|
---|
58 | {$IFDEF WINDOWS}
|
---|
59 | {$IFDEF USE_INPOUT32}
|
---|
60 | if Win32Platform = VER_PLATFORM_WIN32_NT then
|
---|
61 | Out32(adr,y)
|
---|
62 | else
|
---|
63 | OutPort_direct(adr,y);
|
---|
64 | {$ENDIF}
|
---|
65 |
|
---|
66 | {$IFDEF USE_GIVEIO}
|
---|
67 | OutPort_direct(adr,y);
|
---|
68 | {$ENDIF}
|
---|
69 | {$ENDIF}
|
---|
70 | end;
|
---|
71 |
|
---|
72 | {$IFDEF USE_GIVEIO}
|
---|
73 | function InitializeGiveIo:boolean;
|
---|
74 | var
|
---|
75 | hDriver:THandle;
|
---|
76 | begin
|
---|
77 | hDriver := CreateFile('\\.\giveio', GENERIC_READ, 0, nil, OPEN_EXISTING,
|
---|
78 | FILE_ATTRIBUTE_NORMAL, 0);
|
---|
79 | if hDriver = INVALID_HANDLE_VALUE then
|
---|
80 | Result:=false
|
---|
81 | else
|
---|
82 | begin
|
---|
83 | if hDriver <> 0 then
|
---|
84 | CloseHandle(hDriver);
|
---|
85 | Result:=true;
|
---|
86 | end;
|
---|
87 | end;
|
---|
88 | {$ENDIF}
|
---|
89 |
|
---|
90 | procedure Init;
|
---|
91 | begin
|
---|
92 | {$IFDEF WINDOWS}
|
---|
93 | if not Initialized then begin
|
---|
94 | if Win32Platform = VER_PLATFORM_WIN32_NT then
|
---|
95 | begin
|
---|
96 | {$IFDEF USE_GIVEIO}
|
---|
97 | if not InitializeGiveIo then
|
---|
98 | begin
|
---|
99 | MessageBox(0,
|
---|
100 | 'Can''t find giveio.sys driver.' + #13#10#13#10 +
|
---|
101 | 'The giveio.sys driver must be installed' + #13#10 +
|
---|
102 | 'before running ISP Programmer.' + #13#10#13#10 +
|
---|
103 | 'Uninstall and install ISP Programmer again.',
|
---|
104 | 'ISP Programmer', MB_OK or MB_ICONERROR);
|
---|
105 | ExitProcess(1);
|
---|
106 | end;
|
---|
107 | {$ENDIF}
|
---|
108 |
|
---|
109 | {$IFDEF USE_INPOUT32}
|
---|
110 | if not IsInpOutDriverOpen then
|
---|
111 | begin
|
---|
112 | MessageBox(0,
|
---|
113 | 'Can''t initialize InpOut32 driver.' + #13#10#13#10 +
|
---|
114 | 'The InpOut32 driver must be installed' + #13#10 +
|
---|
115 | 'before running ISP Programmer.' + #13#10#13#10 +
|
---|
116 | 'Run ISP Programmer with administrator rights' + #13#10 +
|
---|
117 | 'or uninstall and install ISP Programmer again.',
|
---|
118 | 'ISP Programmer', MB_OK or MB_ICONERROR);
|
---|
119 | ExitProcess(1);
|
---|
120 | end;
|
---|
121 | {$ENDIF}
|
---|
122 | end;
|
---|
123 | Initialized := True;
|
---|
124 | end;
|
---|
125 | {$ENDIF}
|
---|
126 | end;
|
---|
127 |
|
---|
128 | initialization
|
---|
129 |
|
---|
130 | Initialized := False;
|
---|
131 |
|
---|
132 | end.
|
---|
133 |
|
---|