]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cd_bsd.c
implemented real support for QW skins (pants, shirt, glow, cropped pcx
[xonotic/darkplaces.git] / cd_bsd.c
index 14bb317260ada047bbc5d3e3a1e2977f34b0ef20..7b3a855af4db44d1077a2847c16eea379eb99aa9 100644 (file)
--- a/cd_bsd.c
+++ b/cd_bsd.c
@@ -17,8 +17,8 @@ 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.
+
+#include "quakedef.h"
 
 #include <sys/types.h>
 #include <sys/cdio.h>
@@ -28,13 +28,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include <fcntl.h>
 #include <paths.h>
 #include <unistd.h>
-#include <util.h>
+#include <time.h>
+#ifndef __FreeBSD__
+# include <util.h>
+#endif
+
+#include "cdaudio.h"
 
-#include "quakedef.h"
 
+#ifndef __FreeBSD__
+# define DEFAULT_CD_DEVICE _PATH_DEV "cd0"
+#else
+# define DEFAULT_CD_DEVICE "/dev/acd0c"
+#endif
 
 static int cdfile = -1;
-static char cd_dev[64] = _PATH_DEV "cd0";
+static char cd_dev[64] = DEFAULT_CD_DEVICE;
 
 
 void CDAudio_SysEject (void)
@@ -44,7 +53,7 @@ void CDAudio_SysEject (void)
 
        ioctl(cdfile, CDIOCALLOW);
        if (ioctl(cdfile, CDIOCEJECT) == -1)
-               Con_DPrintf("ioctl CDIOCEJECT failed\n");
+               Con_Print("ioctl CDIOCEJECT failed\n");
 }
 
 
@@ -55,22 +64,25 @@ void CDAudio_SysCloseDoor (void)
 
        ioctl(cdfile, CDIOCALLOW);
        if (ioctl(cdfile, CDIOCCLOSE) == -1)
-               Con_DPrintf("ioctl CDIOCCLOSE failed\n");
+               Con_Print("ioctl CDIOCCLOSE failed\n");
 }
 
 int CDAudio_SysGetAudioDiskInfo (void)
 {
        struct ioc_toc_header tochdr;
 
+       if (cdfile == -1)
+               return -1;
+
        if (ioctl(cdfile, CDIOREADTOCHEADER, &tochdr) == -1)
        {
-               Con_DPrintf("ioctl CDIOREADTOCHEADER failed\n");
+               Con_Print("ioctl CDIOREADTOCHEADER failed\n");
                return -1;
        }
 
        if (tochdr.starting_track < 1)
        {
-               Con_DPrintf("CDAudio: no music tracks\n");
+               Con_Print("CDAudio: no music tracks\n");
                return -1;
        }
 
@@ -78,7 +90,39 @@ int CDAudio_SysGetAudioDiskInfo (void)
 }
 
 
-int CDAudio_SysPlay (qbyte track)
+float CDAudio_SysGetVolume (void)
+{
+       struct ioc_vol vol;
+
+       if (cdfile == -1)
+               return -1.0f;
+
+       if (ioctl (cdfile, CDIOCGETVOL, &vol) == -1)
+       {
+               Con_Print("ioctl CDIOCGETVOL failed\n");
+               return -1.0f;
+       }
+
+       return (vol.vol[0] + vol.vol[1]) / 2.0f / 255.0f;
+}
+
+
+void CDAudio_SysSetVolume (float volume)
+{
+       struct ioc_vol vol;
+
+       if (cdfile == -1)
+               return;
+
+       vol.vol[0] = vol.vol[1] = volume * 255;
+       vol.vol[2] = vol.vol[3] = 0;
+
+       if (ioctl (cdfile, CDIOCSETVOL, &vol) == -1)
+               Con_Printf ("ioctl CDIOCSETVOL failed\n");
+}
+
+
+int CDAudio_SysPlay (int track)
 {
        struct ioc_read_toc_entry rte;
        struct cd_toc_entry entry;
@@ -94,7 +138,7 @@ int CDAudio_SysPlay (qbyte track)
        rte.data = &entry;
        if (ioctl(cdfile, CDIOREADTOCENTRYS, &rte) == -1)
        {
-               Con_DPrintf("ioctl CDIOREADTOCENTRYS failed\n");
+               Con_Print("ioctl CDIOREADTOCENTRYS failed\n");
                return -1;
        }
        if (entry.control & 4)  // if it's a data track
@@ -113,13 +157,13 @@ int CDAudio_SysPlay (qbyte track)
 
        if (ioctl(cdfile, CDIOCPLAYTRACKS, &ti) == -1)
        {
-               Con_DPrintf("ioctl CDIOCPLAYTRACKS failed\n");
+               Con_Print("ioctl CDIOCPLAYTRACKS failed\n");
                return -1;
        }
 
        if (ioctl(cdfile, CDIOCRESUME) == -1)
        {
-               Con_DPrintf("ioctl CDIOCRESUME failed\n");
+               Con_Print("ioctl CDIOCRESUME failed\n");
                return -1;
        }
 
@@ -134,7 +178,7 @@ int CDAudio_SysStop (void)
 
        if (ioctl(cdfile, CDIOCSTOP) == -1)
        {
-               Con_DPrintf("ioctl CDIOCSTOP failed (%d)\n", errno);
+               Con_Printf("ioctl CDIOCSTOP failed (%d)\n", errno);
                return -1;
        }
        ioctl(cdfile, CDIOCALLOW);
@@ -149,7 +193,7 @@ int CDAudio_SysPause (void)
 
        if (ioctl(cdfile, CDIOCPAUSE) == -1)
        {
-               Con_DPrintf("ioctl CDIOCPAUSE failed\n");
+               Con_Print("ioctl CDIOCPAUSE failed\n");
                return -1;
        }
 
@@ -163,7 +207,7 @@ int CDAudio_SysResume (void)
                return -1;
 
        if (ioctl(cdfile, CDIOCRESUME) == -1)
-               Con_DPrintf("ioctl CDIOCRESUME failed\n");
+               Con_Print("ioctl CDIOCRESUME failed\n");
 
        return 0;
 }
@@ -186,7 +230,7 @@ int CDAudio_SysUpdate (void)
 
                if (ioctl(cdfile, CDIOCREADSUBCHANNEL, &subchnl) == -1)
                {
-                       Con_DPrintf("ioctl CDIOCREADSUBCHANNEL failed\n");
+                       Con_Print("ioctl CDIOCREADSUBCHANNEL failed\n");
                        cdPlaying = false;
                        return -1;
                }
@@ -208,17 +252,22 @@ void CDAudio_SysInit (void)
 {
        int i;
 
+// COMMANDLINEOPTION: BSD Sound: -cddev <devicepath> 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));
 }
 
 int CDAudio_SysStartup (void)
 {
+#ifndef __FreeBSD__
        char buff [80];
 
        if ((cdfile = opendisk(cd_dev, O_RDONLY, buff, sizeof(buff), 0)) == -1)
+#else
+       if ((cdfile = open(cd_dev, O_RDONLY)) < 0)
+#endif
        {
-               Con_DPrintf("CDAudio_SysStartup: open of \"%s\" failed (%i)\n",
+               Con_Printf("CDAudio_SysStartup: open of \"%s\" failed (%i)\n",
                                        cd_dev, errno);
                cdfile = -1;
                return -1;