123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667 |
- // ----------------------------------------------
- // - DAC32.DLL Implementations Datei -
- // - Written 1996-1998 by Christoph Schmelnik -
- // ----------------------------------------------
- // Version 1.33 : 18.01.1998
- // Changes:
- // Added speed selection support for all current Plextor drives
- //
- // Version 1.40 : 24.02.1998
- // Changes:
- // Set correct direction flags, to work with NT device IO interface and ATAPI drives
- // Changed main CD detection to TestUnitReady
- // Removed CD detection from Audio Status Info
- // Added hopefully correct read command for Matsushita/Panasonic drives
- // Added Parameters to CDAC class to allow the disabling of the audio test and to spin up the drive for a specified time
- // in seconds to avoid spin up problems on some drives. Both parameters have default values so it behaves like the old version
- // without the additional parameters
- // Added Parameter to the constructor of CWaveSave to disable writing any Headers. Also this parameter has a default to work like
- // before.
- // Added virtual function in CDAC to report buffer underruns in Burst Copy Mode
- // For the last feature an immediate parameter in WaitCDDA is added
- // GetLastSense function added to return the sense information for the last read audio command
- // Configuration in CMapDrive extended by new features
- // Added function to CD Class to read Media Cataloge Number
- //
- // Version 1.41 : 02.05.1998
- // Changes:
- // New GetInfoEx() function in CMapDrive, to allow a better result checking.
- // Bugfixed error handling in CWaveSave and CDAC regarding write errors
- //
- // Version 1.42 : 02.08.1998
- // Changes:
- // Added GetLastReadableAddress function to get the last readable Sektor of a session.
- // Added a flag in the drive properties for the function.
- // Added this function to the CDAC object.
- //
- // Version 1.43 : 23.12.1998
- // Changes:
- // Added Wave and DAC classes are now available in a MT version, the old versions will not longer be updated.
- //
- // Version 1.44 : 10.03.1999
- // Changes:
- // Added Support for current Plextor CDROM drives and CD-Writers.
- // Added Support for Jukeboxes
- // Changed Handling of the Ringbuffer
- //
- // Version 1.45 : 15.08.1999
- // Changes:
- // Added Enhanced error detection for Plextor drives.
- // Several Bugfixes (initialising under NT and Ringbuffer specific)
- //
- // Version 1.45-Build 11 : 11.11.1999
- // Changes:
- // Added a check for the MaxSektor parameter in CBaseWaveMT to avoid Program failures even if the applications provides an invalid value.
- // Changed source to comile with Borland compiler
- // Added MMC-2 Type which will be default for Sony CD-Writers 140 and 928
- // Skip Virtual CD devices in Bus scan
- // Fixed Array out of bound bug in drive detection.
- //limit the read to 64k, because of a bug in the Adaptec drivers
- #define Bug64
- //limit the number of retries at error to 5
- #define MAXTRIES 5
- #include "dac32.h"
- #include <stdlib.h>
- #include <assert.h>
- #include <process.h>
- #ifdef __BORLANDC__ // pgo (to make it compatible with Bormand compiler)
- #define _stricmp _stricmp
- #define _strlwr strlwr
- #endif
- // ----------------------------------------------------------------------------------------
- // - Implementation of the private copy operators -
- // - -
- // - Author: Christoph Schmelnik -
- // - Purpose: Check the syntax of program -
- // ----------------------------------------------------------------------------------------
- CBaseCD& CBaseCD::operator = (const CBaseCD &other)
- {
- assert(!&other);
- return (*this);
- }
- CSCSICD& CSCSICD::operator = (const CSCSICD &other)
- {
- assert(!&other);
- return (*this);
- }
- // ----------------------------------------------------------------------------------------
- // - Implementation of the class members of CCDAdress -
- // - -
- // - Author: Christoph Schmelnik -
- // - Purpose: Eliminate the errors at compile time -
- // ----------------------------------------------------------------------------------------
- void CCDAdress::SetRedbook(long Value)
- {
- Adresse=Value >> 24;
- Adresse+=((Value >> 16) & 255)*75;
- Adresse+=((Value >> 8) & 255)*4500;
- };
- // ----------------------------------------------------------------------------------------
- // - Implementation of the class members of CMapInfo -
- // - -
- // - Author: Christoph Schmelnik -
- // - Purpose: Implement the information of the TypeMappings -
- // ----------------------------------------------------------------------------------------
- CMapInfo::CMapInfo()
- {
- strncpy(TypNamen[0],"TOSHIBA ", 9);
- strncpy(TypNamen[1],"SONY ", 9);
- strncpy(TypNamen[2],"NEC ", 9);
- strncpy(TypNamen[3],"HITACHI ", 9);
- strncpy(TypNamen[4],"YAMAHA ", 9);
- strncpy(TypNamen[5],"PIONEER ", 9);
- strncpy(TypNamen[6],"IBM ", 9);
- strncpy(TypNamen[7],"PLEXTOR ", 9);
- strncpy(TypNamen[8],"PHILIPS ", 9);
- strncpy(TypNamen[9],"GRUNDIG ", 9);
- strncpy(TypNamen[10],"HP ", 9);
- strncpy(TypNamen[11],"IMS ", 9);
- strncpy(TypNamen[12],"MITSUMI ", 9);
- strncpy(TypNamen[13],"ATAPI ", 9);
- strncpy(TypNamen[14],"TOSHNEW ", 9);
- strncpy(TypNamen[15],"RICOH ", 9);
- strncpy(TypNamen[16],"MATSHITA", 9);
- strncpy(TypNamen[17],"PLASMON ", 9);
- strncpy(TypNamen[18],"KODAK ", 9);
- strncpy(TypNamen[19],"TEAC ", 9);
- strncpy(TypNamen[20],"CyberDrv", 9);
- strncpy(TypNamen[21],"MMC-2 ", 9); // pgo
- int const t[]={CDTYPE_TOSHIBA,CDTYPE_SONY,CDTYPE_NEC,CDTYPE_SONY,CDTYPE_SONY,CDTYPE_SONY,
- CDTYPE_SONY,CDTYPE_PLEXTOR,CDTYPE_PHILIPS,CDTYPE_PHILIPS,CDTYPE_PHILIPS,CDTYPE_PHILIPS,
- CDTYPE_PHILIPS,CDTYPE_ATAPI,CDTYPE_TOSHNEW,CDTYPE_RICOH,CDTYPE_MATSHITA,CDTYPE_PHILIPS,
- CDTYPE_PHILIPS,CDTYPE_SONY,CDTYPE_CYBERDRV,
- CDTYPE_CYBERDRV}; // pgo
- for (int i=0; i<MaxMappings; i++)
- TypMapping[i]=t[i];
- }
- char *CMapInfo::GetTypName(int Index)
- {
- return TypNamen[Index];
- };
- int CMapInfo::GetTypMapping(int Index)
- {
- return TypMapping[Index];
- };
- int CMapInfo::GetTypMappingRev(int CDType)
- {
- int Index=0;
- while ((Index<MaxMappings) &&
- (TypMapping[Index]!=CDType))
- Index++;
- return Index;
- };
- // ----------------------------------------------------------------------------------------
- // - Implementation of the class members of CMapDrive -
- // - -
- // - Author: Christoph Schmelnik -
- // - Purpose: Administration of the drive configuration -
- // ----------------------------------------------------------------------------------------
- CMapDrive::CMapDrive(BOOL bDoReset)
- {
- First=0;
-
- m_hDriveEvent=INVALID_HANDLE_VALUE;
- wchar_t szEventName[32] = {0};
- wsprintf(szEventName,L"%X",this);
- m_hDriveEvent=CreateEvent(NULL,TRUE,FALSE,szEventName);
- if (bDoReset)
- Reset();
- };
- CMapDrive::~CMapDrive()
- {
- DeleteAll();
- if (m_hDriveEvent!=INVALID_HANDLE_VALUE)
- CloseHandle(m_hDriveEvent);
- };
- void CMapDrive::DeleteAll()
- {
- TDriveInfoMem *Akt;
- Akt=First;
- while (First)
- {
- Akt=First;
- First=Akt->Next;
- delete Akt;
- }
- };
- void CMapDrive::Reset()
- {
- TDriveInfoMem *Akt,*Last;
- DeleteAll();
- BYTE SCSIType;
- TDriveInfo Info = {0};
- int DType = DTYPE_UNKNOWN;
- char Revision[5] = {0};
- char ManagerID[17] = {0};
- char HAID[17] = {0};
- THAUnique HAUnique;
- MEMORYSTATUS MemStat;
- MemStat.dwLength=sizeof(MEMORYSTATUS);
- GlobalMemoryStatus((LPMEMORYSTATUS)&MemStat);
- CMapInfo MapInfo;
- int HostNum;
- for (HostNum=0; HostNum<NumberOfHostAdapters; HostNum++)
- {
- memset(Revision,0,sizeof(Revision));
- memset(ManagerID,0,sizeof(ManagerID));
- memset(HAID,0,sizeof(HAID));
- memset(&HAUnique,0,sizeof(HAUnique));
- if (HAInquiry(HostNum,ManagerID,HAID,HAUnique))
- {
- if (_stricmp(HAID, "fastcdmp") == 0) //pgo: Skip Virtual CD Adapter in Bus Scan
- continue;
- HostAdapterMemory[HostNum]=HAUnique.MaximumTransferLen;
- for (int IDNum=0; IDNum<8; IDNum++)
- for (int LUNNum=0; LUNNum<=MAXLUN; LUNNum++)
- {
- DType=GetDeviceInfo(HostNum,IDNum,LUNNum,SCSIType,Info.VendorID,Info.ProductID,Revision,m_hDriveEvent);
- if ((DType==DTYPE_CROM)||
- (DType==DTYPE_WORM))
- {
- if (SCSIType)
- {
- int i;
- for (i=0; (i<MaxMappings) && _stricmp(Info.VendorID,MapInfo.GetTypName(i)); i++);
- if (i>=MaxMappings) i=1; //pgo: avoid array out of bound
- Info.Type=i;
- }
- else
- Info.Type=MapInfo.GetTypMappingRev(CDTYPE_ATAPI);
- if (MapInfo.GetTypMapping(Info.Type)==CDTYPE_TOSHIBA)
- {
- char szNumbers[17] = {0};
- for (size_t i=0; i<strlen(Info.ProductID); i++)
- if (isdigit(Info.ProductID[i]))
- strncat(szNumbers,&Info.ProductID[i],1);
- int nProductID=atoi(szNumbers);
- if (((nProductID>3800) &&
- (nProductID<4000)) ||
- ((nProductID>5700) &&
- (nProductID<10000)))
- Info.Type=MapInfo.GetTypMappingRev(CDTYPE_TOSHNEW);
- }
- // pgo
- else if (MapInfo.GetTypMapping(Info.Type)==CDTYPE_SONY)
- {
- if (SCSIType)
- {
- char szNumbers[17] = {0};
- for (size_t i=0; i<strlen(Info.ProductID); i++)
- if (isdigit(Info.ProductID[i]))
- strncat(szNumbers,&Info.ProductID[i],1);
- int nProductID=atoi(szNumbers);
- if ((nProductID == 140) || (nProductID == 928))
- Info.Type=MapInfo.GetTypMappingRev(CDTYPE_CYBERDRV);
- }
- }
- Info.ID=IDNum;
- Info.LUN=LUNNum;
- Info.HostAdapterNumber=HostNum;
- Info.Mode=ModeBurst;
- Info.MaxSektors=MemStat.dwTotalPhys/16/2352;
- if (Info.MaxSektors>(HostAdapterMemory[HostNum]/2352))
- Info.MaxSektors=HostAdapterMemory[HostNum]/2352;
- #ifdef Bug64
- if (Info.MaxSektors>27) Info.MaxSektors=27;
- #else
- if (Info.MaxSektors>446) Info.MaxSektors=446;
- #endif
- if (!Info.MaxSektors) Info.MaxSektors=26;
- Info.SynchSektors=3;
- Info.Speed=0;
- Info.PerformDATest=DATEST_FIRSTTRACK;
- Info.SpinUpMode=SPINUP_NEVER;
- Info.dwSpinUpTime=5;
- Info.bUseLastReadableAddress=FALSE;
- Info.bUseC2ErrorInfo=FALSE;
- Info.bSpinDown=FALSE;
- Akt=new TDriveInfoMem;
- Akt->Info=Info;
- Akt->Next=0;
- if (!First) First=Akt;
- else Last->Next=Akt;
- //Last must be set to Akt
- Last=Akt;
- }
- }
- }
- }
- if (RunningNT)
- {
- //check all drives for direct access
- int Index, Length;
- wchar_t DriveList[128] = {0}, *pDrives = 0;
- Length=GetLogicalDriveStrings(128,DriveList);
- if (Length)
- {
- pDrives=DriveList;
- Index=0;
- while (pDrives && *pDrives && (Index<Length))
- {
- if (GetDriveType(pDrives)==DRIVE_CDROM)
- {
- wchar_t CDDevice[10]=L"\\\\.\\x:";
- HANDLE hDrive;
- CharLower(pDrives);
- //_strlwr(pDrives);
- CDDevice[4]=pDrives[0];
- int IDNum=pDrives[0]-'a';
-
- //For Windows NT 5 use other file flags
- OSVERSIONINFO osver;
- memset( &osver, 0x00, sizeof(osver) );
- osver.dwOSVersionInfoSize = sizeof(osver);
- GetVersionEx( &osver );
- DWORD dwOpenFlags = GENERIC_READ;
- if ( (osver.dwPlatformId == VER_PLATFORM_WIN32_NT) && (osver.dwMajorVersion > 4) ) dwOpenFlags |= GENERIC_WRITE;
-
- hDrive=CreateFile(CDDevice,dwOpenFlags,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);
- if (hDrive!=INVALID_HANDLE_VALUE)
- {
- //CT> added correct host/id/lun guessing
- extern int getSCSIIDFromDrive(char driveletter, int *host, int *id, int *lun);
- int m_lun;
- getSCSIIDFromDrive((char)pDrives[0],&HostNum,&IDNum,&m_lun);
- DType=GetDeviceInfo(HostNum,IDNum,m_lun,SCSIType,Info.VendorID,Info.ProductID,Revision,hDrive);
- if ((DType==DTYPE_CROM)||
- (DType==DTYPE_WORM))
- {
- SCSIMaxBlocks(hDrive,&HostAdapterMemory[HostNum]);
- if (SCSIType)
- {
- int i;
- for (i=0; (i<MaxMappings) && _stricmp(Info.VendorID,MapInfo.GetTypName(i)); i++);
- if (i>=MaxMappings) i=1; //pgo: avoid array out of bound
- Info.Type=i;
- }
- else
- Info.Type=MapInfo.GetTypMappingRev(CDTYPE_ATAPI);
- if (MapInfo.GetTypMapping(Info.Type)==CDTYPE_TOSHIBA)
- {
- char szNumbers[17];
- szNumbers[0]=0;
- for (size_t i=0; i<strlen(Info.ProductID); i++)
- if (isdigit(Info.ProductID[i]))
- strncat(szNumbers,&Info.ProductID[i],1);
- int nProductID=atoi(szNumbers);
- if (((nProductID>3800) &&
- (nProductID<4000)) ||
- ((nProductID>5700) &&
- (nProductID<10000)))
- Info.Type=MapInfo.GetTypMappingRev(CDTYPE_TOSHNEW);
- }
- // pgo
- else if (MapInfo.GetTypMapping(Info.Type)==CDTYPE_SONY)
- {
- if (SCSIType)
- {
- char szNumbers[17] = {0};
- for (size_t i=0; i<strlen(Info.ProductID); i++)
- if (isdigit(Info.ProductID[i]))
- strncat(szNumbers,&Info.ProductID[i],1);
- int nProductID=atoi(szNumbers);
- if ((nProductID == 140) || (nProductID == 928))
- Info.Type=MapInfo.GetTypMappingRev(CDTYPE_CYBERDRV);
- }
- }
- Info.ID=IDNum;
- Info.LUN=0;
- Info.HostAdapterNumber=HostNum;
- Info.Mode=ModeNormal;
- Info.MaxSektors=MemStat.dwTotalPhys/16/2352;
- if (Info.MaxSektors>(HostAdapterMemory[HostNum]/2352))
- Info.MaxSektors=HostAdapterMemory[HostNum]/2352;
- #ifdef Bug64
- if (Info.MaxSektors>27) Info.MaxSektors=27;
- #else
- if (Info.MaxSektors>446) Info.MaxSektors=446;
- #endif
- if (!Info.MaxSektors ||
- (MapInfo.GetTypMapping(Info.Type)==CDTYPE_ATAPI))
- Info.MaxSektors=26;
- Info.SynchSektors=3;
- Info.Speed=0;
- Info.PerformDATest=DATEST_FIRSTTRACK;
- Info.SpinUpMode=SPINUP_NEVER;
- Info.dwSpinUpTime=5;
- Info.bUseLastReadableAddress=FALSE;
- Info.bUseC2ErrorInfo=FALSE;
- Info.bSpinDown=FALSE;
- Akt=new TDriveInfoMem;
- Akt->Info=Info;
- Akt->Next=0;
- if (!First) First=Akt;
- else Last->Next=Akt;
- //Last must be set to Akt
- Last=Akt;
- HostNum++;
- }
- CloseHandle(hDrive);
- }
- }
- pDrives+=4;
- Index+=4;
- }
- }
- }
- };
- int CMapDrive::GetMaxDrives()
- {
- int i=0;
- TDriveInfoMem *Akt;
- Akt=First;
- while (Akt)
- {
- i++;
- Akt=Akt->Next;
- }
- return i;
- };
- TDriveInfo &CMapDrive::GetInfo(int index)
- {
- int i=0;
- TDriveInfoMem *Akt;
- Akt=First;
- while ((Akt) && (i<index))
- {
- i++;
- Akt=Akt->Next;
- }
- return Akt->Info;
- };
- BOOL CMapDrive::GetInfoEx(int index, TDriveInfo *&pInfo)
- {
- int i=0;
- TDriveInfoMem *Akt;
- Akt=First;
- while ((Akt) && (i<index))
- {
- i++;
- Akt=Akt->Next;
- }
- if (!Akt)
- return FALSE;
- pInfo=&Akt->Info;
- return TRUE;
- };
- void CMapDrive::DeleteInfo(int index)
- {
- int i=0;
- TDriveInfoMem *Akt,*Prev;
- Akt=First;
- Prev=0;
- while ((Akt) && (i<index))
- {
- i++;
- Prev=Akt;
- Akt=Akt->Next;
- }
- if (!Akt) return;
- if (Prev) Prev->Next=Akt->Next;
- else First=Akt->Next;
- delete Akt;
- };
- int CMapDrive::GetMaxHostAdapters()
- {
- return NumberOfHostAdapters;
- };
- int CMapDrive::GetSupportedHostAdapterMemory(int index)
- {
- if ((index<NumberOfHostAdapters) &&
- (index>=0))
- return HostAdapterMemory[index];
- else
- return -1;
- };
- void CMapDrive::SetSupportedHostAdapterMemory(int index,int Memory)
- {
- if ((index<NumberOfHostAdapters) &&
- (index>=0))
- HostAdapterMemory[index]=Memory;
- }
- int CMapDrive::GetMaxSektors(int HostAdapterNumber)
- {
- #ifdef Bug64
- int Result=HostAdapterMemory[HostAdapterNumber]/2352;
- if (Result>27)
- Result=27;
- return Result;
- #else
- return HostAdapterMemory[HostAdapterNumber]/2352;
- #endif
- };
- // ----------------------------------------------------------------------------------------
- // - Implementation of the class members of CMapInfoJuke -
- // - -
- // - Author: Christoph Schmelnik -
- // - Purpose: Implement the information of the TypeMappings -
- // ----------------------------------------------------------------------------------------
- CMapInfoJuke::CMapInfoJuke()
- {
- strncpy(TypNamen[0],"SONY ", 9);
- strncpy(TypNamen[1],"PIONEER ", 9);
- int const t[]={JUKETYPE_SONY,JUKETYPE_PIONEER};
- for (int i=0; i<MaxMappingsJuke; i++)
- TypMapping[i]=t[i];
- }
- char *CMapInfoJuke::GetTypName(int Index)
- {
- return TypNamen[Index];
- };
- int CMapInfoJuke::GetTypMapping(int Index)
- {
- return TypMapping[Index];
- };
- int CMapInfoJuke::GetTypMappingRev(int JukeType)
- {
- int Index=0;
- while ((Index<MaxMappingsJuke) &&
- (TypMapping[Index]!=JukeType))
- Index++;
- return Index;
- };
- // ----------------------------------------------------------------------------------------
- // - Implementation of the class members of CMapJuke -
- // - -
- // - Author: Christoph Schmelnik -
- // - Purpose: Administration of the jukebox configuration -
- // ----------------------------------------------------------------------------------------
- CMapJuke::CMapJuke(BOOL bDoReset)
- {
- First=0;
-
- m_hJukeEvent=INVALID_HANDLE_VALUE;
- wchar_t szEventName[32] = {0};
- wsprintf(szEventName,L"%X",this);
- m_hJukeEvent=CreateEvent(NULL,TRUE,FALSE,szEventName);
- if (bDoReset)
- Reset();
- };
- CMapJuke::~CMapJuke()
- {
- DeleteAll();
- if (m_hJukeEvent!=INVALID_HANDLE_VALUE)
- CloseHandle(m_hJukeEvent);
- };
- void CMapJuke::DeleteAll()
- {
- TJukeInfoMem *Akt;
- Akt=First;
- while (First)
- {
- Akt=First;
- First=Akt->Next;
- if (Akt->Info.pConnectedDrives)
- delete Akt->Info.pConnectedDrives;
- delete Akt;
- }
- };
- void CMapJuke::Reset()
- {
- TJukeInfoMem *Akt,*Last;
- DeleteAll();
- BYTE SCSIType = 0;
- TJukeInfo Info = {0};
- int DType = DTYPE_UNKNOWN;
- char Revision[5] = {0};
- char ManagerID[17] = {0};
- char HAID[17] = {0};
- THAUnique HAUnique;
- CMapInfoJuke MapInfo;
- for (int HostNum=0; HostNum<NumberOfHostAdapters; HostNum++)
- {
- memset(Revision,0,sizeof(Revision));
- memset(ManagerID,0,sizeof(ManagerID));
- memset(HAID,0,sizeof(HAID));
- memset(&HAUnique,0,sizeof(HAUnique));
- if (HAInquiry(HostNum,ManagerID,HAID,HAUnique))
- {
- for (int IDNum=0; IDNum<8; IDNum++)
- {
- for (int LUNNum=0; LUNNum<=MAXLUN; LUNNum++)
- {
- memset(&Info,0,sizeof(Info));
- DType=GetDeviceInfo(HostNum,IDNum,LUNNum,SCSIType,Info.VendorID,Info.ProductID,Revision,m_hJukeEvent);
- if (DType==DTYPE_JUKE)
- {
- int i;
- for (i=0; (i<MaxMappingsJuke) && _stricmp(Info.VendorID,MapInfo.GetTypName(i)); i++);
- if (_stricmp(Info.VendorID,MapInfo.GetTypName(i))) i=JUKETYPE_SONY;
- Info.Type=i;
- switch (Info.Type)
- {
- case JUKETYPE_PIONEER :
- Info.MaxDrives=4; //currently only data for the 500x changer implemeneted
- Info.MaxDiscs=500;
- break;
- case JUKETYPE_SONY :
- default:
- Info.MaxDrives=2;
- Info.MaxDiscs=100;
- break;
- }
- Info.pConnectedDrives=new int[Info.MaxDrives];
- for (int nDriveNum=0; nDriveNum<Info.MaxDrives; nDriveNum++)
- Info.pConnectedDrives[nDriveNum]=-1;
- Info.ID=IDNum;
- Info.LUN=LUNNum;
- Info.HostAdapterNumber=HostNum;
-
- Akt=new TJukeInfoMem;
- Akt->Info=Info;
- Akt->bIsWorking=FALSE;
- Akt->Next=0;
- if (!First) First=Akt;
- else Last->Next=Akt;
- //Last must be set to Akt
- Last=Akt;
- }
- }
- }
- }
- }
- };
- int CMapJuke::GetMaxJukes()
- {
- int i=0;
- TJukeInfoMem *Akt;
- Akt=First;
- while (Akt)
- {
- i++;
- Akt=Akt->Next;
- }
- return i;
- };
- TJukeInfo &CMapJuke::GetInfo(int index)
- {
- int i=0;
- TJukeInfoMem *Akt;
- Akt=First;
- while ((Akt) && (i<index))
- {
- i++;
- Akt=Akt->Next;
- }
- return Akt->Info;
- };
- BOOL CMapJuke::IsWorking(int index)
- {
- int i=0;
- TJukeInfoMem *Akt;
- Akt=First;
- while ((Akt) && (i<index))
- {
- i++;
- Akt=Akt->Next;
- }
- return Akt->bIsWorking;
- };
- void CMapJuke::SetWorking(int index,BOOL bIsWorking)
- {
- int i=0;
- TJukeInfoMem *Akt;
- Akt=First;
- while ((Akt) && (i<index))
- {
- i++;
- Akt=Akt->Next;
- }
- Akt->bIsWorking=bIsWorking;
- };
- void CMapJuke::DeleteInfo(int index)
- {
- int i=0;
- TJukeInfoMem *Akt,*Prev;
- Akt=First;
- Prev=0;
- while ((Akt) && (i<index))
- {
- i++;
- Prev=Akt;
- Akt=Akt->Next;
- }
- if (!Akt) return;
- if (Prev) Prev->Next=Akt->Next;
- else First=Akt->Next;
- if (Akt->Info.pConnectedDrives)
- delete Akt->Info.pConnectedDrives;
- delete Akt;
- };
- // ----------------------------------------------------------------------------------------
- // - Implementation of the class members of CJukeBox -
- // - -
- // - Author: Christoph Schmelnik -
- // - Purpose: Control the basic JukeBox functions over ASPI -
- // ----------------------------------------------------------------------------------------
- CJukeBox::CJukeBox (TJukeInfo &xInfo):Config(xInfo)
- {
- m_hJukeEvent=INVALID_HANDLE_VALUE;
- wchar_t szEventName[32] = {0};
- wsprintf(szEventName,L"%X",this);
- m_hJukeEvent=CreateEvent(NULL,TRUE,FALSE,szEventName);
- assert(m_hJukeEvent);
- }
- CJukeBox::~CJukeBox()
- {
- if (m_hJukeEvent!=INVALID_HANDLE_VALUE)
- CloseHandle(m_hJukeEvent);
- }
- BOOL CJukeBox::MoveMedium(int Source,int Destination)
- {
- switch (MapInfo.GetTypMapping(Config.Type))
- {
- case JUKETYPE_PIONEER :
- if ((Source<1) || (Source>Config.MaxDiscs))
- if ((Source<0x4000) || (Source>=(0x4000+Config.MaxDrives)))
- return FALSE;
- if ((Destination<1) || (Destination>Config.MaxDiscs))
- if ((Destination<0x4000) || (Destination>=(0x4000+Config.MaxDrives)))
- return FALSE;
- break;
- case JUKETYPE_SONY :
- default:
- if ((Source<1) || (Source>Config.MaxDiscs))
- {
- if ((Source<0x4000) || (Source>=(0x4000+Config.MaxDrives)))
- return FALSE;
- else
- Source-=0x3fff;
- }
- else
- Source+=10;
- if ((Destination<1) || (Destination>Config.MaxDiscs))
- {
- if ((Destination<0x4000) || (Destination>=(0x4000+Config.MaxDrives)))
- return FALSE;
- else
- Destination-=0x3fff;
- }
- else
- Destination+=10;
- break;
- }
- while (!TestUnitReady(Config.HostAdapterNumber,Config.ID,Config.LUN,m_hJukeEvent));
- TOpcode OpC;
- OpC[0]=0xa5;
- OpC[1]=Config.LUN>>5;
- OpC[2]=0x00;
- OpC[3]=0x00;
- OpC[4]=Source/256;
- OpC[5]=Source%256;
- OpC[6]=Destination/256;
- OpC[7]=Destination%256;
- OpC[8]=0x00;
- OpC[9]=0x00;
- OpC[10]=0x00;
- OpC[11]=0x00;
- return ExecuteSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,0,OpC,12,NULL,0,m_hJukeEvent);
- }
- // ----------------------------------------------------------------------------------------
- // - Implementation of the class members of CBaseCD -
- // - -
- // - Author: Christoph Schmelnik -
- // - Purpose: The drive independent functions to access the CD-ROM drives -
- // ----------------------------------------------------------------------------------------
- int CBaseCD::Lasterror()
- {
- int h;
- h=Error;
- Error=CDOK;
- return h;
- }
- int CBaseCD::ReadFirstTrackInfo(TTrackList &Infos)
- {
- if (!FirstTrack) return 0;
- AktTrack=FirstTrack;
- Infos=AktTrack->Info;
- return 1;
- }
- int CBaseCD::ReadNextTrackInfo(TTrackList &Infos)
- {
- if ((!FirstTrack) ||
- (!AktTrack->Next)) return 0;
- AktTrack=AktTrack->Next;
- Infos=AktTrack->Info;
- return 1;
- }
- int CBaseCD::ReadPrevTrackInfo(TTrackList &Infos)
- {
- if ((!FirstTrack) ||
- (!AktTrack->Prev)) return 0;
- AktTrack=AktTrack->Prev;
- Infos=AktTrack->Info;
- return 1;
- }
- int CBaseCD::ReadTrackInfo(TTrackList &Infos)
- {
- if ((!FirstTrack) ||
- (Infos.TrackNummer<1)) return 0;
- if (!AktTrack)
- AktTrack=FirstTrack;
- if (AktTrack->Info.TrackNummer==Infos.TrackNummer)
- {
- Infos=AktTrack->Info;
- return 1;
- }
- while ((AktTrack->Info.TrackNummer>Infos.TrackNummer) &&
- (AktTrack->Prev))
- AktTrack=AktTrack->Prev;
- while ((AktTrack->Info.TrackNummer<Infos.TrackNummer) &&
- (AktTrack->Next))
- AktTrack=AktTrack->Next;
- if (AktTrack->Info.TrackNummer!=Infos.TrackNummer) return 0;
- Infos=AktTrack->Info;
- return 1;
- }
- int CBaseCD::ReadMaxTracks()
- {
- TTrackListeMem *Laeufer;
- if (!FirstTrack) return 0;
- Laeufer=AktTrack;
- while (Laeufer->Next)
- Laeufer=Laeufer->Next;
- return Laeufer->Info.TrackNummer;
- }
- void CBaseCD::DeleteTrackList()
- {
- while (FirstTrack)
- {
- AktTrack=FirstTrack->Next;
- delete FirstTrack;
- FirstTrack=AktTrack;
- }
- }
- // ----------------------------------------------------------------------------------------
- // - Implementation of the class members of CSCSICD -
- // - -
- // - Author: Christoph Schmelnik -
- // - Purpose: Control the basic CDROM functions over ASPI -
- // ----------------------------------------------------------------------------------------
- CSCSICD::CSCSICD (char drive, TDriveInfo &xInfo):Config(xInfo)
- {
- m_bSpeedTableInitialized=FALSE;
- FirstTrack=0;
- NECRotationSpeed = 0; // pgo
- Changed=FALSE;
- CDPresentLast=TRUE;
- Error=CDOK;
- m_hDriveEvent=INVALID_HANDLE_VALUE;
- memset(&m_SenseInfo,0,sizeof(TSenseInfo));
- if ((Config.HostAdapterNumber>=NumberOfHostAdapters) &&
- RunningNT)
- {
- DWORD dwFlags;
- OSVERSIONINFO osver;
- wchar_t CDDevice[10]=L"\\\\.\\x:";
- CDDevice[4]=(wchar_t)drive;//(Config.HostAdapterNumber + 'A'/* + 1*/);
- //For Windows NT 5 use other file flags
- memset( &osver, 0x00, sizeof(osver) );
- osver.dwOSVersionInfoSize = sizeof(osver);
- GetVersionEx( &osver );
- // if Win2K or greater, add GENERIC_WRITE
- dwFlags = GENERIC_READ;
- if ( (osver.dwPlatformId == VER_PLATFORM_WIN32_NT) && (osver.dwMajorVersion > 4) ) dwFlags |= GENERIC_WRITE;
-
- m_hDriveEvent = CreateFile( CDDevice, dwFlags, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
- }
- else
- {
- wchar_t szEventName[32] = {0};
- wsprintf(szEventName,L"%X",this);
- m_hDriveEvent=CreateEvent(NULL,TRUE,FALSE,szEventName);
- assert(m_hDriveEvent);
- }
- TDriveStatus DInfo=Get_DriveStatus();
- if (DInfo.CDPresent) ReRead();
- }
- CSCSICD::~CSCSICD()
- {
- DeleteTrackList();
- if (m_hDriveEvent!=INVALID_HANDLE_VALUE)
- CloseHandle(m_hDriveEvent);
- }
- void CSCSICD::PrepareCDDA()
- {
- switch (MapInfo.GetTypMapping(Config.Type))
- {
- case CDTYPE_TOSHIBA :
- {
- memset(&ModeData,0,sizeof(ModeData));
- if (!ModeSense(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeData,12,0,m_hDriveEvent))
- {
- Error=CDASPIError;
- return;
- }
- ModeData[0]=0;
- TDriveMode ModeSelectData;
- ModeSelectData[0]=0x00;
- ModeSelectData[1]=0x00;
- ModeSelectData[2]=0x00;
- ModeSelectData[3]=0x08;
- ModeSelectData[4]=0x82;
- ModeSelectData[5]=0x00;
- ModeSelectData[6]=0x00;
- ModeSelectData[7]=0x00;
- ModeSelectData[8]=0x00;
- ModeSelectData[9]=0x00;
- ModeSelectData[10]=0x09;
- ModeSelectData[11]=0x30;
- if (!ModeSelect(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeSelectData,12,m_hDriveEvent))
- {
- Error=CDASPIError;
- return;
- }
- break;
- }
- case CDTYPE_TOSHNEW :
- {
- memset(&ModeData,0,sizeof(ModeData));
- if (!ModeSense(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeData,15,0x20,m_hDriveEvent))
- {
- Error=CDASPIError;
- return;
- }
- ModeData[0]=0;
- TDriveMode ModeSelectData;
- ModeSelectData[0]=0x00;
- ModeSelectData[1]=0x00;
- ModeSelectData[2]=0x00;
- ModeSelectData[3]=0x08;
- ModeSelectData[4]=0x82;
- ModeSelectData[5]=0x00;
- ModeSelectData[6]=0x00;
- ModeSelectData[7]=0x00;
- ModeSelectData[8]=0x00;
- ModeSelectData[9]=0x00;
- ModeSelectData[10]=0x09;
- ModeSelectData[11]=0x30;
- ModeSelectData[12]=0x20;
- ModeSelectData[13]=0x01;
- ModeSelectData[14]=(ModeData[14] & 0xcf)|0x10;
- if (!ModeSelect(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeSelectData,15,m_hDriveEvent))
- {
- Error=CDASPIError;
- return;
- }
- break;
- }
- case CDTYPE_NEC :
- {
- memset(&ModeData,0,sizeof(ModeData));
- if (!addModeSense(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeData,12,m_hDriveEvent))
- {
- Error=CDASPIError;
- return;
- }
- NECRotationSpeed=ModeData[6] & 0x20;
- ModeData[6]=ModeData[6]|0x20;
- if (!addModeSelect(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeData,12,m_hDriveEvent))
- {
- Error=CDASPIError;
- return;
- }
- break;
- }
- case CDTYPE_PHILIPS :
- case CDTYPE_MATSHITA :
- {
- memset(&ModeData,0,sizeof(ModeData));
- if (!ModeSense(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeData,12,0,m_hDriveEvent))
- {
- Error=CDASPIError;
- return;
- }
- ModeData[0]=0;
- TDriveMode ModeSelectData;
- ModeSelectData[0]=0x00;
- ModeSelectData[1]=0x00;
- ModeSelectData[2]=0x00;
- ModeSelectData[3]=0x08;
- ModeSelectData[4]=0x00;
- ModeSelectData[5]=0x00;
- ModeSelectData[6]=0x00;
- ModeSelectData[7]=0x00;
- ModeSelectData[8]=0x00;
- ModeSelectData[9]=0x00;
- ModeSelectData[10]=0x09;
- ModeSelectData[11]=0x30;
- if (!ModeSelect(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeSelectData,12,m_hDriveEvent))
- {
- Error=CDASPIError;
- return;
- }
- break;
- }
- }
- }
- void CSCSICD::ReadCDDA(CCDAdress StartSektor,long Sektoranzahl,void *Buffer,BOOL bUseC2ErrorInfo)
- {
- TOpcode OpC;
- OpC[1]=0x00;
- OpC[2]=0x00;
- OpC[3]=LOBYTE(HIWORD(StartSektor.GetHSG()));
- OpC[4]=HIBYTE(LOWORD(StartSektor.GetHSG()));
- OpC[5]=LOBYTE(LOWORD(StartSektor.GetHSG()));
- OpC[6]=0x00;
- switch (MapInfo.GetTypMapping(Config.Type))
- {
- case CDTYPE_TOSHIBA :
- case CDTYPE_TOSHNEW :
- {
- OpC[0]=0x28;
- OpC[7]=HIBYTE(LOWORD(Sektoranzahl));
- OpC[8]=LOBYTE(LOWORD(Sektoranzahl));
- OpC[9]=0x00;
- FillSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,SRB_DIR_IN,OpC,10,Buffer,Sektoranzahl*2352,ReadSRB,m_hDriveEvent);
- break;
- }
- case CDTYPE_SONY :
- case CDTYPE_RICOH :
- case CDTYPE_PLEXTOR :
- {
- OpC[0]=0xD8;
- OpC[7]=0x00;
- OpC[8]=HIBYTE(LOWORD(Sektoranzahl));
- OpC[9]=LOBYTE(LOWORD(Sektoranzahl));
- // benski
- if (bUseC2ErrorInfo)
- OpC[10]=0x04;
- else
- OpC[10]=0x00;
- OpC[11]=0x00;
- FillSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,SRB_DIR_IN,OpC,12,Buffer,(bUseC2ErrorInfo)?(Sektoranzahl*2646):(Sektoranzahl*2352),ReadSRB,m_hDriveEvent);
- break;
- }
- case CDTYPE_NEC :
- {
- OpC[0]=0xD4;
- OpC[7]=HIBYTE(LOWORD(Sektoranzahl));
- OpC[8]=LOBYTE(LOWORD(Sektoranzahl));
- OpC[9]=0x00;
- FillSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,SRB_DIR_IN,OpC,10,Buffer,Sektoranzahl*2352,ReadSRB,m_hDriveEvent);
- break;
- }
- case CDTYPE_MATSHITA :
- {
- OpC[0]=0xD4;
- OpC[7]=0x00;
- OpC[8]=HIBYTE(LOWORD(Sektoranzahl));
- OpC[9]=LOBYTE(LOWORD(Sektoranzahl));
- OpC[10]=0x00;
- OpC[11]=0x00;
- FillSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,SRB_DIR_IN,OpC,12,Buffer,Sektoranzahl*2352,ReadSRB,m_hDriveEvent);
- break;
- }
- case CDTYPE_PHILIPS :
- {
- OpC[0]=0x28;
- OpC[7]=HIBYTE(LOWORD(Sektoranzahl));
- OpC[8]=LOBYTE(LOWORD(Sektoranzahl));
- OpC[9]=0x00;
- FillSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,SRB_DIR_IN,OpC,10,Buffer,Sektoranzahl*2352,ReadSRB,m_hDriveEvent);
- break;
- }
- case CDTYPE_ATAPI :
- case CDTYPE_CYBERDRV :
- {
- OpC[0]=0xBE;
- OpC[1]=0x04;
- OpC[7]=HIBYTE(LOWORD(Sektoranzahl));
- OpC[8]=LOBYTE(LOWORD(Sektoranzahl));
- OpC[9]=0xF0;
- // benski
- if (bUseC2ErrorInfo)
- OpC[9]|=2; // flag 2 is supposed to mean check for C2 error info
- OpC[10]=0x00;
- OpC[11]=0x00;
- // with C2 error info, our sector size is now 2646 bytes
- FillSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,SRB_DIR_IN,OpC,12,Buffer,bUseC2ErrorInfo?(Sektoranzahl*2646):(Sektoranzahl*2352),ReadSRB,m_hDriveEvent);
- break;
- }
- }
- ExecuteSCSIRequest(ReadSRB,m_hDriveEvent);
- StartReadTime=GetTickCount();
- }
- BOOL CSCSICD::WaitCDDA(BOOL bImmediate)
- {
- BYTE Status=WaitSCSIRequest(ReadSRB,m_hDriveEvent,bImmediate);
- if ((Status!=SS_PENDING) &&
- (Status!=SS_COMP))
- {
- memcpy(&m_SenseInfo,&ReadSRB.SenseArea,SENSE_LEN);
- Error=CDASPIError;
- }
- if ((Status==SS_PENDING) &&
- !bImmediate)
- {
- DWORD AktReadTime=GetTickCount();
- if (abs((long long)AktReadTime-StartReadTime)>12000)
- {
- AbortSCSIRequest(ReadSRB);
- Error=CDTimeOut;
- Status=SS_COMP;
- }
- }
- return (Status!=SS_PENDING);
- }
- void CSCSICD::FinishCDDA()
- {
- switch (MapInfo.GetTypMapping(Config.Type))
- {
- case CDTYPE_TOSHIBA :
- {
- if (!ModeSelect(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeData,12,m_hDriveEvent))
- {
- Error=CDASPIError;
- return;
- }
- break;
- }
- case CDTYPE_TOSHNEW :
- {
- if (!ModeSelect(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeData,15,m_hDriveEvent))
- {
- Error=CDASPIError;
- return;
- }
- break;
- }
- case CDTYPE_NEC :
- {
- ModeData[6]=ModeData[6]|NECRotationSpeed;
- if (!addModeSelect(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeData,12,m_hDriveEvent))
- {
- Error=CDASPIError;
- return;
- }
- break;
- }
- case CDTYPE_PHILIPS :
- case CDTYPE_MATSHITA :
- {
- if (!ModeSelect(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeData,12,m_hDriveEvent))
- {
- Error=CDASPIError;
- return;
- }
- break;
- }
- }
- }
- void CSCSICD::SortWaveData(DWORD *Data,int Samples)
- {
- switch (MapInfo.GetTypMapping(Config.Type))
- {
- case CDTYPE_PHILIPS :
- // RICOH Drives doesn't seem to swap the bytes
- // This has been evaluated with the CD-RW drives
- // So they are even just handled like SONY drives, but i don't remove this type
- // case CDTYPE_RICOH :
- {
- for (int i=0; i<Samples; i++)
- Data[i]=((Data[i]&0xff00ff00)>>8)|
- ((Data[i]&0x00ff00ff)<<8);
- break;
- }
- }
- }
- CCDAdress CSCSICD::GetErrorAdress()
- {
- CCDAdress h;
- h.SetHSG(0);
- if ((Error!=CDOK)&&
- (ReadSRB.SRB_TargStat==STATUS_CHKCOND))
- h.SetHSG((ReadSRB.SenseArea[3]<<24)+
- (ReadSRB.SenseArea[4]<<16)+
- (ReadSRB.SenseArea[5]<<8)+
- ReadSRB.SenseArea[6]);
- return h;
- }
- void CSCSICD::Play_Audio(CCDAdress StartSektor,long Sektoranzahl)
- {
- while (!TestUnitReady(Config.HostAdapterNumber,Config.ID,Config.LUN,m_hDriveEvent));
- TOpcode OpC;
- OpC[0]=0x45;
- OpC[1]=0x00;
- OpC[2]=HIBYTE(HIWORD(StartSektor.GetHSG()));
- OpC[3]=LOBYTE(HIWORD(StartSektor.GetHSG()));
- OpC[4]=HIBYTE(LOWORD(StartSektor.GetHSG()));
- OpC[5]=LOBYTE(LOWORD(StartSektor.GetHSG()));
- OpC[6]=0x00;
- OpC[7]=HIBYTE(LOWORD(Sektoranzahl));
- OpC[8]=LOBYTE(LOWORD(Sektoranzahl));
- OpC[9]=0x00;
- if (!ExecuteSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,0,OpC,10,NULL,0,m_hDriveEvent))
- Error=CDDriveNotReady;
- }
- void CSCSICD::Stop_Audio()
- {
- while (!TestUnitReady(Config.HostAdapterNumber,Config.ID,Config.LUN,m_hDriveEvent));
- TOpcode OpC;
- /* OpC[0]=0x1b;
- OpC[1]=0x00;
- OpC[2]=0x00;
- OpC[3]=0x00;
- OpC[4]=0x00;
- OpC[5]=0x00;
- */
- OpC[0]=0x2b;
- OpC[1]=0x00;
- OpC[2]=0x00;
- OpC[3]=0x00;
- OpC[4]=0x00;
- OpC[5]=0x00;
- OpC[6]=0x00;
- OpC[7]=0x00;
- OpC[8]=0x00;
- OpC[9]=0x00;
- if (!ExecuteSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,0,OpC,10,NULL,0,m_hDriveEvent))
- Error=CDDriveNotReady;
- }
- void CSCSICD::Pause_Audio()
- {
- while (!TestUnitReady(Config.HostAdapterNumber,Config.ID,Config.LUN,m_hDriveEvent));
- TOpcode OpC;
- OpC[0]=0x4b;
- OpC[1]=0x00;
- OpC[2]=0x00;
- OpC[3]=0x00;
- OpC[4]=0x00;
- OpC[5]=0x00;
- OpC[6]=0x00;
- OpC[7]=0x00;
- OpC[8]=0x00;
- OpC[9]=0x00;
- if (!ExecuteSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,0,OpC,10,NULL,0,m_hDriveEvent))
- Error=CDDriveNotReady;
- }
- void CSCSICD::Resume_Audio()
- {
- while (!TestUnitReady(Config.HostAdapterNumber,Config.ID,Config.LUN,m_hDriveEvent));
- TOpcode OpC;
- OpC[0]=0x4b;
- OpC[1]=0x00;
- OpC[2]=0x00;
- OpC[3]=0x00;
- OpC[4]=0x00;
- OpC[5]=0x00;
- OpC[6]=0x00;
- OpC[7]=0x00;
- OpC[8]=0x01;
- OpC[9]=0x00;
- if (!ExecuteSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,0,OpC,10,NULL,0,m_hDriveEvent))
- Error=CDDriveNotReady;
- }
- TDriveStatus CSCSICD::Get_DriveStatus()
- {
- TDriveStatus h = {0};
- /* TOpcode OpC;
- TQChannelInfo ChannelInfo;
- BOOL b;
- memset(&ChannelInfo,0,sizeof(ChannelInfo));
- OpC[0]=0x42;
- OpC[1]=0x02;
- OpC[2]=0x40;
- OpC[3]=0x01;
- OpC[4]=0x00;
- OpC[5]=0x00;
- OpC[6]=0x00;
- OpC[7]=0x00;
- OpC[8]=sizeof(ChannelInfo);
- OpC[9]=0x00;
- if (MapInfo.GetTypMapping(Config.Type)==CDTYPE_ATAPI)
- {
- OpC[10]=0;
- OpC[11]=0;
- b=ExecuteSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,0,OpC,12,(void *)&ChannelInfo,sizeof(ChannelInfo),m_hDriveEvent);
- }
- else
- b=ExecuteSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,0,OpC,10,(void *)&ChannelInfo,sizeof(ChannelInfo),m_hDriveEvent);
- if (b && ChannelInfo.DataLen)
- */
- if (TestUnitReady(Config.HostAdapterNumber,Config.ID,Config.LUN,m_hDriveEvent))
- h.CDPresent=TRUE;
- else
- h.CDPresent=FALSE;
- if (h.CDPresent!=CDPresentLast) Changed=TRUE;
- CDPresentLast=h.CDPresent;
- return h;
- }
- BOOL CSCSICD::MediaChanged()
- {
- BOOL h;
- h=Changed;
- //if (CDPresentLast)
- Changed=FALSE;
- return h;
- }
- TAudioStatus CSCSICD::Get_AudioStatus_Info()
- {
- TAudioStatus h;
- TOpcode OpC;
- TQChannelInfo ChannelInfo;
- BOOL b;
- memset(&ChannelInfo,0,sizeof(ChannelInfo));
- OpC[0]=0x42;
- OpC[1]=0x02;
- OpC[2]=0x40;
- OpC[3]=0x01;
- OpC[4]=0x00;
- OpC[5]=0x00;
- OpC[6]=0x00;
- OpC[7]=0x00;
- OpC[8]=0x10;
- OpC[9]=0x00;
- h.Pause=FALSE;
- h.IsPlaying=FALSE;
- h.IsDone=FALSE;
- h.PlayError=FALSE;
- if (MapInfo.GetTypMapping(Config.Type)==CDTYPE_ATAPI)
- {
- OpC[10]=0;
- OpC[11]=0;
- b=ExecuteSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,SRB_DIR_IN,OpC,12,(void *)&ChannelInfo,16,m_hDriveEvent);
- }
- else
- b=ExecuteSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,SRB_DIR_IN,OpC,10,(void *)&ChannelInfo,16,m_hDriveEvent);
- if (b && ChannelInfo.DataLen)
- {
- // if (!CDPresentLast) Changed=TRUE;
- // CDPresentLast=TRUE;
- switch (ChannelInfo.AudioStatus)
- {
- case 0x11 : h.IsPlaying=TRUE; break;
- case 0x12 : h.Pause=TRUE; break;
- case 0x13 : h.IsDone=TRUE; break;
- case 0x14 : h.PlayError=TRUE; break;
- }
- h.AbsSektor.SetRedbook(ChannelInfo.AbsCDAdress);
- h.RelSektor.SetRedbook(ChannelInfo.RelTrackAdress);
- h.TrackNummer=ChannelInfo.TrackNumber;
- }
- else
- {
- // if (CDPresentLast) Changed=TRUE;
- // CDPresentLast=FALSE;
- h.PlayError=TRUE;
- Error=CDNoCD;
- }
- return h;
- }
- void CSCSICD::Get_MediaCatalogNumber(char szUPC[16])
- {
- TOpcode OpC;
- BYTE Info[24] = {0};
- BOOL b;
- szUPC[0]=0;
- OpC[0]=0x42;
- OpC[1]=0x02;
- OpC[2]=0x40;
- OpC[3]=0x02;
- OpC[4]=0x00;
- OpC[5]=0x00;
- OpC[6]=0x00;
- OpC[7]=0x00;
- OpC[8]=sizeof(Info);
- OpC[9]=0x00;
- if (MapInfo.GetTypMapping(Config.Type)==CDTYPE_ATAPI)
- {
- OpC[10]=0;
- OpC[11]=0;
- b=ExecuteSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,SRB_DIR_IN,OpC,12,(void *)&Info,sizeof(Info),m_hDriveEvent);
- }
- else
- b=ExecuteSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,SRB_DIR_IN,OpC,10,(void *)&Info,sizeof(Info),m_hDriveEvent);
- if (b && (Info[8]&0x80))
- {
- BOOL bIsEmpty=TRUE;
- for (int i=0; i<15; i++)
- {
- BYTE Value=Info[i+9];
- if (Value)
- bIsEmpty=FALSE;
- if (Value<10)
- Value+=0x30;
- szUPC[i]=Value;
- }
- szUPC[15]=0;
- if (bIsEmpty)
- szUPC[0]=0;
- }
- }
- void CSCSICD::EjectDisk()
- {
- TOpcode OpC;
- OpC[0]=0x1b;
- OpC[1]=0x00;
- OpC[2]=0x00;
- OpC[3]=0x00;
- OpC[4]=0x02;
- OpC[5]=0x00;
- if (!ExecuteSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,0,OpC,6,NULL,0,m_hDriveEvent))
- Error=CDDriveNotReady;
- }
- void CSCSICD::LockDoor(int Lock)
- {
- TOpcode OpC;
- OpC[0]=0x1e;
- OpC[1]=0x00;
- OpC[2]=0x00;
- OpC[3]=0x00;
- OpC[4]=((BYTE) Lock) & 1;
- OpC[5]=0x00;
- if (!ExecuteSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,0,OpC,6,NULL,0,m_hDriveEvent))
- Error=CDDriveNotReady;
- }
- void CSCSICD::CloseTray()
- {
- TOpcode OpC;
- OpC[0]=0x1b;
- OpC[1]=0x00;
- OpC[2]=0x00;
- OpC[3]=0x00;
- OpC[4]=0x03;
- OpC[5]=0x00;
- if (!ExecuteSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,0,OpC,6,NULL,0,m_hDriveEvent))
- Error=CDDriveNotReady;
- }
- int Swap(int value)
- {
- int result=(value & 0xff000000)>>24;
- result|=(value & 0x00ff0000)>>8;
- result|=(value & 0x0000ff00)<<8;
- result|=(value & 0x000000ff)<<24;
- return result;
- }
- void CSCSICD::ReRead()
- {
- DeleteTrackList();
- m_bSpeedTableInitialized=FALSE;
- TTOCHeader TOCHeader;
- memset(&TOCHeader,0,sizeof(TOCHeader));
- TOpcode OpC;
- OpC[0]=0x43;
- OpC[1]=0;
- OpC[2]=0;
- OpC[3]=0;
- OpC[4]=0;
- OpC[5]=0;
- OpC[6]=0;
- OpC[7]=HIBYTE(sizeof(TTOCHeader));
- OpC[8]=LOBYTE(sizeof(TTOCHeader));
- OpC[9]=0;
-
- BOOL r=ExecuteSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,SRB_DIR_IN,OpC,10,(void*)&TOCHeader,sizeof(TOCHeader),m_hDriveEvent);
- if (r && TOCHeader.FirstTrack && TOCHeader.LastTrack)
- {
- TTrackListeMem *Last;
- CCDAdress Ende;
- Last=FirstTrack;
- for (int i=TOCHeader.FirstTrack; i<=TOCHeader.LastTrack; i++)
- {
- AktTrack=new TTrackListeMem;
- //AbsCDAdress
- //AdrCtrl
- AktTrack->Info.TrackNummer=TOCHeader.Info[i-1].TrackNummer;
- AktTrack->Info.StartSektor.SetHSG(Swap(TOCHeader.Info[i-1].AbsCDAdress)+150);
- Ende.SetHSG(Swap(TOCHeader.Info[i].AbsCDAdress)+150);
- AktTrack->Info.Laenge=Ende.GetHSG()-AktTrack->Info.StartSektor.GetHSG();
- AktTrack->Info.StartSektor.SetHSG(AktTrack->Info.StartSektor.GetHSG()-150);
- if (TOCHeader.Info[i-1].AdrCtrl & 8)
- AktTrack->Info.Flags.AudioChannels=4;
- else
- AktTrack->Info.Flags.AudioChannels=2;
- AktTrack->Info.Flags.PreEmphasis=(TOCHeader.Info[i-1].AdrCtrl & 1);
- AktTrack->Info.Flags.DataTrack=(TOCHeader.Info[i-1].AdrCtrl & 4);
- AktTrack->Info.Flags.CopyProhibeted=!(TOCHeader.Info[i-1].AdrCtrl & 2);
- AktTrack->Prev=Last;
- AktTrack->Next=0;
- if (FirstTrack)
- Last->Next=AktTrack;
- else
- FirstTrack=AktTrack;
- Last=AktTrack;
- }
- // check for CD-Extra
- if (AktTrack)
- {
- if (AktTrack->Info.Flags.DataTrack)
- {
- Last=AktTrack->Prev;
- if (Last && !Last->Info.Flags.DataTrack)
- {
- if (Last->Info.Laenge>11400)
- Last->Info.Laenge-=11400;
- }
- }
- }
- }
- else
- {
- if (CDPresentLast) Changed=TRUE;
- CDPresentLast=FALSE;
- Error=CDDriveNotReady;
- }
- }
- CCDAdress CSCSICD::GetLastReadableAddress(CCDAdress StartSektor)
- {
- CCDAdress LastSektor;
- BYTE RetVal[8] = {0};
- TOpcode OpC;
- OpC[0]=0x25;
- OpC[1]=0;
- OpC[2]=HIBYTE(HIWORD(StartSektor.GetHSG()));
- OpC[3]=LOBYTE(HIWORD(StartSektor.GetHSG()));
- OpC[4]=HIBYTE(LOWORD(StartSektor.GetHSG()));
- OpC[5]=LOBYTE(LOWORD(StartSektor.GetHSG()));
- OpC[6]=0;
- OpC[7]=0;
- OpC[8]=1; //Set PMI Bit
- OpC[9]=0;
-
- BOOL r=ExecuteSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,SRB_DIR_IN,OpC,10,(void*)&RetVal,sizeof(RetVal),m_hDriveEvent);
- if (!r)
- return StartSektor;
- LastSektor.SetHSG((RetVal[0]<<24)+(RetVal[1]<<16)+(RetVal[2]<<8)+RetVal[3]);
- return LastSektor;
- }
- int CSCSICD::GetMaxSektors()
- {
- return Config.MaxSektors;
- };
- int CSCSICD::GetSynchSektors()
- {
- return Config.SynchSektors;
- };
- int CSCSICD::GetMode()
- {
- return Config.Mode;
- };
- int CSCSICD::GetSpeed()
- {
- return Config.Speed;
- };
- TSenseInfo CSCSICD::GetSense()
- {
- TSenseInfo SenseInfo;
- memset(&SenseInfo,0,sizeof(SenseInfo));
- TOpcode OpC;
- OpC[0]=0x03;
- OpC[1]=0;
- OpC[2]=0;
- OpC[3]=0;
- OpC[4]=sizeof(SenseInfo);
- OpC[5]=0;
-
- BOOL r=ExecuteSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,SRB_DIR_IN,OpC,6,(void*)&SenseInfo,sizeof(SenseInfo),m_hDriveEvent);
- if (!r)
- memset(&SenseInfo,0,sizeof(SenseInfo));
- return SenseInfo;
- }
- TSenseInfo CSCSICD::GetLastSenseInfo()
- {
- TSenseInfo Info=m_SenseInfo;
- memset(&m_SenseInfo,0,sizeof(TSenseInfo));
- return Info;
- }
- void CSCSICD::InitSpeedTable()
- {
- if (m_bSpeedTableInitialized)
- return;
- SupportedSpeeds=0;
- switch (MapInfo.GetTypMapping(Config.Type))
- {
- case CDTYPE_TOSHIBA :
- break;
- case CDTYPE_TOSHNEW :
- {
- SpeedTable[0]=2352*75;
- SpeedTable[1]=2352*75*4;
- SpeedTable[2]=2352*75*4;
- SpeedTable[3]=-2;
- SupportedSpeeds=4;
- break;
- }
- case CDTYPE_SONY :
- case CDTYPE_RICOH :
- case CDTYPE_ATAPI :
- case CDTYPE_CYBERDRV :
- {
- int LastSpeed=GetCurrentSpeed();
- int Speed=65532000;
- BOOL bFound=FALSE;
- while (!bFound && (Speed>0))
- {
- SetCurrentSpeed(Speed);
- if (Lasterror()==CDOK)
- {
- int ResultingSpeed=GetCurrentSpeed();
- if (Lasterror()==CDOK)
- {
- bFound=FALSE;
- for (int i=0; i<SupportedSpeeds; i++)
- {
- if (SpeedTable[i]==ResultingSpeed)
- bFound=TRUE;
- }
- if (!bFound)
- {
- SpeedTable[SupportedSpeeds]=ResultingSpeed;
- SupportedSpeeds++;
- Speed=ResultingSpeed-2352*75;
- }
- else
- {
- Speed-=(2352*75);
- bFound=FALSE;
- }
- }
- }
- else
- Speed=0;
- }
- if (SupportedSpeeds>1)
- {
- //Swap entries
- for (int i=0; i<(SupportedSpeeds/2); i++)
- {
- int Help=SpeedTable[i];
- SpeedTable[i]=SpeedTable[SupportedSpeeds-1-i];
- SpeedTable[SupportedSpeeds-1-i]=Help;
- }
- }
- SetCurrentSpeed(LastSpeed);
- break;
- }
- case CDTYPE_PLEXTOR :
- {
- int LastSpeed=GetCurrentSpeed();
- for (int index=1; index<=20; index++)
- {
- SetCurrentSpeed(index*2352*75);
- if (Lasterror()==CDOK)
- {
- int Speed=GetCurrentSpeed();
- if (Lasterror()==CDOK)
- {
- BOOL found=FALSE;
- for (int i=0; i<SupportedSpeeds; i++)
- {
- if (SpeedTable[i]==Speed)
- found=TRUE;
- }
- if (!found)
- {
- SpeedTable[SupportedSpeeds]=Speed;
- SupportedSpeeds++;
- }
- }
- }
- }
- SetCurrentSpeed(LastSpeed);
- break;
- }
- case CDTYPE_NEC :
- {
- break;
- }
- case CDTYPE_PHILIPS :
- case CDTYPE_MATSHITA :
- {
- int LastSpeed=GetCurrentSpeed();
- SpeedTable[0]=-1;
- SupportedSpeeds++;
- for (int index=1; index<8; index++)
- {
- SetCurrentSpeed(2352*75*index);
- if (Lasterror()==CDOK)
- {
- int Speed=GetCurrentSpeed();
- if ((Lasterror()==CDOK) &&
- (Speed==2352*75*index))
- {
- SpeedTable[SupportedSpeeds]=2352*75*index;
- SupportedSpeeds++;
- }
- }
- }
- SetCurrentSpeed(LastSpeed);
- break;
- }
- }
- m_bSpeedTableInitialized=TRUE;
- }
- BYTE CSCSICD::GetSupportedSpeeds()
- {
- return SupportedSpeeds;
- }
- BOOL IsOldPhilips(TDriveInfo *pConfig)
- {
- BOOL bResult=FALSE;
- if (strstr(pConfig->ProductID,"2000"))
- bResult=TRUE;
- if (strstr(pConfig->ProductID,"4020"))
- bResult=TRUE;
- return bResult;
- }
- //return the identifictaion number for the plextor models
- //defined values:
- #define PX4X 0
- #define PX6X 1
- #define PX8X 2
- #define PX12X 3
- #define PX20X 4
- #define PX32X 5
- #define PXR412 6
- #define PX40X 7
- DWORD GetPlextorModel(TDriveInfo *pConfig)
- {
- DWORD dwResult=PX40X;
- char szId[7] = {0};
- strncpy(szId,&pConfig->ProductID[10],6);
- szId[6]=0;
- if (!_stricmp(szId,"W4220T"))
- {
- dwResult=PXR412;
- }
- else
- {
- if (!_stricmp(szId,"W8220T"))
- {
- dwResult=PXR412;
- }
- else
- {
- szId[5]=0;
- if (!_stricmp(szId,"R412C"))
- {
- dwResult=PXR412;
- }
- else
- {
- if (!_stricmp(szId,"R820T"))
- {
- dwResult=PXR412;
- }
- else
- {
- szId[2]=0;
- if (!strcmp(szId,"40"))
- dwResult=PX40X;
- else
- {
- if (!strcmp(szId,"32"))
- dwResult=PX32X;
- else
- {
- if (!strcmp(szId,"20"))
- dwResult=PX20X;
- else
- {
- if (!strcmp(szId,"12"))
- dwResult=PX12X;
- else
- {
- if (!isdigit(szId[1]))
- szId[1]=0;
- if (!strcmp(szId,"8"))
- dwResult=PX8X;
- else
- {
- if (!strcmp(szId,"6"))
- dwResult=PX6X;
- else
- {
- if (!strcmp(szId,"4"))
- dwResult=PX4X;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return dwResult;
- }
- int CSCSICD::GetCurrentSpeed()
- {
- TDriveMode ModeSenseData;
- int Speed=0;
- switch (MapInfo.GetTypMapping(Config.Type))
- {
- case CDTYPE_TOSHIBA :
- {
- Speed=0;
- break;
- }
- case CDTYPE_TOSHNEW :
- {
- if (!ModeSense(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeSenseData,15,0x20,m_hDriveEvent))
- {
- Error=CDASPIError;
- return 0;
- }
- int Index=(ModeSenseData[14] & 0x30)>>4;
- switch (Index)
- {
- case 0 :
- Speed=2352*75;
- break;
- case 1 :
- Speed=2352*75*4;
- break;
- case 2 :
- Speed=2352*75*4;
- break;
- case 3 :
- Speed=-2;
- break;
- }
- break;
- }
- case CDTYPE_SONY :
- case CDTYPE_RICOH :
- case CDTYPE_CYBERDRV :
- {
- if (!ModeSense(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeSenseData,34,0x2A,m_hDriveEvent))
- {
- Error=CDASPIError;
- return 0;
- }
- Speed=(ModeSenseData[26]*256+ModeSenseData[27])*1000;
- break;
- }
- case CDTYPE_ATAPI :
- {
- if (!ATAPIModeSense(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeSenseData,34,0x2A,m_hDriveEvent))
- {
- Error=CDASPIError;
- return 0;
- }
- if ((ModeSenseData[8]&0x3F)==0x2A)
- Speed=(ModeSenseData[22]*256+ModeSenseData[23])*1000;
- else if ((ModeSenseData[4]&0x3F)==0x2A)
- Speed=(ModeSenseData[18]*256+ModeSenseData[19])*1000;
- else Speed=-1;
- break;
- }
- case CDTYPE_PLEXTOR :
- {
- DWORD dwModel=GetPlextorModel(&Config);
- if (dwModel!=PXR412)
- {
- if (!ModeSense(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeSenseData,16,0x31,m_hDriveEvent))
- {
- Error=CDASPIError;
- return 0;
- }
- int Index=ModeSenseData[14];
- switch (dwModel)
- {
- case PX4X :
- {
- switch (Index)
- {
- case 0 :
- Speed=2352*75;
- break;
- case 1 :
- Speed=2352*75*2;
- break;
- case 2 :
- Speed=2352*75*4;
- break;
- default :
- Speed=-1;
- break;
- }
- break;
- }
- case PX6X :
- {
- switch (Index)
- {
- case 0 :
- Speed=2352*75;
- break;
- case 1 :
- Speed=2352*75*4;
- break;
- case 2 :
- Speed=2352*75*6;
- break;
- default :
- Speed=-1;
- break;
- }
- break;
- }
- case PX8X :
- {
- switch (Index)
- {
- case 0 :
- Speed=2352*75;
- break;
- case 1 :
- Speed=2352*75*2;
- break;
- case 2 :
- Speed=2352*75*4;
- break;
- case 3 :
- Speed=2352*75*8;
- break;
- default :
- Speed=-1;
- break;
- }
- break;
- }
- case PX12X :
- {
- switch (Index)
- {
- case 0 :
- Speed=2352*75;
- break;
- case 1 :
- Speed=2352*75*2;
- break;
- case 2 :
- Speed=2352*75*4;
- break;
- case 3 :
- Speed=2352*75*8;
- break;
- case 4 :
- Speed=2352*75*8;
- break;
- case 5 :
- Speed=2352*75*12;
- break;
- default :
- Speed=-1;
- break;
- }
- break;
- }
- case PX20X :
- {
- switch (Index)
- {
- case 0 :
- Speed=2352*75;
- break;
- case 1 :
- Speed=2352*75*2;
- break;
- case 2 :
- Speed=2352*75*4;
- break;
- case 3 :
- Speed=2352*75*8;
- break;
- case 4 :
- Speed=2352*75*8;
- break;
- case 5 :
- Speed=-2;
- break;
- case 6 :
- Speed=2352*75*12;
- break;
- default :
- Speed=-1;
- break;
- }
- break;
- }
- case PX32X :
- {
- switch (Index)
- {
- case 0 :
- Speed=2352*75;
- break;
- case 1 :
- Speed=2352*75*2;
- break;
- case 2 :
- Speed=2352*75*4;
- break;
- case 3 :
- Speed=2352*75*8;
- break;
- case 4 :
- Speed=2352*75*8;
- break;
- case 5 :
- Speed=2352*75*8;
- break;
- case 6 :
- Speed=2352*75*14;
- break;
- default :
- Speed=-1;
- break;
- }
- break;
- }
- case PX40X :
- {
- switch (Index)
- {
- case 0 :
- Speed=2352*75;
- break;
- case 1 :
- Speed=2352*75*2;
- break;
- case 2 :
- Speed=2352*75*4;
- break;
- case 3 :
- Speed=2352*75*8;
- break;
- case 4 :
- Speed=2352*75*8;
- break;
- case 5 :
- Speed=2352*75*10;
- break;
- case 6 :
- Speed=2352*75*17;
- break;
- default :
- Speed=-1;
- break;
- }
- break;
- }
- }
- }
- else
- {
- if (!ModeSense(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeSenseData,32,0x2A,m_hDriveEvent))
- {
- Error=CDASPIError;
- return 0;
- }
- Speed=(ModeSenseData[26]*256+ModeSenseData[27])*1000;
- }
- break;
- }
- case CDTYPE_NEC :
- {
- if (!addModeSense(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeSenseData,12,m_hDriveEvent))
- {
- Error=CDASPIError;
- return 0;
- }
- // Speed=ModeSenseData[6] & 0x20;
- break;
- }
- case CDTYPE_PHILIPS :
- case CDTYPE_MATSHITA :
- {
- if (!ModeSense(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeSenseData,20,0x23,m_hDriveEvent))
- {
- Error=CDASPIError;
- return 0;
- }
- int Index;
- if (IsOldPhilips(&Config))
- Index=ModeSenseData[14];
- else
- Index=ModeSenseData[16];
- switch (Index)
- {
- case 0 :
- Speed=-1;
- break;
- case 1 :
- Speed=2352*75;
- break;
- case 2 :
- Speed=2352*75*2;
- break;
- case 4 :
- Speed=2352*75*4;
- break;
- case 6 :
- Speed=2352*75*6;
- break;
- case 8 :
- Speed=2352*75*8;
- break;
- default :
- Speed=-2;
- }
- break;
- }
- default :
- Speed=0;
- }
- return Speed;
- }
- void CSCSICD::SetCurrentSpeed(int Speed)
- {
- TDriveMode ModeSenseData;
- if (Speed==0)
- return;
- switch (MapInfo.GetTypMapping(Config.Type))
- {
- case CDTYPE_TOSHIBA :
- break;
- case CDTYPE_TOSHNEW :
- {
- if (!ModeSense(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeSenseData,15,0x20,m_hDriveEvent))
- {
- Error=CDASPIError;
- return;
- }
- ModeSenseData[0]=0;
- int Index;
- switch (Speed)
- {
- case -2 :
- Index=3;
- break;
- case 2352*75 :
- Index=0;
- break;
- case 2352*75*4 :
- Index=1;
- break;
- default :
- Index=2;
- }
- ModeSenseData[14]=(ModeSenseData[14] & 0xcf)|(Index<<4);
- if (!ModeSelect(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeSenseData,15,m_hDriveEvent))
- Error=CDASPIError;
- break;
- }
- case CDTYPE_SONY :
- case CDTYPE_RICOH :
- case CDTYPE_CYBERDRV :
- case CDTYPE_ATAPI :
- {
- TOpcode OpC;
- OpC[0]=0xbb;
- OpC[1]=0x00;
- OpC[4]=0x00;
- OpC[5]=0x00;
- OpC[6]=0x00;
- OpC[7]=0x00;
- OpC[8]=0x00;
- OpC[9]=0x00;
- OpC[10]=0x00;
- OpC[11]=0x00;
- int NewSpeed=Speed/1000;
- int ModSpeed=NewSpeed*1000;
- int Direction=0;
- int AktSpeed=0;
- int Counter=0;
- do
- {
- Error=CDOK;
- Counter++;
- NewSpeed+=Direction;
- OpC[2]=NewSpeed/256;
- OpC[3]=NewSpeed%256;
- if (!ExecuteSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,SRB_DIR_OUT,OpC,12,NULL,0,m_hDriveEvent))
- Error=CDASPIError;
- // Is the speed really the one we have selected?
- AktSpeed=GetCurrentSpeed();
- if (!Direction)
- {
- if (AktSpeed<Speed)
- Direction=1;
- else if (AktSpeed>Speed)
- Direction=-1;
- }
- }
- while ((AktSpeed!=ModSpeed) && NewSpeed && (Counter<3));
- break;
- }
- case CDTYPE_PLEXTOR :
- {
- DWORD dwModel=GetPlextorModel(&Config);
- if (dwModel!=PXR412)
- {
- if (!ModeSense(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeSenseData,16,0x31,m_hDriveEvent))
- {
- Error=CDASPIError;
- return;
- }
- int Index;
- switch (dwModel)
- {
- case PX4X :
- {
- switch (Speed)
- {
- case 2352*75 :
- Index=0;
- break;
- case 2352*75*2 :
- Index=1;
- break;
- case -1 :
- case 2352*75*4 :
- Index=2;
- break;
- default :
- Index=-1;
- break;
- }
- break;
- }
- case PX6X :
- {
- switch (Speed)
- {
- case 2352*75 :
- Index=0;
- break;
- case 2352*75*4 :
- Index=1;
- break;
- case -1 :
- case 2352*75*6 :
- Index=2;
- break;
- default :
- Index=-1;
- break;
- }
- break;
- }
- case PX8X :
- {
- switch (Speed)
- {
- case 2352*75 :
- Index=0;
- break;
- case 2352*75*2 :
- Index=1;
- break;
- case 2352*75*4 :
- Index=2;
- break;
- case -1 :
- case 2352*75*8 :
- Index=3;
- break;
- default :
- Index=-1;
- break;
- }
- break;
- }
- case PX12X :
- {
- switch (Speed)
- {
- case 2352*75 :
- Index=0;
- break;
- case 2352*75*2 :
- Index=1;
- break;
- case 2352*75*4 :
- Index=2;
- break;
- case 2352*75*8 :
- Index=3;
- break;
- case -1 :
- case 2352*75*12 :
- Index=5;
- break;
- default :
- Index=-1;
- break;
- }
- break;
- }
- case PX20X :
- {
- switch (Speed)
- {
- case 2352*75 :
- Index=0;
- break;
- case 2352*75*2 :
- Index=1;
- break;
- case 2352*75*4 :
- Index=2;
- break;
- case 2352*75*8 :
- Index=3;
- break;
- case -1 :
- case 2352*75*12 :
- Index=6;
- break;
- default :
- Index=-1;
- break;
- }
- break;
- }
- case PX32X :
- {
- switch (Speed)
- {
- case 2352*75 :
- Index=0;
- break;
- case 2352*75*2 :
- Index=1;
- break;
- case 2352*75*4 :
- Index=2;
- break;
- case 2352*75*8 :
- Index=3;
- break;
- case -1 :
- case 2352*75*14 :
- Index=6;
- break;
- default :
- Index=-1;
- break;
- }
- break;
- }
- case PX40X :
- {
- switch (Speed)
- {
- case 2352*75 :
- Index=0;
- break;
- case 2352*75*2 :
- Index=1;
- break;
- case 2352*75*4 :
- Index=2;
- break;
- case 2352*75*8 :
- Index=3;
- break;
- case 2352*75*10 :
- Index=5;
- break;
- case -1 :
- case 2352*75*17 :
- Index=6;
- break;
- default :
- Index=-1;
- break;
- }
- break;
- }
- }
- if (Index>=0)
- {
- ModeSenseData[14]=Index;
- if (!ModeSelect(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeSenseData,16,m_hDriveEvent))
- Error=CDASPIError;
- }
- else
- Error=CDASPIError;
- }
- else
- {
- TOpcode OpC;
- OpC[0]=0xbb;
- OpC[1]=0x00;
- OpC[4]=0xff;
- OpC[5]=0xff;
- OpC[6]=0x00;
- OpC[7]=0x00;
- OpC[8]=0x00;
- OpC[9]=0x00;
- OpC[10]=0x00;
- OpC[11]=0x00;
- int NewSpeed=Speed/1000;
- int ModSpeed=NewSpeed*1000;
- int Direction=0;
- int AktSpeed=0;
- int Counter=0;
- do
- {
- Error=CDOK;
- Counter++;
- NewSpeed+=Direction;
- OpC[2]=NewSpeed/256;
- OpC[3]=NewSpeed%256;
- if (!ExecuteSCSIRequest(Config.HostAdapterNumber,Config.ID,Config.LUN,SRB_DIR_OUT,OpC,12,NULL,0,m_hDriveEvent))
- Error=CDASPIError;
- // Is the speed really the one we have selected?
- AktSpeed=GetCurrentSpeed();
- if (!Direction)
- {
- if (AktSpeed<Speed)
- Direction=1;
- else if (AktSpeed>Speed)
- Direction=-1;
- }
- }
- while ((AktSpeed!=ModSpeed) && NewSpeed && (Counter<3));
- }
- break;
- }
- case CDTYPE_NEC :
- {
- if (!addModeSense(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeSenseData,12,m_hDriveEvent))
- {
- Error=CDASPIError;
- return;
- }
- // Speed=ModeSenseData[6] & 0x20;
- if (!addModeSelect(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeSenseData,12,m_hDriveEvent))
- Error=CDASPIError;
- break;
- }
- case CDTYPE_PHILIPS :
- case CDTYPE_MATSHITA :
- {
- if (!ModeSense(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeSenseData,20,0x23,m_hDriveEvent))
- {
- Error=CDASPIError;
- return;
- }
- ModeSenseData[0]=0;
- int Index;
- switch (Speed)
- {
- case -2 :
- case -1 :
- Index=0;
- break;
- case 2352*75 :
- Index=1;
- break;
- case 2352*75*2 :
- Index=2;
- break;
- case 2352*75*4 :
- Index=4;
- break;
- case 2352*75*6 :
- Index=6;
- break;
- case 2352*75*8 :
- Index=8;
- break;
- default :
- Index=0;
- }
- if (IsOldPhilips(&Config))
- ModeSenseData[14]=Index;
- else
- ModeSenseData[16]=Index;
- if (!ModeSelect(Config.HostAdapterNumber,Config.ID,Config.LUN,ModeSenseData,20,m_hDriveEvent))
- Error=CDASPIError;
- break;
- }
- }
- }
- int CSCSICD::GetSpeed(BYTE Index)
- {
- if (Index<SupportedSpeeds)
- return SpeedTable[Index];
- return 0;
- }
- // ----------------------------------------------------------------------------------------
- // - Implementation of general functions -
- // - -
- // - Author: Christoph Schmelnik -
- // - Purposee: variour initialisations -
- // ----------------------------------------------------------------------------------------
- extern "C" DWORD NtScsiSendASPI32Command( LPSRB lpsrb );
- int LoadASPI2()
- {
- OSVERSIONINFO VersionInfo;
- VersionInfo.dwOSVersionInfoSize=sizeof(VersionInfo);
- GetVersionEx(&VersionInfo);
- if (VersionInfo.dwPlatformId==VER_PLATFORM_WIN32_NT)
- RunningNT=TRUE;
- else
- RunningNT=FALSE;
- ASPIInstalled=TRUE;
- hDLL=LoadLibrary(L"WNASPI32.DLL"); // load DLL
-
- if (hDLL==0)
- {
- if(RunningNT) {
- // ok, let's try to see if we can use NT's internal SCSI manager
- extern int NtScsiInit( void );
- int nb;
- if(nb=NtScsiInit()) {
- NumberOfHostAdapters=nb;
- SendASPI32Command=(SRBPROC)&NtScsiSendASPI32Command;
- return TRUE;
- }
- }
- ASPIInstalled=FALSE;
- return FALSE;
- }
- GetASPI32SupportInfo=(VOIDPROC)GetProcAddress(hDLL,"GetASPI32SupportInfo"); // get Address
- SendASPI32Command=(SRBPROC)GetProcAddress(hDLL,"SendASPI32Command"); // get Address
- if (GetASPI32SupportInfo==NULL)
- {
- ASPIInstalled=FALSE;
- return FALSE;
- }
- if (SendASPI32Command==NULL)
- {
- ASPIInstalled=FALSE;
- return FALSE;
- }
- int r=GetASPI32SupportInfo();
- if (HIBYTE(r)!=SS_COMP)
- {
- ASPIInstalled=FALSE;
- return FALSE;
- }
- NumberOfHostAdapters=LOBYTE(r);
- return TRUE;
- }
- int LoadASPI() {
- int ret=0;
- __try {
- ret=LoadASPI2();
- } __except(EXCEPTION_EXECUTE_HANDLER)
- {
- ret=0;
- }
- return ret;
- }
- int FreeASPI()
- {
- extern int NtScsiDeInit( void );
- NtScsiDeInit();
- if (hDLL) FreeLibrary(hDLL);
- hDLL=NULL;
- return TRUE;
- }
- int CheckASPI()
- {
- return ASPIInstalled;
- }
|