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