src/cdrom/beos/SDL_syscdrom.cc
changeset 1895 c121d94672cb
parent 1635 92947e3a18db
child 2669 e27bdcc80744
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
    35 #include <Directory.h>
    35 #include <Directory.h>
    36 #include <Entry.h>
    36 #include <Entry.h>
    37 #include <Path.h>
    37 #include <Path.h>
    38 
    38 
    39 #include "SDL_cdrom.h"
    39 #include "SDL_cdrom.h"
    40 extern "C" {
    40 extern "C"
       
    41 {
    41 #include "../SDL_syscdrom.h"
    42 #include "../SDL_syscdrom.h"
    42 }
    43 }
    43 
    44 
    44 /* Constants to help us get at the SCSI table-of-contents info */
    45 /* Constants to help us get at the SCSI table-of-contents info */
    45 #define CD_NUMTRACKS(toc)	toc.toc_data[3]
    46 #define CD_NUMTRACKS(toc)	toc.toc_data[3]
    57 #define POS_REL_M(pos)	pos.position[13]
    58 #define POS_REL_M(pos)	pos.position[13]
    58 #define POS_REL_S(pos)	pos.position[14]
    59 #define POS_REL_S(pos)	pos.position[14]
    59 #define POS_REL_F(pos)	pos.position[15]
    60 #define POS_REL_F(pos)	pos.position[15]
    60 
    61 
    61 /* The maximum number of CD-ROM drives we'll detect */
    62 /* The maximum number of CD-ROM drives we'll detect */
    62 #define MAX_DRIVES	16	
    63 #define MAX_DRIVES	16
    63 
    64 
    64 /* A list of available CD-ROM drives */
    65 /* A list of available CD-ROM drives */
    65 static char *SDL_cdlist[MAX_DRIVES];
    66 static char *SDL_cdlist[MAX_DRIVES];
    66 
    67 
    67 /* The system-dependent CD control functions */
    68 /* The system-dependent CD control functions */
    68 static const char *SDL_SYS_CDName(int drive);
    69 static const char *SDL_SYS_CDName(int drive);
    69 static int SDL_SYS_CDOpen(int drive);
    70 static int SDL_SYS_CDOpen(int drive);
    70 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom);
    71 static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
    71 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position);
    72 static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
    72 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length);
    73 static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
    73 static int SDL_SYS_CDPause(SDL_CD *cdrom);
    74 static int SDL_SYS_CDPause(SDL_CD * cdrom);
    74 static int SDL_SYS_CDResume(SDL_CD *cdrom);
    75 static int SDL_SYS_CDResume(SDL_CD * cdrom);
    75 static int SDL_SYS_CDStop(SDL_CD *cdrom);
    76 static int SDL_SYS_CDStop(SDL_CD * cdrom);
    76 static int SDL_SYS_CDEject(SDL_CD *cdrom);
    77 static int SDL_SYS_CDEject(SDL_CD * cdrom);
    77 static void SDL_SYS_CDClose(SDL_CD *cdrom);
    78 static void SDL_SYS_CDClose(SDL_CD * cdrom);
    78 int try_dir(const char *directory);
    79 int try_dir(const char *directory);
    79 
    80 
    80 
    81 
    81 /* Check a drive to see if it is a CD-ROM */
    82 /* Check a drive to see if it is a CD-ROM */
    82 static int CheckDrive(char *drive)
    83 static int
    83 {
    84 CheckDrive(char *drive)
    84 	struct stat stbuf;
    85 {
    85 	int is_cd, cdfd;
    86     struct stat stbuf;
    86 	device_geometry info;
    87     int is_cd, cdfd;
    87 
    88     device_geometry info;
    88 	/* If it doesn't exist, return -1 */
    89 
    89 	if ( stat(drive, &stbuf) < 0 ) {
    90     /* If it doesn't exist, return -1 */
    90 		return(-1);
    91     if (stat(drive, &stbuf) < 0) {
    91 	}
    92         return (-1);
    92 
    93     }
    93 	/* If it does exist, verify that it's an available CD-ROM */
    94 
    94 	is_cd = 0;
    95     /* If it does exist, verify that it's an available CD-ROM */
    95 	cdfd = open(drive, 0);
    96     is_cd = 0;
    96 	if ( cdfd >= 0 ) {
    97     cdfd = open(drive, 0);
    97 		if ( ioctl(cdfd, B_GET_GEOMETRY, &info) == B_NO_ERROR ) {
    98     if (cdfd >= 0) {
    98 			if ( info.device_type == B_CD ) {
    99         if (ioctl(cdfd, B_GET_GEOMETRY, &info) == B_NO_ERROR) {
    99 				is_cd = 1;
   100             if (info.device_type == B_CD) {
   100 			}
   101                 is_cd = 1;
   101 		}
   102             }
   102 		close(cdfd);
   103         }
   103 	} else {
   104         close(cdfd);
   104 		/* This can happen when the drive is open .. (?) */;
   105     } else {
   105 		is_cd = 1;
   106         /* This can happen when the drive is open .. (?) */ ;
   106 	}
   107         is_cd = 1;
   107 	return(is_cd);
   108     }
       
   109     return (is_cd);
   108 }
   110 }
   109 
   111 
   110 /* Add a CD-ROM drive to our list of valid drives */
   112 /* Add a CD-ROM drive to our list of valid drives */
   111 static void AddDrive(char *drive)
   113 static void
   112 {
   114 AddDrive(char *drive)
   113 	int i;
   115 {
   114 	size_t len;
   116     int i;
   115 
   117     size_t len;
   116 	if ( SDL_numcds < MAX_DRIVES ) {
   118 
   117 		/* Add this drive to our list */
   119     if (SDL_numcds < MAX_DRIVES) {
   118 		i = SDL_numcds;
   120         /* Add this drive to our list */
   119 		len = SDL_strlen(drive)+1;
   121         i = SDL_numcds;
   120 		SDL_cdlist[i] = (char *)SDL_malloc(len);
   122         len = SDL_strlen(drive) + 1;
   121 		if ( SDL_cdlist[i] == NULL ) {
   123         SDL_cdlist[i] = (char *) SDL_malloc(len);
   122 			SDL_OutOfMemory();
   124         if (SDL_cdlist[i] == NULL) {
   123 			return;
   125             SDL_OutOfMemory();
   124 		}
   126             return;
   125 		SDL_strlcpy(SDL_cdlist[i], drive, len);
   127         }
   126 		++SDL_numcds;
   128         SDL_strlcpy(SDL_cdlist[i], drive, len);
       
   129         ++SDL_numcds;
   127 #ifdef CDROM_DEBUG
   130 #ifdef CDROM_DEBUG
   128   fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
   131         fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
   129 #endif
   132 #endif
   130 	}
   133     }
   131 }
   134 }
   132 
   135 
   133 /* IDE bus scanning magic */
   136 /* IDE bus scanning magic */
   134 enum {
   137 enum
   135 	IDE_GET_DEVICES_INFO = B_DEVICE_OP_CODES_END + 50,
   138 {
       
   139     IDE_GET_DEVICES_INFO = B_DEVICE_OP_CODES_END + 50,
   136 };
   140 };
   137 struct ide_ctrl_info {
   141 struct ide_ctrl_info
   138 	bool	ide_0_present;
   142 {
   139 	bool	ide_0_master_present;
   143     bool ide_0_present;
   140 	bool	ide_0_slave_present;
   144     bool ide_0_master_present;
   141 	int	ide_0_master_type;
   145     bool ide_0_slave_present;
   142 	int	ide_0_slave_type;
   146     int ide_0_master_type;
   143 	bool	ide_1_present;
   147     int ide_0_slave_type;
   144 	bool	ide_1_master_present;
   148     bool ide_1_present;
   145 	bool	ide_1_slave_present;
   149     bool ide_1_master_present;
   146 	int	ide_1_master_type;
   150     bool ide_1_slave_present;
   147 	int	ide_1_slave_type;
   151     int ide_1_master_type;
       
   152     int ide_1_slave_type;
   148 };
   153 };
   149 
   154 
   150 int  SDL_SYS_CDInit(void)
   155 int
   151 {
   156 SDL_SYS_CDInit(void)
   152 	char *SDLcdrom;
   157 {
   153 	int raw_fd;
   158     char *SDLcdrom;
   154 	struct ide_ctrl_info info;
   159     int raw_fd;
   155 
   160     struct ide_ctrl_info info;
   156 	/* Fill in our driver capabilities */
   161 
   157 	SDL_CDcaps.Name = SDL_SYS_CDName;
   162     /* Fill in our driver capabilities */
   158 	SDL_CDcaps.Open = SDL_SYS_CDOpen;
   163     SDL_CDcaps.Name = SDL_SYS_CDName;
   159 	SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
   164     SDL_CDcaps.Open = SDL_SYS_CDOpen;
   160 	SDL_CDcaps.Status = SDL_SYS_CDStatus;
   165     SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
   161 	SDL_CDcaps.Play = SDL_SYS_CDPlay;
   166     SDL_CDcaps.Status = SDL_SYS_CDStatus;
   162 	SDL_CDcaps.Pause = SDL_SYS_CDPause;
   167     SDL_CDcaps.Play = SDL_SYS_CDPlay;
   163 	SDL_CDcaps.Resume = SDL_SYS_CDResume;
   168     SDL_CDcaps.Pause = SDL_SYS_CDPause;
   164 	SDL_CDcaps.Stop = SDL_SYS_CDStop;
   169     SDL_CDcaps.Resume = SDL_SYS_CDResume;
   165 	SDL_CDcaps.Eject = SDL_SYS_CDEject;
   170     SDL_CDcaps.Stop = SDL_SYS_CDStop;
   166 	SDL_CDcaps.Close = SDL_SYS_CDClose;
   171     SDL_CDcaps.Eject = SDL_SYS_CDEject;
   167 
   172     SDL_CDcaps.Close = SDL_SYS_CDClose;
   168 	/* Look in the environment for our CD-ROM drive list */
   173 
   169 	SDLcdrom = SDL_getenv("SDL_CDROM");	/* ':' separated list of devices */
   174     /* Look in the environment for our CD-ROM drive list */
   170 	if ( SDLcdrom != NULL ) {
   175     SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
   171 		char *cdpath, *delim;
   176     if (SDLcdrom != NULL) {
   172 		size_t len = SDL_strlen(SDLcdrom)+1;
   177         char *cdpath, *delim;
   173 		cdpath = SDL_stack_alloc(char, len);
   178         size_t len = SDL_strlen(SDLcdrom) + 1;
   174 		if ( cdpath != NULL ) {
   179         cdpath = SDL_stack_alloc(char, len);
   175 			SDL_strlcpy(cdpath, SDLcdrom, len);
   180         if (cdpath != NULL) {
   176 			SDLcdrom = cdpath;
   181             SDL_strlcpy(cdpath, SDLcdrom, len);
   177 			do {
   182             SDLcdrom = cdpath;
   178 				delim = SDL_strchr(SDLcdrom, ':');
   183             do {
   179 				if ( delim ) {
   184                 delim = SDL_strchr(SDLcdrom, ':');
   180 					*delim++ = '\0';
   185                 if (delim) {
   181 				}
   186                     *delim++ = '\0';
   182 				if ( CheckDrive(SDLcdrom) > 0 ) {
   187                 }
   183 					AddDrive(SDLcdrom);
   188                 if (CheckDrive(SDLcdrom) > 0) {
   184 				}
   189                     AddDrive(SDLcdrom);
   185 				if ( delim ) {
   190                 }
   186 					SDLcdrom = delim;
   191                 if (delim) {
   187 				} else {
   192                     SDLcdrom = delim;
   188 					SDLcdrom = NULL;
   193                 } else {
   189 				}
   194                     SDLcdrom = NULL;
   190 			} while ( SDLcdrom );
   195                 }
   191 			SDL_stack_free(cdpath);
   196             }
   192 		}
   197             while (SDLcdrom);
   193 
   198             SDL_stack_free(cdpath);
   194 		/* If we found our drives, there's nothing left to do */
   199         }
   195 		if ( SDL_numcds > 0 ) {
   200 
   196 			return(0);
   201         /* If we found our drives, there's nothing left to do */
   197 		}
   202         if (SDL_numcds > 0) {
   198 	}
   203             return (0);
   199 	
   204         }
   200 	/* Scan the system for CD-ROM drives */
   205     }
   201 	try_dir("/dev/disk");
   206 
   202 	return 0;
   207     /* Scan the system for CD-ROM drives */
   203 }
   208     try_dir("/dev/disk");
   204 
   209     return 0;
   205 
   210 }
   206 int try_dir(const char *directory)
   211 
   207 { 
   212 
   208 	BDirectory dir; 
   213 int
   209 	dir.SetTo(directory); 
   214 try_dir(const char *directory)
   210 	if(dir.InitCheck() != B_NO_ERROR) { 
   215 {
   211 		return false; 
   216     BDirectory dir;
   212 	} 
   217     dir.SetTo(directory);
   213 	dir.Rewind(); 
   218     if (dir.InitCheck() != B_NO_ERROR) {
   214 	BEntry entry; 
   219         return false;
   215 	while(dir.GetNextEntry(&entry) >= 0) { 
   220     }
   216 		BPath path; 
   221     dir.Rewind();
   217 		const char *name; 
   222     BEntry entry;
   218 		entry_ref e; 
   223     while (dir.GetNextEntry(&entry) >= 0) {
   219 		
   224         BPath path;
   220 		if(entry.GetPath(&path) != B_NO_ERROR) 
   225         const char *name;
   221 			continue; 
   226         entry_ref e;
   222 		name = path.Path(); 
   227 
   223 		
   228         if (entry.GetPath(&path) != B_NO_ERROR)
   224 		if(entry.GetRef(&e) != B_NO_ERROR) 
   229             continue;
   225 			continue; 
   230         name = path.Path();
   226 
   231 
   227 		if(entry.IsDirectory()) { 
   232         if (entry.GetRef(&e) != B_NO_ERROR)
   228 			if(SDL_strcmp(e.name, "floppy") == 0) 
   233             continue;
   229 				continue; /* ignore floppy (it is not silent)  */
   234 
   230 			int devfd = try_dir(name);
   235         if (entry.IsDirectory()) {
   231 			if(devfd >= 0)
   236             if (SDL_strcmp(e.name, "floppy") == 0)
   232 				return devfd;
   237                 continue;       /* ignore floppy (it is not silent)  */
   233 		} 
   238             int devfd = try_dir(name);
   234 		else { 
   239             if (devfd >= 0)
   235 			int devfd; 
   240                 return devfd;
   236 			device_geometry g; 
   241         } else {
   237 
   242             int devfd;
   238 			if(SDL_strcmp(e.name, "raw") != 0) 
   243             device_geometry g;
   239 				continue; /* ignore partitions */
   244 
   240 
   245             if (SDL_strcmp(e.name, "raw") != 0)
   241 			devfd = open(name, O_RDONLY); 
   246                 continue;       /* ignore partitions */
   242 			if(devfd < 0) 
   247 
   243 				continue; 
   248             devfd = open(name, O_RDONLY);
   244 
   249             if (devfd < 0)
   245 			if(ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g)) >= 0) {
   250                 continue;
   246 				if(g.device_type == B_CD)
   251 
   247 				{
   252             if (ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g)) >= 0) {
   248 				AddDrive(strdup(name));
   253                 if (g.device_type == B_CD) {
   249 				}
   254                     AddDrive(strdup(name));
   250 			}
   255                 }
   251 			close(devfd);
   256             }
   252 		} 
   257             close(devfd);
   253 	}
   258         }
   254 	return B_ERROR;
   259     }
       
   260     return B_ERROR;
   255 }
   261 }
   256 
   262 
   257 
   263 
   258 /* General ioctl() CD-ROM command function */
   264 /* General ioctl() CD-ROM command function */
   259 static int SDL_SYS_CDioctl(int index, int command, void *arg)
   265 static int
   260 {
   266 SDL_SYS_CDioctl(int index, int command, void *arg)
   261 	int okay;
   267 {
   262 	int fd;
   268     int okay;
   263 
   269     int fd;
   264 	okay = 0;
   270 
   265 	fd = open(SDL_cdlist[index], 0);
   271     okay = 0;
   266 	if ( fd >= 0 ) {
   272     fd = open(SDL_cdlist[index], 0);
   267 		if ( ioctl(fd, command, arg) == B_NO_ERROR ) {
   273     if (fd >= 0) {
   268 			okay = 1;
   274         if (ioctl(fd, command, arg) == B_NO_ERROR) {
   269 		}
   275             okay = 1;
   270 		close(fd);
   276         }
   271 	}
   277         close(fd);
   272 	return(okay ? 0 : -1);
   278     }
   273 }
   279     return (okay ? 0 : -1);
   274 
   280 }
   275 static const char *SDL_SYS_CDName(int drive)
   281 
   276 {
   282 static const char *
   277 	return(SDL_cdlist[drive]);
   283 SDL_SYS_CDName(int drive)
   278 } 
   284 {
   279 
   285     return (SDL_cdlist[drive]);
   280 static int SDL_SYS_CDOpen(int drive)
   286 }
   281 {
   287 
   282 	return(drive);
   288 static int
   283 }
   289 SDL_SYS_CDOpen(int drive)
   284 
   290 {
   285 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom)
   291     return (drive);
   286 {
   292 }
   287 	int i;
   293 
   288 	scsi_toc toc;
   294 static int
   289 
   295 SDL_SYS_CDGetTOC(SDL_CD * cdrom)
   290 	if ( SDL_SYS_CDioctl(cdrom->id, B_SCSI_GET_TOC, &toc) == 0 ) {
   296 {
   291 		cdrom->numtracks = CD_NUMTRACKS(toc);
   297     int i;
   292 		if ( cdrom->numtracks > SDL_MAX_TRACKS ) {
   298     scsi_toc toc;
   293 			cdrom->numtracks = SDL_MAX_TRACKS;
   299 
   294 		}
   300     if (SDL_SYS_CDioctl(cdrom->id, B_SCSI_GET_TOC, &toc) == 0) {
   295 		for ( i=0; i<=cdrom->numtracks; ++i ) {
   301         cdrom->numtracks = CD_NUMTRACKS(toc);
   296 			cdrom->track[i].id = CD_TRACK_N(toc, i);
   302         if (cdrom->numtracks > SDL_MAX_TRACKS) {
   297 			/* FIXME:  How do we tell on BeOS? */
   303             cdrom->numtracks = SDL_MAX_TRACKS;
   298 			cdrom->track[i].type = SDL_AUDIO_TRACK;
   304         }
   299 			cdrom->track[i].offset = MSF_TO_FRAMES(
   305         for (i = 0; i <= cdrom->numtracks; ++i) {
   300 							CD_TRACK_M(toc, i),
   306             cdrom->track[i].id = CD_TRACK_N(toc, i);
   301 							CD_TRACK_S(toc, i),
   307             /* FIXME:  How do we tell on BeOS? */
   302 							CD_TRACK_F(toc, i));
   308             cdrom->track[i].type = SDL_AUDIO_TRACK;
   303 			cdrom->track[i].length = 0;
   309             cdrom->track[i].offset = MSF_TO_FRAMES(CD_TRACK_M(toc, i),
   304 			if ( i > 0 ) {
   310                                                    CD_TRACK_S(toc, i),
   305 				cdrom->track[i-1].length =
   311                                                    CD_TRACK_F(toc, i));
   306 						cdrom->track[i].offset-
   312             cdrom->track[i].length = 0;
   307 						cdrom->track[i-1].offset;
   313             if (i > 0) {
   308 			}
   314                 cdrom->track[i - 1].length =
   309 		}
   315                     cdrom->track[i].offset - cdrom->track[i - 1].offset;
   310 		return(0);
   316             }
   311 	} else {
   317         }
   312 		return(-1);
   318         return (0);
   313 	}
   319     } else {
       
   320         return (-1);
       
   321     }
   314 }
   322 }
   315 
   323 
   316 /* Get CD-ROM status */
   324 /* Get CD-ROM status */
   317 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position)
   325 static CDstatus
   318 {
   326 SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
   319 	CDstatus status;
   327 {
   320 	int fd;
   328     CDstatus status;
   321 	int cur_frame;
   329     int fd;
   322 	scsi_position pos;
   330     int cur_frame;
   323 
   331     scsi_position pos;
   324 	fd = open(SDL_cdlist[cdrom->id], 0);
   332 
   325 	cur_frame = 0;
   333     fd = open(SDL_cdlist[cdrom->id], 0);
   326 	if ( fd >= 0 ) {
   334     cur_frame = 0;
   327 		if ( ioctl(fd, B_SCSI_GET_POSITION, &pos) == B_NO_ERROR ) {
   335     if (fd >= 0) {
   328 			cur_frame = MSF_TO_FRAMES(
   336         if (ioctl(fd, B_SCSI_GET_POSITION, &pos) == B_NO_ERROR) {
   329 				POS_ABS_M(pos), POS_ABS_S(pos), POS_ABS_F(pos));
   337             cur_frame =
   330 		}
   338                 MSF_TO_FRAMES(POS_ABS_M(pos), POS_ABS_S(pos), POS_ABS_F(pos));
   331 		if ( ! pos.position[1] || (pos.position[1] >= 0x13) ||
   339         }
   332 			((pos.position[1] == 0x12) && (!pos.position[6])) ) {
   340         if (!pos.position[1] || (pos.position[1] >= 0x13) ||
   333 			status = CD_STOPPED;
   341             ((pos.position[1] == 0x12) && (!pos.position[6]))) {
   334 		} else
   342             status = CD_STOPPED;
   335 		if ( pos.position[1] == 0x11 ) {
   343         } else if (pos.position[1] == 0x11) {
   336 			status = CD_PLAYING;
   344             status = CD_PLAYING;
   337 		} else {
   345         } else {
   338 			status = CD_PAUSED;
   346             status = CD_PAUSED;
   339 		}
   347         }
   340 		close(fd);
   348         close(fd);
   341 	} else {
   349     } else {
   342 		status = CD_TRAYEMPTY;
   350         status = CD_TRAYEMPTY;
   343 	}
   351     }
   344 	if ( position ) {
   352     if (position) {
   345 		*position = cur_frame;
   353         *position = cur_frame;
   346 	}
   354     }
   347 	return(status);
   355     return (status);
   348 }
   356 }
   349 
   357 
   350 /* Start play */
   358 /* Start play */
   351 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length)
   359 static int
   352 {
   360 SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
   353 	int okay;
   361 {
   354 	int fd;
   362     int okay;
   355 	scsi_play_position pos;
   363     int fd;
   356 
   364     scsi_play_position pos;
   357 	okay = 0;
   365 
   358 	fd = open(SDL_cdlist[cdrom->id], 0);
   366     okay = 0;
   359 	if ( fd >= 0 ) {
   367     fd = open(SDL_cdlist[cdrom->id], 0);
   360 		FRAMES_TO_MSF(start, &pos.start_m, &pos.start_s, &pos.start_f);
   368     if (fd >= 0) {
   361 		FRAMES_TO_MSF(start+length, &pos.end_m, &pos.end_s, &pos.end_f);
   369         FRAMES_TO_MSF(start, &pos.start_m, &pos.start_s, &pos.start_f);
   362 		if ( ioctl(fd, B_SCSI_PLAY_POSITION, &pos) == B_NO_ERROR ) {
   370         FRAMES_TO_MSF(start + length, &pos.end_m, &pos.end_s, &pos.end_f);
   363 			okay = 1;
   371         if (ioctl(fd, B_SCSI_PLAY_POSITION, &pos) == B_NO_ERROR) {
   364 		}
   372             okay = 1;
   365 		close(fd);
   373         }
   366 	}
   374         close(fd);
   367 	return(okay ? 0 : -1);
   375     }
       
   376     return (okay ? 0 : -1);
   368 }
   377 }
   369 
   378 
   370 /* Pause play */
   379 /* Pause play */
   371 static int SDL_SYS_CDPause(SDL_CD *cdrom)
   380 static int
   372 {
   381 SDL_SYS_CDPause(SDL_CD * cdrom)
   373 	return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_PAUSE_AUDIO, 0));
   382 {
       
   383     return (SDL_SYS_CDioctl(cdrom->id, B_SCSI_PAUSE_AUDIO, 0));
   374 }
   384 }
   375 
   385 
   376 /* Resume play */
   386 /* Resume play */
   377 static int SDL_SYS_CDResume(SDL_CD *cdrom)
   387 static int
   378 {
   388 SDL_SYS_CDResume(SDL_CD * cdrom)
   379 	return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_RESUME_AUDIO, 0));
   389 {
       
   390     return (SDL_SYS_CDioctl(cdrom->id, B_SCSI_RESUME_AUDIO, 0));
   380 }
   391 }
   381 
   392 
   382 /* Stop play */
   393 /* Stop play */
   383 static int SDL_SYS_CDStop(SDL_CD *cdrom)
   394 static int
   384 {
   395 SDL_SYS_CDStop(SDL_CD * cdrom)
   385 	return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_STOP_AUDIO, 0));
   396 {
       
   397     return (SDL_SYS_CDioctl(cdrom->id, B_SCSI_STOP_AUDIO, 0));
   386 }
   398 }
   387 
   399 
   388 /* Eject the CD-ROM */
   400 /* Eject the CD-ROM */
   389 static int SDL_SYS_CDEject(SDL_CD *cdrom)
   401 static int
   390 {
   402 SDL_SYS_CDEject(SDL_CD * cdrom)
   391 	return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_EJECT, 0));
   403 {
       
   404     return (SDL_SYS_CDioctl(cdrom->id, B_SCSI_EJECT, 0));
   392 }
   405 }
   393 
   406 
   394 /* Close the CD-ROM handle */
   407 /* Close the CD-ROM handle */
   395 static void SDL_SYS_CDClose(SDL_CD *cdrom)
   408 static void
   396 {
   409 SDL_SYS_CDClose(SDL_CD * cdrom)
   397 	close(cdrom->id);
   410 {
   398 }
   411     close(cdrom->id);
   399 
   412 }
   400 void SDL_SYS_CDQuit(void)
   413 
   401 {
   414 void
   402 	int i;
   415 SDL_SYS_CDQuit(void)
   403 
   416 {
   404 	if ( SDL_numcds > 0 ) {
   417     int i;
   405 		for ( i=0; i<SDL_numcds; ++i ) {
   418 
   406 			SDL_free(SDL_cdlist[i]);
   419     if (SDL_numcds > 0) {
   407 		}
   420         for (i = 0; i < SDL_numcds; ++i) {
   408 		SDL_numcds = 0;
   421             SDL_free(SDL_cdlist[i]);
   409 	}
   422         }
       
   423         SDL_numcds = 0;
       
   424     }
   410 }
   425 }
   411 
   426 
   412 #endif /* SDL_CDROM_BEOS */
   427 #endif /* SDL_CDROM_BEOS */
       
   428 /* vi: set ts=4 sw=4 expandtab: */