#include <stdio.h><br />#include "ppt.h"<br /><br />int validPpt; <br />#ifdef __linux__<br />int io_access_on( unsigned long port )<br />{<br /> if (ioperm (port, 3, 1)) {<br /> perror ("ioperm()");<br /> return 0;<br /> }<br /> if (ioperm (0x80, 1, 1)) {<br /> perror ("ioperm()");<br /> return 0;<br /> }<br /> return 1;<br />}<br /><br />void io_access_off( unsigned long port )<br />{<br /> ioperm (port, 3, 0);<br /> ioperm (0x80, 1, 0);<br />}<br />#else<br />#define io_access_on(x) (1)<br />#define io_access_off(x)<br />#endif<br />int GetValidPpt(void)<br />{<br /> // search for valid parallel port<br /> if( io_access_on(LPT1) ){<br /> _outp(LPT1, 0x55);<br /> if((int)_inp(LPT1) == 0x55) return LPT1;<br /> io_access_off(LPT1);<br /> }<br /><br /> if( io_access_on(LPT2) ){ <br /> _outp(LPT2, 0x55);<br /> if((int)_inp(LPT2) == 0x55) return LPT2;<br /> io_access_off(LPT2);<br /> }<br /><br /> if( io_access_on(LPT3) ){<br /> _outp(LPT3, 0x55);<br /> if((int)_inp(LPT3) == 0x55) return LPT3;<br /> io_access_off(LPT3);<br /> }<br /> <br /> return 0; <br />}<br /><br />#define ECP_ECR (0x402)<br />#define ECR_STANDARD (0x0)<br />#define ECR_DISnERRORINT (0x10)<br />#define ECR_DISDMA (0x0)<br />#define ECR_DISSVCINT (0x4)<br /><br />void SetPptCompMode(void)<br />{<br /> //configure the parallel port at the compatibility mode.<br /> //_outp(validPpt+ECP_ECR,ECR_STANDARD | ECR_DISnERRORINT | ECR_DISDMA | ECR_DISSVCINT);<br />}<br />#ifndef __linux__<br />int InstallGiveIo(void)<br />{<br /> HANDLE h;<br /> OSVERSIONINFO osvi;<br /> <br /> osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);<br /> GetVersionEx(&osvi);<br /> <br /> if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)<br /> {<br /> //OS=NT/2000<br /> h = CreateFile("\.giveio", GENERIC_READ, 0, NULL,<br /> OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);<br /> CloseHandle(h);<br /> if(h == INVALID_HANDLE_VALUE)<br /> return 0;<br /> else<br /> return 0x2000;<br /> }<br /> else<br /> { //OS=WIN98<br /> return 0x0098;<br /> }<br />}<br />#endif<br /><br />
|