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
73
74
75
76
77
78
79
80
81
|
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winioctl.h>
#include "porttalk_IOCTL.h"
// Globals
extern BOOL bWindowsNT;
HANDLE hFddDev=INVALID_HANDLE_VALUE;
void outportb(UINT portid, BYTE value)
{
__asm mov edx,portid
__asm mov al,value
__asm out dx,al
}
BOOL OpenFddDevice(void)
{
if (!bWindowsNT)
return TRUE;
if((hFddDev = CreateFile("\\\\.\\PortTalk", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE)
return FALSE;
return TRUE;
}
BOOL ToggleFddLight(BYTE drive, BYTE status)
{
DWORD BytesReturned;
unsigned char Buffer[3];
unsigned short *pBuffer;
BYTE value = status<<(drive|4)|drive|12;
if (!bWindowsNT) {
outportb(0x3F2, value);
return TRUE;
}
if (hFddDev == INVALID_HANDLE_VALUE)
return FALSE;
pBuffer = (unsigned short *)&Buffer[0];
*pBuffer = 0x3F2;
Buffer[2] = (unsigned char)value;
if (!DeviceIoControl(hFddDev, IOCTL_WRITE_PORT_UCHAR, &Buffer, 3, NULL, 0, &BytesReturned, NULL))
return FALSE;
return TRUE;
}
void CloseFddDevice(void)
{
if (!bWindowsNT)
return;
if (hFddDev != INVALID_HANDLE_VALUE)
CloseHandle(hFddDev);
}
|