pkgsrc/games/quake/patches/patch-aj
2009-08-29 19:26:01 +00:00

176 lines
4.6 KiB
Text

$NetBSD: patch-aj,v 1.4 2009/08/29 19:26:01 wiz Exp $
--- WinQuake/snd_linux.c.orig 1999-12-21 18:40:36.000000000 +0000
+++ WinQuake/snd_linux.c
@@ -25,15 +25,42 @@ Foundation, Inc., 59 Temple Place - Suit
#include <sys/mman.h>
#include <sys/shm.h>
#include <sys/wait.h>
+
+#ifdef __NetBSD__
+#include <soundcard.h>
+#endif
+
+#if defined(__DragonFly__)
+#include <sys/soundcard.h>
+#endif
+
+#ifdef __linux__
#include <linux/soundcard.h>
+#endif
+
#include <stdio.h>
#include "quakedef.h"
-int audio_fd;
+int audio_fd = -1;
int snd_inited;
static int tryrates[] = { 11025, 22051, 44100, 8000 };
+#ifdef __linux__
+const char *audio_device="/dev/dsp";
+#define MMAP_PROTECTION PROT_WRITE
+#endif
+
+#ifdef __NetBSD__
+const char *audio_device="/dev/audio";
+#define MMAP_PROTECTION PROT_WRITE|PROT_READ
+#endif
+
+#if defined(__DragonFly__)
+const char *audio_device="/dev/dsp";
+#define MMAP_PROTECTION PROT_WRITE|PROT_READ
+#endif
+
qboolean SNDDMA_Init(void)
{
@@ -47,28 +74,29 @@ qboolean SNDDMA_Init(void)
snd_inited = 0;
-// open /dev/dsp, confirm capability to mmap, and get size of dma buffer
+// open /dev/dsp or whatever, confirm capability to mmap, and get size of
+// dma buffer
- audio_fd = open("/dev/dsp", O_RDWR);
+ audio_fd = open(audio_device, O_RDWR);
if (audio_fd < 0)
{
- perror("/dev/dsp");
- Con_Printf("Could not open /dev/dsp\n");
+ perror(audio_device);
+ Con_Printf("Could not open %s\n",audio_device);
return 0;
}
rc = ioctl(audio_fd, SNDCTL_DSP_RESET, 0);
if (rc < 0)
{
- perror("/dev/dsp");
- Con_Printf("Could not reset /dev/dsp\n");
+ perror(audio_device);
+ Con_Printf("Could not reset %s\n",audio_device);
close(audio_fd);
return 0;
}
if (ioctl(audio_fd, SNDCTL_DSP_GETCAPS, &caps)==-1)
{
- perror("/dev/dsp");
+ perror(audio_device);
Con_Printf("Sound driver too old\n");
close(audio_fd);
return 0;
@@ -130,11 +158,11 @@ qboolean SNDDMA_Init(void)
// memory map the dma buffer
shm->buffer = (unsigned char *) mmap(NULL, info.fragstotal
- * info.fragsize, PROT_WRITE, MAP_FILE|MAP_SHARED, audio_fd, 0);
+ * info.fragsize, MMAP_PROTECTION, MAP_FILE|MAP_SHARED, audio_fd, 0);
if (!shm->buffer || shm->buffer == (unsigned char *)-1)
{
- perror("/dev/dsp");
- Con_Printf("Could not mmap /dev/dsp\n");
+ perror(audio_device);
+ Con_Printf("Could not mmap %s\n",audio_device);
close(audio_fd);
return 0;
}
@@ -145,8 +173,8 @@ qboolean SNDDMA_Init(void)
rc = ioctl(audio_fd, SNDCTL_DSP_STEREO, &tmp);
if (rc < 0)
{
- perror("/dev/dsp");
- Con_Printf("Could not set /dev/dsp to stereo=%d", shm->channels);
+ perror(audio_device);
+ Con_Printf("Could not set %s to stereo=%d", audio_device, shm->channels);
close(audio_fd);
return 0;
}
@@ -158,8 +186,8 @@ qboolean SNDDMA_Init(void)
rc = ioctl(audio_fd, SNDCTL_DSP_SPEED, &shm->speed);
if (rc < 0)
{
- perror("/dev/dsp");
- Con_Printf("Could not set /dev/dsp speed to %d", shm->speed);
+ perror(audio_device);
+ Con_Printf("Could not set %s speed to %d", audio_device, shm->speed);
close(audio_fd);
return 0;
}
@@ -170,7 +198,7 @@ qboolean SNDDMA_Init(void)
rc = ioctl(audio_fd, SNDCTL_DSP_SETFMT, &rc);
if (rc < 0)
{
- perror("/dev/dsp");
+ perror(audio_device);
Con_Printf("Could not support 16-bit data. Try 8-bit.\n");
close(audio_fd);
return 0;
@@ -182,7 +210,7 @@ qboolean SNDDMA_Init(void)
rc = ioctl(audio_fd, SNDCTL_DSP_SETFMT, &rc);
if (rc < 0)
{
- perror("/dev/dsp");
+ perror(audio_device);
Con_Printf("Could not support 8-bit data.\n");
close(audio_fd);
return 0;
@@ -190,7 +218,7 @@ qboolean SNDDMA_Init(void)
}
else
{
- perror("/dev/dsp");
+ perror(audio_device);
Con_Printf("%d-bit sound not supported.", shm->samplebits);
close(audio_fd);
return 0;
@@ -202,7 +230,7 @@ qboolean SNDDMA_Init(void)
rc = ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp);
if (rc < 0)
{
- perror("/dev/dsp");
+ perror(audio_device);
Con_Printf("Could not toggle.\n");
close(audio_fd);
return 0;
@@ -211,7 +239,7 @@ qboolean SNDDMA_Init(void)
rc = ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp);
if (rc < 0)
{
- perror("/dev/dsp");
+ perror(audio_device);
Con_Printf("Could not toggle.\n");
close(audio_fd);
return 0;
@@ -233,7 +261,7 @@ int SNDDMA_GetDMAPos(void)
if (ioctl(audio_fd, SNDCTL_DSP_GETOPTR, &count)==-1)
{
- perror("/dev/dsp");
+ perror(audio_device);
Con_Printf("Uh, sound dead.\n");
close(audio_fd);
snd_inited = 0;