annotate src/cdrom/beos/SDL_syscdrom.cc @ 1336:3692456e7b0f

Use SDL_ prefixed versions of C library functions. FIXME: Change #include <stdlib.h> to #include "SDL_stdlib.h" Change #include <string.h> to #include "SDL_string.h" Make sure nothing else broke because of this...
author Sam Lantinga <slouken@libsdl.org>
date Tue, 07 Feb 2006 06:59:48 +0000
parents c9b51268668f
children 604d73db6802
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
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
3 Copyright (C) 1997-2006 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
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
6 modify it under the terms of the GNU Lesser General Public
153
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
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
153
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
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
13 Lesser General Public License for more details.
153
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
153
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 /* 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
24 (not completely implemented yet)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 #include <sys/types.h>
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 #include <stdlib.h>
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 #include <sys/stat.h>
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #include <stdio.h>
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #include <string.h>
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #include <unistd.h>
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #include <scsi.h>
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 #include <Directory.h>
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #include <Entry.h>
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 #include <Path.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 "SDL_error.h"
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 #include "SDL_cdrom.h"
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 extern "C" {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 #include "SDL_syscdrom.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
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 /* 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
46 #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
47 #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
48 #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
49 #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
50 #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
51 #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
52
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 /* 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
54 #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
55 #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
56 #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
57 #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
58 #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
59 #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
60 #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
61
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 /* 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
63 #define MAX_DRIVES 16
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 /* 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
66 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
67
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 /* 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
69 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
70 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
71 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
72 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
73 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
74 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
75 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
76 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
77 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
78 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
79 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
80
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 /* 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
83 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
84 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 struct stat stbuf;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 int is_cd, cdfd;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 device_geometry info;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 /* 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
90 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
91 return(-1);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 }
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 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
95 is_cd = 0;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 cdfd = open(drive, 0);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 if ( cdfd >= 0 ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 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
99 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
100 is_cd = 1;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 close(cdfd);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 } else {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 /* 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
106 is_cd = 1;
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 return(is_cd);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 /* 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
112 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
113 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 int i;
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 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
117 /* 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
118 i = SDL_numcds;
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
119 SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1);
153
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 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
121 SDL_OutOfMemory();
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 return;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
124 SDL_strcpy(SDL_cdlist[i], drive);
153
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 ++SDL_numcds;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 #ifdef CDROM_DEBUG
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 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
128 #endif
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 /* IDE bus scanning magic */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 enum {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 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
135 };
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 struct ide_ctrl_info {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 bool ide_0_present;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 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
139 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
140 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
141 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
142 bool ide_1_present;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 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
144 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
145 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
146 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
147 };
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 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
150 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 char *SDLcdrom;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 int raw_fd;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 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
154
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 /* 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
156 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
157 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
158 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
159 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
160 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
161 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
162 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
163 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
164 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
165 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
166
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 /* Look in the environment for our CD-ROM drive list */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
168 SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
153
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 if ( SDLcdrom != NULL ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 char *cdpath, *delim;
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
171 cdpath = (char *)SDL_malloc(SDL_strlen(SDLcdrom)+1);
153
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 if ( cdpath != NULL ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
173 SDL_strcpy(cdpath, SDLcdrom);
153
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 SDLcdrom = cdpath;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 do {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
176 delim = SDL_strchr(SDLcdrom, ':');
153
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 if ( delim ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 *delim++ = '\0';
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 if ( CheckDrive(SDLcdrom) > 0 ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 AddDrive(SDLcdrom);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 if ( delim ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 SDLcdrom = delim;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 } else {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 SDLcdrom = NULL;
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 } while ( SDLcdrom );
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
189 SDL_free(cdpath);
153
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 /* 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
193 if ( SDL_numcds > 0 ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 return(0);
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
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 /* 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
199 try_dir("/dev/disk");
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 return 0;
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
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 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
205 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 BDirectory dir;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 dir.SetTo(directory);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 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
209 return false;
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 dir.Rewind();
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 BEntry entry;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 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
214 BPath path;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 const char *name;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 entry_ref e;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 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
219 continue;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 name = path.Path();
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 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
223 continue;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 if(entry.IsDirectory()) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
226 if(SDL_strcmp(e.name, "floppy") == 0)
153
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 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
228 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
229 if(devfd >= 0)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 return devfd;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 else {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 int devfd;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 device_geometry g;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
236 if(SDL_strcmp(e.name, "raw") != 0)
153
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 continue; /* ignore partitions */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 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
240 if(devfd < 0)
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 continue;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 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
244 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
245 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 AddDrive(strdup(name));
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 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 close(devfd);
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 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 return B_ERROR;
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
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 /* 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
257 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
258 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 int okay;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 int fd;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 okay = 0;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 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
264 if ( fd >= 0 ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 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
266 okay = 1;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 close(fd);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 return(okay ? 0 : -1);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 }
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 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
274 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 return(SDL_cdlist[drive]);
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 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
279 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 return(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_CDGetTOC(SDL_CD *cdrom)
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 int i;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286 scsi_toc toc;
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 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
289 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
290 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
291 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
292 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293 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
294 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
295 /* 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
296 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
297 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
298 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
299 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
300 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
301 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
302 if ( i > 0 ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 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
304 cdrom->track[i].offset-
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 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
306 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308 return(0);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309 } else {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 return(-1);
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
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314 /* Get CD-ROM status */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 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
316 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 CDstatus status;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318 int fd;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319 int cur_frame;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 scsi_position pos;
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 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
323 cur_frame = 0;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324 if ( fd >= 0 ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
325 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
326 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
327 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
328 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329 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
330 ((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
331 status = CD_STOPPED;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332 } else
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333 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
334 status = CD_PLAYING;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
335 } else {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336 status = CD_PAUSED;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 close(fd);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339 } else {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 status = CD_TRAYEMPTY;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342 if ( position ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343 *position = cur_frame;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 return(status);
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
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 /* Start play */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 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
350 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 int okay;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352 int fd;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
353 scsi_play_position pos;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
355 okay = 0;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
356 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
357 if ( fd >= 0 ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358 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
359 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
360 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
361 okay = 1;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
362 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 close(fd);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
364 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 return(okay ? 0 : -1);
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366 }
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 /* Pause play */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369 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
370 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 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
372 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374 /* Resume play */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 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
376 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
377 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
378 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380 /* Stop play */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381 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
382 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 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
384 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 /* Eject the CD-ROM */
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387 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
388 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389 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
390 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
392 /* 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
393 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
394 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395 close(cdrom->id);
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
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 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
399 {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 int i;
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 if ( SDL_numcds > 0 ) {
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
403 for ( i=0; i<SDL_numcds; ++i ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
404 SDL_free(SDL_cdlist[i]);
153
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406 SDL_numcds = 0;
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
407 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
408 }
2839f45bdba0 Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409