1 /*
2  * SDL_cdrom.h
3  *
4  * Written by
5  *  Sam Lantinga <slouken@libsdl.org>
6  *
7  * This file is a modified SDL header.
8  *
9  * This file is part of VICE, the Versatile Commodore Emulator.
10  * See README for copyright notice.
11  *
12  *  This program is free software; you can redistribute it and/or modify
13  *  it under the terms of the GNU General Public License as published by
14  *  the Free Software Foundation; either version 2 of the License, or
15  *  (at your option) any later version.
16  *
17  *  This program is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *  GNU General Public License for more details.
21  *
22  *  You should have received a copy of the GNU General Public License
23  *  along with this program; if not, write to the Free Software
24  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25  *  02111-1307  USA.
26  *
27  */
28 
29 /**
30  *  @file SDL_cdrom.h
31  *  This is the CD-audio control API for Simple DirectMedia Layer
32  */
33 
34 #ifndef _SDL_cdrom_h
35 #define _SDL_cdrom_h
36 
37 #include "SDL_stdinc.h"
38 #include "SDL_error.h"
39 
40 #include "begin_code.h"
41 /* Set up for C function definitions, even when using C++ */
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /**
47  *  @file SDL_cdrom.h
48  *  In order to use these functions, SDL_Init() must have been called
49  *  with the SDL_INIT_CDROM flag.  This causes SDL to scan the system
50  *  for CD-ROM drives, and load appropriate drivers.
51  */
52 
53 /** The maximum number of CD-ROM tracks on a disk */
54 #define SDL_MAX_TRACKS   99
55 
56 /** @name Track Types
57  *  The types of CD-ROM track possible
58  */
59 /*@{*/
60 #define SDL_AUDIO_TRACK   0x00
61 #define SDL_DATA_TRACK    0x04
62 /*@}*/
63 
64 /** The possible states which a CD-ROM drive can be in. */
65 typedef enum {
66 	CD_TRAYEMPTY,
67 	CD_STOPPED,
68 	CD_PLAYING,
69 	CD_PAUSED,
70 	CD_ERROR = -1
71 } CDstatus;
72 
73 /** Given a status, returns true if there's a disk in the drive */
74 #define CD_INDRIVE(status)   ((int)(status) > 0)
75 
76 typedef struct SDL_CDtrack {
77 	Uint8 id;			/**< Track number */
78 	Uint8 type;		/**< Data or audio track */
79 	Uint16 unused;
80 	Uint32 length;		/**< Length, in frames, of this track */
81 	Uint32 offset;		/**< Offset, in frames, from start of disk */
82 } SDL_CDtrack;
83 
84 /** This structure is only current as of the last call to SDL_CDStatus() */
85 typedef struct SDL_CD {
86 	int id;			/**< Private drive identifier */
87 	CDstatus status;	/**< Current drive status */
88 
89 	/** The rest of this structure is only valid if there's a CD in drive */
90         /*@{*/
91 	int numtracks;		/**< Number of tracks on disk */
92 	int cur_track;		/**< Current track position */
93 	int cur_frame;		/**< Current frame offset within current track */
94 	SDL_CDtrack track[SDL_MAX_TRACKS+1];
95         /*@}*/
96 } SDL_CD;
97 
98 /** @name Frames / MSF Conversion Functions
99  *  Conversion functions from frames to Minute/Second/Frames and vice versa
100  */
101 /*@{*/
102 #define CD_FPS   75
103 #define FRAMES_TO_MSF(f, M,S,F)	{ \
104 	int value = f;               \
105 	*(F) = value % CD_FPS;       \
106 	value /= CD_FPS;             \
107 	*(S) = value % 60;           \
108 	value /= 60;                 \
109 	*(M) = value;                \
110 }
111 
112 #define MSF_TO_FRAMES(M, S, F)   ((M) * 60 * CD_FPS + (S) * CD_FPS + (F))
113 /*@}*/
114 
115 /* CD-audio API functions: */
116 
117 /**
118  *  Returns the number of CD-ROM drives on the system, or -1 if
119  *  SDL_Init() has not been called with the SDL_INIT_CDROM flag.
120  */
121 extern DECLSPEC int SDLCALL SDL_CDNumDrives(void);
122 
123 /**
124  *  Returns a human-readable, system-dependent identifier for the CD-ROM.
125  *  Example:
126  *   - "/dev/cdrom"
127  *   - "E:"
128  *   - "/dev/disk/ide/1/master"
129  */
130 extern DECLSPEC const char * SDLCALL SDL_CDName(int drive);
131 
132 /**
133  *  Opens a CD-ROM drive for access.  It returns a drive handle on success,
134  *  or NULL if the drive was invalid or busy.  This newly opened CD-ROM
135  *  becomes the default CD used when other CD functions are passed a NULL
136  *  CD-ROM handle.
137  *  Drives are numbered starting with 0.  Drive 0 is the system default CD-ROM.
138  */
139 extern DECLSPEC SDL_CD * SDLCALL SDL_CDOpen(int drive);
140 
141 /**
142  *  This function returns the current status of the given drive.
143  *  If the drive has a CD in it, the table of contents of the CD and current
144  *  play position of the CD will be stored in the SDL_CD structure.
145  */
146 extern DECLSPEC CDstatus SDLCALL SDL_CDStatus(SDL_CD *cdrom);
147 
148 /**
149  *  Play the given CD starting at 'start_track' and 'start_frame' for 'ntracks'
150  *  tracks and 'nframes' frames.  If both 'ntrack' and 'nframe' are 0, play
151  *  until the end of the CD.  This function will skip data tracks.
152  *  This function should only be called after calling SDL_CDStatus() to
153  *  get track information about the CD.
154  *  For example:
155  *      @code
156  *	// Play entire CD:
157  *	if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
158  *		SDL_CDPlayTracks(cdrom, 0, 0, 0, 0);
159  *	// Play last track:
160  *	if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) {
161  *		SDL_CDPlayTracks(cdrom, cdrom->numtracks-1, 0, 0, 0);
162  *	}
163  *	// Play first and second track and 10 seconds of third track:
164  *	if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
165  *		SDL_CDPlayTracks(cdrom, 0, 0, 2, 10);
166  *      @endcode
167  *
168  *  @return This function returns 0, or -1 if there was an error.
169  */
170 extern DECLSPEC int SDLCALL SDL_CDPlayTracks(SDL_CD *cdrom,
171 		int start_track, int start_frame, int ntracks, int nframes);
172 
173 /**
174  *  Play the given CD starting at 'start' frame for 'length' frames.
175  *  @return It returns 0, or -1 if there was an error.
176  */
177 extern DECLSPEC int SDLCALL SDL_CDPlay(SDL_CD *cdrom, int start, int length);
178 
179 /** Pause play
180  *  @return returns 0, or -1 on error
181  */
182 extern DECLSPEC int SDLCALL SDL_CDPause(SDL_CD *cdrom);
183 
184 /** Resume play
185  *  @return returns 0, or -1 on error
186  */
187 extern DECLSPEC int SDLCALL SDL_CDResume(SDL_CD *cdrom);
188 
189 /** Stop play
190  *  @return returns 0, or -1 on error
191  */
192 extern DECLSPEC int SDLCALL SDL_CDStop(SDL_CD *cdrom);
193 
194 /** Eject CD-ROM
195  *  @return returns 0, or -1 on error
196  */
197 extern DECLSPEC int SDLCALL SDL_CDEject(SDL_CD *cdrom);
198 
199 /** Closes the handle for the CD-ROM drive */
200 extern DECLSPEC void SDLCALL SDL_CDClose(SDL_CD *cdrom);
201 
202 
203 /* Ends C function definitions when using C++ */
204 #ifdef __cplusplus
205 }
206 #endif
207 #include "close_code.h"
208 
209 #endif /* _SDL_video_h */
210