/[pcsx2_0.9.7]/trunk/plugins/CDVDpeops/Scsi.c
ViewVC logotype

Contents of /trunk/plugins/CDVDpeops/Scsi.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 11 months ago) by william
File MIME type: text/plain
File size: 30638 byte(s)
committing r3113 initial commit again...
1 /***************************************************************************
2 scsi.c - description
3 -------------------
4 begin : Sun Nov 16 2003
5 copyright : (C) 2003 by Pete Bernert
6 email : BlackDove@addcom.de
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. See also the license.txt file for *
15 * additional informations. *
16 * *
17 ***************************************************************************/
18
19 //*************************************************************************//
20 // History of changes:
21 //
22 // 2003/11/16 - Pete
23 // - generic cleanup for the Peops release
24 //
25 //*************************************************************************//
26
27 /////////////////////////////////////////////////////////
28
29 #include "stdafx.h"
30 #define _IN_SCSI
31 #include "externals.h"
32
33 /////////////////////////////////////////////////////////
34
35 SRB_ExecSCSICmd sx; // used with all (non-waiting) read funcs
36 BOOL bDoWaiting=FALSE; // flag for async reads
37
38 /////////////////////////////////////////////////////////
39 // returns device type
40
41 int GetSCSIDevice(int iA,int iT,int iL)
42 {
43 SRB_GDEVBlock s;DWORD dwStatus;
44
45 memset(&s,0,sizeof(SRB_GDEVBlock));
46 s.SRB_Cmd = SC_GET_DEV_TYPE;
47 s.SRB_HaID = iA;
48 s.SRB_Target = iT;
49 s.SRB_Lun = iL;
50
51 ResetEvent(hEvent);
52
53 dwStatus=pSendASPI32Command((LPSRB)&s);
54
55 if(dwStatus==SS_PENDING)
56 {WaitGenEvent(30000);dwStatus=s.SRB_Status;}
57
58 if(dwStatus==SS_COMP) return s.SRB_DeviceType;
59
60 return -1;
61 }
62
63 /////////////////////////////////////////////////////////
64
65 int GetSCSIStatus(int iA,int iT,int iL)
66 {
67 SRB_ExecSCSICmd s;DWORD dwStatus;
68 char ret[0x324];
69
70 memset(&s,0,sizeof(s));
71
72 s.SRB_Cmd = SC_EXEC_SCSI_CMD;
73 s.SRB_HaId = iCD_AD;
74 s.SRB_Target = iCD_TA;
75 s.SRB_Lun = iCD_LU;
76 s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
77 s.SRB_BufLen = 0x324;
78 s.SRB_BufPointer = (BYTE FAR *)ret;
79 s.SRB_SenseLen = 0x0E;
80 s.SRB_CDBLen = 0x0A;
81 s.SRB_PostProc = (LPVOID)hEvent;
82 s.CDBByte[0] = 0x00;
83
84 ResetEvent(hEvent);
85 dwStatus=pSendASPI32Command((LPSRB)&s);
86
87 if(dwStatus==SS_PENDING) WaitGenEvent(30000);
88
89 return s.SRB_Status;
90 }
91
92 /////////////////////////////////////////////////////////
93 // fills toc infos
94
95 DWORD GetSCSITOC(LPTOC toc)
96 {
97 SRB_ExecSCSICmd s;DWORD dwStatus;
98
99 memset(&s,0,sizeof(s));
100
101 s.SRB_Cmd = SC_EXEC_SCSI_CMD;
102 s.SRB_HaId = iCD_AD;
103 s.SRB_Target = iCD_TA;
104 s.SRB_Lun = iCD_LU;
105 s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
106 s.SRB_BufLen = 0x324;
107 s.SRB_BufPointer = (BYTE FAR *)toc;
108 s.SRB_SenseLen = 0x0E;
109 s.SRB_CDBLen = 0x0A;
110 s.SRB_PostProc = (LPVOID)hEvent;
111 s.CDBByte[0] = 0x43;
112 s.CDBByte[1] = 0x00; // 0x02 for MSF
113 s.CDBByte[7] = 0x03;
114 s.CDBByte[8] = 0x24;
115
116 ResetEvent(hEvent);
117 dwStatus=pSendASPI32Command((LPSRB)&s);
118
119 if(dwStatus==SS_PENDING) WaitGenEvent(30000);
120
121 if(s.SRB_Status!=SS_COMP) return SS_ERR;
122
123 return SS_COMP;
124 }
125
126 /////////////////////////////////////////////////////////
127 // enum all cd drives into 32k buffer, return num of drives
128
129 int GetSCSICDDrives(char * pDList)
130 {
131 int iCnt=0,iA,iT,iL;char * p=pDList;
132 SRB_HAInquiry si;SRB_GDEVBlock sd;
133 SRB_ExecSCSICmd s;int iNumA;char szBuf[100];
134 DWORD dw,dwStatus;
135
136 if(!pGetASPI32SupportInfo) return 0;
137
138 dw=pGetASPI32SupportInfo();
139
140 if(HIBYTE(LOWORD(dw))!=SS_COMP) return 0;
141 iNumA=(int)LOBYTE(LOWORD(dw));
142
143 for(iA=0;iA<iNumA;iA++)
144 {
145 memset(&si,0,sizeof(SRB_HAInquiry));
146 si.SRB_Cmd = SC_HA_INQUIRY;
147 si.SRB_HaId = iA;
148 pSendASPI32Command((LPSRB)&si);
149 if(si.SRB_Status!=SS_COMP) continue;
150 if(!si.HA_Unique[3]) si.HA_Unique[3]=8;
151 for(iT=0;iT<si.HA_Unique[3];iT++)
152 {
153 for(iL=0;iL<8;iL++)
154 {
155 memset(&sd,0,sizeof(SRB_GDEVBlock));
156 sd.SRB_Cmd = SC_GET_DEV_TYPE;
157 sd.SRB_HaID = iA;
158 sd.SRB_Target = iT;
159 sd.SRB_Lun = iL;
160
161 pSendASPI32Command((LPSRB)&sd);
162 if(sd.SRB_Status==SS_COMP &&
163 sd.SRB_DeviceType==DTYPE_CDROM)
164 {
165 memset(&s,0,sizeof(s));
166
167 s.SRB_Cmd = SC_EXEC_SCSI_CMD;
168 s.SRB_HaId = iA;
169 s.SRB_Target = iT;
170 s.SRB_Lun = iL;
171 s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
172 s.SRB_BufLen = 100;
173 s.SRB_BufPointer = szBuf;
174 s.SRB_SenseLen = SENSE_LEN;
175 s.SRB_CDBLen = 6;
176 s.SRB_PostProc = (LPVOID)hEvent;
177 s.CDBByte[0] = SCSI_INQUIRY;
178 s.CDBByte[4] = 100;
179 ResetEvent(hEvent);
180 dwStatus=pSendASPI32Command((LPSRB)&s);
181 if(dwStatus==SS_PENDING)
182 WaitGenEvent(WAITFOREVER);
183 if(s.SRB_Status==SS_COMP)
184 {
185 int i;
186 for(i=8 ;i<15;i++) if(szBuf[i]==' ') {szBuf[i]=0;break;}
187 szBuf[15]=0;
188 for(i=16;i<32;i++) if(szBuf[i]==' ') {szBuf[i]=0;break;}
189 szBuf[31]=0;
190 for(i=32;i<37;i++) if(szBuf[i]==' ') {szBuf[i]=0;break;}
191 szBuf[36]=0;
192 wsprintf(p,"[%d:%d:%d] %s %s V%s",
193 iA,iT,iL,&szBuf[8],&szBuf[16],&szBuf[32]);
194 iCnt++;
195 p+=strlen(p)+1;
196 }
197 }
198 }
199 }
200 }
201 return iCnt;
202 }
203
204 /////////////////////////////////////////////////////////
205 // play audio
206
207 DWORD PlaySCSIAudio(unsigned long start,unsigned long len)
208 {
209 SRB_ExecSCSICmd s;DWORD dwStatus;
210
211 memset(&s,0,sizeof(s));
212 s.SRB_Cmd = SC_EXEC_SCSI_CMD;
213 s.SRB_HaId = iCD_AD;
214 s.SRB_Target = iCD_TA;
215 s.SRB_Lun = iCD_LU;
216 s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
217 s.SRB_BufLen = 0;
218 s.SRB_BufPointer = 0;
219 s.SRB_SenseLen = SENSE_LEN;
220 s.SRB_CDBLen = 12;
221 s.SRB_PostProc = (LPVOID)hEvent;
222
223 if(start==0) // mmm... that stop doesn't seem to work on all drives... pfff
224 {
225 s.CDBByte[0] = 0x4b;
226 s.CDBByte[1] = (iCD_LU << 5) | 01;
227 s.CDBByte[2] = 0;
228 s.CDBByte[3] = 0;
229 s.CDBByte[4] = 0;
230 s.CDBByte[5] = 0;
231 s.CDBByte[6] = 0;
232 s.CDBByte[7] = 0;
233 s.CDBByte[8] = 0;
234 s.CDBByte[9] = 0;
235 }
236 else // start playing
237 {
238 s.CDBByte[0] = 0xa5;
239 s.CDBByte[1] = iCD_LU << 5;
240 s.CDBByte[2] = (unsigned char)((start >> 24) & 0xFF);
241 s.CDBByte[3] = (unsigned char)((start >> 16) & 0xFF);
242 s.CDBByte[4] = (unsigned char)((start >> 8) & 0xFF);
243 s.CDBByte[5] = (unsigned char)((start & 0xFF));
244 s.CDBByte[6] = (unsigned char)((len >> 24) & 0xFF);
245 s.CDBByte[7] = (unsigned char)((len >> 16) & 0xFF);
246 s.CDBByte[8] = (unsigned char)((len >> 8) & 0xFF);
247 s.CDBByte[9] = (unsigned char)(len & 0xFF);
248 }
249
250 ResetEvent(hEvent);
251
252 dwStatus = pSendASPI32Command((LPSRB)&s);
253
254 if(dwStatus==SS_PENDING) WaitGenEvent(10000);
255
256 return s.SRB_Status;
257 }
258
259 /////////////////////////////////////////////////////////
260 // do (unprecise) sub channel read on audio play
261
262 unsigned char * GetSCSIAudioSub(void)
263 {
264 SRB_ExecSCSICmd s;DWORD dwStatus;
265 unsigned char cB[20];
266
267 memset(cB,0,20);
268 memset(&s,0,sizeof(s));
269
270 s.SRB_Cmd = SC_EXEC_SCSI_CMD;
271 s.SRB_HaId = iCD_AD;
272 s.SRB_Target = iCD_TA;
273 s.SRB_Lun = iCD_LU;
274 s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
275 s.SRB_SenseLen = SENSE_LEN;
276
277 s.SRB_BufLen = 20;//44;
278 s.SRB_BufPointer = cB;
279 s.SRB_CDBLen = 10;
280
281 s.CDBByte[0] = 0x42;
282 s.CDBByte[1] = (iCD_LU<<5)|2; // lun & msf
283 s.CDBByte[2] = 0x40; // subq
284 s.CDBByte[3] = 0x01; // curr pos info
285 s.CDBByte[6] = 0; // track number (only in isrc mode, ignored)
286 s.CDBByte[7] = 0; // alloc len
287 s.CDBByte[8] = 20;//44;
288
289 ResetEvent(hEvent);
290
291 dwStatus = pSendASPI32Command((LPSRB)&s);
292
293 if(dwStatus==SS_PENDING) WaitGenEvent(WAITFOREVER);
294
295 if(s.SRB_Status!=SS_COMP) return NULL;
296
297 SubAData[12]=(cB[5]<<4)|(cB[5]>>4);
298 SubAData[13]=cB[6];
299 SubAData[14]=cB[7];
300 SubAData[15]=itob(cB[13]);
301 SubAData[16]=itob(cB[14]);
302 SubAData[17]=itob(cB[15]);
303 SubAData[18]=0;
304 SubAData[19]=itob(cB[9]);
305 SubAData[20]=itob(cB[10]);
306 SubAData[21]=itob(cB[11]);
307
308 return SubAData;
309 }
310
311 /////////////////////////////////////////////////////////
312 // test, if drive is ready (doesn't work on all drives)
313
314 BOOL TestSCSIUnitReady(void)
315 {
316 SRB_ExecSCSICmd s;DWORD dwStatus;
317
318 memset(&s,0,sizeof(s));
319 s.SRB_Cmd = SC_EXEC_SCSI_CMD;
320 s.SRB_HaId = iCD_AD;
321 s.SRB_Target = iCD_TA;
322 s.SRB_Lun = iCD_LU;
323 s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
324 s.SRB_BufLen = 0;
325 s.SRB_BufPointer = 0;
326 s.SRB_SenseLen = SENSE_LEN;
327 s.SRB_CDBLen = 6;
328 s.SRB_PostProc = (LPVOID)hEvent;
329 s.CDBByte[0] = 0x00;
330 s.CDBByte[1] = iCD_LU << 5;
331
332 ResetEvent(hEvent);
333 dwStatus = pSendASPI32Command((LPSRB)&s);
334
335 if(dwStatus==SS_PENDING)
336 WaitGenEvent(1000);
337
338 if(s.SRB_Status!=SS_COMP)
339 return FALSE;
340
341 if(s.SRB_TargStat==STATUS_GOOD) return TRUE; // will always be GOOD with ioctl, so no problem here
342
343 return FALSE;
344 }
345
346 /////////////////////////////////////////////////////////
347 // change the read speed (not supported on all drives)
348
349 DWORD SetSCSISpeed(DWORD dwSpeed)
350 {
351 SRB_ExecSCSICmd s;DWORD dwStatus;
352
353 memset(&s,0,sizeof(s));
354
355 s.SRB_Cmd = SC_EXEC_SCSI_CMD;
356 s.SRB_HaId = iCD_AD;
357 s.SRB_Target = iCD_TA;
358 s.SRB_Lun = iCD_LU;
359 s.SRB_Flags = SRB_DIR_OUT | SRB_EVENT_NOTIFY;
360 s.SRB_SenseLen = SENSE_LEN;
361 s.SRB_CDBLen = 12;
362 s.SRB_PostProc = (LPVOID)hEvent;
363 s.CDBByte[0] = 0xBB;
364 s.CDBByte[2] = (BYTE)(dwSpeed >> 8);
365 s.CDBByte[3] = (BYTE)dwSpeed;
366
367 ResetEvent(hEvent);
368 dwStatus=pSendASPI32Command((LPSRB)&s);
369
370 if(dwStatus==SS_PENDING)
371 WaitGenEvent(WAITFOREVER);
372
373 if(s.SRB_Status!=SS_COMP) return SS_ERR;
374
375 return SS_COMP;
376 }
377
378 /////////////////////////////////////////////////////////
379
380 /////////////////////////////////////////////////////////
381 // all the different SCSI read commands can be found here
382 // 'bWait' is a flag, if the command should wait until
383 // completed, or if the func can return as soon as possible
384 // (async reading). Attention: 'bWait' is not really used
385 // in the Sub-channel commands yet (sub is done always
386 // blocking, and just 'one sector' reads are done, caching=0)
387 /////////////////////////////////////////////////////////
388
389 /////////////////////////////////////////////////////////
390 // BE: used by most ATAPI drives
391 /////////////////////////////////////////////////////////
392
393 DWORD ReadSCSI_BE(BOOL bWait,FRAMEBUF * f)
394 {
395 DWORD dwStatus;
396
397 memset(&sx,0,sizeof(sx));
398
399 sx.SRB_Cmd = SC_EXEC_SCSI_CMD;
400 sx.SRB_HaId = iCD_AD;
401 sx.SRB_Target = iCD_TA;
402 sx.SRB_Lun = iCD_LU;
403 sx.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
404 sx.SRB_BufLen = f->dwBufLen;
405 sx.SRB_BufPointer = &(f->BufData[0]);
406 sx.SRB_SenseLen = SENSE_LEN;
407 sx.SRB_CDBLen = 12;
408 sx.SRB_PostProc = (LPVOID)hEvent;
409 sx.CDBByte[0] = 0xBE;
410 //s.CDBByte[1] = 0x04;
411 sx.CDBByte[2] = (unsigned char)((f->dwFrame >> 24) & 0xFF);
412 sx.CDBByte[3] = (unsigned char)((f->dwFrame >> 16) & 0xFF);
413 sx.CDBByte[4] = (unsigned char)((f->dwFrame >> 8) & 0xFF);
414 sx.CDBByte[5] = (unsigned char)(f->dwFrame & 0xFF);
415 sx.CDBByte[8] = (unsigned char)(f->dwFrameCnt & 0xFF);
416 sx.CDBByte[9] = (iRType==MODE_BE_1)?0x10:0xF8;//F0!!!!!!!!!!!
417
418 ResetEvent(hEvent);
419 dwStatus=pSendASPI32Command((LPSRB)&sx);
420
421 if(dwStatus==SS_PENDING)
422 {
423 if(bWait) WaitGenEvent(WAITFOREVER);
424 else
425 {
426 bDoWaiting=TRUE;
427 return SS_COMP;
428 }
429 }
430
431 if(sx.SRB_Status!=SS_COMP)
432 return SS_ERR;
433
434 return SS_COMP;
435 }
436
437 /////////////////////////////////////////////////////////
438
439 DWORD ReadSCSI_BE_Sub(BOOL bWait,FRAMEBUF * f)
440 {
441 DWORD dwStatus;
442
443 memset(&sx,0,sizeof(sx));
444 sx.SRB_Cmd = SC_EXEC_SCSI_CMD;
445 sx.SRB_HaId = iCD_AD;
446 sx.SRB_Target = iCD_TA;
447 sx.SRB_Lun = iCD_LU;
448 sx.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
449 sx.SRB_BufLen = f->dwBufLen + 16;
450 sx.SRB_BufPointer = &(f->BufData[0]);
451 sx.SRB_SenseLen = SENSE_LEN;
452 sx.SRB_CDBLen = 12;
453 sx.SRB_PostProc = (LPVOID)hEvent;
454 sx.CDBByte[0] = 0xBE;
455 //s.CDBByte[1] = 0x04;
456 sx.CDBByte[2] = (unsigned char)((f->dwFrame >> 24) & 0xFF);
457 sx.CDBByte[3] = (unsigned char)((f->dwFrame >> 16) & 0xFF);
458 sx.CDBByte[4] = (unsigned char)((f->dwFrame >> 8) & 0xFF);
459 sx.CDBByte[5] = (unsigned char)(f->dwFrame & 0xFF);
460 sx.CDBByte[8] = (unsigned char)(f->dwFrameCnt & 0xFF);
461 sx.CDBByte[9] = (iRType==MODE_BE_1)?0x10:0xF8;//F0!!!!!!!!!!!
462 sx.CDBByte[10] = 0x2;
463
464 ResetEvent(hEvent );
465 dwStatus=pSendASPI32Command((LPSRB)&sx);
466
467 if(dwStatus==SS_PENDING)
468 WaitGenEvent(WAITSUB);
469
470 if(sx.SRB_Status!=SS_COMP)
471 return SS_ERR;
472
473 memcpy(&SubCData[12],&f->BufData[2352],16);
474
475 SubCData[15]=itob(SubCData[15]);
476 SubCData[16]=itob(SubCData[16]);
477 SubCData[17]=itob(SubCData[17]);
478
479 SubCData[19]=itob(SubCData[19]);
480 SubCData[20]=itob(SubCData[20]);
481 SubCData[21]=itob(SubCData[21]);
482
483 return SS_COMP;
484 }
485
486 /////////////////////////////////////////////////////////
487 // different sub reading for lite-on ltd163d...
488 // 16 bytes subc data is encoded in 96 bytes...
489
490 DWORD ReadSCSI_BE_Sub_1(BOOL bWait,FRAMEBUF * f)
491 {
492 DWORD dwStatus;
493
494 memset(&sx,0,sizeof(sx));
495
496 sx.SRB_Cmd = SC_EXEC_SCSI_CMD;
497 sx.SRB_HaId = iCD_AD;
498 sx.SRB_Target = iCD_TA;
499 sx.SRB_Lun = iCD_LU;
500 sx.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
501 sx.SRB_BufLen = f->dwBufLen + 96;
502 sx.SRB_BufPointer = &(f->BufData[0]);
503 sx.SRB_SenseLen = SENSE_LEN;
504 sx.SRB_CDBLen = 12;
505 sx.SRB_PostProc = (LPVOID)hEvent;
506 sx.CDBByte[0] = 0xBE;
507 sx.CDBByte[2] = (unsigned char)((f->dwFrame >> 24) & 0xFF);
508 sx.CDBByte[3] = (unsigned char)((f->dwFrame >> 16) & 0xFF);
509 sx.CDBByte[4] = (unsigned char)((f->dwFrame >> 8) & 0xFF);
510 sx.CDBByte[5] = (unsigned char)(f->dwFrame & 0xFF);
511 sx.CDBByte[8] = (unsigned char)(f->dwFrameCnt & 0xFF);
512 sx.CDBByte[9] = 0xF8;
513 sx.CDBByte[10] = 0x1;
514
515 ResetEvent(hEvent);
516 dwStatus=pSendASPI32Command((LPSRB)&sx);
517
518 if(dwStatus==SS_PENDING)
519 WaitGenEvent(WAITSUB);
520
521 if(sx.SRB_Status!=SS_COMP)
522 return SS_ERR;
523
524 DecodeSub_BE_2_1(&f->BufData[2352]);
525
526 memcpy(&SubCData[12],&f->BufData[2352],16);
527
528 return SS_COMP;
529 }
530
531 /////////////////////////////////////////////////////////
532 // 28: used by most SCSI drives
533 /////////////////////////////////////////////////////////
534
535 DWORD InitSCSI_28_2(void)
536 {
537 SRB_ExecSCSICmd s;DWORD dwStatus;
538 int i;
539 BYTE init1[] = { 0, 0, 0, 0x08, 0, 0, 0, 0, 0, 0, 0x09, 0x30, 0x23, 6, 0, 0, 0, 0, 0, 0x80 };
540 BYTE init2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
541
542 for(i=0;i<2;i++)
543 {
544 memset( &s, 0, sizeof( s ) );
545 s.SRB_Cmd = SC_EXEC_SCSI_CMD;
546 s.SRB_HaId = iCD_AD;
547 s.SRB_Target = iCD_TA;
548 s.SRB_Lun = iCD_LU;
549 s.SRB_Flags = SRB_EVENT_NOTIFY;
550 s.SRB_BufLen = 0x14;
551 s.SRB_BufPointer = (i==0)?init1:init2;
552 s.SRB_SenseLen = SENSE_LEN;
553 s.SRB_CDBLen = 6;
554 s.SRB_PostProc = (LPVOID)hEvent;
555 s.CDBByte[0] = 0x15;
556 s.CDBByte[1] = 0x10;
557 s.CDBByte[4] = 0x14;
558
559 ResetEvent(hEvent);
560
561 dwStatus=pSendASPI32Command((LPSRB)&s);
562 if (dwStatus == SS_PENDING)
563 WaitGenEvent(WAITFOREVER);
564
565 if(s.SRB_Status!=SS_COMP)
566 return SS_ERR;
567 }
568
569 pDeInitFunc = DeInitSCSI_28;
570
571 return s.SRB_Status;
572 }
573
574 /////////////////////////////////////////////////////////
575
576 DWORD InitSCSI_28_1(void)
577 {
578 SRB_ExecSCSICmd s;DWORD dwStatus;
579 BYTE init1[] = { 0, 0, 0, 0x08, 0, 0, 0, 0, 0, 0, 0x09, 0x30 };
580
581 memset(&s,0,sizeof(s));
582 s.SRB_Cmd = SC_EXEC_SCSI_CMD;
583 s.SRB_HaId = iCD_AD;
584 s.SRB_Target = iCD_TA;
585 s.SRB_Lun = iCD_LU;
586 s.SRB_Flags = SRB_EVENT_NOTIFY;
587 s.SRB_BufLen = 0x0C;
588 s.SRB_BufPointer = init1;
589 s.SRB_SenseLen = SENSE_LEN;
590 s.SRB_CDBLen = 6;
591 s.SRB_PostProc = (LPVOID)hEvent;
592 s.CDBByte[0] = 0x15;
593 s.CDBByte[4] = 0x0C;
594
595 ResetEvent(hEvent);
596 dwStatus=pSendASPI32Command((LPSRB)&s);
597 if(dwStatus==SS_PENDING)
598 WaitGenEvent(WAITFOREVER);
599
600 if(s.SRB_Status!=SS_COMP)
601 return SS_ERR;
602
603 pDeInitFunc = DeInitSCSI_28;
604
605 return s.SRB_Status;
606 }
607
608 /////////////////////////////////////////////////////////
609
610 DWORD InitSCSI_28_2048(void)
611 {
612 SRB_ExecSCSICmd s;DWORD dwStatus;
613 BYTE init1[] = { 0, 0, 0, 0x08, 0, 0, 0, 0, 0, 0, 0x08, 0x0 };
614
615 pDeInitFunc = DeInitSCSI_28;
616
617 memset(&s,0,sizeof(s));
618 s.SRB_Cmd = SC_EXEC_SCSI_CMD;
619 s.SRB_HaId = iCD_AD;
620 s.SRB_Target = iCD_TA;
621 s.SRB_Lun = iCD_LU;
622 s.SRB_Flags = SRB_EVENT_NOTIFY;
623 s.SRB_BufLen = 0x0C;
624 s.SRB_BufPointer = init1;
625 s.SRB_SenseLen = SENSE_LEN;
626 s.SRB_CDBLen = 6;
627 s.SRB_PostProc = (LPVOID)hEvent;
628 s.CDBByte[0] = 0x15;
629 s.CDBByte[4] = 0x0C;
630
631 ResetEvent(hEvent);
632 dwStatus=pSendASPI32Command((LPSRB)&s);
633 if(dwStatus==SS_PENDING)
634 WaitGenEvent(WAITFOREVER);
635
636 if(s.SRB_Status!=SS_COMP)
637 return SS_ERR;
638
639 return s.SRB_Status;
640 }
641
642 /////////////////////////////////////////////////////////
643
644 DWORD DeInitSCSI_28(void)
645 {
646 SRB_ExecSCSICmd s;DWORD dwStatus;
647 BYTE init1[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
648
649 memset(&s,0,sizeof(s));
650 s.SRB_Cmd = SC_EXEC_SCSI_CMD;
651 s.SRB_HaId = iCD_AD;
652 s.SRB_Target = iCD_TA;
653 s.SRB_Lun = iCD_LU;
654 s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
655 s.SRB_BufLen = 0x0C;
656 s.SRB_BufPointer = init1;
657 s.SRB_SenseLen = SENSE_LEN;
658 s.SRB_CDBLen = 6;
659 s.SRB_PostProc = (LPVOID)hEvent;
660 s.CDBByte[0] = 0x15;
661 s.CDBByte[4] = 0x0C;
662
663 ResetEvent(hEvent);
664 dwStatus=pSendASPI32Command((LPSRB)&s);
665 if(dwStatus==SS_PENDING)
666 WaitGenEvent(WAITFOREVER);
667
668 if(s.SRB_Status!=SS_COMP)
669 return SS_ERR;
670
671 return s.SRB_Status;
672 }
673
674 /////////////////////////////////////////////////////////
675
676 DWORD ReadSCSI_28(BOOL bWait,FRAMEBUF * f)
677 {
678 DWORD dwStatus;
679
680 if(!pDeInitFunc)
681 {
682 if(iRType==MODE_28_2)
683 {
684 if(InitSCSI_28_2()!=SS_COMP) return SS_ERR;
685 }
686 else
687 {
688 if(InitSCSI_28_1()!=SS_COMP) return SS_ERR;
689 }
690 }
691
692 memset(&sx,0,sizeof(sx));
693 sx.SRB_Cmd = SC_EXEC_SCSI_CMD;
694 sx.SRB_HaId = iCD_AD;
695 sx.SRB_Target = iCD_TA;
696 sx.SRB_Lun = iCD_LU;
697 sx.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
698 sx.SRB_BufLen = f->dwBufLen;
699 sx.SRB_BufPointer = &(f->BufData[0]);
700 sx.SRB_SenseLen = SENSE_LEN;
701 sx.SRB_CDBLen = 10;
702 sx.SRB_PostProc = (LPVOID)hEvent;
703 sx.CDBByte[0] = 0x28; // read10 command
704 sx.CDBByte[1] = iCD_LU << 5;
705 sx.CDBByte[2] = (unsigned char)((f->dwFrame >> 24) & 0xFF);
706 sx.CDBByte[3] = (unsigned char)((f->dwFrame >> 16) & 0xFF);
707 sx.CDBByte[4] = (unsigned char)((f->dwFrame >> 8) & 0xFF);
708 sx.CDBByte[5] = (unsigned char)(f->dwFrame & 0xFF);
709 sx.CDBByte[8] = (unsigned char)(f->dwFrameCnt & 0xFF);
710
711 ResetEvent(hEvent);
712 dwStatus=pSendASPI32Command((LPSRB)&sx);
713 if(dwStatus==SS_PENDING)
714 {
715 if(bWait) WaitGenEvent(WAITFOREVER);
716 else
717 {
718 bDoWaiting=TRUE;
719 return SS_COMP;
720 }
721 }
722
723 if(sx.SRB_Status!=SS_COMP)
724 return SS_ERR;
725
726 return SS_COMP;
727 }
728
729 /////////////////////////////////////////////////////////
730 // DVD MODE
731
732 DWORD ReadSCSI_28_2048(BOOL bWait,FRAMEBUF * f)
733 {
734 DWORD dwStatus;
735
736 if(!pDeInitFunc)
737 {
738 InitSCSI_28_2048();
739
740 //if(InitSCSI_28_2048()!=SS_COMP) return SS_ERR;
741 }
742
743 memset(&sx,0,sizeof(sx));
744 sx.SRB_Cmd = SC_EXEC_SCSI_CMD;
745 sx.SRB_HaId = iCD_AD;
746 sx.SRB_Target = iCD_TA;
747 sx.SRB_Lun = iCD_LU;
748 sx.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
749 sx.SRB_BufLen = f->dwBufLen;
750 sx.SRB_BufPointer = &(f->BufData[0]);
751 sx.SRB_SenseLen = SENSE_LEN;
752 sx.SRB_CDBLen = 10;
753 sx.SRB_PostProc = (LPVOID)hEvent;
754 sx.CDBByte[0] = 0x28; // read10 command
755 sx.CDBByte[1] = iCD_LU << 5;
756 sx.CDBByte[2] = (unsigned char)((f->dwFrame >> 24) & 0xFF);
757 sx.CDBByte[3] = (unsigned char)((f->dwFrame >> 16) & 0xFF);
758 sx.CDBByte[4] = (unsigned char)((f->dwFrame >> 8) & 0xFF);
759 sx.CDBByte[5] = (unsigned char)(f->dwFrame & 0xFF);
760 sx.CDBByte[8] = (unsigned char)(f->dwFrameCnt & 0xFF);
761 sx.CDBByte[9] = 0xF8;
762
763 ResetEvent(hEvent);
764 dwStatus=pSendASPI32Command((LPSRB)&sx);
765 if(dwStatus==SS_PENDING)
766 {
767 if(bWait) WaitGenEvent(WAITFOREVER);
768 else
769 {
770 bDoWaiting=TRUE;
771 return SS_COMP;
772 }
773 }
774
775 if(sx.SRB_Status!=SS_COMP)
776 return SS_ERR;
777
778 return SS_COMP;
779 }
780
781 DWORD ReadSCSI_28_2048_Ex(BOOL bWait,FRAMEBUF * f)
782 {
783 DWORD dwStatus;
784
785 if(!pDeInitFunc)
786 {
787 InitSCSI_28_2048();
788
789 //if(InitSCSI_28_2048()!=SS_COMP) return SS_ERR;
790 }
791
792 memset(&sx,0,sizeof(sx));
793 sx.SRB_Cmd = SC_EXEC_SCSI_CMD;
794 sx.SRB_HaId = iCD_AD;
795 sx.SRB_Target = iCD_TA;
796 sx.SRB_Lun = iCD_LU;
797 sx.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
798 sx.SRB_BufLen = f->dwBufLen;
799 sx.SRB_BufPointer = &(f->BufData[0]);
800 sx.SRB_SenseLen = SENSE_LEN;
801 sx.SRB_CDBLen = 10;
802 sx.SRB_PostProc = (LPVOID)hEvent;
803 sx.CDBByte[0] = 0x28; // read10 command
804 sx.CDBByte[1] = iCD_LU << 5;
805 sx.CDBByte[2] = (unsigned char)((f->dwFrame >> 24) & 0xFF);
806 sx.CDBByte[3] = (unsigned char)((f->dwFrame >> 16) & 0xFF);
807 sx.CDBByte[4] = (unsigned char)((f->dwFrame >> 8) & 0xFF);
808 sx.CDBByte[5] = (unsigned char)(f->dwFrame & 0xFF);
809 sx.CDBByte[8] = (unsigned char)(f->dwFrameCnt & 0xFF);
810 // NO F8
811 //sx.CDBByte[9] = 0xF8;
812
813 ResetEvent(hEvent);
814 dwStatus=pSendASPI32Command((LPSRB)&sx);
815 if(dwStatus==SS_PENDING)
816 {
817 if(bWait) WaitGenEvent(WAITFOREVER);
818 else
819 {
820 bDoWaiting=TRUE;
821 return SS_COMP;
822 }
823 }
824
825 if(sx.SRB_Status!=SS_COMP)
826 return SS_ERR;
827
828 return SS_COMP;
829 }
830
831
832 /////////////////////////////////////////////////////////
833 // stupid subc reading on Teac 532S
834
835 char tbuf[2368];
836
837 DWORD ReadSCSI_28_Sub(BOOL bWait,FRAMEBUF * f)
838 {
839 DWORD dwStatus;
840
841 if(!pDeInitFunc)
842 {
843 if(iRType==MODE_28_2)
844 {
845 if(InitSCSI_28_2()!=SS_COMP) return SS_ERR;
846 }
847 else
848 {
849 if(InitSCSI_28_1()!=SS_COMP) return SS_ERR;
850 }
851 }
852
853 memset(&sx,0,sizeof(sx));
854 sx.SRB_Cmd = SC_EXEC_SCSI_CMD;
855 sx.SRB_HaId = iCD_AD;
856 sx.SRB_Target = iCD_TA;
857 sx.SRB_Lun = iCD_LU;
858 sx.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
859 sx.SRB_BufLen = f->dwBufLen;
860 sx.SRB_BufPointer = &(f->BufData[0]);
861 sx.SRB_SenseLen = SENSE_LEN;
862 sx.SRB_CDBLen = 10;
863 sx.SRB_PostProc = (LPVOID)hEvent;
864 sx.CDBByte[0] = 0x28; // read10
865 sx.CDBByte[1] = iCD_LU << 5;
866 sx.CDBByte[2] = (unsigned char)((f->dwFrame >> 24) & 0xFF);
867 sx.CDBByte[3] = (unsigned char)((f->dwFrame >> 16) & 0xFF);
868 sx.CDBByte[4] = (unsigned char)((f->dwFrame >> 8) & 0xFF);
869 sx.CDBByte[5] = (unsigned char)(f->dwFrame & 0xFF);
870 sx.CDBByte[8] = (unsigned char)(f->dwFrameCnt & 0xFF);
871
872 ResetEvent(hEvent);
873 dwStatus=pSendASPI32Command((LPSRB)&sx);
874 if(dwStatus==SS_PENDING)
875 WaitGenEvent(WAITFOREVER);
876
877 if(sx.SRB_Status!=SS_COMP)
878 return SS_ERR;
879
880 memset(&sx,0,sizeof(sx));
881 sx.SRB_Cmd = SC_EXEC_SCSI_CMD;
882 sx.SRB_HaId = iCD_AD;
883 sx.SRB_Target = iCD_TA;
884 sx.SRB_Lun = iCD_LU;
885 sx.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
886 sx.SRB_BufLen = 2368;
887 sx.SRB_BufPointer = tbuf;
888 sx.SRB_SenseLen = SENSE_LEN;
889 sx.SRB_CDBLen = 12;
890 sx.SRB_PostProc = (LPVOID)hEvent;
891 sx.CDBByte[0] = 0xD8;
892 sx.CDBByte[2] = (unsigned char)((f->dwFrame >> 24) & 0xFF);
893 sx.CDBByte[3] = (unsigned char)((f->dwFrame >> 16) & 0xFF);
894 sx.CDBByte[4] = (unsigned char)((f->dwFrame >> 8) & 0xFF);
895 sx.CDBByte[5] = (unsigned char)(f->dwFrame & 0xFF);
896 sx.CDBByte[9] = (unsigned char)(f->dwFrameCnt & 0xFF);
897 sx.CDBByte[10] = 1;
898
899 ResetEvent(hEvent);
900 dwStatus=pSendASPI32Command((LPSRB)&sx);
901 if(dwStatus==SS_PENDING)
902 WaitGenEvent(WAITFOREVER);
903
904 if(sx.SRB_Status!=SS_COMP)
905 return SS_ERR;
906
907 memcpy(&SubCData[12],&tbuf[2352],16);
908
909 return SS_COMP;
910 }
911
912
913 /////////////////////////////////////////////////////////
914 // various simple scsi sub data read funcs... used for
915 // ripping and subread checking... first 2352 bytes can
916 // be trash after read, only the bytes after are important
917 /////////////////////////////////////////////////////////
918
919 /////////////////////////////////////////////////////////
920
921 int ReadSub_BE_2(unsigned long addr,unsigned char * pBuf,int iNum)
922 {
923 DWORD dwStatus;
924
925 memset(&sx,0,sizeof(sx));
926 sx.SRB_Cmd = SC_EXEC_SCSI_CMD;
927 sx.SRB_HaId = iCD_AD;
928 sx.SRB_Target = iCD_TA;
929 sx.SRB_Lun = iCD_LU;
930 sx.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
931 sx.SRB_BufLen = 2368*iNum;
932 sx.SRB_BufPointer = pBuf;
933 sx.SRB_SenseLen = SENSE_LEN;
934 sx.SRB_CDBLen = 12;
935 sx.SRB_PostProc = (LPVOID)hEvent;
936 sx.CDBByte[0] = 0xBE;
937 sx.CDBByte[2] = (unsigned char)((addr >> 24) & 0xFF);
938 sx.CDBByte[3] = (unsigned char)((addr >> 16) & 0xFF);
939 sx.CDBByte[4] = (unsigned char)((addr >> 8) & 0xFF);
940 sx.CDBByte[5] = (unsigned char)(addr & 0xFF);
941 sx.CDBByte[8] = iNum;
942 sx.CDBByte[9] = 0xF8;
943 sx.CDBByte[10] = 0x2;
944
945 ResetEvent(hEvent);
946 dwStatus=pSendASPI32Command( (LPSRB)&sx );
947 if(dwStatus==SS_PENDING)
948 WaitGenEvent(WAITSUB);
949
950 if(sx.SRB_Status!=SS_COMP)
951 return 0;
952
953 return 1;
954 }
955
956 /////////////////////////////////////////////////////////
957
958 int ReadSub_BE_2_1(unsigned long addr,unsigned char * pBuf,int iNum)
959 {
960 DWORD dwStatus;
961
962 memset(&sx,0,sizeof(sx));
963 sx.SRB_Cmd = SC_EXEC_SCSI_CMD;
964 sx.SRB_HaId = iCD_AD;
965 sx.SRB_Target = iCD_TA;
966 sx.SRB_Lun = iCD_LU;
967 sx.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
968 sx.SRB_BufLen = 2448*iNum; // special! 96 bytes instead of 16
969 sx.SRB_BufPointer = pBuf;
970 sx.SRB_SenseLen = SENSE_LEN;
971 sx.SRB_CDBLen = 12;
972 sx.SRB_PostProc = (LPVOID)hEvent;
973 sx.CDBByte[0] = 0xBE;
974 sx.CDBByte[2] = (unsigned char)((addr >> 24) & 0xFF);
975 sx.CDBByte[3] = (unsigned char)((addr >> 16) & 0xFF);
976 sx.CDBByte[4] = (unsigned char)((addr >> 8) & 0xFF);
977 sx.CDBByte[5] = (unsigned char)(addr & 0xFF);
978 sx.CDBByte[8] = iNum;
979 sx.CDBByte[9] = 0xF8;
980 sx.CDBByte[10] = 0x1;
981
982 ResetEvent(hEvent);
983 dwStatus=pSendASPI32Command((LPSRB)&sx);
984 if(dwStatus==SS_PENDING)
985 WaitGenEvent(WAITSUB);
986
987 if(sx.SRB_Status!=SS_COMP)
988 return 0;
989
990 return 1;
991 }
992
993 /////////////////////////////////////////////////////////
994
995 int ReadSub_D8(unsigned long addr,unsigned char * pBuf,int iNum)
996 {
997 DWORD dwStatus;
998
999 memset(&sx,0,sizeof(sx));
1000 sx.SRB_Cmd = SC_EXEC_SCSI_CMD;
1001 sx.SRB_HaId = iCD_AD;
1002 sx.SRB_Target = iCD_TA;
1003 sx.SRB_Lun = iCD_LU;
1004 sx.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
1005 sx.SRB_BufLen = 2368*iNum;
1006 sx.SRB_BufPointer = pBuf;
1007 sx.SRB_SenseLen = SENSE_LEN;
1008 sx.SRB_CDBLen = 12;
1009 sx.SRB_PostProc = (LPVOID)hEvent;
1010 sx.CDBByte[0] = 0xD8;
1011 sx.CDBByte[2] = (unsigned char)((addr >> 24) & 0xFF);
1012 sx.CDBByte[3] = (unsigned char)((addr >> 16) & 0xFF);
1013 sx.CDBByte[4] = (unsigned char)((addr >> 8) & 0xFF);
1014 sx.CDBByte[5] = (unsigned char)(addr & 0xFF);
1015 sx.CDBByte[9] = iNum;
1016 sx.CDBByte[10] = 1;
1017
1018 ResetEvent(hEvent);
1019 dwStatus=pSendASPI32Command((LPSRB)&sx);
1020 if(dwStatus==SS_PENDING)
1021 WaitGenEvent(WAITFOREVER);
1022
1023 if(sx.SRB_Status!=SS_COMP)
1024 return 0;
1025
1026 return 1;
1027 }
1028
1029 /////////////////////////////////////////////////////////
1030 // liteon subdata decoding
1031
1032 void DecodeSub_BE_2_1(unsigned char * pBuf)
1033 {
1034 int i,j;
1035 unsigned char * pS=pBuf;
1036 unsigned char c;
1037
1038 for(i=0;i<12;i++)
1039 {
1040 c=0;
1041 for(j=7;j>=0;j--,pS++)
1042 {
1043 if(*pS & 0x40) c|=(1<<j);
1044 }
1045 *(pBuf+i)=c;
1046 }
1047
1048 for(i=12;i<16;i++) *(pBuf+i)=0;
1049 }
1050
1051 /////////////////////////////////////////////////////////
1052 // auto-detection of read mode (without subc), called
1053 // on plugin startup
1054
1055 #define MAXMODES 6
1056
1057 DWORD CheckSCSIReadMode(void)
1058 {
1059 DWORD dwStatus;int i,j,k,iCnt;char * p;
1060 int iModes[MAXMODES]={MODE_BE_2,MODE_BE_1,MODE_28_1,MODE_28_2,MODE_28_2048,MODE_28_2048_Ex};
1061 int iBlock[MAXMODES]={2352, 2352, 2352, 2352, 2048, 2048};
1062 unsigned char cdb[3000];
1063 FRAMEBUF * f=(FRAMEBUF *)cdb;
1064
1065 for(i=0;i<MAXMODES;i++) // loop avail read modes
1066 {
1067 f->dwFrame = 16; // we check on addr 16 (should be available on all ps2 cds/dvds)
1068 f->dwFrameCnt = 1;
1069 f->dwBufLen = iBlock[i];
1070
1071 pDeInitFunc = NULL;
1072 iRType=iModes[i]; // set global read mode
1073 GetGenReadFunc(iRType); // get read func pointer
1074
1075 for(j=0;j<3;j++) // try it 3 times
1076 {
1077 memset(f->BufData,0xAA,f->dwBufLen); // fill buf with AA
1078 dwStatus=pReadFunc(TRUE,f); // do the read
1079
1080 #ifdef DBGOUT
1081 auxprintf("status %d\n",dwStatus);
1082 #endif
1083
1084 if(dwStatus!=SS_COMP) continue; // error? try again
1085
1086 p=&(f->BufData[0]);
1087
1088 #ifdef DBGOUT
1089 auxprintf("check mode %d\n",i);
1090 #endif
1091
1092 for(k=0,iCnt=0;k<(int)f->dwBufLen;k+=4,p+=4) // now check the returned data
1093 {
1094 #ifdef DBGOUT
1095 // auxprintf("%08x ",*((DWORD *)p));
1096 #endif
1097
1098 if(*((DWORD *)p)==0xAAAAAAAA) // -> still AA? bad
1099 iCnt++;
1100 else iCnt=0;
1101
1102 if(iCnt>=8) {dwStatus=SS_ERR;break;} // -> if we have found many AA's, the reading was bad
1103 }
1104
1105 if(dwStatus==SS_COMP) // reading was a success, no AA's?
1106 {
1107 iRType = iModes[i]; // -> set found mode
1108 iUsedBlockSize = iBlock[i];
1109 if(iUsedBlockSize==2352)
1110 iUsedMode=CDVD_MODE_2352;
1111 else iUsedMode=CDVD_MODE_2048;
1112
1113 #ifdef DBGOUT
1114 auxprintf("mode found %d\n",i);
1115 #endif
1116
1117 return dwStatus; // -> bye
1118 }
1119 }
1120 if(pDeInitFunc) pDeInitFunc(); // deinit, try next mode
1121 }
1122
1123 return dwStatus;
1124 }
1125
1126 /////////////////////////////////////////////////////////
1127 // dummy read dunc
1128
1129 DWORD ReadSCSI_Dummy(BOOL bWait,FRAMEBUF * f)
1130 {
1131 return SS_ERR;
1132 }
1133
1134 /////////////////////////////////////////////////////////

  ViewVC Help
Powered by ViewVC 1.1.22