📄 sacwd32.c
字号:
hThread=GetCurrentThread();
if(!hPassThruSem)
{
if(!(hPassThruSem = OpenSemaphore(SYNCHRONIZE|SEMAPHORE_MODIFY_STATE,
FALSE,
SAUTH95_PASSTHRU_SEM)))
{
hPassThruSem = CreateSemaphore(NULL,1,1,SAUTH95_PASSTHRU_SEM);
}
}
return TRUE;
}
else if(WinNT)
{
if(!CheckDriver())
return ((uchar)LoadDriver());
else
return TRUE;
}
else
return FALSE;
}
////////////////////////////////////////////////////////////////////////////////
uchar nowaitkeyopen(void)// Added for Win16 compatibility.
{ // This function should never be called
return TRUE;
}
////////////////////////////////////////////////////////////////////////////////
uchar APIENTRY keyopen(void) // Must be used in Win32 Apps!!!!!
{
PSECURITY_DESCRIPTOR pSD;//(3.11Beta2)
SECURITY_ATTRIBUTES sa;//(3.11Beta2)
DWORD WaitResult=0;
if(Win32s)
{
return (uchar)((*pfnUTProc)(NULL, MYKEYOPEN, NULL));
}
else if(Win95)
{
if(!AuthFlag)
{
AuthFlag = ((hDriver==INVALID_HANDLE_VALUE)?FALSE:TRUE);
if(AuthFlag) // have valid driver handle
{
if(!SemCreated)
{
hSemaphore = CreateSemaphore(NULL,1,1,SAUTH95_SEM);
SemCreated = TRUE;
}
if(!hSemaphore) // no semaphore handle yet
{
hSemaphore = OpenSemaphore(SYNCHRONIZE|SEMAPHORE_MODIFY_STATE,
FALSE,
SAUTH95_SEM);
}
if(hSemaphore)
{
// try to spread access to all applications evenly
SetThreadPriority(hThread,THREAD_PRIORITY_ABOVE_NORMAL);// 1 point higher
WaitResult=WaitForSingleObject(hSemaphore,SEM_TIMEOUT);
if(WaitResult==WAIT_FAILED)
{
SetThreadPriority(hThread,THREAD_PRIORITY_NORMAL);
ReleaseSemaphore(hSemaphore,1,NULL);
AuthFlag = FALSE;
Sleep(0);
return FALSE;
}
// Added for Win16 compatibility
hSA16CompatSem=CreateSemaphore(NULL,1,1,SA16COMPAT_SEM);
}
else
return FALSE;
}// if(AuthFlag)
}// if(!AuthFlag)
if(AuthFlag)
{
ExitPassthru();
if(CheckOverdrive())
OverdriveOff(); // call overdrive off if mixed stacking is not enabled
}
return AuthFlag;
}
else if(WinNT)
{
if (!AuthFlag)
{
// If it existed we still don't have a handle
if (sHandle == NULL || !SemCreated)
{
sHandle = OpenSemaphore(SYNCHRONIZE | SEMAPHORE_MODIFY_STATE,
FALSE,
"DS1410XAccessSem");
// Make sure we got a handle.
if (sHandle != NULL)
SemCreated = TRUE;
}
// Create semaphore if it doesn't exist
if (!SemCreated)
{
// Begin 3.11Beta1 Changes
pSD = (PSECURITY_DESCRIPTOR) LocalAlloc( LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
if (pSD == NULL)
{
return FALSE;
}
if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION))
{
return FALSE;
}
// Add a NULL DACL to the security descriptor to share objects with service (3.11Beta)
if (!SetSecurityDescriptorDacl(pSD, TRUE, (PACL) NULL, FALSE))
{
return FALSE;
}
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = TRUE;
sHandle = CreateSemaphore(&sa, 1, 1, "DS1410XAccessSem");
if (sHandle != NULL)
SemCreated = TRUE;
/* begin old sect (3.11alpha and prior)
sHandle = CreateSemaphore(NULL, 1, 1, "DS1410XAccessSem");
if (sHandle != NULL)
SemCreated = TRUE;
*/
}
if (SemCreated == TRUE)
{
// Wait until semaphore value = 0, or 5 second timeout
WaitForSingleObject(sHandle, 5000);
// Once we've got the semaphore we should be able to get the handle
// (unless semaphore wait timed out, then we fail CreateFile)
// Try to get handle to our driver
AuthFlag = !((DOWHandle = CreateFile("LPT9",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL)) == INVALID_HANDLE_VALUE);
if(AuthFlag)
{
// Set port number in the driver
SetPortNumber();
// Enter EPP passthru mode
ExitPassthru();
if (CheckOverdrive())
OverdriveOff();
}
else
{
ReleaseSemaphore(sHandle, 1, NULL);
return FALSE;
}
}
else
return AuthFlag;
}
return AuthFlag;
}
return FALSE;
}
////////////////////////////////////////////////////////////////////////////////
uchar APIENTRY keyclose(void) // Must be Used in All Apps!!!!!
{
if(Win32s)
{
(*pfnUTProc)(NULL, MYKEYCLOSE, NULL);
return TRUE;
}
else if(Win95)
{
if(AuthFlag)
{
EnterPassthru();
// Added for Win16 compatibility
if(hSA16CompatSem)
{
CloseHandle(hSA16CompatSem);// release semaphore handle to system
}
ReleaseSemaphore(hSemaphore,1,NULL);
AuthFlag = FALSE;
// allow fair access to other applications
SetThreadPriority(hThread,THREAD_PRIORITY_BELOW_NORMAL);// 1 point lower
Sleep(0); //release time slice
SetThreadPriority(hThread,THREAD_PRIORITY_NORMAL);
return TRUE;
}
}
else if(WinNT)
{
// If we had control, release control
if (AuthFlag)
{
// Enter EPP passthru mode
EnterPassthru();
// Close handle to DS1410E.SYS
CloseHandle(DOWHandle);
// Set semaphore value back to 0
ReleaseSemaphore(sHandle, 1, NULL);
AuthFlag = FALSE;
}
return TRUE;
}
return FALSE; // (OWPD) get all control paths
}
////////////////////////////////////////////////////////////////////////////////
uchar APIENTRY first(sa_struct *gb)
{
DWORD Args[1];
if(Win95 || WinNT)
{
// Don't force a failure here
gb->lastone = FALSE;
// Point Rom Search algorithm to the top
gb->ld = 0;
// Go look for the first DOW part on the bus
return next(gb);
}
else
{
Args[0] = (DWORD) gb; //only passing one argument, windows handles translation
return (uchar)((* pfnUTProc)(gb, MYFIRST, NULL));
}
}
////////////////////////////////////////////////////////////////////////////////
uchar APIENTRY next(sa_struct *gb)
{
uchar tr;
DWORD Args[1];
if(Win32s)
{
Args[0] = (DWORD) gb;//only passing one argument, windows handles translation
return(uchar)( (*pfnUTProc)(gb, MYNEXT, NULL));
}
else if(Win95)
{
if (gb->setup_ok)
{
// See if last search found last button
if (gb->lastone)
{
gb->lastone = FALSE;
// Reset next function
gb->ld = 0;
}
else
while ((tr = RomSearch(gb)) != 0) // Do that ROM search thang
{
// See if we should force failure
if (tr == 2)
gb->lastone = 1;
// Detect short circuit
if (!RomDta[0])
return FALSE;
return TRUE;
}//else
}//if (gb->setup_ok)
return FALSE;
}
else if(WinNT)
{
if (gb->setup_ok)
{
// See if last search found last button
if (gb->lastone)
{
gb->lastone = FALSE;
// Reset next function
gb->ld = 0;
}
else while ((tr = RomSearch(gb)) != 0)
{
// See if we should force failure
if (tr == 2)
gb->lastone = 1;
// Detect short circuit
if (!RomDta[0])
return FALSE;
gb->accflg = TRUE;
return TRUE;
}
}
return FALSE;
}
return FALSE; // (OWPD) get all control paths
}
////////////////////////////////////////////////////////////////////////////////
uchar APIENTRY access(sa_struct *gb)
{
uchar i, j;
DWORD Args[1];
// update 'local' rom number from state buffer
memcpy(&(RomDta[0]), &(gb->romdta[0]), 8);
if(Win32s)
{
Args[0] = (DWORD) gb;//only passing one argument, windows handles translation
return (uchar)( (*pfnUTProc)(gb, MYACCESS, NULL));
}
else if(Win95)
{
// Assume failure
gb->accflg = FALSE;
// Send reset pulse
if (DOWReset())
{
// ROM search command byte
DOWByte(ROMSEARCH);
// Byte loop
for (i = 0; i < 8; i++)
{
// Bit loop
for (j = 0; j < 8; j++)
{
if (((DOWBit(TRUE) << 1) | DOWBit(TRUE)) == 3)
return FALSE; // Part not there
// Send write time slot
DOWBit((uchar) ((RomDta[i] >> j) & 1));
}
}
// Success if we made it through all the bits
gb->accflg = TRUE;
}
return gb->accflg;
}
else if (WinNT)
{
// Assume failure
gb->accflg = FALSE;
// Send reset pulse
if (DOWReset())
{
// ROM search command byte
DOWByte(0xF0);
// Byte loop
for (i = 0; i < 8; i++)
{
// Bit loop
for (j = 0; j < 8; j++)
{
if (((DOWBit(TRUE) << 1) | DOWBit(TRUE)) == 3)
return FALSE;
// Send write time slot
DOWBit((UCHAR) ((RomDta[i] >> j) & 1));
}
}
// Success if we made it through all the bits
gb->accflg = TRUE;
}
return gb->accflg;
}
return FALSE; // (OWPD) get all control paths
}
////////////////////////////////////////////////////////////////////////////////
uchar APIENTRY gndtest(sa_struct *gb)
{
DWORD Args[1];
if(Win32s)
{
Args[0] = (DWORD) gb; //passing one argument, no translation needed
return (uchar)( (*pfnUTProc)(gb, MYGNDTEST, NULL));
}
else if(Win95)
{
if (gb->setup_ok)
{
DOWReset();
return DOWBit(TRUE);
}
return FALSE;
}
else if(WinNT)
return (uchar)(gb->setup_ok);
return FALSE; // (OWPD) get all control paths
}
////////////////////////////////////////////////////////////////////////////////
uchar * APIENTRY romdata(sa_struct *gb)
{
uchar far *romptr;
DWORD Args[1];
if(Win32s)
{
Args[0] = (DWORD) gb;//passing one argument, no translation needed
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -