shithub: qk1

Download patch

ref: af7c9e9e4c647a9b155842cb98f25d0facd2bc95
parent: bf5f906a21121a00f6b264c90539392d4a68e3ba
author: Konstantinn Bonnet <qu7uux@gmail.com>
date: Thu Jan 29 16:05:45 EST 2015

make mostly compilable on 9front

--- /dev/null
+++ b/cd_9.c
@@ -1,0 +1,395 @@
+#include <u.h>
+#include <libc.h>
+//#include <stdio.h>
+//#include <unistd.h>
+//#include <stdlib.h>
+#include <sys/ioctl.h>
+//#include <sys/file.h>
+//#include <sys/types.h>
+//#include <fcntl.h>
+//#include <string.h>
+//#include <time.h>
+#include <errno.h>
+#include <linux/cdrom.h>
+
+#include "quakedef.h"
+
+static qboolean cdValid = false;
+static qboolean	playing = false;
+static qboolean	wasPlaying = false;
+static qboolean	initialized = false;
+static qboolean	enabled = true;
+static qboolean playLooping = false;
+static float	cdvolume;
+static byte 	remap[100];
+static byte		playTrack;
+static byte		maxTrack;
+
+static int cdfile = -1;
+static char cd_dev[64] = "/dev/cdrom";
+
+static void CDAudio_Eject(void)
+{
+	if (cdfile == -1 || !enabled)
+		return; // no cd init'd
+
+	if ( ioctl(cdfile, CDROMEJECT) == -1 ) 
+		Con_DPrintf("ioctl cdromeject failed\n");
+}
+
+
+static void CDAudio_CloseDoor(void)
+{
+	if (cdfile == -1 || !enabled)
+		return; // no cd init'd
+
+	if ( ioctl(cdfile, CDROMCLOSETRAY) == -1 ) 
+		Con_DPrintf("ioctl cdromclosetray failed\n");
+}
+
+static int CDAudio_GetAudioDiskInfo(void)
+{
+	struct cdrom_tochdr tochdr;
+
+	cdValid = false;
+
+	if ( ioctl(cdfile, CDROMREADTOCHDR, &tochdr) == -1 ) 
+    {
+      Con_DPrintf("ioctl cdromreadtochdr failed\n");
+	  return -1;
+    }
+
+	if (tochdr.cdth_trk0 < 1)
+	{
+		Con_DPrintf("CDAudio: no music tracks\n");
+		return -1;
+	}
+
+	cdValid = true;
+	maxTrack = tochdr.cdth_trk1;
+
+	return 0;
+}
+
+
+void CDAudio_Play(byte track, qboolean looping)
+{
+	struct cdrom_tocentry entry;
+	struct cdrom_ti ti;
+
+	if (cdfile == -1 || !enabled)
+		return;
+	
+	if (!cdValid)
+	{
+		CDAudio_GetAudioDiskInfo();
+		if (!cdValid)
+			return;
+	}
+
+	track = remap[track];
+
+	if (track < 1 || track > maxTrack)
+	{
+		Con_DPrintf("CDAudio: Bad track number %u.\n", track);
+		return;
+	}
+
+	// don't try to play a non-audio track
+	entry.cdte_track = track;
+	entry.cdte_format = CDROM_MSF;
+    if ( ioctl(cdfile, CDROMREADTOCENTRY, &entry) == -1 )
+	{
+		Con_DPrintf("ioctl cdromreadtocentry failed\n");
+		return;
+	}
+	if (entry.cdte_ctrl == CDROM_DATA_TRACK)
+	{
+		Con_Printf("CDAudio: track %i is not audio\n", track);
+		return;
+	}
+
+	if (playing)
+	{
+		if (playTrack == track)
+			return;
+		CDAudio_Stop();
+	}
+
+	ti.cdti_trk0 = track;
+	ti.cdti_trk1 = track;
+	ti.cdti_ind0 = 1;
+	ti.cdti_ind1 = 99;
+
+	if ( ioctl(cdfile, CDROMPLAYTRKIND, &ti) == -1 ) 
+    {
+		Con_DPrintf("ioctl cdromplaytrkind failed\n");
+		return;
+    }
+
+	if ( ioctl(cdfile, CDROMRESUME) == -1 ) 
+		Con_DPrintf("ioctl cdromresume failed\n");
+
+	playLooping = looping;
+	playTrack = track;
+	playing = true;
+
+	if (cdvolume == 0.0)
+		CDAudio_Pause ();
+}
+
+
+void CDAudio_Stop(void)
+{
+	if (cdfile == -1 || !enabled)
+		return;
+	
+	if (!playing)
+		return;
+
+	if ( ioctl(cdfile, CDROMSTOP) == -1 )
+		Con_DPrintf("ioctl cdromstop failed (%d)\n", errno);
+
+	wasPlaying = false;
+	playing = false;
+}
+
+void CDAudio_Pause(void)
+{
+	if (cdfile == -1 || !enabled)
+		return;
+
+	if (!playing)
+		return;
+
+	if ( ioctl(cdfile, CDROMPAUSE) == -1 ) 
+		Con_DPrintf("ioctl cdrompause failed\n");
+
+	wasPlaying = playing;
+	playing = false;
+}
+
+
+void CDAudio_Resume(void)
+{
+	if (cdfile == -1 || !enabled)
+		return;
+	
+	if (!cdValid)
+		return;
+
+	if (!wasPlaying)
+		return;
+	
+	if ( ioctl(cdfile, CDROMRESUME) == -1 ) 
+		Con_DPrintf("ioctl cdromresume failed\n");
+	playing = true;
+}
+
+static void CD_f (void)
+{
+	char	*command;
+	int		ret;
+	int		n;
+
+	if (Cmd_Argc() < 2)
+		return;
+
+	command = Cmd_Argv (1);
+
+	if (Q_strcasecmp(command, "on") == 0)
+	{
+		enabled = true;
+		return;
+	}
+
+	if (Q_strcasecmp(command, "off") == 0)
+	{
+		if (playing)
+			CDAudio_Stop();
+		enabled = false;
+		return;
+	}
+
+	if (Q_strcasecmp(command, "reset") == 0)
+	{
+		enabled = true;
+		if (playing)
+			CDAudio_Stop();
+		for (n = 0; n < 100; n++)
+			remap[n] = n;
+		CDAudio_GetAudioDiskInfo();
+		return;
+	}
+
+	if (Q_strcasecmp(command, "remap") == 0)
+	{
+		ret = Cmd_Argc() - 2;
+		if (ret <= 0)
+		{
+			for (n = 1; n < 100; n++)
+				if (remap[n] != n)
+					Con_Printf("  %u -> %u\n", n, remap[n]);
+			return;
+		}
+		for (n = 1; n <= ret; n++)
+			remap[n] = Q_atoi(Cmd_Argv (n+1));
+		return;
+	}
+
+	if (Q_strcasecmp(command, "close") == 0)
+	{
+		CDAudio_CloseDoor();
+		return;
+	}
+
+	if (!cdValid)
+	{
+		CDAudio_GetAudioDiskInfo();
+		if (!cdValid)
+		{
+			Con_Printf("No CD in player.\n");
+			return;
+		}
+	}
+
+	if (Q_strcasecmp(command, "play") == 0)
+	{
+		CDAudio_Play((byte)Q_atoi(Cmd_Argv (2)), false);
+		return;
+	}
+
+	if (Q_strcasecmp(command, "loop") == 0)
+	{
+		CDAudio_Play((byte)Q_atoi(Cmd_Argv (2)), true);
+		return;
+	}
+
+	if (Q_strcasecmp(command, "stop") == 0)
+	{
+		CDAudio_Stop();
+		return;
+	}
+
+	if (Q_strcasecmp(command, "pause") == 0)
+	{
+		CDAudio_Pause();
+		return;
+	}
+
+	if (Q_strcasecmp(command, "resume") == 0)
+	{
+		CDAudio_Resume();
+		return;
+	}
+
+	if (Q_strcasecmp(command, "eject") == 0)
+	{
+		if (playing)
+			CDAudio_Stop();
+		CDAudio_Eject();
+		cdValid = false;
+		return;
+	}
+
+	if (Q_strcasecmp(command, "info") == 0)
+	{
+		Con_Printf("%u tracks\n", maxTrack);
+		if (playing)
+			Con_Printf("Currently %s track %u\n", playLooping ? "looping" : "playing", playTrack);
+		else if (wasPlaying)
+			Con_Printf("Paused %s track %u\n", playLooping ? "looping" : "playing", playTrack);
+		Con_Printf("Volume is %f\n", cdvolume);
+		return;
+	}
+}
+
+void CDAudio_Update(void)
+{
+	struct cdrom_subchnl subchnl;
+	static time_t lastchk;
+
+	if (!enabled)
+		return;
+
+	if (bgmvolume.value != cdvolume)
+	{
+		if (cdvolume)
+		{
+			Cvar_SetValue ("bgmvolume", 0.0);
+			cdvolume = bgmvolume.value;
+			CDAudio_Pause ();
+		}
+		else
+		{
+			Cvar_SetValue ("bgmvolume", 1.0);
+			cdvolume = bgmvolume.value;
+			CDAudio_Resume ();
+		}
+	}
+
+	if (playing && 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");
+			playing = false;
+			return;
+		}
+		if (subchnl.cdsc_audiostatus != CDROM_AUDIO_PLAY &&
+			subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED) {
+			playing = false;
+			if (playLooping)
+				CDAudio_Play(playTrack, true);
+		}
+	}
+}
+
+int CDAudio_Init(void)
+{
+	int i;
+
+	if (cls.state == ca_dedicated)
+		return -1;
+
+	if (COM_CheckParm("-nocdaudio"))
+		return -1;
+
+	if ((i = COM_CheckParm("-cddev")) != 0 && i < com_argc - 1) {
+		strncpy(cd_dev, com_argv[i + 1], sizeof(cd_dev));
+		cd_dev[sizeof(cd_dev) - 1] = 0;
+	}
+
+	if ((cdfile = open(cd_dev, OREAD)) == -1) {
+		Con_Printf("CDAudio_Init: open of \"%s\" failed (%i)\n", cd_dev, errno);
+		cdfile = -1;
+		return -1;
+	}
+
+	for (i = 0; i < 100; i++)
+		remap[i] = i;
+	initialized = true;
+	enabled = true;
+
+	if (CDAudio_GetAudioDiskInfo())
+	{
+		Con_Printf("CDAudio_Init: No CD in player.\n");
+		cdValid = false;
+	}
+
+	Cmd_AddCommand ("cd", CD_f);
+
+	Con_Printf("CD Audio Initialized\n");
+
+	return 0;
+}
+
+
+void CDAudio_Shutdown(void)
+{
+	if (!initialized)
+		return;
+	CDAudio_Stop();
+	close(cdfile);
+	cdfile = -1;
+}
--- a/cd_linux.c
+++ /dev/null
@@ -1,399 +1,0 @@
-// Quake is a trademark of Id Software, Inc., (c) 1996 Id Software, Inc. All
-// rights reserved.
-
-#include <u.h>
-#include <libc.h>
-//#include <stdio.h>
-//#include <unistd.h>
-//#include <stdlib.h>
-#include <sys/ioctl.h>
-//#include <sys/file.h>
-//#include <sys/types.h>
-//#include <fcntl.h>
-//#include <string.h>
-//#include <time.h>
-#include <errno.h>
-
-#include <linux/cdrom.h>
-
-#include "quakedef.h"
-
-static qboolean cdValid = false;
-static qboolean	playing = false;
-static qboolean	wasPlaying = false;
-static qboolean	initialized = false;
-static qboolean	enabled = true;
-static qboolean playLooping = false;
-static float	cdvolume;
-static byte 	remap[100];
-static byte		playTrack;
-static byte		maxTrack;
-
-static int cdfile = -1;
-static char cd_dev[64] = "/dev/cdrom";
-
-static void CDAudio_Eject(void)
-{
-	if (cdfile == -1 || !enabled)
-		return; // no cd init'd
-
-	if ( ioctl(cdfile, CDROMEJECT) == -1 ) 
-		Con_DPrintf("ioctl cdromeject failed\n");
-}
-
-
-static void CDAudio_CloseDoor(void)
-{
-	if (cdfile == -1 || !enabled)
-		return; // no cd init'd
-
-	if ( ioctl(cdfile, CDROMCLOSETRAY) == -1 ) 
-		Con_DPrintf("ioctl cdromclosetray failed\n");
-}
-
-static int CDAudio_GetAudioDiskInfo(void)
-{
-	struct cdrom_tochdr tochdr;
-
-	cdValid = false;
-
-	if ( ioctl(cdfile, CDROMREADTOCHDR, &tochdr) == -1 ) 
-    {
-      Con_DPrintf("ioctl cdromreadtochdr failed\n");
-	  return -1;
-    }
-
-	if (tochdr.cdth_trk0 < 1)
-	{
-		Con_DPrintf("CDAudio: no music tracks\n");
-		return -1;
-	}
-
-	cdValid = true;
-	maxTrack = tochdr.cdth_trk1;
-
-	return 0;
-}
-
-
-void CDAudio_Play(byte track, qboolean looping)
-{
-	struct cdrom_tocentry entry;
-	struct cdrom_ti ti;
-
-	if (cdfile == -1 || !enabled)
-		return;
-	
-	if (!cdValid)
-	{
-		CDAudio_GetAudioDiskInfo();
-		if (!cdValid)
-			return;
-	}
-
-	track = remap[track];
-
-	if (track < 1 || track > maxTrack)
-	{
-		Con_DPrintf("CDAudio: Bad track number %u.\n", track);
-		return;
-	}
-
-	// don't try to play a non-audio track
-	entry.cdte_track = track;
-	entry.cdte_format = CDROM_MSF;
-    if ( ioctl(cdfile, CDROMREADTOCENTRY, &entry) == -1 )
-	{
-		Con_DPrintf("ioctl cdromreadtocentry failed\n");
-		return;
-	}
-	if (entry.cdte_ctrl == CDROM_DATA_TRACK)
-	{
-		Con_Printf("CDAudio: track %i is not audio\n", track);
-		return;
-	}
-
-	if (playing)
-	{
-		if (playTrack == track)
-			return;
-		CDAudio_Stop();
-	}
-
-	ti.cdti_trk0 = track;
-	ti.cdti_trk1 = track;
-	ti.cdti_ind0 = 1;
-	ti.cdti_ind1 = 99;
-
-	if ( ioctl(cdfile, CDROMPLAYTRKIND, &ti) == -1 ) 
-    {
-		Con_DPrintf("ioctl cdromplaytrkind failed\n");
-		return;
-    }
-
-	if ( ioctl(cdfile, CDROMRESUME) == -1 ) 
-		Con_DPrintf("ioctl cdromresume failed\n");
-
-	playLooping = looping;
-	playTrack = track;
-	playing = true;
-
-	if (cdvolume == 0.0)
-		CDAudio_Pause ();
-}
-
-
-void CDAudio_Stop(void)
-{
-	if (cdfile == -1 || !enabled)
-		return;
-	
-	if (!playing)
-		return;
-
-	if ( ioctl(cdfile, CDROMSTOP) == -1 )
-		Con_DPrintf("ioctl cdromstop failed (%d)\n", errno);
-
-	wasPlaying = false;
-	playing = false;
-}
-
-void CDAudio_Pause(void)
-{
-	if (cdfile == -1 || !enabled)
-		return;
-
-	if (!playing)
-		return;
-
-	if ( ioctl(cdfile, CDROMPAUSE) == -1 ) 
-		Con_DPrintf("ioctl cdrompause failed\n");
-
-	wasPlaying = playing;
-	playing = false;
-}
-
-
-void CDAudio_Resume(void)
-{
-	if (cdfile == -1 || !enabled)
-		return;
-	
-	if (!cdValid)
-		return;
-
-	if (!wasPlaying)
-		return;
-	
-	if ( ioctl(cdfile, CDROMRESUME) == -1 ) 
-		Con_DPrintf("ioctl cdromresume failed\n");
-	playing = true;
-}
-
-static void CD_f (void)
-{
-	char	*command;
-	int		ret;
-	int		n;
-
-	if (Cmd_Argc() < 2)
-		return;
-
-	command = Cmd_Argv (1);
-
-	if (Q_strcasecmp(command, "on") == 0)
-	{
-		enabled = true;
-		return;
-	}
-
-	if (Q_strcasecmp(command, "off") == 0)
-	{
-		if (playing)
-			CDAudio_Stop();
-		enabled = false;
-		return;
-	}
-
-	if (Q_strcasecmp(command, "reset") == 0)
-	{
-		enabled = true;
-		if (playing)
-			CDAudio_Stop();
-		for (n = 0; n < 100; n++)
-			remap[n] = n;
-		CDAudio_GetAudioDiskInfo();
-		return;
-	}
-
-	if (Q_strcasecmp(command, "remap") == 0)
-	{
-		ret = Cmd_Argc() - 2;
-		if (ret <= 0)
-		{
-			for (n = 1; n < 100; n++)
-				if (remap[n] != n)
-					Con_Printf("  %u -> %u\n", n, remap[n]);
-			return;
-		}
-		for (n = 1; n <= ret; n++)
-			remap[n] = Q_atoi(Cmd_Argv (n+1));
-		return;
-	}
-
-	if (Q_strcasecmp(command, "close") == 0)
-	{
-		CDAudio_CloseDoor();
-		return;
-	}
-
-	if (!cdValid)
-	{
-		CDAudio_GetAudioDiskInfo();
-		if (!cdValid)
-		{
-			Con_Printf("No CD in player.\n");
-			return;
-		}
-	}
-
-	if (Q_strcasecmp(command, "play") == 0)
-	{
-		CDAudio_Play((byte)Q_atoi(Cmd_Argv (2)), false);
-		return;
-	}
-
-	if (Q_strcasecmp(command, "loop") == 0)
-	{
-		CDAudio_Play((byte)Q_atoi(Cmd_Argv (2)), true);
-		return;
-	}
-
-	if (Q_strcasecmp(command, "stop") == 0)
-	{
-		CDAudio_Stop();
-		return;
-	}
-
-	if (Q_strcasecmp(command, "pause") == 0)
-	{
-		CDAudio_Pause();
-		return;
-	}
-
-	if (Q_strcasecmp(command, "resume") == 0)
-	{
-		CDAudio_Resume();
-		return;
-	}
-
-	if (Q_strcasecmp(command, "eject") == 0)
-	{
-		if (playing)
-			CDAudio_Stop();
-		CDAudio_Eject();
-		cdValid = false;
-		return;
-	}
-
-	if (Q_strcasecmp(command, "info") == 0)
-	{
-		Con_Printf("%u tracks\n", maxTrack);
-		if (playing)
-			Con_Printf("Currently %s track %u\n", playLooping ? "looping" : "playing", playTrack);
-		else if (wasPlaying)
-			Con_Printf("Paused %s track %u\n", playLooping ? "looping" : "playing", playTrack);
-		Con_Printf("Volume is %f\n", cdvolume);
-		return;
-	}
-}
-
-void CDAudio_Update(void)
-{
-	struct cdrom_subchnl subchnl;
-	static time_t lastchk;
-
-	if (!enabled)
-		return;
-
-	if (bgmvolume.value != cdvolume)
-	{
-		if (cdvolume)
-		{
-			Cvar_SetValue ("bgmvolume", 0.0);
-			cdvolume = bgmvolume.value;
-			CDAudio_Pause ();
-		}
-		else
-		{
-			Cvar_SetValue ("bgmvolume", 1.0);
-			cdvolume = bgmvolume.value;
-			CDAudio_Resume ();
-		}
-	}
-
-	if (playing && 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");
-			playing = false;
-			return;
-		}
-		if (subchnl.cdsc_audiostatus != CDROM_AUDIO_PLAY &&
-			subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED) {
-			playing = false;
-			if (playLooping)
-				CDAudio_Play(playTrack, true);
-		}
-	}
-}
-
-int CDAudio_Init(void)
-{
-	int i;
-
-	if (cls.state == ca_dedicated)
-		return -1;
-
-	if (COM_CheckParm("-nocdaudio"))
-		return -1;
-
-	if ((i = COM_CheckParm("-cddev")) != 0 && i < com_argc - 1) {
-		strncpy(cd_dev, com_argv[i + 1], sizeof(cd_dev));
-		cd_dev[sizeof(cd_dev) - 1] = 0;
-	}
-
-	if ((cdfile = open(cd_dev, OREAD)) == -1) {
-		Con_Printf("CDAudio_Init: open of \"%s\" failed (%i)\n", cd_dev, errno);
-		cdfile = -1;
-		return -1;
-	}
-
-	for (i = 0; i < 100; i++)
-		remap[i] = i;
-	initialized = true;
-	enabled = true;
-
-	if (CDAudio_GetAudioDiskInfo())
-	{
-		Con_Printf("CDAudio_Init: No CD in player.\n");
-		cdValid = false;
-	}
-
-	Cmd_AddCommand ("cd", CD_f);
-
-	Con_Printf("CD Audio Initialized\n");
-
-	return 0;
-}
-
-
-void CDAudio_Shutdown(void)
-{
-	if (!initialized)
-		return;
-	CDAudio_Stop();
-	close(cdfile);
-	cdfile = -1;
-}
--- a/common.c
+++ b/common.c
@@ -122,7 +122,7 @@
 {
 	int             i;
 	
-	if ( (((intptr)dest | count) & 3) == 0)
+	if ( ((uintptr)dest | count) & 3 == 0)
 	{
 		count >>= 2;
 		fill = fill | (fill<<8) | (fill<<16) | (fill<<24);
@@ -138,7 +138,7 @@
 {
 	int             i;
 	
-	if (( ( (intptr)dest | (intptr)src | count) & 3) == 0 )
+	if (( ( (uintptr)dest | (uintptr)src | count) & 3) == 0 )
 	{
 		count>>=2;
 		for (i=0 ; i<count ; i++)
@@ -166,7 +166,7 @@
 	{
 		*dest++ = *src++;
 	}
-	*dest++ = 0;
+	*dest = 0;
 }
 
 void Q_strncpy (char *dest, char *src, int count)
@@ -176,7 +176,7 @@
 		*dest++ = *src++;
 	}
 	if (count)
-		*dest++ = 0;
+		*dest = 0;
 }
 
 int Q_strlen (char *str)
@@ -216,8 +216,6 @@
 		s1++;
 		s2++;
 	}
-	
-	return -1;
 }
 
 int Q_strncmp (char *s1, char *s2, int count)
@@ -233,8 +231,6 @@
 		s1++;
 		s2++;
 	}
-	
-	return -1;
 }
 
 int Q_strncasecmp (char *s1, char *s2, int n)
@@ -263,8 +259,6 @@
 //              s1++;
 //              s2++;
 	}
-	
-	return -1;
 }
 
 int Q_strcasecmp (char *s1, char *s2)
@@ -326,8 +320,6 @@
 			return val*sign;
 		val = val*10 + c - '0';
 	}
-	
-	return 0;
 }
 
 
@@ -1102,7 +1094,7 @@
 COM_Init
 ================
 */
-void COM_Init (char *basedir)
+void COM_Init (char *) /*basedir*/
 {
 	byte    swaptest[2] = {1,0};
 
--- a/common.h
+++ b/common.h
@@ -44,7 +44,7 @@
 // (type *)STRUCT_FROM_LINK(link_t *link, type, member)
 // ent = STRUCT_FROM_LINK(link,entity_t,order)
 // FIXME: remove this mess!
-#define	STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - (intptr)&(((t *)0)->m)))
+#define	STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - (uintptr)&(((t *)0)->m)))
 
 //============================================================================
 
--- a/console.c
+++ b/console.c
@@ -198,7 +198,7 @@
 		if (strlen (com_gamedir) < (MAXGAMEDIRLEN - strlen (t2)))
 		{
 			sprintf (temp, "%s%s", com_gamedir, t2);
-			unlink (temp);
+			remove (temp);
 		}
 	}
 
@@ -336,7 +336,7 @@
     vsprintf(data, fmt, argptr);
     va_end(argptr);
     /*fd = open(file, OWRITE | O_WRONLY | O_CREAT | O_APPEND, 0666);*/
-    fd = open(file, OWRITE|OAPPEND);
+    fd = open(file, OWRITE);
     write(fd, data, strlen(data));
     close(fd);
 }
--- a/d_edge.c
+++ b/d_edge.c
@@ -173,7 +173,7 @@
 			d_zistepv = s->d_zistepv;
 			d_ziorigin = s->d_ziorigin;
 
-			D_DrawSolidSurface (s, (intptr)s->data & 0xFF);
+			D_DrawSolidSurface (s, (uintptr)s->data & 0xFF);
 			D_DrawZSpans (s->spans);
 		}
 	}
--- a/d_fill.c
+++ b/d_fill.c
@@ -41,7 +41,7 @@
 
 	dest = ((byte *)vid.buffer + ry*vid.rowbytes + rx);
 
-	if (((rwidth & 0x03) == 0) && (((intptr)dest & 0x03) == 0))
+	if (((rwidth & 0x03) == 0) && (((uintptr)dest & 0x03) == 0))
 	{
 	// faster aligned dword clear
 		ldest = (unsigned *)dest;
--- a/d_init.c
+++ b/d_init.c
@@ -59,8 +59,8 @@
 // console); Quake will then draw into wherever the driver points vid.buffer
 // and will call this function before swapping buffers
 
-	UNUSED(prects);
-	UNUSED(transparent);
+	USED(prects);
+	USED(transparent);
 }
 
 
@@ -144,6 +144,6 @@
 
 // the software driver draws these directly to the vid buffer
 
-	UNUSED(prect);
+	USED(prect);
 }
 
--- a/d_polyse.c
+++ b/d_polyse.c
@@ -110,7 +110,7 @@
 						// one extra because of cache line pretouching
 
 	a_spans = (spanpackage_t *)
-			(((intptr)&spans[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
+			(((uintptr)&spans[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
 
 	if (r_affinetridesc.drawtype)
 	{
--- a/d_scan.c
+++ b/d_scan.c
@@ -392,7 +392,7 @@
 	// we count on FP exceptions being turned off to avoid range problems
 		izi = (int)(zi * 0x8000 * 0x10000);
 
-		if ((intptr)pdest & 0x02)
+		if ((uintptr)pdest & 0x02)
 		{
 			*pdest++ = (short)(izi >> 16);
 			izi += izistep;
--- a/d_surf.c
+++ b/d_surf.c
@@ -110,7 +110,7 @@
 D_SCAlloc
 =================
 */
-surfcache_t     *D_SCAlloc (int width, intptr size)
+surfcache_t     *D_SCAlloc (int width, uintptr size)
 {
 	surfcache_t             *new;
 	qboolean                wrapped_this_time;
@@ -121,7 +121,7 @@
 	if ((size <= 0) || (size > 0x10000))
 		Sys_Error ("D_SCAlloc: bad cache size %d\n", size);
 	
-	size = (intptr)&((surfcache_t *)0)->data[size];
+	size = (uintptr)&((surfcache_t *)0)->data[size];
 	size = (size + 3) & ~3;
 	if (size > sc_size)
 		Sys_Error ("D_SCAlloc: %i > cache size",size);
--- a/draw.c
+++ b/draw.c
@@ -527,20 +527,8 @@
 	conback = Draw_CachePic ("gfx/conback.lmp");
 
 // hack the version number directly into the pic
-#ifdef X11
-	sprintf (ver, "(X11 Quake %2.2f) %4.2f", (float)X11_VERSION, (float)VERSION);
+	sprintf (ver, "((9)quake nil) %4.2f", (float)VERSION);
 	dest = conback->data + 320*186 + 320 - 11 - 8*strlen(ver);
-#endif
-/*
-#ifdef __linux__
-	sprintf (ver, "(Linux Quake %2.2f) %4.2f", (float)LINUX_VERSION, (float)VERSION);
-	dest = conback->data + 320*186 + 320 - 11 - 8*strlen(ver);
-#endif
-#ifndef __linux__
-	dest = conback->data + 320 - 43 + 320*186;
-	sprintf (ver, "%4.2f", VERSION);
-#endif
-*/
 
 	for (x=0 ; x<strlen(ver) ; x++)
 		Draw_CharToConback (ver[x], dest+(x<<3));
--- a/host.c
+++ b/host.c
@@ -425,7 +425,7 @@
 	while (count);
 
 // make sure all the clients know we're disconnecting
-	buf.data = message;
+	buf.data = (uchar *)message;
 	buf.maxsize = 4;
 	buf.cursize = 0;
 	MSG_WriteByte(&buf, svc_disconnect);
@@ -798,7 +798,7 @@
 	NET_Init ();
 	SV_Init ();
 
-	Con_Printf ("Exe: "__TIME__" "__DATE__"\n");
+	Con_Printf ("Exe: 00:00:00 Jun 22 1996\n");
 	Con_Printf ("%4.1f megabyte heap\n",parms->memsize/ (1024*1024.0));
 	
 	R_InitTextures ();		// needed even for dedicated servers
--- a/host_cmd.c
+++ b/host_cmd.c
@@ -40,7 +40,7 @@
 	client_t	*client;
 	int			seconds;
 	int			minutes;
-	int			hours = 0;
+	int			hours;
 	int			j;
 	void		(*print) (char *fmt, ...);
 	
@@ -595,7 +595,6 @@
 		if (i == sizeof(str)-1)
 			Sys_Error ("Loadgame buffer overflow");
 		str[i] = 0;
-		start = str;
 		start = COM_Parse(str);
 		if (!com_token[0])
 			break;		// end of file
@@ -687,7 +686,7 @@
 void Host_Version_f (void)
 {
 	Con_Printf ("Version %4.2f\n", VERSION);
-	Con_Printf ("Exe: "__TIME__" "__DATE__"\n");
+	Con_Printf ("Exe: 00:00:00 Jun 22 1996\n");
 }
 
 #ifdef IDGODS
@@ -749,7 +748,7 @@
 	client_t *save;
 	int		j;
 	char	*p;
-	unsigned char	text[64];
+	char	text[64];
 	qboolean	fromServer = false;
 
 	if (cmd_source == src_command)
--- a/menu.c
+++ b/menu.c
@@ -1373,12 +1373,8 @@
 	if (bind_grab)
 	{	// defining a key
 		S_LocalSound ("misc/menu1.wav");
-		if (k == K_ESCAPE)
+		if (k != '`')
 		{
-			bind_grab = false;
-		}
-		else if (k != '`')
-		{
 			sprintf (cmd, "bind \"%s\" \"%s\"\n", Key_KeynumToString (k), bindnames[keys_cursor][0]);
 			Cbuf_InsertText (cmd);
 		}
@@ -2263,9 +2259,7 @@
 			lanConfig_cursor = 0;
 
 	l =  Q_atoi(lanConfig_portname);
-	if (l > 65535)
-		l = lanConfig_port;
-	else
+	if (l < 65535)
 		lanConfig_port = l;
 	sprintf(lanConfig_portname, "%u", lanConfig_port);
 }
@@ -2783,7 +2777,7 @@
 }
 
 
-void M_Search_Key (int key)
+void M_Search_Key (int) /*key*/
 {
 }
 
--- /dev/null
+++ b/menu.h
@@ -1,0 +1,16 @@
+//
+// the net drivers should just set the apropriate bits in m_activenet,
+// instead of having the menu code look through their internal tables
+//
+#define	MNET_IPX		1
+#define	MNET_TCP		2
+
+extern	int	m_activenet;
+
+//
+// menus
+//
+void M_Init (void);
+void M_Keydown (int key);
+void M_Draw (void);
+void M_ToggleMenu_f (void);
--- a/mkfile
+++ b/mkfile
@@ -1,85 +1,81 @@
-<$PLAN9/src/mkhdr
+</$objtype/mkfile
 
-# [words]
-CFLAGS= -D_DEFAULT_SOURCE -Dstricmp=strcasecmp -DX11 -O0 -ggdb -Wall -trigraphs
-LDFLAGS= -lX11 -lXext -lXxf86dga
-AFLAGS= $CFLAGS -DELF -x assembler-with-cpp
-
 BIN=.
 TARG=qk1
 
 OFILES=\
-	cl_demo.o\
-	cl_input.o\
-	cl_main.o\
-	cl_parse.o\
-	cl_tent.o\
-	chase.o\
-	cmd.o\
-	common.o\
-	console.o\
-	crc.o\
-	cvar.o\
-	draw.o\
-	d_edge.o\
-	d_fill.o\
-	d_init.o\
-	d_modech.o\
-	d_part.o\
-	d_polyse.o\
-	d_scan.o\
-	d_sky.o\
-	d_sprite.o\
-	d_surf.o\
-	d_vars.o\
-	d_zpoint.o\
-	host.o\
-	host_cmd.o\
-	keys.o\
-	menu.o\
-	mathlib.o\
-	model.o\
-	net_dgrm.o\
-	net_loop.o\
-	net_main.o\
-	net_vcr.o\
-	net_udp.o\
-	net_bsd.o\
-	nonintel.o\
-	pr_cmds.o\
-	pr_edict.o\
-	pr_exec.o\
-	r_aclip.o\
-	r_alias.o\
-	r_bsp.o\
-	r_light.o\
-	r_draw.o\
-	r_efrag.o\
-	r_edge.o\
-	r_misc.o\
-	r_main.o\
-	r_sky.o\
-	r_sprite.o\
-	r_surf.o\
-	r_part.o\
-	r_vars.o\
-	screen.o\
-	sbar.o\
-	sv_main.o\
-	sv_phys.o\
-	sv_move.o\
-	sv_user.o\
-	zone.o\
-	view.o\
-	wad.o\
-	world.o\
-	cd_linux.o\
-	sys_linux.o\
-	vid_x.o\
-	snd_dma.o\
-	snd_mem.o\
-	snd_mix.o\
-	snd_linux.o\
+	cl_demo.$O\
+	cl_input.$O\
+	cl_main.$O\
+	cl_parse.$O\
+	cl_tent.$O\
+	chase.$O\
+	cmd.$O\
+	common.$O\
+	console.$O\
+	crc.$O\
+	cvar.$O\
+	draw.$O\
+	d_edge.$O\
+	d_fill.$O\
+	d_init.$O\
+	d_modech.$O\
+	d_part.$O\
+	d_polyse.$O\
+	d_scan.$O\
+	d_sky.$O\
+	d_sprite.$O\
+	d_surf.$O\
+	d_vars.$O\
+	d_zpoint.$O\
+	host.$O\
+	host_cmd.$O\
+	keys.$O\
+	menu.$O\
+	mathlib.$O\
+	model.$O\
+	net_loop.$O\
+	net_main.$O\
+	net_vcr.$O\
+	net_dgrm.$O\
+	net_bsd.$O\
+	nonintel.$O\
+	pr_cmds.$O\
+	pr_edict.$O\
+	pr_exec.$O\
+	r_aclip.$O\
+	r_alias.$O\
+	r_bsp.$O\
+	r_light.$O\
+	r_draw.$O\
+	r_efrag.$O\
+	r_edge.$O\
+	r_misc.$O\
+	r_main.$O\
+	r_sky.$O\
+	r_sprite.$O\
+	r_surf.$O\
+	r_part.$O\
+	r_vars.$O\
+	screen.$O\
+	sbar.$O\
+	sv_main.$O\
+	sv_phys.$O\
+	sv_move.$O\
+	sv_user.$O\
+	zone.$O\
+	view.$O\
+	wad.$O\
+	world.$O\
+	snd_dma.$O\
+	snd_mem.$O\
+	snd_mix.$O\
+	in_9.$O\
+	sys_9.$O\
+	vid_9.$O\
+	snd_9.$O\
+	cd_9.$O\
+	net_udp.$O\
 
 HFILES=\
 	adivtab.h\
@@ -98,6 +94,7 @@
 	input.h\
 	keys.h\
 	mathlib.h\
+	menu.h\
 	modelgen.h\
 	model.h\
 	net_dgrm.h\
@@ -125,4 +122,4 @@
 	world.h\
 	zone.h\
 
-<$PLAN9/src/mkone
+</sys/src/cmd/mkone
--- /dev/null
+++ b/mkfile.p9p
@@ -1,0 +1,129 @@
+<$PLAN9/src/mkhdr
+
+# [words]
+CFLAGS= -D_DEFAULT_SOURCE -Dstricmp=strcasecmp -DX11 -O0 -ggdb -Wall -trigraphs
+LDFLAGS= -lX11 -lXext -lXxf86dga
+AFLAGS= $CFLAGS -DELF -x assembler-with-cpp
+
+BIN=.
+TARG=qk1
+
+OFILES=\
+	cl_demo.o\
+	cl_input.o\
+	cl_main.o\
+	cl_parse.o\
+	cl_tent.o\
+	chase.o\
+	cmd.o\
+	common.o\
+	console.o\
+	crc.o\
+	cvar.o\
+	draw.o\
+	d_edge.o\
+	d_fill.o\
+	d_init.o\
+	d_modech.o\
+	d_part.o\
+	d_polyse.o\
+	d_scan.o\
+	d_sky.o\
+	d_sprite.o\
+	d_surf.o\
+	d_vars.o\
+	d_zpoint.o\
+	host.o\
+	host_cmd.o\
+	keys.o\
+	menu.o\
+	mathlib.o\
+	model.o\
+	net_dgrm.o\
+	net_loop.o\
+	net_main.o\
+	net_vcr.o\
+	net_udp.o\
+	net_bsd.o\
+	nonintel.o\
+	pr_cmds.o\
+	pr_edict.o\
+	pr_exec.o\
+	r_aclip.o\
+	r_alias.o\
+	r_bsp.o\
+	r_light.o\
+	r_draw.o\
+	r_efrag.o\
+	r_edge.o\
+	r_misc.o\
+	r_main.o\
+	r_sky.o\
+	r_sprite.o\
+	r_surf.o\
+	r_part.o\
+	r_vars.o\
+	screen.o\
+	sbar.o\
+	sv_main.o\
+	sv_phys.o\
+	sv_move.o\
+	sv_user.o\
+	zone.o\
+	view.o\
+	wad.o\
+	world.o\
+	cd_9.o\
+	sys_9.o\
+	vid_9.o\
+	snd_dma.o\
+	snd_mem.o\
+	snd_mix.o\
+	snd_9.o\
+	in_9.o\
+
+HFILES=\
+	adivtab.h\
+	anorms.h\
+	bspfile.h\
+	cdaudio.h\
+	client.h\
+	cmd.h\
+	common.h\
+	console.h\
+	crc.h\
+	cvar.h\
+	d_iface.h\
+	d_local.h\
+	draw.h\
+	input.h\
+	keys.h\
+	mathlib.h\
+	modelgen.h\
+	model.h\
+	net_dgrm.h\
+	net.h\
+	net_loop.h\
+	net_udp.h\
+	net_vcr.h\
+	pr_comp.h\
+	progdefs.h\
+	progs.h\
+	protocol.h\
+	quakedef.h\
+	render.h\
+	r_local.h\
+	r_shared.h\
+	sbar.h\
+	screen.h\
+	server.h\
+	sound.h\
+	spritegn.h\
+	sys.h\
+	vid.h\
+	view.h\
+	wad.h\
+	world.h\
+	zone.h\
+
+<$PLAN9/src/mkone
--- a/model.c
+++ b/model.c
@@ -85,8 +85,6 @@
 		else
 			node = node->children[1];
 	}
-	
-	return NULL;	// never reached
 }
 
 
--- a/modelgen.h
+++ b/modelgen.h
@@ -27,7 +27,8 @@
 
 #define ALIAS_VERSION	6
 
-#define ALIAS_ONSEAM				0x0020
+/* defined in r_shared.h */
+//#define ALIAS_ONSEAM				0x0020
 
 // must match definition in spritegn.h
 #ifndef SYNCTYPE_T
--- a/net.h
+++ b/net.h
@@ -295,7 +295,7 @@
 {
 	struct _PollProcedure	*next;
 	double					nextTime;
-	void					(*procedure)();
+	void					(*procedure)(void *);
 	void					*arg;
 } PollProcedure;
 
--- a/net_dgrm.c
+++ b/net_dgrm.c
@@ -256,7 +256,7 @@
 }
 
 
-qboolean Datagram_CanSendUnreliableMessage (qsocket_t *sock)
+qboolean Datagram_CanSendUnreliableMessage (qsocket_t *) /*sock*/
 {
 	return true;
 }
@@ -492,10 +492,10 @@
 static int		testDriver;
 static int		testSocket;
 
-static void Test_Poll(void);
+static void Test_Poll(void *);
 PollProcedure	testPollProcedure = {NULL, 0.0, Test_Poll};
 
-static void Test_Poll(void)
+static void Test_Poll(void *)
 {
 	struct qsockaddr clientaddr;
 	int		control;
@@ -620,10 +620,10 @@
 static int		test2Driver;
 static int		test2Socket;
 
-static void Test2_Poll(void);
+static void Test2_Poll(void *);
 PollProcedure	test2PollProcedure = {NULL, 0.0, Test2_Poll};
 
-static void Test2_Poll(void)
+static void Test2_Poll(void *)
 {
 	struct qsockaddr clientaddr;
 	int		control;
--- a/net_loop.c
+++ b/net_loop.c
@@ -20,12 +20,12 @@
 }
 
 
-void Loop_Listen (qboolean state)
+void Loop_Listen (qboolean) /*state*/
 {
 }
 
 
-void Loop_SearchForHosts (qboolean xmit)
+void Loop_SearchForHosts (qboolean) /*xmit*/
 {
 	if (!sv.active)
 		return;
@@ -206,7 +206,7 @@
 }
 
 
-qboolean Loop_CanSendUnreliableMessage (qsocket_t *sock)
+qboolean Loop_CanSendUnreliableMessage (qsocket_t *) /*sock*/
 {
 	return true;
 }
--- a/net_main.c
+++ b/net_main.c
@@ -30,8 +30,8 @@
 static double	slistStartTime;
 static int		slistLastShown;
 
-static void Slist_Send(void);
-static void Slist_Poll(void);
+static void Slist_Send(void *);
+static void Slist_Poll(void *);
 PollProcedure	slistSendProcedure = {NULL, 0.0, Slist_Send};
 PollProcedure	slistPollProcedure = {NULL, 0.0, Slist_Poll};
 
@@ -293,7 +293,7 @@
 }
 
 
-static void Slist_Send(void)
+static void Slist_Send(void *)
 {
 	for (net_driverlevel=0; net_driverlevel < net_numdrivers; net_driverlevel++)
 	{
@@ -309,7 +309,7 @@
 }
 
 
-static void Slist_Poll(void)
+static void Slist_Poll(void *)
 {
 	for (net_driverlevel=0; net_driverlevel < net_numdrivers; net_driverlevel++)
 	{
@@ -432,7 +432,7 @@
 {
 	double	time;
 	int		op;
-	intptr	session;
+	int	session;
 } vcrConnect;
 
 qsocket_t *NET_CheckNewConnections (void)
@@ -454,7 +454,7 @@
 			{
 				vcrConnect.time = host_time;
 				vcrConnect.op = VCR_OP_CONNECT;
-				vcrConnect.session = (intptr)ret;
+				vcrConnect.session = (int)ret;
 				Sys_FileWrite (vcrFile, &vcrConnect, sizeof(vcrConnect));
 				Sys_FileWrite (vcrFile, ret->address, NET_NAMELEN);
 			}
@@ -511,7 +511,8 @@
 {
 	double	time;
 	int		op;
-	intptr	session;
+	/* FIXME: different size -> vcr problems? */
+	uintptr	session;
 	int		ret;
 	int		len;
 } vcrGetMessage;
@@ -561,7 +562,7 @@
 		{
 			vcrGetMessage.time = host_time;
 			vcrGetMessage.op = VCR_OP_GETMESSAGE;
-			vcrGetMessage.session = (intptr)sock;
+			vcrGetMessage.session = (uintptr)sock;
 			vcrGetMessage.ret = ret;
 			vcrGetMessage.len = net_message.cursize;
 			Sys_FileWrite (vcrFile, &vcrGetMessage, 24);
@@ -574,7 +575,7 @@
 		{
 			vcrGetMessage.time = host_time;
 			vcrGetMessage.op = VCR_OP_GETMESSAGE;
-			vcrGetMessage.session = (intptr)sock;
+			vcrGetMessage.session = (uintptr)sock;
 			vcrGetMessage.ret = ret;
 			Sys_FileWrite (vcrFile, &vcrGetMessage, 20);
 		}
@@ -599,7 +600,8 @@
 {
 	double	time;
 	int		op;
-	intptr	session;
+	/* FIXME: different size -> vcr problems? */
+	uintptr	session;
 	int		r;
 } vcrSendMessage;
 
@@ -625,7 +627,7 @@
 	{
 		vcrSendMessage.time = host_time;
 		vcrSendMessage.op = VCR_OP_SENDMESSAGE;
-		vcrSendMessage.session = (intptr)sock;
+		vcrSendMessage.session = (uintptr)sock;
 		vcrSendMessage.r = r;
 		Sys_FileWrite (vcrFile, &vcrSendMessage, 20);
 	}
@@ -656,7 +658,7 @@
 	{
 		vcrSendMessage.time = host_time;
 		vcrSendMessage.op = VCR_OP_SENDMESSAGE;
-		vcrSendMessage.session = (intptr)sock;
+		vcrSendMessage.session = (uintptr)sock;
 		vcrSendMessage.r = r;
 		Sys_FileWrite (vcrFile, &vcrSendMessage, 20);
 	}
@@ -691,7 +693,7 @@
 	{
 		vcrSendMessage.time = host_time;
 		vcrSendMessage.op = VCR_OP_CANSENDMESSAGE;
-		vcrSendMessage.session = (intptr)sock;
+		vcrSendMessage.session = (uintptr)sock;
 		vcrSendMessage.r = r;
 		Sys_FileWrite (vcrFile, &vcrSendMessage, 20);
 	}
--- a/net_udp.c
+++ b/net_udp.c
@@ -7,7 +7,6 @@
 typedef uintptr_t uintptr;
 typedef uint32_t u32int;
 
-
 #include "quakedef.h"
 
 #include <sys/types.h>
--- a/net_vcr.c
+++ b/net_vcr.c
@@ -14,7 +14,7 @@
 {
 	double	time;
 	int		op;
-	intptr	session;
+	int	session;
 }	next;
 
 int VCR_Init (void)
@@ -46,7 +46,7 @@
 }
 
 
-void VCR_Listen (qboolean state)
+void VCR_Listen (qboolean) /*state*/
 {
 }
 
@@ -60,7 +60,7 @@
 {
 	int	ret;
 	
-	if (host_time != next.time || next.op != VCR_OP_GETMESSAGE || next.session != *(s32int *)(&sock->driverdata))
+	if (host_time != next.time || next.op != VCR_OP_GETMESSAGE || next.session != *(int *)(&sock->driverdata))
 		Sys_Error ("VCR missmatch");
 
 	Sys_FileRead(vcrFile, &ret, sizeof(int));
@@ -79,11 +79,11 @@
 }
 
 
-int VCR_SendMessage (qsocket_t *sock, sizebuf_t *data)
+int VCR_SendMessage (qsocket_t *sock, sizebuf_t *) /*data*/
 {
 	int	ret;
 
-	if (host_time != next.time || next.op != VCR_OP_SENDMESSAGE || next.session != *(s32int *)(&sock->driverdata))
+	if (host_time != next.time || next.op != VCR_OP_SENDMESSAGE || next.session != *(int *)(&sock->driverdata))
 		Sys_Error ("VCR missmatch");
 
 	Sys_FileRead(vcrFile, &ret, sizeof(int));
@@ -98,7 +98,7 @@
 {
 	qboolean	ret;
 
-	if (host_time != next.time || next.op != VCR_OP_CANSENDMESSAGE || next.session != *(s32int *)(&sock->driverdata))
+	if (host_time != next.time || next.op != VCR_OP_CANSENDMESSAGE || next.session != *(int *)(&sock->driverdata))
 		Sys_Error ("VCR missmatch");
 
 	Sys_FileRead(vcrFile, &ret, sizeof(int));
@@ -109,17 +109,17 @@
 }
 
 
-void VCR_Close (qsocket_t *sock)
+void VCR_Close (qsocket_t *) /*sock*/
 {
 }
 
 
-void VCR_SearchForHosts (qboolean xmit)
+void VCR_SearchForHosts (qboolean) /*xmit*/
 {
 }
 
 
-qsocket_t *VCR_Connect (char *host)
+qsocket_t *VCR_Connect (char *) /*host*/
 {
 	return NULL;
 }
@@ -139,7 +139,7 @@
 	}
 
 	sock = NET_NewQSocket ();
-	*(s32int *)(&sock->driverdata) = next.session;
+	*(int *)(&sock->driverdata) = next.session;
 
 	Sys_FileRead (vcrFile, sock->address, NET_NAMELEN);
 	VCR_ReadNext ();
--- a/pr_edict.c
+++ b/pr_edict.c
@@ -231,7 +231,7 @@
 
 eval_t *GetEdictFieldValue(edict_t *ed, char *field)
 {
-	ddef_t			*def = NULL;
+	ddef_t			*def;
 	int				i;
 	static int		rep = 0;
 
@@ -254,8 +254,8 @@
 	}
 
 Done:
-	if (!def)
-		return NULL;
+	if (def == nil)
+		return nil;
 
 	return (eval_t *)((char *)&ed->v + def->ofs*4);
 }
--- a/quakedef.h
+++ b/quakedef.h
@@ -1,11 +1,7 @@
 // quakedef.h -- primary header for client
 
 #define	QUAKE_GAME			// as opposed to utilities
-
 #define	VERSION				1.09
-#define	LINUX_VERSION		1.30
-#define	X11_VERSION			1.10
-
 //#define	PARANOID			// speed sapping error checking
 #define	GAMENAME	"id1"		// directory to look in by default
 
@@ -26,8 +22,7 @@
 // !!! if this is changed, it must be changed in d_ifacea.h too !!!
 #define CACHE_SIZE	32		// used to align key data structures
 
-#define UNUSED(x)	(x = x)	// for pesky compiler / lint warnings
-
+/* FIXME? wrong on !386? */
 #define	MINIMUM_MEMORY			0x550000
 #define	MINIMUM_MEMORY_LEVELPAK	(MINIMUM_MEMORY + 0x100000)
 
--- a/r_alias.c
+++ b/r_alias.c
@@ -689,7 +689,7 @@
 
 // cache align
 	pfinalverts = (finalvert_t *)
-			(((intptr)&finalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
+			(((uintptr)&finalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
 	pauxverts = &auxverts[0];
 
 	paliashdr = (aliashdr_t *)Mod_Extradata (currententity->model);
--- a/r_edge.c
+++ b/r_edge.c
@@ -267,7 +267,7 @@
 R_CleanupSpan
 ==============
 */
-void R_CleanupSpan ()
+void R_CleanupSpan (void)
 {
 	surf_t	*surf;
 	int		iu;
@@ -632,7 +632,7 @@
 	surf_t	*s;
 
 	basespan_p = (espan_t *)
-			((intptr)(basespans + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
+			((uintptr)(basespans + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
 	max_span_p = &basespan_p[MAXSPANS - r_refdef.vrect.width];
 
 	span_p = basespan_p;
--- a/r_main.c
+++ b/r_main.c
@@ -840,13 +840,13 @@
 	else
 	{
 		r_edges =  (edge_t *)
-				(((intptr)&ledges[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
+				(((uintptr)&ledges[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
 	}
 
 	if (r_surfsonstack)
 	{
 		surfaces =  (surf_t *)
-				(((intptr)&lsurfs[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
+				(((uintptr)&lsurfs[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
 		surf_max = &surfaces[r_cnumsurfs];
 	// surface 0 doesn't really exist; it's just a dummy because index 0
 	// is used to indicate no edge attached to surface
@@ -1012,10 +1012,10 @@
 	if ( Hunk_LowMark() & 3 )
 		Sys_Error ("Hunk is missaligned");
 
-	if ( (intptr)(&dummy) & 3 )
+	if ( (uintptr)(&dummy) & 3 )
 		Sys_Error ("Stack is missaligned");
 
-	if ( (intptr)(&r_warpbuffer) & 3 )
+	if ( (uintptr)(&r_warpbuffer) & 3 )
 		Sys_Error ("Globals are missaligned");
 
 	R_RenderView_ ();
--- a/r_part.c
+++ b/r_part.c
@@ -63,16 +63,14 @@
 
 void R_EntityParticles (entity_t *ent)
 {
-	int			count;
 	int			i;
 	particle_t	*p;
 	float		angle;
-	float		sr, sp, sy, cr, cp, cy;
+	float		sp, sy, cp, cy;
 	vec3_t		forward;
 	float		dist;
 	
 	dist = 64;
-	count = 50;
 
 if (!avelocities[0][0])
 {
@@ -89,9 +87,6 @@
 		angle = cl.time * avelocities[i][1];
 		sp = sin(angle);
 		cp = cos(angle);
-		angle = cl.time * avelocities[i][2];
-		sr = sin(angle);
-		cr = cos(angle);
 	
 		forward[0] = cp*cy;
 		forward[1] = cp*sy;
--- a/r_sprite.c
+++ b/r_sprite.c
@@ -114,7 +114,7 @@
 R_SetupAndDrawSprite
 ================
 */
-void R_SetupAndDrawSprite ()
+void R_SetupAndDrawSprite (void)
 {
 	int			i, nump;
 	float		dot, scale, *pv;
--- a/r_surf.c
+++ b/r_surf.c
@@ -540,7 +540,7 @@
 		pbasesource += sourcetstep;
 		lightright += lightrightstep;
 		lightleft += lightleftstep;
-		prowdest = (unsigned short *)((intptr)prowdest + surfrowbytes);
+		prowdest = (ushort *)((uintptr)prowdest + surfrowbytes);
 	}
 
 	prowdestbase = prowdest;
--- a/server.h
+++ b/server.h
@@ -200,5 +200,5 @@
 
 void SV_CheckForNewClients (void);
 void SV_RunClients (void);
-void SV_SaveSpawnparms ();
+void SV_SaveSpawnparms (void);
 void SV_SpawnServer (char *server);
--- /dev/null
+++ b/snd_9.c
@@ -1,0 +1,253 @@
+#include <u.h>
+#include <libc.h>
+//#include <unistd.h>
+//#include <fcntl.h>
+//#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/shm.h>
+//#include <sys/wait.h>
+#include <linux/soundcard.h>
+//#include <stdio.h>
+
+#include "quakedef.h"
+
+int audio_fd;
+int snd_inited;
+
+static int tryrates[] = { 11025, 22051, 44100, 8000 };
+
+qboolean SNDDMA_Init(void)
+{
+
+	int rc;
+    int fmt;
+	int tmp;
+    int i;
+    char *s;
+	struct audio_buf_info info;
+	int caps;
+
+	snd_inited = 0;
+
+// open /dev/dsp, confirm capability to mmap, and get size of dma buffer
+
+    audio_fd = open("/dev/dsp", OREAD);
+    if (audio_fd < 0)
+	{
+		perror("/dev/dsp");
+        Con_Printf("Could not open /dev/dsp\n");
+		return 0;
+	}
+
+    rc = ioctl(audio_fd, SNDCTL_DSP_RESET, 0);
+    if (rc < 0)
+	{
+		perror("/dev/dsp");
+		Con_Printf("Could not reset /dev/dsp\n");
+		close(audio_fd);
+		return 0;
+	}
+
+	if (ioctl(audio_fd, SNDCTL_DSP_GETCAPS, &caps)==-1)
+	{
+		perror("/dev/dsp");
+        Con_Printf("Sound driver too old\n");
+		close(audio_fd);
+		return 0;
+	}
+
+	if (!(caps & DSP_CAP_TRIGGER) || !(caps & DSP_CAP_MMAP))
+	{
+		Con_Printf("Sorry but your soundcard can't do this\n");
+		close(audio_fd);
+		return 0;
+	}
+
+    if (ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info)==-1)
+    {   
+        perror("GETOSPACE");
+		Con_Printf("Um, can't do GETOSPACE?\n");
+		close(audio_fd);
+		return 0;
+    }
+    
+	shm = &sn;
+    shm->splitbuffer = 0;
+
+// set sample bits & speed
+
+    s = getenv("QUAKE_SOUND_SAMPLEBITS");
+    if (s) shm->samplebits = atoi(s);
+	else if ((i = COM_CheckParm("-sndbits")) != 0)
+		shm->samplebits = atoi(com_argv[i+1]);
+	if (shm->samplebits != 16 && shm->samplebits != 8)
+    {
+        ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &fmt);
+        if (fmt & AFMT_S16_LE) shm->samplebits = 16;
+        else if (fmt & AFMT_U8) shm->samplebits = 8;
+    }
+
+    s = getenv("QUAKE_SOUND_SPEED");
+    if (s) shm->speed = atoi(s);
+	else if ((i = COM_CheckParm("-sndspeed")) != 0)
+		shm->speed = atoi(com_argv[i+1]);
+    else
+    {
+        for (i=0 ; i<sizeof(tryrates)/4 ; i++)
+            if (!ioctl(audio_fd, SNDCTL_DSP_SPEED, &tryrates[i])) break;
+        shm->speed = tryrates[i];
+    }
+
+    s = getenv("QUAKE_SOUND_CHANNELS");
+    if (s) shm->channels = atoi(s);
+	else if ((i = COM_CheckParm("-sndmono")) != 0)
+		shm->channels = 1;
+	else if ((i = COM_CheckParm("-sndstereo")) != 0)
+		shm->channels = 2;
+    else shm->channels = 2;
+
+	shm->samples = info.fragstotal * info.fragsize / (shm->samplebits/8);
+	shm->submission_chunk = 1;
+
+// memory map the dma buffer
+
+	shm->buffer = (unsigned char *) mmap(NULL, info.fragstotal
+		* info.fragsize, PROT_WRITE, 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");
+		close(audio_fd);
+		return 0;
+	}
+
+	tmp = 0;
+	if (shm->channels == 2)
+		tmp = 1;
+    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);
+		close(audio_fd);
+        return 0;
+    }
+	if (tmp)
+		shm->channels = 2;
+	else
+		shm->channels = 1;
+
+    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);
+		close(audio_fd);
+        return 0;
+    }
+
+    if (shm->samplebits == 16)
+    {
+        rc = AFMT_S16_LE;
+        rc = ioctl(audio_fd, SNDCTL_DSP_SETFMT, &rc);
+        if (rc < 0)
+		{
+			perror("/dev/dsp");
+			Con_Printf("Could not support 16-bit data.  Try 8-bit.\n");
+			close(audio_fd);
+			return 0;
+		}
+    }
+    else if (shm->samplebits == 8)
+    {
+        rc = AFMT_U8;
+        rc = ioctl(audio_fd, SNDCTL_DSP_SETFMT, &rc);
+        if (rc < 0)
+		{
+			perror("/dev/dsp");
+			Con_Printf("Could not support 8-bit data.\n");
+			close(audio_fd);
+			return 0;
+		}
+    }
+	else
+	{
+		perror("/dev/dsp");
+		Con_Printf("%d-bit sound not supported.", shm->samplebits);
+		close(audio_fd);
+		return 0;
+	}
+
+// toggle the trigger & start her up
+
+    tmp = 0;
+    rc  = ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp);
+	if (rc < 0)
+	{
+		perror("/dev/dsp");
+		Con_Printf("Could not toggle.\n");
+		close(audio_fd);
+		return 0;
+	}
+    tmp = PCM_ENABLE_OUTPUT;
+    rc = ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp);
+	if (rc < 0)
+	{
+		perror("/dev/dsp");
+		Con_Printf("Could not toggle.\n");
+		close(audio_fd);
+		return 0;
+	}
+
+	shm->samplepos = 0;
+
+	snd_inited = 1;
+	return 1;
+
+}
+
+int SNDDMA_GetDMAPos(void)
+{
+
+	struct count_info count;
+
+	if (!snd_inited) return 0;
+
+	if (ioctl(audio_fd, SNDCTL_DSP_GETOPTR, &count)==-1)
+	{
+		perror("/dev/dsp");
+		Con_Printf("Uh, sound dead.\n");
+		close(audio_fd);
+		snd_inited = 0;
+		return 0;
+	}
+//	shm->samplepos = (count.bytes / (shm->samplebits / 8)) & (shm->samples-1);
+//	fprintf(stderr, "%d    \r", count.ptr);
+	shm->samplepos = count.ptr / (shm->samplebits / 8);
+
+	return shm->samplepos;
+
+}
+
+void SNDDMA_Shutdown(void)
+{
+	if (snd_inited)
+	{
+		close(audio_fd);
+		snd_inited = 0;
+	}
+}
+
+/*
+==============
+SNDDMA_Submit
+
+Send sound to device if buffer isn't really the dma buffer
+===============
+*/
+void SNDDMA_Submit(void)
+{
+}
+
--- a/snd_dma.c
+++ b/snd_dma.c
@@ -7,7 +7,7 @@
 void S_Play(void);
 void S_PlayVol(void);
 void S_SoundList(void);
-void S_Update_();
+void S_Update_(void);
 void S_StopAllSounds(qboolean clear);
 void S_StopAllSoundsC(void);
 
@@ -375,10 +375,9 @@
 void SND_Spatialize(channel_t *ch)
 {
     vec_t dot;
-    vec_t ldist, rdist, dist;
+    vec_t dist;
     vec_t lscale, rscale, scale;
     vec3_t source_vec;
-	sfx_t *snd;
 
 // anything coming from the view entity will allways be full volume
 	if (ch->entnum == cl.viewentity)
@@ -390,7 +389,6 @@
 
 // calculate stereo seperation and distance attenuation
 
-	snd = ch->sfx;
 	VectorSubtract(ch->origin, listener_origin, source_vec);
 	
 	dist = VectorNormalize(source_vec) * ch->dist_mult;
--- a/snd_linux.c
+++ /dev/null
@@ -1,252 +1,0 @@
-#include <u.h>
-#include <libc.h>
-//#include <unistd.h>
-//#include <fcntl.h>
-//#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <sys/shm.h>
-//#include <sys/wait.h>
-#include <linux/soundcard.h>
-//#include <stdio.h>
-#include "quakedef.h"
-
-int audio_fd;
-int snd_inited;
-
-static int tryrates[] = { 11025, 22051, 44100, 8000 };
-
-qboolean SNDDMA_Init(void)
-{
-
-	int rc;
-    int fmt;
-	int tmp;
-    int i;
-    char *s;
-	struct audio_buf_info info;
-	int caps;
-
-	snd_inited = 0;
-
-// open /dev/dsp, confirm capability to mmap, and get size of dma buffer
-
-    audio_fd = open("/dev/dsp", OREAD);
-    if (audio_fd < 0)
-	{
-		perror("/dev/dsp");
-        Con_Printf("Could not open /dev/dsp\n");
-		return 0;
-	}
-
-    rc = ioctl(audio_fd, SNDCTL_DSP_RESET, 0);
-    if (rc < 0)
-	{
-		perror("/dev/dsp");
-		Con_Printf("Could not reset /dev/dsp\n");
-		close(audio_fd);
-		return 0;
-	}
-
-	if (ioctl(audio_fd, SNDCTL_DSP_GETCAPS, &caps)==-1)
-	{
-		perror("/dev/dsp");
-        Con_Printf("Sound driver too old\n");
-		close(audio_fd);
-		return 0;
-	}
-
-	if (!(caps & DSP_CAP_TRIGGER) || !(caps & DSP_CAP_MMAP))
-	{
-		Con_Printf("Sorry but your soundcard can't do this\n");
-		close(audio_fd);
-		return 0;
-	}
-
-    if (ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info)==-1)
-    {   
-        perror("GETOSPACE");
-		Con_Printf("Um, can't do GETOSPACE?\n");
-		close(audio_fd);
-		return 0;
-    }
-    
-	shm = &sn;
-    shm->splitbuffer = 0;
-
-// set sample bits & speed
-
-    s = getenv("QUAKE_SOUND_SAMPLEBITS");
-    if (s) shm->samplebits = atoi(s);
-	else if ((i = COM_CheckParm("-sndbits")) != 0)
-		shm->samplebits = atoi(com_argv[i+1]);
-	if (shm->samplebits != 16 && shm->samplebits != 8)
-    {
-        ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &fmt);
-        if (fmt & AFMT_S16_LE) shm->samplebits = 16;
-        else if (fmt & AFMT_U8) shm->samplebits = 8;
-    }
-
-    s = getenv("QUAKE_SOUND_SPEED");
-    if (s) shm->speed = atoi(s);
-	else if ((i = COM_CheckParm("-sndspeed")) != 0)
-		shm->speed = atoi(com_argv[i+1]);
-    else
-    {
-        for (i=0 ; i<sizeof(tryrates)/4 ; i++)
-            if (!ioctl(audio_fd, SNDCTL_DSP_SPEED, &tryrates[i])) break;
-        shm->speed = tryrates[i];
-    }
-
-    s = getenv("QUAKE_SOUND_CHANNELS");
-    if (s) shm->channels = atoi(s);
-	else if ((i = COM_CheckParm("-sndmono")) != 0)
-		shm->channels = 1;
-	else if ((i = COM_CheckParm("-sndstereo")) != 0)
-		shm->channels = 2;
-    else shm->channels = 2;
-
-	shm->samples = info.fragstotal * info.fragsize / (shm->samplebits/8);
-	shm->submission_chunk = 1;
-
-// memory map the dma buffer
-
-	shm->buffer = (unsigned char *) mmap(NULL, info.fragstotal
-		* info.fragsize, PROT_WRITE, 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");
-		close(audio_fd);
-		return 0;
-	}
-
-	tmp = 0;
-	if (shm->channels == 2)
-		tmp = 1;
-    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);
-		close(audio_fd);
-        return 0;
-    }
-	if (tmp)
-		shm->channels = 2;
-	else
-		shm->channels = 1;
-
-    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);
-		close(audio_fd);
-        return 0;
-    }
-
-    if (shm->samplebits == 16)
-    {
-        rc = AFMT_S16_LE;
-        rc = ioctl(audio_fd, SNDCTL_DSP_SETFMT, &rc);
-        if (rc < 0)
-		{
-			perror("/dev/dsp");
-			Con_Printf("Could not support 16-bit data.  Try 8-bit.\n");
-			close(audio_fd);
-			return 0;
-		}
-    }
-    else if (shm->samplebits == 8)
-    {
-        rc = AFMT_U8;
-        rc = ioctl(audio_fd, SNDCTL_DSP_SETFMT, &rc);
-        if (rc < 0)
-		{
-			perror("/dev/dsp");
-			Con_Printf("Could not support 8-bit data.\n");
-			close(audio_fd);
-			return 0;
-		}
-    }
-	else
-	{
-		perror("/dev/dsp");
-		Con_Printf("%d-bit sound not supported.", shm->samplebits);
-		close(audio_fd);
-		return 0;
-	}
-
-// toggle the trigger & start her up
-
-    tmp = 0;
-    rc  = ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp);
-	if (rc < 0)
-	{
-		perror("/dev/dsp");
-		Con_Printf("Could not toggle.\n");
-		close(audio_fd);
-		return 0;
-	}
-    tmp = PCM_ENABLE_OUTPUT;
-    rc = ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp);
-	if (rc < 0)
-	{
-		perror("/dev/dsp");
-		Con_Printf("Could not toggle.\n");
-		close(audio_fd);
-		return 0;
-	}
-
-	shm->samplepos = 0;
-
-	snd_inited = 1;
-	return 1;
-
-}
-
-int SNDDMA_GetDMAPos(void)
-{
-
-	struct count_info count;
-
-	if (!snd_inited) return 0;
-
-	if (ioctl(audio_fd, SNDCTL_DSP_GETOPTR, &count)==-1)
-	{
-		perror("/dev/dsp");
-		Con_Printf("Uh, sound dead.\n");
-		close(audio_fd);
-		snd_inited = 0;
-		return 0;
-	}
-//	shm->samplepos = (count.bytes / (shm->samplebits / 8)) & (shm->samples-1);
-//	fprintf(stderr, "%d    \r", count.ptr);
-	shm->samplepos = count.ptr / (shm->samplebits / 8);
-
-	return shm->samplepos;
-
-}
-
-void SNDDMA_Shutdown(void)
-{
-	if (snd_inited)
-	{
-		close(audio_fd);
-		snd_inited = 0;
-	}
-}
-
-/*
-==============
-SNDDMA_Submit
-
-Send sound to device if buffer isn't really the dma buffer
-===============
-*/
-void SNDDMA_Submit(void)
-{
-}
-
--- a/snd_mem.c
+++ b/snd_mem.c
@@ -154,7 +154,8 @@
 
 short GetLittleShort(void)
 {
-	short val = 0;
+	short val;
+
 	val = *data_p;
 	val = val + (*(data_p+1)<<8);
 	data_p += 2;
@@ -163,7 +164,8 @@
 
 int GetLittleLong(void)
 {
-	int val = 0;
+	int val;
+
 	val = *data_p;
 	val = val + (*(data_p+1)<<8);
 	val = val + (*(data_p+2)<<16);
@@ -195,7 +197,7 @@
 //			Sys_Error ("FindNextChunk: %i length is past the 1 meg sanity limit", iff_chunk_len);
 		data_p -= 8;
 		last_chunk = data_p + 8 + ( (iff_chunk_len + 1) & ~1 );
-		if (!Q_strncmp(data_p, name, 4))
+		if (!Q_strncmp((char *)data_p, name, 4))
 			return;
 	}
 }
@@ -218,7 +220,7 @@
 		memcpy (str, data_p, 4);
 		data_p += 4;
 		iff_chunk_len = GetLittleLong();
-		Con_Printf ("0x%x : %s (%d)\n", (intptr)(data_p - 4), str, iff_chunk_len);
+		Con_Printf ("0x%x : %s (%d)\n", (uintptr)(data_p - 4), str, iff_chunk_len);
 		data_p += (iff_chunk_len + 1) & ~1;
 	} while (data_p < iff_end);
 }
@@ -245,7 +247,7 @@
 
 // find "RIFF" chunk
 	FindChunk("RIFF");
-	if (!(data_p && !Q_strncmp(data_p+8, "WAVE", 4)))
+	if (!(data_p && !Q_strncmp((char *)data_p+8, "WAVE", 4)))
 	{
 		Con_Printf("Missing RIFF/WAVE chunks\n");
 		return info;
@@ -286,7 +288,7 @@
 		FindNextChunk ("LIST");
 		if (data_p)
 		{
-			if (!strncmp (data_p + 28, "mark", 4))
+			if (!strncmp ((char *)data_p+28, "mark", 4))
 			{	// this is not a proper parse, but it works with cooledit...
 				data_p += 24;
 				i = GetLittleLong ();	// samples in loop
--- a/snd_mix.c
+++ b/snd_mix.c
@@ -229,9 +229,9 @@
 void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int count)
 {
 	int 	data;
-	int		*lscale, *rscale;
-	unsigned char *sfx;
-	int		i;
+	int	*lscale, *rscale;
+	uchar	*sfx;
+	int	i;
 
 	if (ch->leftvol > 255)
 		ch->leftvol = 255;
@@ -240,7 +240,7 @@
 		
 	lscale = snd_scaletable[ch->leftvol >> 3];
 	rscale = snd_scaletable[ch->rightvol >> 3];
-	sfx = (signed char *)sc->data + ch->pos;
+	sfx = (uchar *)((uintptr)sc->data + (uintptr)ch->pos);
 
 	for (i=0 ; i<count ; i++)
 	{
--- a/sv_main.c
+++ b/sv_main.c
@@ -956,7 +956,7 @@
 */
 void SV_SendReconnect (void)
 {
-	char	data[128];
+	uchar	data[128];
 	sizebuf_t	msg;
 
 	msg.data = data;
--- /dev/null
+++ b/sys_9.c
@@ -1,0 +1,451 @@
+#include <u.h>
+#include <libc.h>
+//#include <unistd.h>
+#include <signal.h>
+//#include <stdlib.h>
+//#include <limits.h>
+#include <sys/time.h>
+#include <sys/types.h>
+//#include <unistd.h>
+//#include <fcntl.h>
+//#include <stdarg.h>
+//#include <stdio.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/stat.h>
+//#include <string.h>
+//#include <ctype.h>
+//#include <sys/wait.h>
+#include <sys/mman.h>
+#include <errno.h>
+
+#include "quakedef.h"
+
+qboolean			isDedicated;
+
+int nostdout = 0;
+
+char *basedir = ".";
+char *cachedir = "/tmp";
+
+cvar_t  sys_linerefresh = {"sys_linerefresh","0"};// set for entity display
+
+// =======================================================================
+// General routines
+// =======================================================================
+
+void Sys_DebugNumber(int y, int val)
+{
+}
+
+/*
+void Sys_Printf (char *fmt, ...)
+{
+	va_list		argptr;
+	char		text[1024];
+	
+	va_start (argptr,fmt);
+	vsprintf (text,fmt,argptr);
+	va_end (argptr);
+	fprintf(stderr, "%s", text);
+	
+	Con_Print (text);
+}
+
+void Sys_Printf (char *fmt, ...)
+{
+
+    va_list     argptr;
+    char        text[1024], *t_p;
+    int         l, r;
+
+	if (nostdout)
+		return;
+
+    va_start (argptr,fmt);
+    vsprintf (text,fmt,argptr);
+    va_end (argptr);
+
+    l = strlen(text);
+    t_p = text;
+
+// make sure everything goes through, even though we are non-blocking
+    while (l)
+    {
+        r = write (1, text, l);
+        if (r != l)
+            sleep (0);
+        if (r > 0)
+        {
+            t_p += r;
+            l -= r;
+        }
+    }
+
+}
+*/
+
+void Sys_Printf (char *fmt, ...)
+{
+	va_list		argptr;
+	char		text[1024];
+	unsigned char		*p;
+
+	va_start (argptr,fmt);
+	vsprintf (text,fmt,argptr);
+	va_end (argptr);
+
+	if (strlen(text) > sizeof(text))
+		Sys_Error("memory overwrite in Sys_Printf");
+
+    if (nostdout)
+        return;
+
+	for (p = (unsigned char *)text; *p; p++) {
+		*p &= 0x7f;
+		if ((*p > 128 || *p < 32) && *p != 10 && *p != 13 && *p != 9)
+			printf("[%02x]", *p);
+		else
+			putc(*p, stdout);
+	}
+}
+
+/*
+static char end1[] =
+"\x1b[?7h\x1b[40m\x1b[2J\x1b[0;1;41m\x1b[1;1H                QUAKE: The Doomed Dimension \x1b[33mby \x1b[44mid\x1b[41m Software                      \x1b[2;1H  ----------------------------------------------------------------------------  \x1b[3;1H           CALL 1-800-IDGAMES TO ORDER OR FOR TECHNICAL SUPPORT                 \x1b[4;1H             PRICE: $45.00 (PRICES MAY VARY OUTSIDE THE US.)                    \x1b[5;1H                                                                                \x1b[6;1H  \x1b[37mYes! You only have one fourth of this incredible epic. That is because most   \x1b[7;1H   of you have paid us nothing or at most, very little. You could steal the     \x1b[8;1H   game from a friend. But we both know you'll be punished by God if you do.    \x1b[9;1H        \x1b[33mWHY RISK ETERNAL DAMNATION? CALL 1-800-IDGAMES AND BUY NOW!             \x1b[10;1H             \x1b[37mRemember, we love you almost as much as He does.                   \x1b[11;1H                                                                                \x1b[12;1H            \x1b[33mProgramming: \x1b[37mJohn Carmack, Michael Abrash, John Cash                \x1b[13;1H       \x1b[33mDesign: \x1b[37mJohn Romero, Sandy Petersen, American McGee, Tim Willits         \x1b[14;1H                     \x1b[33mArt: \x1b[37mAdrian Carmack, Kevin Cloud                           \x1b[15;1H               \x1b[33mBiz: \x1b[37mJay Wilbur, Mike Wilson, Donna Jackson                      \x1b[16;1H            \x1b[33mProjects: \x1b[37mShawn Green   \x1b[33mSupport: \x1b[37mBarrett Alexander                  \x1b[17;1H              \x1b[33mSound Effects: \x1b[37mTrent Reznor and Nine Inch Nails                   \x1b[18;1H  For other information or details on ordering outside the US, check out the    \x1b[19;1H     files accompanying QUAKE or our website at http://www.idsoftware.com.      \x1b[20;1H    \x1b[0;41mQuake is a trademark of Id Software, inc., (c)1996 Id Software, inc.        \x1b[21;1H     All rights reserved. NIN logo is a registered trademark licensed to        \x1b[22;1H                 Nothing Interactive, Inc. All rights reserved.                 \x1b[40m\x1b[23;1H\x1b[0m";
+static char end2[] =
+"\x1b[?7h\x1b[40m\x1b[2J\x1b[0;1;41m\x1b[1;1H        QUAKE \x1b[33mby \x1b[44mid\x1b[41m Software                                                    \x1b[2;1H -----------------------------------------------------------------------------  \x1b[3;1H        \x1b[37mWhy did you quit from the registered version of QUAKE? Did the          \x1b[4;1H        scary monsters frighten you? Or did Mr. Sandman tug at your             \x1b[5;1H        little lids? No matter! What is important is you love our               \x1b[6;1H        game, and gave us your money. Congratulations, you are probably         \x1b[7;1H        not a thief.                                                            \x1b[8;1H                                                           Thank You.           \x1b[9;1H        \x1b[33;44mid\x1b[41m Software is:                                                         \x1b[10;1H        PROGRAMMING: \x1b[37mJohn Carmack, Michael Abrash, John Cash                    \x1b[11;1H        \x1b[33mDESIGN: \x1b[37mJohn Romero, Sandy Petersen, American McGee, Tim Willits        \x1b[12;1H        \x1b[33mART: \x1b[37mAdrian Carmack, Kevin Cloud                                        \x1b[13;1H        \x1b[33mBIZ: \x1b[37mJay Wilbur, Mike Wilson     \x1b[33mPROJECTS MAN: \x1b[37mShawn Green              \x1b[14;1H        \x1b[33mBIZ ASSIST: \x1b[37mDonna Jackson        \x1b[33mSUPPORT: \x1b[37mBarrett Alexander             \x1b[15;1H        \x1b[33mSOUND EFFECTS AND MUSIC: \x1b[37mTrent Reznor and Nine Inch Nails               \x1b[16;1H                                                                                \x1b[17;1H        If you need help running QUAKE refer to the text files in the           \x1b[18;1H        QUAKE directory, or our website at http://www.idsoftware.com.           \x1b[19;1H        If all else fails, call our technical support at 1-800-IDGAMES.         \x1b[20;1H      \x1b[0;41mQuake is a trademark of Id Software, inc., (c)1996 Id Software, inc.      \x1b[21;1H        All rights reserved. NIN logo is a registered trademark licensed        \x1b[22;1H             to Nothing Interactive, Inc. All rights reserved.                  \x1b[23;1H\x1b[40m\x1b[0m";
+
+*/
+void Sys_Quit (void)
+{
+	Host_Shutdown();
+    fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
+	/*
+	if (registered.value)
+		printf("%s", end2);
+	else
+		printf("%s", end1);
+	*/
+	fflush(stdout);
+	exit(0);
+}
+
+void Sys_Init(void)
+{
+}
+
+void Sys_Error (char *error, ...)
+{ 
+    va_list     argptr;
+    char        string[1024];
+
+// change stdin to non blocking
+    fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
+    
+    va_start (argptr,error);
+    vsprintf (string,error,argptr);
+    va_end (argptr);
+	fprintf(stderr, "Error: %s\n", string);
+
+	Host_Shutdown ();
+	exit (1);
+
+} 
+
+void Sys_Warn (char *warning, ...)
+{ 
+    va_list     argptr;
+    char        string[1024];
+    
+    va_start (argptr,warning);
+    vsprintf (string,warning,argptr);
+    va_end (argptr);
+	fprintf(stderr, "Warning: %s", string);
+} 
+
+/*
+============
+Sys_FileTime
+
+returns -1 if not present
+============
+*/
+int	Sys_FileTime (char *path)
+{
+	struct	stat	buf;
+	
+	if (stat (path,&buf) == -1)
+		return -1;
+	
+	return buf.st_mtime;
+}
+
+
+void Sys_mkdir (char *path)
+{
+    mkdir (path, 0777);
+}
+
+int Sys_FileOpenRead (char *path, int *handle)
+{
+	int	h;
+	struct stat	fileinfo;
+    
+	
+	/*h = open (path, O_RDONLY, 0666);*/
+	h = open (path, OREAD);
+	*handle = h;
+	if (h == -1)
+		return -1;
+	
+	if (fstat (h,&fileinfo) == -1)
+		Sys_Error ("Error fstating %s", path);
+
+	return fileinfo.st_size;
+}
+
+int Sys_FileOpenWrite (char *path)
+{
+	int     handle;
+
+	umask (0);
+	
+	/*handle = open(path,O_RDWR | O_CREAT | O_TRUNC, 0666);*/
+	handle = open(path, OREAD);
+
+	if (handle == -1)
+		Sys_Error ("Error opening %s: %s", path,strerror(errno));
+
+	return handle;
+}
+
+int Sys_FileWrite (int handle, void *src, int count)
+{
+	return write (handle, src, count);
+}
+
+void Sys_FileClose (int handle)
+{
+	close (handle);
+}
+
+void Sys_FileSeek (int handle, int position)
+{
+	lseek (handle, position, SEEK_SET);
+}
+
+int Sys_FileRead (int handle, void *dest, int count)
+{
+    return read (handle, dest, count);
+}
+
+void Sys_DebugLog(char *file, char *fmt, ...)
+{
+    va_list argptr; 
+    static char data[1024];
+    int fd;
+    
+    va_start(argptr, fmt);
+    vsprintf(data, fmt, argptr);
+    va_end(argptr);
+//    fd = open(file, O_WRONLY | O_BINARY | O_CREAT | O_APPEND, 0666);
+    /*fd = open(file, O_WRONLY | O_CREAT | O_APPEND, 0666);*/
+	fd = open(file, OREAD);
+    write(fd, data, strlen(data));
+    close(fd);
+}
+
+void Sys_EditFile(char *filename)
+{
+
+	char cmd[256];
+	char *term;
+	char *editor;
+
+	term = getenv("TERM");
+	if (term && !strcmp(term, "xterm"))
+	{
+		editor = getenv("VISUAL");
+		if (!editor)
+			editor = getenv("EDITOR");
+		if (!editor)
+			editor = getenv("EDIT");
+		if (!editor)
+			editor = "vi";
+		sprintf(cmd, "xterm -e %s %s", editor, filename);
+		system(cmd);
+	}
+
+}
+
+double Sys_FloatTime (void)
+{
+    struct timeval tp;
+    struct timezone tzp; 
+    static int      secbase; 
+    
+    gettimeofday(&tp, &tzp);  
+
+    if (!secbase)
+    {
+        secbase = tp.tv_sec;
+        return tp.tv_usec/1000000.0;
+    }
+
+    return (tp.tv_sec - secbase) + tp.tv_usec/1000000.0;
+}
+
+// =======================================================================
+// Sleeps for microseconds
+// =======================================================================
+
+static volatile int oktogo;
+
+void alarm_handler(int x)
+{
+	oktogo=1;
+}
+
+void Sys_LineRefresh(void)
+{
+}
+
+void floating_point_exception_handler(int whatever)
+{
+//	Sys_Warn("floating point exception\n");
+	signal(SIGFPE, floating_point_exception_handler);
+}
+
+char *Sys_ConsoleInput(void)
+{
+    static char text[256];
+    int     len;
+	fd_set	fdset;
+    struct timeval timeout;
+
+	if (cls.state == ca_dedicated) {
+		FD_ZERO(&fdset);
+		FD_SET(0, &fdset); // stdin
+		timeout.tv_sec = 0;
+		timeout.tv_usec = 0;
+		if (select (1, &fdset, NULL, NULL, &timeout) == -1 || !FD_ISSET(0, &fdset))
+			return NULL;
+
+		len = read (0, text, sizeof(text));
+		if (len < 1)
+			return NULL;
+		text[len-1] = 0;    // rip off the /n and terminate
+
+		return text;
+	}
+	return NULL;
+}
+
+void Sys_HighFPPrecision (void)
+{
+}
+
+void Sys_LowFPPrecision (void)
+{
+}
+
+int main (int c, char **v)
+{
+
+	double		time, oldtime, newtime;
+	quakeparms_t parms;
+	extern int vcrFile;
+	extern int recording;
+	int j;
+
+//	static char cwd[1024];
+
+//	signal(SIGFPE, floating_point_exception_handler);
+	signal(SIGFPE, SIG_IGN);
+
+	memset(&parms, 0, sizeof(parms));
+
+	COM_InitArgv(c, v);
+	parms.argc = com_argc;
+	parms.argv = com_argv;
+	parms.memsize = 8*1024*1024;
+
+	j = COM_CheckParm("-mem");
+	if (j)
+		parms.memsize = (int) (Q_atof(com_argv[j+1]) * 1024 * 1024);
+	parms.membase = malloc (parms.memsize);
+
+	parms.basedir = basedir;
+// caching is disabled by default, use -cachedir to enable
+//	parms.cachedir = cachedir;
+
+	fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
+
+    Host_Init(&parms);
+
+	Sys_Init();
+
+	if (COM_CheckParm("-nostdout"))
+		nostdout = 1;
+	else {
+		fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
+		printf ("Linux Quake -- Version %0.3f\n", LINUX_VERSION);
+	}
+
+    oldtime = Sys_FloatTime () - 0.1;
+    while (1)
+    {
+// find time spent rendering last frame
+        newtime = Sys_FloatTime ();
+        time = newtime - oldtime;
+
+        if (cls.state == ca_dedicated)
+        {   // play vcrfiles at max speed
+            if (time < sys_ticrate.value && (vcrFile == -1 || recording) )
+            {
+				usleep(1);
+                continue;       // not time to run a server only tic yet
+            }
+            time = sys_ticrate.value;
+        }
+
+        if (time > sys_ticrate.value*2)
+            oldtime = newtime;
+        else
+            oldtime += time;
+
+        Host_Frame (time);
+
+// graphic debugging aids
+        if (sys_linerefresh.value)
+            Sys_LineRefresh ();
+    }
+
+}
+
+
+/*
+================
+Sys_MakeCodeWriteable
+================
+*/
+void Sys_MakeCodeWriteable (uintptr startaddr, uintptr length)
+{
+
+	int r;
+	uintptr addr;
+	int psize = getpagesize();
+
+	addr = (startaddr & ~(psize-1)) - psize;
+
+//	fprintf(stderr, "writable code %lx(%lx)-%lx, length=%lx\n", startaddr,
+//			addr, startaddr+length, length);
+
+	r = mprotect((char*)addr, length + startaddr - addr + psize, 7);
+
+	if (r < 0)
+    		Sys_Error("Protection change failed\n");
+
+}
+
--- a/sys_linux.c
+++ /dev/null
@@ -1,451 +1,0 @@
-#include <u.h>
-#include <libc.h>
-//#include <unistd.h>
-#include <signal.h>
-//#include <stdlib.h>
-//#include <limits.h>
-#include <sys/time.h>
-#include <sys/types.h>
-//#include <unistd.h>
-//#include <fcntl.h>
-//#include <stdarg.h>
-//#include <stdio.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <sys/stat.h>
-//#include <string.h>
-//#include <ctype.h>
-//#include <sys/wait.h>
-#include <sys/mman.h>
-#include <errno.h>
-
-#include "quakedef.h"
-
-qboolean			isDedicated;
-
-int nostdout = 0;
-
-char *basedir = ".";
-char *cachedir = "/tmp";
-
-cvar_t  sys_linerefresh = {"sys_linerefresh","0"};// set for entity display
-
-// =======================================================================
-// General routines
-// =======================================================================
-
-void Sys_DebugNumber(int y, int val)
-{
-}
-
-/*
-void Sys_Printf (char *fmt, ...)
-{
-	va_list		argptr;
-	char		text[1024];
-	
-	va_start (argptr,fmt);
-	vsprintf (text,fmt,argptr);
-	va_end (argptr);
-	fprintf(stderr, "%s", text);
-	
-	Con_Print (text);
-}
-
-void Sys_Printf (char *fmt, ...)
-{
-
-    va_list     argptr;
-    char        text[1024], *t_p;
-    int         l, r;
-
-	if (nostdout)
-		return;
-
-    va_start (argptr,fmt);
-    vsprintf (text,fmt,argptr);
-    va_end (argptr);
-
-    l = strlen(text);
-    t_p = text;
-
-// make sure everything goes through, even though we are non-blocking
-    while (l)
-    {
-        r = write (1, text, l);
-        if (r != l)
-            sleep (0);
-        if (r > 0)
-        {
-            t_p += r;
-            l -= r;
-        }
-    }
-
-}
-*/
-
-void Sys_Printf (char *fmt, ...)
-{
-	va_list		argptr;
-	char		text[1024];
-	unsigned char		*p;
-
-	va_start (argptr,fmt);
-	vsprintf (text,fmt,argptr);
-	va_end (argptr);
-
-	if (strlen(text) > sizeof(text))
-		Sys_Error("memory overwrite in Sys_Printf");
-
-    if (nostdout)
-        return;
-
-	for (p = (unsigned char *)text; *p; p++) {
-		*p &= 0x7f;
-		if ((*p > 128 || *p < 32) && *p != 10 && *p != 13 && *p != 9)
-			printf("[%02x]", *p);
-		else
-			putc(*p, stdout);
-	}
-}
-
-/*
-static char end1[] =
-"\x1b[?7h\x1b[40m\x1b[2J\x1b[0;1;41m\x1b[1;1H                QUAKE: The Doomed Dimension \x1b[33mby \x1b[44mid\x1b[41m Software                      \x1b[2;1H  ----------------------------------------------------------------------------  \x1b[3;1H           CALL 1-800-IDGAMES TO ORDER OR FOR TECHNICAL SUPPORT                 \x1b[4;1H             PRICE: $45.00 (PRICES MAY VARY OUTSIDE THE US.)                    \x1b[5;1H                                                                                \x1b[6;1H  \x1b[37mYes! You only have one fourth of this incredible epic. That is because most   \x1b[7;1H   of you have paid us nothing or at most, very little. You could steal the     \x1b[8;1H   game from a friend. But we both know you'll be punished by God if you do.    \x1b[9;1H        \x1b[33mWHY RISK ETERNAL DAMNATION? CALL 1-800-IDGAMES AND BUY NOW!             \x1b[10;1H             \x1b[37mRemember, we love you almost as much as He does.                   \x1b[11;1H                                                                                \x1b[12;1H            \x1b[33mProgramming: \x1b[37mJohn Carmack, Michael Abrash, John Cash                \x1b[13;1H       \x1b[33mDesign: \x1b[37mJohn Romero, Sandy Petersen, American McGee, Tim Willits         \x1b[14;1H                     \x1b[33mArt: \x1b[37mAdrian Carmack, Kevin Cloud                           \x1b[15;1H               \x1b[33mBiz: \x1b[37mJay Wilbur, Mike Wilson, Donna Jackson                      \x1b[16;1H            \x1b[33mProjects: \x1b[37mShawn Green   \x1b[33mSupport: \x1b[37mBarrett Alexander                  \x1b[17;1H              \x1b[33mSound Effects: \x1b[37mTrent Reznor and Nine Inch Nails                   \x1b[18;1H  For other information or details on ordering outside the US, check out the    \x1b[19;1H     files accompanying QUAKE or our website at http://www.idsoftware.com.      \x1b[20;1H    \x1b[0;41mQuake is a trademark of Id Software, inc., (c)1996 Id Software, inc.        \x1b[21;1H     All rights reserved. NIN logo is a registered trademark licensed to        \x1b[22;1H                 Nothing Interactive, Inc. All rights reserved.                 \x1b[40m\x1b[23;1H\x1b[0m";
-static char end2[] =
-"\x1b[?7h\x1b[40m\x1b[2J\x1b[0;1;41m\x1b[1;1H        QUAKE \x1b[33mby \x1b[44mid\x1b[41m Software                                                    \x1b[2;1H -----------------------------------------------------------------------------  \x1b[3;1H        \x1b[37mWhy did you quit from the registered version of QUAKE? Did the          \x1b[4;1H        scary monsters frighten you? Or did Mr. Sandman tug at your             \x1b[5;1H        little lids? No matter! What is important is you love our               \x1b[6;1H        game, and gave us your money. Congratulations, you are probably         \x1b[7;1H        not a thief.                                                            \x1b[8;1H                                                           Thank You.           \x1b[9;1H        \x1b[33;44mid\x1b[41m Software is:                                                         \x1b[10;1H        PROGRAMMING: \x1b[37mJohn Carmack, Michael Abrash, John Cash                    \x1b[11;1H        \x1b[33mDESIGN: \x1b[37mJohn Romero, Sandy Petersen, American McGee, Tim Willits        \x1b[12;1H        \x1b[33mART: \x1b[37mAdrian Carmack, Kevin Cloud                                        \x1b[13;1H        \x1b[33mBIZ: \x1b[37mJay Wilbur, Mike Wilson     \x1b[33mPROJECTS MAN: \x1b[37mShawn Green              \x1b[14;1H        \x1b[33mBIZ ASSIST: \x1b[37mDonna Jackson        \x1b[33mSUPPORT: \x1b[37mBarrett Alexander             \x1b[15;1H        \x1b[33mSOUND EFFECTS AND MUSIC: \x1b[37mTrent Reznor and Nine Inch Nails               \x1b[16;1H                                                                                \x1b[17;1H        If you need help running QUAKE refer to the text files in the           \x1b[18;1H        QUAKE directory, or our website at http://www.idsoftware.com.           \x1b[19;1H        If all else fails, call our technical support at 1-800-IDGAMES.         \x1b[20;1H      \x1b[0;41mQuake is a trademark of Id Software, inc., (c)1996 Id Software, inc.      \x1b[21;1H        All rights reserved. NIN logo is a registered trademark licensed        \x1b[22;1H             to Nothing Interactive, Inc. All rights reserved.                  \x1b[23;1H\x1b[40m\x1b[0m";
-
-*/
-void Sys_Quit (void)
-{
-	Host_Shutdown();
-    fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
-	/*
-	if (registered.value)
-		printf("%s", end2);
-	else
-		printf("%s", end1);
-	*/
-	fflush(stdout);
-	exit(0);
-}
-
-void Sys_Init(void)
-{
-}
-
-void Sys_Error (char *error, ...)
-{ 
-    va_list     argptr;
-    char        string[1024];
-
-// change stdin to non blocking
-    fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
-    
-    va_start (argptr,error);
-    vsprintf (string,error,argptr);
-    va_end (argptr);
-	fprintf(stderr, "Error: %s\n", string);
-
-	Host_Shutdown ();
-	exit (1);
-
-} 
-
-void Sys_Warn (char *warning, ...)
-{ 
-    va_list     argptr;
-    char        string[1024];
-    
-    va_start (argptr,warning);
-    vsprintf (string,warning,argptr);
-    va_end (argptr);
-	fprintf(stderr, "Warning: %s", string);
-} 
-
-/*
-============
-Sys_FileTime
-
-returns -1 if not present
-============
-*/
-int	Sys_FileTime (char *path)
-{
-	struct	stat	buf;
-	
-	if (stat (path,&buf) == -1)
-		return -1;
-	
-	return buf.st_mtime;
-}
-
-
-void Sys_mkdir (char *path)
-{
-    mkdir (path, 0777);
-}
-
-int Sys_FileOpenRead (char *path, int *handle)
-{
-	int	h;
-	struct stat	fileinfo;
-    
-	
-	/*h = open (path, O_RDONLY, 0666);*/
-	h = open (path, OREAD);
-	*handle = h;
-	if (h == -1)
-		return -1;
-	
-	if (fstat (h,&fileinfo) == -1)
-		Sys_Error ("Error fstating %s", path);
-
-	return fileinfo.st_size;
-}
-
-int Sys_FileOpenWrite (char *path)
-{
-	int     handle;
-
-	umask (0);
-	
-	/*handle = open(path,O_RDWR | O_CREAT | O_TRUNC, 0666);*/
-	handle = open(path, OREAD|OAPPEND);
-
-	if (handle == -1)
-		Sys_Error ("Error opening %s: %s", path,strerror(errno));
-
-	return handle;
-}
-
-int Sys_FileWrite (int handle, void *src, int count)
-{
-	return write (handle, src, count);
-}
-
-void Sys_FileClose (int handle)
-{
-	close (handle);
-}
-
-void Sys_FileSeek (int handle, int position)
-{
-	lseek (handle, position, SEEK_SET);
-}
-
-int Sys_FileRead (int handle, void *dest, int count)
-{
-    return read (handle, dest, count);
-}
-
-void Sys_DebugLog(char *file, char *fmt, ...)
-{
-    va_list argptr; 
-    static char data[1024];
-    int fd;
-    
-    va_start(argptr, fmt);
-    vsprintf(data, fmt, argptr);
-    va_end(argptr);
-//    fd = open(file, O_WRONLY | O_BINARY | O_CREAT | O_APPEND, 0666);
-    /*fd = open(file, O_WRONLY | O_CREAT | O_APPEND, 0666);*/
-	fd = open(file, OREAD|OAPPEND);
-    write(fd, data, strlen(data));
-    close(fd);
-}
-
-void Sys_EditFile(char *filename)
-{
-
-	char cmd[256];
-	char *term;
-	char *editor;
-
-	term = getenv("TERM");
-	if (term && !strcmp(term, "xterm"))
-	{
-		editor = getenv("VISUAL");
-		if (!editor)
-			editor = getenv("EDITOR");
-		if (!editor)
-			editor = getenv("EDIT");
-		if (!editor)
-			editor = "vi";
-		sprintf(cmd, "xterm -e %s %s", editor, filename);
-		system(cmd);
-	}
-
-}
-
-double Sys_FloatTime (void)
-{
-    struct timeval tp;
-    struct timezone tzp; 
-    static int      secbase; 
-    
-    gettimeofday(&tp, &tzp);  
-
-    if (!secbase)
-    {
-        secbase = tp.tv_sec;
-        return tp.tv_usec/1000000.0;
-    }
-
-    return (tp.tv_sec - secbase) + tp.tv_usec/1000000.0;
-}
-
-// =======================================================================
-// Sleeps for microseconds
-// =======================================================================
-
-static volatile int oktogo;
-
-void alarm_handler(int x)
-{
-	oktogo=1;
-}
-
-void Sys_LineRefresh(void)
-{
-}
-
-void floating_point_exception_handler(int whatever)
-{
-//	Sys_Warn("floating point exception\n");
-	signal(SIGFPE, floating_point_exception_handler);
-}
-
-char *Sys_ConsoleInput(void)
-{
-    static char text[256];
-    int     len;
-	fd_set	fdset;
-    struct timeval timeout;
-
-	if (cls.state == ca_dedicated) {
-		FD_ZERO(&fdset);
-		FD_SET(0, &fdset); // stdin
-		timeout.tv_sec = 0;
-		timeout.tv_usec = 0;
-		if (select (1, &fdset, NULL, NULL, &timeout) == -1 || !FD_ISSET(0, &fdset))
-			return NULL;
-
-		len = read (0, text, sizeof(text));
-		if (len < 1)
-			return NULL;
-		text[len-1] = 0;    // rip off the /n and terminate
-
-		return text;
-	}
-	return NULL;
-}
-
-void Sys_HighFPPrecision (void)
-{
-}
-
-void Sys_LowFPPrecision (void)
-{
-}
-
-int main (int c, char **v)
-{
-
-	double		time, oldtime, newtime;
-	quakeparms_t parms;
-	extern int vcrFile;
-	extern int recording;
-	int j;
-
-//	static char cwd[1024];
-
-//	signal(SIGFPE, floating_point_exception_handler);
-	signal(SIGFPE, SIG_IGN);
-
-	memset(&parms, 0, sizeof(parms));
-
-	COM_InitArgv(c, v);
-	parms.argc = com_argc;
-	parms.argv = com_argv;
-	parms.memsize = 8*1024*1024;
-
-	j = COM_CheckParm("-mem");
-	if (j)
-		parms.memsize = (int) (Q_atof(com_argv[j+1]) * 1024 * 1024);
-	parms.membase = malloc (parms.memsize);
-
-	parms.basedir = basedir;
-// caching is disabled by default, use -cachedir to enable
-//	parms.cachedir = cachedir;
-
-	fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
-
-    Host_Init(&parms);
-
-	Sys_Init();
-
-	if (COM_CheckParm("-nostdout"))
-		nostdout = 1;
-	else {
-		fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
-		printf ("Linux Quake -- Version %0.3f\n", LINUX_VERSION);
-	}
-
-    oldtime = Sys_FloatTime () - 0.1;
-    while (1)
-    {
-// find time spent rendering last frame
-        newtime = Sys_FloatTime ();
-        time = newtime - oldtime;
-
-        if (cls.state == ca_dedicated)
-        {   // play vcrfiles at max speed
-            if (time < sys_ticrate.value && (vcrFile == -1 || recording) )
-            {
-				usleep(1);
-                continue;       // not time to run a server only tic yet
-            }
-            time = sys_ticrate.value;
-        }
-
-        if (time > sys_ticrate.value*2)
-            oldtime = newtime;
-        else
-            oldtime += time;
-
-        Host_Frame (time);
-
-// graphic debugging aids
-        if (sys_linerefresh.value)
-            Sys_LineRefresh ();
-    }
-
-}
-
-
-/*
-================
-Sys_MakeCodeWriteable
-================
-*/
-void Sys_MakeCodeWriteable (uintptr startaddr, uintptr length)
-{
-
-	int r;
-	uintptr addr;
-	int psize = getpagesize();
-
-	addr = (startaddr & ~(psize-1)) - psize;
-
-//	fprintf(stderr, "writable code %lx(%lx)-%lx, length=%lx\n", startaddr,
-//			addr, startaddr+length, length);
-
-	r = mprotect((char*)addr, length + startaddr - addr + psize, 7);
-
-	if (r < 0)
-    		Sys_Error("Protection change failed\n");
-
-}
-
--- a/u/menu.h
+++ /dev/null
@@ -1,38 +1,0 @@
-/*
-Copyright (C) 1996-1997 Id Software, Inc.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
-
-See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-*/
-
-//
-// the net drivers should just set the apropriate bits in m_activenet,
-// instead of having the menu code look through their internal tables
-//
-#define	MNET_IPX		1
-#define	MNET_TCP		2
-
-extern	int	m_activenet;
-
-//
-// menus
-//
-void M_Init (void);
-void M_Keydown (int key);
-void M_Draw (void);
-void M_ToggleMenu_f (void);
-
-
--- /dev/null
+++ b/vid_9.c
@@ -1,0 +1,1155 @@
+#define _BSD
+
+#include <u.h>
+#include <libc.h>
+//#include <ctype.h>
+#include <sys/time.h>
+#include <sys/types.h>
+//#include <unistd.h>
+#include <signal.h>
+//#include <stdlib.h>
+//#include <stdio.h>
+//#include <string.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xatom.h>
+#include <X11/keysym.h>
+#include <X11/extensions/XShm.h>
+
+#include "quakedef.h"
+#include "d_local.h"
+
+cvar_t		_windowed_mouse = {"_windowed_mouse","0", true};
+cvar_t		m_filter = {"m_filter","0", true};
+float old_windowed_mouse;
+
+qboolean        mouse_avail;
+int             mouse_buttons=3;
+int             mouse_oldbuttonstate;
+int             mouse_buttonstate;
+float   mouse_x, mouse_y;
+float   old_mouse_x, old_mouse_y;
+int p_mouse_x;
+int p_mouse_y;
+int ignorenext;
+int bits_per_pixel;
+
+typedef struct
+{
+	int input;
+	int output;
+} keymap_t;
+
+viddef_t vid; // global video state
+unsigned short d_8to16table[256];
+
+int		num_shades=32;
+
+int	d_con_indirect = 0;
+
+int		vid_buffersize;
+
+static qboolean			doShm;
+static Display			*x_disp;
+static Colormap			x_cmap;
+static Window			x_win;
+static GC				x_gc;
+static Visual			*x_vis;
+static XVisualInfo		*x_visinfo;
+//static XImage			*x_image;
+
+static int				x_shmeventtype;
+//static XShmSegmentInfo	x_shminfo;
+
+static qboolean			oktodraw = false;
+
+int XShmQueryExtension(Display *);
+int XShmGetEventBase(Display *);
+
+int current_framebuffer;
+static XImage			*x_framebuffer[2] = { 0, 0 };
+static XShmSegmentInfo	x_shminfo[2];
+
+static int verbose=0;
+
+static byte current_palette[768];
+
+static int X11_highhunkmark;
+static int X11_buffersize;
+
+int vid_surfcachesize;
+void *vid_surfcache;
+
+void (*vid_menudrawfn)(void);
+void (*vid_menukeyfn)(int key);
+void VID_MenuKey (int key);
+
+typedef unsigned short PIXEL16;
+typedef u32int PIXEL24;
+static PIXEL16 st2d_8to16table[256];
+static PIXEL24 st2d_8to24table[256];
+static int shiftmask_fl=0;
+static int r_shift,g_shift,b_shift;
+static uint r_mask,g_mask,b_mask;
+
+void shiftmask_init()
+{
+    unsigned int x;
+    r_mask=x_vis->red_mask;
+    g_mask=x_vis->green_mask;
+    b_mask=x_vis->blue_mask;
+    for(r_shift=-8,x=1;x<r_mask;x=x<<1)r_shift++;
+    for(g_shift=-8,x=1;x<g_mask;x=x<<1)g_shift++;
+    for(b_shift=-8,x=1;x<b_mask;x=x<<1)b_shift++;
+    shiftmask_fl=1;
+}
+
+PIXEL16 xlib_rgb16(int r,int g,int b)
+{
+    PIXEL16 p;
+    if(shiftmask_fl==0) shiftmask_init();
+    p=0;
+
+    if(r_shift>0) {
+        p=(r<<(r_shift))&r_mask;
+    } else if(r_shift<0) {
+        p=(r>>(-r_shift))&r_mask;
+    } else p|=(r&r_mask);
+
+    if(g_shift>0) {
+        p|=(g<<(g_shift))&g_mask;
+    } else if(g_shift<0) {
+        p|=(g>>(-g_shift))&g_mask;
+    } else p|=(g&g_mask);
+
+    if(b_shift>0) {
+        p|=(b<<(b_shift))&b_mask;
+    } else if(b_shift<0) {
+        p|=(b>>(-b_shift))&b_mask;
+    } else p|=(b&b_mask);
+
+    return p;
+}
+
+PIXEL24 xlib_rgb24(int r,int g,int b)
+{
+    PIXEL24 p;
+    if(shiftmask_fl==0) shiftmask_init();
+    p=0;
+
+    if(r_shift>0) {
+        p=(r<<(r_shift))&r_mask;
+    } else if(r_shift<0) {
+        p=(r>>(-r_shift))&r_mask;
+    } else p|=(r&r_mask);
+
+    if(g_shift>0) {
+        p|=(g<<(g_shift))&g_mask;
+    } else if(g_shift<0) {
+        p|=(g>>(-g_shift))&g_mask;
+    } else p|=(g&g_mask);
+
+    if(b_shift>0) {
+        p|=(b<<(b_shift))&b_mask;
+    } else if(b_shift<0) {
+        p|=(b>>(-b_shift))&b_mask;
+    } else p|=(b&b_mask);
+
+    return p;
+}
+
+void st2_fixup( XImage *framebuf, int x, int y, int width, int height)
+{
+	int xi,yi;
+	unsigned char *src;
+	PIXEL16 *dest;
+	register int count, n;
+
+	if( (x<0)||(y<0) )return;
+
+	for (yi = y; yi < (y+height); yi++) {
+		src = &framebuf->data [yi * framebuf->bytes_per_line];
+
+		// Duff's Device
+		count = width;
+		n = (count + 7) / 8;
+		dest = ((PIXEL16 *)src) + x+width - 1;
+		src += x+width - 1;
+
+		switch (count % 8) {
+		case 0:	do {	*dest-- = st2d_8to16table[*src--];
+		case 7:			*dest-- = st2d_8to16table[*src--];
+		case 6:			*dest-- = st2d_8to16table[*src--];
+		case 5:			*dest-- = st2d_8to16table[*src--];
+		case 4:			*dest-- = st2d_8to16table[*src--];
+		case 3:			*dest-- = st2d_8to16table[*src--];
+		case 2:			*dest-- = st2d_8to16table[*src--];
+		case 1:			*dest-- = st2d_8to16table[*src--];
+				} while (--n > 0);
+		}
+
+//		for(xi = (x+width-1); xi >= x; xi--) {
+//			dest[xi] = st2d_8to16table[src[xi]];
+//		}
+	}
+}
+
+void st3_fixup( XImage *framebuf, int x, int y, int width, int height)
+{
+	int xi,yi;
+	unsigned char *src;
+	PIXEL24 *dest;
+	register int count, n;
+
+	if( (x<0)||(y<0) )return;
+
+	for (yi = y; yi < (y+height); yi++) {
+		src = &framebuf->data [yi * framebuf->bytes_per_line];
+
+		// Duff's Device
+		count = width;
+		n = (count + 7) / 8;
+		dest = ((PIXEL24 *)src) + x+width - 1;
+		src += x+width - 1;
+
+		switch (count % 8) {
+		case 0:	do {	*dest-- = st2d_8to24table[*src--];
+		case 7:			*dest-- = st2d_8to24table[*src--];
+		case 6:			*dest-- = st2d_8to24table[*src--];
+		case 5:			*dest-- = st2d_8to24table[*src--];
+		case 4:			*dest-- = st2d_8to24table[*src--];
+		case 3:			*dest-- = st2d_8to24table[*src--];
+		case 2:			*dest-- = st2d_8to24table[*src--];
+		case 1:			*dest-- = st2d_8to24table[*src--];
+				} while (--n > 0);
+		}
+
+//		for(xi = (x+width-1); xi >= x; xi--) {
+//			dest[xi] = st2d_8to16table[src[xi]];
+//		}
+	}
+}
+
+
+// ========================================================================
+// Tragic death handler
+// ========================================================================
+
+void TragicDeath(int signal_num)
+{
+	XAutoRepeatOn(x_disp);
+	XCloseDisplay(x_disp);
+	Sys_Error("This death brought to you by the number %d\n", signal_num);
+}
+
+// ========================================================================
+// makes a null cursor
+// ========================================================================
+
+static Cursor CreateNullCursor(Display *display, Window root)
+{
+    Pixmap cursormask; 
+    XGCValues xgc;
+    GC gc;
+    XColor dummycolour;
+    Cursor cursor;
+
+    cursormask = XCreatePixmap(display, root, 1, 1, 1/*depth*/);
+    xgc.function = GXclear;
+    gc =  XCreateGC(display, cursormask, GCFunction, &xgc);
+    XFillRectangle(display, cursormask, gc, 0, 0, 1, 1);
+    dummycolour.pixel = 0;
+    dummycolour.red = 0;
+    dummycolour.flags = 04;
+    cursor = XCreatePixmapCursor(display, cursormask, cursormask,
+          &dummycolour,&dummycolour, 0,0);
+    XFreePixmap(display,cursormask);
+    XFreeGC(display,gc);
+    return cursor;
+}
+
+void ResetFrameBuffer(void)
+{
+	int mem;
+	int pwidth;
+
+	if (x_framebuffer[0])
+	{
+		free(x_framebuffer[0]->data);
+		free(x_framebuffer[0]);
+	}
+
+	if (d_pzbuffer)
+	{
+		D_FlushCaches ();
+		Hunk_FreeToHighMark (X11_highhunkmark);
+		d_pzbuffer = NULL;
+	}
+	X11_highhunkmark = Hunk_HighMark ();
+
+// alloc an extra line in case we want to wrap, and allocate the z-buffer
+	X11_buffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
+
+	vid_surfcachesize = D_SurfaceCacheForRes (vid.width, vid.height);
+
+	X11_buffersize += vid_surfcachesize;
+
+	d_pzbuffer = Hunk_HighAllocName (X11_buffersize, "video");
+	if (d_pzbuffer == NULL)
+		Sys_Error ("Not enough memory for video mode\n");
+
+	vid_surfcache = (byte *) d_pzbuffer
+		+ vid.width * vid.height * sizeof (*d_pzbuffer);
+
+	D_InitCaches(vid_surfcache, vid_surfcachesize);
+
+	pwidth = x_visinfo->depth / 8;
+	if (pwidth == 3) pwidth = 4;
+	mem = ((vid.width*pwidth+7)&~7) * vid.height;
+
+	x_framebuffer[0] = XCreateImage(	x_disp,
+		x_vis,
+		x_visinfo->depth,
+		ZPixmap,
+		0,
+		malloc(mem),
+		vid.width, vid.height,
+		32,
+		0);
+
+	if (!x_framebuffer[0])
+		Sys_Error("VID: XCreateImage failed\n");
+
+	vid.buffer = (byte*) (x_framebuffer[0]);
+	vid.conbuffer = vid.buffer;
+
+}
+
+void ResetSharedFrameBuffers(void)
+{
+
+	int size;
+	int key;
+	int minsize = getpagesize();
+	int frm;
+
+	if (d_pzbuffer)
+	{
+		D_FlushCaches ();
+		Hunk_FreeToHighMark (X11_highhunkmark);
+		d_pzbuffer = NULL;
+	}
+
+	X11_highhunkmark = Hunk_HighMark ();
+
+// alloc an extra line in case we want to wrap, and allocate the z-buffer
+	X11_buffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
+
+	vid_surfcachesize = D_SurfaceCacheForRes (vid.width, vid.height);
+
+	X11_buffersize += vid_surfcachesize;
+
+	d_pzbuffer = Hunk_HighAllocName (X11_buffersize, "video");
+	if (d_pzbuffer == NULL)
+		Sys_Error ("Not enough memory for video mode\n");
+
+	vid_surfcache = (byte *) d_pzbuffer
+		+ vid.width * vid.height * sizeof (*d_pzbuffer);
+
+	D_InitCaches(vid_surfcache, vid_surfcachesize);
+
+	for (frm=0 ; frm<2 ; frm++)
+	{
+
+	// free up old frame buffer memory
+
+		if (x_framebuffer[frm])
+		{
+			XShmDetach(x_disp, &x_shminfo[frm]);
+			free(x_framebuffer[frm]);
+			shmdt(x_shminfo[frm].shmaddr);
+		}
+
+	// create the image
+
+		x_framebuffer[frm] = XShmCreateImage(	x_disp,
+						x_vis,
+						x_visinfo->depth,
+						ZPixmap,
+						0,
+						&x_shminfo[frm],
+						vid.width,
+						vid.height );
+
+	// grab shared memory
+
+		size = x_framebuffer[frm]->bytes_per_line
+			* x_framebuffer[frm]->height;
+		if (size < minsize)
+			Sys_Error("VID: Window must use at least %d bytes\n", minsize);
+
+		key = random();
+		x_shminfo[frm].shmid = shmget((key_t)key, size, IPC_CREAT|0777);
+		if (x_shminfo[frm].shmid==-1)
+			Sys_Error("VID: Could not get any shared memory\n");
+
+		// attach to the shared memory segment
+		x_shminfo[frm].shmaddr =
+			(void *) shmat(x_shminfo[frm].shmid, 0, 0);
+
+		printf("VID: shared memory id=%d, addr=0x%p\n", x_shminfo[frm].shmid,
+			x_shminfo[frm].shmaddr);
+
+		x_framebuffer[frm]->data = x_shminfo[frm].shmaddr;
+
+	// get the X server to attach to it
+
+		if (!XShmAttach(x_disp, &x_shminfo[frm]))
+			Sys_Error("VID: XShmAttach() failed\n");
+		XSync(x_disp, 0);
+		shmctl(x_shminfo[frm].shmid, IPC_RMID, 0);
+
+	}
+
+}
+
+// Called at startup to set up translation tables, takes 256 8 bit RGB values
+// the palette data will go away after the call, so it must be copied off if
+// the video driver will need it again
+
+void	VID_Init (unsigned char *palette)
+{
+
+   int pnum, i;
+   XVisualInfo template;
+   int num_visuals;
+   int template_mask;
+   
+   ignorenext=0;
+   vid.width = 320;
+   vid.height = 200;
+   vid.maxwarpwidth = WARP_WIDTH;
+   vid.maxwarpheight = WARP_HEIGHT;
+   vid.numpages = 2;
+   vid.colormap = host_colormap;
+   //	vid.cbits = VID_CBITS;
+   //	vid.grades = VID_GRADES;
+   vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
+   
+	srandom(getpid());
+
+	verbose=COM_CheckParm("-verbose");
+
+// open the display
+	x_disp = XOpenDisplay(0);
+	if (!x_disp)
+	{
+		if (getenv("DISPLAY"))
+			Sys_Error("VID: Could not open display [%s]\n",
+				getenv("DISPLAY"));
+		else
+			Sys_Error("VID: Could not open local display\n");
+	}
+
+// catch signals so i can turn on auto-repeat
+
+	{
+		struct sigaction sa;
+		sigaction(SIGINT, 0, &sa);
+		sa.sa_handler = TragicDeath;
+		sigaction(SIGINT, &sa, 0);
+		sigaction(SIGTERM, &sa, 0);
+	}
+
+	XAutoRepeatOff(x_disp);
+
+// for debugging only
+	XSynchronize(x_disp, True);
+
+// check for command-line window size
+	if ((pnum=COM_CheckParm("-winsize")))
+	{
+		if (pnum >= com_argc-2)
+			Sys_Error("VID: -winsize <width> <height>\n");
+		vid.width = Q_atoi(com_argv[pnum+1]);
+		vid.height = Q_atoi(com_argv[pnum+2]);
+		if (!vid.width || !vid.height)
+			Sys_Error("VID: Bad window width/height\n");
+	}
+	if ((pnum=COM_CheckParm("-width"))) {
+		if (pnum >= com_argc-1)
+			Sys_Error("VID: -width <width>\n");
+		vid.width = Q_atoi(com_argv[pnum+1]);
+		if (!vid.width)
+			Sys_Error("VID: Bad window width\n");
+	}
+	if ((pnum=COM_CheckParm("-height"))) {
+		if (pnum >= com_argc-1)
+			Sys_Error("VID: -height <height>\n");
+		vid.height = Q_atoi(com_argv[pnum+1]);
+		if (!vid.height)
+			Sys_Error("VID: Bad window height\n");
+	}
+
+	template_mask = 0;
+
+// specify a visual id
+	if ((pnum=COM_CheckParm("-visualid")))
+	{
+		if (pnum >= com_argc-1)
+			Sys_Error("VID: -visualid <id#>\n");
+		template.visualid = Q_atoi(com_argv[pnum+1]);
+		template_mask = VisualIDMask;
+	}
+
+// If not specified, use default visual
+	else
+	{
+		int screen;
+		screen = XDefaultScreen(x_disp);
+		template.visualid =
+			XVisualIDFromVisual(XDefaultVisual(x_disp, screen));
+		template_mask = VisualIDMask;
+	}
+
+// pick a visual- warn if more than one was available
+	x_visinfo = XGetVisualInfo(x_disp, template_mask, &template, &num_visuals);
+	if (num_visuals > 1)
+	{
+		printf("Found more than one visual id at depth %d:\n", template.depth);
+		for (i=0 ; i<num_visuals ; i++)
+			printf("	-visualid %d\n", (int)(x_visinfo[i].visualid));
+	}
+	else if (num_visuals == 0)
+	{
+		if (template_mask == VisualIDMask)
+			Sys_Error("VID: Bad visual id %d\n", template.visualid);
+		else
+			Sys_Error("VID: No visuals at depth %d\n", template.depth);
+	}
+
+	if (verbose)
+	{
+		printf("Using visualid %d:\n", (int)(x_visinfo->visualid));
+		printf("	screen %d\n", x_visinfo->screen);
+		printf("	red_mask 0x%x\n", (int)(x_visinfo->red_mask));
+		printf("	green_mask 0x%x\n", (int)(x_visinfo->green_mask));
+		printf("	blue_mask 0x%x\n", (int)(x_visinfo->blue_mask));
+		printf("	colormap_size %d\n", x_visinfo->colormap_size);
+		printf("	bits_per_rgb %d\n", x_visinfo->bits_per_rgb);
+	}
+
+	x_vis = x_visinfo->visual;
+
+// setup attributes for main window
+	{
+	   int attribmask = CWEventMask  | CWColormap | CWBorderPixel;
+	   XSetWindowAttributes attribs;
+	   Colormap tmpcmap;
+	   
+	   tmpcmap = XCreateColormap(x_disp, XRootWindow(x_disp,
+							 x_visinfo->screen), x_vis, AllocNone);
+	   
+           attribs.event_mask = StructureNotifyMask | KeyPressMask
+	     | KeyReleaseMask | ExposureMask | PointerMotionMask |
+	     ButtonPressMask | ButtonReleaseMask;
+	   attribs.border_pixel = 0;
+	   attribs.colormap = tmpcmap;
+
+// create the main window
+		x_win = XCreateWindow(	x_disp,
+			XRootWindow(x_disp, x_visinfo->screen),
+			0, 0,	// x, y
+			vid.width, vid.height,
+			0, // borderwidth
+			x_visinfo->depth,
+			InputOutput,
+			x_vis,
+			attribmask,
+			&attribs );
+		XStoreName( x_disp,x_win,"xquake");
+
+
+		if (x_visinfo->class != TrueColor)
+			XFreeColormap(x_disp, tmpcmap);
+	}
+
+	if (x_visinfo->depth == 8)
+	{
+		// create and upload the palette
+		if (x_visinfo->class == PseudoColor)
+		{
+			x_cmap = XCreateColormap(x_disp, x_win, x_vis, AllocAll);
+			VID_SetPalette(palette);
+			XSetWindowColormap(x_disp, x_win, x_cmap);
+		}
+	}
+
+// inviso cursor
+	XDefineCursor(x_disp, x_win, CreateNullCursor(x_disp, x_win));
+
+// create the GC
+	{
+		XGCValues xgcvalues;
+		int valuemask = GCGraphicsExposures;
+		xgcvalues.graphics_exposures = False;
+		x_gc = XCreateGC(x_disp, x_win, valuemask, &xgcvalues );
+	}
+
+// map the window
+	XMapWindow(x_disp, x_win);
+
+// wait for first exposure event
+	{
+		XEvent event;
+		do
+		{
+			XNextEvent(x_disp, &event);
+			if (event.type == Expose && !event.xexpose.count)
+				oktodraw = true;
+		} while (!oktodraw);
+	}
+// now safe to draw
+
+// even if MITSHM is available, make sure it's a local connection
+	if (XShmQueryExtension(x_disp))
+	{
+		char *displayname;
+		doShm = true;
+		displayname = (char *) getenv("DISPLAY");
+		if (displayname)
+		{
+			char *d = displayname;
+			while (*d && (*d != ':')) d++;
+			if (*d) *d = 0;
+			if (!(!strcasecmp(displayname, "unix") || !*displayname))
+				doShm = false;
+		}
+	}
+
+	if (doShm)
+	{
+		x_shmeventtype = XShmGetEventBase(x_disp) + ShmCompletion;
+		ResetSharedFrameBuffers();
+	}
+	else
+		ResetFrameBuffer();
+
+	current_framebuffer = 0;
+	vid.rowbytes = x_framebuffer[0]->bytes_per_line;
+	vid.buffer = x_framebuffer[0]->data;
+	vid.direct = 0;
+	vid.conbuffer = x_framebuffer[0]->data;
+	vid.conrowbytes = vid.rowbytes;
+	vid.conwidth = vid.width;
+	vid.conheight = vid.height;
+	vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0);
+
+//	XSynchronize(x_disp, False);
+
+}
+
+void VID_ShiftPalette(unsigned char *p)
+{
+	VID_SetPalette(p);
+}
+
+
+
+void VID_SetPalette(unsigned char *palette)
+{
+
+	int i;
+	XColor colors[256];
+
+	for(i=0;i<256;i++) {
+		st2d_8to16table[i]= xlib_rgb16(palette[i*3], palette[i*3+1],palette[i*3+2]);
+		st2d_8to24table[i]= xlib_rgb24(palette[i*3], palette[i*3+1],palette[i*3+2]);
+	}
+
+	if (x_visinfo->class == PseudoColor && x_visinfo->depth == 8)
+	{
+		if (palette != current_palette)
+			memcpy(current_palette, palette, 768);
+		for (i=0 ; i<256 ; i++)
+		{
+			colors[i].pixel = i;
+			colors[i].flags = DoRed|DoGreen|DoBlue;
+			colors[i].red = palette[i*3] * 257;
+			colors[i].green = palette[i*3+1] * 257;
+			colors[i].blue = palette[i*3+2] * 257;
+		}
+		XStoreColors(x_disp, x_cmap, colors, 256);
+	}
+
+}
+
+// Called at shutdown
+
+void	VID_Shutdown (void)
+{
+	Con_Printf("VID_Shutdown\n");
+	XAutoRepeatOn(x_disp);
+	XCloseDisplay(x_disp);
+}
+
+int XLateKey(XKeyEvent *ev)
+{
+
+	int key;
+	char buf[64];
+	KeySym keysym;
+
+	key = 0;
+
+	XLookupString(ev, buf, sizeof buf, &keysym, 0);
+
+	switch(keysym)
+	{
+		case XK_KP_Page_Up:
+		case XK_Page_Up:	 key = K_PGUP; break;
+
+		case XK_KP_Page_Down:
+		case XK_Page_Down:	 key = K_PGDN; break;
+
+		case XK_KP_Home:
+		case XK_Home:	 key = K_HOME; break;
+
+		case XK_KP_End:
+		case XK_End:	 key = K_END; break;
+
+		case XK_KP_Left:
+		case XK_Left:	 key = K_LEFTARROW; break;
+
+		case XK_KP_Right:
+		case XK_Right:	key = K_RIGHTARROW;		break;
+
+		case XK_KP_Down:
+		case XK_Down:	 key = K_DOWNARROW; break;
+
+		case XK_KP_Up:
+		case XK_Up:		 key = K_UPARROW;	 break;
+
+		case XK_Escape: key = K_ESCAPE;		break;
+
+		case XK_KP_Enter:
+		case XK_Return: key = K_ENTER;		 break;
+
+		case XK_Tab:		key = K_TAB;			 break;
+
+		case XK_F1:		 key = K_F1;				break;
+
+		case XK_F2:		 key = K_F2;				break;
+
+		case XK_F3:		 key = K_F3;				break;
+
+		case XK_F4:		 key = K_F4;				break;
+
+		case XK_F5:		 key = K_F5;				break;
+
+		case XK_F6:		 key = K_F6;				break;
+
+		case XK_F7:		 key = K_F7;				break;
+
+		case XK_F8:		 key = K_F8;				break;
+
+		case XK_F9:		 key = K_F9;				break;
+
+		case XK_F10:		key = K_F10;			 break;
+
+		case XK_F11:		key = K_F11;			 break;
+
+		case XK_F12:		key = K_F12;			 break;
+
+		case XK_BackSpace: key = K_BACKSPACE; break;
+
+		case XK_KP_Delete:
+		case XK_Delete: key = K_DEL; break;
+
+		case XK_Pause:	key = K_PAUSE;		 break;
+
+		case XK_Shift_L:
+		case XK_Shift_R:	key = K_SHIFT;		break;
+
+		case XK_Execute: 
+		case XK_Control_L: 
+		case XK_Control_R:	key = K_CTRL;		 break;
+
+		case XK_Alt_L:	
+		case XK_Meta_L: 
+		case XK_Alt_R:	
+		case XK_Meta_R: key = K_ALT;			break;
+
+		case XK_KP_Begin: key = K_AUX30;	break;
+
+		case XK_Insert:
+		case XK_KP_Insert: key = K_INS; break;
+
+		case XK_KP_Multiply: key = '*'; break;
+		case XK_KP_Add: key = '+'; break;
+		case XK_KP_Subtract: key = '-'; break;
+		case XK_KP_Divide: key = '/'; break;
+		default:
+			key = *(unsigned char*)buf;
+			if (key >= 'A' && key <= 'Z')
+				key = key - 'A' + 'a';
+//			fprintf(stdout, "case 0x0%x: key = ___;break;/* [%c] */\n", keysym);
+			break;
+	} 
+
+	return key;
+}
+
+struct
+{
+	int key;
+	int down;
+} keyq[64];
+int keyq_head=0;
+int keyq_tail=0;
+
+int config_notify=0;
+int config_notify_width;
+int config_notify_height;
+						      
+void GetEvent(void)
+{
+	XEvent x_event;
+	int b;
+   
+	XNextEvent(x_disp, &x_event);
+	switch(x_event.type) {
+	case KeyPress:
+		keyq[keyq_head].key = XLateKey(&x_event.xkey);
+		keyq[keyq_head].down = true;
+		keyq_head = (keyq_head + 1) & 63;
+		break;
+	case KeyRelease:
+		keyq[keyq_head].key = XLateKey(&x_event.xkey);
+		keyq[keyq_head].down = false;
+		keyq_head = (keyq_head + 1) & 63;
+		break;
+
+	case MotionNotify:
+		if (_windowed_mouse.value) {
+			mouse_x = (float) ((int)x_event.xmotion.x - (int)(vid.width/2));
+			mouse_y = (float) ((int)x_event.xmotion.y - (int)(vid.height/2));
+//printf("m: x=%d,y=%d, mx=%3.2f,my=%3.2f\n", 
+//	x_event.xmotion.x, x_event.xmotion.y, mouse_x, mouse_y);
+
+			/* move the mouse to the window center again */
+			XSelectInput(x_disp,x_win,StructureNotifyMask|KeyPressMask
+				|KeyReleaseMask|ExposureMask
+				|ButtonPressMask
+				|ButtonReleaseMask);
+			XWarpPointer(x_disp,None,x_win,0,0,0,0, 
+				(vid.width/2),(vid.height/2));
+			XSelectInput(x_disp,x_win,StructureNotifyMask|KeyPressMask
+				|KeyReleaseMask|ExposureMask
+				|PointerMotionMask|ButtonPressMask
+				|ButtonReleaseMask);
+		} else {
+			mouse_x = (float) (x_event.xmotion.x-p_mouse_x);
+			mouse_y = (float) (x_event.xmotion.y-p_mouse_y);
+			p_mouse_x=x_event.xmotion.x;
+			p_mouse_y=x_event.xmotion.y;
+		}
+		break;
+
+	case ButtonPress:
+		b=-1;
+		if (x_event.xbutton.button == 1)
+			b = 0;
+		else if (x_event.xbutton.button == 2)
+			b = 2;
+		else if (x_event.xbutton.button == 3)
+			b = 1;
+		if (b>=0)
+			mouse_buttonstate |= 1<<b;
+		break;
+
+	case ButtonRelease:
+		b=-1;
+		if (x_event.xbutton.button == 1)
+			b = 0;
+		else if (x_event.xbutton.button == 2)
+			b = 2;
+		else if (x_event.xbutton.button == 3)
+			b = 1;
+		if (b>=0)
+			mouse_buttonstate &= ~(1<<b);
+		break;
+	
+	case ConfigureNotify:
+//printf("config notify\n");
+		config_notify_width = x_event.xconfigure.width;
+		config_notify_height = x_event.xconfigure.height;
+		config_notify = 1;
+		break;
+
+	default:
+		if (doShm && x_event.type == x_shmeventtype)
+			oktodraw = true;
+	}
+   
+	if (old_windowed_mouse != _windowed_mouse.value) {
+		old_windowed_mouse = _windowed_mouse.value;
+
+		if (!_windowed_mouse.value) {
+			/* ungrab the pointer */
+			XUngrabPointer(x_disp,CurrentTime);
+		} else {
+			/* grab the pointer */
+			XGrabPointer(x_disp,x_win,True,0,GrabModeAsync,
+				GrabModeAsync,x_win,None,CurrentTime);
+		}
+	}
+}
+
+// flushes the given rectangles from the view buffer to the screen
+
+void	VID_Update (vrect_t *rects)
+{
+	vrect_t full;
+
+// if the window changes dimension, skip this frame
+
+	if (config_notify)
+	{
+		fprintf(stderr, "config notify\n");
+		config_notify = 0;
+		vid.width = config_notify_width & ~7;
+		vid.height = config_notify_height;
+		if (doShm)
+			ResetSharedFrameBuffers();
+		else
+			ResetFrameBuffer();
+		vid.rowbytes = x_framebuffer[0]->bytes_per_line;
+		vid.buffer = x_framebuffer[current_framebuffer]->data;
+		vid.conbuffer = vid.buffer;
+		vid.conwidth = vid.width;
+		vid.conheight = vid.height;
+		vid.conrowbytes = vid.rowbytes;
+		vid.recalc_refdef = 1;				// force a surface cache flush
+		Con_CheckResize();
+		Con_Clear_f();
+		return;
+	}
+
+	// force full update if not 8bit
+	if (x_visinfo->depth != 8) {
+		extern int scr_fullupdate;
+
+		scr_fullupdate = 0;
+	}
+
+
+	if (doShm)
+	{
+
+		while (rects)
+		{
+			if (x_visinfo->depth == 16)
+				st2_fixup( x_framebuffer[current_framebuffer], 
+					rects->x, rects->y, rects->width,
+					rects->height);
+			else if (x_visinfo->depth == 24)
+				st3_fixup( x_framebuffer[current_framebuffer], 
+					rects->x, rects->y, rects->width,
+					rects->height);
+			if (!XShmPutImage(x_disp, x_win, x_gc,
+				x_framebuffer[current_framebuffer], rects->x, rects->y,
+				rects->x, rects->y, rects->width, rects->height, True))
+					Sys_Error("VID_Update: XShmPutImage failed\n");
+			oktodraw = false;
+			while (!oktodraw) GetEvent();
+			rects = rects->pnext;
+		}
+		current_framebuffer = !current_framebuffer;
+		vid.buffer = x_framebuffer[current_framebuffer]->data;
+		vid.conbuffer = vid.buffer;
+		XSync(x_disp, False);
+	}
+	else
+	{
+		while (rects)
+		{
+			if (x_visinfo->depth == 16)
+				st2_fixup( x_framebuffer[current_framebuffer], 
+					rects->x, rects->y, rects->width,
+					rects->height);
+			else if (x_visinfo->depth == 24)
+				st3_fixup( x_framebuffer[current_framebuffer], 
+					rects->x, rects->y, rects->width,
+					rects->height);
+			XPutImage(x_disp, x_win, x_gc, x_framebuffer[0], rects->x,
+				rects->y, rects->x, rects->y, rects->width, rects->height);
+			rects = rects->pnext;
+		}
+		XSync(x_disp, False);
+	}
+
+}
+
+static int dither;
+
+void VID_DitherOn(void)
+{
+    if (dither == 0)
+    {
+		vid.recalc_refdef = 1;
+        dither = 1;
+    }
+}
+
+void VID_DitherOff(void)
+{
+    if (dither)
+    {
+		vid.recalc_refdef = 1;
+        dither = 0;
+    }
+}
+
+int Sys_OpenWindow(void)
+{
+	return 0;
+}
+
+void Sys_EraseWindow(int window)
+{
+}
+
+void Sys_DrawCircle(int window, int x, int y, int r)
+{
+}
+
+void Sys_DisplayWindow(int window)
+{
+}
+
+void Sys_SendKeyEvents(void)
+{
+// get events from x server
+	if (x_disp)
+	{
+		while (XPending(x_disp)) GetEvent();
+		while (keyq_head != keyq_tail)
+		{
+			Key_Event(keyq[keyq_tail].key, keyq[keyq_tail].down);
+			keyq_tail = (keyq_tail + 1) & 63;
+		}
+	}
+}
+
+/*
+char *Sys_ConsoleInput (void)
+{
+
+	static char	text[256];
+	int		len;
+	fd_set  readfds;
+	int		ready;
+	struct timeval timeout;
+
+	timeout.tv_sec = 0;
+	timeout.tv_usec = 0;
+	FD_ZERO(&readfds);
+	FD_SET(0, &readfds);
+	ready = select(1, &readfds, 0, 0, &timeout);
+
+	if (ready>0)
+	{
+		len = read (0, text, sizeof(text));
+		if (len >= 1)
+		{
+			text[len-1] = 0;	// rip off the /n and terminate
+			return text;
+		}
+	}
+
+	return 0;
+	
+}
+*/
+
+void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
+{
+// direct drawing of the "accessing disk" icon isn't supported under Linux
+}
+
+void D_EndDirectRect (int x, int y, int width, int height)
+{
+// direct drawing of the "accessing disk" icon isn't supported under Linux
+}
+
+void IN_Init (void)
+{
+	Cvar_RegisterVariable (&_windowed_mouse);
+	Cvar_RegisterVariable (&m_filter);
+   if ( COM_CheckParm ("-nomouse") )
+     return;
+   mouse_x = mouse_y = 0.0;
+   mouse_avail = 1;
+}
+
+void IN_Shutdown (void)
+{
+   mouse_avail = 0;
+}
+
+void IN_Commands (void)
+{
+	int i;
+   
+	if (!mouse_avail) return;
+   
+	for (i=0 ; i<mouse_buttons ; i++) {
+		if ( (mouse_buttonstate & (1<<i)) && !(mouse_oldbuttonstate & (1<<i)) )
+			Key_Event (K_MOUSE1 + i, true);
+
+		if ( !(mouse_buttonstate & (1<<i)) && (mouse_oldbuttonstate & (1<<i)) )
+			Key_Event (K_MOUSE1 + i, false);
+	}
+	mouse_oldbuttonstate = mouse_buttonstate;
+}
+
+void IN_Move (usercmd_t *cmd)
+{
+	if (!mouse_avail)
+		return;
+   
+	if (m_filter.value) {
+		mouse_x = (mouse_x + old_mouse_x) * 0.5;
+		mouse_y = (mouse_y + old_mouse_y) * 0.5;
+	}
+
+	old_mouse_x = mouse_x;
+	old_mouse_y = mouse_y;
+   
+	mouse_x *= sensitivity.value;
+	mouse_y *= sensitivity.value;
+   
+	if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) ))
+		cmd->sidemove += m_side.value * mouse_x;
+	else
+		cl.viewangles[YAW] -= m_yaw.value * mouse_x;
+	if (in_mlook.state & 1)
+		V_StopPitchDrift ();
+   
+	if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) {
+		cl.viewangles[PITCH] += m_pitch.value * mouse_y;
+		if (cl.viewangles[PITCH] > 80)
+			cl.viewangles[PITCH] = 80;
+		if (cl.viewangles[PITCH] < -70)
+			cl.viewangles[PITCH] = -70;
+	} else {
+		if ((in_strafe.state & 1) && noclip_anglehack)
+			cmd->upmove -= m_forward.value * mouse_y;
+		else
+			cmd->forwardmove -= m_forward.value * mouse_y;
+	}
+	mouse_x = mouse_y = 0.0;
+}
--- a/vid_x.c
+++ /dev/null
@@ -1,1157 +1,0 @@
-// vid_x.c -- general x video driver
-
-#define _BSD
-
-#include <u.h>
-#include <libc.h>
-//#include <ctype.h>
-#include <sys/time.h>
-#include <sys/types.h>
-//#include <unistd.h>
-#include <signal.h>
-//#include <stdlib.h>
-//#include <stdio.h>
-//#include <string.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/Xatom.h>
-#include <X11/keysym.h>
-#include <X11/extensions/XShm.h>
-
-#include "quakedef.h"
-#include "d_local.h"
-
-cvar_t		_windowed_mouse = {"_windowed_mouse","0", true};
-cvar_t		m_filter = {"m_filter","0", true};
-float old_windowed_mouse;
-
-qboolean        mouse_avail;
-int             mouse_buttons=3;
-int             mouse_oldbuttonstate;
-int             mouse_buttonstate;
-float   mouse_x, mouse_y;
-float   old_mouse_x, old_mouse_y;
-int p_mouse_x;
-int p_mouse_y;
-int ignorenext;
-int bits_per_pixel;
-
-typedef struct
-{
-	int input;
-	int output;
-} keymap_t;
-
-viddef_t vid; // global video state
-unsigned short d_8to16table[256];
-
-int		num_shades=32;
-
-int	d_con_indirect = 0;
-
-int		vid_buffersize;
-
-static qboolean			doShm;
-static Display			*x_disp;
-static Colormap			x_cmap;
-static Window			x_win;
-static GC				x_gc;
-static Visual			*x_vis;
-static XVisualInfo		*x_visinfo;
-//static XImage			*x_image;
-
-static int				x_shmeventtype;
-//static XShmSegmentInfo	x_shminfo;
-
-static qboolean			oktodraw = false;
-
-int XShmQueryExtension(Display *);
-int XShmGetEventBase(Display *);
-
-int current_framebuffer;
-static XImage			*x_framebuffer[2] = { 0, 0 };
-static XShmSegmentInfo	x_shminfo[2];
-
-static int verbose=0;
-
-static byte current_palette[768];
-
-static s32int X11_highhunkmark;
-static s32int X11_buffersize;
-
-int vid_surfcachesize;
-void *vid_surfcache;
-
-void (*vid_menudrawfn)(void);
-void (*vid_menukeyfn)(int key);
-void VID_MenuKey (int key);
-
-typedef unsigned short PIXEL16;
-typedef u32int PIXEL24;
-static PIXEL16 st2d_8to16table[256];
-static PIXEL24 st2d_8to24table[256];
-static int shiftmask_fl=0;
-static s32int r_shift,g_shift,b_shift;
-static u32int r_mask,g_mask,b_mask;
-
-void shiftmask_init()
-{
-    unsigned int x;
-    r_mask=x_vis->red_mask;
-    g_mask=x_vis->green_mask;
-    b_mask=x_vis->blue_mask;
-    for(r_shift=-8,x=1;x<r_mask;x=x<<1)r_shift++;
-    for(g_shift=-8,x=1;x<g_mask;x=x<<1)g_shift++;
-    for(b_shift=-8,x=1;x<b_mask;x=x<<1)b_shift++;
-    shiftmask_fl=1;
-}
-
-PIXEL16 xlib_rgb16(int r,int g,int b)
-{
-    PIXEL16 p;
-    if(shiftmask_fl==0) shiftmask_init();
-    p=0;
-
-    if(r_shift>0) {
-        p=(r<<(r_shift))&r_mask;
-    } else if(r_shift<0) {
-        p=(r>>(-r_shift))&r_mask;
-    } else p|=(r&r_mask);
-
-    if(g_shift>0) {
-        p|=(g<<(g_shift))&g_mask;
-    } else if(g_shift<0) {
-        p|=(g>>(-g_shift))&g_mask;
-    } else p|=(g&g_mask);
-
-    if(b_shift>0) {
-        p|=(b<<(b_shift))&b_mask;
-    } else if(b_shift<0) {
-        p|=(b>>(-b_shift))&b_mask;
-    } else p|=(b&b_mask);
-
-    return p;
-}
-
-PIXEL24 xlib_rgb24(int r,int g,int b)
-{
-    PIXEL24 p;
-    if(shiftmask_fl==0) shiftmask_init();
-    p=0;
-
-    if(r_shift>0) {
-        p=(r<<(r_shift))&r_mask;
-    } else if(r_shift<0) {
-        p=(r>>(-r_shift))&r_mask;
-    } else p|=(r&r_mask);
-
-    if(g_shift>0) {
-        p|=(g<<(g_shift))&g_mask;
-    } else if(g_shift<0) {
-        p|=(g>>(-g_shift))&g_mask;
-    } else p|=(g&g_mask);
-
-    if(b_shift>0) {
-        p|=(b<<(b_shift))&b_mask;
-    } else if(b_shift<0) {
-        p|=(b>>(-b_shift))&b_mask;
-    } else p|=(b&b_mask);
-
-    return p;
-}
-
-void st2_fixup( XImage *framebuf, int x, int y, int width, int height)
-{
-	int xi,yi;
-	unsigned char *src;
-	PIXEL16 *dest;
-	register int count, n;
-
-	if( (x<0)||(y<0) )return;
-
-	for (yi = y; yi < (y+height); yi++) {
-		src = &framebuf->data [yi * framebuf->bytes_per_line];
-
-		// Duff's Device
-		count = width;
-		n = (count + 7) / 8;
-		dest = ((PIXEL16 *)src) + x+width - 1;
-		src += x+width - 1;
-
-		switch (count % 8) {
-		case 0:	do {	*dest-- = st2d_8to16table[*src--];
-		case 7:			*dest-- = st2d_8to16table[*src--];
-		case 6:			*dest-- = st2d_8to16table[*src--];
-		case 5:			*dest-- = st2d_8to16table[*src--];
-		case 4:			*dest-- = st2d_8to16table[*src--];
-		case 3:			*dest-- = st2d_8to16table[*src--];
-		case 2:			*dest-- = st2d_8to16table[*src--];
-		case 1:			*dest-- = st2d_8to16table[*src--];
-				} while (--n > 0);
-		}
-
-//		for(xi = (x+width-1); xi >= x; xi--) {
-//			dest[xi] = st2d_8to16table[src[xi]];
-//		}
-	}
-}
-
-void st3_fixup( XImage *framebuf, int x, int y, int width, int height)
-{
-	int xi,yi;
-	unsigned char *src;
-	PIXEL24 *dest;
-	register int count, n;
-
-	if( (x<0)||(y<0) )return;
-
-	for (yi = y; yi < (y+height); yi++) {
-		src = &framebuf->data [yi * framebuf->bytes_per_line];
-
-		// Duff's Device
-		count = width;
-		n = (count + 7) / 8;
-		dest = ((PIXEL24 *)src) + x+width - 1;
-		src += x+width - 1;
-
-		switch (count % 8) {
-		case 0:	do {	*dest-- = st2d_8to24table[*src--];
-		case 7:			*dest-- = st2d_8to24table[*src--];
-		case 6:			*dest-- = st2d_8to24table[*src--];
-		case 5:			*dest-- = st2d_8to24table[*src--];
-		case 4:			*dest-- = st2d_8to24table[*src--];
-		case 3:			*dest-- = st2d_8to24table[*src--];
-		case 2:			*dest-- = st2d_8to24table[*src--];
-		case 1:			*dest-- = st2d_8to24table[*src--];
-				} while (--n > 0);
-		}
-
-//		for(xi = (x+width-1); xi >= x; xi--) {
-//			dest[xi] = st2d_8to16table[src[xi]];
-//		}
-	}
-}
-
-
-// ========================================================================
-// Tragic death handler
-// ========================================================================
-
-void TragicDeath(int signal_num)
-{
-	XAutoRepeatOn(x_disp);
-	XCloseDisplay(x_disp);
-	Sys_Error("This death brought to you by the number %d\n", signal_num);
-}
-
-// ========================================================================
-// makes a null cursor
-// ========================================================================
-
-static Cursor CreateNullCursor(Display *display, Window root)
-{
-    Pixmap cursormask; 
-    XGCValues xgc;
-    GC gc;
-    XColor dummycolour;
-    Cursor cursor;
-
-    cursormask = XCreatePixmap(display, root, 1, 1, 1/*depth*/);
-    xgc.function = GXclear;
-    gc =  XCreateGC(display, cursormask, GCFunction, &xgc);
-    XFillRectangle(display, cursormask, gc, 0, 0, 1, 1);
-    dummycolour.pixel = 0;
-    dummycolour.red = 0;
-    dummycolour.flags = 04;
-    cursor = XCreatePixmapCursor(display, cursormask, cursormask,
-          &dummycolour,&dummycolour, 0,0);
-    XFreePixmap(display,cursormask);
-    XFreeGC(display,gc);
-    return cursor;
-}
-
-void ResetFrameBuffer(void)
-{
-	int mem;
-	int pwidth;
-
-	if (x_framebuffer[0])
-	{
-		free(x_framebuffer[0]->data);
-		free(x_framebuffer[0]);
-	}
-
-	if (d_pzbuffer)
-	{
-		D_FlushCaches ();
-		Hunk_FreeToHighMark (X11_highhunkmark);
-		d_pzbuffer = NULL;
-	}
-	X11_highhunkmark = Hunk_HighMark ();
-
-// alloc an extra line in case we want to wrap, and allocate the z-buffer
-	X11_buffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
-
-	vid_surfcachesize = D_SurfaceCacheForRes (vid.width, vid.height);
-
-	X11_buffersize += vid_surfcachesize;
-
-	d_pzbuffer = Hunk_HighAllocName (X11_buffersize, "video");
-	if (d_pzbuffer == NULL)
-		Sys_Error ("Not enough memory for video mode\n");
-
-	vid_surfcache = (byte *) d_pzbuffer
-		+ vid.width * vid.height * sizeof (*d_pzbuffer);
-
-	D_InitCaches(vid_surfcache, vid_surfcachesize);
-
-	pwidth = x_visinfo->depth / 8;
-	if (pwidth == 3) pwidth = 4;
-	mem = ((vid.width*pwidth+7)&~7) * vid.height;
-
-	x_framebuffer[0] = XCreateImage(	x_disp,
-		x_vis,
-		x_visinfo->depth,
-		ZPixmap,
-		0,
-		malloc(mem),
-		vid.width, vid.height,
-		32,
-		0);
-
-	if (!x_framebuffer[0])
-		Sys_Error("VID: XCreateImage failed\n");
-
-	vid.buffer = (byte*) (x_framebuffer[0]);
-	vid.conbuffer = vid.buffer;
-
-}
-
-void ResetSharedFrameBuffers(void)
-{
-
-	int size;
-	int key;
-	int minsize = getpagesize();
-	int frm;
-
-	if (d_pzbuffer)
-	{
-		D_FlushCaches ();
-		Hunk_FreeToHighMark (X11_highhunkmark);
-		d_pzbuffer = NULL;
-	}
-
-	X11_highhunkmark = Hunk_HighMark ();
-
-// alloc an extra line in case we want to wrap, and allocate the z-buffer
-	X11_buffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
-
-	vid_surfcachesize = D_SurfaceCacheForRes (vid.width, vid.height);
-
-	X11_buffersize += vid_surfcachesize;
-
-	d_pzbuffer = Hunk_HighAllocName (X11_buffersize, "video");
-	if (d_pzbuffer == NULL)
-		Sys_Error ("Not enough memory for video mode\n");
-
-	vid_surfcache = (byte *) d_pzbuffer
-		+ vid.width * vid.height * sizeof (*d_pzbuffer);
-
-	D_InitCaches(vid_surfcache, vid_surfcachesize);
-
-	for (frm=0 ; frm<2 ; frm++)
-	{
-
-	// free up old frame buffer memory
-
-		if (x_framebuffer[frm])
-		{
-			XShmDetach(x_disp, &x_shminfo[frm]);
-			free(x_framebuffer[frm]);
-			shmdt(x_shminfo[frm].shmaddr);
-		}
-
-	// create the image
-
-		x_framebuffer[frm] = XShmCreateImage(	x_disp,
-						x_vis,
-						x_visinfo->depth,
-						ZPixmap,
-						0,
-						&x_shminfo[frm],
-						vid.width,
-						vid.height );
-
-	// grab shared memory
-
-		size = x_framebuffer[frm]->bytes_per_line
-			* x_framebuffer[frm]->height;
-		if (size < minsize)
-			Sys_Error("VID: Window must use at least %d bytes\n", minsize);
-
-		key = random();
-		x_shminfo[frm].shmid = shmget((key_t)key, size, IPC_CREAT|0777);
-		if (x_shminfo[frm].shmid==-1)
-			Sys_Error("VID: Could not get any shared memory\n");
-
-		// attach to the shared memory segment
-		x_shminfo[frm].shmaddr =
-			(void *) shmat(x_shminfo[frm].shmid, 0, 0);
-
-		printf("VID: shared memory id=%d, addr=0x%p\n", x_shminfo[frm].shmid,
-			x_shminfo[frm].shmaddr);
-
-		x_framebuffer[frm]->data = x_shminfo[frm].shmaddr;
-
-	// get the X server to attach to it
-
-		if (!XShmAttach(x_disp, &x_shminfo[frm]))
-			Sys_Error("VID: XShmAttach() failed\n");
-		XSync(x_disp, 0);
-		shmctl(x_shminfo[frm].shmid, IPC_RMID, 0);
-
-	}
-
-}
-
-// Called at startup to set up translation tables, takes 256 8 bit RGB values
-// the palette data will go away after the call, so it must be copied off if
-// the video driver will need it again
-
-void	VID_Init (unsigned char *palette)
-{
-
-   int pnum, i;
-   XVisualInfo template;
-   int num_visuals;
-   int template_mask;
-   
-   ignorenext=0;
-   vid.width = 320;
-   vid.height = 200;
-   vid.maxwarpwidth = WARP_WIDTH;
-   vid.maxwarpheight = WARP_HEIGHT;
-   vid.numpages = 2;
-   vid.colormap = host_colormap;
-   //	vid.cbits = VID_CBITS;
-   //	vid.grades = VID_GRADES;
-   vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
-   
-	srandom(getpid());
-
-	verbose=COM_CheckParm("-verbose");
-
-// open the display
-	x_disp = XOpenDisplay(0);
-	if (!x_disp)
-	{
-		if (getenv("DISPLAY"))
-			Sys_Error("VID: Could not open display [%s]\n",
-				getenv("DISPLAY"));
-		else
-			Sys_Error("VID: Could not open local display\n");
-	}
-
-// catch signals so i can turn on auto-repeat
-
-	{
-		struct sigaction sa;
-		sigaction(SIGINT, 0, &sa);
-		sa.sa_handler = TragicDeath;
-		sigaction(SIGINT, &sa, 0);
-		sigaction(SIGTERM, &sa, 0);
-	}
-
-	XAutoRepeatOff(x_disp);
-
-// for debugging only
-	XSynchronize(x_disp, True);
-
-// check for command-line window size
-	if ((pnum=COM_CheckParm("-winsize")))
-	{
-		if (pnum >= com_argc-2)
-			Sys_Error("VID: -winsize <width> <height>\n");
-		vid.width = Q_atoi(com_argv[pnum+1]);
-		vid.height = Q_atoi(com_argv[pnum+2]);
-		if (!vid.width || !vid.height)
-			Sys_Error("VID: Bad window width/height\n");
-	}
-	if ((pnum=COM_CheckParm("-width"))) {
-		if (pnum >= com_argc-1)
-			Sys_Error("VID: -width <width>\n");
-		vid.width = Q_atoi(com_argv[pnum+1]);
-		if (!vid.width)
-			Sys_Error("VID: Bad window width\n");
-	}
-	if ((pnum=COM_CheckParm("-height"))) {
-		if (pnum >= com_argc-1)
-			Sys_Error("VID: -height <height>\n");
-		vid.height = Q_atoi(com_argv[pnum+1]);
-		if (!vid.height)
-			Sys_Error("VID: Bad window height\n");
-	}
-
-	template_mask = 0;
-
-// specify a visual id
-	if ((pnum=COM_CheckParm("-visualid")))
-	{
-		if (pnum >= com_argc-1)
-			Sys_Error("VID: -visualid <id#>\n");
-		template.visualid = Q_atoi(com_argv[pnum+1]);
-		template_mask = VisualIDMask;
-	}
-
-// If not specified, use default visual
-	else
-	{
-		int screen;
-		screen = XDefaultScreen(x_disp);
-		template.visualid =
-			XVisualIDFromVisual(XDefaultVisual(x_disp, screen));
-		template_mask = VisualIDMask;
-	}
-
-// pick a visual- warn if more than one was available
-	x_visinfo = XGetVisualInfo(x_disp, template_mask, &template, &num_visuals);
-	if (num_visuals > 1)
-	{
-		printf("Found more than one visual id at depth %d:\n", template.depth);
-		for (i=0 ; i<num_visuals ; i++)
-			printf("	-visualid %d\n", (int)(x_visinfo[i].visualid));
-	}
-	else if (num_visuals == 0)
-	{
-		if (template_mask == VisualIDMask)
-			Sys_Error("VID: Bad visual id %d\n", template.visualid);
-		else
-			Sys_Error("VID: No visuals at depth %d\n", template.depth);
-	}
-
-	if (verbose)
-	{
-		printf("Using visualid %d:\n", (int)(x_visinfo->visualid));
-		printf("	screen %d\n", x_visinfo->screen);
-		printf("	red_mask 0x%x\n", (int)(x_visinfo->red_mask));
-		printf("	green_mask 0x%x\n", (int)(x_visinfo->green_mask));
-		printf("	blue_mask 0x%x\n", (int)(x_visinfo->blue_mask));
-		printf("	colormap_size %d\n", x_visinfo->colormap_size);
-		printf("	bits_per_rgb %d\n", x_visinfo->bits_per_rgb);
-	}
-
-	x_vis = x_visinfo->visual;
-
-// setup attributes for main window
-	{
-	   int attribmask = CWEventMask  | CWColormap | CWBorderPixel;
-	   XSetWindowAttributes attribs;
-	   Colormap tmpcmap;
-	   
-	   tmpcmap = XCreateColormap(x_disp, XRootWindow(x_disp,
-							 x_visinfo->screen), x_vis, AllocNone);
-	   
-           attribs.event_mask = StructureNotifyMask | KeyPressMask
-	     | KeyReleaseMask | ExposureMask | PointerMotionMask |
-	     ButtonPressMask | ButtonReleaseMask;
-	   attribs.border_pixel = 0;
-	   attribs.colormap = tmpcmap;
-
-// create the main window
-		x_win = XCreateWindow(	x_disp,
-			XRootWindow(x_disp, x_visinfo->screen),
-			0, 0,	// x, y
-			vid.width, vid.height,
-			0, // borderwidth
-			x_visinfo->depth,
-			InputOutput,
-			x_vis,
-			attribmask,
-			&attribs );
-		XStoreName( x_disp,x_win,"xquake");
-
-
-		if (x_visinfo->class != TrueColor)
-			XFreeColormap(x_disp, tmpcmap);
-	}
-
-	if (x_visinfo->depth == 8)
-	{
-		// create and upload the palette
-		if (x_visinfo->class == PseudoColor)
-		{
-			x_cmap = XCreateColormap(x_disp, x_win, x_vis, AllocAll);
-			VID_SetPalette(palette);
-			XSetWindowColormap(x_disp, x_win, x_cmap);
-		}
-	}
-
-// inviso cursor
-	XDefineCursor(x_disp, x_win, CreateNullCursor(x_disp, x_win));
-
-// create the GC
-	{
-		XGCValues xgcvalues;
-		int valuemask = GCGraphicsExposures;
-		xgcvalues.graphics_exposures = False;
-		x_gc = XCreateGC(x_disp, x_win, valuemask, &xgcvalues );
-	}
-
-// map the window
-	XMapWindow(x_disp, x_win);
-
-// wait for first exposure event
-	{
-		XEvent event;
-		do
-		{
-			XNextEvent(x_disp, &event);
-			if (event.type == Expose && !event.xexpose.count)
-				oktodraw = true;
-		} while (!oktodraw);
-	}
-// now safe to draw
-
-// even if MITSHM is available, make sure it's a local connection
-	if (XShmQueryExtension(x_disp))
-	{
-		char *displayname;
-		doShm = true;
-		displayname = (char *) getenv("DISPLAY");
-		if (displayname)
-		{
-			char *d = displayname;
-			while (*d && (*d != ':')) d++;
-			if (*d) *d = 0;
-			if (!(!strcasecmp(displayname, "unix") || !*displayname))
-				doShm = false;
-		}
-	}
-
-	if (doShm)
-	{
-		x_shmeventtype = XShmGetEventBase(x_disp) + ShmCompletion;
-		ResetSharedFrameBuffers();
-	}
-	else
-		ResetFrameBuffer();
-
-	current_framebuffer = 0;
-	vid.rowbytes = x_framebuffer[0]->bytes_per_line;
-	vid.buffer = x_framebuffer[0]->data;
-	vid.direct = 0;
-	vid.conbuffer = x_framebuffer[0]->data;
-	vid.conrowbytes = vid.rowbytes;
-	vid.conwidth = vid.width;
-	vid.conheight = vid.height;
-	vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0);
-
-//	XSynchronize(x_disp, False);
-
-}
-
-void VID_ShiftPalette(unsigned char *p)
-{
-	VID_SetPalette(p);
-}
-
-
-
-void VID_SetPalette(unsigned char *palette)
-{
-
-	int i;
-	XColor colors[256];
-
-	for(i=0;i<256;i++) {
-		st2d_8to16table[i]= xlib_rgb16(palette[i*3], palette[i*3+1],palette[i*3+2]);
-		st2d_8to24table[i]= xlib_rgb24(palette[i*3], palette[i*3+1],palette[i*3+2]);
-	}
-
-	if (x_visinfo->class == PseudoColor && x_visinfo->depth == 8)
-	{
-		if (palette != current_palette)
-			memcpy(current_palette, palette, 768);
-		for (i=0 ; i<256 ; i++)
-		{
-			colors[i].pixel = i;
-			colors[i].flags = DoRed|DoGreen|DoBlue;
-			colors[i].red = palette[i*3] * 257;
-			colors[i].green = palette[i*3+1] * 257;
-			colors[i].blue = palette[i*3+2] * 257;
-		}
-		XStoreColors(x_disp, x_cmap, colors, 256);
-	}
-
-}
-
-// Called at shutdown
-
-void	VID_Shutdown (void)
-{
-	Con_Printf("VID_Shutdown\n");
-	XAutoRepeatOn(x_disp);
-	XCloseDisplay(x_disp);
-}
-
-int XLateKey(XKeyEvent *ev)
-{
-
-	int key;
-	char buf[64];
-	KeySym keysym;
-
-	key = 0;
-
-	XLookupString(ev, buf, sizeof buf, &keysym, 0);
-
-	switch(keysym)
-	{
-		case XK_KP_Page_Up:
-		case XK_Page_Up:	 key = K_PGUP; break;
-
-		case XK_KP_Page_Down:
-		case XK_Page_Down:	 key = K_PGDN; break;
-
-		case XK_KP_Home:
-		case XK_Home:	 key = K_HOME; break;
-
-		case XK_KP_End:
-		case XK_End:	 key = K_END; break;
-
-		case XK_KP_Left:
-		case XK_Left:	 key = K_LEFTARROW; break;
-
-		case XK_KP_Right:
-		case XK_Right:	key = K_RIGHTARROW;		break;
-
-		case XK_KP_Down:
-		case XK_Down:	 key = K_DOWNARROW; break;
-
-		case XK_KP_Up:
-		case XK_Up:		 key = K_UPARROW;	 break;
-
-		case XK_Escape: key = K_ESCAPE;		break;
-
-		case XK_KP_Enter:
-		case XK_Return: key = K_ENTER;		 break;
-
-		case XK_Tab:		key = K_TAB;			 break;
-
-		case XK_F1:		 key = K_F1;				break;
-
-		case XK_F2:		 key = K_F2;				break;
-
-		case XK_F3:		 key = K_F3;				break;
-
-		case XK_F4:		 key = K_F4;				break;
-
-		case XK_F5:		 key = K_F5;				break;
-
-		case XK_F6:		 key = K_F6;				break;
-
-		case XK_F7:		 key = K_F7;				break;
-
-		case XK_F8:		 key = K_F8;				break;
-
-		case XK_F9:		 key = K_F9;				break;
-
-		case XK_F10:		key = K_F10;			 break;
-
-		case XK_F11:		key = K_F11;			 break;
-
-		case XK_F12:		key = K_F12;			 break;
-
-		case XK_BackSpace: key = K_BACKSPACE; break;
-
-		case XK_KP_Delete:
-		case XK_Delete: key = K_DEL; break;
-
-		case XK_Pause:	key = K_PAUSE;		 break;
-
-		case XK_Shift_L:
-		case XK_Shift_R:	key = K_SHIFT;		break;
-
-		case XK_Execute: 
-		case XK_Control_L: 
-		case XK_Control_R:	key = K_CTRL;		 break;
-
-		case XK_Alt_L:	
-		case XK_Meta_L: 
-		case XK_Alt_R:	
-		case XK_Meta_R: key = K_ALT;			break;
-
-		case XK_KP_Begin: key = K_AUX30;	break;
-
-		case XK_Insert:
-		case XK_KP_Insert: key = K_INS; break;
-
-		case XK_KP_Multiply: key = '*'; break;
-		case XK_KP_Add: key = '+'; break;
-		case XK_KP_Subtract: key = '-'; break;
-		case XK_KP_Divide: key = '/'; break;
-		default:
-			key = *(unsigned char*)buf;
-			if (key >= 'A' && key <= 'Z')
-				key = key - 'A' + 'a';
-//			fprintf(stdout, "case 0x0%x: key = ___;break;/* [%c] */\n", keysym);
-			break;
-	} 
-
-	return key;
-}
-
-struct
-{
-	int key;
-	int down;
-} keyq[64];
-int keyq_head=0;
-int keyq_tail=0;
-
-int config_notify=0;
-int config_notify_width;
-int config_notify_height;
-						      
-void GetEvent(void)
-{
-	XEvent x_event;
-	int b;
-   
-	XNextEvent(x_disp, &x_event);
-	switch(x_event.type) {
-	case KeyPress:
-		keyq[keyq_head].key = XLateKey(&x_event.xkey);
-		keyq[keyq_head].down = true;
-		keyq_head = (keyq_head + 1) & 63;
-		break;
-	case KeyRelease:
-		keyq[keyq_head].key = XLateKey(&x_event.xkey);
-		keyq[keyq_head].down = false;
-		keyq_head = (keyq_head + 1) & 63;
-		break;
-
-	case MotionNotify:
-		if (_windowed_mouse.value) {
-			mouse_x = (float) ((int)x_event.xmotion.x - (int)(vid.width/2));
-			mouse_y = (float) ((int)x_event.xmotion.y - (int)(vid.height/2));
-//printf("m: x=%d,y=%d, mx=%3.2f,my=%3.2f\n", 
-//	x_event.xmotion.x, x_event.xmotion.y, mouse_x, mouse_y);
-
-			/* move the mouse to the window center again */
-			XSelectInput(x_disp,x_win,StructureNotifyMask|KeyPressMask
-				|KeyReleaseMask|ExposureMask
-				|ButtonPressMask
-				|ButtonReleaseMask);
-			XWarpPointer(x_disp,None,x_win,0,0,0,0, 
-				(vid.width/2),(vid.height/2));
-			XSelectInput(x_disp,x_win,StructureNotifyMask|KeyPressMask
-				|KeyReleaseMask|ExposureMask
-				|PointerMotionMask|ButtonPressMask
-				|ButtonReleaseMask);
-		} else {
-			mouse_x = (float) (x_event.xmotion.x-p_mouse_x);
-			mouse_y = (float) (x_event.xmotion.y-p_mouse_y);
-			p_mouse_x=x_event.xmotion.x;
-			p_mouse_y=x_event.xmotion.y;
-		}
-		break;
-
-	case ButtonPress:
-		b=-1;
-		if (x_event.xbutton.button == 1)
-			b = 0;
-		else if (x_event.xbutton.button == 2)
-			b = 2;
-		else if (x_event.xbutton.button == 3)
-			b = 1;
-		if (b>=0)
-			mouse_buttonstate |= 1<<b;
-		break;
-
-	case ButtonRelease:
-		b=-1;
-		if (x_event.xbutton.button == 1)
-			b = 0;
-		else if (x_event.xbutton.button == 2)
-			b = 2;
-		else if (x_event.xbutton.button == 3)
-			b = 1;
-		if (b>=0)
-			mouse_buttonstate &= ~(1<<b);
-		break;
-	
-	case ConfigureNotify:
-//printf("config notify\n");
-		config_notify_width = x_event.xconfigure.width;
-		config_notify_height = x_event.xconfigure.height;
-		config_notify = 1;
-		break;
-
-	default:
-		if (doShm && x_event.type == x_shmeventtype)
-			oktodraw = true;
-	}
-   
-	if (old_windowed_mouse != _windowed_mouse.value) {
-		old_windowed_mouse = _windowed_mouse.value;
-
-		if (!_windowed_mouse.value) {
-			/* ungrab the pointer */
-			XUngrabPointer(x_disp,CurrentTime);
-		} else {
-			/* grab the pointer */
-			XGrabPointer(x_disp,x_win,True,0,GrabModeAsync,
-				GrabModeAsync,x_win,None,CurrentTime);
-		}
-	}
-}
-
-// flushes the given rectangles from the view buffer to the screen
-
-void	VID_Update (vrect_t *rects)
-{
-	vrect_t full;
-
-// if the window changes dimension, skip this frame
-
-	if (config_notify)
-	{
-		fprintf(stderr, "config notify\n");
-		config_notify = 0;
-		vid.width = config_notify_width & ~7;
-		vid.height = config_notify_height;
-		if (doShm)
-			ResetSharedFrameBuffers();
-		else
-			ResetFrameBuffer();
-		vid.rowbytes = x_framebuffer[0]->bytes_per_line;
-		vid.buffer = x_framebuffer[current_framebuffer]->data;
-		vid.conbuffer = vid.buffer;
-		vid.conwidth = vid.width;
-		vid.conheight = vid.height;
-		vid.conrowbytes = vid.rowbytes;
-		vid.recalc_refdef = 1;				// force a surface cache flush
-		Con_CheckResize();
-		Con_Clear_f();
-		return;
-	}
-
-	// force full update if not 8bit
-	if (x_visinfo->depth != 8) {
-		extern int scr_fullupdate;
-
-		scr_fullupdate = 0;
-	}
-
-
-	if (doShm)
-	{
-
-		while (rects)
-		{
-			if (x_visinfo->depth == 16)
-				st2_fixup( x_framebuffer[current_framebuffer], 
-					rects->x, rects->y, rects->width,
-					rects->height);
-			else if (x_visinfo->depth == 24)
-				st3_fixup( x_framebuffer[current_framebuffer], 
-					rects->x, rects->y, rects->width,
-					rects->height);
-			if (!XShmPutImage(x_disp, x_win, x_gc,
-				x_framebuffer[current_framebuffer], rects->x, rects->y,
-				rects->x, rects->y, rects->width, rects->height, True))
-					Sys_Error("VID_Update: XShmPutImage failed\n");
-			oktodraw = false;
-			while (!oktodraw) GetEvent();
-			rects = rects->pnext;
-		}
-		current_framebuffer = !current_framebuffer;
-		vid.buffer = x_framebuffer[current_framebuffer]->data;
-		vid.conbuffer = vid.buffer;
-		XSync(x_disp, False);
-	}
-	else
-	{
-		while (rects)
-		{
-			if (x_visinfo->depth == 16)
-				st2_fixup( x_framebuffer[current_framebuffer], 
-					rects->x, rects->y, rects->width,
-					rects->height);
-			else if (x_visinfo->depth == 24)
-				st3_fixup( x_framebuffer[current_framebuffer], 
-					rects->x, rects->y, rects->width,
-					rects->height);
-			XPutImage(x_disp, x_win, x_gc, x_framebuffer[0], rects->x,
-				rects->y, rects->x, rects->y, rects->width, rects->height);
-			rects = rects->pnext;
-		}
-		XSync(x_disp, False);
-	}
-
-}
-
-static int dither;
-
-void VID_DitherOn(void)
-{
-    if (dither == 0)
-    {
-		vid.recalc_refdef = 1;
-        dither = 1;
-    }
-}
-
-void VID_DitherOff(void)
-{
-    if (dither)
-    {
-		vid.recalc_refdef = 1;
-        dither = 0;
-    }
-}
-
-int Sys_OpenWindow(void)
-{
-	return 0;
-}
-
-void Sys_EraseWindow(int window)
-{
-}
-
-void Sys_DrawCircle(int window, int x, int y, int r)
-{
-}
-
-void Sys_DisplayWindow(int window)
-{
-}
-
-void Sys_SendKeyEvents(void)
-{
-// get events from x server
-	if (x_disp)
-	{
-		while (XPending(x_disp)) GetEvent();
-		while (keyq_head != keyq_tail)
-		{
-			Key_Event(keyq[keyq_tail].key, keyq[keyq_tail].down);
-			keyq_tail = (keyq_tail + 1) & 63;
-		}
-	}
-}
-
-/*
-char *Sys_ConsoleInput (void)
-{
-
-	static char	text[256];
-	int		len;
-	fd_set  readfds;
-	int		ready;
-	struct timeval timeout;
-
-	timeout.tv_sec = 0;
-	timeout.tv_usec = 0;
-	FD_ZERO(&readfds);
-	FD_SET(0, &readfds);
-	ready = select(1, &readfds, 0, 0, &timeout);
-
-	if (ready>0)
-	{
-		len = read (0, text, sizeof(text));
-		if (len >= 1)
-		{
-			text[len-1] = 0;	// rip off the /n and terminate
-			return text;
-		}
-	}
-
-	return 0;
-	
-}
-*/
-
-void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
-{
-// direct drawing of the "accessing disk" icon isn't supported under Linux
-}
-
-void D_EndDirectRect (int x, int y, int width, int height)
-{
-// direct drawing of the "accessing disk" icon isn't supported under Linux
-}
-
-void IN_Init (void)
-{
-	Cvar_RegisterVariable (&_windowed_mouse);
-	Cvar_RegisterVariable (&m_filter);
-   if ( COM_CheckParm ("-nomouse") )
-     return;
-   mouse_x = mouse_y = 0.0;
-   mouse_avail = 1;
-}
-
-void IN_Shutdown (void)
-{
-   mouse_avail = 0;
-}
-
-void IN_Commands (void)
-{
-	int i;
-   
-	if (!mouse_avail) return;
-   
-	for (i=0 ; i<mouse_buttons ; i++) {
-		if ( (mouse_buttonstate & (1<<i)) && !(mouse_oldbuttonstate & (1<<i)) )
-			Key_Event (K_MOUSE1 + i, true);
-
-		if ( !(mouse_buttonstate & (1<<i)) && (mouse_oldbuttonstate & (1<<i)) )
-			Key_Event (K_MOUSE1 + i, false);
-	}
-	mouse_oldbuttonstate = mouse_buttonstate;
-}
-
-void IN_Move (usercmd_t *cmd)
-{
-	if (!mouse_avail)
-		return;
-   
-	if (m_filter.value) {
-		mouse_x = (mouse_x + old_mouse_x) * 0.5;
-		mouse_y = (mouse_y + old_mouse_y) * 0.5;
-	}
-
-	old_mouse_x = mouse_x;
-	old_mouse_y = mouse_y;
-   
-	mouse_x *= sensitivity.value;
-	mouse_y *= sensitivity.value;
-   
-	if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) ))
-		cmd->sidemove += m_side.value * mouse_x;
-	else
-		cl.viewangles[YAW] -= m_yaw.value * mouse_x;
-	if (in_mlook.state & 1)
-		V_StopPitchDrift ();
-   
-	if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) {
-		cl.viewangles[PITCH] += m_pitch.value * mouse_y;
-		if (cl.viewangles[PITCH] > 80)
-			cl.viewangles[PITCH] = 80;
-		if (cl.viewangles[PITCH] < -70)
-			cl.viewangles[PITCH] = -70;
-	} else {
-		if ((in_strafe.state & 1) && noclip_anglehack)
-			cmd->upmove -= m_forward.value * mouse_y;
-		else
-			cmd->forwardmove -= m_forward.value * mouse_y;
-	}
-	mouse_x = mouse_y = 0.0;
-}