Moved CD_f from cd_linux.c and cd_win.c into cd_wrapper.c.

Added support for CDROM on (Free)BSD.
This commit is contained in:
Marcus Sundberg 2000-01-06 02:43:04 +00:00
parent 8e9d7f6b4b
commit 42154bc63f
5 changed files with 274 additions and 297 deletions

View file

@ -620,6 +620,7 @@ void CDAudio_Resume(void)
}
#define CD_f_DEFINED
static void CD_f (void)
{
char *command;

View file

@ -20,6 +20,8 @@ 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.
#include "quakedef.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
@ -31,9 +33,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <time.h>
#include <errno.h>
#include <linux/cdrom.h>
#include "quakedef.h"
#ifdef USE_LINUX_CD
# include <linux/cdrom.h>
#endif
#ifdef USE_BSD_CD
# include <sys/cdio.h>
#endif
static qboolean cdValid = false;
static qboolean playing = false;
@ -49,13 +54,26 @@ static byte maxTrack;
static int cdfile = -1;
static char cd_dev[64] = "/dev/cdrom";
#ifdef USE_BSD_CD
# define CDROMEJECT CDIOEJECT
# define CDROMCLOSETRAY CDIOCLOSE
# define CDROMREADTOCHDR CDIOREADTOCHEADER
# define CDROMREADTOCENTRY CDIOREADTOCENTRY
# define CDROMPLAYTRKIND CDIOCPLAYTRACKS
# define CDROMRESUME CDIOCRESUME
# define CDROMSTOP CDIOCSTOP
# define CDROMPAUSE CDIOCPAUSE
# define CDROMSUBCHNL CDIOCREADSUBCHANNEL
#endif
static void CDAudio_Eject(void)
{
if (cdfile == -1 || !enabled)
return; // no cd init'd
if ( ioctl(cdfile, CDROMEJECT) == -1 )
Con_DPrintf("ioctl cdromeject failed\n");
Con_DPrintf("CD eject ioctl failed\n");
}
@ -65,29 +83,41 @@ static void CDAudio_CloseDoor(void)
return; // no cd init'd
if ( ioctl(cdfile, CDROMCLOSETRAY) == -1 )
Con_DPrintf("ioctl cdromclosetray failed\n");
Con_DPrintf("CD close ioctl failed\n");
}
static int CDAudio_GetAudioDiskInfo(void)
{
#if defined(USE_LINUX_CD)
struct cdrom_tochdr tochdr;
#elif defined(USE_BSD_CD)
struct ioc_toc_header tochdr;
#endif
cdValid = false;
if ( ioctl(cdfile, CDROMREADTOCHDR, &tochdr) == -1 )
{
Con_DPrintf("ioctl cdromreadtochdr failed\n");
Con_DPrintf("CD readtochdr ioctl failed\n");
return -1;
}
#if defined(USE_LINUX_CD)
if (tochdr.cdth_trk0 < 1)
#elif defined(USE_BSD_CD)
if (tochdr.starting_track < 1)
#endif
{
Con_DPrintf("CDAudio: no music tracks\n");
return -1;
}
cdValid = true;
#if defined(USE_LINUX_CD)
maxTrack = tochdr.cdth_trk1;
#elif defined(USE_BSD_CD)
maxTrack = tochdr.ending_track;
#endif
return 0;
}
@ -95,8 +125,13 @@ static int CDAudio_GetAudioDiskInfo(void)
void CDAudio_Play(byte track, qboolean looping)
{
#if defined(USE_LINUX_CD)
struct cdrom_tocentry entry;
struct cdrom_ti ti;
#elif defined(USE_BSD_CD)
struct ioc_read_toc_single_entry entry;
struct ioc_play_track ti;
#endif
if (cdfile == -1 || !enabled)
return;
@ -117,14 +152,24 @@ void CDAudio_Play(byte track, qboolean looping)
}
// don't try to play a non-audio track
#if defined(USE_LINUX_CD)
entry.cdte_track = track;
entry.cdte_format = CDROM_MSF;
#elif defined(USE_BSD_CD)
entry.track = track;
entry.address_format = CD_MSF_FORMAT;
#endif
if ( ioctl(cdfile, CDROMREADTOCENTRY, &entry) == -1 )
{
Con_DPrintf("ioctl cdromreadtocentry failed\n");
return;
}
#if defined(USE_LINUX_CD)
if (entry.cdte_ctrl == CDROM_DATA_TRACK)
#elif defined(USE_BSD_CD)
/* XXX: Is this magic number really necessary? */
if (entry.entry.control & 4)
#endif
{
Con_Printf("CDAudio: track %i is not audio\n", track);
return;
@ -137,19 +182,26 @@ void CDAudio_Play(byte track, qboolean looping)
CDAudio_Stop();
}
#if defined(USE_LINUX_CD)
ti.cdti_trk0 = track;
ti.cdti_trk1 = track;
ti.cdti_ind0 = 1;
ti.cdti_ind1 = 99;
#elif defined(USE_BSD_CD)
ti.start_track = track;
ti.end_track = track;
ti.start_index = 1;
ti.end_index = 99;
#endif
if ( ioctl(cdfile, CDROMPLAYTRKIND, &ti) == -1 )
{
Con_DPrintf("ioctl cdromplaytrkind failed\n");
Con_DPrintf("CD play ioctl failed\n");
return;
}
if ( ioctl(cdfile, CDROMRESUME) == -1 )
Con_DPrintf("ioctl cdromresume failed\n");
Con_DPrintf("CD resume ioctl failed\n");
playLooping = looping;
playTrack = track;
@ -169,7 +221,7 @@ void CDAudio_Stop(void)
return;
if ( ioctl(cdfile, CDROMSTOP) == -1 )
Con_DPrintf("ioctl cdromstop failed (%d)\n", errno);
Con_DPrintf("CD stop ioctl failed (%d)\n", errno);
wasPlaying = false;
playing = false;
@ -184,7 +236,7 @@ void CDAudio_Pause(void)
return;
if ( ioctl(cdfile, CDROMPAUSE) == -1 )
Con_DPrintf("ioctl cdrompause failed\n");
Con_DPrintf("CD pause ioctl failed\n");
wasPlaying = playing;
playing = false;
@ -203,131 +255,18 @@ void CDAudio_Resume(void)
return;
if ( ioctl(cdfile, CDROMRESUME) == -1 )
Con_DPrintf("ioctl cdromresume failed\n");
Con_DPrintf("CD resume ioctl failed\n");
playing = true;
}
static void CD_f (void)
{
char *command;
int ret;
int n;
if (Cmd_Argc() < 2)
return;
command = Cmd_Argv (1);
if (Q_strcasecmp(command, "on") == 0)
{
enabled = true;
return;
}
if (Q_strcasecmp(command, "off") == 0)
{
if (playing)
CDAudio_Stop();
enabled = false;
return;
}
if (Q_strcasecmp(command, "reset") == 0)
{
enabled = true;
if (playing)
CDAudio_Stop();
for (n = 0; n < 100; n++)
remap[n] = n;
CDAudio_GetAudioDiskInfo();
return;
}
if (Q_strcasecmp(command, "remap") == 0)
{
ret = Cmd_Argc() - 2;
if (ret <= 0)
{
for (n = 1; n < 100; n++)
if (remap[n] != n)
Con_Printf(" %u -> %u\n", n, remap[n]);
return;
}
for (n = 1; n <= ret; n++)
remap[n] = Q_atoi(Cmd_Argv (n+1));
return;
}
if (Q_strcasecmp(command, "close") == 0)
{
CDAudio_CloseDoor();
return;
}
if (!cdValid)
{
CDAudio_GetAudioDiskInfo();
if (!cdValid)
{
Con_Printf("No CD in player.\n");
return;
}
}
if (Q_strcasecmp(command, "play") == 0)
{
CDAudio_Play((byte)Q_atoi(Cmd_Argv (2)), false);
return;
}
if (Q_strcasecmp(command, "loop") == 0)
{
CDAudio_Play((byte)Q_atoi(Cmd_Argv (2)), true);
return;
}
if (Q_strcasecmp(command, "stop") == 0)
{
CDAudio_Stop();
return;
}
if (Q_strcasecmp(command, "pause") == 0)
{
CDAudio_Pause();
return;
}
if (Q_strcasecmp(command, "resume") == 0)
{
CDAudio_Resume();
return;
}
if (Q_strcasecmp(command, "eject") == 0)
{
if (playing)
CDAudio_Stop();
CDAudio_Eject();
cdValid = false;
return;
}
if (Q_strcasecmp(command, "info") == 0)
{
Con_Printf("%u tracks\n", maxTrack);
if (playing)
Con_Printf("Currently %s track %u\n", playLooping ? "looping" : "playing", playTrack);
else if (wasPlaying)
Con_Printf("Paused %s track %u\n", playLooping ? "looping" : "playing", playTrack);
Con_Printf("Volume is %f\n", cdvolume);
return;
}
}
void CDAudio_Update(void)
{
#if defined(USE_LINUX_CD)
struct cdrom_subchnl subchnl;
#elif defined(USE_BSD_CD)
struct ioc_read_subchannel subchnl;
#endif
static time_t lastchk;
if (!enabled)
@ -351,14 +290,24 @@ void CDAudio_Update(void)
if (playing && lastchk < time(NULL)) {
lastchk = time(NULL) + 2; //two seconds between chks
#if defined(USE_LINUX_CD)
subchnl.cdsc_format = CDROM_MSF;
#elif defined(USE_BSD_CD)
subchnl.data_format = CD_MSF_FORMAT;
#endif
if (ioctl(cdfile, CDROMSUBCHNL, &subchnl) == -1 ) {
Con_DPrintf("ioctl cdromsubchnl failed\n");
Con_DPrintf("CD subcchannel ioctl failed\n");
playing = false;
return;
}
#if defined(USE_LINUX_CD)
if (subchnl.cdsc_audiostatus != CDROM_AUDIO_PLAY &&
subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED) {
subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED)
#elif defined(USE_BSD_CD)
if (subchnl.data->header.audio_status != CD_AS_PLAY_IN_PROGRESS
&& subchnl.data->header.audio_status != CD_AS_PLAY_PAUSED)
#endif
{
playing = false;
if (playLooping)
CDAudio_Play(playTrack, true);

View file

@ -158,6 +158,8 @@ void CDAudio_Shutdown()
cd_id = NULL;
}
#define CD_f_DEFINED
static void CD_f()
{
char *command;

View file

@ -37,7 +37,6 @@ static qboolean enabled = false;
static qboolean playLooping = false;
static float cdvolume;
static byte remap[100];
static byte cdrom;
static byte playTrack;
static byte maxTrack;
@ -48,7 +47,9 @@ static void CDAudio_Eject(void)
{
DWORD dwReturn;
if (dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, (DWORD)NULL))
dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN,
(DWORD)NULL);
if (dwReturn)
Con_DPrintf("MCI_SET_DOOR_OPEN failed (%i)\n", dwReturn);
}
@ -57,7 +58,9 @@ static void CDAudio_CloseDoor(void)
{
DWORD dwReturn;
if (dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, (DWORD)NULL))
dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED,
(DWORD)NULL);
if (dwReturn)
Con_DPrintf("MCI_SET_DOOR_CLOSED failed (%i)\n", dwReturn);
}
@ -67,11 +70,12 @@ static int CDAudio_GetAudioDiskInfo(void)
DWORD dwReturn;
MCI_STATUS_PARMS mciStatusParms;
cdValid = false;
mciStatusParms.dwItem = MCI_STATUS_READY;
dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
dwReturn = mciSendCommand(wDeviceID, MCI_STATUS,
MCI_STATUS_ITEM | MCI_WAIT,
(DWORD) (LPVOID) &mciStatusParms);
if (dwReturn)
{
Con_DPrintf("CDAudio: drive ready test - get status failed\n");
@ -84,7 +88,9 @@ static int CDAudio_GetAudioDiskInfo(void)
}
mciStatusParms.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
dwReturn = mciSendCommand(wDeviceID, MCI_STATUS,
MCI_STATUS_ITEM | MCI_WAIT,
(DWORD) (LPVOID) &mciStatusParms);
if (dwReturn)
{
Con_DPrintf("CDAudio: get tracks - status failed\n");
@ -130,7 +136,9 @@ void CDAudio_Play(byte track, qboolean looping)
// don't try to play a non-audio track
mciStatusParms.dwItem = MCI_CDA_STATUS_TYPE_TRACK;
mciStatusParms.dwTrack = track;
dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
dwReturn = mciSendCommand(wDeviceID, MCI_STATUS,
MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT,
(DWORD) (LPVOID) &mciStatusParms);
if (dwReturn)
{
Con_DPrintf("MCI_STATUS failed (%i)\n", dwReturn);
@ -145,7 +153,9 @@ void CDAudio_Play(byte track, qboolean looping)
// get the length of the track to be played
mciStatusParms.dwItem = MCI_STATUS_LENGTH;
mciStatusParms.dwTrack = track;
dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT, (DWORD) (LPVOID) &mciStatusParms);
dwReturn = mciSendCommand(wDeviceID, MCI_STATUS,
MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT,
(DWORD) (LPVOID) &mciStatusParms);
if (dwReturn)
{
Con_DPrintf("MCI_STATUS failed (%i)\n", dwReturn);
@ -162,7 +172,9 @@ void CDAudio_Play(byte track, qboolean looping)
mciPlayParms.dwFrom = MCI_MAKE_TMSF(track, 0, 0, 0);
mciPlayParms.dwTo = (mciStatusParms.dwReturn << 8) | track;
mciPlayParms.dwCallback = (DWORD)mainwindow;
dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_NOTIFY | MCI_FROM | MCI_TO, (DWORD)(LPVOID) &mciPlayParms);
dwReturn = mciSendCommand(wDeviceID, MCI_PLAY,
MCI_NOTIFY | MCI_FROM | MCI_TO,
(DWORD)(LPVOID) &mciPlayParms);
if (dwReturn)
{
Con_DPrintf("CDAudio: MCI_PLAY failed (%i)\n", dwReturn);
@ -188,7 +200,8 @@ void CDAudio_Stop(void)
if (!playing)
return;
if (dwReturn = mciSendCommand(wDeviceID, MCI_STOP, 0, (DWORD)NULL))
dwReturn = mciSendCommand(wDeviceID, MCI_STOP, 0, (DWORD)NULL);
if (dwReturn)
Con_DPrintf("MCI_STOP failed (%i)", dwReturn);
wasPlaying = false;
@ -208,7 +221,9 @@ void CDAudio_Pause(void)
return;
mciGenericParms.dwCallback = (DWORD)mainwindow;
if (dwReturn = mciSendCommand(wDeviceID, MCI_PAUSE, 0, (DWORD)(LPVOID) &mciGenericParms))
dwReturn = mciSendCommand(wDeviceID, MCI_PAUSE, 0,
(DWORD)(LPVOID) &mciGenericParms);
if (dwReturn)
Con_DPrintf("MCI_PAUSE failed (%i)", dwReturn);
wasPlaying = playing;
@ -233,7 +248,8 @@ void CDAudio_Resume(void)
mciPlayParms.dwFrom = MCI_MAKE_TMSF(playTrack, 0, 0, 0);
mciPlayParms.dwTo = MCI_MAKE_TMSF(playTrack + 1, 0, 0, 0);
mciPlayParms.dwCallback = (DWORD)mainwindow;
dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_TO | MCI_NOTIFY, (DWORD)(LPVOID) &mciPlayParms);
dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_TO | MCI_NOTIFY,
(DWORD)(LPVOID) &mciPlayParms);
if (dwReturn)
{
Con_DPrintf("CDAudio: MCI_PLAY failed (%i)\n", dwReturn);
@ -243,126 +259,6 @@ void CDAudio_Resume(void)
}
static void CD_f (void)
{
char *command;
int ret;
int n;
int startAddress;
if (Cmd_Argc() < 2)
return;
command = Cmd_Argv (1);
if (Q_strcasecmp(command, "on") == 0)
{
enabled = true;
return;
}
if (Q_strcasecmp(command, "off") == 0)
{
if (playing)
CDAudio_Stop();
enabled = false;
return;
}
if (Q_strcasecmp(command, "reset") == 0)
{
enabled = true;
if (playing)
CDAudio_Stop();
for (n = 0; n < 100; n++)
remap[n] = n;
CDAudio_GetAudioDiskInfo();
return;
}
if (Q_strcasecmp(command, "remap") == 0)
{
ret = Cmd_Argc() - 2;
if (ret <= 0)
{
for (n = 1; n < 100; n++)
if (remap[n] != n)
Con_Printf(" %u -> %u\n", n, remap[n]);
return;
}
for (n = 1; n <= ret; n++)
remap[n] = Q_atoi(Cmd_Argv (n+1));
return;
}
if (Q_strcasecmp(command, "close") == 0)
{
CDAudio_CloseDoor();
return;
}
if (!cdValid)
{
CDAudio_GetAudioDiskInfo();
if (!cdValid)
{
Con_Printf("No CD in player.\n");
return;
}
}
if (Q_strcasecmp(command, "play") == 0)
{
CDAudio_Play((byte)Q_atoi(Cmd_Argv (2)), false);
return;
}
if (Q_strcasecmp(command, "loop") == 0)
{
CDAudio_Play((byte)Q_atoi(Cmd_Argv (2)), true);
return;
}
if (Q_strcasecmp(command, "stop") == 0)
{
CDAudio_Stop();
return;
}
if (Q_strcasecmp(command, "pause") == 0)
{
CDAudio_Pause();
return;
}
if (Q_strcasecmp(command, "resume") == 0)
{
CDAudio_Resume();
return;
}
if (Q_strcasecmp(command, "eject") == 0)
{
if (playing)
CDAudio_Stop();
CDAudio_Eject();
cdValid = false;
return;
}
if (Q_strcasecmp(command, "info") == 0)
{
Con_Printf("%u tracks\n", maxTrack);
if (playing)
Con_Printf("Currently %s track %u\n", playLooping ? "looping" : "playing", playTrack);
else if (wasPlaying)
Con_Printf("Paused %s track %u\n", playLooping ? "looping" : "playing", playTrack);
Con_Printf("Volume is %f\n", cdvolume);
return;
}
}
LONG CDAudio_MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (lParam != wDeviceID)
@ -437,7 +333,10 @@ int CDAudio_Init(void)
return -1;
mciOpenParms.lpstrDeviceType = "cdaudio";
if (dwReturn = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_SHAREABLE, (DWORD) (LPVOID) &mciOpenParms))
dwReturn = mciSendCommand(0, MCI_OPEN,
MCI_OPEN_TYPE | MCI_OPEN_SHAREABLE,
(DWORD) (LPVOID) &mciOpenParms);
if (dwReturn)
{
Con_Printf("CDAudio_Init: MCI_OPEN failed (%i)\n", dwReturn);
return -1;
@ -446,7 +345,9 @@ int CDAudio_Init(void)
// Set the time format to track/minute/second/frame (TMSF).
mciSetParms.dwTimeFormat = MCI_FORMAT_TMSF;
if (dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD)(LPVOID) &mciSetParms))
dwReturn = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT,
(DWORD)(LPVOID) &mciSetParms);
if (dwReturn)
{
Con_Printf("MCI_SET_TIME_FORMAT failed (%i)\n", dwReturn);
mciSendCommand(wDeviceID, MCI_CLOSE, 0, (DWORD)NULL);

View file

@ -17,10 +17,134 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#if defined(__linux__)
#include "quakedef.h"
static void CD_f(void);
#if defined(USE_LINUX_CD) || defined(USE_BSD_CD)
# include "cd_linux.c"
#elif defined(_WIN32)
# include "cd_win.c"
#else
# include "cd_null.c"
#endif
#ifndef CD_f_DEFINED
static void CD_f(void)
{
char *command;
int ret, n;
if (Cmd_Argc() < 2)
return;
command = Cmd_Argv (1);
if (Q_strcasecmp(command, "on") == 0)
{
enabled = true;
return;
}
if (Q_strcasecmp(command, "off") == 0)
{
if (playing)
CDAudio_Stop();
enabled = false;
return;
}
if (Q_strcasecmp(command, "reset") == 0)
{
enabled = true;
if (playing)
CDAudio_Stop();
for (n = 0; n < 100; n++)
remap[n] = n;
CDAudio_GetAudioDiskInfo();
return;
}
if (Q_strcasecmp(command, "remap") == 0)
{
ret = Cmd_Argc() - 2;
if (ret <= 0)
{
for (n = 1; n < 100; n++)
if (remap[n] != n)
Con_Printf(" %u -> %u\n", n, remap[n]);
return;
}
for (n = 1; n <= ret; n++)
remap[n] = Q_atoi(Cmd_Argv (n+1));
return;
}
if (Q_strcasecmp(command, "close") == 0)
{
CDAudio_CloseDoor();
return;
}
if (!cdValid)
{
CDAudio_GetAudioDiskInfo();
if (!cdValid)
{
Con_Printf("No CD in player.\n");
return;
}
}
if (Q_strcasecmp(command, "play") == 0)
{
CDAudio_Play((byte)Q_atoi(Cmd_Argv (2)), false);
return;
}
if (Q_strcasecmp(command, "loop") == 0)
{
CDAudio_Play((byte)Q_atoi(Cmd_Argv (2)), true);
return;
}
if (Q_strcasecmp(command, "stop") == 0)
{
CDAudio_Stop();
return;
}
if (Q_strcasecmp(command, "pause") == 0)
{
CDAudio_Pause();
return;
}
if (Q_strcasecmp(command, "resume") == 0)
{
CDAudio_Resume();
return;
}
if (Q_strcasecmp(command, "eject") == 0)
{
if (playing)
CDAudio_Stop();
CDAudio_Eject();
cdValid = false;
return;
}
if (Q_strcasecmp(command, "info") == 0)
{
Con_Printf("%u tracks\n", maxTrack);
if (playing)
Con_Printf("Currently %s track %u\n", playLooping ? "looping" : "playing", playTrack);
else if (wasPlaying)
Con_Printf("Paused %s track %u\n", playLooping ? "looping" : "playing", playTrack);
Con_Printf("Volume is %f\n", cdvolume);
return;
}
}
#endif /* CD_f_DEFINED */