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