comparison src/cdrom/openbsd/SDL_syscdrom.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 92947e3a18db
children e27bdcc80744
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
37 #include "SDL_cdrom.h" 37 #include "SDL_cdrom.h"
38 #include "../SDL_syscdrom.h" 38 #include "../SDL_syscdrom.h"
39 39
40 40
41 /* The maximum number of CD-ROM drives we'll detect */ 41 /* The maximum number of CD-ROM drives we'll detect */
42 #define MAX_DRIVES 16 42 #define MAX_DRIVES 16
43 43
44 /* A list of available CD-ROM drives */ 44 /* A list of available CD-ROM drives */
45 static char *SDL_cdlist[MAX_DRIVES]; 45 static char *SDL_cdlist[MAX_DRIVES];
46 static dev_t SDL_cdmode[MAX_DRIVES]; 46 static dev_t SDL_cdmode[MAX_DRIVES];
47 47
48 /* The system-dependent CD control functions */ 48 /* The system-dependent CD control functions */
49 static const char *SDL_SYS_CDName(int drive); 49 static const char *SDL_SYS_CDName(int drive);
50 static int SDL_SYS_CDOpen(int drive); 50 static int SDL_SYS_CDOpen(int drive);
51 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); 51 static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
52 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); 52 static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
53 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); 53 static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
54 static int SDL_SYS_CDPause(SDL_CD *cdrom); 54 static int SDL_SYS_CDPause(SDL_CD * cdrom);
55 static int SDL_SYS_CDResume(SDL_CD *cdrom); 55 static int SDL_SYS_CDResume(SDL_CD * cdrom);
56 static int SDL_SYS_CDStop(SDL_CD *cdrom); 56 static int SDL_SYS_CDStop(SDL_CD * cdrom);
57 static int SDL_SYS_CDEject(SDL_CD *cdrom); 57 static int SDL_SYS_CDEject(SDL_CD * cdrom);
58 static void SDL_SYS_CDClose(SDL_CD *cdrom); 58 static void SDL_SYS_CDClose(SDL_CD * cdrom);
59 59
60 /* Some ioctl() errno values which occur when the tray is empty */ 60 /* Some ioctl() errno values which occur when the tray is empty */
61 #define ERRNO_TRAYEMPTY(errno) \ 61 #define ERRNO_TRAYEMPTY(errno) \
62 ((errno == EIO) || (errno == ENOENT) || (errno == EINVAL) || \ 62 ((errno == EIO) || (errno == ENOENT) || (errno == EINVAL) || \
63 (errno == ENODEV)) 63 (errno == ENODEV))
64 64
65 /* Check a drive to see if it is a CD-ROM */ 65 /* Check a drive to see if it is a CD-ROM */
66 static int CheckDrive(char *drive, struct stat *stbuf) 66 static int
67 { 67 CheckDrive(char *drive, struct stat *stbuf)
68 int is_cd, cdfd; 68 {
69 struct ioc_read_subchannel info; 69 int is_cd, cdfd;
70 70 struct ioc_read_subchannel info;
71 /* If it doesn't exist, return -1 */ 71
72 if ( stat(drive, stbuf) < 0 ) { 72 /* If it doesn't exist, return -1 */
73 return(-1); 73 if (stat(drive, stbuf) < 0) {
74 } 74 return (-1);
75 75 }
76 /* If it does exist, verify that it's an available CD-ROM */ 76
77 is_cd = 0; 77 /* If it does exist, verify that it's an available CD-ROM */
78 if ( S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode) ) { 78 is_cd = 0;
79 cdfd = open(drive, (O_RDONLY|O_EXCL|O_NONBLOCK), 0); 79 if (S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode)) {
80 if ( cdfd >= 0 ) { 80 cdfd = open(drive, (O_RDONLY | O_EXCL | O_NONBLOCK), 0);
81 info.address_format = CD_MSF_FORMAT; 81 if (cdfd >= 0) {
82 info.data_format = CD_CURRENT_POSITION; 82 info.address_format = CD_MSF_FORMAT;
83 info.data_len = 0; 83 info.data_format = CD_CURRENT_POSITION;
84 info.data = NULL; 84 info.data_len = 0;
85 /* Under Linux, EIO occurs when a disk is not present. 85 info.data = NULL;
86 This isn't 100% reliable, so we use the USE_MNTENT 86 /* Under Linux, EIO occurs when a disk is not present.
87 code above instead. 87 This isn't 100% reliable, so we use the USE_MNTENT
88 */ 88 code above instead.
89 if ( (ioctl(cdfd, CDIOCREADSUBCHANNEL, &info) == 0) || 89 */
90 ERRNO_TRAYEMPTY(errno) ) { 90 if ((ioctl(cdfd, CDIOCREADSUBCHANNEL, &info) == 0) ||
91 is_cd = 1; 91 ERRNO_TRAYEMPTY(errno)) {
92 } 92 is_cd = 1;
93 close(cdfd); 93 }
94 } 94 close(cdfd);
95 else if (ERRNO_TRAYEMPTY(errno)) 95 } else if (ERRNO_TRAYEMPTY(errno))
96 is_cd = 1; 96 is_cd = 1;
97 } 97 }
98 return(is_cd); 98 return (is_cd);
99 } 99 }
100 100
101 /* Add a CD-ROM drive to our list of valid drives */ 101 /* Add a CD-ROM drive to our list of valid drives */
102 static void AddDrive(char *drive, struct stat *stbuf) 102 static void
103 { 103 AddDrive(char *drive, struct stat *stbuf)
104 int i; 104 {
105 105 int i;
106 if ( SDL_numcds < MAX_DRIVES ) { 106
107 /* Check to make sure it's not already in our list. 107 if (SDL_numcds < MAX_DRIVES) {
108 This can happen when we see a drive via symbolic link. 108 /* Check to make sure it's not already in our list.
109 */ 109 This can happen when we see a drive via symbolic link.
110 for ( i=0; i<SDL_numcds; ++i ) { 110 */
111 if ( stbuf->st_rdev == SDL_cdmode[i] ) { 111 for (i = 0; i < SDL_numcds; ++i) {
112 if (stbuf->st_rdev == SDL_cdmode[i]) {
112 #ifdef DEBUG_CDROM 113 #ifdef DEBUG_CDROM
113 fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]); 114 fprintf(stderr, "Duplicate drive detected: %s == %s\n",
115 drive, SDL_cdlist[i]);
114 #endif 116 #endif
115 return; 117 return;
116 } 118 }
117 } 119 }
118 120
119 /* Add this drive to our list */ 121 /* Add this drive to our list */
120 i = SDL_numcds; 122 i = SDL_numcds;
121 SDL_cdlist[i] = SDL_strdup(drive); 123 SDL_cdlist[i] = SDL_strdup(drive);
122 if ( SDL_cdlist[i] == NULL ) { 124 if (SDL_cdlist[i] == NULL) {
123 SDL_OutOfMemory(); 125 SDL_OutOfMemory();
124 return; 126 return;
125 } 127 }
126 SDL_cdmode[i] = stbuf->st_rdev; 128 SDL_cdmode[i] = stbuf->st_rdev;
127 ++SDL_numcds; 129 ++SDL_numcds;
128 #ifdef DEBUG_CDROM 130 #ifdef DEBUG_CDROM
129 fprintf(stderr, "Added CD-ROM drive: %s\n", drive); 131 fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
130 #endif 132 #endif
131 } 133 }
132 } 134 }
133 135
134 int SDL_SYS_CDInit(void) 136 int
135 { 137 SDL_SYS_CDInit(void)
136 static char *checklist[] = { 138 {
139 static char *checklist[] = {
137 #if defined(__OPENBSD__) 140 #if defined(__OPENBSD__)
138 "?0 cd?c", "cdrom", NULL 141 "?0 cd?c", "cdrom", NULL
139 #elif defined(__NETBSD__) 142 #elif defined(__NETBSD__)
140 "?0 cd?d", "?0 cd?c", "cdrom", NULL 143 "?0 cd?d", "?0 cd?c", "cdrom", NULL
141 #else 144 #else
142 "?0 cd?c", "?0 acd?c", "cdrom", NULL 145 "?0 cd?c", "?0 acd?c", "cdrom", NULL
143 #endif 146 #endif
144 }; 147 };
145 char *SDLcdrom; 148 char *SDLcdrom;
146 int i, j, exists; 149 int i, j, exists;
147 char drive[32]; 150 char drive[32];
148 struct stat stbuf; 151 struct stat stbuf;
149 152
150 /* Fill in our driver capabilities */ 153 /* Fill in our driver capabilities */
151 SDL_CDcaps.Name = SDL_SYS_CDName; 154 SDL_CDcaps.Name = SDL_SYS_CDName;
152 SDL_CDcaps.Open = SDL_SYS_CDOpen; 155 SDL_CDcaps.Open = SDL_SYS_CDOpen;
153 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; 156 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
154 SDL_CDcaps.Status = SDL_SYS_CDStatus; 157 SDL_CDcaps.Status = SDL_SYS_CDStatus;
155 SDL_CDcaps.Play = SDL_SYS_CDPlay; 158 SDL_CDcaps.Play = SDL_SYS_CDPlay;
156 SDL_CDcaps.Pause = SDL_SYS_CDPause; 159 SDL_CDcaps.Pause = SDL_SYS_CDPause;
157 SDL_CDcaps.Resume = SDL_SYS_CDResume; 160 SDL_CDcaps.Resume = SDL_SYS_CDResume;
158 SDL_CDcaps.Stop = SDL_SYS_CDStop; 161 SDL_CDcaps.Stop = SDL_SYS_CDStop;
159 SDL_CDcaps.Eject = SDL_SYS_CDEject; 162 SDL_CDcaps.Eject = SDL_SYS_CDEject;
160 SDL_CDcaps.Close = SDL_SYS_CDClose; 163 SDL_CDcaps.Close = SDL_SYS_CDClose;
161 164
162 /* Look in the environment for our CD-ROM drive list */ 165 /* Look in the environment for our CD-ROM drive list */
163 SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ 166 SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
164 if ( SDLcdrom != NULL ) { 167 if (SDLcdrom != NULL) {
165 char *cdpath, *delim; 168 char *cdpath, *delim;
166 size_t len = SDL_strlen(SDLcdrom)+1; 169 size_t len = SDL_strlen(SDLcdrom) + 1;
167 cdpath = SDL_stack_alloc(char, len); 170 cdpath = SDL_stack_alloc(char, len);
168 if ( cdpath != NULL ) { 171 if (cdpath != NULL) {
169 SDL_strlcpy(cdpath, SDLcdrom, len); 172 SDL_strlcpy(cdpath, SDLcdrom, len);
170 SDLcdrom = cdpath; 173 SDLcdrom = cdpath;
171 do { 174 do {
172 delim = SDL_strchr(SDLcdrom, ':'); 175 delim = SDL_strchr(SDLcdrom, ':');
173 if ( delim ) { 176 if (delim) {
174 *delim++ = '\0'; 177 *delim++ = '\0';
175 } 178 }
176 if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) { 179 if (CheckDrive(SDLcdrom, &stbuf) > 0) {
177 AddDrive(SDLcdrom, &stbuf); 180 AddDrive(SDLcdrom, &stbuf);
178 } 181 }
179 if ( delim ) { 182 if (delim) {
180 SDLcdrom = delim; 183 SDLcdrom = delim;
181 } else { 184 } else {
182 SDLcdrom = NULL; 185 SDLcdrom = NULL;
183 } 186 }
184 } while ( SDLcdrom ); 187 }
185 SDL_stack_free(cdpath); 188 while (SDLcdrom);
186 } 189 SDL_stack_free(cdpath);
187 190 }
188 /* If we found our drives, there's nothing left to do */ 191
189 if ( SDL_numcds > 0 ) { 192 /* If we found our drives, there's nothing left to do */
190 return(0); 193 if (SDL_numcds > 0) {
191 } 194 return (0);
192 } 195 }
193 196 }
194 /* Scan the system for CD-ROM drives */ 197
195 for ( i=0; checklist[i]; ++i ) { 198 /* Scan the system for CD-ROM drives */
196 if ( checklist[i][0] == '?' ) { 199 for (i = 0; checklist[i]; ++i) {
197 char *insert; 200 if (checklist[i][0] == '?') {
198 exists = 1; 201 char *insert;
199 for ( j=checklist[i][1]; exists; ++j ) { 202 exists = 1;
200 SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", &checklist[i][3]); 203 for (j = checklist[i][1]; exists; ++j) {
201 insert = SDL_strchr(drive, '?'); 204 SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s",
202 if ( insert != NULL ) { 205 &checklist[i][3]);
203 *insert = j; 206 insert = SDL_strchr(drive, '?');
204 } 207 if (insert != NULL) {
205 switch (CheckDrive(drive, &stbuf)) { 208 *insert = j;
206 /* Drive exists and is a CD-ROM */ 209 }
207 case 1: 210 switch (CheckDrive(drive, &stbuf)) {
208 AddDrive(drive, &stbuf); 211 /* Drive exists and is a CD-ROM */
209 break; 212 case 1:
210 /* Drive exists, but isn't a CD-ROM */ 213 AddDrive(drive, &stbuf);
211 case 0: 214 break;
212 break; 215 /* Drive exists, but isn't a CD-ROM */
213 /* Drive doesn't exist */ 216 case 0:
214 case -1: 217 break;
215 exists = 0; 218 /* Drive doesn't exist */
216 break; 219 case -1:
217 } 220 exists = 0;
218 } 221 break;
219 } else { 222 }
220 SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", checklist[i]); 223 }
221 if ( CheckDrive(drive, &stbuf) > 0 ) { 224 } else {
222 AddDrive(drive, &stbuf); 225 SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s",
223 } 226 checklist[i]);
224 } 227 if (CheckDrive(drive, &stbuf) > 0) {
225 } 228 AddDrive(drive, &stbuf);
226 return(0); 229 }
230 }
231 }
232 return (0);
227 } 233 }
228 234
229 /* General ioctl() CD-ROM command function */ 235 /* General ioctl() CD-ROM command function */
230 static int SDL_SYS_CDioctl(int id, int command, void *arg) 236 static int
231 { 237 SDL_SYS_CDioctl(int id, int command, void *arg)
232 int retval; 238 {
233 239 int retval;
234 retval = ioctl(id, command, arg); 240
235 if ( retval < 0 ) { 241 retval = ioctl(id, command, arg);
236 SDL_SetError("ioctl() error: %s", strerror(errno)); 242 if (retval < 0) {
237 } 243 SDL_SetError("ioctl() error: %s", strerror(errno));
238 return(retval); 244 }
239 } 245 return (retval);
240 246 }
241 static const char *SDL_SYS_CDName(int drive) 247
242 { 248 static const char *
243 return(SDL_cdlist[drive]); 249 SDL_SYS_CDName(int drive)
244 } 250 {
245 251 return (SDL_cdlist[drive]);
246 static int SDL_SYS_CDOpen(int drive) 252 }
247 { 253
248 return(open(SDL_cdlist[drive], (O_RDONLY|O_EXCL|O_NONBLOCK), 0)); 254 static int
249 } 255 SDL_SYS_CDOpen(int drive)
250 256 {
251 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) 257 return (open(SDL_cdlist[drive], (O_RDONLY | O_EXCL | O_NONBLOCK), 0));
252 { 258 }
253 struct ioc_toc_header toc; 259
254 int i, okay; 260 static int
255 struct ioc_read_toc_entry entry; 261 SDL_SYS_CDGetTOC(SDL_CD * cdrom)
256 struct cd_toc_entry data; 262 {
257 263 struct ioc_toc_header toc;
258 okay = 0; 264 int i, okay;
259 if ( SDL_SYS_CDioctl(cdrom->id, CDIOREADTOCHEADER, &toc) == 0 ) { 265 struct ioc_read_toc_entry entry;
260 cdrom->numtracks = toc.ending_track-toc.starting_track+1; 266 struct cd_toc_entry data;
261 if ( cdrom->numtracks > SDL_MAX_TRACKS ) { 267
262 cdrom->numtracks = SDL_MAX_TRACKS; 268 okay = 0;
263 } 269 if (SDL_SYS_CDioctl(cdrom->id, CDIOREADTOCHEADER, &toc) == 0) {
264 /* Read all the track TOC entries */ 270 cdrom->numtracks = toc.ending_track - toc.starting_track + 1;
265 for ( i=0; i<=cdrom->numtracks; ++i ) { 271 if (cdrom->numtracks > SDL_MAX_TRACKS) {
266 if ( i == cdrom->numtracks ) { 272 cdrom->numtracks = SDL_MAX_TRACKS;
267 cdrom->track[i].id = 0xAA; /* CDROM_LEADOUT */ 273 }
268 } else { 274 /* Read all the track TOC entries */
269 cdrom->track[i].id = toc.starting_track+i; 275 for (i = 0; i <= cdrom->numtracks; ++i) {
270 } 276 if (i == cdrom->numtracks) {
271 entry.starting_track = cdrom->track[i].id; 277 cdrom->track[i].id = 0xAA; /* CDROM_LEADOUT */
272 entry.address_format = CD_MSF_FORMAT; 278 } else {
273 entry.data_len = sizeof(data); 279 cdrom->track[i].id = toc.starting_track + i;
274 entry.data = &data; 280 }
275 if ( SDL_SYS_CDioctl(cdrom->id, CDIOREADTOCENTRYS, 281 entry.starting_track = cdrom->track[i].id;
276 &entry) < 0 ) { 282 entry.address_format = CD_MSF_FORMAT;
277 break; 283 entry.data_len = sizeof(data);
278 } else { 284 entry.data = &data;
279 cdrom->track[i].type = data.control; 285 if (SDL_SYS_CDioctl(cdrom->id, CDIOREADTOCENTRYS, &entry) < 0) {
280 cdrom->track[i].offset = MSF_TO_FRAMES( 286 break;
281 data.addr.msf.minute, 287 } else {
282 data.addr.msf.second, 288 cdrom->track[i].type = data.control;
283 data.addr.msf.frame); 289 cdrom->track[i].offset =
284 cdrom->track[i].length = 0; 290 MSF_TO_FRAMES(data.addr.msf.minute,
285 if ( i > 0 ) { 291 data.addr.msf.second, data.addr.msf.frame);
286 cdrom->track[i-1].length = 292 cdrom->track[i].length = 0;
287 cdrom->track[i].offset- 293 if (i > 0) {
288 cdrom->track[i-1].offset; 294 cdrom->track[i - 1].length =
289 } 295 cdrom->track[i].offset - cdrom->track[i - 1].offset;
290 } 296 }
291 } 297 }
292 if ( i == (cdrom->numtracks+1) ) { 298 }
293 okay = 1; 299 if (i == (cdrom->numtracks + 1)) {
294 } 300 okay = 1;
295 } 301 }
296 return(okay ? 0 : -1); 302 }
303 return (okay ? 0 : -1);
297 } 304 }
298 305
299 /* Get CD-ROM status */ 306 /* Get CD-ROM status */
300 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) 307 static CDstatus
301 { 308 SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
302 CDstatus status; 309 {
303 struct ioc_toc_header toc; 310 CDstatus status;
304 struct ioc_read_subchannel info; 311 struct ioc_toc_header toc;
305 struct cd_sub_channel_info data; 312 struct ioc_read_subchannel info;
306 313 struct cd_sub_channel_info data;
307 info.address_format = CD_MSF_FORMAT; 314
308 info.data_format = CD_CURRENT_POSITION; 315 info.address_format = CD_MSF_FORMAT;
309 info.track = 0; 316 info.data_format = CD_CURRENT_POSITION;
310 info.data_len = sizeof(data); 317 info.track = 0;
311 info.data = &data; 318 info.data_len = sizeof(data);
312 if ( ioctl(cdrom->id, CDIOCREADSUBCHANNEL, &info) < 0 ) { 319 info.data = &data;
313 if ( ERRNO_TRAYEMPTY(errno) ) { 320 if (ioctl(cdrom->id, CDIOCREADSUBCHANNEL, &info) < 0) {
314 status = CD_TRAYEMPTY; 321 if (ERRNO_TRAYEMPTY(errno)) {
315 } else { 322 status = CD_TRAYEMPTY;
316 status = CD_ERROR; 323 } else {
317 } 324 status = CD_ERROR;
318 } else { 325 }
319 switch (data.header.audio_status) { 326 } else {
320 case CD_AS_AUDIO_INVALID: 327 switch (data.header.audio_status) {
321 case CD_AS_NO_STATUS: 328 case CD_AS_AUDIO_INVALID:
322 /* Try to determine if there's a CD available */ 329 case CD_AS_NO_STATUS:
323 if (ioctl(cdrom->id,CDIOREADTOCHEADER,&toc)==0) 330 /* Try to determine if there's a CD available */
324 status = CD_STOPPED; 331 if (ioctl(cdrom->id, CDIOREADTOCHEADER, &toc) == 0)
325 else 332 status = CD_STOPPED;
326 status = CD_TRAYEMPTY; 333 else
327 break; 334 status = CD_TRAYEMPTY;
328 case CD_AS_PLAY_COMPLETED: 335 break;
329 status = CD_STOPPED; 336 case CD_AS_PLAY_COMPLETED:
330 break; 337 status = CD_STOPPED;
331 case CD_AS_PLAY_IN_PROGRESS: 338 break;
332 status = CD_PLAYING; 339 case CD_AS_PLAY_IN_PROGRESS:
333 break; 340 status = CD_PLAYING;
334 case CD_AS_PLAY_PAUSED: 341 break;
335 status = CD_PAUSED; 342 case CD_AS_PLAY_PAUSED:
336 break; 343 status = CD_PAUSED;
337 default: 344 break;
338 status = CD_ERROR; 345 default:
339 break; 346 status = CD_ERROR;
340 } 347 break;
341 } 348 }
342 if ( position ) { 349 }
343 if ( status == CD_PLAYING || (status == CD_PAUSED) ) { 350 if (position) {
344 *position = MSF_TO_FRAMES( 351 if (status == CD_PLAYING || (status == CD_PAUSED)) {
345 data.what.position.absaddr.msf.minute, 352 *position =
346 data.what.position.absaddr.msf.second, 353 MSF_TO_FRAMES(data.what.position.absaddr.msf.minute,
347 data.what.position.absaddr.msf.frame); 354 data.what.position.absaddr.msf.second,
348 } else { 355 data.what.position.absaddr.msf.frame);
349 *position = 0; 356 } else {
350 } 357 *position = 0;
351 } 358 }
352 return(status); 359 }
360 return (status);
353 } 361 }
354 362
355 /* Start play */ 363 /* Start play */
356 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) 364 static int
357 { 365 SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
358 struct ioc_play_msf playtime; 366 {
359 367 struct ioc_play_msf playtime;
360 FRAMES_TO_MSF(start, 368
361 &playtime.start_m, &playtime.start_s, &playtime.start_f); 369 FRAMES_TO_MSF(start,
362 FRAMES_TO_MSF(start+length, 370 &playtime.start_m, &playtime.start_s, &playtime.start_f);
363 &playtime.end_m, &playtime.end_s, &playtime.end_f); 371 FRAMES_TO_MSF(start + length,
372 &playtime.end_m, &playtime.end_s, &playtime.end_f);
364 #ifdef DEBUG_CDROM 373 #ifdef DEBUG_CDROM
365 fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", 374 fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n",
366 playtime.start_m, playtime.start_s, playtime.start_f, 375 playtime.start_m, playtime.start_s, playtime.start_f,
367 playtime.end_m, playtime.end_s, playtime.end_f); 376 playtime.end_m, playtime.end_s, playtime.end_f);
368 #endif 377 #endif
369 ioctl(cdrom->id, CDIOCSTART, 0); 378 ioctl(cdrom->id, CDIOCSTART, 0);
370 return(SDL_SYS_CDioctl(cdrom->id, CDIOCPLAYMSF, &playtime)); 379 return (SDL_SYS_CDioctl(cdrom->id, CDIOCPLAYMSF, &playtime));
371 } 380 }
372 381
373 /* Pause play */ 382 /* Pause play */
374 static int SDL_SYS_CDPause(SDL_CD *cdrom) 383 static int
375 { 384 SDL_SYS_CDPause(SDL_CD * cdrom)
376 return(SDL_SYS_CDioctl(cdrom->id, CDIOCPAUSE, 0)); 385 {
386 return (SDL_SYS_CDioctl(cdrom->id, CDIOCPAUSE, 0));
377 } 387 }
378 388
379 /* Resume play */ 389 /* Resume play */
380 static int SDL_SYS_CDResume(SDL_CD *cdrom) 390 static int
381 { 391 SDL_SYS_CDResume(SDL_CD * cdrom)
382 return(SDL_SYS_CDioctl(cdrom->id, CDIOCRESUME, 0)); 392 {
393 return (SDL_SYS_CDioctl(cdrom->id, CDIOCRESUME, 0));
383 } 394 }
384 395
385 /* Stop play */ 396 /* Stop play */
386 static int SDL_SYS_CDStop(SDL_CD *cdrom) 397 static int
387 { 398 SDL_SYS_CDStop(SDL_CD * cdrom)
388 return(SDL_SYS_CDioctl(cdrom->id, CDIOCSTOP, 0)); 399 {
400 return (SDL_SYS_CDioctl(cdrom->id, CDIOCSTOP, 0));
389 } 401 }
390 402
391 /* Eject the CD-ROM */ 403 /* Eject the CD-ROM */
392 static int SDL_SYS_CDEject(SDL_CD *cdrom) 404 static int
393 { 405 SDL_SYS_CDEject(SDL_CD * cdrom)
394 return(SDL_SYS_CDioctl(cdrom->id, CDIOCEJECT, 0)); 406 {
407 return (SDL_SYS_CDioctl(cdrom->id, CDIOCEJECT, 0));
395 } 408 }
396 409
397 /* Close the CD-ROM handle */ 410 /* Close the CD-ROM handle */
398 static void SDL_SYS_CDClose(SDL_CD *cdrom) 411 static void
399 { 412 SDL_SYS_CDClose(SDL_CD * cdrom)
400 close(cdrom->id); 413 {
401 } 414 close(cdrom->id);
402 415 }
403 void SDL_SYS_CDQuit(void) 416
404 { 417 void
405 int i; 418 SDL_SYS_CDQuit(void)
406 419 {
407 if ( SDL_numcds > 0 ) { 420 int i;
408 for ( i=0; i<SDL_numcds; ++i ) { 421
409 SDL_free(SDL_cdlist[i]); 422 if (SDL_numcds > 0) {
410 } 423 for (i = 0; i < SDL_numcds; ++i) {
411 SDL_numcds = 0; 424 SDL_free(SDL_cdlist[i]);
412 } 425 }
426 SDL_numcds = 0;
427 }
413 } 428 }
414 429
415 #endif /* SDL_CDROM_OPENBSD */ 430 #endif /* SDL_CDROM_OPENBSD */
431 /* vi: set ts=4 sw=4 expandtab: */