Mercurial > sdl-ios-xcode
annotate src/cdrom/mint/SDL_syscdrom.c @ 1367:e440d5c488c1
Fixes for BeOS and Solaris builds
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 17 Feb 2006 08:43:23 +0000 |
parents | 19418e4422cb |
children | d910939febfa |
rev | line source |
---|---|
724 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
727
diff
changeset
|
3 Copyright (C) 1997-2004 Sam Lantinga |
724 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@libsdl.org | |
21 */ | |
22 | |
23 /* | |
24 Atari MetaDOS CD-ROM functions | |
25 | |
26 Patrice Mandin | |
27 */ | |
28 | |
29 #include <errno.h> | |
30 | |
31 #include <cdromio.h> | |
32 #include <metados.h> | |
33 | |
34 #include "SDL_cdrom.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
35 #include "../SDL_syscdrom.h" |
724 | 36 |
727
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
37 /* Some ioctl() errno values which occur when the tray is empty */ |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
38 #ifndef ENOMEDIUM |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
39 #define ENOMEDIUM ENOENT |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
40 #endif |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
41 #define ERRNO_TRAYEMPTY(errno) \ |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
42 ((errno == EIO) || (errno == ENOENT) || \ |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
43 (errno == EINVAL) || (errno == ENOMEDIUM)) |
724 | 44 |
45 /* The maximum number of CD-ROM drives we'll detect */ | |
46 #define MAX_DRIVES 32 | |
47 | |
48 typedef struct { | |
49 unsigned char device[3]; /* Physical device letter + ':' + '\0' */ | |
50 metaopen_t metaopen; /* Infos on opened drive */ | |
51 } metados_drive_t; | |
52 | |
53 static metados_drive_t metados_drives[MAX_DRIVES]; | |
54 | |
55 /* The system-dependent CD control functions */ | |
56 static const char *SDL_SYS_CDName(int drive); | |
57 static int SDL_SYS_CDOpen(int drive); | |
58 static void SDL_SYS_CDClose(SDL_CD *cdrom); | |
59 static int SDL_SYS_CDioctl(int id, int command, void *arg); | |
60 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); | |
61 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); | |
62 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); | |
63 static int SDL_SYS_CDPause(SDL_CD *cdrom); | |
64 static int SDL_SYS_CDResume(SDL_CD *cdrom); | |
65 static int SDL_SYS_CDStop(SDL_CD *cdrom); | |
66 static int SDL_SYS_CDEject(SDL_CD *cdrom); | |
67 | |
68 int SDL_SYS_CDInit(void) | |
69 { | |
70 metainit_t metainit={0,0,0,0}; | |
71 metaopen_t metaopen; | |
72 int i, handle; | |
727
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
73 struct cdrom_subchnl info; |
724 | 74 |
75 Metainit(&metainit); | |
76 if (metainit.version == NULL) { | |
77 #ifdef DEBUG_CDROM | |
78 fprintf(stderr, "MetaDOS not installed\n"); | |
79 #endif | |
80 return -1; | |
81 } | |
82 | |
83 if (metainit.drives_map == 0) { | |
84 #ifdef DEBUG_CDROM | |
85 fprintf(stderr, "No MetaDOS devices present\n"); | |
86 #endif | |
87 return -1; | |
88 } | |
89 | |
90 SDL_numcds = 0; | |
91 | |
92 for (i='A'; i<='Z'; i++) { | |
93 metados_drives[SDL_numcds].device[0] = 0; | |
94 metados_drives[SDL_numcds].device[1] = ':'; | |
95 metados_drives[SDL_numcds].device[2] = 0; | |
96 | |
97 if (metainit.drives_map & (1<<(i-'A'))) { | |
98 handle = Metaopen(i, &metaopen); | |
99 if (handle == 0) { | |
100 | |
727
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
101 info.cdsc_format = CDROM_MSF; |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
102 if ( (Metaioctl(i, METADOS_IOCTL_MAGIC, CDROMSUBCHNL, &info) == 0) || ERRNO_TRAYEMPTY(errno) ) { |
724 | 103 metados_drives[SDL_numcds].device[0] = i; |
104 ++SDL_numcds; | |
105 } | |
106 | |
107 Metaclose(i); | |
108 } | |
109 } | |
110 } | |
111 | |
112 /* Fill in our driver capabilities */ | |
113 SDL_CDcaps.Name = SDL_SYS_CDName; | |
114 SDL_CDcaps.Open = SDL_SYS_CDOpen; | |
115 SDL_CDcaps.Close = SDL_SYS_CDClose; | |
116 | |
117 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; | |
118 SDL_CDcaps.Status = SDL_SYS_CDStatus; | |
119 SDL_CDcaps.Play = SDL_SYS_CDPlay; | |
120 SDL_CDcaps.Pause = SDL_SYS_CDPause; | |
121 SDL_CDcaps.Resume = SDL_SYS_CDResume; | |
122 SDL_CDcaps.Stop = SDL_SYS_CDStop; | |
123 SDL_CDcaps.Eject = SDL_SYS_CDEject; | |
124 | |
125 return 0; | |
126 } | |
127 | |
128 void SDL_SYS_CDQuit(void) | |
129 { | |
130 SDL_numcds = 0; | |
131 } | |
132 | |
133 static const char *SDL_SYS_CDName(int drive) | |
134 { | |
135 return(metados_drives[drive].device); | |
136 } | |
137 | |
138 static int SDL_SYS_CDOpen(int drive) | |
139 { | |
140 int handle; | |
141 | |
142 handle = Metaopen(metados_drives[drive].device[0], &(metados_drives[drive].metaopen)); | |
143 if (handle == 0) { | |
144 return drive; | |
145 } | |
146 | |
147 return -1; | |
148 } | |
149 | |
150 static void SDL_SYS_CDClose(SDL_CD *cdrom) | |
151 { | |
152 Metaclose(metados_drives[cdrom->id].device[0]); | |
153 } | |
154 | |
155 static int SDL_SYS_CDioctl(int id, int command, void *arg) | |
156 { | |
157 int retval; | |
158 | |
159 retval = Metaioctl(metados_drives[id].device[0], METADOS_IOCTL_MAGIC, command, arg); | |
160 if ( retval < 0 ) { | |
161 SDL_SetError("ioctl() error: %s", strerror(errno)); | |
162 } | |
163 return(retval); | |
164 } | |
165 | |
166 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) | |
167 { | |
168 int i,okay; | |
169 struct cdrom_tochdr toc; | |
170 struct cdrom_tocentry entry; | |
171 | |
172 /* Use standard ioctl() */ | |
173 if (SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCHDR, &toc)<0) { | |
174 return -1; | |
175 } | |
176 | |
177 cdrom->numtracks = toc.cdth_trk1-toc.cdth_trk0+1; | |
178 if ( cdrom->numtracks > SDL_MAX_TRACKS ) { | |
179 cdrom->numtracks = SDL_MAX_TRACKS; | |
180 } | |
181 | |
182 /* Read all the track TOC entries */ | |
183 okay=1; | |
184 for ( i=0; i<=cdrom->numtracks; ++i ) { | |
185 if ( i == cdrom->numtracks ) { | |
186 cdrom->track[i].id = CDROM_LEADOUT; | |
187 } else { | |
188 cdrom->track[i].id = toc.cdth_trk0+i; | |
189 } | |
190 entry.cdte_track = cdrom->track[i].id; | |
191 entry.cdte_format = CDROM_MSF; | |
192 if ( SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCENTRY, &entry) < 0 ) { | |
193 okay=0; | |
194 break; | |
195 } else { | |
196 if ( entry.cdte_ctrl & CDROM_DATA_TRACK ) { | |
197 cdrom->track[i].type = SDL_DATA_TRACK; | |
198 } else { | |
199 cdrom->track[i].type = SDL_AUDIO_TRACK; | |
200 } | |
201 cdrom->track[i].offset = MSF_TO_FRAMES( | |
202 entry.cdte_addr.msf.minute, | |
203 entry.cdte_addr.msf.second, | |
204 entry.cdte_addr.msf.frame); | |
205 cdrom->track[i].length = 0; | |
206 if ( i > 0 ) { | |
207 cdrom->track[i-1].length = cdrom->track[i].offset-cdrom->track[i-1].offset; | |
208 } | |
209 } | |
210 } | |
211 | |
212 return(okay ? 0 : -1); | |
213 } | |
214 | |
215 /* Get CD-ROM status */ | |
216 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) | |
217 { | |
218 CDstatus status; | |
219 struct cdrom_tochdr toc; | |
220 struct cdrom_subchnl info; | |
221 | |
222 info.cdsc_format = CDROM_MSF; | |
223 if ( SDL_SYS_CDioctl(cdrom->id, CDROMSUBCHNL, &info) < 0 ) { | |
727
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
224 if ( ERRNO_TRAYEMPTY(errno) ) { |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
225 status = CD_TRAYEMPTY; |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
226 } else { |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
227 status = CD_ERROR; |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
228 } |
724 | 229 } else { |
230 switch (info.cdsc_audiostatus) { | |
231 case CDROM_AUDIO_INVALID: | |
232 case CDROM_AUDIO_NO_STATUS: | |
233 /* Try to determine if there's a CD available */ | |
234 if (SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCHDR, &toc)==0) { | |
235 status = CD_STOPPED; | |
236 } else { | |
237 status = CD_TRAYEMPTY; | |
238 } | |
239 break; | |
240 case CDROM_AUDIO_COMPLETED: | |
241 status = CD_STOPPED; | |
242 break; | |
243 case CDROM_AUDIO_PLAY: | |
244 status = CD_PLAYING; | |
245 break; | |
246 case CDROM_AUDIO_PAUSED: | |
247 /* Workaround buggy CD-ROM drive */ | |
248 if ( info.cdsc_trk == CDROM_LEADOUT ) { | |
249 status = CD_STOPPED; | |
250 } else { | |
251 status = CD_PAUSED; | |
252 } | |
253 break; | |
254 default: | |
255 status = CD_ERROR; | |
256 break; | |
257 } | |
258 } | |
259 if ( position ) { | |
260 if ( status == CD_PLAYING || (status == CD_PAUSED) ) { | |
261 *position = MSF_TO_FRAMES( | |
262 info.cdsc_absaddr.msf.minute, | |
263 info.cdsc_absaddr.msf.second, | |
264 info.cdsc_absaddr.msf.frame); | |
265 } else { | |
266 *position = 0; | |
267 } | |
268 } | |
269 return(status); | |
270 } | |
271 | |
272 /* Start play */ | |
273 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) | |
274 { | |
275 struct cdrom_msf playtime; | |
276 | |
277 FRAMES_TO_MSF(start, | |
278 &playtime.cdmsf_min0, &playtime.cdmsf_sec0, &playtime.cdmsf_frame0); | |
279 FRAMES_TO_MSF(start+length, | |
280 &playtime.cdmsf_min1, &playtime.cdmsf_sec1, &playtime.cdmsf_frame1); | |
281 #ifdef DEBUG_CDROM | |
282 fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", | |
283 playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0, | |
284 playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1); | |
285 #endif | |
727
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
286 |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
287 return SDL_SYS_CDioctl(cdrom->id, CDROMPLAYMSF, &playtime); |
724 | 288 } |
289 | |
290 /* Pause play */ | |
291 static int SDL_SYS_CDPause(SDL_CD *cdrom) | |
292 { | |
727
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
293 return SDL_SYS_CDioctl(cdrom->id, CDROMPAUSE, 0); |
724 | 294 } |
295 | |
296 /* Resume play */ | |
297 static int SDL_SYS_CDResume(SDL_CD *cdrom) | |
298 { | |
727
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
299 return SDL_SYS_CDioctl(cdrom->id, CDROMRESUME, 0); |
724 | 300 } |
301 | |
302 /* Stop play */ | |
303 static int SDL_SYS_CDStop(SDL_CD *cdrom) | |
304 { | |
727
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
305 return SDL_SYS_CDioctl(cdrom->id, CDROMSTOP, 0); |
724 | 306 } |
307 | |
308 /* Eject the CD-ROM */ | |
309 static int SDL_SYS_CDEject(SDL_CD *cdrom) | |
310 { | |
727
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
311 return SDL_SYS_CDioctl(cdrom->id, CDROMEJECT, 0); |
724 | 312 } |