annotate src/cdrom/macosx/SDL_syscdrom.c @ 2259:1e690901ecd7

Date: Fri, 17 Aug 2007 01:12:31 +0200 From: Couriersud Subject: fix for audio dsp exit crash / various dfb issues improved cursor handling fixes some mouse and event related bugs
author Sam Lantinga <slouken@libsdl.org>
date Fri, 17 Aug 2007 02:54:50 +0000
parents c121d94672cb
children 99210400e8b9
rev   line source
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
12c746afbc27 Oops...
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: 1126
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
12c746afbc27 Oops...
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: 1126
diff changeset
6 modify it under the terms of the GNU Lesser General Public
616
12c746afbc27 Oops...
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: 1126
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12c746afbc27 Oops...
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: 1126
diff changeset
13 Lesser General Public License for more details.
616
12c746afbc27 Oops...
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: 1126
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: 1126
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: 1126
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
22 #include "SDL_config.h"
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
1635
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
24 #ifdef SDL_CDROM_MACOSX
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
25
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #include "SDL_syscdrom_c.h"
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 #pragma mark -- Globals --
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
30 static FSRef **tracks;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
31 static FSVolumeRefNum *volumes;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
32 static CDstatus status;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
33 static int nextTrackFrame;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
34 static int nextTrackFramesRemaining;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
35 static int fakeCD;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
36 static int currentTrack;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
37 static int didReadTOC;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
38 static int cacheTOCNumTracks;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
39 static int currentDrive; /* Only allow 1 drive in use at a time */
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 #pragma mark -- Prototypes --
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
43 static const char *SDL_SYS_CDName(int drive);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
44 static int SDL_SYS_CDOpen(int drive);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
45 static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
46 static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
47 static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
48 static int SDL_SYS_CDPause(SDL_CD * cdrom);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
49 static int SDL_SYS_CDResume(SDL_CD * cdrom);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
50 static int SDL_SYS_CDStop(SDL_CD * cdrom);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
51 static int SDL_SYS_CDEject(SDL_CD * cdrom);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
52 static void SDL_SYS_CDClose(SDL_CD * cdrom);
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 #pragma mark -- Helper Functions --
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 /* Read a list of tracks from the volume */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
57 static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
58 LoadTracks(SDL_CD * cdrom)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 {
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 /* Check if tracks are already loaded */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
61 if (tracks[cdrom->id] != NULL)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
63
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 /* Allocate memory for tracks */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
65 tracks[cdrom->id] =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
66 (FSRef *) SDL_calloc(1, sizeof(**tracks) * cdrom->numtracks);
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 if (tracks[cdrom->id] == NULL) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
68 SDL_OutOfMemory();
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 return -1;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
71
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 /* Load tracks */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
73 if (ListTrackFiles
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
74 (volumes[cdrom->id], tracks[cdrom->id], cdrom->numtracks) < 0)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 return -1;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 return 0;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 }
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 /* Find a file for a given start frame and length */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
81 static FSRef *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
82 GetFileForOffset(SDL_CD * cdrom, int start, int length, int *outStartFrame,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
83 int *outStopFrame)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 {
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 int i;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
86
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 for (i = 0; i < cdrom->numtracks; i++) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
88
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 if (cdrom->track[i].offset <= start &&
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 start < (cdrom->track[i].offset + cdrom->track[i].length))
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 break;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
93
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 if (i == cdrom->numtracks)
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 return NULL;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
96
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 currentTrack = i;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 *outStartFrame = start - cdrom->track[i].offset;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
100
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 if ((*outStartFrame + length) < cdrom->track[i].length) {
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 *outStopFrame = *outStartFrame + length;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 length = 0;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 nextTrackFrame = -1;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 nextTrackFramesRemaining = -1;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
106 } else {
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 *outStopFrame = -1;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 length -= cdrom->track[i].length - *outStartFrame;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
109 nextTrackFrame = cdrom->track[i + 1].offset;
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 nextTrackFramesRemaining = length;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
112
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 return &tracks[cdrom->id][i];
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 }
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 /* Setup another file for playback, or stop playback (called from another thread) */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
117 static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
118 CompletionProc(SDL_CD * cdrom)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
120
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
121 Lock();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
122
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 if (nextTrackFrame > 0 && nextTrackFramesRemaining > 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
124
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 /* Load the next file to play */
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 int startFrame, stopFrame;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 FSRef *file;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
128
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
129 PauseFile();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
130 ReleaseFile();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
131
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
132 file = GetFileForOffset(cdrom, nextTrackFrame,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
133 nextTrackFramesRemaining, &startFrame,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
134 &stopFrame);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
135
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 if (file == NULL) {
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 status = CD_STOPPED;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
138 Unlock();
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 return;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
141
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
142 LoadFile(file, startFrame, stopFrame);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
143
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
144 SetCompletionProc(CompletionProc, cdrom);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
145
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
146 PlayFile();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
147 } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
148
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 /* Release the current file */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
150 PauseFile();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
151 ReleaseFile();
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 status = CD_STOPPED;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
154
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
155 Unlock();
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 }
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 #pragma mark -- Driver Functions --
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 /* Initialize */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
162 int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
163 SDL_SYS_CDInit(void)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 {
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 /* Initialize globals */
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 volumes = NULL;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
167 tracks = NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
168 status = CD_STOPPED;
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 nextTrackFrame = -1;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 nextTrackFramesRemaining = -1;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
171 fakeCD = SDL_FALSE;
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 currentTrack = -1;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 didReadTOC = SDL_FALSE;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 cacheTOCNumTracks = -1;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 currentDrive = -1;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
176
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 /* Fill in function pointers */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
178 SDL_CDcaps.Name = SDL_SYS_CDName;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
179 SDL_CDcaps.Open = SDL_SYS_CDOpen;
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 SDL_CDcaps.Status = SDL_SYS_CDStatus;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
182 SDL_CDcaps.Play = SDL_SYS_CDPlay;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
183 SDL_CDcaps.Pause = SDL_SYS_CDPause;
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 SDL_CDcaps.Resume = SDL_SYS_CDResume;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
185 SDL_CDcaps.Stop = SDL_SYS_CDStop;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
186 SDL_CDcaps.Eject = SDL_SYS_CDEject;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
187 SDL_CDcaps.Close = SDL_SYS_CDClose;
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 /*
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
190 Read the list of "drives"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
191
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
192 This is currently a hack that infers drives from
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
193 mounted audio CD volumes, rather than
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
194 actual CD-ROM devices - which means it may not
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
195 act as expected sometimes.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
196 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
197
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 /* Find out how many cd volumes are mounted */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
199 SDL_numcds = DetectAudioCDVolumes(NULL, 0);
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 /*
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
202 If there are no volumes, fake a cd device
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
203 so tray empty can be reported.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
204 */
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 if (SDL_numcds == 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
206
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 fakeCD = SDL_TRUE;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 SDL_numcds = 1;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 status = CD_TRAYEMPTY;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
210
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 return 0;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
213
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 /* Allocate space for volumes */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
215 volumes = (FSVolumeRefNum *) SDL_calloc(1, sizeof(*volumes) * SDL_numcds);
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 if (volumes == NULL) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
217 SDL_OutOfMemory();
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 return -1;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
220
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 /* Allocate space for tracks */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
222 tracks = (FSRef **) SDL_calloc(1, sizeof(*tracks) * (SDL_numcds + 1));
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 if (tracks == NULL) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
224 SDL_OutOfMemory();
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 return -1;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
227
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 /* Mark the end of the tracks array */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
229 tracks[SDL_numcds] = (FSRef *) - 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
230
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 /*
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
232 Redetect, now save all volumes for later
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
233 Update SDL_numcds just in case it changed
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
234 */
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 {
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 int numVolumes = SDL_numcds;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
237
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
238 SDL_numcds = DetectAudioCDVolumes(volumes, numVolumes);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
239
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 /* If more cds suddenly show up, ignore them */
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 if (SDL_numcds > numVolumes) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
242 SDL_SetError("Some CD's were added but they will be ignored");
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 SDL_numcds = numVolumes;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 }
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
246
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 return 0;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 }
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 /* Shutdown and cleanup */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
251 void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
252 SDL_SYS_CDQuit(void)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 {
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 ReleaseFile();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
255
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 if (volumes != NULL)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
257 free(volumes);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
258
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 if (tracks != NULL) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
260
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 FSRef **ptr;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
262 for (ptr = tracks; *ptr != (FSRef *) - 1; ptr++)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 if (*ptr != NULL)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
264 free(*ptr);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
265
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
266 free(tracks);
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 }
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 }
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 /* Get the Unix disk name of the volume */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
271 static const char *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
272 SDL_SYS_CDName(int drive)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
274 OSStatus err = noErr;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
275 HParamBlockRec pb;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
276 GetVolParmsInfoBuffer volParmsInfo;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
277
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 if (fakeCD)
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279 return "Fake CD-ROM Device";
768
de1b2c3063b9 Max has been reworking this code so it works on MacOS X 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 616
diff changeset
280
de1b2c3063b9 Max has been reworking this code so it works on MacOS X 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 616
diff changeset
281 pb.ioParam.ioNamePtr = NULL;
de1b2c3063b9 Max has been reworking this code so it works on MacOS X 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 616
diff changeset
282 pb.ioParam.ioVRefNum = volumes[drive];
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
283 pb.ioParam.ioBuffer = (Ptr) & volParmsInfo;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
284 pb.ioParam.ioReqCount = (SInt32) sizeof(volParmsInfo);
768
de1b2c3063b9 Max has been reworking this code so it works on MacOS X 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 616
diff changeset
285 err = PBHGetVolParmsSync(&pb);
de1b2c3063b9 Max has been reworking this code so it works on MacOS X 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 616
diff changeset
286
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 if (err != noErr) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
288 SDL_SetError("PBHGetVolParmsSync returned %d", err);
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 return NULL;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290 }
768
de1b2c3063b9 Max has been reworking this code so it works on MacOS X 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 616
diff changeset
291
de1b2c3063b9 Max has been reworking this code so it works on MacOS X 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 616
diff changeset
292 return volParmsInfo.vMDeviceID;
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293 }
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 /* Open the "device" */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
296 static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
297 SDL_SYS_CDOpen(int drive)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 {
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299 /* Only allow 1 device to be open */
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300 if (currentDrive >= 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
301 SDL_SetError("Only one cdrom is supported");
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
302 return -1;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
303 } else
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304 currentDrive = drive;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306 return drive;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 }
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309 /* Get the table of contents */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
310 static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
311 SDL_SYS_CDGetTOC(SDL_CD * cdrom)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 {
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 if (fakeCD) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
314 SDL_SetError(kErrorFakeDevice);
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 return -1;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
317
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318 if (didReadTOC) {
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319 cdrom->numtracks = cacheTOCNumTracks;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 return 0;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
321 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
322
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
323
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
324 ReadTOCData(volumes[cdrom->id], cdrom);
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
325 didReadTOC = SDL_TRUE;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
326 cacheTOCNumTracks = cdrom->numtracks;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
327
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328 return 0;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329 }
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
330
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331 /* Get CD-ROM status */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
332 static CDstatus
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
333 SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 {
768
de1b2c3063b9 Max has been reworking this code so it works on MacOS X 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 616
diff changeset
335 if (position) {
de1b2c3063b9 Max has been reworking this code so it works on MacOS X 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 616
diff changeset
336 int trackFrame;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
337
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
338 Lock();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
339 trackFrame = GetCurrentFrame();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
340 Unlock();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
341
768
de1b2c3063b9 Max has been reworking this code so it works on MacOS X 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 616
diff changeset
342 *position = cdrom->track[currentTrack].offset + trackFrame;
de1b2c3063b9 Max has been reworking this code so it works on MacOS X 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 616
diff changeset
343 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
344
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 return status;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346 }
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 /* Start playback */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
349 static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
350 SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 {
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352 int startFrame, stopFrame;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
353 FSRef *ref;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
354
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
355 if (fakeCD) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
356 SDL_SetError(kErrorFakeDevice);
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357 return -1;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
359
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360 Lock();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
361
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
362 if (LoadTracks(cdrom) < 0)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 return -2;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
364
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
365 if (PauseFile() < 0)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366 return -3;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
367
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
368 if (ReleaseFile() < 0)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369 return -4;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
370
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
371 ref = GetFileForOffset(cdrom, start, length, &startFrame, &stopFrame);
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 if (ref == NULL) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
373 SDL_SetError("SDL_SYS_CDPlay: No file for start=%d, length=%d",
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
374 start, length);
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 return -5;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
377
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
378 if (LoadFile(ref, startFrame, stopFrame) < 0)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 return -6;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
380
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
381 SetCompletionProc(CompletionProc, cdrom);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
382
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
383 if (PlayFile() < 0)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384 return -7;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
385
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 status = CD_PLAYING;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
387
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388 Unlock();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
389
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
390 return 0;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391 }
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
392
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
393 /* Pause playback */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
394 static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
395 SDL_SYS_CDPause(SDL_CD * cdrom)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396 {
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
397 if (fakeCD) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
398 SDL_SetError(kErrorFakeDevice);
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399 return -1;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
401
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
402 Lock();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
403
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
404 if (PauseFile() < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
405 Unlock();
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406 return -2;
768
de1b2c3063b9 Max has been reworking this code so it works on MacOS X 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 616
diff changeset
407 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
408
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409 status = CD_PAUSED;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
410
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
411 Unlock();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
412
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 return 0;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
414 }
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
415
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
416 /* Resume playback */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
417 static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
418 SDL_SYS_CDResume(SDL_CD * cdrom)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
419 {
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
420 if (fakeCD) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
421 SDL_SetError(kErrorFakeDevice);
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
422 return -1;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
423 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
424
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
425 Lock();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
426
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
427 if (PlayFile() < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
428 Unlock();
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
429 return -2;
768
de1b2c3063b9 Max has been reworking this code so it works on MacOS X 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 616
diff changeset
430 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
431
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
432 status = CD_PLAYING;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
433
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
434 Unlock();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
435
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
436 return 0;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
437 }
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
438
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
439 /* Stop playback */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
440 static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
441 SDL_SYS_CDStop(SDL_CD * cdrom)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
442 {
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
443 if (fakeCD) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
444 SDL_SetError(kErrorFakeDevice);
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
445 return -1;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
446 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
447
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
448 Lock();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
449
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
450 if (PauseFile() < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
451 Unlock();
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
452 return -2;
768
de1b2c3063b9 Max has been reworking this code so it works on MacOS X 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 616
diff changeset
453 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
454
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
455 if (ReleaseFile() < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
456 Unlock();
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
457 return -3;
768
de1b2c3063b9 Max has been reworking this code so it works on MacOS X 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 616
diff changeset
458 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
459
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
460 status = CD_STOPPED;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
461
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
462 Unlock();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
463
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
464 return 0;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
465 }
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
466
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
467 /* Eject the CD-ROM (Unmount the volume) */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
468 static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
469 SDL_SYS_CDEject(SDL_CD * cdrom)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
470 {
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
471 OSStatus err;
1793
4d66375c2012 Date: Mon, 8 May 2006 14:19:30 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
472 pid_t dissenter;
4d66375c2012 Date: Mon, 8 May 2006 14:19:30 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
473
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
474 if (fakeCD) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
475 SDL_SetError(kErrorFakeDevice);
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
476 return -1;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
477 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
478
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
479 Lock();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
480
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
481 if (PauseFile() < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
482 Unlock();
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
483 return -2;
768
de1b2c3063b9 Max has been reworking this code so it works on MacOS X 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 616
diff changeset
484 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
485
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
486 if (ReleaseFile() < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
487 Unlock();
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
488 return -3;
768
de1b2c3063b9 Max has been reworking this code so it works on MacOS X 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 616
diff changeset
489 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
490
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
491 status = CD_STOPPED;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
492
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
493 /* Eject the volume */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
494 err = FSEjectVolumeSync(volumes[cdrom->id], kNilOptions, &dissenter);
768
de1b2c3063b9 Max has been reworking this code so it works on MacOS X 10.1
Sam Lantinga <slouken@libsdl.org>
parents: 616
diff changeset
495
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
496 if (err != noErr) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
497 Unlock();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
498 SDL_SetError("PBUnmountVol returned %d", err);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
499 return -4;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
500 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
501
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
502 status = CD_TRAYEMPTY;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
503
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
504 /* Invalidate volume and track info */
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
505 volumes[cdrom->id] = 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
506 free(tracks[cdrom->id]);
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
507 tracks[cdrom->id] = NULL;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
508
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
509 Unlock();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
510
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
511 return 0;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512 }
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
513
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
514 /* Close the CD-ROM */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
515 static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
516 SDL_SYS_CDClose(SDL_CD * cdrom)
616
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
517 {
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
518 currentDrive = -1;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
519 return;
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
520 }
12c746afbc27 Oops...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
521
1635
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
522 #endif /* SDL_CDROM_MACOSX */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
523 /* vi: set ts=4 sw=4 expandtab: */