2
* this is a wrapper for the cor port i/o functions for WinNT/2000/XP.
3
* this is to be replaced by some functions that are platform/interface
4
* specific to access the data lines.
5
* for now, this is only for parport access, but in future there will be a way
6
* to plug this on the usb bus.
7
* if the interface changes, only this file has to be adopted for the target system
9
#if defined __WIN32__ && defined Z_WANT_LPT
14
int read_parport(int port);
15
void write_parport(int port, int value);
16
int open_port(int port);
18
static BOOL bPrivException = FALSE;
20
int read_parport(int port)
28
/* hmm, i should read some documentation about inline assembler */
29
post("lpt: cannot read from parport (recompile!)");
35
void write_parport(int port, int invalue)
37
/* _outp((unsigned short)port, value); */
38
BYTE value = (BYTE)invalue;
45
* hmm, i should read some documentation about inline assembler
46
* and probably about assembler in general...
48
post("lpt: cannot write to parport (recompile!)");
55
: "a"(port),"b"(value)
61
static LONG WINAPI HandlerExceptionFilter ( EXCEPTION_POINTERS *pExPtrs )
64
if (pExPtrs->ExceptionRecord->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION)
66
pExPtrs->ContextRecord->Eip ++; /* Skip the OUT or IN instruction that caused the exception */
67
bPrivException = TRUE;
68
return EXCEPTION_CONTINUE_EXECUTION;
71
return EXCEPTION_CONTINUE_SEARCH;
74
static BOOL StartUpIoPorts(UINT PortToAccess, BOOL bShowMessageBox, HWND hParentWnd)
78
hUserPort = CreateFile("\\\\.\\UserPort", GENERIC_READ, 0, NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
79
CloseHandle(hUserPort); /* Activate the driver */
80
Sleep(100); /* We must make a process switch */
82
SetUnhandledExceptionFilter(HandlerExceptionFilter);
84
bPrivException = FALSE;
85
read_parport(PortToAccess); /* Try to access the given port address */
92
MessageBox(hParentWnd,"Privileged instruction exception has occured!\r\n\r\n"
93
"To use this external under Windows NT, 2000 or XP\r\n"
94
"you need to install the driver 'UserPort.sys' and grant\r\n"
95
"access to the ports used by this program.\r\n\r\n"
96
"See the file README for further information!\r\n", NULL, MB_OK);
103
/* check if we are running NT/2k/XP */
104
static int IsWinNT(void)
106
OSVERSIONINFO OSVersionInfo;
107
OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
109
GetVersionEx(&OSVersionInfo);
111
return OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT;
115
int open_port(int port)
117
if(IsWinNT()) /* we are under NT and need kernel driver */
119
if(StartUpIoPorts(port, 1, 0))
123
else /* no need to use kernel driver */
128
#endif /* __WIN32__ & Z_WANT_LPT */