Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
authorSam Lantinga <slouken@libsdl.org>
Sat, 18 Aug 2001 22:03:11 +0000
changeset 1532839f45bdba0
parent 152 2cf88672fc7f
child 154 50d2b5305c2c
Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
configure.in
docs.html
src/cdrom/Makefile.am
src/cdrom/aix/.cvsignore
src/cdrom/aix/Makefile.am
src/cdrom/beos/.cvsignore
src/cdrom/beos/Makefile.am
src/cdrom/beos/SDL_syscdrom.c
src/cdrom/beos/SDL_syscdrom.cc
src/cdrom/dummy/.cvsignore
src/cdrom/dummy/Makefile.am
src/cdrom/freebsd/.cvsignore
src/cdrom/freebsd/Makefile.am
src/cdrom/linux/.cvsignore
src/cdrom/linux/Makefile.am
src/cdrom/macos/.cvsignore
src/cdrom/macos/Makefile.am
src/cdrom/openbsd/.cvsignore
src/cdrom/openbsd/Makefile.am
src/cdrom/qnx/.cvsignore
src/cdrom/qnx/Makefile.am
src/cdrom/win32/.cvsignore
src/cdrom/win32/Makefile.am
     1.1 --- a/configure.in	Sat Aug 18 21:58:26 2001 +0000
     1.2 +++ b/configure.in	Sat Aug 18 22:03:11 2001 +0000
     1.3 @@ -1237,7 +1237,8 @@
     1.4          fi
     1.5          # Set up files for the cdrom library
     1.6          if test x$enable_cdrom = xyes; then
     1.7 -            COPY_ARCH_SRC(src/cdrom, linux, SDL_syscdrom.c)
     1.8 +            CDROM_SUBDIRS="$CDROM_SUBDIRS linux"
     1.9 +            CDROM_DRIVERS="$CDROM_DRIVERS linux/libcdrom_linux.la"
    1.10          fi
    1.11          # Set up files for the thread library
    1.12          if test x$enable_threads = xyes; then
    1.13 @@ -1302,7 +1303,8 @@
    1.14          # Set up files for the cdrom library
    1.15          # (No cdrom support yet)
    1.16          if test x$enable_cdrom = xyes; then
    1.17 -            COPY_ARCH_SRC(src/cdrom, dummy, SDL_syscdrom.c)
    1.18 +            CDROM_SUBDIRS="$CDROM_SUBDIRS dummy"
    1.19 +            CDROM_DRIVERS="$CDROM_DRIVERS dummy/libcdrom_dummy.la"
    1.20          fi
    1.21          # Set up files for the thread library
    1.22          if test x$enable_threads = xyes; then
    1.23 @@ -1353,7 +1355,8 @@
    1.24          fi
    1.25          # Set up files for the cdrom library
    1.26          if test x$enable_cdrom = xyes; then
    1.27 -            COPY_ARCH_SRC(src/cdrom, freebsd, SDL_syscdrom.c)
    1.28 +            CDROM_SUBDIRS="$CDROM_SUBDIRS freebsd"
    1.29 +            CDROM_DRIVERS="$CDROM_DRIVERS freebsd/libcdrom_freebsd.la"
    1.30          fi
    1.31          # Set up files for the thread library
    1.32          if test x$enable_threads = xyes; then
    1.33 @@ -1404,7 +1407,8 @@
    1.34          fi
    1.35          # Set up files for the cdrom library
    1.36          if test x$enable_cdrom = xyes; then
    1.37 -            COPY_ARCH_SRC(src/cdrom, openbsd, SDL_syscdrom.c)
    1.38 +            CDROM_SUBDIRS="$CDROM_SUBDIRS openbsd"
    1.39 +            CDROM_DRIVERS="$CDROM_DRIVERS openbsd/libcdrom_openbsd.la"
    1.40          fi
    1.41          # Set up files for the thread library
    1.42          if test x$enable_threads = xyes; then
    1.43 @@ -1463,7 +1467,8 @@
    1.44          fi
    1.45          # Set up files for the cdrom library
    1.46          if test x$enable_cdrom = xyes; then
    1.47 -            COPY_ARCH_SRC(src/cdrom, openbsd, SDL_syscdrom.c)
    1.48 +            CDROM_SUBDIRS="$CDROM_SUBDIRS openbsd"
    1.49 +            CDROM_DRIVERS="$CDROM_DRIVERS openbsd/libcdrom_openbsd.la"
    1.50          fi
    1.51          # Set up files for the thread library
    1.52          if test x$enable_threads = xyes; then
    1.53 @@ -1517,7 +1522,8 @@
    1.54          fi
    1.55          # Set up files for the cdrom library
    1.56          if test x$enable_cdrom = xyes; then
    1.57 -            COPY_ARCH_SRC(src/cdrom, dummy, SDL_syscdrom.c)
    1.58 +            CDROM_SUBDIRS="$CDROM_SUBDIRS dummy"
    1.59 +            CDROM_DRIVERS="$CDROM_DRIVERS dummy/libcdrom_dummy.la"
    1.60          fi
    1.61          # Set up files for the thread library
    1.62          if test x$enable_threads = xyes; then
    1.63 @@ -1566,7 +1572,8 @@
    1.64          fi
    1.65          # Set up files for the cdrom library
    1.66          if test x$enable_cdrom = xyes; then
    1.67 -            COPY_ARCH_SRC(src/cdrom, linux, SDL_syscdrom.c)
    1.68 +            CDROM_SUBDIRS="$CDROM_SUBDIRS linux"
    1.69 +            CDROM_DRIVERS="$CDROM_DRIVERS linux/libcdrom_linux.la"
    1.70          fi
    1.71          # Set up files for the thread library
    1.72          if test x$enable_threads = xyes; then
    1.73 @@ -1612,7 +1619,8 @@
    1.74          # Set up files for the cdrom library
    1.75          # (No CD-ROM support yet)
    1.76          if test x$enable_cdrom = xyes; then
    1.77 -            COPY_ARCH_SRC(src/cdrom, dummy, SDL_syscdrom.c)
    1.78 +            CDROM_SUBDIRS="$CDROM_SUBDIRS dummy"
    1.79 +            CDROM_DRIVERS="$CDROM_DRIVERS dummy/libcdrom_dummy.la"
    1.80          fi
    1.81          # Set up files for the thread library
    1.82          if test x$enable_threads = xyes; then
    1.83 @@ -1673,7 +1681,8 @@
    1.84          # Set up files for the cdrom library
    1.85          # (No CD-ROM support yet)
    1.86          if test x$enable_cdrom = xyes; then
    1.87 -            COPY_ARCH_SRC(src/cdrom, dummy, SDL_syscdrom.c)
    1.88 +            CDROM_SUBDIRS="$CDROM_SUBDIRS dummy"
    1.89 +            CDROM_DRIVERS="$CDROM_DRIVERS dummy/libcdrom_dummy.la"
    1.90          fi
    1.91          # Set up files for the thread library
    1.92          if test x$enable_threads = xyes; then
    1.93 @@ -1717,7 +1726,8 @@
    1.94          fi
    1.95          # Set up files for the cdrom library
    1.96          if test x$enable_cdrom = xyes; then
    1.97 -            COPY_ARCH_SRC(src/cdrom, aix, SDL_syscdrom.c)
    1.98 +            CDROM_SUBDIRS="$CDROM_SUBDIRS aix"
    1.99 +            CDROM_DRIVERS="$CDROM_DRIVERS aix/libcdrom_aix.la"
   1.100          fi
   1.101          # Set up files for the thread library
   1.102          if test x$enable_threads = xyes; then
   1.103 @@ -1762,7 +1772,8 @@
   1.104          # Set up files for the cdrom library
   1.105          # (No cdrom support yet)
   1.106          if test x$enable_cdrom = xyes; then
   1.107 -            COPY_ARCH_SRC(src/cdrom, dummy, SDL_syscdrom.c)
   1.108 +            CDROM_SUBDIRS="$CDROM_SUBDIRS dummy"
   1.109 +            CDROM_DRIVERS="$CDROM_DRIVERS dummy/libcdrom_dummy.la"
   1.110          fi
   1.111          # Set up files for the thread library
   1.112          if test x$enable_threads = xyes; then
   1.113 @@ -1806,7 +1817,8 @@
   1.114          fi
   1.115          # Set up files for the cdrom library
   1.116          if test x$enable_cdrom = xyes; then
   1.117 -            COPY_ARCH_SRC(src/cdrom, qnx, SDL_syscdrom.c)
   1.118 +            CDROM_SUBDIRS="$CDROM_SUBDIRS qnx"
   1.119 +            CDROM_DRIVERS="$CDROM_DRIVERS qnx/libcdrom_qnx.la"
   1.120          fi
   1.121          # Set up files for the thread library
   1.122          if test x$enable_threads = xyes; then
   1.123 @@ -1858,7 +1870,8 @@
   1.124          fi
   1.125          # Set up files for the cdrom library
   1.126          if test x$enable_cdrom = xyes; then
   1.127 -            COPY_ARCH_SRC(src/cdrom, win32, SDL_syscdrom.c)
   1.128 +            CDROM_SUBDIRS="$CDROM_SUBDIRS win32"
   1.129 +            CDROM_DRIVERS="$CDROM_DRIVERS win32/libcdrom_win32.la"
   1.130          fi
   1.131          # Set up files for the thread library
   1.132          if test x$enable_threads = xyes; then
   1.133 @@ -1913,7 +1926,8 @@
   1.134          fi
   1.135          # Set up files for the cdrom library
   1.136          if test x$enable_cdrom = xyes; then
   1.137 -            COPY_ARCH_SRC(src/cdrom, beos, SDL_syscdrom.c)
   1.138 +            CDROM_SUBDIRS="$CDROM_SUBDIRS beos"
   1.139 +            CDROM_DRIVERS="$CDROM_DRIVERS beos/libcdrom_beos.la"
   1.140          fi
   1.141          # Set up files for the thread library
   1.142          if test x$enable_threads = xyes; then
   1.143 @@ -1956,7 +1970,8 @@
   1.144          fi
   1.145          # Set up files for the cdrom library
   1.146          if test x$enable_cdrom = xyes; then
   1.147 -            COPY_ARCH_SRC(src/cdrom, macos, SDL_syscdrom.c)
   1.148 +            CDROM_SUBDIRS="$CDROM_SUBDIRS macos"
   1.149 +            CDROM_DRIVERS="$CDROM_DRIVERS macos/libcdrom_macos.la"
   1.150          fi
   1.151          # Set up files for the thread library
   1.152          if test x$enable_threads = xyes; then
   1.153 @@ -2002,7 +2017,8 @@
   1.154          fi
   1.155          # Set up files for the cdrom library
   1.156          if test x$enable_cdrom = xyes; then
   1.157 -            COPY_ARCH_SRC(src/cdrom, dummy, SDL_syscdrom.c)
   1.158 +            CDROM_SUBDIRS="$CDROM_SUBDIRS dummy"
   1.159 +            CDROM_DRIVERS="$CDROM_DRIVERS dummy/libcdrom_dummy.la"
   1.160          fi
   1.161          # Set up files for the thread library
   1.162          if test x$enable_threads = xyes; then
   1.163 @@ -2077,6 +2093,8 @@
   1.164  AC_SUBST(VIDEO_DRIVERS)
   1.165  AC_SUBST(JOYSTICK_SUBDIRS)
   1.166  AC_SUBST(JOYSTICK_DRIVERS)
   1.167 +AC_SUBST(CDROM_SUBDIRS)
   1.168 +AC_SUBST(CDROM_DRIVERS)
   1.169  AC_SUBST(SDL_EXTRADIRS)
   1.170  AC_SUBST(SDL_EXTRALIBS)
   1.171  AC_SUBST(SYSTEM_LIBS)
   1.172 @@ -2164,6 +2182,15 @@
   1.173  src/joystick/macos/Makefile
   1.174  src/joystick/win32/Makefile
   1.175  src/cdrom/Makefile
   1.176 +src/cdrom/aix/Makefile
   1.177 +src/cdrom/beos/Makefile
   1.178 +src/cdrom/dummy/Makefile
   1.179 +src/cdrom/freebsd/Makefile
   1.180 +src/cdrom/linux/Makefile
   1.181 +src/cdrom/macos/Makefile
   1.182 +src/cdrom/openbsd/Makefile
   1.183 +src/cdrom/qnx/Makefile
   1.184 +src/cdrom/win32/Makefile
   1.185  src/thread/Makefile
   1.186  src/timer/Makefile
   1.187  src/endian/Makefile
     2.1 --- a/docs.html	Sat Aug 18 21:58:26 2001 +0000
     2.2 +++ b/docs.html	Sat Aug 18 22:03:11 2001 +0000
     2.3 @@ -16,6 +16,7 @@
     2.4  Major changes since SDL 1.0.0:
     2.5  </H2>
     2.6  <UL>
     2.7 +	<LI> 1.2.3: Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
     2.8  	<LI> 1.2.3: Fixed the system dependent SDL_WINDOWID hack on Windows
     2.9  	<LI> 1.2.3: Added 640x480 as a scaled resolution for NTSC/PAL output 
    2.10  	<LI> 1.2.3: Added support for TV output on the Linux PlayStation Beta
     3.1 --- a/src/cdrom/Makefile.am	Sat Aug 18 21:58:26 2001 +0000
     3.2 +++ b/src/cdrom/Makefile.am	Sat Aug 18 22:03:11 2001 +0000
     3.3 @@ -3,27 +3,17 @@
     3.4  
     3.5  noinst_LTLIBRARIES = libcdrom.la
     3.6  
     3.7 -ARCH_SUBDIRS = $(srcdir)/dummy $(srcdir)/beos $(srcdir)/freebsd \
     3.8 -	$(srcdir)/linux $(srcdir)/macos $(srcdir)/openbsd \
     3.9 -	$(srcdir)/qnx $(srcdir)/win32
    3.10 +# Define which subdirectories need to be built
    3.11 +SUBDIRS = @CDROM_SUBDIRS@
    3.12 +DIST_SUBDIRS = aix beos dummy freebsd linux macos openbsd qnx win32
    3.13 +
    3.14 +DRIVERS = @CDROM_DRIVERS@
    3.15  
    3.16  # Include the architecture-independent sources
    3.17 -COMMON_SRCS = SDL_cdrom.c SDL_syscdrom.h
    3.18 +COMMON_SRCS =			\
    3.19 +	SDL_cdrom.c		\
    3.20 +	SDL_syscdrom.h
    3.21  
    3.22 -# Include the architecture-specific sources
    3.23 -ARCH_SRCS = SDL_syscdrom.c
    3.24 -
    3.25 -libcdrom_la_SOURCES = $(COMMON_SRCS) $(ARCH_SRCS)
    3.26 -
    3.27 -## Let automake know that it shouldn't distribute linked sources
    3.28 -BUILT_SOURCES = $(ARCH_SRCS)
    3.29 -
    3.30 -## Let automake know that it should remove these for distribution
    3.31 -DISTCLEANFILES = $(ARCH_SRCS)
    3.32 -
    3.33 -# The architecture specific directories need to be copied into place
    3.34 -# when building a distribution.
    3.35 -dist-hook:
    3.36 -	(cd $(distdir) && rm -f $(BUILT_SOURCES))
    3.37 -	cp -rp $(ARCH_SUBDIRS) $(distdir)
    3.38 -	(cd $(distdir) && rm -rf `find . -name CVS`)
    3.39 +libcdrom_la_SOURCES = $(COMMON_SRCS)
    3.40 +libcdrom_la_LIBADD = $(DRIVERS)
    3.41 +libcdrom_la_DEPENDENCIES = $(DRIVERS)
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/cdrom/aix/.cvsignore	Sat Aug 18 22:03:11 2001 +0000
     4.3 @@ -0,0 +1,6 @@
     4.4 +Makefile.in
     4.5 +Makefile
     4.6 +.libs
     4.7 +*.o
     4.8 +*.lo
     4.9 +*.la
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/cdrom/aix/Makefile.am	Sat Aug 18 22:03:11 2001 +0000
     5.3 @@ -0,0 +1,8 @@
     5.4 +
     5.5 +## Makefile.am for the AIX cdrom driver for SDL
     5.6 +
     5.7 +noinst_LTLIBRARIES = libcdrom_aix.la
     5.8 +libcdrom_aix_la_SOURCES = $(SRCS)
     5.9 +
    5.10 +# The SDL cdrom driver sources
    5.11 +SRCS =  SDL_syscdrom.c
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/cdrom/beos/.cvsignore	Sat Aug 18 22:03:11 2001 +0000
     6.3 @@ -0,0 +1,6 @@
     6.4 +Makefile.in
     6.5 +Makefile
     6.6 +.libs
     6.7 +*.o
     6.8 +*.lo
     6.9 +*.la
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/cdrom/beos/Makefile.am	Sat Aug 18 22:03:11 2001 +0000
     7.3 @@ -0,0 +1,8 @@
     7.4 +
     7.5 +## Makefile.am for the BeOS cdrom driver for SDL
     7.6 +
     7.7 +noinst_LTLIBRARIES = libcdrom_beos.la
     7.8 +libcdrom_beos_la_SOURCES = $(SRCS)
     7.9 +
    7.10 +# The SDL cdrom driver sources
    7.11 +SRCS =  SDL_syscdrom.cc
     8.1 --- a/src/cdrom/beos/SDL_syscdrom.c	Sat Aug 18 21:58:26 2001 +0000
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,398 +0,0 @@
     8.4 -/*
     8.5 -    SDL - Simple DirectMedia Layer
     8.6 -    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     8.7 -
     8.8 -    This library is free software; you can redistribute it and/or
     8.9 -    modify it under the terms of the GNU Library General Public
    8.10 -    License as published by the Free Software Foundation; either
    8.11 -    version 2 of the License, or (at your option) any later version.
    8.12 -
    8.13 -    This library is distributed in the hope that it will be useful,
    8.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    8.16 -    Library General Public License for more details.
    8.17 -
    8.18 -    You should have received a copy of the GNU Library General Public
    8.19 -    License along with this library; if not, write to the Free
    8.20 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    8.21 -
    8.22 -    Sam Lantinga
    8.23 -    slouken@devolution.com
    8.24 -*/
    8.25 -
    8.26 -#ifdef SAVE_RCSID
    8.27 -static char rcsid =
    8.28 - "@(#) $Id$";
    8.29 -#endif
    8.30 -
    8.31 -/* Functions for system-level CD-ROM audio control on BeOS
    8.32 -   (not completely implemented yet)
    8.33 - */
    8.34 -
    8.35 -#include <sys/types.h>
    8.36 -#include <stdlib.h>
    8.37 -#include <sys/stat.h>
    8.38 -#include <stdio.h>
    8.39 -#include <string.h>
    8.40 -#include <unistd.h>
    8.41 -
    8.42 -#include <scsi.h>
    8.43 -
    8.44 -#include "SDL_error.h"
    8.45 -#include "SDL_cdrom.h"
    8.46 -#include "SDL_syscdrom.h"
    8.47 -
    8.48 -/* Constants to help us get at the SCSI table-of-contents info */
    8.49 -#define CD_NUMTRACKS(toc)	toc.toc_data[3]
    8.50 -#define CD_TRACK(toc, track)	(&toc.toc_data[6+(track)*8])
    8.51 -#define CD_TRACK_N(toc, track)	CD_TRACK(toc, track)[0]
    8.52 -#define CD_TRACK_M(toc, track)	CD_TRACK(toc, track)[3]
    8.53 -#define CD_TRACK_S(toc, track)	CD_TRACK(toc, track)[4]
    8.54 -#define CD_TRACK_F(toc, track)	CD_TRACK(toc, track)[5]
    8.55 -
    8.56 -/* Constants to help us get at the SCSI position info */
    8.57 -#define POS_TRACK(pos)	pos.position[6]
    8.58 -#define POS_ABS_M(pos)	pos.position[9]
    8.59 -#define POS_ABS_S(pos)	pos.position[10]
    8.60 -#define POS_ABS_F(pos)	pos.position[11]
    8.61 -#define POS_REL_M(pos)	pos.position[13]
    8.62 -#define POS_REL_S(pos)	pos.position[14]
    8.63 -#define POS_REL_F(pos)	pos.position[15]
    8.64 -
    8.65 -/* The maximum number of CD-ROM drives we'll detect */
    8.66 -#define MAX_DRIVES	16	
    8.67 -
    8.68 -/* A list of available CD-ROM drives */
    8.69 -static char *SDL_cdlist[MAX_DRIVES];
    8.70 -
    8.71 -/* The system-dependent CD control functions */
    8.72 -static const char *SDL_SYS_CDName(int drive);
    8.73 -static int SDL_SYS_CDOpen(int drive);
    8.74 -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom);
    8.75 -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position);
    8.76 -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length);
    8.77 -static int SDL_SYS_CDPause(SDL_CD *cdrom);
    8.78 -static int SDL_SYS_CDResume(SDL_CD *cdrom);
    8.79 -static int SDL_SYS_CDStop(SDL_CD *cdrom);
    8.80 -static int SDL_SYS_CDEject(SDL_CD *cdrom);
    8.81 -static void SDL_SYS_CDClose(SDL_CD *cdrom);
    8.82 -
    8.83 -
    8.84 -/* Check a drive to see if it is a CD-ROM */
    8.85 -static int CheckDrive(char *drive)
    8.86 -{
    8.87 -	struct stat stbuf;
    8.88 -	int is_cd, cdfd;
    8.89 -	device_geometry info;
    8.90 -
    8.91 -	/* If it doesn't exist, return -1 */
    8.92 -	if ( stat(drive, &stbuf) < 0 ) {
    8.93 -		return(-1);
    8.94 -	}
    8.95 -
    8.96 -	/* If it does exist, verify that it's an available CD-ROM */
    8.97 -	is_cd = 0;
    8.98 -	cdfd = open(drive, 0);
    8.99 -	if ( cdfd >= 0 ) {
   8.100 -		if ( ioctl(cdfd, B_GET_GEOMETRY, &info) == B_NO_ERROR ) {
   8.101 -			if ( info.device_type == B_CD ) {
   8.102 -				is_cd = 1;
   8.103 -			}
   8.104 -		}
   8.105 -		close(cdfd);
   8.106 -	} else {
   8.107 -		/* This can happen when the drive is open .. (?) */;
   8.108 -		is_cd = 1;
   8.109 -	}
   8.110 -	return(is_cd);
   8.111 -}
   8.112 -
   8.113 -/* Add a CD-ROM drive to our list of valid drives */
   8.114 -static void AddDrive(char *drive)
   8.115 -{
   8.116 -	int i;
   8.117 -
   8.118 -	if ( SDL_numcds < MAX_DRIVES ) {
   8.119 -		/* Add this drive to our list */
   8.120 -		i = SDL_numcds;
   8.121 -		SDL_cdlist[i] = (char *)malloc(strlen(drive)+1);
   8.122 -		if ( SDL_cdlist[i] == NULL ) {
   8.123 -			SDL_OutOfMemory();
   8.124 -			return;
   8.125 -		}
   8.126 -		strcpy(SDL_cdlist[i], drive);
   8.127 -		++SDL_numcds;
   8.128 -#ifdef CDROM_DEBUG
   8.129 -  fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
   8.130 -#endif
   8.131 -	}
   8.132 -}
   8.133 -
   8.134 -# if 0 /* Save this for later, when I can test it */
   8.135 -/* SCSI bus scanning magic */
   8.136 -static int CheckSCSI(int path, int id, int lun)
   8.137 -{
   8.138 -	int is_cd;
   8.139 -	int fd;
   8.140 -	scsiprobe_inquiry inquiry;
   8.141 -
   8.142 -	is_cd = 0;
   8.143 -	fd = open("/dev/scsiprobe", 0);
   8.144 -	if ( fd >= 0 ) {
   8.145 -		inquiry.path = path;
   8.146 -		inquiry.id = id;
   8.147 -		inquiry.lun = lun;
   8.148 -		inquiry.len = sizeof(inquiry);
   8.149 -		if ( ioctl(fd, B_SCSIPROBE_INQUIRY, &inquiry) == B_NO_ERROR ) {
   8.150 -			if ( (inquiry.data[0]&0x1F) == B_SCSI_CD ) {
   8.151 -				is_cd = 1;
   8.152 -			}
   8.153 -		}
   8.154 -		close(fd);
   8.155 -	}
   8.156 -	return(is_cd);
   8.157 -}
   8.158 -#endif
   8.159 -		
   8.160 -/* IDE bus scanning magic */
   8.161 -enum {
   8.162 -	IDE_GET_DEVICES_INFO = B_DEVICE_OP_CODES_END + 50,
   8.163 -};
   8.164 -struct ide_ctrl_info {
   8.165 -	bool	ide_0_present;
   8.166 -	bool	ide_0_master_present;
   8.167 -	bool	ide_0_slave_present;
   8.168 -	int	ide_0_master_type;
   8.169 -	int	ide_0_slave_type;
   8.170 -	bool	ide_1_present;
   8.171 -	bool	ide_1_master_present;
   8.172 -	bool	ide_1_slave_present;
   8.173 -	int	ide_1_master_type;
   8.174 -	int	ide_1_slave_type;
   8.175 -};
   8.176 -
   8.177 -int  SDL_SYS_CDInit(void)
   8.178 -{
   8.179 -	char *SDLcdrom;
   8.180 -	int raw_fd;
   8.181 -	struct ide_ctrl_info info;
   8.182 -
   8.183 -	/* Fill in our driver capabilities */
   8.184 -	SDL_CDcaps.Name = SDL_SYS_CDName;
   8.185 -	SDL_CDcaps.Open = SDL_SYS_CDOpen;
   8.186 -	SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
   8.187 -	SDL_CDcaps.Status = SDL_SYS_CDStatus;
   8.188 -	SDL_CDcaps.Play = SDL_SYS_CDPlay;
   8.189 -	SDL_CDcaps.Pause = SDL_SYS_CDPause;
   8.190 -	SDL_CDcaps.Resume = SDL_SYS_CDResume;
   8.191 -	SDL_CDcaps.Stop = SDL_SYS_CDStop;
   8.192 -	SDL_CDcaps.Eject = SDL_SYS_CDEject;
   8.193 -	SDL_CDcaps.Close = SDL_SYS_CDClose;
   8.194 -
   8.195 -	/* Look in the environment for our CD-ROM drive list */
   8.196 -	SDLcdrom = getenv("SDL_CDROM");	/* ':' separated list of devices */
   8.197 -	if ( SDLcdrom != NULL ) {
   8.198 -		char *cdpath, *delim;
   8.199 -		cdpath = malloc(strlen(SDLcdrom)+1);
   8.200 -		if ( cdpath != NULL ) {
   8.201 -			strcpy(cdpath, SDLcdrom);
   8.202 -			SDLcdrom = cdpath;
   8.203 -			do {
   8.204 -				delim = strchr(SDLcdrom, ':');
   8.205 -				if ( delim ) {
   8.206 -					*delim++ = '\0';
   8.207 -				}
   8.208 -				if ( CheckDrive(SDLcdrom) > 0 ) {
   8.209 -					AddDrive(SDLcdrom);
   8.210 -				}
   8.211 -				if ( delim ) {
   8.212 -					SDLcdrom = delim;
   8.213 -				} else {
   8.214 -					SDLcdrom = NULL;
   8.215 -				}
   8.216 -			} while ( SDLcdrom );
   8.217 -			free(cdpath);
   8.218 -		}
   8.219 -
   8.220 -		/* If we found our drives, there's nothing left to do */
   8.221 -		if ( SDL_numcds > 0 ) {
   8.222 -			return(0);
   8.223 -		}
   8.224 -	}
   8.225 -
   8.226 -	/* Scan the system for CD-ROM drives */
   8.227 -	raw_fd = open("/dev/disk/ide/rescan", 0);
   8.228 -	if ( raw_fd >= 0 ) {
   8.229 -		if (ioctl(raw_fd, IDE_GET_DEVICES_INFO, &info) == B_NO_ERROR) {
   8.230 -			if ( info.ide_0_master_type == B_CD ) {
   8.231 -				AddDrive("/dev/disk/ide/0/master/raw");
   8.232 -			}
   8.233 -			if ( info.ide_0_slave_type == B_CD ) {
   8.234 -				AddDrive("/dev/disk/ide/0/slave/raw");
   8.235 -			}
   8.236 -			if ( info.ide_1_master_type == B_CD ) {
   8.237 -				AddDrive("/dev/disk/ide/1/master/raw");
   8.238 -			}
   8.239 -			if ( info.ide_1_slave_type == B_CD ) {
   8.240 -				AddDrive("/dev/disk/ide/1/slave/raw");
   8.241 -			}
   8.242 -		}
   8.243 -		close(raw_fd);
   8.244 -	}
   8.245 -	return(0);
   8.246 -}
   8.247 -
   8.248 -/* General ioctl() CD-ROM command function */
   8.249 -static int SDL_SYS_CDioctl(int index, int command, void *arg)
   8.250 -{
   8.251 -	int okay;
   8.252 -	int fd;
   8.253 -
   8.254 -	okay = 0;
   8.255 -	fd = open(SDL_cdlist[index], 0);
   8.256 -	if ( fd >= 0 ) {
   8.257 -		if ( ioctl(fd, command, arg) == B_NO_ERROR ) {
   8.258 -			okay = 1;
   8.259 -		}
   8.260 -		close(fd);
   8.261 -	}
   8.262 -	return(okay ? 0 : -1);
   8.263 -}
   8.264 -
   8.265 -static const char *SDL_SYS_CDName(int drive)
   8.266 -{
   8.267 -	return(SDL_cdlist[drive]);
   8.268 -} 
   8.269 -
   8.270 -static int SDL_SYS_CDOpen(int drive)
   8.271 -{
   8.272 -	return(drive);
   8.273 -}
   8.274 -
   8.275 -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom)
   8.276 -{
   8.277 -	int i;
   8.278 -	scsi_toc toc;
   8.279 -
   8.280 -	if ( SDL_SYS_CDioctl(cdrom->id, B_SCSI_GET_TOC, &toc) == 0 ) {
   8.281 -		cdrom->numtracks = CD_NUMTRACKS(toc);
   8.282 -		if ( cdrom->numtracks > SDL_MAX_TRACKS ) {
   8.283 -			cdrom->numtracks = SDL_MAX_TRACKS;
   8.284 -		}
   8.285 -		for ( i=0; i<=cdrom->numtracks; ++i ) {
   8.286 -			cdrom->track[i].id = CD_TRACK_N(toc, i);
   8.287 -			/* FIXME:  How do we tell on BeOS? */
   8.288 -			cdrom->track[i].type = SDL_AUDIO_TRACK;
   8.289 -			cdrom->track[i].offset = MSF_TO_FRAMES(
   8.290 -							CD_TRACK_M(toc, i),
   8.291 -							CD_TRACK_S(toc, i),
   8.292 -							CD_TRACK_F(toc, i));
   8.293 -			cdrom->track[i].length = 0;
   8.294 -			if ( i > 0 ) {
   8.295 -				cdrom->track[i-1].length =
   8.296 -						cdrom->track[i].offset-
   8.297 -						cdrom->track[i-1].offset;
   8.298 -			}
   8.299 -		}
   8.300 -		return(0);
   8.301 -	} else {
   8.302 -		return(-1);
   8.303 -	}
   8.304 -}
   8.305 -
   8.306 -/* Get CD-ROM status */
   8.307 -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position)
   8.308 -{
   8.309 -	CDstatus status;
   8.310 -	int fd;
   8.311 -	int cur_frame;
   8.312 -	scsi_position pos;
   8.313 -
   8.314 -	fd = open(SDL_cdlist[cdrom->id], 0);
   8.315 -	cur_frame = 0;
   8.316 -	if ( fd >= 0 ) {
   8.317 -		if ( ioctl(fd, B_SCSI_GET_POSITION, &pos) == B_NO_ERROR ) {
   8.318 -			cur_frame = MSF_TO_FRAMES(
   8.319 -				POS_ABS_M(pos), POS_ABS_S(pos), POS_ABS_F(pos));
   8.320 -		}
   8.321 -		if ( ! pos.position[1] || (pos.position[1] >= 0x13) ||
   8.322 -			((pos.position[1] == 0x12) && (!pos.position[6])) ) {
   8.323 -			status = CD_STOPPED;
   8.324 -		} else
   8.325 -		if ( pos.position[1] == 0x11 ) {
   8.326 -			status = CD_PLAYING;
   8.327 -		} else {
   8.328 -			status = CD_PAUSED;
   8.329 -		}
   8.330 -		close(fd);
   8.331 -	} else {
   8.332 -		status = CD_TRAYEMPTY;
   8.333 -	}
   8.334 -	if ( position ) {
   8.335 -		*position = cur_frame;
   8.336 -	}
   8.337 -	return(status);
   8.338 -}
   8.339 -
   8.340 -/* Start play */
   8.341 -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length)
   8.342 -{
   8.343 -	int okay;
   8.344 -	int fd;
   8.345 -	scsi_play_position pos;
   8.346 -
   8.347 -	okay = 0;
   8.348 -	fd = open(SDL_cdlist[cdrom->id], 0);
   8.349 -	if ( fd >= 0 ) {
   8.350 -		FRAMES_TO_MSF(start, &pos.start_m, &pos.start_s, &pos.start_f);
   8.351 -		FRAMES_TO_MSF(start+length, &pos.end_m, &pos.end_s, &pos.end_f);
   8.352 -		if ( ioctl(fd, B_SCSI_PLAY_POSITION, &pos) == B_NO_ERROR ) {
   8.353 -			okay = 1;
   8.354 -		}
   8.355 -		close(fd);
   8.356 -	}
   8.357 -	return(okay ? 0 : -1);
   8.358 -}
   8.359 -
   8.360 -/* Pause play */
   8.361 -static int SDL_SYS_CDPause(SDL_CD *cdrom)
   8.362 -{
   8.363 -	return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_PAUSE_AUDIO, 0));
   8.364 -}
   8.365 -
   8.366 -/* Resume play */
   8.367 -static int SDL_SYS_CDResume(SDL_CD *cdrom)
   8.368 -{
   8.369 -	return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_RESUME_AUDIO, 0));
   8.370 -}
   8.371 -
   8.372 -/* Stop play */
   8.373 -static int SDL_SYS_CDStop(SDL_CD *cdrom)
   8.374 -{
   8.375 -	return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_STOP_AUDIO, 0));
   8.376 -}
   8.377 -
   8.378 -/* Eject the CD-ROM */
   8.379 -static int SDL_SYS_CDEject(SDL_CD *cdrom)
   8.380 -{
   8.381 -	return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_EJECT, 0));
   8.382 -}
   8.383 -
   8.384 -/* Close the CD-ROM handle */
   8.385 -static void SDL_SYS_CDClose(SDL_CD *cdrom)
   8.386 -{
   8.387 -	free(cdrom);
   8.388 -}
   8.389 -
   8.390 -void SDL_SYS_CDQuit(void)
   8.391 -{
   8.392 -	int i;
   8.393 -
   8.394 -	if ( SDL_numcds > 0 ) {
   8.395 -		for ( i=0; i<SDL_numcds; ++i ) {
   8.396 -			free(SDL_cdlist[i]);
   8.397 -		}
   8.398 -		SDL_numcds = 0;
   8.399 -	}
   8.400 -}
   8.401 -
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/cdrom/beos/SDL_syscdrom.cc	Sat Aug 18 22:03:11 2001 +0000
     9.3 @@ -0,0 +1,414 @@
     9.4 +/*
     9.5 +    SDL - Simple DirectMedia Layer
     9.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     9.7 +
     9.8 +    This library is free software; you can redistribute it and/or
     9.9 +    modify it under the terms of the GNU Library General Public
    9.10 +    License as published by the Free Software Foundation; either
    9.11 +    version 2 of the License, or (at your option) any later version.
    9.12 +
    9.13 +    This library is distributed in the hope that it will be useful,
    9.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    9.16 +    Library General Public License for more details.
    9.17 +
    9.18 +    You should have received a copy of the GNU Library General Public
    9.19 +    License along with this library; if not, write to the Free
    9.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    9.21 +
    9.22 +    Sam Lantinga
    9.23 +    slouken@devolution.com
    9.24 +*/
    9.25 +
    9.26 +#ifdef SAVE_RCSID
    9.27 +static char rcsid =
    9.28 + "@(#) $Id$";
    9.29 +#endif
    9.30 +
    9.31 +/* Functions for system-level CD-ROM audio control on BeOS
    9.32 +   (not completely implemented yet)
    9.33 + */
    9.34 +
    9.35 +#include <sys/types.h>
    9.36 +#include <stdlib.h>
    9.37 +#include <sys/stat.h>
    9.38 +#include <stdio.h>
    9.39 +#include <string.h>
    9.40 +#include <unistd.h>
    9.41 +
    9.42 +#include <scsi.h>
    9.43 +#include <Directory.h>
    9.44 +#include <Entry.h>
    9.45 +#include <Path.h>
    9.46 +
    9.47 +#include "SDL_error.h"
    9.48 +#include "SDL_cdrom.h"
    9.49 +extern "C" {
    9.50 +#include "SDL_syscdrom.h"
    9.51 +}
    9.52 +
    9.53 +/* Constants to help us get at the SCSI table-of-contents info */
    9.54 +#define CD_NUMTRACKS(toc)	toc.toc_data[3]
    9.55 +#define CD_TRACK(toc, track)	(&toc.toc_data[6+(track)*8])
    9.56 +#define CD_TRACK_N(toc, track)	CD_TRACK(toc, track)[0]
    9.57 +#define CD_TRACK_M(toc, track)	CD_TRACK(toc, track)[3]
    9.58 +#define CD_TRACK_S(toc, track)	CD_TRACK(toc, track)[4]
    9.59 +#define CD_TRACK_F(toc, track)	CD_TRACK(toc, track)[5]
    9.60 +
    9.61 +/* Constants to help us get at the SCSI position info */
    9.62 +#define POS_TRACK(pos)	pos.position[6]
    9.63 +#define POS_ABS_M(pos)	pos.position[9]
    9.64 +#define POS_ABS_S(pos)	pos.position[10]
    9.65 +#define POS_ABS_F(pos)	pos.position[11]
    9.66 +#define POS_REL_M(pos)	pos.position[13]
    9.67 +#define POS_REL_S(pos)	pos.position[14]
    9.68 +#define POS_REL_F(pos)	pos.position[15]
    9.69 +
    9.70 +/* The maximum number of CD-ROM drives we'll detect */
    9.71 +#define MAX_DRIVES	16	
    9.72 +
    9.73 +/* A list of available CD-ROM drives */
    9.74 +static char *SDL_cdlist[MAX_DRIVES];
    9.75 +
    9.76 +/* The system-dependent CD control functions */
    9.77 +static const char *SDL_SYS_CDName(int drive);
    9.78 +static int SDL_SYS_CDOpen(int drive);
    9.79 +static int SDL_SYS_CDGetTOC(SDL_CD *cdrom);
    9.80 +static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position);
    9.81 +static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length);
    9.82 +static int SDL_SYS_CDPause(SDL_CD *cdrom);
    9.83 +static int SDL_SYS_CDResume(SDL_CD *cdrom);
    9.84 +static int SDL_SYS_CDStop(SDL_CD *cdrom);
    9.85 +static int SDL_SYS_CDEject(SDL_CD *cdrom);
    9.86 +static void SDL_SYS_CDClose(SDL_CD *cdrom);
    9.87 +int try_dir(const char *directory);
    9.88 +
    9.89 +
    9.90 +/* Check a drive to see if it is a CD-ROM */
    9.91 +static int CheckDrive(char *drive)
    9.92 +{
    9.93 +	struct stat stbuf;
    9.94 +	int is_cd, cdfd;
    9.95 +	device_geometry info;
    9.96 +
    9.97 +	/* If it doesn't exist, return -1 */
    9.98 +	if ( stat(drive, &stbuf) < 0 ) {
    9.99 +		return(-1);
   9.100 +	}
   9.101 +
   9.102 +	/* If it does exist, verify that it's an available CD-ROM */
   9.103 +	is_cd = 0;
   9.104 +	cdfd = open(drive, 0);
   9.105 +	if ( cdfd >= 0 ) {
   9.106 +		if ( ioctl(cdfd, B_GET_GEOMETRY, &info) == B_NO_ERROR ) {
   9.107 +			if ( info.device_type == B_CD ) {
   9.108 +				is_cd = 1;
   9.109 +			}
   9.110 +		}
   9.111 +		close(cdfd);
   9.112 +	} else {
   9.113 +		/* This can happen when the drive is open .. (?) */;
   9.114 +		is_cd = 1;
   9.115 +	}
   9.116 +	return(is_cd);
   9.117 +}
   9.118 +
   9.119 +/* Add a CD-ROM drive to our list of valid drives */
   9.120 +static void AddDrive(char *drive)
   9.121 +{
   9.122 +	int i;
   9.123 +
   9.124 +	if ( SDL_numcds < MAX_DRIVES ) {
   9.125 +		/* Add this drive to our list */
   9.126 +		i = SDL_numcds;
   9.127 +		SDL_cdlist[i] = (char *)malloc(strlen(drive)+1);
   9.128 +		if ( SDL_cdlist[i] == NULL ) {
   9.129 +			SDL_OutOfMemory();
   9.130 +			return;
   9.131 +		}
   9.132 +		strcpy(SDL_cdlist[i], drive);
   9.133 +		++SDL_numcds;
   9.134 +#ifdef CDROM_DEBUG
   9.135 +  fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
   9.136 +#endif
   9.137 +	}
   9.138 +}
   9.139 +
   9.140 +/* IDE bus scanning magic */
   9.141 +enum {
   9.142 +	IDE_GET_DEVICES_INFO = B_DEVICE_OP_CODES_END + 50,
   9.143 +};
   9.144 +struct ide_ctrl_info {
   9.145 +	bool	ide_0_present;
   9.146 +	bool	ide_0_master_present;
   9.147 +	bool	ide_0_slave_present;
   9.148 +	int	ide_0_master_type;
   9.149 +	int	ide_0_slave_type;
   9.150 +	bool	ide_1_present;
   9.151 +	bool	ide_1_master_present;
   9.152 +	bool	ide_1_slave_present;
   9.153 +	int	ide_1_master_type;
   9.154 +	int	ide_1_slave_type;
   9.155 +};
   9.156 +
   9.157 +int  SDL_SYS_CDInit(void)
   9.158 +{
   9.159 +	char *SDLcdrom;
   9.160 +	int raw_fd;
   9.161 +	struct ide_ctrl_info info;
   9.162 +
   9.163 +	/* Fill in our driver capabilities */
   9.164 +	SDL_CDcaps.Name = SDL_SYS_CDName;
   9.165 +	SDL_CDcaps.Open = SDL_SYS_CDOpen;
   9.166 +	SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
   9.167 +	SDL_CDcaps.Status = SDL_SYS_CDStatus;
   9.168 +	SDL_CDcaps.Play = SDL_SYS_CDPlay;
   9.169 +	SDL_CDcaps.Pause = SDL_SYS_CDPause;
   9.170 +	SDL_CDcaps.Resume = SDL_SYS_CDResume;
   9.171 +	SDL_CDcaps.Stop = SDL_SYS_CDStop;
   9.172 +	SDL_CDcaps.Eject = SDL_SYS_CDEject;
   9.173 +	SDL_CDcaps.Close = SDL_SYS_CDClose;
   9.174 +
   9.175 +	/* Look in the environment for our CD-ROM drive list */
   9.176 +	SDLcdrom = getenv("SDL_CDROM");	/* ':' separated list of devices */
   9.177 +	if ( SDLcdrom != NULL ) {
   9.178 +		char *cdpath, *delim;
   9.179 +		cdpath = (char *)malloc(strlen(SDLcdrom)+1);
   9.180 +		if ( cdpath != NULL ) {
   9.181 +			strcpy(cdpath, SDLcdrom);
   9.182 +			SDLcdrom = cdpath;
   9.183 +			do {
   9.184 +				delim = strchr(SDLcdrom, ':');
   9.185 +				if ( delim ) {
   9.186 +					*delim++ = '\0';
   9.187 +				}
   9.188 +				if ( CheckDrive(SDLcdrom) > 0 ) {
   9.189 +					AddDrive(SDLcdrom);
   9.190 +				}
   9.191 +				if ( delim ) {
   9.192 +					SDLcdrom = delim;
   9.193 +				} else {
   9.194 +					SDLcdrom = NULL;
   9.195 +				}
   9.196 +			} while ( SDLcdrom );
   9.197 +			free(cdpath);
   9.198 +		}
   9.199 +
   9.200 +		/* If we found our drives, there's nothing left to do */
   9.201 +		if ( SDL_numcds > 0 ) {
   9.202 +			return(0);
   9.203 +		}
   9.204 +	}
   9.205 +	
   9.206 +	/* Scan the system for CD-ROM drives */
   9.207 +	try_dir("/dev/disk");
   9.208 +	return 0;
   9.209 +}
   9.210 +
   9.211 +
   9.212 +int try_dir(const char *directory)
   9.213 +{ 
   9.214 +	BDirectory dir; 
   9.215 +	dir.SetTo(directory); 
   9.216 +	if(dir.InitCheck() != B_NO_ERROR) { 
   9.217 +		return false; 
   9.218 +	} 
   9.219 +	dir.Rewind(); 
   9.220 +	BEntry entry; 
   9.221 +	while(dir.GetNextEntry(&entry) >= 0) { 
   9.222 +		BPath path; 
   9.223 +		const char *name; 
   9.224 +		entry_ref e; 
   9.225 +		
   9.226 +		if(entry.GetPath(&path) != B_NO_ERROR) 
   9.227 +			continue; 
   9.228 +		name = path.Path(); 
   9.229 +		
   9.230 +		if(entry.GetRef(&e) != B_NO_ERROR) 
   9.231 +			continue; 
   9.232 +
   9.233 +		if(entry.IsDirectory()) { 
   9.234 +			if(strcmp(e.name, "floppy") == 0) 
   9.235 +				continue; /* ignore floppy (it is not silent)  */
   9.236 +			int devfd = try_dir(name);
   9.237 +			if(devfd >= 0)
   9.238 +				return devfd;
   9.239 +		} 
   9.240 +		else { 
   9.241 +			int devfd; 
   9.242 +			device_geometry g; 
   9.243 +
   9.244 +			if(strcmp(e.name, "raw") != 0) 
   9.245 +				continue; /* ignore partitions */
   9.246 +
   9.247 +			devfd = open(name, O_RDONLY); 
   9.248 +			if(devfd < 0) 
   9.249 +				continue; 
   9.250 +
   9.251 +			if(ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g)) >= 0) {
   9.252 +				if(g.device_type == B_CD)
   9.253 +				{
   9.254 +				AddDrive(strdup(name));
   9.255 +				}
   9.256 +			}
   9.257 +			close(devfd);
   9.258 +		} 
   9.259 +	}
   9.260 +	return B_ERROR;
   9.261 +}
   9.262 +
   9.263 +
   9.264 +/* General ioctl() CD-ROM command function */
   9.265 +static int SDL_SYS_CDioctl(int index, int command, void *arg)
   9.266 +{
   9.267 +	int okay;
   9.268 +	int fd;
   9.269 +
   9.270 +	okay = 0;
   9.271 +	fd = open(SDL_cdlist[index], 0);
   9.272 +	if ( fd >= 0 ) {
   9.273 +		if ( ioctl(fd, command, arg) == B_NO_ERROR ) {
   9.274 +			okay = 1;
   9.275 +		}
   9.276 +		close(fd);
   9.277 +	}
   9.278 +	return(okay ? 0 : -1);
   9.279 +}
   9.280 +
   9.281 +static const char *SDL_SYS_CDName(int drive)
   9.282 +{
   9.283 +	return(SDL_cdlist[drive]);
   9.284 +} 
   9.285 +
   9.286 +static int SDL_SYS_CDOpen(int drive)
   9.287 +{
   9.288 +	return(drive);
   9.289 +}
   9.290 +
   9.291 +static int SDL_SYS_CDGetTOC(SDL_CD *cdrom)
   9.292 +{
   9.293 +	int i;
   9.294 +	scsi_toc toc;
   9.295 +
   9.296 +	if ( SDL_SYS_CDioctl(cdrom->id, B_SCSI_GET_TOC, &toc) == 0 ) {
   9.297 +		cdrom->numtracks = CD_NUMTRACKS(toc);
   9.298 +		if ( cdrom->numtracks > SDL_MAX_TRACKS ) {
   9.299 +			cdrom->numtracks = SDL_MAX_TRACKS;
   9.300 +		}
   9.301 +		for ( i=0; i<=cdrom->numtracks; ++i ) {
   9.302 +			cdrom->track[i].id = CD_TRACK_N(toc, i);
   9.303 +			/* FIXME:  How do we tell on BeOS? */
   9.304 +			cdrom->track[i].type = SDL_AUDIO_TRACK;
   9.305 +			cdrom->track[i].offset = MSF_TO_FRAMES(
   9.306 +							CD_TRACK_M(toc, i),
   9.307 +							CD_TRACK_S(toc, i),
   9.308 +							CD_TRACK_F(toc, i));
   9.309 +			cdrom->track[i].length = 0;
   9.310 +			if ( i > 0 ) {
   9.311 +				cdrom->track[i-1].length =
   9.312 +						cdrom->track[i].offset-
   9.313 +						cdrom->track[i-1].offset;
   9.314 +			}
   9.315 +		}
   9.316 +		return(0);
   9.317 +	} else {
   9.318 +		return(-1);
   9.319 +	}
   9.320 +}
   9.321 +
   9.322 +/* Get CD-ROM status */
   9.323 +static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position)
   9.324 +{
   9.325 +	CDstatus status;
   9.326 +	int fd;
   9.327 +	int cur_frame;
   9.328 +	scsi_position pos;
   9.329 +
   9.330 +	fd = open(SDL_cdlist[cdrom->id], 0);
   9.331 +	cur_frame = 0;
   9.332 +	if ( fd >= 0 ) {
   9.333 +		if ( ioctl(fd, B_SCSI_GET_POSITION, &pos) == B_NO_ERROR ) {
   9.334 +			cur_frame = MSF_TO_FRAMES(
   9.335 +				POS_ABS_M(pos), POS_ABS_S(pos), POS_ABS_F(pos));
   9.336 +		}
   9.337 +		if ( ! pos.position[1] || (pos.position[1] >= 0x13) ||
   9.338 +			((pos.position[1] == 0x12) && (!pos.position[6])) ) {
   9.339 +			status = CD_STOPPED;
   9.340 +		} else
   9.341 +		if ( pos.position[1] == 0x11 ) {
   9.342 +			status = CD_PLAYING;
   9.343 +		} else {
   9.344 +			status = CD_PAUSED;
   9.345 +		}
   9.346 +		close(fd);
   9.347 +	} else {
   9.348 +		status = CD_TRAYEMPTY;
   9.349 +	}
   9.350 +	if ( position ) {
   9.351 +		*position = cur_frame;
   9.352 +	}
   9.353 +	return(status);
   9.354 +}
   9.355 +
   9.356 +/* Start play */
   9.357 +static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length)
   9.358 +{
   9.359 +	int okay;
   9.360 +	int fd;
   9.361 +	scsi_play_position pos;
   9.362 +
   9.363 +	okay = 0;
   9.364 +	fd = open(SDL_cdlist[cdrom->id], 0);
   9.365 +	if ( fd >= 0 ) {
   9.366 +		FRAMES_TO_MSF(start, &pos.start_m, &pos.start_s, &pos.start_f);
   9.367 +		FRAMES_TO_MSF(start+length, &pos.end_m, &pos.end_s, &pos.end_f);
   9.368 +		if ( ioctl(fd, B_SCSI_PLAY_POSITION, &pos) == B_NO_ERROR ) {
   9.369 +			okay = 1;
   9.370 +		}
   9.371 +		close(fd);
   9.372 +	}
   9.373 +	return(okay ? 0 : -1);
   9.374 +}
   9.375 +
   9.376 +/* Pause play */
   9.377 +static int SDL_SYS_CDPause(SDL_CD *cdrom)
   9.378 +{
   9.379 +	return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_PAUSE_AUDIO, 0));
   9.380 +}
   9.381 +
   9.382 +/* Resume play */
   9.383 +static int SDL_SYS_CDResume(SDL_CD *cdrom)
   9.384 +{
   9.385 +	return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_RESUME_AUDIO, 0));
   9.386 +}
   9.387 +
   9.388 +/* Stop play */
   9.389 +static int SDL_SYS_CDStop(SDL_CD *cdrom)
   9.390 +{
   9.391 +	return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_STOP_AUDIO, 0));
   9.392 +}
   9.393 +
   9.394 +/* Eject the CD-ROM */
   9.395 +static int SDL_SYS_CDEject(SDL_CD *cdrom)
   9.396 +{
   9.397 +	return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_EJECT, 0));
   9.398 +}
   9.399 +
   9.400 +/* Close the CD-ROM handle */
   9.401 +static void SDL_SYS_CDClose(SDL_CD *cdrom)
   9.402 +{
   9.403 +	close(cdrom->id);
   9.404 +}
   9.405 +
   9.406 +void SDL_SYS_CDQuit(void)
   9.407 +{
   9.408 +	int i;
   9.409 +
   9.410 +	if ( SDL_numcds > 0 ) {
   9.411 +		for ( i=0; i<SDL_numcds; ++i ) {
   9.412 +			free(SDL_cdlist[i]);
   9.413 +		}
   9.414 +		SDL_numcds = 0;
   9.415 +	}
   9.416 +}
   9.417 +
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/cdrom/dummy/.cvsignore	Sat Aug 18 22:03:11 2001 +0000
    10.3 @@ -0,0 +1,6 @@
    10.4 +Makefile.in
    10.5 +Makefile
    10.6 +.libs
    10.7 +*.o
    10.8 +*.lo
    10.9 +*.la
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/cdrom/dummy/Makefile.am	Sat Aug 18 22:03:11 2001 +0000
    11.3 @@ -0,0 +1,8 @@
    11.4 +
    11.5 +## Makefile.am for the dummy cdrom driver for SDL
    11.6 +
    11.7 +noinst_LTLIBRARIES = libcdrom_dummy.la
    11.8 +libcdrom_dummy_la_SOURCES = $(SRCS)
    11.9 +
   11.10 +# The SDL cdrom driver sources
   11.11 +SRCS =  SDL_syscdrom.c
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/cdrom/freebsd/.cvsignore	Sat Aug 18 22:03:11 2001 +0000
    12.3 @@ -0,0 +1,6 @@
    12.4 +Makefile.in
    12.5 +Makefile
    12.6 +.libs
    12.7 +*.o
    12.8 +*.lo
    12.9 +*.la
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/cdrom/freebsd/Makefile.am	Sat Aug 18 22:03:11 2001 +0000
    13.3 @@ -0,0 +1,8 @@
    13.4 +
    13.5 +## Makefile.am for the FreeBSD cdrom driver for SDL
    13.6 +
    13.7 +noinst_LTLIBRARIES = libcdrom_freebsd.la
    13.8 +libcdrom_freebsd_la_SOURCES = $(SRCS)
    13.9 +
   13.10 +# The SDL cdrom driver sources
   13.11 +SRCS =  SDL_syscdrom.c
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/cdrom/linux/.cvsignore	Sat Aug 18 22:03:11 2001 +0000
    14.3 @@ -0,0 +1,6 @@
    14.4 +Makefile.in
    14.5 +Makefile
    14.6 +.libs
    14.7 +*.o
    14.8 +*.lo
    14.9 +*.la
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/cdrom/linux/Makefile.am	Sat Aug 18 22:03:11 2001 +0000
    15.3 @@ -0,0 +1,8 @@
    15.4 +
    15.5 +## Makefile.am for the Linux cdrom driver for SDL
    15.6 +
    15.7 +noinst_LTLIBRARIES = libcdrom_linux.la
    15.8 +libcdrom_linux_la_SOURCES = $(SRCS)
    15.9 +
   15.10 +# The SDL cdrom driver sources
   15.11 +SRCS =  SDL_syscdrom.c
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/cdrom/macos/.cvsignore	Sat Aug 18 22:03:11 2001 +0000
    16.3 @@ -0,0 +1,6 @@
    16.4 +Makefile.in
    16.5 +Makefile
    16.6 +.libs
    16.7 +*.o
    16.8 +*.lo
    16.9 +*.la
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/src/cdrom/macos/Makefile.am	Sat Aug 18 22:03:11 2001 +0000
    17.3 @@ -0,0 +1,8 @@
    17.4 +
    17.5 +## Makefile.am for the MacOS Classic cdrom driver for SDL
    17.6 +
    17.7 +noinst_LTLIBRARIES = libcdrom_macos.la
    17.8 +libcdrom_macos_la_SOURCES = $(SRCS)
    17.9 +
   17.10 +# The SDL cdrom driver sources
   17.11 +SRCS = SDL_syscdrom.c SDL_syscdrom_c.h
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/src/cdrom/openbsd/.cvsignore	Sat Aug 18 22:03:11 2001 +0000
    18.3 @@ -0,0 +1,6 @@
    18.4 +Makefile.in
    18.5 +Makefile
    18.6 +.libs
    18.7 +*.o
    18.8 +*.lo
    18.9 +*.la
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/src/cdrom/openbsd/Makefile.am	Sat Aug 18 22:03:11 2001 +0000
    19.3 @@ -0,0 +1,8 @@
    19.4 +
    19.5 +## Makefile.am for the OpenBSD cdrom driver for SDL
    19.6 +
    19.7 +noinst_LTLIBRARIES = libcdrom_openbsd.la
    19.8 +libcdrom_openbsd_la_SOURCES = $(SRCS)
    19.9 +
   19.10 +# The SDL cdrom driver sources
   19.11 +SRCS =  SDL_syscdrom.c
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/src/cdrom/qnx/.cvsignore	Sat Aug 18 22:03:11 2001 +0000
    20.3 @@ -0,0 +1,6 @@
    20.4 +Makefile.in
    20.5 +Makefile
    20.6 +.libs
    20.7 +*.o
    20.8 +*.lo
    20.9 +*.la
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/src/cdrom/qnx/Makefile.am	Sat Aug 18 22:03:11 2001 +0000
    21.3 @@ -0,0 +1,8 @@
    21.4 +
    21.5 +## Makefile.am for the QNX cdrom driver for SDL
    21.6 +
    21.7 +noinst_LTLIBRARIES = libcdrom_qnx.la
    21.8 +libcdrom_qnx_la_SOURCES = $(SRCS)
    21.9 +
   21.10 +# The SDL cdrom driver sources
   21.11 +SRCS =  SDL_syscdrom.c
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/src/cdrom/win32/.cvsignore	Sat Aug 18 22:03:11 2001 +0000
    22.3 @@ -0,0 +1,6 @@
    22.4 +Makefile.in
    22.5 +Makefile
    22.6 +.libs
    22.7 +*.o
    22.8 +*.lo
    22.9 +*.la
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/src/cdrom/win32/Makefile.am	Sat Aug 18 22:03:11 2001 +0000
    23.3 @@ -0,0 +1,8 @@
    23.4 +
    23.5 +## Makefile.am for the Windows cdrom driver for SDL
    23.6 +
    23.7 +noinst_LTLIBRARIES = libcdrom_win32.la
    23.8 +libcdrom_win32_la_SOURCES = $(SRCS)
    23.9 +
   23.10 +# The SDL cdrom driver sources
   23.11 +SRCS =  SDL_syscdrom.c