annotate src/cdrom/beos/SDL_syscdrom.cc @ 302:8a86bdf34f0f

Added Atari joystick support (thanks Patrice!)
author Sam Lantinga <slouken@libsdl.org>
date Thu, 07 Mar 2002 20:23:11 +0000
parents f6ffac90895c
children b8d311d90021
rev   line source
153
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
297
f6ffac90895c Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
153
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Library General Public License for more details.
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 153
diff changeset
20 slouken@libsdl.org
153
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 #ifdef SAVE_RCSID
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 static char rcsid =
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 "@(#) $Id$";
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #endif
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 /* Functions for system-level CD-ROM audio control on BeOS
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 (not completely implemented yet)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #include <sys/types.h>
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 #include <stdlib.h>
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #include <sys/stat.h>
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 #include <stdio.h>
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #include <string.h>
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 #include <unistd.h>
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 #include <scsi.h>
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 #include <Directory.h>
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 #include <Entry.h>
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 #include <Path.h>
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 #include "SDL_error.h"
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 #include "SDL_cdrom.h"
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 extern "C" {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 #include "SDL_syscdrom.h"
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 /* Constants to help us get at the SCSI table-of-contents info */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 #define CD_NUMTRACKS(toc) toc.toc_data[3]
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 #define CD_TRACK(toc, track) (&toc.toc_data[6+(track)*8])
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 #define CD_TRACK_N(toc, track) CD_TRACK(toc, track)[0]
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 #define CD_TRACK_M(toc, track) CD_TRACK(toc, track)[3]
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 #define CD_TRACK_S(toc, track) CD_TRACK(toc, track)[4]
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 #define CD_TRACK_F(toc, track) CD_TRACK(toc, track)[5]
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 /* Constants to help us get at the SCSI position info */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 #define POS_TRACK(pos) pos.position[6]
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 #define POS_ABS_M(pos) pos.position[9]
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 #define POS_ABS_S(pos) pos.position[10]
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 #define POS_ABS_F(pos) pos.position[11]
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 #define POS_REL_M(pos) pos.position[13]
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 #define POS_REL_S(pos) pos.position[14]
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 #define POS_REL_F(pos) pos.position[15]
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 /* The maximum number of CD-ROM drives we'll detect */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 #define MAX_DRIVES 16
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 /* A list of available CD-ROM drives */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 static char *SDL_cdlist[MAX_DRIVES];
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 /* The system-dependent CD control functions */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 static const char *SDL_SYS_CDName(int drive);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 static int SDL_SYS_CDOpen(int drive);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 static int SDL_SYS_CDPause(SDL_CD *cdrom);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 static int SDL_SYS_CDResume(SDL_CD *cdrom);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 static int SDL_SYS_CDStop(SDL_CD *cdrom);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 static int SDL_SYS_CDEject(SDL_CD *cdrom);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 static void SDL_SYS_CDClose(SDL_CD *cdrom);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 int try_dir(const char *directory);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 /* Check a drive to see if it is a CD-ROM */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 static int CheckDrive(char *drive)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 struct stat stbuf;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 int is_cd, cdfd;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 device_geometry info;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 /* If it doesn't exist, return -1 */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 if ( stat(drive, &stbuf) < 0 ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 return(-1);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 /* If it does exist, verify that it's an available CD-ROM */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 is_cd = 0;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 cdfd = open(drive, 0);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 if ( cdfd >= 0 ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 if ( ioctl(cdfd, B_GET_GEOMETRY, &info) == B_NO_ERROR ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 if ( info.device_type == B_CD ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 is_cd = 1;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 close(cdfd);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 } else {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 /* This can happen when the drive is open .. (?) */;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 is_cd = 1;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 return(is_cd);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 /* Add a CD-ROM drive to our list of valid drives */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 static void AddDrive(char *drive)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 int i;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 if ( SDL_numcds < MAX_DRIVES ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 /* Add this drive to our list */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 i = SDL_numcds;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 SDL_cdlist[i] = (char *)malloc(strlen(drive)+1);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 if ( SDL_cdlist[i] == NULL ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 SDL_OutOfMemory();
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 return;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 strcpy(SDL_cdlist[i], drive);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 ++SDL_numcds;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 #ifdef CDROM_DEBUG
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 #endif
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 /* IDE bus scanning magic */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 enum {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 IDE_GET_DEVICES_INFO = B_DEVICE_OP_CODES_END + 50,
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 };
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 struct ide_ctrl_info {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 bool ide_0_present;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 bool ide_0_master_present;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 bool ide_0_slave_present;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 int ide_0_master_type;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 int ide_0_slave_type;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 bool ide_1_present;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 bool ide_1_master_present;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 bool ide_1_slave_present;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 int ide_1_master_type;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 int ide_1_slave_type;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 };
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 int SDL_SYS_CDInit(void)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 char *SDLcdrom;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 int raw_fd;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 struct ide_ctrl_info info;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 /* Fill in our driver capabilities */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 SDL_CDcaps.Name = SDL_SYS_CDName;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 SDL_CDcaps.Open = SDL_SYS_CDOpen;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 SDL_CDcaps.Status = SDL_SYS_CDStatus;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 SDL_CDcaps.Play = SDL_SYS_CDPlay;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 SDL_CDcaps.Pause = SDL_SYS_CDPause;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 SDL_CDcaps.Resume = SDL_SYS_CDResume;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 SDL_CDcaps.Stop = SDL_SYS_CDStop;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 SDL_CDcaps.Eject = SDL_SYS_CDEject;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 SDL_CDcaps.Close = SDL_SYS_CDClose;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 /* Look in the environment for our CD-ROM drive list */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 SDLcdrom = getenv("SDL_CDROM"); /* ':' separated list of devices */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 if ( SDLcdrom != NULL ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 char *cdpath, *delim;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 cdpath = (char *)malloc(strlen(SDLcdrom)+1);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 if ( cdpath != NULL ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 strcpy(cdpath, SDLcdrom);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 SDLcdrom = cdpath;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 do {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 delim = strchr(SDLcdrom, ':');
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 if ( delim ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 *delim++ = '\0';
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 if ( CheckDrive(SDLcdrom) > 0 ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 AddDrive(SDLcdrom);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 if ( delim ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 SDLcdrom = delim;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 } else {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 SDLcdrom = NULL;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 } while ( SDLcdrom );
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 free(cdpath);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 /* If we found our drives, there's nothing left to do */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 if ( SDL_numcds > 0 ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 return(0);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 /* Scan the system for CD-ROM drives */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 try_dir("/dev/disk");
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 return 0;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 int try_dir(const char *directory)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 BDirectory dir;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 dir.SetTo(directory);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 if(dir.InitCheck() != B_NO_ERROR) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 return false;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 dir.Rewind();
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 BEntry entry;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 while(dir.GetNextEntry(&entry) >= 0) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 BPath path;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 const char *name;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 entry_ref e;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 if(entry.GetPath(&path) != B_NO_ERROR)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 continue;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 name = path.Path();
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 if(entry.GetRef(&e) != B_NO_ERROR)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 continue;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 if(entry.IsDirectory()) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 if(strcmp(e.name, "floppy") == 0)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 continue; /* ignore floppy (it is not silent) */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 int devfd = try_dir(name);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 if(devfd >= 0)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 return devfd;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 else {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238 int devfd;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 device_geometry g;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 if(strcmp(e.name, "raw") != 0)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 continue; /* ignore partitions */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 devfd = open(name, O_RDONLY);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 if(devfd < 0)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 continue;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 if(ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g)) >= 0) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 if(g.device_type == B_CD)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 AddDrive(strdup(name));
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 close(devfd);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 return B_ERROR;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 /* General ioctl() CD-ROM command function */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 static int SDL_SYS_CDioctl(int index, int command, void *arg)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 int okay;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 int fd;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 okay = 0;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 fd = open(SDL_cdlist[index], 0);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 if ( fd >= 0 ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 if ( ioctl(fd, command, arg) == B_NO_ERROR ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 okay = 1;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 close(fd);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 return(okay ? 0 : -1);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 static const char *SDL_SYS_CDName(int drive)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 return(SDL_cdlist[drive]);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 static int SDL_SYS_CDOpen(int drive)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 return(drive);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290 int i;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291 scsi_toc toc;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
292
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293 if ( SDL_SYS_CDioctl(cdrom->id, B_SCSI_GET_TOC, &toc) == 0 ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294 cdrom->numtracks = CD_NUMTRACKS(toc);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 if ( cdrom->numtracks > SDL_MAX_TRACKS ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 cdrom->numtracks = SDL_MAX_TRACKS;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 for ( i=0; i<=cdrom->numtracks; ++i ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299 cdrom->track[i].id = CD_TRACK_N(toc, i);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300 /* FIXME: How do we tell on BeOS? */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301 cdrom->track[i].type = SDL_AUDIO_TRACK;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
302 cdrom->track[i].offset = MSF_TO_FRAMES(
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 CD_TRACK_M(toc, i),
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304 CD_TRACK_S(toc, i),
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 CD_TRACK_F(toc, i));
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306 cdrom->track[i].length = 0;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 if ( i > 0 ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308 cdrom->track[i-1].length =
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309 cdrom->track[i].offset-
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 cdrom->track[i-1].offset;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 return(0);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314 } else {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 return(-1);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319 /* Get CD-ROM status */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
321 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
322 CDstatus status;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323 int fd;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324 int cur_frame;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
325 scsi_position pos;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
326
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327 fd = open(SDL_cdlist[cdrom->id], 0);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328 cur_frame = 0;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329 if ( fd >= 0 ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
330 if ( ioctl(fd, B_SCSI_GET_POSITION, &pos) == B_NO_ERROR ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331 cur_frame = MSF_TO_FRAMES(
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332 POS_ABS_M(pos), POS_ABS_S(pos), POS_ABS_F(pos));
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 if ( ! pos.position[1] || (pos.position[1] >= 0x13) ||
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
335 ((pos.position[1] == 0x12) && (!pos.position[6])) ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336 status = CD_STOPPED;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337 } else
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 if ( pos.position[1] == 0x11 ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339 status = CD_PLAYING;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 } else {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341 status = CD_PAUSED;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343 close(fd);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 } else {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 status = CD_TRAYEMPTY;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347 if ( position ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 *position = cur_frame;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
350 return(status);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
353 /* Start play */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
355 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
356 int okay;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357 int fd;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358 scsi_play_position pos;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360 okay = 0;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
361 fd = open(SDL_cdlist[cdrom->id], 0);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
362 if ( fd >= 0 ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 FRAMES_TO_MSF(start, &pos.start_m, &pos.start_s, &pos.start_f);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
364 FRAMES_TO_MSF(start+length, &pos.end_m, &pos.end_s, &pos.end_f);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 if ( ioctl(fd, B_SCSI_PLAY_POSITION, &pos) == B_NO_ERROR ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366 okay = 1;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
368 close(fd);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370 return(okay ? 0 : -1);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373 /* Pause play */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374 static int SDL_SYS_CDPause(SDL_CD *cdrom)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376 return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_PAUSE_AUDIO, 0));
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
377 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
378
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 /* Resume play */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380 static int SDL_SYS_CDResume(SDL_CD *cdrom)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382 return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_RESUME_AUDIO, 0));
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385 /* Stop play */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 static int SDL_SYS_CDStop(SDL_CD *cdrom)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388 return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_STOP_AUDIO, 0));
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
390
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391 /* Eject the CD-ROM */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
392 static int SDL_SYS_CDEject(SDL_CD *cdrom)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
393 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
394 return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_EJECT, 0));
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
397 /* Close the CD-ROM handle */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 static void SDL_SYS_CDClose(SDL_CD *cdrom)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 close(cdrom->id);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
402
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
403 void SDL_SYS_CDQuit(void)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
404 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405 int i;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
407 if ( SDL_numcds > 0 ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
408 for ( i=0; i<SDL_numcds; ++i ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409 free(SDL_cdlist[i]);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
410 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
411 SDL_numcds = 0;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
412 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
414