Esempio n. 1
0
bool CDROM_Interface_SDL::SetDevice (char* path, int forceCD) 
{ 
	char buffer[512];
	strcpy(buffer,path);
	upcase(buffer);

	int num = SDL_CDNumDrives();
	if ((forceCD>=0) && (forceCD<num)) {
		driveID = forceCD;
	        cd = SDL_CDOpen(driveID);
	        SDL_CDStatus(cd);
	   	return true;
	};	
	
	const char* cdname = 0;
	for (int i=0; i<num; i++) {
		cdname = SDL_CDName(i);
		if (strcmp(buffer,cdname)==0) {
			cd = SDL_CDOpen(i);
			SDL_CDStatus(cd);
			driveID = i;
			return true;
		};
	};
	return false; 
};
Esempio n. 2
0
/* C API */
PyObject*
PyCD_New (int _index)
{
    PyCD *cd;
    SDL_CD *cdrom;
    
    ASSERT_CDROM_INIT(NULL);
    
    if (_index < 0 || _index > SDL_CDNumDrives ())
    {
        PyErr_SetString (PyExc_ValueError, "invalid cdrom drive index");
        return NULL;
    }

    cd = (PyCD*) PyCD_Type.tp_new (&PyCD_Type, NULL, NULL);
    if (!cd)
        return NULL;

    cdrom = SDL_CDOpen (_index);
    if (!cdrom)
    {
        Py_DECREF (cd);
        PyErr_SetString (PyExc_PyGameError, SDL_GetError ());
        return NULL;
    }
    
    cd->cd = cdrom;
    cd->index = _index;
    cdrommod_add_drive (_index, cdrom);
    return (PyObject*) cd;
}
Esempio n. 3
0
/* Methods */
static PyObject*
_cd_open (PyObject *self)
{
    SDL_CD *cd;
    PyCD *cdrom = (PyCD*)self;
    
    ASSERT_CDROM_INIT(NULL);
    
    cd = cdrommod_get_drive (cdrom->index);
    if (cd)
    {
        cdrom->cd = cd;
        Py_RETURN_NONE; /* Already open */
    }

    cd = SDL_CDOpen (cdrom->index);
    if (!cd)
    {
        PyErr_SetString (PyExc_PyGameError, SDL_GetError ());
        return NULL;
    }
    cdrom->cd = cd;
    cdrommod_add_drive (cdrom->index, cd);

    Py_RETURN_NONE;
}
Esempio n. 4
0
static int
_cd_init (PyObject *self, PyObject *args, PyObject *kwds)
{
    int _index;
    SDL_CD *cd;
    
    ASSERT_CDROM_INIT(-1);
    
    if (!PyArg_ParseTuple (args, "i", &_index))
        return -1;
    if (_index < 0 || _index > SDL_CDNumDrives ())
    {
        PyErr_SetString (PyExc_ValueError, "invalid cdrom drive index");
        return -1;
    }
    cd = SDL_CDOpen (_index);
    if (!cd)
    {
        PyErr_SetString (PyExc_PyGameError, SDL_GetError ());
        return -1;
    }

    ((PyCD*)self)->cd = cd;
    ((PyCD*)self)->index = _index;
    cdrommod_add_drive (_index, cd);

    return 0;
}
Esempio n. 5
0
static int modcd_getinfo( INSTANCE * my, int * params )
{
    int i, total = 0;
    char * trackinfo;

    if ( params[0] < 0 || params[0] >= SDL_CDNumDrives() ) return 0;

    if ( sdl_cd == NULL || sdl_cdnum != params[0] )
    {
        if ( sdl_cd ) SDL_CDClose( sdl_cd );
        sdl_cd = SDL_CDOpen( params[0] );
        if ( sdl_cd == NULL ) return 0;
        sdl_cdnum = params[0];
    }

    GLODWORD( mod_cd, CD_TRACKS ) = sdl_cd->numtracks;
    GLODWORD( mod_cd, CD_TRACK )  = sdl_cd->cur_track;
    FRAMES_TO_MSF( sdl_cd->cur_frame, &GLODWORD( mod_cd, CD_MINUTE ), &GLODWORD( mod_cd, CD_SECOND ), &GLODWORD( mod_cd, CD_SUBFRAME ) );

    trackinfo = ( char * ) & GLODWORD( mod_cd, CD_TRACKINFO );

    for ( i = 0; i < sdl_cd->numtracks ; i++, trackinfo += 16 )
    {
        total += sdl_cd->track[i].length;
        *( Uint32 * ) trackinfo = ( sdl_cd->track[i].type == SDL_AUDIO_TRACK );
        FRAMES_TO_MSF( sdl_cd->track[i].length, trackinfo + 4, trackinfo + 8, trackinfo + 12 );
    }
    FRAMES_TO_MSF( total, &GLODWORD( mod_cd, CD_MINUTES ), &GLODWORD( mod_cd, CD_SECONDS ), &GLODWORD( mod_cd, CD_FRAMES ) );
    return 1;
}
Esempio n. 6
0
int CDAudio_Init()
{
	if((cls.state == ca_dedicated) || COM_CheckParm("-nocdaudio"))
		return -1;
		
	cd_id = SDL_CDOpen(0);
	if(!cd_id)
	{
		Con_Printf("CDAudio_Init: Unable to open default CD-ROM drive: %s\n",
			SDL_GetError());
		return -1;
	}
	
	initialized = true;
	enabled = true;
	cdValid = true;
	
	if(!CD_INDRIVE(SDL_CDStatus(cd_id)))
	{
		Con_Printf("CDAudio_Init: No CD in drive.\n");
		cdValid = false;
	}
	if(!cd_id->numtracks)
	{
		Con_Printf("CDAudio_Init: CD contains no audio tracks.\n");
		cdValid = false;
	}
	Cmd_AddCommand("cd",CD_f);
	Con_Printf("CD Audio Initialized.\n");
	return 0;
}
Esempio n. 7
0
File: rbaudio.c Progetto: btb/d2x
void RBAInit()
{
	if (initialised) return;
	if (FindArg("-nocdrom")) return; 

	if (SDL_Init(SDL_INIT_CDROM) < 0)
	{
		Warning("SDL library initialisation failed: %s.",SDL_GetError());
		return;
	}

	if (SDL_CDNumDrives() == 0)
	{
		Warning("No cdrom drives found!\n");
		return;
	}
	s_cd = SDL_CDOpen(0);
	if (s_cd == NULL) {
		Warning("Could not open cdrom for redbook audio!\n");
		return;
	}

	SDL_CDStatus(s_cd); /* update the drive status */

	atexit(RBAExit);
	initialised = 1;
}
Esempio n. 8
0
void RBAInit()
{
	int num_cds;
	int i,j;
	
	if (initialised) return;

	if (SDL_Init(SDL_INIT_CDROM) < 0)
	{
		Warning("SDL library initialisation failed: %s.",SDL_GetError());
		return;
	}

	num_cds = SDL_CDNumDrives();
	if (num_cds < 1)
	{
		con_printf(CON_NORMAL, "No cdrom drives found!\n");
#if defined(__APPLE__) || defined(macintosh)
		SDL_QuitSubSystem(SDL_INIT_CDROM);	// necessary for rescanning CDROMs
#endif
		return;
	}
	
	for (i = 0; i < num_cds; i++)
	{
		if (s_cd)
			SDL_CDClose(s_cd);
		s_cd = SDL_CDOpen(i);
		
		if (s_cd && CD_INDRIVE(SDL_CDStatus(s_cd)))
		{
			for (j = 0; j < s_cd->numtracks; j++)
			{
				if (s_cd->track[j].type == SDL_AUDIO_TRACK)
					break;
			}
			
			if (j != s_cd->numtracks)
				break;	// we've found an audio CD
		}
		else if (s_cd == NULL)
			Warning("Could not open cdrom %i for redbook audio:%s\n", i, SDL_GetError());
	}
	
	if (i == num_cds)
	{
		con_printf(CON_NORMAL, "No audio CDs found\n");
		if (s_cd)	// if there's no audio CD, say that there's no redbook and hence play MIDI instead
		{
			SDL_CDClose(s_cd);
			s_cd = NULL;
		}
#if defined(__APPLE__) || defined(macintosh)
		SDL_QuitSubSystem(SDL_INIT_CDROM);	// necessary for rescanning CDROMs
#endif
		return;
	}
	
	initialised = 1;
}
Esempio n. 9
0
int main(int argc, char **argv)
{
	SDL_Init(SDL_INIT_CDROM);
	atexit(SDL_Quit);

	int ndrives = SDL_CDNumDrives();
	if (ndrives == 0) {
		printf("Alas, no CD drives.\n");
	}
	int drive_no;
	for (drive_no = 0; drive_no < ndrives; drive_no++) {
		SDL_CD *drive = SDL_CDOpen(drive_no);
		if (drive == NULL) {
			printf("Couldn't get drive %d.\n", drive_no);
			continue;
		}
		if (SDL_CDEject(drive)) {
			printf("Couldn't eject drive %d.\n", drive_no);
		} else {
			printf("Ping! (%d of %d)\n", drive_no + 1, ndrives);
		}
		SDL_CDClose(drive);
	}
	printf("Ejected everything.\n");
	return 0;
}
Esempio n. 10
0
int CDAudio_SysStartup (void)
{
	int i;
	int numdrives;

	numdrives = SDL_CDNumDrives();
	if( numdrives == -1 ) // was the CDROM system initialized correctly?
		return -1;

	Con_Printf( "Found %i cdrom drives.\n", numdrives );

	for( i = 0 ; i < numdrives ; i++, cd = NULL ) {
		cd = SDL_CDOpen( i );
		if( !cd ) {
			Con_Printf( "CD drive %i is invalid.\n", i );
			continue;
		}

		if( CD_INDRIVE( SDL_CDStatus( cd ) ) )
			if( IsAudioCD() )
				break;
			else
				Con_Printf( "The CD in drive %i is not an audio cd.\n", i );
		else
			Con_Printf( "No CD in drive %i.\n", i );

		SDL_CDClose( cd );
	}

	if( i == numdrives && !cd )
		return -1;

	return 0;
}
Esempio n. 11
0
bool CDROM_Interface_SDL::StopAudio(void) {
    // Has to be there, otherwise wrong cd status report (dunno why, sdl bug ?)
    SDL_CDClose(cd);
    cd = SDL_CDOpen(driveID);
    bool success = (SDL_CDStop(cd)==0);
    return success;
}
Esempio n. 12
0
bool SDL::ejectCDTray()
{
    SDL_CD* cdrom;

    if (SDL_CDNumDrives() <= 0)
    {
        Log::warning("SDL_CDNumDrives: No CD-ROM drives available");
        return false;
    }

    // The system's default CD-ROM is always drive 0
    cdrom = SDL_CDOpen(0);
    if (!cdrom)
    {
        Log::warning("SDL_CDOpen: Couldn't open default CD-ROM: " +
                     std::string(SDL_GetError()));
        return false;
    }

    if (SDL_CDEject(cdrom) == -1)
    {
        SDL_CDClose(cdrom);
        return false;
    }
    else
    {
        SDL_CDClose(cdrom);
        return true;
    }
}
Esempio n. 13
0
bool CDROM_Interface_SDL::PlayAudioSector(unsigned long start,unsigned long len) {
    // Has to be there, otherwise wrong cd status report (dunno why, sdl bug ?)
    SDL_CDClose(cd);
    cd = SDL_CDOpen(driveID);
    bool success = (SDL_CDPlay(cd,start+150,len)==0);
    return success;
}
Esempio n. 14
0
void CDAudio_SDL_CDDrive_f( void )
{
	int i;
	int numdrives = SDL_CDNumDrives();

	if( Cmd_Argc() != 2 ) {
		Con_Print( "cddrive <drivenr>\n" );
		return;
	}

	i = atoi( Cmd_Argv( 1 ) );
	if( i >= numdrives ) {
		Con_Printf("Only %i drives!\n", numdrives );
		return;
	}

	if( cd )
		SDL_CDClose( cd );

	cd = SDL_CDOpen( i );
	if( !cd ) {
		Con_Printf( "Couldn't open drive %i.\n", i );
		return;
	}

	if( !CD_INDRIVE( SDL_CDStatus( cd ) ) )
		Con_Printf( "No cd in drive %i.\n", i );
	else if( !IsAudioCD() )
		Con_Printf( "The CD in drive %i is not an audio CD.\n", i );

	ValidateDrive();
}
Esempio n. 15
0
	Cdrom::Cdrom(int index) :
		shared_ptr_base<SDL_CD>(SDL_CDOpen(index), SDL_CDClose)
	{
		if (p.get() == 0) {
			throw runtime_error(string()
					+ "SDL_CDOpen returned NULL: "
					+ SDL_GetError());
		}
	}
Esempio n. 16
0
void I_InitCD()
{
  int i;
  const char *cdName;
    
  // Don't start music on a dedicated server
  if (M_CheckParm("-dedicated"))
    return ;
    
  // Has been checked in d_main.c, but doesn't hurt here
  if (M_CheckParm("-nocd"))
    return ;
    
  CONS_Printf(" Initializing CD audio...\n");

  // Initialize SDL first
  if (SDL_Init(SDL_INIT_CDROM) < 0) {
    CONS_Printf(" Couldn't initialize SDL CD: %s\n", SDL_GetError());
    return;
  }

  // Open drive
  cdrom = SDL_CDOpen(0);
  cdName = SDL_CDName(0);
    
  if (cdrom == NULL) {
    if (cdName == NULL)
      {
	    
	CONS_Printf(" Couldn't open default CD-ROM drive: %s\n",
		    SDL_GetError());
      }
    else
      {
	CONS_Printf(" Couldn't open default CD-ROM drive %s: %s\n",
		    cdName, SDL_GetError());
      }
	
    return;
  }
    
  for (i = 0; i < MAX_CD_TRACKS; i++)
    cdRemap[i] = i;
    
  initialized = true;
  enabled = true;

  CDAudio_GetAudioDiskInfo();

  COM.AddCommand("cd", Command_Cd_f);
    
  CONS_Printf(" CD audio initialized.\n");
    
  return ;
}
Esempio n. 17
0
int CDAudio_Init()
{
	cvar_t *cv;

	if (initialized)
		return 0;

	cv = Cvar_Get ("nocdaudio", "0", CVAR_NOSET);
	if (cv->value)
		return -1;

	cd_nocd = Cvar_Get ("cd_nocd", "0", CVAR_ARCHIVE );
	if ( cd_nocd->value)
		return -1;

	cd_volume = Cvar_Get ("cd_volume", "1", CVAR_ARCHIVE);

	if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
		if (SDL_Init(SDL_INIT_CDROM) < 0) {
			Com_Printf ("Couldn't init SDL cdrom: %s\n", SDL_GetError ());
			return -1;
		}
	} else if (SDL_WasInit(SDL_INIT_CDROM) == 0) {
		if (SDL_InitSubSystem(SDL_INIT_CDROM) < 0) {
			Com_Printf ("Couldn't init SDL cdrom: %s\n", SDL_GetError ());
			return -1;
		}
	}
	
	cd_id = SDL_CDOpen(0);
	if(!cd_id)
	{
		Com_Printf("CDAudio_Init: Unable to open default CD-ROM drive: %s\n",
			SDL_GetError());
		return -1;
	}
	
	initialized = true;
	enabled = true;
	cdValid = true;
	
	if(!CD_INDRIVE(SDL_CDStatus(cd_id)))
	{
		Com_Printf("CDAudio_Init: No CD in drive.\n");
		cdValid = false;
	}
	if(!cd_id->numtracks)
	{
		Com_Printf("CDAudio_Init: CD contains no audio tracks.\n");
		cdValid = false;
	}
	Cmd_AddCommand("cd",CD_f);
	Com_Printf("CD Audio Initialized.\n");
	return 0;
}
Esempio n. 18
0
/**************************************************************************
 *
 * function: InitCD
 *
 * description:
 * Initialize the first CD drive SDL detects and add console command 'cd'
 *
 **************************************************************************/
void I_InitCD (void)
{
#ifndef NOSDLCD
	INT32 i;

	// Has been checked in d_main.c, but doesn't hurt here
	if (M_CheckParm ("-nocd"))
		return;

	CONS_Printf("I_InitCD: Init CD audio\n");

	// Initialize SDL first
	if (SDL_InitSubSystem(SDL_INIT_CDROM) < 0)
	{
		CONS_Printf("Couldn't initialize SDL CDROM: %s\n",SDL_GetError());
		return;
	}

	// Open drive
	cdrom = SDL_CDOpen(0);

	if (!cdrom)
	{
		const char *cdName = SDL_CDName(0);
		if (!cdName)
		{

			CONS_Printf("Couldn't open default CD-ROM drive: %s\n",
				SDL_GetError());
		}
		else
		{
			CONS_Printf("Couldn't open default CD-ROM drive %s: %s\n",
				cdName, SDL_GetError());
		}
		//return;
	}

	for (i = 0; i < MAX_CD_TRACKS; i++)
		cdRemap[i] = (Uint8)i;

	cdaudio_started = true;
	if (cdrom) cdEnabled = true;

	if (CDAudio_GetAudioDiskInfo()==-1)
	{
		CONS_Printf("I_InitCD: No CD in player.\n");
		cdValid = SDL_FALSE;
	}

	COM_AddCommand ("cd", Command_Cd_f);

	CONS_Printf("CD audio Initialized\n");
#endif
}
Esempio n. 19
0
bool CDROM_Interface_SDL::SetDevice(char* path, int forceCD) { 
	char buffer[512];
	strcpy(buffer,path);
	upcase(buffer);

	int num = SDL_CDNumDrives();
	if ((forceCD>=0) && (forceCD<num)) {
		driveID = forceCD;
			//--Added 2009-12-31 by Alun Bestor: shut down and restart the CDROM subsystem to reset SDL's
			//cached file information about the CD-ROM volumes
			//This is needed otherwise SDL persists invalid file pointers to the CD-ROM and its tracks,
			//way to go guys
			SDL_QuitSubSystem(SDL_INIT_CDROM);
			SDL_Init(SDL_INIT_CDROM);
			//--End of modifications
		
	        cd = SDL_CDOpen(driveID);
	        SDL_CDStatus(cd);
	   	return true;
	};	
	
	const char* cdname = 0;
	for (int i=0; i<num; i++) {
		cdname = SDL_CDName(i);
		if (strcmp(buffer,cdname)==0) {
			//--Added 2009-12-31 by Alun Bestor: shut down and restart the CDROM subsystem to reset SDL's
			//cached file information about the CD-ROM volumes
			//This is needed otherwise SDL persists invalid file pointers to the CD-ROM and its tracks,
			//way to go guys
			SDL_QuitSubSystem(SDL_INIT_CDROM);
			SDL_Init(SDL_INIT_CDROM);
			//--End of modifications
			
			cd = SDL_CDOpen(i);
			SDL_CDStatus(cd);
			driveID = i;
			return true;
		};
	};
	return false; 
}
Esempio n. 20
0
static int modcd_status( INSTANCE * my, int * params )
{
    if ( params[0] < 0 || params[0] >= SDL_CDNumDrives() ) return 0;

    if ( sdl_cd == NULL || sdl_cdnum != params[0] )
    {
        if ( sdl_cd ) SDL_CDClose( sdl_cd );
        sdl_cd = SDL_CDOpen( params[0] );
        if ( sdl_cd == NULL ) return 0;
        sdl_cdnum = params[0];
    }

    return SDL_CDStatus( sdl_cd );
}
Esempio n. 21
0
static PyObject*
cd_init (PyObject* self)
{
    int cd_id = PyCD_AsID (self);

    CDROM_INIT_CHECK ();
    if (!cdrom_drivedata[cd_id]) {
        cdrom_drivedata[cd_id] = SDL_CDOpen (cd_id);
        if (!cdrom_drivedata[cd_id]) {
            return RAISE (PyExc_SDLError, "Cannot initialize device");
        }
    }
    Py_RETURN_NONE;
}
Esempio n. 22
0
int I_CDMusInit(void)
{
    int drive_num = 0;

    // The initialize function is re-invoked when the CD track play cheat
    // is used, so use the opportunity to call SDL_CDStatus() to update
    // the status of the drive.

    if (cd_handle == NULL)
    {
        if (SDL_Init(SDL_INIT_CDROM) < 0)
        {
            startup_error = "Failed to init CD subsystem.";
            cd_Error = 1;
            return -1;
        }

        // TODO: config variable to control CDROM to use.

        cd_handle = SDL_CDOpen(drive_num);

        if (cd_handle == NULL)
        {
            startup_error = "Failed to open CD-ROM drive.";
            cd_Error = 1;
            return -1;
        }

        cd_name = SDL_CDName(drive_num);
    }

    if (SDL_CDStatus(cd_handle) == CD_ERROR)
    {
        startup_error = "Failed to read CD status.";
        cd_Error = 1;
        return -1;
    }

    if (!CD_INDRIVE(cd_handle->status))
    {
        startup_error = "No CD in drive.";
        cd_Error = 1;
        return -1;
    }

    cd_Error = 0;

    return 0;
}
Esempio n. 23
0
void SoundManager::InitRedbook()
{
#if defined(USE_SDL)
    if (!m_cdrom) {
        int errcode = SDL_Init(SDL_INIT_CDROM | m_SDLInitFlags);

        Assert(0 == errcode);
        if (errcode < 0) {
            return;
        }

        int numDrives = SDL_CDNumDrives();
        Assert(numDrives >= 0);

        int drive = -1;
        int i = 0;
        // Hack: We don't have the num of the SDL drive stored,
        //       so we search for the drive with the drive letter stored
        MBCHAR driveLetter = toupper(c3files_GetCtpCdId());
        while ((i < numDrives) && (-1 == drive)) {
            const char *cd_name = SDL_CDName(i);
            if (cd_name) {
                if (toupper(cd_name[0]) == driveLetter) {
                    drive = i;
                }
            }
            i++;
        }

        // No drive match?!
        if (drive < 0) {
            return;
        }
        m_cdrom = SDL_CDOpen(drive);
        Assert(m_cdrom != 0);
        // No control structur?
        if (m_cdrom) 
        {
            CDstatus status = SDL_CDStatus(m_cdrom);
        }
    }
#else // !USE_SDL
	if (!m_redbook) 
	{
		m_redbook = AIL_redbook_open_drive(c3files_GetCtpCdId());
	}
#endif // USE_SDL
}
Esempio n. 24
0
bool OSystem_SDL::openCD(int drive) {
	if (SDL_InitSubSystem(SDL_INIT_CDROM) == -1)
		_cdrom = NULL;
	else {
		_cdrom = SDL_CDOpen(drive);
		// Did it open? Check if _cdrom is NULL
		if (!_cdrom) {
			warning("Couldn't open drive: %s", SDL_GetError());
		} else {
			_cdNumLoops = 0;
			_cdStopTime = 0;
			_cdEndTime = 0;
		}
	}

	return (_cdrom != NULL);
}
Esempio n. 25
0
static int modcd_playtracks( INSTANCE * my, int * params )
{
    if ( params[0] < 0 || params[0] >= SDL_CDNumDrives() ) return 0;

    if ( sdl_cd == NULL || sdl_cdnum != params[0] )
    {
        if ( sdl_cd ) SDL_CDClose( sdl_cd );
        sdl_cd = SDL_CDOpen( params[0] );
        if ( sdl_cd == NULL ) return 0;
        sdl_cdnum = params[0];
    }

    if ( CD_INDRIVE( SDL_CDStatus( sdl_cd ) ) )
        return !SDL_CDPlayTracks( sdl_cd, params[1], 0, params[2], 0 );

    return 0;
}
Esempio n. 26
0
void RBAInit()
{
	int	d, i, j;
	char	szDrive [FILENAME_LEN], sz [FILENAME_LEN];
	
if (initialised) 
	return;
if (FindArg("-nocdrom")) 
	return; 

if (SDL_Init(SDL_INIT_CDROM) < 0) {
	Warning(TXT_SDL_INIT_LIB,SDL_GetError());
	return;
	}

if ((j = SDL_CDNumDrives()) == 0) {
	Warning(TXT_CDROM_NONE);
	return;
	}

d = 0;
if ((i = FindArg ("-cdrom")) && *Args [++i]) {
#ifdef _WIN32
	sprintf (szDrive, "%c:\\", *Args [i]);
#else
	strncpy (szDrive, Args [i], sizeof (szDrive));
#endif
	strlwr (szDrive);
	for (i = 0; i < j; i++) {
		strcpy (sz, SDL_CDName (i));
		strlwr (sz);
		if (!strcmp (szDrive, sz)) {
			d = i;
			break;
			}
		}
	}

if (!(s_cd = SDL_CDOpen(d))) {
	Warning(TXT_CDROM_OPEN);
	return;
	}
atexit(RBAExit);
initialised = 1;
}
Esempio n. 27
0
void cd_init()
{
 int i;
  if ((nocdaudio=FindArg("-nocdaudio"))) {
    if (Inferno_verbose) printf( "cd audio disabled.\n");
  } else {
#ifdef __DJGPP__
    bcd_open();
#elif defined __SDL__
    if( SDL_Init(SDL_INIT_CDROM) >= 0 )
     {
      atexit(SDL_Quit);
      cdrom=SDL_CDOpen(0);
     }
#endif
    cd_playlist_reset();
     if((i=FindArg("-cdplaylist")))
      cd_playlist_set(Args[i+1]);
  }
}
Esempio n. 28
0
//------------------------------------------------------------------------------
bool UnixRedBookDevice::open()
{
#if !defined(__FreeBSD__)
    if(mAcquired)
    {
       setLastError("Device is already open.");
       return(false);
    }

    // open the device
    mCD = SDL_CDOpen(mDeviceId);
    if (mCD == NULL)
    {
       setLastError(SDL_GetError());
       return false;
    }

    mAcquired = true;

    openVolume();
    setLastError("");
    return(true);
#endif	// !defined(__FreeBSD__)
}
Esempio n. 29
0
int main(int argc, char *argv[])
{
	int drive;
	int i;
	SDL_CD *cdrom;

	/* Initialize SDL first */
	if ( SDL_Init(SDL_INIT_CDROM) < 0 ) {
		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
		return(1);
	}

	/* Find out how many CD-ROM drives are connected to the system */
	if ( SDL_CDNumDrives() == 0 ) {
		printf("No CD-ROM devices detected\n");
		quit(0);
	}
	printf("Drives available: %d\n", SDL_CDNumDrives());
	for ( i=0; i<SDL_CDNumDrives(); ++i ) {
		printf("Drive %d:  \"%s\"\n", i, SDL_CDName(i));
	}

	/* Open the CD-ROM */
	drive = 0;
	i=1;
	if ( argv[i] && isdigit(argv[i][0]) ) {
		drive = atoi(argv[i++]);
	}
	cdrom = SDL_CDOpen(drive);
	if ( cdrom == NULL ) {
		fprintf(stderr, "Couldn't open drive %d: %s\n", drive,
							SDL_GetError());
		quit(2);
	}
#ifdef TEST_NULLCD
	cdrom = NULL;
#endif
	
	/* Find out which function to perform */
	for ( ; argv[i]; ++i ) {
		if ( strcmp(argv[i], "-status") == 0 ) {
			/* PrintStatus(drive, cdrom); */
		} else
		if ( strcmp(argv[i], "-list") == 0 ) {
			ListTracks(cdrom);
		} else
		if ( strcmp(argv[i], "-play") == 0 ) {
			int strack, sframe;
			int ntrack, nframe;

			strack = 0;
			if ( argv[i+1] && isdigit(argv[i+1][0]) ) {
				strack = atoi(argv[++i]);
			}
			sframe = 0;
			if ( argv[i+1] && isdigit(argv[i+1][0]) ) {
				sframe = atoi(argv[++i]);
			}
			ntrack = 0;
			if ( argv[i+1] && isdigit(argv[i+1][0]) ) {
				ntrack = atoi(argv[++i]);
			}
			nframe = 0;
			if ( argv[i+1] && isdigit(argv[i+1][0]) ) {
				nframe = atoi(argv[++i]);
			}
			if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) {
				if ( SDL_CDPlayTracks(cdrom, strack, sframe,
							ntrack, nframe) < 0 ) {
					fprintf(stderr,
			"Couldn't play tracks %d/%d for %d/%d: %s\n",
				strack, sframe, ntrack, nframe, SDL_GetError());
				}
			} else {
				fprintf(stderr, "No CD in drive!\n");
			}
		} else
		if ( strcmp(argv[i], "-pause") == 0 ) {
			if ( SDL_CDPause(cdrom) < 0 ) {
				fprintf(stderr, "Couldn't pause CD: %s\n",
								SDL_GetError());
			}
		} else
		if ( strcmp(argv[i], "-resume") == 0 ) {
			if ( SDL_CDResume(cdrom) < 0 ) {
				fprintf(stderr, "Couldn't resume CD: %s\n",
								SDL_GetError());
			}
		} else
		if ( strcmp(argv[i], "-stop") == 0 ) {
			if ( SDL_CDStop(cdrom) < 0 ) {
				fprintf(stderr, "Couldn't eject CD: %s\n",
								SDL_GetError());
			}
		} else
		if ( strcmp(argv[i], "-eject") == 0 ) {
			if ( SDL_CDEject(cdrom) < 0 ) {
				fprintf(stderr, "Couldn't eject CD: %s\n",
								SDL_GetError());
			}
		} else
		if ( (strcmp(argv[i], "-sleep") == 0) &&
				(argv[i+1] && isdigit(argv[i+1][0])) ) {
			SDL_Delay(atoi(argv[++i]));
			printf("Delayed %d milliseconds\n", atoi(argv[i]));
		} else {
			PrintUsage(argv[0]);
			SDL_CDClose(cdrom);
			quit(1);
		}
	}
	PrintStatus(drive, cdrom);
	SDL_CDClose(cdrom);
	SDL_Quit();

	return(0);
}
Esempio n. 30
0
int CDAudio_Init(void)
{
	int	i, x, sdl_num_drives;

	if (safemode || COM_CheckParm("-nocdaudio"))
		return -1;

	if (SDL_InitSubSystem(SDL_INIT_CDROM) < 0)
	{
		Con_Printf("Couldn't init SDL cdrom: %s\n", SDL_GetError());
		return -1;
	}

	sdl_num_drives = SDL_CDNumDrives ();
	Con_Printf ("SDL detected %d CD-ROM drive%c\n", sdl_num_drives,
					sdl_num_drives == 1 ? ' ' : 's');

	if (sdl_num_drives < 1)
		return -1;

	if ((i = COM_CheckParm("-cddev")) != 0 && i < com_argc - 1)
	{
		for (x = 0; x < sdl_num_drives; x++)
		{
			if (!q_strcasecmp(SDL_CDName(x), com_argv[i+1]))
			{
				cd_dev = x;
				break;
			}
		}
		if (cd_dev == -1)
		{
			Con_Printf("SDL couldn't find cdrom device %s\n", com_argv[i+1]);
			return -1;
		}
	}

	if (cd_dev == -1)
		cd_dev = 0;	// default drive

	cd_handle = SDL_CDOpen(cd_dev);
	if (!cd_handle)
	{
		Con_Printf ("%s: Unable to open CD-ROM drive %s (%s)\n",
				__thisfunc__, SDL_CDName(cd_dev), SDL_GetError());
		return -1;
	}

	for (i = 0; i < 100; i++)
		remap[i] = i;
	enabled = true;
	old_cdvolume = bgmvolume.value;

	Con_Printf("CDAudio initialized (SDL, using %s)\n", SDL_CDName(cd_dev));

	if (CDAudio_GetAudioDiskInfo())
	{
		Con_Printf("%s: No CD in drive\n", __thisfunc__);
		cdValid = false;
	}

	Cmd_AddCommand ("cd", CD_f);

// cd hardware volume: no SDL support at present.
	hw_vol_works = CD_GetVolume (NULL);
	if (hw_vol_works)
		hw_vol_works = CDAudio_SetVolume (&bgmvolume);

	return 0;
}