Mercurial > sdl-ios-xcode
annotate src/cdrom/aix/SDL_syscdrom.c @ 1348:40d0975c1769
Date: Mon, 6 Feb 2006 11:41:04 -0500
From: "mystml@adinet.com.uy"
Subject: [SDL] ALT-F4 using DirectX
My game isn't getting SDL_QUIT when I press ALT-F4 using the DirectX
driver; it does get SDL_QUIT when I press the red X in the window.
I tracked this down to DX5_HandleMessage() in SDL_dx5events.c;
WM_SYSKEYDOWN is being trapped and ignored which causes Windows not to post
a WM_CLOSE, hence no SDL_QUIT is being generated.
The relevant code is this :
/* The keyboard is handled via DirectInput */
case WM_SYSKEYUP:
case WM_SYSKEYDOWN:
case WM_KEYUP:
case WM_KEYDOWN: {
/* Ignore windows keyboard messages */;
}
return(0);
If I comment the WM_SYSKEYDOWN case, it falls through DefWindowProc() and
ALT-F4 starts working again.
I'm not sure about the best way to fix this. One option is handling ALT-F4
as a particular case somehow, but doesn't sound good. Another option would
be to handle WM_SYSKEYDOWN separately and breaking instead of returning 0,
so processing falls through and goes to DefWindowProc which does The Right
Thing (TM). This seems to be the minimal change that makes ALT-F4 work and
normal keyboard input continues to work.
Does this sound reasonable? Am I overlooking anything? Do I submit a patch?
--Gabriel
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 08 Feb 2006 17:19:43 +0000 |
parents | 604d73db6802 |
children | c71e05b4dc2e |
rev | line source |
---|---|
0 | 1 /* |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
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:
0
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 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:
0
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
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:
0
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
0
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:
0
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:
0
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Carsten Griwodz | |
20 griff@kom.tu-darmstadt.de | |
21 | |
22 based on linux/SDL_syscdrom.c by Sam Lantinga | |
23 */ | |
24 | |
25 /* Functions for system-level CD-ROM audio control */ | |
26 | |
27 #define DEBUG_CDROM 1 | |
28 | |
29 #include <sys/types.h> | |
30 #include <sys/stat.h> | |
31 #include <fcntl.h> | |
32 #include <errno.h> | |
33 #include <unistd.h> | |
34 | |
35 #include <sys/ioctl.h> | |
36 #include <sys/devinfo.h> | |
37 #include <sys/mntctl.h> | |
38 #include <sys/statfs.h> | |
39 #include <sys/vmount.h> | |
40 #include <fstab.h> | |
41 #include <sys/scdisk.h> | |
42 | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
43 #include "SDL_stdlib.h" |
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
44 #include "SDL_string.h" |
0 | 45 #include "SDL_error.h" |
46 #include "SDL_cdrom.h" | |
47 #include "SDL_syscdrom.h" | |
48 | |
49 /* The maximum number of CD-ROM drives we'll detect */ | |
50 #define MAX_DRIVES 16 | |
51 | |
52 /* A list of available CD-ROM drives */ | |
53 static char *SDL_cdlist[MAX_DRIVES]; | |
54 static dev_t SDL_cdmode[MAX_DRIVES]; | |
55 | |
56 /* The system-dependent CD control functions */ | |
57 static const char *SDL_SYS_CDName(int drive); | |
58 static int SDL_SYS_CDOpen(int drive); | |
59 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); | |
60 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); | |
61 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); | |
62 static int SDL_SYS_CDPause(SDL_CD *cdrom); | |
63 static int SDL_SYS_CDResume(SDL_CD *cdrom); | |
64 static int SDL_SYS_CDStop(SDL_CD *cdrom); | |
65 static int SDL_SYS_CDEject(SDL_CD *cdrom); | |
66 static void SDL_SYS_CDClose(SDL_CD *cdrom); | |
67 static int SDL_SYS_CDioctl(int id, int command, void *arg); | |
68 | |
69 /* Check a drive to see if it is a CD-ROM */ | |
70 static int CheckDrive(char *drive, struct stat *stbuf) | |
71 { | |
72 int is_cd; | |
73 int cdfd; | |
74 int ret; | |
75 struct devinfo info; | |
76 | |
77 /* If it doesn't exist, return -1 */ | |
78 if ( stat(drive, stbuf) < 0 ) { | |
79 return -1; | |
80 } | |
81 | |
82 /* If it does exist, verify that it's an available CD-ROM */ | |
83 is_cd = 0; | |
84 if ( S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode) ) { | |
85 cdfd = open(drive, (O_RDONLY|O_EXCL|O_NONBLOCK), 0); | |
86 if ( cdfd >= 0 ) { | |
87 ret = SDL_SYS_CDioctl( cdfd, IOCINFO, &info ); | |
88 if ( ret < 0 ) { | |
89 /* Some kind of error */ | |
90 is_cd = 0; | |
91 } else { | |
92 if ( info.devtype == DD_CDROM ) { | |
93 is_cd = 1; | |
94 } else { | |
95 is_cd = 0; | |
96 } | |
97 } | |
98 close(cdfd); | |
99 } | |
100 #ifdef DEBUG_CDROM | |
101 else | |
102 { | |
103 fprintf(stderr, "Could not open drive %s (%s)\n", drive, strerror(errno)); | |
104 } | |
105 #endif | |
106 } | |
107 return is_cd; | |
108 } | |
109 | |
110 /* Add a CD-ROM drive to our list of valid drives */ | |
111 static void AddDrive(char *drive, struct stat *stbuf) | |
112 { | |
113 int i; | |
114 | |
115 if ( SDL_numcds < MAX_DRIVES ) { | |
116 /* Check to make sure it's not already in our list. | |
117 This can happen when we see a drive via symbolic link. | |
118 */ | |
119 for ( i=0; i<SDL_numcds; ++i ) { | |
120 if ( stbuf->st_rdev == SDL_cdmode[i] ) { | |
121 #ifdef DEBUG_CDROM | |
122 fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]); | |
123 #endif | |
124 return; | |
125 } | |
126 } | |
127 | |
128 /* Add this drive to our list */ | |
129 i = SDL_numcds; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
130 SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1); |
0 | 131 if ( SDL_cdlist[i] == NULL ) { |
132 SDL_OutOfMemory(); | |
133 return; | |
134 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
135 SDL_strcpy(SDL_cdlist[i], drive); |
0 | 136 SDL_cdmode[i] = stbuf->st_rdev; |
137 ++SDL_numcds; | |
138 #ifdef DEBUG_CDROM | |
139 fprintf(stderr, "Added CD-ROM drive: %s\n", drive); | |
140 #endif | |
141 } | |
142 } | |
143 | |
144 static void CheckMounts() | |
145 { | |
146 char* buffer; | |
147 int bufsz; | |
148 struct vmount* ptr; | |
149 int ret; | |
150 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
151 buffer = (char*)SDL_malloc(10); |
0 | 152 bufsz = 10; |
153 if ( buffer==NULL ) | |
154 { | |
155 fprintf(stderr, "Could not allocate 10 bytes in aix/SDL_syscdrom.c:CheckMounts\n" ); | |
156 exit ( -10 ); | |
157 } | |
158 | |
159 do | |
160 { | |
161 /* mntctrl() returns an array of all mounted filesystems */ | |
162 ret = mntctl ( MCTL_QUERY, bufsz, buffer ); | |
163 if ( ret == 0 ) | |
164 { | |
165 /* Buffer was too small, realloc. */ | |
166 bufsz = *(int*)buffer; /* Required size is in first word. */ | |
167 /* (whatever a word is in AIX 4.3.3) */ | |
168 /* int seems to be OK in 32bit mode. */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
169 SDL_free(buffer); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
170 buffer = (char*)SDL_malloc(bufsz); |
0 | 171 if ( buffer==NULL ) |
172 { | |
173 fprintf(stderr, | |
174 "Could not allocate %d bytes in aix/SDL_syscdrom.c:CheckMounts\n", | |
175 bufsz ); | |
176 exit ( -10 ); | |
177 } | |
178 } | |
179 else if ( ret < 0 ) | |
180 { | |
181 #ifdef DEBUG_CDROM | |
182 fprintf(stderr, "Error reading vmount structures\n"); | |
183 #endif | |
184 return; | |
185 } | |
186 } | |
187 while ( ret == 0 ); | |
188 | |
189 #ifdef DEBUG_CDROM | |
190 fprintf ( stderr, "Read %d vmount structures\n",ret ); | |
191 #endif | |
192 ptr = (struct vmount*)buffer; | |
193 do | |
194 { | |
195 switch(ptr->vmt_gfstype) | |
196 { | |
197 case MNT_CDROM : | |
198 { | |
199 struct stat stbuf; | |
200 char* text; | |
201 | |
202 text = (char*)ptr + ptr->vmt_data[VMT_OBJECT].vmt_off; | |
203 #ifdef DEBUG_CDROM | |
204 fprintf(stderr, "Checking mount path: %s mounted on %s\n", | |
205 text, (char*)ptr + ptr->vmt_data[VMT_STUB].vmt_off ); | |
206 #endif | |
207 if ( CheckDrive( text, &stbuf) > 0) | |
208 { | |
209 AddDrive( text, &stbuf); | |
210 } | |
211 } | |
212 break; | |
213 default : | |
214 break; | |
215 } | |
216 ptr = (struct vmount*)((char*)ptr + ptr->vmt_length); | |
217 ret--; | |
218 } | |
219 while ( ret > 0 ); | |
220 | |
221 free ( buffer ); | |
222 } | |
223 | |
224 static int CheckNonmounts() | |
225 { | |
226 #ifdef _THREAD_SAFE | |
227 AFILE_t fsFile = NULL; | |
228 int passNo = 0; | |
229 int ret; | |
230 struct fstab entry; | |
231 struct stat stbuf; | |
232 | |
233 ret = setfsent_r( &fsFile, &passNo ); | |
234 if ( ret != 0 ) return -1; | |
235 do | |
236 { | |
237 ret = getfsent_r ( &entry, &fsFile, &passNo ); | |
238 if ( ret == 0 ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
239 char* l = SDL_strrchr(entry.fs_spec,'/'); |
0 | 240 if ( l != NULL ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
241 if ( !SDL_strncmp("cd",++l,2) ) { |
0 | 242 #ifdef DEBUG_CDROM |
243 fprintf(stderr, | |
244 "Found unmounted CD ROM drive with device name %s\n", | |
245 entry.fs_spec); | |
246 #endif | |
247 if ( CheckDrive( entry.fs_spec, &stbuf) > 0) | |
248 { | |
249 AddDrive( entry.fs_spec, &stbuf); | |
250 } | |
251 } | |
252 } | |
253 } | |
254 } | |
255 while ( ret == 0 ); | |
256 ret = endfsent_r ( &fsFile ); | |
257 if ( ret != 0 ) return -1; | |
258 return 0; | |
259 #else | |
260 struct fstab* entry; | |
261 struct stat stbuf; | |
262 | |
263 setfsent(); | |
264 do | |
265 { | |
266 entry = getfsent(); | |
267 if ( entry != NULL ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
268 char* l = SDL_strrchr(entry->fs_spec,'/'); |
0 | 269 if ( l != NULL ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
270 if ( !SDL_strncmp("cd",++l,2) ) { |
0 | 271 #ifdef DEBUG_CDROM |
272 fprintf(stderr,"Found unmounted CD ROM drive with device name %s", entry->fs_spec); | |
273 #endif | |
274 if ( CheckDrive( entry->fs_spec, &stbuf) > 0) | |
275 { | |
276 AddDrive( entry->fs_spec, &stbuf); | |
277 } | |
278 } | |
279 } | |
280 } | |
281 } | |
282 while ( entry != NULL ); | |
283 endfsent(); | |
284 #endif | |
285 } | |
286 | |
287 int SDL_SYS_CDInit(void) | |
288 { | |
289 char *SDLcdrom; | |
290 struct stat stbuf; | |
291 | |
292 /* Fill in our driver capabilities */ | |
293 SDL_CDcaps.Name = SDL_SYS_CDName; | |
294 SDL_CDcaps.Open = SDL_SYS_CDOpen; | |
295 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; | |
296 SDL_CDcaps.Status = SDL_SYS_CDStatus; | |
297 SDL_CDcaps.Play = SDL_SYS_CDPlay; | |
298 SDL_CDcaps.Pause = SDL_SYS_CDPause; | |
299 SDL_CDcaps.Resume = SDL_SYS_CDResume; | |
300 SDL_CDcaps.Stop = SDL_SYS_CDStop; | |
301 SDL_CDcaps.Eject = SDL_SYS_CDEject; | |
302 SDL_CDcaps.Close = SDL_SYS_CDClose; | |
303 | |
304 /* 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
|
305 SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ |
0 | 306 if ( SDLcdrom != NULL ) { |
307 char *cdpath, *delim; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
308 cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1); |
0 | 309 if ( cdpath != NULL ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
310 SDL_strcpy(cdpath, SDLcdrom); |
0 | 311 SDLcdrom = cdpath; |
312 do { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
313 delim = SDL_strchr(SDLcdrom, ':'); |
0 | 314 if ( delim ) { |
315 *delim++ = '\0'; | |
316 } | |
317 #ifdef DEBUG_CDROM | |
318 fprintf(stderr, "Checking CD-ROM drive from SDL_CDROM: %s\n", SDLcdrom); | |
319 #endif | |
320 if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) { | |
321 AddDrive(SDLcdrom, &stbuf); | |
322 } | |
323 if ( delim ) { | |
324 SDLcdrom = delim; | |
325 } else { | |
326 SDLcdrom = NULL; | |
327 } | |
328 } while ( SDLcdrom ); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
329 SDL_free(cdpath); |
0 | 330 } |
331 | |
332 /* If we found our drives, there's nothing left to do */ | |
333 if ( SDL_numcds > 0 ) { | |
334 return(0); | |
335 } | |
336 } | |
337 | |
338 CheckMounts(); | |
339 CheckNonmounts(); | |
340 | |
341 return 0; | |
342 } | |
343 | |
344 /* General ioctl() CD-ROM command function */ | |
345 static int SDL_SYS_CDioctl(int id, int command, void *arg) | |
346 { | |
347 int retval; | |
348 | |
349 retval = ioctl(id, command, arg); | |
350 if ( retval < 0 ) { | |
351 SDL_SetError("ioctl() error: %s", strerror(errno)); | |
352 } | |
353 return retval; | |
354 } | |
355 | |
356 static const char *SDL_SYS_CDName(int drive) | |
357 { | |
358 return(SDL_cdlist[drive]); | |
359 } | |
360 | |
361 static int SDL_SYS_CDOpen(int drive) | |
362 { | |
363 int fd; | |
364 char* lastsl; | |
365 char* cdromname; | |
366 | |
367 /* | |
368 * We found /dev/cd? drives and that is in our list. But we can | |
369 * open only the /dev/rcd? versions of those devices for Audio CD. | |
370 */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
371 cdromname = (char*)SDL_malloc( SDL_strlen(SDL_cdlist[drive]+2) ); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
372 SDL_strcpy(cdromname,SDL_cdlist[drive]); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
373 lastsl = SDL_strrchr(cdromname,'/'); |
0 | 374 if (lastsl) { |
375 *lastsl = 0; | |
376 strcat(cdromname,"/r"); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
377 lastsl = SDL_strrchr(SDL_cdlist[drive],'/'); |
0 | 378 if (lastsl) { |
379 lastsl++; | |
380 strcat(cdromname,lastsl); | |
381 } | |
382 } | |
383 | |
384 #ifdef DEBUG_CDROM | |
385 fprintf(stderr, "Should open drive %s, opening %s\n", SDL_cdlist[drive], cdromname); | |
386 #endif | |
387 | |
388 /* | |
389 * Use exclusive access. Don't use SC_DIAGNOSTICS as xmcd does because they | |
390 * require root priviledges, and we don't want that. SC_SINGLE provides | |
391 * exclusive access with less trouble. | |
392 */ | |
393 fd = openx(cdromname, O_RDONLY, NULL, SC_SINGLE); | |
394 if ( fd < 0 ) | |
395 { | |
396 #ifdef DEBUG_CDROM | |
397 fprintf(stderr, "Could not open drive %s (%s)\n", cdromname, strerror(errno)); | |
398 #endif | |
399 } | |
400 else | |
401 { | |
402 struct mode_form_op cdMode; | |
403 int ret; | |
404 #ifdef DEBUG_CDROM | |
405 cdMode.action = CD_GET_MODE; | |
406 ret = SDL_SYS_CDioctl(fd, DK_CD_MODE, &cdMode); | |
407 if ( ret < 0 ) { | |
408 fprintf(stderr, | |
409 "Could not get drive mode for %s (%s)\n", | |
410 cdromname, strerror(errno)); | |
411 } else { | |
412 switch(cdMode.cd_mode_form) { | |
413 case CD_MODE1 : | |
414 fprintf(stderr, | |
415 "Drive mode for %s is %s\n", | |
416 cdromname, "CD-ROM Data Mode 1"); | |
417 break; | |
418 case CD_MODE2_FORM1 : | |
419 fprintf(stderr, | |
420 "Drive mode for %s is %s\n", | |
421 cdromname, "CD-ROM XA Data Mode 2 Form 1"); | |
422 break; | |
423 case CD_MODE2_FORM2 : | |
424 fprintf(stderr, | |
425 "Drive mode for %s is %s\n", | |
426 cdromname, "CD-ROM XA Data Mode 2 Form 2"); | |
427 break; | |
428 case CD_DA : | |
429 fprintf(stderr, | |
430 "Drive mode for %s is %s\n", | |
431 cdromname, "CD-DA"); | |
432 break; | |
433 default : | |
434 fprintf(stderr, | |
435 "Drive mode for %s is %s\n", | |
436 cdromname, "unknown"); | |
437 break; | |
438 } | |
439 } | |
440 #endif | |
441 | |
442 cdMode.action = CD_CHG_MODE; | |
443 cdMode.cd_mode_form = CD_DA; | |
444 ret = SDL_SYS_CDioctl(fd, DK_CD_MODE, &cdMode); | |
445 if ( ret < 0 ) { | |
446 #ifdef DEBUG_CDROM | |
447 fprintf(stderr, | |
448 "Could not set drive mode for %s (%s)\n", | |
449 cdromname, strerror(errno)); | |
450 #endif | |
451 SDL_SetError("ioctl() error: Could not set CD drive mode, %s", | |
452 strerror(errno)); | |
453 } else { | |
454 #ifdef DEBUG_CDROM | |
455 fprintf(stderr, | |
456 "Drive mode for %s set to CD_DA\n", | |
457 cdromname); | |
458 #endif | |
459 } | |
460 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
461 SDL_free(cdromname); |
0 | 462 return fd; |
463 } | |
464 | |
465 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) | |
466 { | |
467 struct cd_audio_cmd cmd; | |
468 struct cd_audio_cmd entry; | |
469 int i; | |
470 int okay; | |
471 | |
472 cmd.audio_cmds = CD_TRK_INFO_AUDIO; | |
473 cmd.msf_flag = FALSE; | |
474 if ( SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd) < 0 ) { | |
475 return -1; | |
476 } | |
477 | |
478 okay = 0; | |
479 cdrom->numtracks = cmd.indexing.track_index.last_track | |
480 - cmd.indexing.track_index.first_track+1; | |
481 if ( cdrom->numtracks > SDL_MAX_TRACKS ) { | |
482 cdrom->numtracks = SDL_MAX_TRACKS; | |
483 } | |
484 | |
485 /* Read all the track TOC entries */ | |
486 for ( i=0; i<=cdrom->numtracks; ++i ) { | |
487 if ( i == cdrom->numtracks ) { | |
488 cdrom->track[i].id = 0xAA;; | |
489 } else { | |
490 cdrom->track[i].id = cmd.indexing.track_index.first_track+i; | |
491 } | |
492 entry.audio_cmds = CD_GET_TRK_MSF; | |
493 entry.indexing.track_msf.track = cdrom->track[i].id; | |
494 if ( SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &entry) < 0 ) { | |
495 break; | |
496 } else { | |
497 cdrom->track[i].type = 0; /* don't know how to detect 0x04 data track */ | |
498 cdrom->track[i].offset = MSF_TO_FRAMES( | |
499 entry.indexing.track_msf.mins, | |
500 entry.indexing.track_msf.secs, | |
501 entry.indexing.track_msf.frames); | |
502 cdrom->track[i].length = 0; | |
503 if ( i > 0 ) { | |
504 cdrom->track[i-1].length = cdrom->track[i].offset | |
505 - cdrom->track[i-1].offset; | |
506 } | |
507 } | |
508 } | |
509 if ( i == (cdrom->numtracks+1) ) { | |
510 okay = 1; | |
511 } | |
512 return(okay ? 0 : -1); | |
513 } | |
514 | |
515 /* Get CD-ROM status */ | |
516 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) | |
517 { | |
518 CDstatus status; | |
519 struct cd_audio_cmd cmd; | |
520 cmd.audio_cmds = CD_INFO_AUDIO; | |
521 | |
522 if ( SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd) < 0 ) { | |
523 #ifdef DEBUG_CDROM | |
524 fprintf(stderr, "ioctl failed in SDL_SYS_CDStatus (%s)\n", SDL_GetError()); | |
525 #endif | |
526 status = CD_ERROR; | |
527 } else { | |
528 switch (cmd.status) { | |
529 case CD_NO_AUDIO: | |
530 case CD_COMPLETED: | |
531 status = CD_STOPPED; | |
532 break; | |
533 case CD_PLAY_AUDIO: | |
534 status = CD_PLAYING; | |
535 break; | |
536 case CD_PAUSE_AUDIO: | |
537 status = CD_PAUSED; | |
538 break; | |
539 case CD_NOT_VALID: | |
540 #ifdef DEBUG_CDROM | |
541 fprintf(stderr, "cdStatus failed with CD_NOT_VALID\n"); | |
542 #endif | |
543 status = CD_ERROR; | |
544 break; | |
545 case CD_STATUS_ERROR: | |
546 #ifdef DEBUG_CDROM | |
547 fprintf(stderr, "cdStatus failed with CD_STATUS_ERROR\n"); | |
548 #endif | |
549 status = CD_ERROR; | |
550 break; | |
551 default: | |
552 #ifdef DEBUG_CDROM | |
553 fprintf(stderr, "cdStatus failed with unknown error\n"); | |
554 #endif | |
555 status = CD_ERROR; | |
556 break; | |
557 } | |
558 } | |
559 if ( position ) { | |
560 if ( status == CD_PLAYING || (status == CD_PAUSED) ) { | |
561 *position = MSF_TO_FRAMES( cmd.indexing.info_audio.current_mins, | |
562 cmd.indexing.info_audio.current_secs, | |
563 cmd.indexing.info_audio.current_frames); | |
564 } else { | |
565 *position = 0; | |
566 } | |
567 } | |
568 return status; | |
569 } | |
570 | |
571 /* Start play */ | |
572 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) | |
573 { | |
574 struct cd_audio_cmd cmd; | |
575 | |
576 /* | |
577 * My CD Rom is muted by default. I think I read that this is new with | |
578 * AIX 4.3. SDL does not change the volume, so I need a kludge. Maybe | |
579 * its better to do this elsewhere? | |
580 */ | |
581 cmd.audio_cmds = CD_PLAY_AUDIO | CD_SET_VOLUME; | |
582 cmd.msf_flag = TRUE; | |
583 FRAMES_TO_MSF(start, | |
584 &cmd.indexing.msf.first_mins, | |
585 &cmd.indexing.msf.first_secs, | |
586 &cmd.indexing.msf.first_frames); | |
587 FRAMES_TO_MSF(start+length, | |
588 &cmd.indexing.msf.last_mins, | |
589 &cmd.indexing.msf.last_secs, | |
590 &cmd.indexing.msf.last_frames); | |
591 cmd.volume_type = CD_VOLUME_ALL; | |
592 cmd.all_channel_vol = 255; /* This is a uchar. What is a good value? No docu! */ | |
593 cmd.out_port_0_sel = CD_AUDIO_CHNL_0; | |
594 cmd.out_port_1_sel = CD_AUDIO_CHNL_1; | |
595 cmd.out_port_2_sel = CD_AUDIO_CHNL_2; | |
596 cmd.out_port_3_sel = CD_AUDIO_CHNL_3; | |
597 | |
598 #ifdef DEBUG_CDROM | |
599 fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", | |
600 cmd.indexing.msf.first_mins, | |
601 cmd.indexing.msf.first_secs, | |
602 cmd.indexing.msf.first_frames, | |
603 cmd.indexing.msf.last_mins, | |
604 cmd.indexing.msf.last_secs, | |
605 cmd.indexing.msf.last_frames); | |
606 #endif | |
607 return(SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd)); | |
608 } | |
609 | |
610 /* Pause play */ | |
611 static int SDL_SYS_CDPause(SDL_CD *cdrom) | |
612 { | |
613 struct cd_audio_cmd cmd; | |
614 cmd.audio_cmds = CD_PAUSE_AUDIO; | |
615 return(SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd)); | |
616 } | |
617 | |
618 /* Resume play */ | |
619 static int SDL_SYS_CDResume(SDL_CD *cdrom) | |
620 { | |
621 struct cd_audio_cmd cmd; | |
622 cmd.audio_cmds = CD_RESUME_AUDIO; | |
623 return(SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd)); | |
624 } | |
625 | |
626 /* Stop play */ | |
627 static int SDL_SYS_CDStop(SDL_CD *cdrom) | |
628 { | |
629 struct cd_audio_cmd cmd; | |
630 cmd.audio_cmds = CD_STOP_AUDIO; | |
631 return(SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd)); | |
632 } | |
633 | |
634 /* Eject the CD-ROM */ | |
635 static int SDL_SYS_CDEject(SDL_CD *cdrom) | |
636 { | |
637 return(SDL_SYS_CDioctl(cdrom->id, DKEJECT, 0)); | |
638 } | |
639 | |
640 /* Close the CD-ROM handle */ | |
641 static void SDL_SYS_CDClose(SDL_CD *cdrom) | |
642 { | |
643 close(cdrom->id); | |
644 } | |
645 | |
646 void SDL_SYS_CDQuit(void) | |
647 { | |
648 int i; | |
649 | |
650 if ( SDL_numcds > 0 ) { | |
651 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
|
652 SDL_free(SDL_cdlist[i]); |
0 | 653 } |
654 SDL_numcds = 0; | |
655 } | |
656 } | |
657 |