comparison src/cdrom/osf/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
44 static char *SDL_cdlist[MAX_DRIVES]; 44 static char *SDL_cdlist[MAX_DRIVES];
45 static dev_t SDL_cdmode[MAX_DRIVES]; 45 static dev_t SDL_cdmode[MAX_DRIVES];
46 46
47 /* The system-dependent CD control functions */ 47 /* The system-dependent CD control functions */
48 static const char *SDL_SYS_CDName(int drive); 48 static const char *SDL_SYS_CDName(int drive);
49 static int SDL_SYS_CDOpen(int drive); 49 static int SDL_SYS_CDOpen(int drive);
50 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); 50 static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
51 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); 51 static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
52 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); 52 static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
53 static int SDL_SYS_CDPause(SDL_CD *cdrom); 53 static int SDL_SYS_CDPause(SDL_CD * cdrom);
54 static int SDL_SYS_CDResume(SDL_CD *cdrom); 54 static int SDL_SYS_CDResume(SDL_CD * cdrom);
55 static int SDL_SYS_CDStop(SDL_CD *cdrom); 55 static int SDL_SYS_CDStop(SDL_CD * cdrom);
56 static int SDL_SYS_CDEject(SDL_CD *cdrom); 56 static int SDL_SYS_CDEject(SDL_CD * cdrom);
57 static void SDL_SYS_CDClose(SDL_CD *cdrom); 57 static void SDL_SYS_CDClose(SDL_CD * cdrom);
58 58
59 /* Check a drive to see if it is a CD-ROM */ 59 /* Check a drive to see if it is a CD-ROM */
60 /* Caution!! Not tested. */ 60 /* Caution!! Not tested. */
61 static int CheckDrive(char *drive, struct stat *stbuf) 61 static int
62 CheckDrive(char *drive, struct stat *stbuf)
62 { 63 {
63 int cdfd, is_cd = 0; 64 int cdfd, is_cd = 0;
64 struct mode_sel_sns_params msp; 65 struct mode_sel_sns_params msp;
65 struct inquiry_info inq; 66 struct inquiry_info inq;
66 67
67 #ifdef DEBUG_CDROM 68 #ifdef DEBUG_CDROM
68 char *devtype[] = {"Disk", "Tape", "Printer", "Processor", "WORM", 69 char *devtype[] = { "Disk", "Tape", "Printer", "Processor", "WORM",
69 "CD-ROM", "Scanner", "Optical", "Changer", "Comm", "Unknown"}; 70 "CD-ROM", "Scanner", "Optical", "Changer", "Comm", "Unknown"
71 };
70 #endif 72 #endif
71 73
72 bzero(&msp, sizeof(msp)); 74 bzero(&msp, sizeof(msp));
73 bzero(&inq, sizeof(inq)); 75 bzero(&inq, sizeof(inq));
74 76
75 /* If it doesn't exist, return -1 */ 77 /* If it doesn't exist, return -1 */
76 if ( stat(drive, stbuf) < 0 ) { 78 if (stat(drive, stbuf) < 0) {
77 return(-1); 79 return (-1);
78 } 80 }
79 81
80 if ( (cdfd = open(drive, (O_RDWR|O_NDELAY), 0)) >= 0 ) { 82 if ((cdfd = open(drive, (O_RDWR | O_NDELAY), 0)) >= 0) {
81 msp.msp_addr = (caddr_t) &inq; 83 msp.msp_addr = (caddr_t) & inq;
82 msp.msp_pgcode = 0; 84 msp.msp_pgcode = 0;
83 msp.msp_pgctrl = 0; 85 msp.msp_pgctrl = 0;
84 msp.msp_length = sizeof(inq); 86 msp.msp_length = sizeof(inq);
85 msp.msp_setps = 0; 87 msp.msp_setps = 0;
86 88
87 if ( ioctl(cdfd, SCSI_GET_INQUIRY_DATA, &msp) ) 89 if (ioctl(cdfd, SCSI_GET_INQUIRY_DATA, &msp))
88 return (0); 90 return (0);
89 91
90 #ifdef DEBUG_CDROM 92 #ifdef DEBUG_CDROM
91 fprintf(stderr, "Device Type: %s\n", devtype[inq.perfdt]); 93 fprintf(stderr, "Device Type: %s\n", devtype[inq.perfdt]);
92 fprintf(stderr, "Vendor: %.8s\n", inq.vndrid); 94 fprintf(stderr, "Vendor: %.8s\n", inq.vndrid);
93 fprintf(stderr, "Product: %.8s\n", inq.prodid); 95 fprintf(stderr, "Product: %.8s\n", inq.prodid);
94 fprintf(stderr, "Revision: %.8s\n", inq.revlvl); 96 fprintf(stderr, "Revision: %.8s\n", inq.revlvl);
95 #endif 97 #endif
96 if ( inq.perfdt == DTYPE_RODIRECT ) 98 if (inq.perfdt == DTYPE_RODIRECT)
97 is_cd = 1; 99 is_cd = 1;
98 } 100 }
99 101
100 return(is_cd); 102 return (is_cd);
101 } 103 }
102 104
103 /* Add a CD-ROM drive to our list of valid drives */ 105 /* Add a CD-ROM drive to our list of valid drives */
104 static void AddDrive(char *drive, struct stat *stbuf) 106 static void
107 AddDrive(char *drive, struct stat *stbuf)
105 { 108 {
106 int i; 109 int i;
107 110
108 if ( SDL_numcds < MAX_DRIVES ) { 111 if (SDL_numcds < MAX_DRIVES) {
109 /* Check to make sure it's not already in our list. 112 /* Check to make sure it's not already in our list.
110 * This can happen when we see a drive via symbolic link. 113 * This can happen when we see a drive via symbolic link.
111 * 114 *
112 */ 115 */
113 for ( i=0; i<SDL_numcds; ++i ) { 116 for (i = 0; i < SDL_numcds; ++i) {
114 if ( stbuf->st_rdev == SDL_cdmode[i] ) { 117 if (stbuf->st_rdev == SDL_cdmode[i]) {
115 #ifdef DEBUG_CDROM 118 #ifdef DEBUG_CDROM
116 fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]); 119 fprintf(stderr, "Duplicate drive detected: %s == %s\n",
117 #endif 120 drive, SDL_cdlist[i]);
118 return; 121 #endif
119 } 122 return;
120 } 123 }
121 124 }
122 /* Add this drive to our list */ 125
123 i = SDL_numcds; 126 /* Add this drive to our list */
124 SDL_cdlist[i] = SDL_strdup(drive); 127 i = SDL_numcds;
125 if ( SDL_cdlist[i] == NULL ) { 128 SDL_cdlist[i] = SDL_strdup(drive);
126 SDL_OutOfMemory(); 129 if (SDL_cdlist[i] == NULL) {
127 return; 130 SDL_OutOfMemory();
128 } 131 return;
129 SDL_cdmode[i] = stbuf->st_rdev; 132 }
130 ++SDL_numcds; 133 SDL_cdmode[i] = stbuf->st_rdev;
131 #ifdef DEBUG_CDROM 134 ++SDL_numcds;
132 fprintf(stderr, "Added CD-ROM drive: %s\n", drive); 135 #ifdef DEBUG_CDROM
133 #endif 136 fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
134 } 137 #endif
135 } 138 }
136 139 }
137 int SDL_SYS_CDInit(void) 140
141 int
142 SDL_SYS_CDInit(void)
138 { 143 {
139 /* checklist: 144 /* checklist:
140 * 145 *
141 * Tru64 5.X (/dev/rdisk/cdrom?c) 146 * Tru64 5.X (/dev/rdisk/cdrom?c)
142 * dir: /dev/rdisk, name: cdrom 147 * dir: /dev/rdisk, name: cdrom
143 * 148 *
144 * Digital UNIX 4.0X (/dev/rrz?c) 149 * Digital UNIX 4.0X (/dev/rrz?c)
145 * dir: /dev, name: rrz 150 * dir: /dev, name: rrz
146 * 151 *
147 */ 152 */
148 struct { 153 struct
149 char *dir; 154 {
150 char *name; 155 char *dir;
156 char *name;
151 } checklist[] = { 157 } checklist[] = {
152 {"/dev/rdisk", "cdrom"}, 158 {
153 {"/dev", "rrz"}, 159 "/dev/rdisk", "cdrom"}, {
154 {NULL, NULL}}; 160 "/dev", "rrz"}, {
161 NULL, NULL}};
155 char drive[32]; 162 char drive[32];
156 char *SDLcdrom; 163 char *SDLcdrom;
157 int i, j, exists; 164 int i, j, exists;
158 struct stat stbuf; 165 struct stat stbuf;
159 166
160 /* Fill in our driver capabilities */ 167 /* Fill in our driver capabilities */
161 SDL_CDcaps.Name = SDL_SYS_CDName; 168 SDL_CDcaps.Name = SDL_SYS_CDName;
162 SDL_CDcaps.Open = SDL_SYS_CDOpen; 169 SDL_CDcaps.Open = SDL_SYS_CDOpen;
163 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; 170 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
164 SDL_CDcaps.Status = SDL_SYS_CDStatus; 171 SDL_CDcaps.Status = SDL_SYS_CDStatus;
165 SDL_CDcaps.Play = SDL_SYS_CDPlay; 172 SDL_CDcaps.Play = SDL_SYS_CDPlay;
166 SDL_CDcaps.Pause = SDL_SYS_CDPause; 173 SDL_CDcaps.Pause = SDL_SYS_CDPause;
167 SDL_CDcaps.Resume = SDL_SYS_CDResume; 174 SDL_CDcaps.Resume = SDL_SYS_CDResume;
168 SDL_CDcaps.Stop = SDL_SYS_CDStop; 175 SDL_CDcaps.Stop = SDL_SYS_CDStop;
169 SDL_CDcaps.Eject = SDL_SYS_CDEject; 176 SDL_CDcaps.Eject = SDL_SYS_CDEject;
170 SDL_CDcaps.Close = SDL_SYS_CDClose; 177 SDL_CDcaps.Close = SDL_SYS_CDClose;
171 178
172 179
173 /* Look in the environment for our CD-ROM drive list */ 180 /* Look in the environment for our CD-ROM drive list */
174 SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ 181 SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
175 if ( SDLcdrom != NULL ) { 182 if (SDLcdrom != NULL) {
176 char *cdpath, *delim; 183 char *cdpath, *delim;
177 size_t len = SDL_strlen(SDLcdrom)+1; 184 size_t len = SDL_strlen(SDLcdrom) + 1;
178 cdpath = SDL_stack_alloc(char, len); 185 cdpath = SDL_stack_alloc(char, len);
179 if ( cdpath != NULL ) { 186 if (cdpath != NULL) {
180 SDL_strlcpy(cdpath, SDLcdrom, len); 187 SDL_strlcpy(cdpath, SDLcdrom, len);
181 SDLcdrom = cdpath; 188 SDLcdrom = cdpath;
182 do { 189 do {
183 delim = SDL_strchr(SDLcdrom, ':'); 190 delim = SDL_strchr(SDLcdrom, ':');
184 if ( delim ) { 191 if (delim) {
185 *delim++ = '\0'; 192 *delim++ = '\0';
186 } 193 }
187 if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) { 194 if (CheckDrive(SDLcdrom, &stbuf) > 0) {
188 AddDrive(SDLcdrom, &stbuf); 195 AddDrive(SDLcdrom, &stbuf);
189 } 196 }
190 if ( delim ) { 197 if (delim) {
191 SDLcdrom = delim; 198 SDLcdrom = delim;
192 } else { 199 } else {
193 SDLcdrom = NULL; 200 SDLcdrom = NULL;
194 } 201 }
195 } while ( SDLcdrom ); 202 }
196 SDL_stack_free(cdpath); 203 while (SDLcdrom);
197 } 204 SDL_stack_free(cdpath);
198 205 }
199 /* If we found our drives, there's nothing left to do */ 206
200 if ( SDL_numcds > 0 ) { 207 /* If we found our drives, there's nothing left to do */
201 return(0); 208 if (SDL_numcds > 0) {
202 } 209 return (0);
210 }
203 } 211 }
204 /* Scan the system for CD-ROM drives */ 212 /* Scan the system for CD-ROM drives */
205 for ( i = 0; checklist[i].dir; ++i) { 213 for (i = 0; checklist[i].dir; ++i) {
206 DIR *devdir; 214 DIR *devdir;
207 struct dirent *devent; 215 struct dirent *devent;
208 int name_len; 216 int name_len;
209 217
210 devdir = opendir(checklist[i].dir); 218 devdir = opendir(checklist[i].dir);
211 if (devdir) { 219 if (devdir) {
212 name_len = SDL_strlen(checklist[i].name); 220 name_len = SDL_strlen(checklist[i].name);
213 while (devent = readdir(devdir)) 221 while (devent = readdir(devdir))
214 if (SDL_memcmp(checklist[i].name, devent->d_name, name_len) == 0) 222 if (SDL_memcmp
215 if (devent->d_name[devent->d_namlen-1] == 'c') { 223 (checklist[i].name, devent->d_name, name_len) == 0)
216 SDL_snprintf(drive, SDL_arraysize(drive), "%s/%s", checklist[i].dir, devent->d_name); 224 if (devent->d_name[devent->d_namlen - 1] == 'c') {
217 #ifdef DEBUG_CDROM 225 SDL_snprintf(drive, SDL_arraysize(drive),
218 fprintf(stderr, "Try to add drive: %s\n", drive); 226 "%s/%s", checklist[i].dir,
219 #endif 227 devent->d_name);
220 if ( CheckDrive(drive, &stbuf) > 0 ) 228 #ifdef DEBUG_CDROM
221 AddDrive(drive, &stbuf); 229 fprintf(stderr, "Try to add drive: %s\n", drive);
222 } 230 #endif
223 closedir(devdir); 231 if (CheckDrive(drive, &stbuf) > 0)
224 } else { 232 AddDrive(drive, &stbuf);
225 #ifdef DEBUG_CDROM 233 }
226 fprintf(stderr, "cannot open dir: %s\n", checklist[i].dir); 234 closedir(devdir);
227 #endif 235 } else {
228 } 236 #ifdef DEBUG_CDROM
237 fprintf(stderr, "cannot open dir: %s\n", checklist[i].dir);
238 #endif
239 }
229 } 240 }
230 return (0); 241 return (0);
231 } 242 }
232 243
233 static const char *SDL_SYS_CDName(int drive) 244 static const char *
234 { 245 SDL_SYS_CDName(int drive)
235 return(SDL_cdlist[drive]); 246 {
236 } 247 return (SDL_cdlist[drive]);
237 248 }
238 static int SDL_SYS_CDOpen(int drive) 249
250 static int
251 SDL_SYS_CDOpen(int drive)
239 { 252 {
240 /* O_RDWR: To use ioctl(fd, SCSI_STOP_UNIT) */ 253 /* O_RDWR: To use ioctl(fd, SCSI_STOP_UNIT) */
241 return(open(SDL_cdlist[drive], (O_RDWR|O_NDELAY), 0)); 254 return (open(SDL_cdlist[drive], (O_RDWR | O_NDELAY), 0));
242 } 255 }
243 256
244 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) 257 static int
245 { 258 SDL_SYS_CDGetTOC(SDL_CD * cdrom)
246 struct cd_toc toc; 259 {
247 struct cd_toc_header hdr; 260 struct cd_toc toc;
248 struct cd_toc_entry *cdte; 261 struct cd_toc_header hdr;
262 struct cd_toc_entry *cdte;
249 int i; 263 int i;
250 int okay = 0; 264 int okay = 0;
251 if ( ioctl(cdrom->id, CDROM_TOC_HEADER, &hdr) ) { 265 if (ioctl(cdrom->id, CDROM_TOC_HEADER, &hdr)) {
252 fprintf(stderr,"ioctl error CDROM_TOC_HEADER\n"); 266 fprintf(stderr, "ioctl error CDROM_TOC_HEADER\n");
253 return -1; 267 return -1;
254 } 268 }
255 cdrom->numtracks = hdr.th_ending_track - hdr.th_starting_track + 1; 269 cdrom->numtracks = hdr.th_ending_track - hdr.th_starting_track + 1;
256 if ( cdrom->numtracks > SDL_MAX_TRACKS ) { 270 if (cdrom->numtracks > SDL_MAX_TRACKS) {
257 cdrom->numtracks = SDL_MAX_TRACKS; 271 cdrom->numtracks = SDL_MAX_TRACKS;
258 } 272 }
259 #ifdef DEBUG_CDROM 273 #ifdef DEBUG_CDROM
260 fprintf(stderr,"hdr.th_data_len1 = %d\n", hdr.th_data_len1); 274 fprintf(stderr, "hdr.th_data_len1 = %d\n", hdr.th_data_len1);
261 fprintf(stderr,"hdr.th_data_len0 = %d\n", hdr.th_data_len0); 275 fprintf(stderr, "hdr.th_data_len0 = %d\n", hdr.th_data_len0);
262 fprintf(stderr,"hdr.th_starting_track = %d\n", hdr.th_starting_track); 276 fprintf(stderr, "hdr.th_starting_track = %d\n", hdr.th_starting_track);
263 fprintf(stderr,"hdr.th_ending_track = %d\n", hdr.th_ending_track); 277 fprintf(stderr, "hdr.th_ending_track = %d\n", hdr.th_ending_track);
264 fprintf(stderr,"cdrom->numtracks = %d\n", cdrom->numtracks); 278 fprintf(stderr, "cdrom->numtracks = %d\n", cdrom->numtracks);
265 #endif 279 #endif
266 toc.toc_address_format = CDROM_LBA_FORMAT; 280 toc.toc_address_format = CDROM_LBA_FORMAT;
267 toc.toc_starting_track = 0; 281 toc.toc_starting_track = 0;
268 toc.toc_alloc_length = (hdr.th_data_len1 << 8) + 282 toc.toc_alloc_length = (hdr.th_data_len1 << 8) +
269 hdr.th_data_len0 + sizeof(hdr); 283 hdr.th_data_len0 + sizeof(hdr);
270 if ( (toc.toc_buffer = alloca(toc.toc_alloc_length)) == NULL) { 284 if ((toc.toc_buffer = alloca(toc.toc_alloc_length)) == NULL) {
271 fprintf(stderr,"cannot allocate toc.toc_buffer\n"); 285 fprintf(stderr, "cannot allocate toc.toc_buffer\n");
272 return -1; 286 return -1;
273 } 287 }
274 288
275 bzero (toc.toc_buffer, toc.toc_alloc_length); 289 bzero(toc.toc_buffer, toc.toc_alloc_length);
276 if (ioctl(cdrom->id, CDROM_TOC_ENTRYS, &toc)) { 290 if (ioctl(cdrom->id, CDROM_TOC_ENTRYS, &toc)) {
277 fprintf(stderr,"ioctl error CDROM_TOC_ENTRYS\n"); 291 fprintf(stderr, "ioctl error CDROM_TOC_ENTRYS\n");
278 return -1; 292 return -1;
279 } 293 }
280 294
281 cdte =(struct cd_toc_entry *) ((char *) toc.toc_buffer + sizeof(hdr)); 295 cdte = (struct cd_toc_entry *) ((char *) toc.toc_buffer + sizeof(hdr));
282 for (i=0; i <= cdrom->numtracks; ++i) { 296 for (i = 0; i <= cdrom->numtracks; ++i) {
283 if (i == cdrom->numtracks ) { 297 if (i == cdrom->numtracks) {
284 cdrom->track[i].id = 0xAA;; 298 cdrom->track[i].id = 0xAA;;
285 } else { 299 } else {
286 cdrom->track[i].id = hdr.th_starting_track + i; 300 cdrom->track[i].id = hdr.th_starting_track + i;
287 } 301 }
288 302
289 cdrom->track[i].type = 303 cdrom->track[i].type = cdte[i].te_control & CDROM_DATA_TRACK;
290 cdte[i].te_control & CDROM_DATA_TRACK; 304 cdrom->track[i].offset =
291 cdrom->track[i].offset = 305 cdte[i].te_absaddr.lba.addr3 << 24 |
292 cdte[i].te_absaddr.lba.addr3 << 24 | 306 cdte[i].te_absaddr.lba.addr2 << 16 |
293 cdte[i].te_absaddr.lba.addr2 << 16 | 307 cdte[i].te_absaddr.lba.addr1 << 8 | cdte[i].te_absaddr.lba.addr0;
294 cdte[i].te_absaddr.lba.addr1 << 8 | 308 cdrom->track[i].length = 0;
295 cdte[i].te_absaddr.lba.addr0; 309 if (i > 0) {
296 cdrom->track[i].length = 0; 310 cdrom->track[i - 1].length =
297 if ( i > 0 ) { 311 cdrom->track[i].offset - cdrom->track[i - 1].offset;
298 cdrom->track[i - 1].length = 312 }
299 cdrom->track[i].offset - 313 }
300 cdrom->track[i - 1].offset; 314 #ifdef DEBUG_CDROM
301 } 315 for (i = 0; i <= cdrom->numtracks; i++) {
302 } 316 fprintf(stderr, "toc_entry[%d].te_track_number = %d\n",
303 #ifdef DEBUG_CDROM 317 i, cdte[i].te_track_number);
304 for (i = 0; i <= cdrom->numtracks; i++) { 318 fprintf(stderr, "cdrom->track[%d].id = %d\n", i, cdrom->track[i].id);
305 fprintf(stderr,"toc_entry[%d].te_track_number = %d\n", 319 fprintf(stderr, "cdrom->track[%d].type = %x\n", i,
306 i,cdte[i].te_track_number); 320 cdrom->track[i].type);
307 fprintf(stderr,"cdrom->track[%d].id = %d\n", i,cdrom->track[i].id); 321 fprintf(stderr, "cdrom->track[%d].offset = %d\n", i,
308 fprintf(stderr,"cdrom->track[%d].type = %x\n", i,cdrom->track[i].type); 322 cdrom->track[i].offset);
309 fprintf(stderr,"cdrom->track[%d].offset = %d\n", i,cdrom->track[i].offset); 323 fprintf(stderr, "cdrom->track[%d].length = %d\n", i,
310 fprintf(stderr,"cdrom->track[%d].length = %d\n", i,cdrom->track[i].length); 324 cdrom->track[i].length);
311 } 325 }
312 #endif 326 #endif
313 if ( i == (cdrom->numtracks+1) ) { 327 if (i == (cdrom->numtracks + 1)) {
314 okay = 1; 328 okay = 1;
315 } 329 }
316 330
317 return(okay ? 0 : -1); 331 return (okay ? 0 : -1);
318 } 332 }
319 333
320 /* Get CD-ROM status */ 334 /* Get CD-ROM status */
321 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) 335 static CDstatus
322 { 336 SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
323 CDstatus status; 337 {
324 struct cd_sub_channel sc; 338 CDstatus status;
325 struct cd_subc_channel_data scd; 339 struct cd_sub_channel sc;
340 struct cd_subc_channel_data scd;
326 341
327 sc.sch_address_format = CDROM_LBA_FORMAT; 342 sc.sch_address_format = CDROM_LBA_FORMAT;
328 sc.sch_data_format = CDROM_CURRENT_POSITION; 343 sc.sch_data_format = CDROM_CURRENT_POSITION;
329 sc.sch_track_number = 0; 344 sc.sch_track_number = 0;
330 sc.sch_alloc_length = sizeof(scd); 345 sc.sch_alloc_length = sizeof(scd);
331 sc.sch_buffer = (caddr_t)&scd; 346 sc.sch_buffer = (caddr_t) & scd;
332 if ( ioctl(cdrom->id, CDROM_READ_SUBCHANNEL, &sc) ) { 347 if (ioctl(cdrom->id, CDROM_READ_SUBCHANNEL, &sc)) {
333 status = CD_ERROR; 348 status = CD_ERROR;
334 fprintf(stderr,"ioctl error CDROM_READ_SUBCHANNEL \n"); 349 fprintf(stderr, "ioctl error CDROM_READ_SUBCHANNEL \n");
335 } else { 350 } else {
336 switch (scd.scd_header.sh_audio_status) { 351 switch (scd.scd_header.sh_audio_status) {
337 case AS_AUDIO_INVALID: 352 case AS_AUDIO_INVALID:
338 status = CD_STOPPED; 353 status = CD_STOPPED;
339 break; 354 break;
340 case AS_PLAY_IN_PROGRESS: 355 case AS_PLAY_IN_PROGRESS:
341 status = CD_PLAYING; 356 status = CD_PLAYING;
342 break; 357 break;
343 case AS_PLAY_PAUSED: 358 case AS_PLAY_PAUSED:
344 status = CD_PAUSED; 359 status = CD_PAUSED;
345 break; 360 break;
346 case AS_PLAY_COMPLETED: 361 case AS_PLAY_COMPLETED:
347 status = CD_STOPPED; 362 status = CD_STOPPED;
348 break; 363 break;
349 case AS_PLAY_ERROR: 364 case AS_PLAY_ERROR:
350 status = CD_ERROR; 365 status = CD_ERROR;
351 break; 366 break;
352 case AS_NO_STATUS: 367 case AS_NO_STATUS:
353 status = CD_STOPPED; 368 status = CD_STOPPED;
354 break; 369 break;
355 default: 370 default:
356 status = CD_ERROR; 371 status = CD_ERROR;
357 break; 372 break;
358 } 373 }
359 #ifdef DEBUG_CDROM 374 #ifdef DEBUG_CDROM
360 fprintf(stderr,"scd.scd_header.sh_audio_status = %x\n", 375 fprintf(stderr, "scd.scd_header.sh_audio_status = %x\n",
361 scd.scd_header.sh_audio_status); 376 scd.scd_header.sh_audio_status);
362 #endif 377 #endif
363 } 378 }
364 if (position) { 379 if (position) {
365 if (status == CD_PLAYING || (status == CD_PAUSED) ) { 380 if (status == CD_PLAYING || (status == CD_PAUSED)) {
366 *position = 381 *position =
367 scd.scd_position_data.scp_absaddr.lba.addr3 << 24 | 382 scd.scd_position_data.scp_absaddr.lba.addr3 << 24 |
368 scd.scd_position_data.scp_absaddr.lba.addr2 << 16 | 383 scd.scd_position_data.scp_absaddr.lba.addr2 << 16 |
369 scd.scd_position_data.scp_absaddr.lba.addr1 << 8 | 384 scd.scd_position_data.scp_absaddr.lba.addr1 << 8 |
370 scd.scd_position_data.scp_absaddr.lba.addr0; 385 scd.scd_position_data.scp_absaddr.lba.addr0;
371 } else { 386 } else {
372 *position = 0; 387 *position = 0;
373 } 388 }
374 } 389 }
375 390
376 return status; 391 return status;
377 } 392 }
378 393
379 /* Start play */ 394 /* Start play */
380 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) 395 static int
396 SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
381 { 397 {
382 /* 398 /*
383 * Play MSF 399 * Play MSF
384 */ 400 */
385 struct cd_play_audio_msf msf; 401 struct cd_play_audio_msf msf;
386 int end; 402 int end;
387 403
388 bzero(&msf, sizeof(msf)); 404 bzero(&msf, sizeof(msf));
389 end = start +length; 405 end = start + length;
390 FRAMES_TO_MSF(start + 150, /* LBA = 4500*M + 75*S + F - 150 */ 406 FRAMES_TO_MSF(start + 150, /* LBA = 4500*M + 75*S + F - 150 */
391 &msf.msf_starting_M_unit, 407 &msf.msf_starting_M_unit,
392 &msf.msf_starting_S_unit, 408 &msf.msf_starting_S_unit, &msf.msf_starting_F_unit);
393 &msf.msf_starting_F_unit); 409 FRAMES_TO_MSF(end + 150, /* LBA = 4500*M + 75*S + F - 150 */
394 FRAMES_TO_MSF(end + 150, /* LBA = 4500*M + 75*S + F - 150 */ 410 &msf.msf_ending_M_unit,
395 &msf.msf_ending_M_unit, 411 &msf.msf_ending_S_unit, &msf.msf_ending_F_unit);
396 &msf.msf_ending_S_unit, 412
397 &msf.msf_ending_F_unit); 413 return (ioctl(cdrom->id, CDROM_PLAY_AUDIO_MSF, &msf));
398
399 return(ioctl(cdrom->id, CDROM_PLAY_AUDIO_MSF, &msf));
400 } 414 }
401 415
402 /* Pause play */ 416 /* Pause play */
403 static int SDL_SYS_CDPause(SDL_CD *cdrom) 417 static int
404 { 418 SDL_SYS_CDPause(SDL_CD * cdrom)
405 return(ioctl(cdrom->id, CDROM_PAUSE_PLAY)); 419 {
420 return (ioctl(cdrom->id, CDROM_PAUSE_PLAY));
406 } 421 }
407 422
408 /* Resume play */ 423 /* Resume play */
409 static int SDL_SYS_CDResume(SDL_CD *cdrom) 424 static int
410 { 425 SDL_SYS_CDResume(SDL_CD * cdrom)
411 return(ioctl(cdrom->id, CDROM_RESUME_PLAY)); 426 {
427 return (ioctl(cdrom->id, CDROM_RESUME_PLAY));
412 } 428 }
413 429
414 /* Stop play */ 430 /* Stop play */
415 static int SDL_SYS_CDStop(SDL_CD *cdrom) 431 static int
416 { 432 SDL_SYS_CDStop(SDL_CD * cdrom)
417 return(ioctl(cdrom->id, SCSI_STOP_UNIT)); 433 {
434 return (ioctl(cdrom->id, SCSI_STOP_UNIT));
418 } 435 }
419 436
420 /* Eject the CD-ROM */ 437 /* Eject the CD-ROM */
421 static int SDL_SYS_CDEject(SDL_CD *cdrom) 438 static int
422 { 439 SDL_SYS_CDEject(SDL_CD * cdrom)
423 return(ioctl(cdrom->id, CDROM_EJECT_CADDY)); 440 {
441 return (ioctl(cdrom->id, CDROM_EJECT_CADDY));
424 } 442 }
425 443
426 /* Close the CD-ROM handle */ 444 /* Close the CD-ROM handle */
427 static void SDL_SYS_CDClose(SDL_CD *cdrom) 445 static void
446 SDL_SYS_CDClose(SDL_CD * cdrom)
428 { 447 {
429 close(cdrom->id); 448 close(cdrom->id);
430 } 449 }
431 450
432 void SDL_SYS_CDQuit(void) 451 void
452 SDL_SYS_CDQuit(void)
433 { 453 {
434 int i; 454 int i;
435 455
436 if ( SDL_numcds > 0 ) { 456 if (SDL_numcds > 0) {
437 for ( i=0; i<SDL_numcds; ++i ) { 457 for (i = 0; i < SDL_numcds; ++i) {
438 SDL_free(SDL_cdlist[i]); 458 SDL_free(SDL_cdlist[i]);
439 } 459 }
440 SDL_numcds = 0; 460 SDL_numcds = 0;
441 } 461 }
442 } 462 }
443 463
444 #endif /* SDL_CDROM_OSF */ 464 #endif /* SDL_CDROM_OSF */
465 /* vi: set ts=4 sw=4 expandtab: */