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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (10 years ago) by william
File MIME type: text/plain
File size: 26067 byte(s)
committing r3113 initial commit again...
1 /***************************************************************************
2 cdr.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 // 2004/12/25 - Pete
23 // - added an hack in CDVDgetTD for big dvds
24 //
25 // 2003/11/16 - Pete
26 // - generic cleanup for the Peops cdvd release
27 //
28 //*************************************************************************//
29
30 /////////////////////////////////////////////////////////
31
32 #include "stdafx.h"
33 #include <time.h>
34 #include "resource.h"
35 #define _IN_CDR
36 #include "externals.h"
37 #define CDVDdefs
38 #include "PS2Etypes.h"
39 #include "PS2Edefs.h"
40 #include "libiso.h"
41
42 #ifdef DBGOUT
43 #define SMALLDEBUG 1
44 #include <dbgout.h>
45 #endif
46
47 /////////////////////////////////////////////////////////
48 // PCSX2 CDVD interface:
49
50 EXPORT_GCC char * CALLBACK PS2EgetLibName();
51 EXPORT_GCC unsigned long CALLBACK PS2EgetLibType();
52 EXPORT_GCC unsigned long CALLBACK PS2EgetLibVersion2(unsigned long type);
53 EXPORT_GCC long CALLBACK CDVDinit();
54 EXPORT_GCC void CALLBACK CDVDshutdown();
55 EXPORT_GCC long CALLBACK CDVDopen(const char* pTitle);
56 EXPORT_GCC void CALLBACK CDVDclose();
57 EXPORT_GCC long CALLBACK CDVDtest();
58 EXPORT_GCC long CALLBACK CDVDreadTrack(unsigned long lsn, int mode);
59 EXPORT_GCC unsigned char * CALLBACK CDVDgetBuffer();
60 EXPORT_GCC long CALLBACK CDVDgetTN(cdvdTN *Buffer);
61 EXPORT_GCC long CALLBACK CDVDgetTD(unsigned char track, cdvdTD *Buffer);
62 EXPORT_GCC long CALLBACK CDVDgetDiskType();
63 EXPORT_GCC long CALLBACK CDVDgetTrayStatus();
64
65 /////////////////////////////////////////////////////////
66
67 const unsigned char version = PS2E_CDVD_VERSION;
68 const unsigned char revision = 1;
69 const unsigned char build = 3;
70
71 #ifdef _DEBUG
72 char *libraryName = "P.E.Op.S. CDVD (Debug, CDDA mod)";
73 #else
74 char *libraryName = "P.E.Op.S. CDVD (CDDA mod)";
75 #endif
76
77 /////////////////////////////////////////////////////////
78
79 BOOL bIsOpen=FALSE; // flag: open called once
80 BOOL bCDDAPlay=FALSE; // flag: audio is playing
81 int iCDROK=0; // !=0: cd is ok
82 int iCDType=CDVD_TYPE_UNKNOWN; // CD/DVD
83 int iCheckTrayStatus=0; // if 0 : report tray as closed, else try a real check
84 void *fdump;
85
86 /////////////////////////////////////////////////////////
87 // usual info funcs
88
89 EXPORT_GCC char * CALLBACK PS2EgetLibName()
90 {
91 return libraryName;
92 }
93
94 EXPORT_GCC unsigned long CALLBACK PS2EgetLibType()
95 {
96 return PS2E_LT_CDVD;
97 }
98
99 EXPORT_GCC unsigned long CALLBACK PS2EgetLibVersion2(unsigned long type)
100 {
101 return version<<16|revision<<8|build;
102 }
103 /*
104 EXPORT_GCC unsigned long CALLBACK PS2EgetCpuPlatform(void)
105 {
106 return PS2E_X86;
107 // return PS2E_X86_64;
108 }*/
109
110 s32 msf_to_lba(u8 m, u8 s, u8 f) {
111 u32 lsn;
112 lsn = f;
113 lsn+=(s - 2) * 75;
114 lsn+= m * 75 * 60;
115 return lsn;
116 }
117
118 void lba_to_msf(s32 lba, u8* m, u8* s, u8* f) {
119 lba += 150;
120 *m = (u8)(lba / (60*75));
121 *s = (u8)((lba / 75) % 60);
122 *f = (u8)(lba % 75);
123 }
124
125 /////////////////////////////////////////////////////////
126 // init: called once at library load
127
128 EXPORT_GCC long CALLBACK CDVDinit()
129 {
130 szSUBF[0]=0; // just init the filename buffers
131 szPPF[0] =0;
132 return 0;
133 }
134
135 /////////////////////////////////////////////////////////
136 // shutdown: called once at final exit
137
138 EXPORT_GCC void CALLBACK CDVDshutdown()
139 {
140 }
141
142 /////////////////////////////////////////////////////////
143 // open: called, when games starts/cd has been changed
144
145 int CheckDiskType(int baseType);
146
147 EXPORT_GCC long CALLBACK CDVDopen(const char* pTitle)
148 {
149 int i,audioTracks,dataTracks;
150 cdvdTD T;
151 if(bIsOpen) // double-open check (if the main emu coder doesn't know what he is doing ;)
152 {
153 if(iCDROK<=0) return -1;
154 else return 0;
155 }
156
157 bIsOpen=TRUE; // ok, open func called once
158
159 ReadConfig(); // read user config
160
161 BuildPPFCache(); // build ppf cache
162
163 BuildSUBCache(); // build sub cache
164
165 CreateREADBufs(); // setup generic read buffers
166
167 CreateGenEvent(); // create read event
168
169 iCDROK=OpenGenCD(iCD_AD,iCD_TA,iCD_LU); // generic open, setup read func
170
171 if(iCDROK<=0) {iCDROK=0;return -1;}
172
173 ReadTOC(); // read the toc
174
175 SetGenCDSpeed(0); // try to change the reading speed (if wanted)
176
177 iCDType=CDVD_TYPE_UNKNOWN; // let's look after the disc type
178 // (funny stuff taken from Xobro's/Florin's bin plugin)
179 if(CDVDreadTrack(16,CDVD_MODE_2048)==0)
180 {
181 struct cdVolDesc *volDesc;
182 volDesc=(struct cdVolDesc *)CDVDgetBuffer();
183 if(volDesc)
184 {
185
186 //todo: CDVD_TYPE_CDDA
187
188 if(volDesc->rootToc.tocSize==2048)
189 iCDType = CDVD_TYPE_DETCTCD;
190 else iCDType = CDVD_TYPE_DETCTDVDS;
191 }
192 }
193
194 fprintf(stderr," * CDVD Disk Open: %d tracks (%d to %d):\n",sTOC.cLastTrack-sTOC.cFirstTrack+1,sTOC.cFirstTrack,sTOC.cLastTrack);
195
196 audioTracks=dataTracks=0;
197 for(i=sTOC.cFirstTrack;i<=sTOC.cLastTrack;i++)
198 {
199 CDVDgetTD(i,&T);
200 if(T.type==CDVD_AUDIO_TRACK) {
201 audioTracks++;
202 fprintf(stderr," * * Track %d: Audio (%d sectors)\n",i,T.lsn);
203 }
204 else {
205 dataTracks++;
206 fprintf(stderr," * * Track %d: Data (Mode %d) (%d sectors)\n",i,((T.type==CDVD_MODE1_TRACK)?1:2),T.lsn);
207 }
208 }
209 if((dataTracks==0)&&(audioTracks>0))
210 iCDType=CDVD_TYPE_CDDA;
211 else if(dataTracks>0)
212 iCDType=CheckDiskType(iCDType);
213
214 if((iCDType==CDVD_TYPE_ILLEGAL)&&(audioTracks>0))
215 iCDType=CDVD_TYPE_CDDA;
216 else if((iCDType==CDVD_TYPE_PS2CD)&&(audioTracks>0))
217 iCDType=CDVD_TYPE_PS2CDDA;
218 else if((iCDType==CDVD_TYPE_PSCD)&&(audioTracks>0))
219 iCDType=CDVD_TYPE_PSCDDA;
220
221 switch(iCDType) {
222 case CDVD_TYPE_ILLEGAL: // Illegal Disc
223 fprintf(stderr," * Disk Type: Illegal Disk.\n");break;
224 case CDVD_TYPE_DVDV: // DVD Video
225 fprintf(stderr," * Disk Type: DVD Video.\n");break;
226 case CDVD_TYPE_CDDA: // Audio CD
227 fprintf(stderr," * Disk Type: CDDA.\n");break;
228 case CDVD_TYPE_PS2DVD: // PS2 DVD
229 fprintf(stderr," * Disk Type: PS2 DVD.\n");break;
230 case CDVD_TYPE_PS2CDDA: // PS2 CD (with audio)
231 fprintf(stderr," * Disk Type: PS2 CD+Audio.\n");break;
232 case CDVD_TYPE_PS2CD: // PS2 CD
233 fprintf(stderr," * Disk Type: PS2 CD.\n");break;
234 case CDVD_TYPE_PSCDDA: // PS CD (with audio)
235 fprintf(stderr," * Disk Type: PS1 CD+Audio.\n");break;
236 case CDVD_TYPE_PSCD: // PS CD
237 fprintf(stderr," * Disk Type: PS1 CD.\n");break;
238 case CDVD_TYPE_UNKNOWN: // Unknown
239 fprintf(stderr," * Disk Type: Unknown.\n");break;
240 case CDVD_TYPE_NODISC: // No Disc
241 fprintf(stderr," * Disk Type: No Disc.\n");break;
242 }
243
244 /* if (iBlockDump)*/ {
245 // fdump = isoCreate("block.dump", ISOFLAGS_BLOCKDUMP);
246 fdump = NULL;
247 if (fdump) {
248 cdvdTD buf;
249 CDVDgetTD(0, &buf);
250 isoSetFormat(fdump, 0, 2352, buf.lsn);
251 }
252 } /*else {
253 fdump = NULL;
254 }*/
255
256
257 return 0; // ok, done
258 }
259
260 /////////////////////////////////////////////////////////
261 // close: called when emulation stops
262
263 EXPORT_GCC void CALLBACK CDVDclose()
264 {
265 if(!bIsOpen) return; // no open? no close...
266
267 if (fdump != NULL) {
268 isoClose(fdump);
269 }
270 bIsOpen=FALSE; // no more open
271
272 LockGenCDAccess(); // make sure that no more reading is happening
273
274 if(iCDROK) // cd was ok?
275 {
276 if(bCDDAPlay) {DoCDDAPlay(0);bCDDAPlay=FALSE;} // -> cdda playing? stop it
277 SetGenCDSpeed(1); // -> repair speed
278 CloseGenCD(); // -> cd not used anymore
279 }
280
281 UnlockGenCDAccess();
282
283 FreeREADBufs(); // free read bufs
284 FreeGenEvent(); // free event
285 FreePPFCache(); // free ppf cache
286 FreeSUBCache(); // free sub cache
287 }
288
289 /////////////////////////////////////////////////////////
290 // test: ah, well, always fine
291
292 EXPORT_GCC long CALLBACK CDVDtest()
293 {
294 return 0;
295 }
296
297 /////////////////////////////////////////////////////////
298 // readSubQ: read subq from disc (only cds have subq data)
299 EXPORT_GCC long CALLBACK CDVDreadSubQ(u32 lsn, cdvdSubQ* subq)
300 {
301 u8 min, sec, frm;
302
303 if(!bIsOpen) CDVDopen("DVD"); // usual checks
304 if(!iCDROK) return -1;
305
306 // fake it
307 subq->ctrl = 4;
308 subq->mode = 1;
309 subq->trackNum = itob(1);
310 subq->trackIndex= itob(1);
311
312 lba_to_msf(lsn, &min, &sec, &frm);
313 subq->trackM = itob(min);
314 subq->trackS = itob(sec);
315 subq->trackF = itob(frm);
316
317 subq->pad = 0;
318
319 lba_to_msf(lsn + (2*75), &min, &sec, &frm);
320 subq->discM = itob(min);
321 subq->discS = itob(sec);
322 subq->discF = itob(frm);
323 return 0;
324 }
325
326 /////////////////////////////////////////////////////////
327 // gettoc: ps2 style TOC
328 static int layer1start = -1;
329 EXPORT_GCC long CALLBACK CDVDgetTOC(void* toc)
330 {
331 u32 type;
332 u8* tocBuff = (u8*)toc;
333
334 if(!bIsOpen) CDVDopen("DVD"); // not open? funny emu...
335
336 if(!iCDROK) return -1; // cd not ok?
337
338 type = CDVDgetDiskType();
339
340 if( type == CDVD_TYPE_DVDV ||
341 type == CDVD_TYPE_PS2DVD)
342 {
343 u32 lastaddr;
344
345 // get dvd structure format
346 // scsi command 0x43
347 memset(tocBuff, 0, 2048);
348
349 lastaddr = GetLastTrack1Addr();
350 if(layer1start > 0 || (layer1start != -2 && lastaddr > 0x280000) ) {
351 int off = 0;
352 FRAMEBUF* f = (FRAMEBUF*)malloc(sizeof(FRAMEBUF));
353
354 f->dwBufLen = iUsedBlockSize;
355 f->dwFrameCnt = 1;
356
357
358 // dual sided
359 tocBuff[ 0] = 0x24;
360 tocBuff[ 1] = 0x02;
361 tocBuff[ 2] = 0xF2;
362 tocBuff[ 3] = 0x00;
363 tocBuff[ 4] = 0x41;
364 tocBuff[ 5] = 0x95;
365
366 tocBuff[14] = 0x60; // dual sided, ptp
367
368 tocBuff[16] = 0x00;
369 tocBuff[17] = 0x03;
370 tocBuff[18] = 0x00;
371 tocBuff[19] = 0x00;
372
373 if( layer1start == -1 ) {
374 // search for it
375 printf("PeopsCDVD: searching for layer1... ");
376 for(layer1start = (lastaddr/2-0x10)&~0xf; layer1start < 0x200010; layer1start += 16) {
377 f->dwFrame = layer1start;
378 if( pReadFunc(TRUE,f) != SS_COMP ) {
379 layer1start = 0x200010;
380 break;
381 }
382 // CD001
383 if( f->BufData[off+1] == 0x43 && f->BufData[off+2] == 0x44 && f->BufData[off+3] == 0x30 && f->BufData[off+4] == 0x30 && f->BufData[off+5] == 0x31 ) {
384 break;
385 }
386 }
387
388 if( layer1start >= 0x200010 ) {
389 printf("Couldn't find second layer on dual layer... ignoring\n");
390 // fake it
391 tocBuff[ 0] = 0x04;
392 tocBuff[ 1] = 0x02;
393 tocBuff[ 2] = 0xF2;
394 tocBuff[ 3] = 0x00;
395 tocBuff[ 4] = 0x86;
396 tocBuff[ 5] = 0x72;
397
398 tocBuff[16] = 0x00;
399 tocBuff[17] = 0x03;
400 tocBuff[18] = 0x00;
401 tocBuff[19] = 0x00;
402 layer1start = -2;
403 return 0;
404 }
405
406 printf("found at 0x%8.8x\n", layer1start);
407 layer1start = layer1start+0x30000-1;
408 }
409
410 tocBuff[20] = layer1start>>24;
411 tocBuff[21] = (layer1start>>16)&0xff;
412 tocBuff[22] = (layer1start>>8)&0xff;
413 tocBuff[23] = (layer1start>>0)&0xff;
414
415 free(f);
416 }
417 else {
418 // fake it
419 tocBuff[ 0] = 0x04;
420 tocBuff[ 1] = 0x02;
421 tocBuff[ 2] = 0xF2;
422 tocBuff[ 3] = 0x00;
423 tocBuff[ 4] = 0x86;
424 tocBuff[ 5] = 0x72;
425
426 tocBuff[16] = 0x00;
427 tocBuff[17] = 0x03;
428 tocBuff[18] = 0x00;
429 tocBuff[19] = 0x00;
430 }
431 }
432 else if(type == CDVD_TYPE_CDDA ||
433 type == CDVD_TYPE_PS2CDDA ||
434 type == CDVD_TYPE_PS2CD ||
435 type == CDVD_TYPE_PSCDDA ||
436 type == CDVD_TYPE_PSCD)
437 {
438 // cd toc
439 // (could be replaced by 1 command that reads the full toc)
440 u8 min, sec, frm,i;
441 s32 err;
442 cdvdTN diskInfo;
443 cdvdTD trackInfo;
444 memset(tocBuff, 0, 1024);
445 if (CDVDgetTN(&diskInfo) == -1) { diskInfo.etrack = 0;diskInfo.strack = 1; }
446 if (CDVDgetTD(0, &trackInfo) == -1) trackInfo.lsn = 0;
447
448 tocBuff[0] = 0x41;
449 tocBuff[1] = 0x00;
450
451 //Number of FirstTrack
452 tocBuff[2] = 0xA0;
453 tocBuff[7] = itob(diskInfo.strack);
454
455 //Number of LastTrack
456 tocBuff[12] = 0xA1;
457 tocBuff[17] = itob(diskInfo.etrack);
458
459 //DiskLength
460 lba_to_msf(trackInfo.lsn, &min, &sec, &frm);
461 tocBuff[22] = 0xA2;
462 tocBuff[27] = itob(min);
463 tocBuff[28] = itob(sec);
464 tocBuff[29] = itob(frm);
465
466 fprintf(stderr,"Track 0: %d mins %d secs %d frames\n",min,sec,frm);
467
468 for (i=diskInfo.strack; i<=diskInfo.etrack; i++)
469 {
470 err = CDVDgetTD(i, &trackInfo);
471 lba_to_msf(trackInfo.lsn, &min, &sec, &frm);
472 tocBuff[i*10+30] = trackInfo.type;
473 tocBuff[i*10+32] = err == -1 ? 0 : itob(i); //number
474 tocBuff[i*10+37] = itob(min);
475 tocBuff[i*10+38] = itob(sec);
476 tocBuff[i*10+39] = itob(frm);
477 fprintf(stderr,"Track %d: %d mins %d secs %d frames\n",i,min,sec,frm);
478 }
479 }
480 else
481 return -1;
482
483 return 0;
484 }
485
486 /////////////////////////////////////////////////////////
487 // gettn: first/last track num
488
489 EXPORT_GCC long CALLBACK CDVDgetTN(cdvdTN *Buffer)
490 {
491 if(!bIsOpen) CDVDopen("DVD"); // not open? funny emu...
492
493 if(!iCDROK) // cd not ok?
494 {
495 Buffer->strack=1;
496 Buffer->etrack=1;
497 return -1;
498 }
499
500 ReadTOC(); // read the TOC
501
502 Buffer->strack=sTOC.cFirstTrack; // get the infos
503 Buffer->etrack=sTOC.cLastTrack;
504
505 return 0;
506 }
507
508 /////////////////////////////////////////////////////////
509 // gettd: track addr
510
511 EXPORT_GCC long CALLBACK CDVDgetTD(unsigned char track, cdvdTD *Buffer)
512 {
513 unsigned long lu,i;
514 unsigned char buffer[2352];
515 unsigned char *buf;
516 u8 t1;
517
518 if(!bIsOpen) CDVDopen("DVD"); // not open? funny emu...
519
520 if(!iCDROK) return -1; // cd not ok? bye
521
522 ReadTOC(); // read toc
523
524 /*
525 // PSEmu style:
526 if(track==0) // 0 = last track
527 {
528 lu=reOrder(sTOC.tracks[sTOC.cLastTrack].lAddr);
529 addr2time(lu,buffer);
530 }
531 else // others: track n
532 {
533 lu=reOrder(sTOC.tracks[track-1].lAddr);
534 addr2time(lu,buffer);
535 }
536
537 Buffer->minute = buffer[1];
538 Buffer->second = buffer[2];
539 Buffer->frame = buffer[3];
540 Buffer->type = iCDType;
541 #ifdef DBGOUT
542 auxprintf("Read Toc %d: %u\n",track,lu);
543 #endif
544 */
545
546 lu=0;
547 if(track==0)
548 lu=reOrder(sTOC.tracks[sTOC.cLastTrack].lAddr);
549 else
550 lu=reOrder(sTOC.tracks[track].lAddr);
551 //addr2time(lu,buffer);
552
553 Buffer->lsn=lu;
554
555 if(track==0)
556 Buffer->type = iCDType;
557 else
558 {
559 lu=0;
560 for(i=sTOC.cFirstTrack;i<track;i++)
561 lu+=sTOC.tracks[i].lAddr;
562
563 CDVDreadTrack(lu+16,CDVD_MODE_2352);
564 buf=CDVDgetBuffer();
565
566 if(buf!=NULL) memcpy(buffer,buf,2352);
567 else memset(buffer,0,2352);
568
569 if( (buffer[16]==01)
570 &&(buffer[17]=='C')
571 &&(buffer[18]=='D')
572 )
573 t1 = CDVD_MODE1_TRACK;
574 else if( (buffer[24]==01)
575 &&(buffer[25]=='C')
576 &&(buffer[26]=='D')
577 )
578 t1 = CDVD_MODE2_TRACK;
579 else t1 = CDVD_AUDIO_TRACK;
580
581 Buffer->type=t1;
582 }
583
584 return 0;
585 }
586
587 /////////////////////////////////////////////////////////
588 // readtrack: start reading at given address
589
590 EXPORT_GCC long CALLBACK CDVDreadTrack(unsigned long lsn, int mode)
591 {
592 if(!bIsOpen) CDVDopen("DVD"); // usual checks
593 if(!iCDROK) return -1;
594 if(bCDDAPlay) bCDDAPlay=FALSE;
595
596 #ifdef DBGOUT
597 auxprintf("Read Track %u: %d\n",lsn,mode);
598 #endif
599
600 lLastAccessedAddr=lsn; // store read track values (for getbuffer)
601 iLastAccessedMode=mode;
602
603 if(!pReadTrackFunc(lLastAccessedAddr)) // start reading
604 return -1;
605
606 return 0;
607 }
608
609 /////////////////////////////////////////////////////////
610 // getbuffer: will be called after readtrack, to get ptr
611 // to data
612
613 // small helper buffer to get bigger block sizes
614 unsigned char cDataAndSub[2368];
615
616 EXPORT_GCC unsigned char * CALLBACK CDVDgetBuffer()
617 {
618 unsigned char * pbuffer;
619
620 if(!bIsOpen) CDVDopen("DVD");
621
622 if(pGetPtrFunc) pGetPtrFunc(); // get ptr on thread modes
623
624 pbuffer=pCurrReadBuf; // init buffer pointer
625 if (fdump != NULL) {
626 isoWriteBlock(fdump, pbuffer, lLastAccessedAddr);
627 }
628
629 if(iLastAccessedMode!=iUsedMode)
630 {
631 switch(iLastAccessedMode) // what does the emu want?
632 {//------------------------------------------------//
633 case CDVD_MODE_2048:
634 {
635 if(iUsedBlockSize==2352) pbuffer+=24;
636 }break;
637 //------------------------------------------------//
638 case CDVD_MODE_2352:
639 {
640 if(iUsedBlockSize==2048)
641 {
642 memset(cDataAndSub,0,2368);
643 memcpy(cDataAndSub+24,pbuffer,2048);
644 pbuffer=cDataAndSub;
645 }
646 }break;
647 //------------------------------------------------//
648 case CDVD_MODE_2340:
649 {
650 if(iUsedBlockSize==2048)
651 {
652 memset(cDataAndSub,0,2368);
653 memcpy(cDataAndSub+12,pbuffer,2048);
654 pbuffer=cDataAndSub;
655 }
656 else pbuffer+=12;
657 }break;
658 //------------------------------------------------//
659 case CDVD_MODE_2328:
660 {
661 if(iUsedBlockSize==2048)
662 {
663 memset(cDataAndSub,0,2368);
664 memcpy(cDataAndSub+0,pbuffer,2048);
665 pbuffer=cDataAndSub;
666 }
667 else pbuffer+=24;
668 }break;
669 //------------------------------------------------//
670 case CDVD_MODE_2368:
671 {
672 if(iUsedBlockSize==2048)
673 {
674 memset(cDataAndSub,0,2368);
675 memcpy(cDataAndSub+24,pbuffer,2048);
676 pbuffer=cDataAndSub;
677
678 /*
679 // NO SUBCHANNEL SUPPORT RIGHT NOW!!!
680 {
681 if(subHead) // some sub file?
682 CheckSUBCache(lLastAccessedAddr); // -> get cached subs
683 else
684 if(iUseSubReading!=1 && pCurrSubBuf) // no direct cd sub read?
685 FakeSubData(lLastAccessedAddr); // -> fake the data
686 memcpy(cDataAndSub,pCurrReadBuf,2352);
687 if(pCurrSubBuf)
688 memcpy(cDataAndSub+2352,pCurrSubBuf+12,16);
689 pbuffer=cDataAndSub;
690 }
691 */
692
693 }
694 }break;
695 //------------------------------------------------//
696 }
697 }
698
699 #ifdef DBGOUT
700 auxprintf("get buf %d\n",iLastAccessedMode);
701
702 /*
703 {
704 int k;
705 for(k=0;k<2352;k++)
706 auxprintf("%02x ",*(pbuffer+k));
707 auxprintf("\n\n");
708 }
709 */
710 #endif
711
712 return pbuffer;
713 }
714
715 /////////////////////////////////////////////////////////
716
717 EXPORT_GCC long CALLBACK CDVDgetDiskType()
718 {
719 return iCDType;
720 }
721
722 /////////////////////////////////////////////////////////
723 // CDVDgetTrayStatus
724
725 EXPORT_GCC long CALLBACK CDVDgetTrayStatus()
726 {
727 static time_t to=0;
728 static long lLastTrayState=CDVD_TRAY_CLOSE;
729
730 if(to==time(NULL)) return lLastTrayState; // we only check once per second
731 to = time(NULL);
732
733 lLastTrayState=CDVD_TRAY_CLOSE; // init state with "closed"
734
735 if(iCheckTrayStatus) // user really want a tray check
736 {
737 int iStatus;
738
739 LockGenCDAccess(); // make sure that no more reading is happening
740 iStatus=GetSCSIStatus(iCD_AD,iCD_TA,iCD_LU); // get device status
741 UnlockGenCDAccess();
742
743 if(iStatus==SS_ERR)
744 lLastTrayState=CDVD_TRAY_OPEN;
745 }
746
747 #ifdef DBGOUT
748 auxprintf("check %d -> %d\n",to,lLastTrayState);
749 #endif
750
751
752 return lLastTrayState;
753 }
754
755 EXPORT_GCC s32 CALLBACK CDVDctrlTrayOpen() {
756 return 0;
757 }
758
759 EXPORT_GCC s32 CALLBACK CDVDctrlTrayClose() {
760 return 0;
761 }
762
763
764
765 /////////////////////////////////////////////////////////
766 // configure: shows config window
767
768 EXPORT_GCC void CALLBACK CDVDconfigure()
769 {
770 if(iCDROK) // mmm... someone has already called Open? bad
771 {MessageBeep((UINT)-1);return;}
772
773 CreateGenEvent(); // we need an event handle
774
775 DialogBox(hInst,MAKEINTRESOURCE(IDD_CONFIG), // call dialog
776 GetActiveWindow(),(DLGPROC)CDRDlgProc);
777
778 FreeGenEvent(); // free event handle
779 }
780
781 /////////////////////////////////////////////////////////
782 // about: shows about window
783
784 EXPORT_GCC void CALLBACK CDVDabout()
785 {
786 DialogBox(hInst,MAKEINTRESOURCE(IDD_ABOUT),
787 GetActiveWindow(),(DLGPROC)AboutDlgProc);
788 }
789
790 /////////////////////////////////////////////////////////
791 /////////////////////////////////////////////////////////
792 /////////////////////////////////////////////////////////
793
794 /*
795 // CURRENTLY UNUSED OLD STUFF FROM PSX CD PLUGIN:
796
797 /////////////////////////////////////////////////////////
798 // audioplay: PLAYSECTOR is NOT BCD coded !!!
799
800 EXPORT_GCC long CALLBACK CDRplay(unsigned char * sector)
801 {
802 if(!bIsOpen) CDVDopen();
803 if(!iCDROK) return PSE_ERR_FATAL;
804
805 if(!DoCDDAPlay(time2addr(sector))) // start playing
806 return PSE_CDR_ERR_NOREAD;
807
808 bCDDAPlay=TRUE; // raise flag: we are playing
809
810 return PSE_CDR_ERR_SUCCESS;
811 }
812
813 /////////////////////////////////////////////////////////
814 // audiostop: stops cdda playing
815
816 EXPORT_GCC long CALLBACK CDRstop(void)
817 {
818 if(!bCDDAPlay) return PSE_ERR_FATAL;
819
820 DoCDDAPlay(0); // stop cdda
821
822 bCDDAPlay=FALSE; // reset flag: no more playing
823
824 return PSE_CDR_ERR_SUCCESS;
825 }
826
827 /////////////////////////////////////////////////////////
828 // getdriveletter
829
830 EXPORT_GCC char CALLBACK CDRgetDriveLetter(void)
831 {
832 if(!iCDROK) return 0; // not open? no way to get the letter
833
834 if(iInterfaceMode==2 || iInterfaceMode==3) // w2k/xp: easy
835 {
836 return MapIOCTLDriveLetter(iCD_AD,iCD_TA,iCD_LU);
837 }
838 else // but with aspi???
839 { // -> no idea yet (maybe registry read...pfff)
840 }
841
842 return 0;
843 }
844
845 /////////////////////////////////////////////////////////
846 // getstatus: pcsx func... poorly supported here
847 // problem is: func will be called often, which
848 // would block all of my cdr reading if I would use
849 // lotsa scsi commands
850
851 struct CdrStat
852 {
853 unsigned long Type;
854 unsigned long Status;
855 unsigned char Time[3]; // current playing time
856 };
857
858 struct CdrStat ostat;
859
860 // reads cdr status
861 // type:
862 // 0x00 - unknown
863 // 0x01 - data
864 // 0x02 - audio
865 // 0xff - no cdrom
866 // status:
867 // 0x00 - unknown
868 // 0x02 - error
869 // 0x08 - seek error
870 // 0x10 - shell open
871 // 0x20 - reading
872 // 0x40 - seeking
873 // 0x80 - playing
874 // time:
875 // byte 0 - minute
876 // byte 1 - second
877 // byte 2 - frame
878
879
880 EXPORT_GCC long CALLBACK CDRgetStatus(struct CdrStat *stat)
881 {
882 int iStatus;
883 static time_t to;
884
885 if(!bCDDAPlay) // if not playing update stat only once in a second
886 {
887 if(to<time(NULL))
888 {
889 to = time(NULL);
890 }
891 else
892 {
893 memcpy(stat, &ostat, sizeof(struct CdrStat));
894 return 0;
895 }
896 }
897
898 memset(stat, 0, sizeof(struct CdrStat));
899
900 if(!iCDROK) return -1; // not opened? bye
901
902 if(bCDDAPlay) // cdda is playing?
903 {
904 unsigned char * pB=GetCDDAPlayPosition(); // -> get pos
905 stat->Type = 0x02; // -> audio
906 if(pB)
907 {
908 stat->Status|=0x80; // --> playing flag
909 stat->Time[0]=pB[18]; // --> and curr play time
910 stat->Time[1]=pB[19];
911 stat->Time[2]=pB[20];
912 }
913 }
914 else // cdda not playing?
915 {
916 stat->Type = 0x01; // -> data
917 }
918
919 LockGenCDAccess(); // make sure that no more reading is happening
920 iStatus=GetSCSIStatus(iCD_AD,iCD_TA,iCD_LU); // get device status
921 UnlockGenCDAccess();
922
923 if(iStatus==SS_ERR)
924 { // no cdrom?
925 stat->Type = 0xff;
926 stat->Status|= 0x10;
927 }
928
929 memcpy(&ostat, stat, sizeof(struct CdrStat));
930
931 return 0;
932 }
933
934 /////////////////////////////////////////////////////////
935 */

  ViewVC Help
Powered by ViewVC 1.1.22