FreeBSD support
authormolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 25 Oct 2004 07:13:18 +0000 (07:13 +0000)
committermolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 25 Oct 2004 07:13:18 +0000 (07:13 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4703 d7cf8633-e32d-0410-b094-e92efae38249

cd_bsd.c
jpeg.c
lhnet.c
makefile
makefile.bsd
makefile.inc
quakedef.h
snd_oss.c
sys_shared.c

index c1b6a32..4ee469c 100644 (file)
--- a/cd_bsd.c
+++ b/cd_bsd.c
@@ -17,8 +17,6 @@ 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 <sys/types.h>
 #include <sys/cdio.h>
@@ -28,13 +26,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 "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)
@@ -250,9 +257,13 @@ void CDAudio_SysInit (void)
 
 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",
                                        cd_dev, errno);
diff --git a/jpeg.c b/jpeg.c
index 2637a03..47f45e9 100644 (file)
--- a/jpeg.c
+++ b/jpeg.c
@@ -400,8 +400,11 @@ qboolean JPEG_OpenLibrary (void)
        if (jpeg_dll)
                return true;
 
+// TODO: make Sys_LoadLibrary support multiple names
 #ifdef WIN32
        dllname = "libjpeg.dll";
+#elif defined(__FreeBSD__)
+       dllname = "libjpeg.so";
 #else
        dllname = "libjpeg.so.62";
 #endif
diff --git a/lhnet.c b/lhnet.c
index 4b33180..1060341 100644 (file)
--- a/lhnet.c
+++ b/lhnet.c
@@ -8,13 +8,13 @@
 #ifdef WIN32
 #include <winsock.h>
 #else
-#include <netdb.h>
-#include <netinet/in.h>
-//#include <arpa/inet.h>
 #include <unistd.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <errno.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
 #endif
 
 // for Z_Malloc/Z_Free in quake
index bba5e01..e959e4e 100644 (file)
--- a/makefile
+++ b/makefile
@@ -9,7 +9,7 @@ else
 
 # UNIXes
 DP_ARCH:=$(shell uname)
-ifeq ($(DP_ARCH),NetBSD)
+ifneq ($(filter %BSD,$(DP_ARCH)),)
        DP_MAKE_TARGET=bsd
 else
        DP_MAKE_TARGET=linux
@@ -19,6 +19,12 @@ endif
 
 endif
 
+# If we're not on compiling for Win32, we need additional information
+ifneq ($(DP_MAKE_TARGET), mingw)
+       DP_ARCH:=$(shell uname)
+       DP_MACHINE:=$(shell uname -m)
+endif
+
 
 # Command used to delete files
 ifdef windir
@@ -27,8 +33,7 @@ else
        CMD_RM=$(CMD_UNIXRM)
 endif
 
-
-DP_MACHINE:=$(shell uname -m)
+# 64bits AMD CPUs use another lib directory
 ifeq ($(DP_MACHINE),x86_64)
        UNIX_X11LIBPATH:=-L/usr/X11R6/lib64
 else
@@ -55,8 +60,13 @@ endif
 
 # BSD configuration
 ifeq ($(DP_MAKE_TARGET), bsd)
+ifeq ($(DP_ARCH),FreeBSD)
+       OBJ_SOUND=$(OBJ_OSSSOUND)
+       LIB_SOUND=$(LIB_OSSSOUND)
+else
        OBJ_SOUND=$(OBJ_BSDSOUND)
        LIB_SOUND=$(LIB_BSDSOUND)
+endif
        OBJ_CD=$(OBJ_BSDCD)
 
        OBJ_CL=$(OBJ_GLX)
index 04821dd..a120a69 100644 (file)
@@ -16,7 +16,12 @@ UNIX_X11LIBPATH=-L/usr/X11R6/lib
 # BSD configuration
 .if $(DP_MAKE_TARGET) == "bsd"
 
+# FreeBSD uses OSS
+.if exists(/usr/include/sys/soundcard.h)
+OBJ_SOUND=$(OBJ_OSSSOUND)
+.else
 OBJ_SOUND=$(OBJ_BSDSOUND)
+.endif
 LIB_SOUND=$(LIB_BSDSOUND)
 OBJ_CD=$(OBJ_BSDCD)
 
index 860d5e7..7568ec5 100644 (file)
@@ -20,6 +20,8 @@ CPUOPTIMIZATIONS=
 # Sound objects
 OBJ_COMMONSOUND=snd_main.o snd_mem.o snd_mix.o snd_ogg.o snd_wav.o
 OBJ_NOSOUND=snd_null.o
+OBJ_OSSSOUND=$(OBJ_COMMONSOUND) snd_oss.o
+LIB_OSSSOUND=
 
 # CD objects
 OBJ_NOCD=cd_null.o
@@ -146,8 +148,8 @@ CMD_UNIXRM=rm -rf
 ##### Linux specific variables #####
 
 # Recommended for: anyone not using ALSA
-OBJ_LINUXSOUND=$(OBJ_COMMONSOUND) snd_oss.o
-LIB_LINUXSOUND=
+OBJ_LINUXSOUND=$(OBJ_OSSSOUND)
+LIB_LINUXSOUND=$(LIB_OSSSOUND)
 # Recommended for: anyone using ALSA
 #OBJ_LINUXSOUND=$(OBJ_COMMONSOUND) snd_alsa.o
 #LIB_LINUXSOUND=-lasound
index 48a28d3..12dbfc1 100644 (file)
@@ -22,8 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #ifndef QUAKEDEF_H
 #define QUAKEDEF_H
 
-#define QUAKE_GAME // as opposed to utilities
 
+#include <sys/types.h>
 #include <math.h>
 #include <string.h>
 #include <stdarg.h>
index bdb8afc..10c2a08 100644 (file)
--- a/snd_oss.c
+++ b/snd_oss.c
@@ -17,6 +17,9 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 */
+
+// OSS module, used by Linux and FreeBSD
+
 #include <unistd.h>
 #include <fcntl.h>
 #include <stdlib.h>
@@ -54,7 +57,7 @@ qboolean SNDDMA_Init(void)
        snd_inited = 0;
 
        // open /dev/dsp, confirm capability to mmap, and get size of dma buffer
-    audio_fd = open("/dev/dsp", O_RDWR);
+    audio_fd = open("/dev/dsp", O_RDWR);  // we have to open it O_RDWR for mmap
        if (audio_fd < 0)
        {
                perror("/dev/dsp");
@@ -118,7 +121,7 @@ qboolean SNDDMA_Init(void)
                shm->format.speed = atoi(com_argv[i+1]);
        else
        {
-               for (i = 0;i < (int) sizeof(tryrates) / 4;i++)
+               for (i = 0;i < (int) sizeof(tryrates) / sizeof(tryrates[0]);i++)
                        if (!ioctl(audio_fd, SNDCTL_DSP_SPEED, &tryrates[i]))
                                break;
 
@@ -132,40 +135,18 @@ qboolean SNDDMA_Init(void)
        else if ((i = COM_CheckParm("-sndmono")) != 0)
                shm->format.channels = 1;
 // COMMANDLINEOPTION: Linux OSS Sound: -sndstereo sets sound output to stereo
-       else if ((i = COM_CheckParm("-sndstereo")) != 0)
-               shm->format.channels = 2;
-       else
+       else // if ((i = COM_CheckParm("-sndstereo")) != 0)
                shm->format.channels = 2;
 
-       shm->samples = info.fragstotal * info.fragsize / shm->format.width;
-
-       // memory map the dma buffer
-       shm->bufferlength = info.fragstotal * info.fragsize;
-       shm->buffer = (unsigned char *) mmap(NULL, shm->bufferlength, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, audio_fd, 0);
-       if (!shm->buffer || shm->buffer == (unsigned char *)-1)
-       {
-               perror("/dev/dsp");
-               Con_Print("Could not mmap /dev/dsp\n");
-               close(audio_fd);
-               return 0;
-       }
-
-       tmp = 0;
-       if (shm->format.channels == 2)
-               tmp = 1;
-
+       tmp = (shm->format.channels == 2);
        rc = ioctl(audio_fd, SNDCTL_DSP_STEREO, &tmp);
        if (rc < 0)
        {
                perror("/dev/dsp");
-               Con_Printf("Could not set /dev/dsp to stereo=%d\n", shm->format.channels);
+               Con_Printf("Could not set /dev/dsp to stereo=%d\n", tmp);
                close(audio_fd);
                return 0;
        }
-       if (tmp)
-               shm->format.channels = 2;
-       else
-               shm->format.channels = 1;
 
        rc = ioctl(audio_fd, SNDCTL_DSP_SPEED, &shm->format.speed);
        if (rc < 0)
@@ -208,6 +189,19 @@ qboolean SNDDMA_Init(void)
                return 0;
        }
 
+       shm->samples = info.fragstotal * info.fragsize / shm->format.width;
+
+       // memory map the dma buffer
+       shm->bufferlength = info.fragstotal * info.fragsize;
+       shm->buffer = (unsigned char *) mmap(NULL, shm->bufferlength, PROT_WRITE, MAP_FILE|MAP_SHARED, audio_fd, 0);
+       if (!shm->buffer || shm->buffer == (unsigned char *)-1)
+       {
+               perror("/dev/dsp");
+               Con_Print("Could not mmap /dev/dsp\n");
+               close(audio_fd);
+               return 0;
+       }
+
        // toggle the trigger & start her up
        tmp = 0;
        rc  = ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp);
index 134b35d..1893c21 100644 (file)
@@ -116,6 +116,8 @@ void Sys_Shared_EarlyInit(void)
        os = "Linux";
 #elif defined(WIN32)
        os = "Windows";
+#elif defined(__FreeBSD__)
+       os = "FreeBSD";
 #elif defined(__NetBSD__)
        os = "NetBSD";
 #elif defined(__OpenBSD__)