2004-09-06 11:14:40 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the included (GNU.txt) GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
// Quake is a trademark of Id Software, Inc., (c) 1996 Id Software, Inc. All
|
|
|
|
// rights reserved.
|
|
|
|
|
2005-02-28 07:16:19 +00:00
|
|
|
#include "quakedef.h"
|
|
|
|
|
2017-02-21 23:26:13 +00:00
|
|
|
#ifndef HAVE_CDPLAYER
|
|
|
|
//nothing
|
|
|
|
#elif defined(__CYGWIN__)
|
2004-09-06 11:14:40 +00:00
|
|
|
#include "cd_null.c"
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <linux/cdrom.h>
|
|
|
|
|
|
|
|
static int cdfile = -1;
|
|
|
|
static char cd_dev[64] = "/dev/cdrom";
|
2013-10-08 16:31:53 +00:00
|
|
|
static qboolean playing;
|
2004-09-06 11:14:40 +00:00
|
|
|
|
2013-10-08 16:17:19 +00:00
|
|
|
void CDAudio_Eject(void)
|
2004-09-06 11:14:40 +00:00
|
|
|
{
|
2013-10-08 14:28:11 +00:00
|
|
|
if (cdfile == -1)
|
2004-09-06 11:14:40 +00:00
|
|
|
return; // no cd init'd
|
|
|
|
|
|
|
|
if ( ioctl(cdfile, CDROMEJECT) == -1 )
|
|
|
|
Con_DPrintf("ioctl cdromeject failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-08 16:17:19 +00:00
|
|
|
void CDAudio_CloseDoor(void)
|
2004-09-06 11:14:40 +00:00
|
|
|
{
|
2013-10-08 14:28:11 +00:00
|
|
|
if (cdfile == -1)
|
2004-09-06 11:14:40 +00:00
|
|
|
return; // no cd init'd
|
|
|
|
|
|
|
|
if ( ioctl(cdfile, CDROMCLOSETRAY) == -1 )
|
|
|
|
Con_DPrintf("ioctl cdromclosetray failed\n");
|
|
|
|
}
|
|
|
|
|
2013-10-08 16:17:19 +00:00
|
|
|
int CDAudio_GetAudioDiskInfo(void)
|
2004-09-06 11:14:40 +00:00
|
|
|
{
|
|
|
|
struct cdrom_tochdr tochdr;
|
|
|
|
|
2013-10-08 14:28:11 +00:00
|
|
|
if (cdfile == -1)
|
|
|
|
return -1;
|
2004-09-06 11:14:40 +00:00
|
|
|
|
|
|
|
if ( ioctl(cdfile, CDROMREADTOCHDR, &tochdr) == -1 )
|
|
|
|
{
|
|
|
|
Con_DPrintf("ioctl cdromreadtochdr failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tochdr.cdth_trk0 < 1)
|
|
|
|
{
|
|
|
|
Con_DPrintf("CDAudio: no music tracks\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-08 14:28:11 +00:00
|
|
|
return tochdr.cdth_trk1;
|
2004-09-06 11:14:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-08 16:29:54 +00:00
|
|
|
void CDAudio_Play(int track)
|
2004-09-06 11:14:40 +00:00
|
|
|
{
|
|
|
|
struct cdrom_tocentry entry;
|
|
|
|
struct cdrom_ti ti;
|
|
|
|
|
2013-10-08 14:28:11 +00:00
|
|
|
if (cdfile == -1)
|
2004-09-06 11:14:40 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// don't try to play a non-audio track
|
|
|
|
entry.cdte_track = track;
|
|
|
|
entry.cdte_format = CDROM_MSF;
|
|
|
|
if ( ioctl(cdfile, CDROMREADTOCENTRY, &entry) == -1 )
|
|
|
|
{
|
|
|
|
Con_DPrintf("ioctl cdromreadtocentry failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (entry.cdte_ctrl == CDROM_DATA_TRACK)
|
|
|
|
{
|
|
|
|
Con_Printf("CDAudio: track %i is not audio\n", track);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ti.cdti_trk0 = track;
|
|
|
|
ti.cdti_trk1 = track;
|
|
|
|
ti.cdti_ind0 = 1;
|
|
|
|
ti.cdti_ind1 = 99;
|
|
|
|
|
|
|
|
if ( ioctl(cdfile, CDROMPLAYTRKIND, &ti) == -1 )
|
|
|
|
{
|
|
|
|
Con_DPrintf("ioctl cdromplaytrkind failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ioctl(cdfile, CDROMRESUME) == -1 )
|
|
|
|
Con_DPrintf("ioctl cdromresume failed\n");
|
|
|
|
|
2013-10-08 16:29:54 +00:00
|
|
|
playing = true;
|
|
|
|
|
2006-05-07 20:57:30 +00:00
|
|
|
if (!bgmvolume.value)
|
2004-09-06 11:14:40 +00:00
|
|
|
CDAudio_Pause ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDAudio_Stop(void)
|
|
|
|
{
|
2013-10-08 14:28:11 +00:00
|
|
|
if (cdfile == -1)
|
2004-09-06 11:14:40 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if ( ioctl(cdfile, CDROMSTOP) == -1 )
|
|
|
|
Con_DPrintf("ioctl cdromstop failed (%d)\n", errno);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDAudio_Pause(void)
|
|
|
|
{
|
2013-10-08 14:28:11 +00:00
|
|
|
if (cdfile == -1)
|
2004-09-06 11:14:40 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if ( ioctl(cdfile, CDROMPAUSE) == -1 )
|
|
|
|
Con_DPrintf("ioctl cdrompause failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDAudio_Resume(void)
|
|
|
|
{
|
2013-10-08 14:28:11 +00:00
|
|
|
if (cdfile == -1)
|
2004-09-06 11:14:40 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if ( ioctl(cdfile, CDROMRESUME) == -1 )
|
|
|
|
Con_DPrintf("ioctl cdromresume failed\n");
|
2006-05-07 20:57:30 +00:00
|
|
|
}
|
|
|
|
|
2004-09-06 11:14:40 +00:00
|
|
|
void CDAudio_Update(void)
|
|
|
|
{
|
|
|
|
struct cdrom_subchnl subchnl;
|
|
|
|
static time_t lastchk;
|
|
|
|
|
2013-10-08 14:28:11 +00:00
|
|
|
if (playing && lastchk < time(NULL))
|
|
|
|
{
|
|
|
|
lastchk = time(NULL) + 2; //two seconds between checks
|
2004-09-06 11:14:40 +00:00
|
|
|
subchnl.cdsc_format = CDROM_MSF;
|
2013-10-08 14:28:11 +00:00
|
|
|
if (ioctl(cdfile, CDROMSUBCHNL, &subchnl) == -1 )
|
|
|
|
{
|
2004-09-06 11:14:40 +00:00
|
|
|
Con_DPrintf("ioctl cdromsubchnl failed\n");
|
|
|
|
playing = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (subchnl.cdsc_audiostatus != CDROM_AUDIO_PLAY &&
|
2013-10-08 14:28:11 +00:00
|
|
|
subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED)
|
|
|
|
{
|
2004-09-06 11:14:40 +00:00
|
|
|
playing = false;
|
2013-10-08 16:21:11 +00:00
|
|
|
Media_EndedTrack();
|
2004-09-06 11:14:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-08 14:28:11 +00:00
|
|
|
qboolean CDAudio_Startup(void)
|
2004-09-06 11:14:40 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2013-10-08 14:28:11 +00:00
|
|
|
if (cdfile != -1)
|
|
|
|
return true;
|
2004-09-06 11:14:40 +00:00
|
|
|
|
2013-10-08 14:28:11 +00:00
|
|
|
if ((i = COM_CheckParm("-cddev")) != 0 && i < com_argc - 1)
|
|
|
|
{
|
2004-09-06 11:14:40 +00:00
|
|
|
Q_strncpyz(cd_dev, com_argv[i + 1], sizeof(cd_dev));
|
|
|
|
cd_dev[sizeof(cd_dev) - 1] = 0;
|
|
|
|
}
|
|
|
|
|
2013-10-08 14:28:11 +00:00
|
|
|
if ((cdfile = open(cd_dev, O_RDONLY)) == -1)
|
|
|
|
{
|
2004-09-06 11:14:40 +00:00
|
|
|
Con_Printf("CDAudio_Init: open of \"%s\" failed (%i)\n", cd_dev, errno);
|
|
|
|
cdfile = -1;
|
2013-10-08 14:28:11 +00:00
|
|
|
return false;
|
2004-09-06 11:14:40 +00:00
|
|
|
}
|
|
|
|
|
2013-10-08 14:28:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
2004-09-06 11:14:40 +00:00
|
|
|
|
2013-10-08 14:28:11 +00:00
|
|
|
void CDAudio_Init(void)
|
|
|
|
{
|
2004-09-06 11:14:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDAudio_Shutdown(void)
|
|
|
|
{
|
2013-10-08 14:28:11 +00:00
|
|
|
if (cdfile == -1)
|
2004-09-06 11:14:40 +00:00
|
|
|
return;
|
|
|
|
CDAudio_Stop();
|
|
|
|
close(cdfile);
|
|
|
|
cdfile = -1;
|
|
|
|
}
|
|
|
|
#endif
|