19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL - Simple DirectMedia Layer 39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Copyright (C) 1997-2012 Sam Lantinga 49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is free software; you can redistribute it and/or 69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall modify it under the terms of the GNU Lesser General Public 79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License as published by the Free Software Foundation; either 89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall version 2.1 of the License, or (at your option) any later version. 99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is distributed in the hope that it will be useful, 119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall but WITHOUT ANY WARRANTY; without even the implied warranty of 129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Lesser General Public License for more details. 149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall You should have received a copy of the GNU Lesser General Public 169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License along with this library; if not, write to the Free Software 179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Sam Lantinga 209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall slouken@libsdl.org 219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/ 229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h" 239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef SDL_CDROM_BEOS 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Functions for system-level CD-ROM audio control on BeOS 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (not completely implemented yet) 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <sys/types.h> 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <sys/stat.h> 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <unistd.h> 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <scsi.h> 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <Directory.h> 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <Entry.h> 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <Path.h> 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_cdrom.h" 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern "C" { 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../SDL_syscdrom.h" 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Constants to help us get at the SCSI table-of-contents info */ 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define CD_NUMTRACKS(toc) toc.toc_data[3] 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define CD_TRACK(toc, track) (&toc.toc_data[6+(track)*8]) 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define CD_TRACK_N(toc, track) CD_TRACK(toc, track)[0] 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define CD_TRACK_M(toc, track) CD_TRACK(toc, track)[3] 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define CD_TRACK_S(toc, track) CD_TRACK(toc, track)[4] 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define CD_TRACK_F(toc, track) CD_TRACK(toc, track)[5] 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Constants to help us get at the SCSI position info */ 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define POS_TRACK(pos) pos.position[6] 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define POS_ABS_M(pos) pos.position[9] 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define POS_ABS_S(pos) pos.position[10] 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define POS_ABS_F(pos) pos.position[11] 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define POS_REL_M(pos) pos.position[13] 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define POS_REL_S(pos) pos.position[14] 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define POS_REL_F(pos) pos.position[15] 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* The maximum number of CD-ROM drives we'll detect */ 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define MAX_DRIVES 16 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* A list of available CD-ROM drives */ 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic char *SDL_cdlist[MAX_DRIVES]; 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* The system-dependent CD control functions */ 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic const char *SDL_SYS_CDName(int drive); 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDOpen(int drive); 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDGetTOC(SDL_CD *cdrom); 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDPause(SDL_CD *cdrom); 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDResume(SDL_CD *cdrom); 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDStop(SDL_CD *cdrom); 769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDEject(SDL_CD *cdrom); 779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void SDL_SYS_CDClose(SDL_CD *cdrom); 789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint try_dir(const char *directory); 799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Check a drive to see if it is a CD-ROM */ 829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int CheckDrive(char *drive) 839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall struct stat stbuf; 859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int is_cd, cdfd; 869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device_geometry info; 879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If it doesn't exist, return -1 */ 899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( stat(drive, &stbuf) < 0 ) { 909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(-1); 919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If it does exist, verify that it's an available CD-ROM */ 949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall is_cd = 0; 959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cdfd = open(drive, 0); 969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( cdfd >= 0 ) { 979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ioctl(cdfd, B_GET_GEOMETRY, &info) == B_NO_ERROR ) { 989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( info.device_type == B_CD ) { 999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall is_cd = 1; 1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall close(cdfd); 1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* This can happen when the drive is open .. (?) */; 1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall is_cd = 1; 1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(is_cd); 1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Add a CD-ROM drive to our list of valid drives */ 1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void AddDrive(char *drive) 1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int i; 1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall size_t len; 1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_numcds < MAX_DRIVES ) { 1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Add this drive to our list */ 1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall i = SDL_numcds; 1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall len = SDL_strlen(drive)+1; 1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_cdlist[i] = (char *)SDL_malloc(len); 1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_cdlist[i] == NULL ) { 1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_OutOfMemory(); 1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return; 1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_strlcpy(SDL_cdlist[i], drive, len); 1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ++SDL_numcds; 1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef CDROM_DEBUG 1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(stderr, "Added CD-ROM drive: %s\n", drive); 1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* IDE bus scanning magic */ 1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallenum { 1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall IDE_GET_DEVICES_INFO = B_DEVICE_OP_CODES_END + 50, 1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}; 1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstruct ide_ctrl_info { 1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bool ide_0_present; 1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bool ide_0_master_present; 1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bool ide_0_slave_present; 1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int ide_0_master_type; 1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int ide_0_slave_type; 1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bool ide_1_present; 1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bool ide_1_master_present; 1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bool ide_1_slave_present; 1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int ide_1_master_type; 1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int ide_1_slave_type; 1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}; 1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_SYS_CDInit(void) 1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall char *SDLcdrom; 1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Fill in our driver capabilities */ 1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_CDcaps.Name = SDL_SYS_CDName; 1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_CDcaps.Open = SDL_SYS_CDOpen; 1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; 1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_CDcaps.Status = SDL_SYS_CDStatus; 1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_CDcaps.Play = SDL_SYS_CDPlay; 1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_CDcaps.Pause = SDL_SYS_CDPause; 1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_CDcaps.Resume = SDL_SYS_CDResume; 1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_CDcaps.Stop = SDL_SYS_CDStop; 1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_CDcaps.Eject = SDL_SYS_CDEject; 1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_CDcaps.Close = SDL_SYS_CDClose; 1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Look in the environment for our CD-ROM drive list */ 1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */ 1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDLcdrom != NULL ) { 1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall char *cdpath, *delim; 1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall size_t len = SDL_strlen(SDLcdrom)+1; 1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cdpath = SDL_stack_alloc(char, len); 1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( cdpath != NULL ) { 1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_strlcpy(cdpath, SDLcdrom, len); 1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDLcdrom = cdpath; 1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall do { 1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall delim = SDL_strchr(SDLcdrom, ':'); 1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( delim ) { 1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *delim++ = '\0'; 1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( CheckDrive(SDLcdrom) > 0 ) { 1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall AddDrive(SDLcdrom); 1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( delim ) { 1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDLcdrom = delim; 1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDLcdrom = NULL; 1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } while ( SDLcdrom ); 1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_stack_free(cdpath); 1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If we found our drives, there's nothing left to do */ 1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_numcds > 0 ) { 1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Scan the system for CD-ROM drives */ 1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall try_dir("/dev/disk"); 2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 0; 2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint try_dir(const char *directory) 2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall BDirectory dir; 2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dir.SetTo(directory); 2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(dir.InitCheck() != B_NO_ERROR) { 2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return false; 2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall dir.Rewind(); 2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall BEntry entry; 2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while(dir.GetNextEntry(&entry) >= 0) { 2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall BPath path; 2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall const char *name; 2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall entry_ref e; 2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(entry.GetPath(&path) != B_NO_ERROR) 2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall continue; 2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall name = path.Path(); 2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(entry.GetRef(&e) != B_NO_ERROR) 2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall continue; 2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(entry.IsDirectory()) { 2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(SDL_strcmp(e.name, "floppy") == 0) 2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall continue; /* ignore floppy (it is not silent) */ 2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int devfd = try_dir(name); 2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(devfd >= 0) 2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return devfd; 2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else { 2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int devfd; 2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall device_geometry g; 2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(SDL_strcmp(e.name, "raw") != 0) 2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall continue; /* ignore partitions */ 2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall devfd = open(name, O_RDONLY); 2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(devfd < 0) 2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall continue; 2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g)) >= 0) { 2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if(g.device_type == B_CD) 2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall AddDrive(strdup(name)); 2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall close(devfd); 2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return B_ERROR; 2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* General ioctl() CD-ROM command function */ 2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDioctl(int index, int command, void *arg) 2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int okay; 2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int fd; 2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall okay = 0; 2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fd = open(SDL_cdlist[index], 0); 2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( fd >= 0 ) { 2659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ioctl(fd, command, arg) == B_NO_ERROR ) { 2669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall okay = 1; 2679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall close(fd); 2699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(okay ? 0 : -1); 2719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic const char *SDL_SYS_CDName(int drive) 2749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(SDL_cdlist[drive]); 2769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDOpen(int drive) 2799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(drive); 2819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDGetTOC(SDL_CD *cdrom) 2849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int i; 2869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall scsi_toc toc; 2879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_SYS_CDioctl(cdrom->id, B_SCSI_GET_TOC, &toc) == 0 ) { 2899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cdrom->numtracks = CD_NUMTRACKS(toc); 2909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( cdrom->numtracks > SDL_MAX_TRACKS ) { 2919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cdrom->numtracks = SDL_MAX_TRACKS; 2929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( i=0; i<=cdrom->numtracks; ++i ) { 2949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cdrom->track[i].id = CD_TRACK_N(toc, i); 2959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* FIXME: How do we tell on BeOS? */ 2969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cdrom->track[i].type = SDL_AUDIO_TRACK; 2979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cdrom->track[i].offset = MSF_TO_FRAMES( 2989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall CD_TRACK_M(toc, i), 2999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall CD_TRACK_S(toc, i), 3009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall CD_TRACK_F(toc, i)); 3019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cdrom->track[i].length = 0; 3029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( i > 0 ) { 3039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cdrom->track[i-1].length = 3049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cdrom->track[i].offset- 3059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cdrom->track[i-1].offset; 3069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 3099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 3109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(-1); 3119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Get CD-ROM status */ 3159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) 3169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall CDstatus status; 3189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int fd; 3199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int cur_frame; 3209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall scsi_position pos; 3219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fd = open(SDL_cdlist[cdrom->id], 0); 3239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cur_frame = 0; 3249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( fd >= 0 ) { 3259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ioctl(fd, B_SCSI_GET_POSITION, &pos) == B_NO_ERROR ) { 3269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cur_frame = MSF_TO_FRAMES( 3279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall POS_ABS_M(pos), POS_ABS_S(pos), POS_ABS_F(pos)); 3289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ! pos.position[1] || (pos.position[1] >= 0x13) || 3309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ((pos.position[1] == 0x12) && (!pos.position[6])) ) { 3319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall status = CD_STOPPED; 3329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 3339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( pos.position[1] == 0x11 ) { 3349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall status = CD_PLAYING; 3359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 3369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall status = CD_PAUSED; 3379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall close(fd); 3399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 3409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall status = CD_TRAYEMPTY; 3419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( position ) { 3439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *position = cur_frame; 3449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(status); 3469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Start play */ 3499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) 3509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int okay; 3529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int fd; 3539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall scsi_play_position pos; 3549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall okay = 0; 3569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fd = open(SDL_cdlist[cdrom->id], 0); 3579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( fd >= 0 ) { 3589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall FRAMES_TO_MSF(start, &pos.start_m, &pos.start_s, &pos.start_f); 3599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall FRAMES_TO_MSF(start+length, &pos.end_m, &pos.end_s, &pos.end_f); 3609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ioctl(fd, B_SCSI_PLAY_POSITION, &pos) == B_NO_ERROR ) { 3619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall okay = 1; 3629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall close(fd); 3649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(okay ? 0 : -1); 3669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Pause play */ 3699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDPause(SDL_CD *cdrom) 3709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_PAUSE_AUDIO, 0)); 3729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Resume play */ 3759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDResume(SDL_CD *cdrom) 3769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_RESUME_AUDIO, 0)); 3789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Stop play */ 3819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDStop(SDL_CD *cdrom) 3829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_STOP_AUDIO, 0)); 3849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Eject the CD-ROM */ 3879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDEject(SDL_CD *cdrom) 3889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(SDL_SYS_CDioctl(cdrom->id, B_SCSI_EJECT, 0)); 3909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Close the CD-ROM handle */ 3939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void SDL_SYS_CDClose(SDL_CD *cdrom) 3949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall close(cdrom->id); 3969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_SYS_CDQuit(void) 3999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 4009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int i; 4019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_numcds > 0 ) { 4039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( i=0; i<SDL_numcds; ++i ) { 4049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(SDL_cdlist[i]); 4059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_numcds = 0; 4079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 4099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* SDL_CDROM_BEOS */ 411