1 /*---------------------------------------------------------------------------*
2   Project:  Revolution OS
3   File:     dvd.h
4 
5   Copyright 1998-2009 Nintendo.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Log: dvd.h,v $
14   Revision 1.12  2009/07/22 05:10:25  ooizumi
15   Added new APIs.
16 
17   Revision 1.11  2009/01/30 01:33:33  ooizumi
18   Added DVDIsDiskIdentified().
19 
20   Revision 1.10  2006/09/28 04:50:20  shirakae
21   Added DVDEntrynumIsDir
22 
23   Revision 1.9  2006/06/07 02:21:23  ooizumi
24   Deleted DVDCheckDisk.
25 
26   Revision 1.8  2006/06/05 00:21:27  ooizumi
27   Enabled DVDCheckDiskAsync for RVL0 target.
28 
29   Revision 1.7  2006/05/17 22:16:20  ooizumi
30   Added DVD_STATE_NO_INPUT state.
31 
32   Revision 1.6  2006/04/24 05:23:16  ooizumi
33   Changed a header file for WIN32 target.
34 
35   Revision 1.5  2006/03/20 10:24:33  ooizumi
36   Deleted APIs for hardware streaming.
37 
38   Revision 1.4  2006/03/12 03:03:29  craig
39   Added GC and RVL magic number locations to disk id structure.
40 
41   Revision 1.3  2006/03/10 22:44:58  ooizumi
42   Chenged DVDGetStartAddr's return value u32 to u64.
43 
44   Revision 1.2  2006/02/04 11:56:44  hashida
45   (none)
46 
47   Revision 1.1.1.1  2005/12/29 06:53:27  hiratsu
48   Initial import.
49 
50   Revision 1.1.1.1  2005/05/12 02:41:06  yasuh-to
51   dolphin�V�[�X�c���[����ڐA
52 
53 
54     54    04/03/31 20:27 Hashida
55     Updated copyright info.
56 
57     53    03/09/10 14:37 Ooshima
58     Modified DVDDirEntry and DVDRewindDir to remove DVDETH definition.
59 
60     51    03/04/22 11:29 Hashida
61     Modified DVDGetFileInfoStatus to refer fileinfo's member instead of
62     just casting to DVDCommandBlock structure.
63 
64     50    03/02/28 5:30p Ooshima
65     Changed DVDCommandBlock and DVDDirEntry structure for DVDETH again
66 
67     49    03/01/09 10:34a Ooshima
68     Changed DVDCommandBlock and DVDDirEntry structure for DVDETH
69 
70     47    8/22/02 12:00 Shiki
71     Clean up.
72 
73     46    8/20/02 21:38 Shiki
74     Added DVDSetAutoFatalMessaging().
75 
76     45    8/05/02 16:19 Shiki
77     Added const keywords to relevant function prototypes.
78 
79     44    02/02/07 16:04 Hashida
80     Change the return value of DVDGenerateDiskID from void to DVDDiskID*
81 
82     43    1/02/02 5:00p Hashida
83     Added DVDCompareDiskID and DVDGenerateDiskID.
84 
85     42    8/10/01 3:04p Hashida
86     Added DVDFastOpenDir
87 
88     41    7/06/01 1:20a Hashida
89     Resurrected function version of DVDGetFileInfoStatus().
90 
91     40    6/29/01 11:43a Hashida
92     Added DVDCheckDisk().
93 
94     39    6/26/01 9:18a Hashida
95     Modified so that DVDGetFileInfoStatus is properly prototype'd for MAC
96     build.
97 
98     38    6/15/01 10:35p Hashida
99     Deleted obsolete result codes.
100 
101     37    6/15/01 9:01p Hashida
102     Changed DVDGetFileInfoStatus to a macro.
103 
104     36    5/29/01 11:52a Hashida
105     Removed duplicated DVDPause and DVDResume prototypes.
106 
107     35    5/10/01 2:24p Hashida
108     Added DVDDumpWaitingQueue.
109 
110     34    5/01/01 2:49p Hashida
111     Removed DVDGetStreamStartAddr & DVDGetStreamLength.
112 
113     33    4/19/01 5:40p Hashida
114     Added DVDGetCurrentDiskID
115 
116     32    3/22/01 6:10p Hashida
117     Added DVDCancelAll and DVDCancelAllAsync.
118     Moved DVDCommandBlock structure in DVDFileInfo to the first member.
119 
120     31    3/02/01 5:48p Hashida
121     Modified error code handling (fatal error, internal retry and retry)
122 
123     30    3/02/01 11:35a Hashida
124     Added DVDCancel, DVDPause, DVDResume, DVDGetTransferredSize.
125 
126     29    2/08/01 3:46p Hashida
127     Added DVDPause and DVDResume prototypes.
128 
129     28    1/08/01 7:02p Hashida
130     Added DVDSet/GetUserData macros.
131 
132     27    11/13/00 5:30p Hashida
133     Added streamingBufSize member to diskid.
134 
135 
136     26    10/27/00 2:24p Hashida
137     Added a check code so that audio streaming command will not be issued
138     while a track is auto finishing.
139 
140     25    10/10/00 11:28a Hashida
141     Fixed a problem that MAC target won't be built.
142 
143     24    10/09/00 6:53p Hashida
144     Added prioritized queuing.
145 
146     23    9/29/00 9:51p Hirose
147     replaced "MAC" flag by better alternatives
148 
149     22    9/26/00 3:38p Hashida
150     Added DVDChangeDisk (synchronous version)
151 
152     21    9/25/00 3:32p Hashida
153     Changed API names that don't follow the convention (sync, async)
154 
155     20    7/21/00 11:15a Hashida
156     Added DVD_STATE_PAUSING.
157 
158     19    7/20/00 12:32p Hashida
159     Removed DVDConvertEntrynumToPath
160 
161     18    7/20/00 9:46a Hashida
162     Added DVDFastOpen(), DVDConvertPathToEntrynum and
163     DVDConvertEntrynumToPath.
164 
165     17    7/07/00 6:00p Dante
166     PC Compatibility
167 
168     16    5/14/00 8:06p Hashida
169     Added DVDGetCurrentDir
170 
171     15    5/10/00 5:24p Hashida
172     Removed relocate FST function.
173 
174     14    4/13/00 5:21p Hashida
175     Added DVD_RESULT_* definitions for streaming commands.
176     Added more streaming APIs' prototypes.
177 
178     13    4/12/00 3:58p Hashida
179     Added audio streaming stuffs.
180 
181     12    4/12/00 1:31p Hashida
182     Misc. change.
183 
184     11    3/29/00 2:29p Hashida
185     Added DVDGetDirEntryName and DVDDirEntryIsDir
186 
187     10    3/28/00 3:42p Hashida
188     Added directory accessing functions to MAC build.
189 
190     9     3/13/00 2:46p Hashida
191     Added DVDGetFSTLocation.
192 
193     8     3/10/00 2:38p Hashida
194     Added DVDRelocateFST
195 
196     7     3/02/00 3:00p Ryan
197     Added DVDChangeDir to MAC build
198 
199     6     3/01/00 1:13p Hashida
200     Renamed DVDDirEntry->filename to name.
201 
202     5     2/29/00 7:57p Hashida
203     Added directory access support.
204 
205     4     2/02/00 6:28p Tian
206     Halved size of DVD_FST_MAX_SIZE
207 
208     3     1/13/00 12:14p Hashida
209     Added directory access functions for future use.
210 
211     21    10/06/99 10:33a Hashida
212     Changed the filename length limit to 200 chars.
213 
214     20    9/09/99 5:55p Hashida
215     Removed warnings.
216 
217     19    8/26/99 5:37p Hashida
218     Added DVDSetAutoInvalidation
219 
220     18    7/21/99 11:52p Hashida
221     Added DVD_MIN_TRANSFER_SIZE
222 
223     17    7/21/99 9:47p Hashida
224     Added DVDSeek(), DVDChangeDir(), DVDChangeDisk()
225 
226     16    7/20/99 2:37p Hashida
227     Changed DVDFileInfo structure for EPPC
228     Removed DVD_RESULT_GOOD
229 
230     15    7/19/99 11:45p Hashida
231     changed the value for fatal error to -1
232 
233     14    7/19/99 4:29p Hashida
234     Added DVDCommandBlockStatus and DVDDriveStatus.
235 
236     13    7/19/99 2:58p Hashida
237     added DVD_FST_MAX_SIZE, DVD_STATE*, DVD_RESULT* and DVDCommandBlock.
238 
239     12    7/09/99 9:59p Hashida
240     added DVDDiskID structure
241 
242     9     6/12/99 12:11a Hashida
243     Added DVDSetRoot()
244 
245     8     6/11/99 3:04p Shiki
246     Added DVDGetFileInfoStatus().
247 
248     7     6/04/99 3:14p Hashida
249     fixed small mistakes
250 
251     6     5/28/99 1:34p Shiki
252     Fixed DVDReadAll() and DVDReadAllAsync() macros.
253 
254     5     5/11/99 4:42p Shiki
255     Refreshed include tree.
256 
257     3     4/30/99 4:22p Shiki
258     Added DVDInit() declaration.
259 
260     2     4/30/99 4:02p Shiki
261     Supported DVDReadAsync().
262 
263     1     4/29/99 2:51p Shiki
264 
265   $NoKeywords: $
266  *---------------------------------------------------------------------------*/
267 
268 #ifndef __DVD_H__
269 #define __DVD_H__
270 
271 #ifdef  MACOS
272 #include <OSUtils.h>
273 #include <Gestalt.h>
274 #include <Files.h>
275 #endif  // MACOS
276 
277 #ifdef WIN32
278 #include <windows.h>
279 #endif
280 
281 #include <revolution/types.h>
282 
283 #ifdef __cplusplus
284 extern "C" {
285 #endif
286 
287 #ifdef MACOS
288 // the following is a restriction that only exists on Mac emulator
289 #define DVD_PATH_MAX    200  // The number of bytes in an absolute pathname
290                              // excluding terminating '\0'.
291 #endif
292 
293 typedef struct DVDDiskID DVDDiskID;
294 
295 struct DVDDiskID
296 {
297     char      gameName[4];
298     char      company[2];
299     u8        diskNumber;
300     u8        gameVersion;
301     u8        streaming;
302     u8        streamingBufSize; // 0 = default
303     u8        padding[14];      // 0's are stored
304     u32       rvlMagic;         // Revolution disk magic number
305     u32       gcMagic;          // GC magic number is here
306 };
307 
308 typedef struct DVDCommandBlock DVDCommandBlock;
309 
310 typedef void (*DVDCBCallback)(s32 result, DVDCommandBlock* block);
311 
312 struct DVDCommandBlock
313 {
314     DVDCommandBlock* next;
315     DVDCommandBlock* prev;
316     u32              command;
317     s32              state;
318     u32              offset;
319     u32              length;
320     void*            addr;
321     u32              currTransferSize;
322     u32              transferredSize;
323     DVDDiskID*       id;
324     DVDCBCallback    callback;
325     void*            userData;
326 };
327 
328 typedef struct DVDFileInfo  DVDFileInfo;
329 
330 /*---------------------------------------------------------------------------*
331   Name:         DVDCallback
332 
333   Description:  DVD callback function
334 
335   Arguments:    result      If the function that set the callback succeeds,
336                             it is the number of bytes transferred. If that
337                             function fails, it is -1.
338 
339   Returns:      None.
340  *---------------------------------------------------------------------------*/
341 typedef void (*DVDCallback)(s32 result, DVDFileInfo* fileInfo);
342 
343 struct DVDFileInfo
344 {
345 #ifndef MACOS
346     DVDCommandBlock cb;
347 #endif
348 
349     u32             startAddr;      // disk address of file
350     u32             length;         // file size in bytes
351 
352 #ifdef MACOS
353     DVDFileInfo*    next;
354 #endif  // MACOS
355     DVDCallback     callback;
356 
357 #ifdef WIN32
358     FILE * file;
359 #endif
360 
361 #ifdef  MACOS
362     IOParam         pb;
363 #endif  // MACOS
364 
365 };
366 
367 typedef struct
368 {
369     u32         entryNum;
370     u32         location;
371     u32         next;
372 } DVDDir;
373 
374 typedef struct
375 {
376     u32         entryNum;
377     BOOL        isDir;
378     char*       name;
379 } DVDDirEntry;
380 
381 
382 // FST maximum size
383 #ifndef MINNOW
384 #define DVD_FST_MAX_SIZE          0x00100000
385 #else // MINNOW
386 #define DVD_FST_MAX_SIZE          0x00080000
387 #endif
388 
389 #define DVD_MIN_TRANSFER_SIZE     32
390 
391 #define DVD_STATE_FATAL_ERROR     -1
392 #define DVD_STATE_END             0
393 #define DVD_STATE_BUSY            1
394 #define DVD_STATE_WAITING         2
395 #define DVD_STATE_COVER_CLOSED    3         // internal state. never returns.
396 #define DVD_STATE_NO_DISK         4
397 #define DVD_STATE_COVER_OPEN      5
398 #define DVD_STATE_WRONG_DISK      6
399 #define DVD_STATE_MOTOR_STOPPED   7
400 #define DVD_STATE_PAUSING         8
401 #define DVD_STATE_IGNORED         9
402 #define DVD_STATE_CANCELED        10
403 #define DVD_STATE_RETRY           11
404 #define DVD_STATE_NO_INPUT        12
405 
406 #define DVD_FILEINFO_READY        0
407 #define DVD_FILEINFO_BUSY         1
408 
409 #define DVD_RESULT_GOOD           0
410 #define DVD_RESULT_FATAL_ERROR    -1
411 #define DVD_RESULT_IGNORED        -2
412 #define DVD_RESULT_CANCELED       -3
413 
414 #define DVD_AIS_SUCCESS           0x0
415 
416 #define DVDGetStartAddr(fileInfo)                               \
417         ((u64)((u64)(fileInfo)->startAddr) << 2)
418 
419 #define DVDGetLength(fileInfo)                                  \
420         ((fileInfo)->length)
421 
422 void DVDInit             ( void );
423 
424 BOOL DVDOpen             ( const char* fileName, DVDFileInfo* fileInfo );
425 BOOL DVDFastOpen         ( s32 entrynum, DVDFileInfo* fileInfo );
426 
427 #ifndef MACOS
428 s32  DVDReadPrio         ( DVDFileInfo* fileInfo, void* addr, s32 length,
429                            s32 offset, s32 prio );
430 
431 BOOL DVDReadAsyncPrio    ( DVDFileInfo* fileInfo, void* addr, s32 length,
432                            s32 offset,
433                            DVDCallback callback, s32 prio );
434 
435 #define DVDRead(fileInfo, addr, length, offset)                 \
436                          DVDReadPrio((fileInfo), (addr), (length), (offset), 2)
437 #define DVDReadAsync(fileInfo, addr, length, offset, callback)  \
438                          DVDReadAsyncPrio((fileInfo), (addr), (length), (offset), (callback), 2)
439 #else
440 s32  DVDRead             ( DVDFileInfo* fileInfo, void* addr, s32 length,
441                            s32 offset );
442 
443 BOOL DVDReadAsync        ( DVDFileInfo* fileInfo, void* addr, s32 length,
444                            s32 offset,
445                            DVDCallback callback );
446 #endif
447 
448 BOOL DVDClose            ( DVDFileInfo* fileInfo );
449 
450 #ifndef MACOS
451 BOOL DVDGetCurrentDir    ( char* path, u32 maxlen );
452 #endif
453 
454 BOOL DVDChangeDir        ( const char* dirName );
455 
456 #ifdef MACOS
457 BOOL DVDMovePickup       ( DVDFileInfo* fileInfo,
458                            s32 offset,
459                            DVDCallback callback );
460 #else  // EPPC
461 s32  DVDSeekPrio         ( DVDFileInfo* fileInfo,
462                            s32 offset, s32 prio );
463 
464 BOOL DVDSeekAsyncPrio    ( DVDFileInfo* fileInfo,
465                            s32 offset,
466                            DVDCallback callback, s32 prio );
467 
468 #define DVDSeek(fileInfo, offset)                               \
469                          DVDSeekPrio((fileInfo), (offset), 2)
470 #define DVDSeekAsync(fileInfo, offset, callback)                \
471                          DVDSeekAsyncPrio((fileInfo), (offset), (callback), 2)
472 
473 s32  DVDChangeDisk       ( DVDCommandBlock* block, DVDDiskID* id );
474 
475 BOOL DVDChangeDiskAsync  ( DVDCommandBlock* block, DVDDiskID* id,
476                            DVDCBCallback callback );
477 #endif
478 
479 s32  DVDGetCommandBlockStatus
480                          ( const DVDCommandBlock* block );
481 
482 s32  DVDGetFileInfoStatus( const DVDFileInfo* fileInfo );
483 
484 #define DVDGetFileInfoStatus(fileinfo)                          \
485                          DVDGetCommandBlockStatus(&(fileinfo)->cb)
486 
487 s32  DVDGetDriveStatus   ( void );
488 
489 BOOL DVDSetAutoInvalidation
490                          ( BOOL autoInval );
491 
492 void* DVDGetFSTLocation  ( void );
493 
494 #ifdef MACOS
495 void DVDSetRoot          ( const char *rootPath );
496 #endif
497 #ifdef WIN32
498 void DVDSetRoot          ( const char *rootPath );
499 #endif
500 
501 s32  DVDConvertPathToEntrynum
502                          ( const char* pathPtr );
503 
504 BOOL DVDEntrynumIsDir    ( s32 entrynum );
505 
506 // Directory access functions
507 BOOL DVDOpenDir          ( const char* dirName, DVDDir* dir );
508 BOOL DVDFastOpenDir      ( s32 entrynum, DVDDir* dir );
509 BOOL DVDReadDir          ( DVDDir* dir, DVDDirEntry* dirent );
510 BOOL DVDCloseDir         ( DVDDir* dir );
511 
512 void DVDPause            ( void );
513 void DVDResume           ( void );
514 
515 /*---------------------------------------------------------------------------*
516   Name:         DVDTellDir
517 
518   Description:  Returns the current location associated with the directory
519 
520   Arguments:    dir         Pre-opened DVDDir* structure
521 
522   Returns:      current location
523  *---------------------------------------------------------------------------*/
524 #define DVDTellDir(dir)             ((dir)->location)
525 
526 /*---------------------------------------------------------------------------*
527   Name:         DVDSeekDir
528 
529   Description:  Sets the position of the next DVDReadDir on the directory
530 
531   Arguments:    dir         Pre-opened DVDDir* structure
532                 loc         location to set
533 
534   Returns:      None
535  *---------------------------------------------------------------------------*/
536 #define DVDSeekDir(dir, loc)        ((dir)->location = loc)
537 
538 /*---------------------------------------------------------------------------*
539   Name:         DVDRewindDir
540 
541   Description:  Resets the position of the directory to the beginning
542 
543   Arguments:    dir         Pre-opened DVDDir* structure
544 
545   Returns:      None
546  *---------------------------------------------------------------------------*/
547 void DVDRewindDir(DVDDir* dir);
548 
549 #define DVDGetDirEntryName(dirent)  ((dirent)->name)
550 #define DVDDirEntryIsDir(dirent)    ((dirent)->isDir)
551 
552 /*---------------------------------------------------------------------------*
553   Name:         DVDSetUserData
554 
555   Description:  Set user data in command block
556 
557   Arguments:    block       Command block
558                 data        Data to set
559 
560   Returns:      None
561  *---------------------------------------------------------------------------*/
562 #define DVDSetUserData(block, data) ((block)->userData = (data))
563 
564 /*---------------------------------------------------------------------------*
565   Name:         DVDGetUserData
566 
567   Description:  Get user data in command block
568 
569   Arguments:    block       Command block
570 
571   Returns:      data (void * type)
572  *---------------------------------------------------------------------------*/
573 #define DVDGetUserData(block)       ((block)->userData)
574 
575 #ifndef EMU
576 
577 BOOL DVDCancelAsync(DVDCommandBlock* block, DVDCBCallback callback);
578 s32 DVDCancel(DVDCommandBlock* block);
579 BOOL DVDCancelAllAsync(DVDCBCallback callback);
580 s32 DVDCancelAll(void);
581 
582 s32 DVDGetTransferredSize(DVDFileInfo* fileinfo);
583 
584 DVDDiskID* DVDGetCurrentDiskID(void);
585 
586 void DVDDumpWaitingQueue(void);
587 
588 BOOL DVDCheckDiskAsync(DVDCommandBlock* block, DVDCBCallback callback);
589 
590 BOOL DVDCompareDiskID(const DVDDiskID* id1, const DVDDiskID* id2);
591 
592 DVDDiskID* DVDGenerateDiskID(DVDDiskID* id, const char* game, const char* company,
593                              u8 diskNum, u8 version);
594 
595 BOOL DVDSetAutoFatalMessaging(BOOL enable);
596 
597 BOOL DVDIsDiskIdentified(void);
598 
599 BOOL DVDConvertEntrynumToPath(s32 entrynum, char* path, u32 maxlen);
600 s32 DVDGetEntrynum(const DVDFileInfo* fileInfo);
601 const char* DVDGetEntryName(s32 entrynum);
602 
603 #define DVDGetDirEntryEntrynum(dirent)  ((s32)((dirent)->entryNum))
604 #define DVDGetDirEntrynum(dir)          ((s32)((dir)->entryNum))
605 
606 #endif
607 
608 #ifdef __cplusplus
609 }
610 #endif
611 
612 #endif  // __DVD_H__
613