X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=cd_linux.c;h=2db702cb3f9f2b685ee644377b51e49c997a4fea;hb=3c0dcba17deda28ea48a69acda942b292f74aeb1;hp=29a4bb062ad19279967b69dd766b3ee7a4b67d61;hpb=9bc13b6cdcd9c514342f1fbdf35a3c5298710870;p=xonotic%2Fdarkplaces.git diff --git a/cd_linux.c b/cd_linux.c index 29a4bb06..2db702cb 100644 --- a/cd_linux.c +++ b/cd_linux.c @@ -20,6 +20,9 @@ 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. +// suggested by Zero_Dogg to fix a compile problem on Mandriva Linux +#define __KERNEL_STRICT_NAMES + #include #include @@ -29,18 +32,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include "quakedef.h" +#include "cdaudio.h" static int cdfile = -1; static char cd_dev[64] = "/dev/cdrom"; + void CDAudio_SysEject (void) { if (cdfile == -1) return; if (ioctl(cdfile, CDROMEJECT) == -1) - Con_DPrintf("ioctl cdromeject failed\n"); + Con_Print("ioctl CDROMEJECT failed\n"); } @@ -50,22 +55,25 @@ void CDAudio_SysCloseDoor (void) return; if (ioctl(cdfile, CDROMCLOSETRAY) == -1) - Con_DPrintf("ioctl cdromclosetray failed\n"); + Con_Print("ioctl CDROMCLOSETRAY failed\n"); } int CDAudio_SysGetAudioDiskInfo (void) { struct cdrom_tochdr tochdr; + if (cdfile == -1) + return -1; + if (ioctl(cdfile, CDROMREADTOCHDR, &tochdr) == -1) { - Con_DPrintf("ioctl cdromreadtochdr failed\n"); + Con_Print("ioctl CDROMREADTOCHDR failed\n"); return -1; } if (tochdr.cdth_trk0 < 1) { - Con_DPrintf("CDAudio: no music tracks\n"); + Con_Print("CDAudio: no music tracks\n"); return -1; } @@ -73,7 +81,39 @@ int CDAudio_SysGetAudioDiskInfo (void) } -int CDAudio_SysPlay (qbyte track) +float CDAudio_SysGetVolume (void) +{ + struct cdrom_volctrl vol; + + if (cdfile == -1) + return -1.0f; + + if (ioctl (cdfile, CDROMVOLREAD, &vol) == -1) + { + Con_Print("ioctl CDROMVOLREAD failed\n"); + return -1.0f; + } + + return (vol.channel0 + vol.channel1) / 2.0f / 255.0f; +} + + +void CDAudio_SysSetVolume (float volume) +{ + struct cdrom_volctrl vol; + + if (cdfile == -1) + return; + + vol.channel0 = vol.channel1 = (__u8)(volume * 255); + vol.channel2 = vol.channel3 = 0; + + if (ioctl (cdfile, CDROMVOLCTRL, &vol) == -1) + Con_Print("ioctl CDROMVOLCTRL failed\n"); +} + + +int CDAudio_SysPlay (unsigned char track) { struct cdrom_tocentry entry; struct cdrom_ti ti; @@ -86,7 +126,7 @@ int CDAudio_SysPlay (qbyte track) entry.cdte_format = CDROM_MSF; if (ioctl(cdfile, CDROMREADTOCENTRY, &entry) == -1) { - Con_DPrintf("ioctl cdromreadtocentry failed\n"); + Con_Print("ioctl CDROMREADTOCENTRY failed\n"); return -1; } if (entry.cdte_ctrl == CDROM_DATA_TRACK) @@ -105,13 +145,13 @@ int CDAudio_SysPlay (qbyte track) if (ioctl(cdfile, CDROMPLAYTRKIND, &ti) == -1) { - Con_DPrintf("ioctl cdromplaytrkind failed\n"); + Con_Print("ioctl CDROMPLAYTRKIND failed\n"); return -1; } if (ioctl(cdfile, CDROMRESUME) == -1) { - Con_DPrintf("ioctl cdromresume failed\n"); + Con_Print("ioctl CDROMRESUME failed\n"); return -1; } @@ -126,10 +166,10 @@ int CDAudio_SysStop (void) if (ioctl(cdfile, CDROMSTOP) == -1) { - Con_DPrintf("ioctl cdromstop failed (%d)\n", errno); + Con_Printf("ioctl CDROMSTOP failed (%d)\n", errno); return -1; } - + return 0; } @@ -140,10 +180,10 @@ int CDAudio_SysPause (void) if (ioctl(cdfile, CDROMPAUSE) == -1) { - Con_DPrintf("ioctl cdrompause failed\n"); + Con_Print("ioctl CDROMPAUSE failed\n"); return -1; } - + return 0; } @@ -154,7 +194,7 @@ int CDAudio_SysResume (void) return -1; if (ioctl(cdfile, CDROMRESUME) == -1) - Con_DPrintf("ioctl cdromresume failed\n"); + Con_Print("ioctl CDROMRESUME failed\n"); return 0; } @@ -164,22 +204,27 @@ int CDAudio_SysUpdate (void) struct cdrom_subchnl subchnl; static time_t lastchk = 0; - if (cdPlaying && lastchk < time(NULL)) { + if (cdPlaying && lastchk < time(NULL)) + { lastchk = time(NULL) + 2; //two seconds between chks subchnl.cdsc_format = CDROM_MSF; - if (ioctl(cdfile, CDROMSUBCHNL, &subchnl) == -1 ) { - Con_DPrintf("ioctl cdromsubchnl failed\n"); + if (ioctl(cdfile, CDROMSUBCHNL, &subchnl) == -1) + { + Con_Print("ioctl CDROMSUBCHNL failed\n"); cdPlaying = false; return -1; } if (subchnl.cdsc_audiostatus != CDROM_AUDIO_PLAY && - subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED) { + subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED) + { cdPlaying = false; if (cdPlayLooping) CDAudio_Play(cdPlayTrack, true); } + else + cdPlayTrack = subchnl.cdsc_trk; } - + return 0; } @@ -187,15 +232,17 @@ void CDAudio_SysInit (void) { int i; +// COMMANDLINEOPTION: Linux Sound: -cddev chooses which CD drive to use if ((i = COM_CheckParm("-cddev")) != 0 && i < com_argc - 1) - strlcpy (cd_dev, com_argv[i + 1], sizeof (cd_dev)); + strlcpy(cd_dev, com_argv[i + 1], sizeof(cd_dev)); } int CDAudio_SysStartup (void) { - if ((cdfile = open(cd_dev, O_RDONLY)) == -1) + if ((cdfile = open(cd_dev, O_RDONLY | O_NONBLOCK)) == -1) { - Con_DPrintf("CDAudio_SysStartup: open of \"%s\" failed (%i)\n", cd_dev, errno); + Con_Printf("CDAudio_SysStartup: open of \"%s\" failed (%i)\n", + cd_dev, errno); cdfile = -1; return -1; }