00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "includes.h"
00010
00011 int validPpt;
00012
00013 int GetValidPpt(void)
00014 {
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 _outp(LPT1, 0x55);
00031 if((int)_inp(LPT1) == 0x55)
00032 return LPT1;
00033
00034 _outp(LPT2, 0x55);
00035 if((int)_inp(LPT2) == 0x55)
00036 return LPT2;
00037
00038 _outp(LPT3, 0x55);
00039 if((int)_inp(LPT3) == 0x55)
00040 return LPT3;
00041
00042 return 0;
00043 }
00044
00045 #define ECP_ECR (0x402)
00046 #define ECR_STANDARD (0x0)
00047 #define ECR_DISnERRORINT (0x10)
00048 #define ECR_DISDMA (0x0)
00049 #define ECR_DISSVCINT (0x4)
00050
00051 void SetPptCompMode(void)
00052 {
00053
00054 _outp(validPpt+ECP_ECR,(ECR_STANDARD | ECR_DISnERRORINT | ECR_DISDMA | ECR_DISSVCINT));
00055 }
00056
00057 int InstallGiveIo(void)
00058 {
00059 HANDLE h;
00060 OSVERSIONINFO osvi;
00061
00062 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
00063 GetVersionEx(&osvi);
00064
00065 if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
00066 {
00067
00068 h = CreateFile("\\\\.\\giveio", GENERIC_READ, 0, NULL,
00069 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
00070 CloseHandle(h);
00071 if(h == INVALID_HANDLE_VALUE)
00072 return 0;
00073 else
00074 return 0x2000;
00075 }
00076 else
00077 {
00078 return 0x0098;
00079 }
00080 }
00081
00082 void OpenLpt(void)
00083 {
00084 if(!InstallGiveIo())
00085 {
00086 printf("ERROR: Couldn't open giveio.sys\n");
00087 exit(0);
00088 }
00089
00090 validPpt = GetValidPpt();
00091 if(!validPpt)
00092 {
00093 printf("ERROR: Unable to find a parallel port\n");
00094 exit(0);
00095 }
00096 SetPptCompMode();
00097 }
00098
00099