From 8e579bbf57c9235bc3c11838e5a68bc52be3e9df Mon Sep 17 00:00:00 2001 From: molivier Date: Mon, 25 Oct 2004 07:13:18 +0000 Subject: [PATCH] FreeBSD support git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4703 d7cf8633-e32d-0410-b094-e92efae38249 --- cd_bsd.c | 19 +++++++++++++++---- jpeg.c | 3 +++ lhnet.c | 6 +++--- makefile | 16 +++++++++++++--- makefile.bsd | 5 +++++ makefile.inc | 6 ++++-- quakedef.h | 2 +- snd_oss.c | 48 +++++++++++++++++++++--------------------------- sys_shared.c | 2 ++ 9 files changed, 67 insertions(+), 40 deletions(-) diff --git a/cd_bsd.c b/cd_bsd.c index c1b6a321..4ee469c5 100644 --- 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 #include @@ -28,13 +26,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include -#include +#include +#ifndef __FreeBSD__ +# include +#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 2637a030..47f45e91 100644 --- 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 4b33180b..1060341f 100644 --- a/lhnet.c +++ b/lhnet.c @@ -8,13 +8,13 @@ #ifdef WIN32 #include #else -#include -#include -//#include #include #include #include #include +#include +#include +#include #endif // for Z_Malloc/Z_Free in quake diff --git a/makefile b/makefile index bba5e017..e959e4e4 100644 --- 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) diff --git a/makefile.bsd b/makefile.bsd index 04821ddb..a120a69f 100644 --- a/makefile.bsd +++ b/makefile.bsd @@ -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) diff --git a/makefile.inc b/makefile.inc index 860d5e7e..7568ec5d 100644 --- a/makefile.inc +++ b/makefile.inc @@ -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 diff --git a/quakedef.h b/quakedef.h index 48a28d3c..12dbfc1f 100644 --- a/quakedef.h +++ b/quakedef.h @@ -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 #include #include #include diff --git a/snd_oss.c b/snd_oss.c index bdb8afcf..10c2a085 100644 --- 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 #include #include @@ -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); diff --git a/sys_shared.c b/sys_shared.c index 134b35dc..1893c219 100644 --- a/sys_shared.c +++ b/sys_shared.c @@ -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__) -- 2.39.2