165 #define U14LIB_MAJOR 4
166 #define U14LIB_MINOR 0
167 #define U14LIB_REVISION 0
168 #define U14LIB_VERSION ((U14LIB_MAJOR<<24) | (U14LIB_MINOR<<16) | U14LIB_REVISION)
179 #pragma warning(disable: 4100)
184 #define sprintf wsprintf
186 #define PATHSEPSTR "\\"
187 #define DEFCMDPATH "\\1401\\" // default command path if all else fails
188 #define MINDRIVERMAJREV 1 // minimum driver revision level we need
189 #define __packed // does nothing in Windows
197 #include <sys/ioctl.h>
199 #include <sys/time.h>
203 #define PATHSEPSTR "/"
204 #define DEFCMDPATH "/var/1401/" // default command path if all else fails
205 #define MINDRIVERMAJREV 2 // minimum driver revision level we need
210 #define MAX1401 8 // The number of 1401s that can be supported
217 #define DRIVRET_STD 4 // Codes for 1401 types matching driver values
218 #define DRIVRET_U1401 5 // This table does not need extending, as
219 #define DRIVRET_PLUS 6 // we can calculate values now.
220 #define DRIVRET_POWER 7 // but we need all of these values still
221 #define DRIVRET_MAX 26 // Maximum tolerated code - future designs
227 static char szLastName[20];
236 static short asDriverType[
MAX1401] = {0};
239 static int alDriverVersion[
MAX1401];
240 static int alTimeOutPeriod[
MAX1401];
241 static short asLastRetCode[
MAX1401];
242 static short asType1401[
MAX1401] = {0};
244 static int iAttached = 0;
250 static HANDLE aHand1401[
MAX1401] = {0};
251 static HANDLE aXferEvent[
MAX1401] = {0};
256 #define USE_NT_DIOC(ind) TRUE
259 #define USE_NT_DIOC(ind) abUseNTDIOC[ind]
265 static int aHand1401[
MAX1401] = {0};
266 #define INVALID_HANDLE_VALUE 0 // to avoid code differences
275 #pragma pack(1) // pack our structure
282 #pragma pack() // back to normal
294 #define MAXSTRLEN 255 // maximum string length we use
298 static short CheckHandle(
short h)
302 if (aHand1401[h] <= 0)
312 static short U14Status1401(
short sHand,
LONG lCode,
TCSBLOCK* pBlk)
316 if ((sHand < 0) || (sHand >=
MAX1401))
319 if (!USE_NT_DIOC(sHand))
321 if (DeviceIoControl(aHand1401[sHand], lCode,
NULL, 0, pBlk,
sizeof(
TCSBLOCK),&dwBytes,
NULL))
324 return (
short)GetLastError();
331 if (DeviceIoControl(aHand1401[sHand], lCode,
NULL, 0, &rWork,
sizeof(
PARAMBLK),&dwBytes,
NULL) &&
346 static short U14Control1401(
short sHand,
LONG lCode,
TCSBLOCK* pBlk)
350 if ((sHand < 0) || (sHand >=
MAX1401))
354 if (!USE_NT_DIOC(sHand))
356 if (DeviceIoControl(aHand1401[sHand], lCode,
NULL, 0, pBlk,
sizeof(
TCSBLOCK), &dwBytes,
NULL))
359 return (
short)GetLastError();
366 if (DeviceIoControl(aHand1401[sHand], lCode, pBlk,
sizeof(
TCSBLOCK), &rWork,
sizeof(
PARAMBLK), &dwBytes,
NULL) &&
379 static long SafeTickCount()
382 return GetTickCount();
387 return (tv.tv_sec*1000 + tv.tv_usec/1000);
395 static int ExtForType(
short sType,
char* szExt)
406 szExt[3] = (
char)(szExt[3] - 26);
418 int iNow = SafeTickCount();
419 if ((hand >= 0) && (hand <
MAX1401))
420 iNow += alTimeOutPeriod[hand];
428 U14API(
short) U14PassedTime(
int lCheckTime)
430 return (
short)((SafeTickCount()-lCheckTime) > 0);
438 static void TranslateString(
char*
pStr)
448 if ((i > 0) && (pStr[i-1] ==
'\n'))
461 while (pszBuff[wChInd] &&
462 (sLgInd < sMaxLongs))
465 switch (pszBuff[wChInd])
468 case '0':
case '1':
case '2':
case '3':
case '4':
469 case '5':
case '6':
case '7':
case '8':
case '9':
475 while ((!bDone) && pszBuff[wChInd])
477 switch (pszBuff[wChInd])
483 case '0':
case '1':
case '2':
case '3':
case '4':
484 case '5':
case '6':
case '7':
case '8':
case '9':
486 lValue += ((
int)pszBuff[wChInd]-(
int)
'0');
495 palNums[sLgInd] = lValue * iSign;
517 short sResult = U14GetString(hand, szWork,
MAXSTRLEN);
519 sResult = U14StrToLongs(szWork, palBuff, sMaxLongs);
528 U14API(
short) U14CheckErr(
short hand)
530 short sResult = U14SendString(hand,
";ERR;");
534 sResult = U14LongsFrom1401(hand, er, 3);
537 sResult = (
short)er[0];
542 sprintf(szMsg,
"U14CheckErr returned %d,%d\n", er[0], er[1]);
543 OutputDebugString(szMsg);
562 U14API(
short) U14LastErrCode(
short hand)
564 if ((hand < 0) || (hand >=
MAX1401))
566 return asLastRetCode[hand];
573 U14API(
void) U14SetTimeout(
short hand,
int lTimeOut)
575 if ((hand < 0) || (hand >=
MAX1401))
577 alTimeOutPeriod[hand] = lTimeOut;
586 if ((hand < 0) || (hand >=
MAX1401))
588 return alTimeOutPeriod[hand];
595 U14API(
short) U14OutBufSpace(
short hand)
601 sErr = csBlock.
ints[0];
605 short sErr = CheckHandle(hand);
615 U14API(
int) U14BaseAddr1401(
short hand)
621 iError = csBlock.
longs[0];
625 short sErr = CheckHandle(hand);
634 U14API(
short) U14StateOf1401(
short hand)
641 sErr = csBlock.
ints[0];
647 short sErr = CheckHandle(hand);
664 U14API(
int) U14DriverVersion(
short hand)
666 return CheckHandle(hand) !=
U14ERR_NOERROR ? lLastDriverVersion : alDriverVersion[hand];
675 U14API(
int) U14DriverType(
short hand)
677 return CheckHandle(hand) !=
U14ERR_NOERROR ? lLastDriverType : asDriverType[hand];
688 switch (U14DriverType(hand))
690 case 0: pName =
"ISA";
break;
691 case 1: pName =
"PCI";
break;
692 case 2: pName =
"USB";
break;
693 case 3: pName =
"HSS";
break;
694 default: pName =
"???";
break;
705 U14API(
short) U14BlkTransState(
short hand)
711 sErr = csBlock.
ints[0];
715 short sErr = CheckHandle(hand);
724 U14API(
short) U14Grab1401(
short hand)
726 short sErr = CheckHandle(hand);
743 abGrabbed[hand] =
TRUE;
751 U14API(
short) U14Free1401(
short hand)
753 short sErr = CheckHandle(hand);
770 abGrabbed[hand] =
FALSE;
784 short sErr = CheckHandle(hand);
794 sErr = U14Control1401(hand,
U14_DBGPEEK, &csBlock);
817 int nSize,
int nRepeats)
819 short sErr = CheckHandle(hand);
830 sErr = U14Control1401(hand,
U14_DBGPOKE, &csBlock);
853 int nSize,
int nRepeats)
855 short sErr = CheckHandle(hand);
891 int nSize,
int nRepeats)
893 short sErr = CheckHandle(hand);
926 U14API(
short) U14StopDebugLoop(
short hand)
928 short sErr = CheckHandle(hand);
953 short sErr = CheckHandle(hand);
962 *plValue = csBlock.
longs[0];
968 *plValue = dbb.
iData;
980 U14API(
short) U14StartSelfTest(
short hand)
987 short sErr = CheckHandle(hand);
1002 pData[0] = csBlock.
longs[0];
1003 pData[1] = csBlock.
longs[1];
1004 pData[2] = csBlock.
longs[2];
1008 short sErr = CheckHandle(hand);
1015 pData[0] = gst.
code;
1030 short sErr = U14SendString(hand, (asType1401[hand] ==
U14TYPE1401) ?
"MEMTOP;" :
"MEMTOP,?;");
1035 sErr = U14LongsFrom1401(hand, alLimits, 4);
1040 *pMemorySize = alLimits[0] - alLimits[1];
1042 *pMemorySize = alLimits[0];
1052 U14API(
short) U14TypeOf1401(
short hand)
1054 if ((hand < 0) || (hand >=
MAX1401))
1057 return asType1401[hand];
1064 U14API(
short) U14NameOf1401(
short hand,
char* pBuf,
WORD wMax)
1066 short sErr = CheckHandle(hand);
1070 switch (asType1401[hand])
1080 default: pName =
"Unknown";
1092 U14API(
short) U14TransferFlags(
short hand)
1100 short sErr = CheckHandle(hand);
1111 static int GetDriverVersion(
short hand)
1117 iErr = csBlock.
longs[0];
1131 U14API(
int) U14MonitorRev(
short hand)
1134 int iErr = CheckHandle(hand);
1140 iErr = U14SendString(hand,
"INFO,S,28;");
1144 iErr = U14LongsFrom1401(hand, lVals, 1);
1149 iRev += asType1401[hand] * 10000;
1155 iErr = U14SendString(hand,
";CLIST;");
1161 iErr = U14GetString(hand, wstr, 45);
1164 char *pstr =
strstr(wstr,
"RESET");
1165 if ((pstr == wstr) && (wstr[5] ==
' '))
1171 while (((pstr[l-1] ==
' ') || (pstr[l-1] == 13)) && (l > 0))
1176 pstr2 =
strchr(pstr,
'.');
1183 iRev += (atoi(pstr) * 1000);
1185 if ((
strlen(wstr) < 3) && (wstr[0] ==
' '))
1204 #define U14NAMEOLD "\\\\.\\CED_140%d"
1205 #define U14NAMENEW "\\\\.\\CED%d"
1206 static short U14TryToOpen(
int n1401,
long* plRetVal,
short* psHandle)
1209 HANDLE hDevice = INVALID_HANDLE_VALUE;
1211 int nFirst, nLast, nDev = 0;
1220 nFirst = nLast = n1401;
1222 while (hDevice == INVALID_HANDLE_VALUE)
1224 for (nDev = nFirst; nDev <= nLast; nDev++)
1227 sprintf(szDevName, bOldName ? U14NAMEOLD : U14NAMENEW, nDev);
1232 if (hDevice != INVALID_HANDLE_VALUE)
1235 assert(aHand1401[nDev-1] == INVALID_HANDLE_VALUE);
1236 aHand1401[nDev-1] = hDevice;
1240 abUseNTDIOC[nDev-1] = (
BOOL)(!bWindows9x || !bOldName);
1245 *plRetVal = csBlock.
ints[0];
1248 CloseHandle(hDevice);
1249 hDevice = INVALID_HANDLE_VALUE;
1250 aHand1401[nDev-1] = INVALID_HANDLE_VALUE;
1258 CloseHandle(hDevice);
1259 hDevice = INVALID_HANDLE_VALUE;
1260 aHand1401[nDev-1] = INVALID_HANDLE_VALUE;
1265 DWORD dwe = GetLastError();
1266 if ((dwe != ERROR_FILE_NOT_FOUND) || (dwErr == 0))
1271 if ((hDevice == INVALID_HANDLE_VALUE) &&
1273 (bOldName ==
FALSE))
1279 if (hDevice != INVALID_HANDLE_VALUE)
1280 *psHandle = (
short)(nDev-1);
1283 if (dwErr == ERROR_FILE_NOT_FOUND)
1285 else if (dwErr == ERROR_NOT_SUPPORTED)
1287 else if (dwErr == ERROR_ACCESS_DENIED)
1296 static short U14TryToOpen(
int n1401,
long* plRetVal,
short* psHandle)
1301 int nFirst, nLast, nDev = 0;
1309 nFirst = nLast = n1401;
1311 for (nDev = nFirst; nDev <= nLast; nDev++)
1314 sprintf(szDevName,
"/dev/cedusb/%d", nDev-1);
1319 aHand1401[nDev-1] = fh;
1322 *plRetVal = iType1401;
1329 aHand1401[nDev-1] = 0;
1334 if (((errno !=
ENODEV) && (errno !=
ENOENT)) || (iErr == 0))
1341 *psHandle = (
short)(nDev-1);
1346 else if (iErr ==
EBUSY)
1359 U14API(
short) U14Open1401(
short n1401)
1365 if ((n1401 < 0) || (n1401 >
MAX1401))
1370 sErr = U14TryToOpen(n1401, &lRetVal, &hand);
1373 long lDriverVersion = GetDriverVersion(hand);
1374 long lDriverRev = -1;
1375 if (lDriverVersion >= 0)
1377 lLastDriverType = (lDriverVersion >> 24) & 0x000000FF;
1378 asDriverType[hand] = (
short)lLastDriverType;
1379 lLastDriverVersion = lDriverVersion & 0x00FFFFFF;
1380 alDriverVersion[hand] = lLastDriverVersion;
1381 lDriverRev = ((lDriverVersion>>16) & 0x00FF);
1386 return (
short)lDriverVersion;
1389 if (lDriverRev < MINDRIVERMAJREV)
1396 abGrabbed[hand] =
FALSE;
1397 U14SetTimeout(hand, 3000);
1411 U14KillIO1401(hand);
1415 sErr = U14CheckErr(hand);
1420 sErr = U14StateOf1401(hand);
1435 U14API(
short) U14Close1401(
short hand)
1439 short sErr = CheckHandle(hand);
1446 int iReturn = U14GetTransfer(hand, >b);
1449 iAreaMask |= (1 <<
j);
1456 if (iAreaMask & (1 << j))
1457 U14UnSetTransfer(hand, (
WORD)j);
1461 if (aXferEvent[hand])
1463 CloseHandle(aXferEvent[hand]);
1464 aXferEvent[hand] =
NULL;
1467 if (CloseHandle(aHand1401[hand]))
1470 if (close(aHand1401[hand]) == 0)
1473 aHand1401[hand] = INVALID_HANDLE_VALUE;
1489 if (aHand1401[i] != INVALID_HANDLE_VALUE)
1490 U14Close1401((
short)i);
1497 U14API(
short) U14Reset1401(
short hand)
1504 short sErr = CheckHandle(hand);
1514 U14API(
short) U14ForceReset(
short hand)
1521 short sErr = CheckHandle(hand);
1530 U14API(
short) U14KillIO1401(
short hand)
1537 short sErr = CheckHandle(hand);
1552 short sErr = CheckHandle(hand);
1562 lTimeOutTicks = U14WhenToTimeOut(hand);
1565 bSpaceToSend = (
BOOL)((
long)U14OutBufSpace(hand) >= nChars);
1567 while (!bSpaceToSend && !U14PassedTime(lTimeOutTicks));
1572 for (i = 0; (i < 4) && (!bSpaceToSend); ++
i)
1575 bSpaceToSend = (
BOOL)((
long)U14OutBufSpace(hand) >= nChars);
1587 if ((hand < 0) || (hand >=
MAX1401))
1593 if (!USE_NT_DIOC(hand))
1596 NULL, 0, tstr, nChars,
1601 sErr = (
short)GetLastError();
1609 if (iOK && (dwBytes >=
sizeof(
PARAMBLK)))
1616 U14ForceReset(hand);
1624 U14ForceReset(hand);
1629 return asLastRetCode[hand];
1637 U14ForceReset(hand);
1642 lTimeOutTicks = U14WhenToTimeOut(hand);
1645 bSpaceToSend = (
BOOL)((
long)U14OutBufSpace(hand) >= nChars);
1649 while (!bSpaceToSend && !U14PassedTime(lTimeOutTicks));
1657 U14ForceReset(hand);
1662 U14ForceReset(hand);
1667 return asLastRetCode[hand];
1681 return(U14SendString(hand, sz));
1684 short sErr = CheckHandle(hand);
1702 short sErr = CheckHandle(hand);
1710 long lTimeOutTicks = U14WhenToTimeOut(hand);
1712 bLineToGet = (
BOOL)(U14LineCount(hand) != 0);
1713 while (!bLineToGet && !U14PassedTime(lTimeOutTicks));
1718 for (i = 0; (i < 4) && (!bLineToGet); ++
i)
1721 bLineToGet = (
BOOL)(U14LineCount(hand) != 0);
1732 if (!USE_NT_DIOC(hand))
1743 NULL, 0, tstr, wMaxLen+
sizeof(
short),
1757 sErr = (
short)GetLastError();
1759 sErr = (
short)-sErr;
1765 HANDLE hMem = GlobalAlloc(GMEM_MOVEABLE,wMaxLen+
sizeof(
short));
1768 char* pMem = (
char*)GlobalLock(hMem);
1771 int iOK = DeviceIoControl(aHand1401[hand],(
DWORD)U14_GETSTRING,
1772 NULL, 0, pMem, wMaxLen+
sizeof(
short),
1776 if (dwBytes >= wMaxLen)
1778 strcpy(pBuffer, pMem+
sizeof(
short));
1779 sErr = *((
SHORT*)pMem);
1799 TranslateString(pBuffer);
1801 U14ForceReset(hand);
1805 sErr = asLastRetCode[hand];
1810 U14ForceReset(hand);
1821 long lTimeOutTicks = U14WhenToTimeOut(hand);
1824 bLineToGet = (
BOOL)(U14LineCount(hand) != 0);
1829 while (!bLineToGet && !U14PassedTime(lTimeOutTicks));
1836 if (sErr >= wMaxLen)
1841 TranslateString(pBuffer);
1846 U14ForceReset(hand);
1851 U14ForceReset(hand);
1869 short sErr = U14GetString(hand, sz, 2);
1873 if (*pcChar ==
'\0')
1879 short sErr = CheckHandle(hand);
1885 *pcChar = (
char)sErr;
1897 U14API(
short) U14Stat1401(
short hand)
1899 return ((
short)(U14LineCount(hand) > 0));
1906 U14API(
short) U14CharCount(
short hand)
1910 short sErr = U14Status1401(hand,
U14_STAT1401, &csBlock);
1912 sErr = csBlock.
ints[0];
1916 short sErr = CheckHandle(hand);
1925 U14API(
short) U14LineCount(
short hand)
1931 sErr = csBlock.
ints[0];
1935 short sErr = CheckHandle(hand);
1949 U14API(
void) U14GetErrorString(
short nErr,
char* pStr,
WORD wMax)
1956 sprintf(wstr,
"The 1401 is apparently switched off (code %d)", nErr);
1960 sprintf(wstr,
"The 1401 is not connected to the interface card (code %d)", nErr);
1964 sprintf(wstr,
"The 1401 is not working correctly (code %d)", nErr);
1968 sprintf(wstr,
"The 1401 interface card was not detected (code %d)", nErr);
1972 sprintf(wstr,
"The 1401 fails to become ready for use (code %d)", nErr);
1976 sprintf(wstr,
"The 1401 interface card jumpers are incorrect (code %d)", nErr);
1980 sprintf(wstr,
"The 1401 interrupt is not available for use (code %d)", nErr);
1984 sprintf(wstr,
"The 1401 is already in use by another program (code %d)", nErr);
1988 sprintf(wstr,
"The 1401 DMA channel is not available for use (code %d)", nErr);
1992 sprintf(wstr,
"The application supplied an incorrect 1401 handle (code %d)", nErr);
1996 sprintf(wstr,
"The application used an incorrect 1401 number (code %d)", nErr);
2000 sprintf(wstr,
"The code passed to the 1401 driver is invalid (code %d)", nErr);
2004 sprintf(wstr,
"The sub-code passed to the 1401 driver is invalid (code %d)", nErr);
2008 sprintf(wstr,
"No room in buffer for characters for the 1401 (code %d)", nErr);
2012 sprintf(wstr,
"No characters from the 1401 are available (code %d)", nErr);
2016 sprintf(wstr,
"A string sent to or read from the 1401 was too long (code %d)", nErr);
2020 sprintf(wstr,
"Failed to lock host memory for data transfer (code %d)", nErr);
2024 sprintf(wstr,
"Failed to unlock host memory after data transfer (code %d)", nErr);
2028 sprintf(wstr,
"The transfer area used is already set up (code %d)", nErr);
2032 sprintf(wstr,
"The transfer area used has not been set up (code %d)", nErr);
2036 sprintf(wstr,
"The transfer area number is incorrect (code %d)", nErr);
2040 sprintf(wstr,
"The command file %s could not be opened (code %d)", szLastName, nErr);
2044 sprintf(wstr,
"The command file %s could not be read (code %d)", szLastName, nErr);
2048 sprintf(wstr,
"The %s command resource could not be found (code %d)", szLastName, nErr);
2052 sprintf(wstr,
"Unable to allocate memory for loading command %s (code %d)", szLastName, nErr);
2056 sprintf(wstr,
"Unable to lock memory for loading command %s (code %d)", szLastName, nErr);
2060 sprintf(wstr,
"Error in loading command %s, bad command format (code %d)", szLastName, nErr);
2064 sprintf(wstr,
"Error detected after data transfer to or from the 1401 (code %d)", nErr);
2068 sprintf(wstr,
"Windows 3.1 is not running in 386 enhanced mode (code %d)", nErr);
2072 sprintf(wstr,
"The 1401 device driver cannot be found (code %d)\nUSB: check plugged in and powered\nOther: not installed?", nErr);
2076 sprintf(wstr,
"The 1401 device driver is too old for use (code %d)", nErr);
2080 sprintf(wstr,
"Character transmissions to the 1401 timed-out (code %d)", nErr);
2084 sprintf(wstr,
"Buffer for text from the 1401 was too small (code %d)", nErr);
2088 sprintf(wstr,
"1401 monitor callback already set up (code %d)", nErr);
2092 sprintf(wstr,
"1401 monitor callback deregister invalid (code %d)", nErr);
2095 case U14ERR_DRIVCOMMS:
2096 sprintf(wstr,
"1401 device driver communications failed (code %d)", nErr);
2100 sprintf(wstr,
"Failed to allocate or lock memory for text from the 1401 (code %d)", nErr);
2104 sprintf(wstr,
"1401 error code %d returned; this code is unknown", nErr);
2119 short sErr = CheckHandle(hand);
2125 sizeof(TGET_TX_BLOCK), &dwBytes,
NULL);
2127 if (bOK && (dwBytes >=
sizeof(TGET_TX_BLOCK)))
2153 DWORD dwVer = GetVersion();
2154 if (dwVer & 0x80000000)
2159 PROCESS_QUERY_INFORMATION |
2164 SIZE_T dwMinSize,dwMaxSize;
2165 if (GetProcessWorkingSetSize(hProcess, &dwMinSize, &dwMaxSize))
2167 DWORD dwMin = dwMinKb << 10;
2168 DWORD dwMax = dwMaxKb << 10;
2171 if (dwMin > dwMinSize)
2174 if (dwMax > dwMaxSize)
2177 if (!SetProcessWorkingSetSize(hProcess, dwMinSize, dwMaxSize))
2183 CloseHandle(hProcess);
2191 if (dwMinKb | dwMaxKb)
2205 short sErr = CheckHandle(hand);
2213 VirtualUnlock(apAreas[hand][wArea], auAreas[hand][wArea]);
2215 auAreas[hand][
wArea] = 0;
2235 short sErr = CheckHandle(hand);
2238 if (wArea >= MAX_TRANSAREAS)
2243 assert(auAreas[hand][wArea] == 0);
2248 if (!VirtualLock(pvBuff, dwLength))
2251 auAreas[hand][
wArea] = 0;
2255 if (!USE_NT_DIOC(hand))
2263 if ((wArea != 0) && (U14DriverVersion(hand) < 0x00010002L))
2281 sErr = (
short)GetLastError();
2301 sErr = U14ERR_DRIVCOMMS;
2310 VirtualUnlock(pvBuff, dwLength);
2312 auAreas[hand][
wArea] = 0;
2320 td.lpvBuff = (
long long)((
unsigned long)
pvBuff);
2321 td.wAreaNum =
wArea;
2352 short sErr = U14TransferFlags(hand);
2356 if (wArea >= MAX_TRANSAREAS)
2361 if ((bEvent != 0) != (aXferEvent[hand] != 0))
2367 CloseHandle(aXferEvent[hand]);
2368 aXferEvent[hand] =
NULL;
2378 csBlock.
longs[0] |= 0x10000;
2379 *((HANDLE*)&csBlock.
longs[1]) = aXferEvent[hand];
2384 csBlock.
longs[1] = (
long)aXferEvent[hand];
2391 sErr = (
short)(aXferEvent[hand] !=
NULL);
2398 short sErr = CheckHandle(hand);
2402 if (wArea >= MAX_TRANSAREAS)
2406 te.
wFlags = bToHost ? 1 : 0;
2419 U14API(
int) U14TestTransferEvent(
short hand,
WORD wArea)
2422 int iErr = CheckHandle(hand);
2425 if (aXferEvent[hand])
2426 iErr = WaitForSingleObject(aXferEvent[hand], 0) == WAIT_OBJECT_0;
2431 short sErr = CheckHandle(hand);
2447 int iErr = CheckHandle(hand);
2450 if (aXferEvent[hand])
2453 msTimeOut = INFINITE;
2454 iErr = WaitForSingleObject(aXferEvent[hand], msTimeOut) != WAIT_OBJECT_0;
2462 short sErr = CheckHandle(hand);
2474 U14API(
short) U14SetCircular(
short hand,
WORD wArea,
BOOL bToHost,
2475 void *pvBuff,
DWORD dwLength)
2477 short sErr = CheckHandle(hand);
2481 if (wArea >= MAX_TRANSAREAS)
2488 assert(auAreas[hand][wArea] == 0);
2493 if (!VirtualLock(pvBuff, dwLength))
2512 sErr = U14ERR_DRIVCOMMS;
2521 VirtualUnlock(pvBuff, dwLength);
2523 auAreas[hand][
wArea] = 0;
2547 int lErr = CheckHandle(hand);
2551 if (wArea >= MAX_TRANSAREAS)
2597 int lErr = CheckHandle(hand);
2601 if (wArea < MAX_TRANSAREAS)
2649 static short Transfer(
short hand,
BOOL bTo1401,
char* pData,
2653 short sResult = U14SetTransArea(hand, 0, (
void *)pData, dwSize, eSz);
2657 "TO%s,$%X,$%X,0;", bTo1401 ?
"1401" :
"HOST", dw1401, dwSize);
2659 U14SendString(hand, strcopy);
2661 sResult = U14CheckErr(hand);
2665 U14UnSetTransfer(hand, 0);
2674 DWORD dw1401,
short eSz)
2676 short sErr = CheckHandle(hand);
2678 sErr = Transfer(hand,
TOHOST, pAddrHost, dwSize, dw1401, eSz);
2686 DWORD dw1401,
short eSz)
2688 short sErr = CheckHandle(hand);
2690 sErr = Transfer(hand,
TO1401, (
char*)pAddrHost, dwSize, dw1401, eSz);
2698 #define file_exist(name) (_access(name, 0) != -1)
2699 #define file_open(name) _lopen(name, OF_READ)
2700 #define file_close(h) _lclose(h)
2701 #define file_seek(h, pos) _llseek(h, pos, FILE_BEGIN)
2702 #define file_read(h, buffer, size) (_lread(h, buffer, size) == size)
2705 #define file_exist(name) (access(name, F_OK) != -1)
2706 #define file_open(name) open(name, O_RDONLY)
2707 #define file_close(h) close(h)
2708 #define file_seek(h, pos) lseek(h, pos, SEEK_SET)
2709 #define file_read(h, buffer, size) (read(h, buffer, size) == (ssize_t)size)
2713 char szProcPath[32];
2714 sprintf(szProcPath,
"/proc/%d/exe", getpid());
2715 if (readlink(szProcPath, buffer, max) != -1)
2734 short sErr = CheckHandle(hand);
2740 if (file_exist(command))
2747 char* pStr =
strrchr(command, PATHSEP);
2761 ExtForType(asType1401[hand], szExt);
2769 DWORD dwLen = GetModuleFileName(
NULL, filnam, FNSZ);
2772 char* pStr =
strrchr(filnam, PATHSEP);
2778 strcat(filnam,
"1401" PATHSEPSTR);
2780 bGotIt = (
BOOL)file_exist(filnam);
2790 char* pStr = getenv(
"1401DIR");
2794 if (filnam[
strlen(filnam)-1] != PATHSEP)
2795 strcat(filnam, PATHSEPSTR);
2797 bGotIt = (
BOOL)file_exist(filnam);
2804 strcpy(filnam, DEFCMDPATH);
2806 bGotIt = file_exist(filnam);
2815 if (file_read(iFHandle, &rCmdHead,
sizeof(CMDHEAD)))
2817 size_t nComSize = rCmdHead.
wCmdSize;
2818 char* pMem =
malloc(nComSize);
2821 file_seek(iFHandle,
sizeof(CMDHEAD));
2822 if (file_read(iFHandle, pMem, (
UINT)nComSize))
2824 sErr = U14SetTransArea(hand, 0, (
void *)pMem, (
DWORD)nComSize,
ESZBYTES);
2827 sprintf(strcopy,
"CLOAD,0,$%X;", (
int)nComSize);
2828 sErr = U14SendString(hand, strcopy);
2831 sErr = U14CheckErr(hand);
2835 U14UnSetTransfer(hand, 0);
2848 file_close(iFHandle);
2867 short sErr = CheckHandle(hand);
2871 ExtForType(asType1401[hand], szFExt);
2885 if (!strcopy[iLoop1])
2888 if (bDone || (strcopy[iLoop1] ==
','))
2892 szFName[iLoop2]=(
char)0;
2894 strncpy(szLastName, szFName,
sizeof(szLastName));
2895 szLastName[
sizeof(szLastName)-1] = 0;
2896 strncat(szLastName, szFExt,
sizeof(szLastName));
2897 szLastName[
sizeof(szLastName)-1] = 0;
2899 U14SendString(hand, szFName);
2900 U14SendString(hand,
";ERR;");
2902 lErr = U14LongsFrom1401(hand, er, 5);
2912 strcat(filnam, PATHSEPSTR);
2919 lErr = U14LdCmd(hand, filnam);
2931 szFName[iLoop2++] = strcopy[iLoop1++];
2942 return ((dwIndex<<16) | ((
DWORD)lErr & 0x0000FFFF));
2946 U14API(
int) U14InitLib(
void)
2954 DWORD dwVersion = GetVersion();
2957 if (dwVersion & 0x80000000)
2969 aHand1401[
i] = INVALID_HANDLE_VALUE;
2971 alTimeOutPeriod[
i] = 3000;
2974 abUseNTDIOC[
i] = (
BOOL)!bWindows9x;
2976 aXferEvent[
i] =
NULL;
3001 INT APIENTRY DllMain(HANDLE hInst,
DWORD ul_reason_being_called, LPVOID lpReserved)
3005 switch (ul_reason_being_called)
3007 case DLL_PROCESS_ATTACH:
3008 iRetVal = U14InitLib() > 0;
3012 case DLL_PROCESS_DETACH:
3013 if (--iAttached == 0)
3019 UNREFERENCED_PARAMETER(lpReserved);
3032 if (--iAttached == 0)