Mercurial > sdl-ios-xcode
annotate src/cdrom/mint/SDL_syscdrom.c @ 1350:adc8ff3c9597
Fixes for new SDL embedded libc stuff
author | Patrice Mandin <patmandin@gmail.com> |
---|---|
date | Wed, 08 Feb 2006 18:59:49 +0000 |
parents | 604d73db6802 |
children | c71e05b4dc2e |
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_error.h" | |
35 #include "SDL_cdrom.h" | |
1350
adc8ff3c9597
Fixes for new SDL embedded libc stuff
Patrice Mandin <patmandin@gmail.com>
parents:
1338
diff
changeset
|
36 #include "SDL_string.h" |
724 | 37 #include "SDL_syscdrom.h" |
38 | |
727
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
39 /* 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
|
40 #ifndef ENOMEDIUM |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
41 #define ENOMEDIUM ENOENT |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
42 #endif |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
43 #define ERRNO_TRAYEMPTY(errno) \ |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
44 ((errno == EIO) || (errno == ENOENT) || \ |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
45 (errno == EINVAL) || (errno == ENOMEDIUM)) |
724 | 46 |
47 /* The maximum number of CD-ROM drives we'll detect */ | |
48 #define MAX_DRIVES 32 | |
49 | |
50 typedef struct { | |
51 unsigned char device[3]; /* Physical device letter + ':' + '\0' */ | |
52 metaopen_t metaopen; /* Infos on opened drive */ | |
53 } metados_drive_t; | |
54 | |
55 static metados_drive_t metados_drives[MAX_DRIVES]; | |
56 | |
57 /* The system-dependent CD control functions */ | |
58 static const char *SDL_SYS_CDName(int drive); | |
59 static int SDL_SYS_CDOpen(int drive); | |
60 static void SDL_SYS_CDClose(SDL_CD *cdrom); | |
61 static int SDL_SYS_CDioctl(int id, int command, void *arg); | |
62 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); | |
63 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); | |
64 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); | |
65 static int SDL_SYS_CDPause(SDL_CD *cdrom); | |
66 static int SDL_SYS_CDResume(SDL_CD *cdrom); | |
67 static int SDL_SYS_CDStop(SDL_CD *cdrom); | |
68 static int SDL_SYS_CDEject(SDL_CD *cdrom); | |
69 | |
70 int SDL_SYS_CDInit(void) | |
71 { | |
72 metainit_t metainit={0,0,0,0}; | |
73 metaopen_t metaopen; | |
74 int i, handle; | |
727
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
75 struct cdrom_subchnl info; |
724 | 76 |
77 Metainit(&metainit); | |
78 if (metainit.version == NULL) { | |
79 #ifdef DEBUG_CDROM | |
80 fprintf(stderr, "MetaDOS not installed\n"); | |
81 #endif | |
82 return -1; | |
83 } | |
84 | |
85 if (metainit.drives_map == 0) { | |
86 #ifdef DEBUG_CDROM | |
87 fprintf(stderr, "No MetaDOS devices present\n"); | |
88 #endif | |
89 return -1; | |
90 } | |
91 | |
92 SDL_numcds = 0; | |
93 | |
94 for (i='A'; i<='Z'; i++) { | |
95 metados_drives[SDL_numcds].device[0] = 0; | |
96 metados_drives[SDL_numcds].device[1] = ':'; | |
97 metados_drives[SDL_numcds].device[2] = 0; | |
98 | |
99 if (metainit.drives_map & (1<<(i-'A'))) { | |
100 handle = Metaopen(i, &metaopen); | |
101 if (handle == 0) { | |
102 | |
727
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
103 info.cdsc_format = CDROM_MSF; |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
104 if ( (Metaioctl(i, METADOS_IOCTL_MAGIC, CDROMSUBCHNL, &info) == 0) || ERRNO_TRAYEMPTY(errno) ) { |
724 | 105 metados_drives[SDL_numcds].device[0] = i; |
106 ++SDL_numcds; | |
107 } | |
108 | |
109 Metaclose(i); | |
110 } | |
111 } | |
112 } | |
113 | |
114 /* Fill in our driver capabilities */ | |
115 SDL_CDcaps.Name = SDL_SYS_CDName; | |
116 SDL_CDcaps.Open = SDL_SYS_CDOpen; | |
117 SDL_CDcaps.Close = SDL_SYS_CDClose; | |
118 | |
119 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; | |
120 SDL_CDcaps.Status = SDL_SYS_CDStatus; | |
121 SDL_CDcaps.Play = SDL_SYS_CDPlay; | |
122 SDL_CDcaps.Pause = SDL_SYS_CDPause; | |
123 SDL_CDcaps.Resume = SDL_SYS_CDResume; | |
124 SDL_CDcaps.Stop = SDL_SYS_CDStop; | |
125 SDL_CDcaps.Eject = SDL_SYS_CDEject; | |
126 | |
127 return 0; | |
128 } | |
129 | |
130 void SDL_SYS_CDQuit(void) | |
131 { | |
132 SDL_numcds = 0; | |
133 } | |
134 | |
135 static const char *SDL_SYS_CDName(int drive) | |
136 { | |
137 return(metados_drives[drive].device); | |
138 } | |
139 | |
140 static int SDL_SYS_CDOpen(int drive) | |
141 { | |
142 int handle; | |
143 | |
144 handle = Metaopen(metados_drives[drive].device[0], &(metados_drives[drive].metaopen)); | |
145 if (handle == 0) { | |
146 return drive; | |
147 } | |
148 | |
149 return -1; | |
150 } | |
151 | |
152 static void SDL_SYS_CDClose(SDL_CD *cdrom) | |
153 { | |
154 Metaclose(metados_drives[cdrom->id].device[0]); | |
155 } | |
156 | |
157 static int SDL_SYS_CDioctl(int id, int command, void *arg) | |
158 { | |
159 int retval; | |
160 | |
161 retval = Metaioctl(metados_drives[id].device[0], METADOS_IOCTL_MAGIC, command, arg); | |
162 if ( retval < 0 ) { | |
163 SDL_SetError("ioctl() error: %s", strerror(errno)); | |
164 } | |
165 return(retval); | |
166 } | |
167 | |
168 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) | |
169 { | |
170 int i,okay; | |
171 struct cdrom_tochdr toc; | |
172 struct cdrom_tocentry entry; | |
173 | |
174 /* Use standard ioctl() */ | |
175 if (SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCHDR, &toc)<0) { | |
176 return -1; | |
177 } | |
178 | |
179 cdrom->numtracks = toc.cdth_trk1-toc.cdth_trk0+1; | |
180 if ( cdrom->numtracks > SDL_MAX_TRACKS ) { | |
181 cdrom->numtracks = SDL_MAX_TRACKS; | |
182 } | |
183 | |
184 /* Read all the track TOC entries */ | |
185 okay=1; | |
186 for ( i=0; i<=cdrom->numtracks; ++i ) { | |
187 if ( i == cdrom->numtracks ) { | |
188 cdrom->track[i].id = CDROM_LEADOUT; | |
189 } else { | |
190 cdrom->track[i].id = toc.cdth_trk0+i; | |
191 } | |
192 entry.cdte_track = cdrom->track[i].id; | |
193 entry.cdte_format = CDROM_MSF; | |
194 if ( SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCENTRY, &entry) < 0 ) { | |
195 okay=0; | |
196 break; | |
197 } else { | |
198 if ( entry.cdte_ctrl & CDROM_DATA_TRACK ) { | |
199 cdrom->track[i].type = SDL_DATA_TRACK; | |
200 } else { | |
201 cdrom->track[i].type = SDL_AUDIO_TRACK; | |
202 } | |
203 cdrom->track[i].offset = MSF_TO_FRAMES( | |
204 entry.cdte_addr.msf.minute, | |
205 entry.cdte_addr.msf.second, | |
206 entry.cdte_addr.msf.frame); | |
207 cdrom->track[i].length = 0; | |
208 if ( i > 0 ) { | |
209 cdrom->track[i-1].length = cdrom->track[i].offset-cdrom->track[i-1].offset; | |
210 } | |
211 } | |
212 } | |
213 | |
214 return(okay ? 0 : -1); | |
215 } | |
216 | |
217 /* Get CD-ROM status */ | |
218 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) | |
219 { | |
220 CDstatus status; | |
221 struct cdrom_tochdr toc; | |
222 struct cdrom_subchnl info; | |
223 | |
224 info.cdsc_format = CDROM_MSF; | |
225 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
|
226 if ( ERRNO_TRAYEMPTY(errno) ) { |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
227 status = CD_TRAYEMPTY; |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
228 } else { |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
229 status = CD_ERROR; |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
230 } |
724 | 231 } else { |
232 switch (info.cdsc_audiostatus) { | |
233 case CDROM_AUDIO_INVALID: | |
234 case CDROM_AUDIO_NO_STATUS: | |
235 /* Try to determine if there's a CD available */ | |
236 if (SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCHDR, &toc)==0) { | |
237 status = CD_STOPPED; | |
238 } else { | |
239 status = CD_TRAYEMPTY; | |
240 } | |
241 break; | |
242 case CDROM_AUDIO_COMPLETED: | |
243 status = CD_STOPPED; | |
244 break; | |
245 case CDROM_AUDIO_PLAY: | |
246 status = CD_PLAYING; | |
247 break; | |
248 case CDROM_AUDIO_PAUSED: | |
249 /* Workaround buggy CD-ROM drive */ | |
250 if ( info.cdsc_trk == CDROM_LEADOUT ) { | |
251 status = CD_STOPPED; | |
252 } else { | |
253 status = CD_PAUSED; | |
254 } | |
255 break; | |
256 default: | |
257 status = CD_ERROR; | |
258 break; | |
259 } | |
260 } | |
261 if ( position ) { | |
262 if ( status == CD_PLAYING || (status == CD_PAUSED) ) { | |
263 *position = MSF_TO_FRAMES( | |
264 info.cdsc_absaddr.msf.minute, | |
265 info.cdsc_absaddr.msf.second, | |
266 info.cdsc_absaddr.msf.frame); | |
267 } else { | |
268 *position = 0; | |
269 } | |
270 } | |
271 return(status); | |
272 } | |
273 | |
274 /* Start play */ | |
275 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) | |
276 { | |
277 struct cdrom_msf playtime; | |
278 | |
279 FRAMES_TO_MSF(start, | |
280 &playtime.cdmsf_min0, &playtime.cdmsf_sec0, &playtime.cdmsf_frame0); | |
281 FRAMES_TO_MSF(start+length, | |
282 &playtime.cdmsf_min1, &playtime.cdmsf_sec1, &playtime.cdmsf_frame1); | |
283 #ifdef DEBUG_CDROM | |
284 fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", | |
285 playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0, | |
286 playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1); | |
287 #endif | |
727
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
288 |
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
289 return SDL_SYS_CDioctl(cdrom->id, CDROMPLAYMSF, &playtime); |
724 | 290 } |
291 | |
292 /* Pause play */ | |
293 static int SDL_SYS_CDPause(SDL_CD *cdrom) | |
294 { | |
727
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
295 return SDL_SYS_CDioctl(cdrom->id, CDROMPAUSE, 0); |
724 | 296 } |
297 | |
298 /* Resume play */ | |
299 static int SDL_SYS_CDResume(SDL_CD *cdrom) | |
300 { | |
727
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
301 return SDL_SYS_CDioctl(cdrom->id, CDROMRESUME, 0); |
724 | 302 } |
303 | |
304 /* Stop play */ | |
305 static int SDL_SYS_CDStop(SDL_CD *cdrom) | |
306 { | |
727
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
307 return SDL_SYS_CDioctl(cdrom->id, CDROMSTOP, 0); |
724 | 308 } |
309 | |
310 /* Eject the CD-ROM */ | |
311 static int SDL_SYS_CDEject(SDL_CD *cdrom) | |
312 { | |
727
cb1208fcd946
Update MiNT CD-ROM driver
Patrice Mandin <patmandin@gmail.com>
parents:
724
diff
changeset
|
313 return SDL_SYS_CDioctl(cdrom->id, CDROMEJECT, 0); |
724 | 314 } |