shithub: qk1

Download patch

ref: ee0395513ea7be03d7dc8aae4c0b4bfbb59c0427
parent: 0b9b33f9b960cd9c56b4d7d7030b8d4676610d4f
author: Konstantinn Bonnet <qu7uux@gmail.com>
date: Mon Jul 13 18:17:17 EDT 2015

misc unfocused changes/fixes

- remove libc replacement functions: they don't do anything different and are
  useless here
- #pragma pack only for structs read from/written to files
- rename files: s/_9//
- don't use vseprint(2) in place of vsnprint(2) if unnecessary
- error checking for read(2), write(2) calls
- remove useless sys.c wrappers
- remove unused/broken vcr code (-record/-playback)
- in.c: limit channel size somewhat, retouch mouse button crap
- sizeof style

--- a/README
+++ b/README
@@ -1,66 +1,91 @@
 qk1 - (9) quake
 ===============
-	- setup:
-		. mk install
-	- to install quake (shareware or registered):
-		. mkdir $home/lib/quake/id1
-		. cp /n/quakecd/id1/*.pak $home/lib/quake/id1
-	- to install an expansion or compatible mod (zB rogue):
-		. mkdir $home/lib/quake/rogue
-		. cp /n/quakecd/rogue/*.pak $home/lib/quake/rogue
-	- cdaudio, networking: PORTME
-	- high resolutions work up to 4096x4096 (arbitrary limit in r_shared.h)
-		. by default, quake uses a 8MB heap, which will be insufficient for higher
-		  resolutions → exits with a related error message (not a note)
-			→ use [-mem MB], e.g.:
-			; quake -mem 16
-		. resolutions under around 328x160 don't work, possibly because menu text
-		  isn't scaled down, or something
-	- mouse is grabbed using m_windowed cvar
-		. open console (~)
-		. type m_windowed 1 (can autocomplete w/ tab)
-		. setting saved on exit in id1/config.cfg
-	- tested on 386 and amd64 only (works ok on a pentium 4)
+port of linux/x11 quake to plan9front. tested on amd64 and 386 only.
+currently lacks networking and music. save for a rare crash and some stupid
+bugs, it works and plays reasonably well. on my machines.
 
 
-some params useful for workarounds
-----------------------------------
-	-nosound
-	-mem MB
-	(-noudp)
+installation
+------------
+besides building and installing qk1, you still need .pak files to play. both
+shareware and registered versions (should) work, as well as the official
+expansions, and mods.
+the data files are to be installed in $home/lib/quake/$gamename, where
+$gamename is 'id1' for plain old quake.
 
+% mk install
+% mkdir -p $home/lib/quake/id1
+% cp /n/quakecd/id1/*.pak $home/lib/quake/id1
 
-port notes
-----------
-	- based on linux/x11 code from original release
-	- pr_strings: assumed 32bit pointer arithmetic: use PR_GetStr() instead of
-	  dealing with it directly; may be ass
-	- global cppdefotomy, removing code seen as useless for plan9
-	- vid_9.c: shitty, can probably improve performance a bit without screwing code
-	- *printf -> *print was (mostly) stupid
-	- removed some of the command line parameters
-		. -winsize, -width, -height: just set the window dimensions with rio/rc
-		. -condebug, -nostdout: can just redirect with rc to same effect
+% quake
 
+installing an expansion or mod, for example rogue:
 
-todo/issues
------------
-	- compiling with PARANOID reveals several points of failure that are otherwise
-          ignored, resulting in abnormal exit (also on linux)
-	- leave running for a couple of hours → invalid write/reads → crash
-	- unrelated(?): after about 5 hours, sound dies
-	- compile with BAN_TEST -> net_dgrm build fails (struct sockaddr_in)
-	- sprites/particles not scaled correctly on high resolutions (also in quake2)
-	- m_windowed 1: can still look around in frozen world when paused
-	- m_windowed 1: mouse can still escape, mouse movement not very smooth
-	- net_9p.c
-	- cd_9.c,net_udp.c,net_dgrm.c: actuallyport
-	- manpages
-	- fix potential fp exceptions in code rather than ignoring them?
-	- g '/\* FIXME'
-	- port quakeworld and utilities +/- merge common code and mkmany
+% mkdir $home/lib/quake/rogue
+% cp /n/roguecd/*.pak $home/lib/quake/rogue
+
+then start with:
+
+% quake -game rogue
+
+
+todo
+----
+- udp/ip, plan9 style
+- cdaudio: reading and mixing music from e.g. cdfs(4)
+- more testing, cleanups and bug fixes (g '/\* FIXME')
+- (bjnh) bring asm for 386/amd64 back
+- (bjnh) plan9 code style everywhere
+- (bjnh) better performance
+- (bjnh) redesign everything to be super cool (e.g. pakfs, console shit,
+  args, etc.)
+
+
+differences with x11/linux original release
+-------------------------------------------
+- no fullscreen; screen resolution is just the window's dimensions;
+  any resolution (under the r_shared.h limits) is allowed; resize
+  by dragging window edges; removed -winsize, -height, -width
+- some stupid kbd/mouse bugs fixed; mouse grabbing actually grabs the mouse
+- removed -condebug, -nostdout: useless in plan9 (and unix?)
+- added m_windowed cvar (replacing _windowed_mouse), for mouse grabbing
+- ungrabs the mouse when main menu is accessed
+- removed -record, -playback: broken and unused
 
 
+shitty workarounds and other bullshit
+-------------------------------------
+- #pragma pack for stuff (structs) loaded from files
+- pr_strings assumed 32bit pointer arithmetic, so enter PR_GetStr(), which
+  completely sucks
+- text and code seen as useless for plan9 nuked from orbit (cpp defs, etc.)
+- arbitrary resolution limit (r_shared.h): 4096x4096 (was 1280x1024), which
+  inflates e.g. a bunch of arrays in the code
+- mouse handling is too heavy, all for the purpose of not letting the mouse
+  escape the window too easily (and the kludged up shit could probably be
+  done better)
+- removal of stdio stuff probably not really warranted and possibly introduced
+  bugs
+
+
+bugs
+----
+- crash in d_sprite.c:D_SpriteDrawSpans() after several hours of looping the
+  demos
+- sound dies after a few hours: (snd.c) wpos and SNDDMA_GetDMAPos() probably
+  wrong, mix buffer being overwritten while writing to /dev/audio, etc.
+- resolutions other than 4:3: some vertical and horizontal strips on the edge
+  of the screen aren't drawn
+- console color print is still screwed up (printf/print differences)
+- resolutions under around 328x160 don't work, possibly because menu text isn't
+  scaled down or something
+- #define PARANOID reveals several points of failure that are otherwise ignored
+- (?) sprites not scaled correctly on higher resolutions
+- m_windowed 1: in a paused game (in menu or console during sp game), can still
+  look around the frozen world
+- screenshot code outputs garbage
+
+
 legal
 -----
-Quake, hence qk1, is licensed under the GPLv2. See COPYING for details.
+Quake, hence qk1, is licensed under the GPLv2. see COPYING for details.
--- a/bspfile.h
+++ b/bspfile.h
@@ -31,10 +31,11 @@
 
 //=============================================================================
 
-
 #define BSPVERSION	29
 #define	TOOLVERSION	2
 
+#pragma pack on
+
 typedef struct
 {
 	int		fileofs, filelen;
@@ -87,13 +88,11 @@
 	unsigned	offsets[MIPLEVELS];		// four mip maps stored
 } miptex_t;
 
-
 typedef struct
 {
 	float	point[3];
 } dvertex_t;
 
-
 // 0-2 are axial planes
 #define	PLANE_X			0
 #define	PLANE_Y			1
@@ -202,6 +201,8 @@
 
 	byte		ambient_level[NUM_AMBIENTS];
 } dleaf_t;
+
+#pragma pack off
 
 
 //============================================================================
--- /dev/null
+++ b/cd.c
@@ -1,0 +1,286 @@
+#include <u.h>
+#include <libc.h>
+#include <stdio.h>
+#include "quakedef.h"
+
+qboolean cdValid = false;
+qboolean playing = false;
+qboolean wasPlaying = false;
+qboolean initialized = false;
+qboolean enabled = true;
+qboolean playLooping = false;
+float cdvolume;
+byte remap[100];
+byte playTrack;
+byte maxTrack;
+int cdfd = -1;
+char cd_dev[64] = "/dev/cdrom";
+
+
+int CDAudio_GetAudioDiskInfo (void)
+{
+	cdValid = false;
+	Con_DPrintf("CDAudio_GetAudioDiskInfo: PORTME\n");
+	return -1;
+
+	/*
+	struct cdrom_tochdr tochdr;
+
+	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*/)
+{
+	if(cdfd == -1 || !enabled)
+		return;
+	if(!cdValid){
+		CDAudio_GetAudioDiskInfo();
+		if(!cdValid)
+			return;
+	}
+
+	track = remap[track];
+	if(track < 1 || track > maxTrack){
+		Con_DPrintf("CDAudio: Bad track number %ud.\n", track);
+		return;
+	}
+
+	Con_DPrintf("CDAudio_Play: PORTME\n");
+	return;
+
+	/*
+	struct cdrom_tocentry entry;
+	struct cdrom_ti ti;
+
+	// don't try to play a non-audio track
+	entry.cdte_track = track;
+	entry.cdte_format = CDROM_MSF;
+	if(ioctl(cdfd, CDROMREADTOCENTRY, &entry) == -1){
+		Con_DPrintf("ioctl cdromreadtocentry failed\n");
+		return;
+	}
+	if(entry.cdte_ctrl == CDROM_DATA_TRACK){
+		Con_Printf("CDAudio: track %d 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(cdfd, CDROMPLAYTRKIND, &ti) == -1) {
+		Con_DPrintf("ioctl cdromplaytrkind failed\n");
+		return;
+	}
+	if(ioctl(cdfd, 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(cdfd == -1 || !enabled || !playing)
+		return;
+	wasPlaying = false;
+	playing = false;
+}
+
+void CDAudio_Pause (void)
+{
+	if(cdfd == -1 || !enabled || !playing)
+		return;
+	wasPlaying = playing;
+	playing = false;
+}
+
+void CDAudio_Resume (void)
+{
+	if(cdfd == -1 || !enabled || !cdValid || !wasPlaying)
+		return;
+	playing = true;
+}
+
+void CD_f (void)
+{
+	int ret, n;
+	char *command;
+
+	if(Cmd_Argc() < 2)
+		return;
+	command = Cmd_Argv(1);
+	if(cistrcmp(command, "on") == 0){
+		enabled = true;
+		return;
+	}
+	if(cistrcmp(command, "off") == 0){
+		if(playing)
+			CDAudio_Stop();
+		enabled = false;
+		return;
+	}
+	if(cistrcmp(command, "reset") == 0){
+		enabled = true;
+		if(playing)
+			CDAudio_Stop();
+		for(n = 0; n < 100; n++)
+			remap[n] = n;
+		CDAudio_GetAudioDiskInfo();
+		return;
+	}
+	if(cistrcmp(command, "remap") == 0){
+		ret = Cmd_Argc() - 2;
+		if(ret <= 0){
+			for(n = 1; n < 100; n++)
+				if(remap[n] != n)
+					Con_Printf("  %ud -> %ud\n", n, remap[n]);
+			return;
+		}
+		for(n = 1; n <= ret; n++)
+			remap[n] = atoi(Cmd_Argv(n+1));
+		return;
+	}
+	if(!cdValid){
+		CDAudio_GetAudioDiskInfo();
+		if(!cdValid){
+			Con_Printf("No CD in player.\n");
+			return;
+		}
+	}
+	if(cistrcmp(command, "play") == 0){
+		CDAudio_Play((uchar)atoi(Cmd_Argv(2)), false);
+		return;
+	}
+	if(cistrcmp(command, "loop") == 0){
+		CDAudio_Play((uchar)atoi(Cmd_Argv(2)), true);
+		return;
+	}
+	if(cistrcmp(command, "stop") == 0){
+		CDAudio_Stop();
+		return;
+	}
+	if (cistrcmp(command, "pause") == 0){
+		CDAudio_Pause();
+		return;
+	}
+	if(cistrcmp(command, "resume") == 0){
+		CDAudio_Resume();
+		return;
+	}
+	if(cistrcmp(command, "info") == 0){
+		Con_Printf("%ud tracks\n", maxTrack);
+		if(playing)
+			Con_Printf("Currently %s track %ud\n", playLooping ? "looping" : "playing", playTrack);
+		else if(wasPlaying)
+			Con_Printf("Paused %s track %ud\n", playLooping ? "looping" : "playing", playTrack);
+		Con_Printf("Volume is %f\n", cdvolume);
+		return;
+	}
+}
+
+void CDAudio_Update (void)
+{
+	static long 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(nil)){
+		lastchk = time(nil) + 2;	//two seconds between chks
+
+		Con_DPrintf("CDAudio_Update: PORTME\n");
+
+		/*
+		struct cdrom_subchnl subchnl;
+
+		subchnl.cdsc_format = CDROM_MSF;
+		if(ioctl(cdfd, 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((cdfd = open(cd_dev, OREAD)) == -1){
+		fprint(2, "open: %r\n");
+		cdfd = -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(cdfd);
+	cdfd = -1;
+}
--- a/cd_9.c
+++ /dev/null
@@ -1,286 +1,0 @@
-#include <u.h>
-#include <libc.h>
-#include <stdio.h>
-#include "quakedef.h"
-
-qboolean cdValid = false;
-qboolean playing = false;
-qboolean wasPlaying = false;
-qboolean initialized = false;
-qboolean enabled = true;
-qboolean playLooping = false;
-float cdvolume;
-byte remap[100];
-byte playTrack;
-byte maxTrack;
-int cdfd = -1;
-char cd_dev[64] = "/dev/cdrom";
-
-
-int CDAudio_GetAudioDiskInfo (void)
-{
-	cdValid = false;
-	Con_DPrintf("CDAudio_GetAudioDiskInfo: PORTME\n");
-	return -1;
-
-	/*
-	struct cdrom_tochdr tochdr;
-
-	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*/)
-{
-	if(cdfd == -1 || !enabled)
-		return;
-	if(!cdValid){
-		CDAudio_GetAudioDiskInfo();
-		if(!cdValid)
-			return;
-	}
-
-	track = remap[track];
-	if(track < 1 || track > maxTrack){
-		Con_DPrintf("CDAudio: Bad track number %ud.\n", track);
-		return;
-	}
-
-	Con_DPrintf("CDAudio_Play: PORTME\n");
-	return;
-
-	/*
-	struct cdrom_tocentry entry;
-	struct cdrom_ti ti;
-
-	// don't try to play a non-audio track
-	entry.cdte_track = track;
-	entry.cdte_format = CDROM_MSF;
-	if(ioctl(cdfd, CDROMREADTOCENTRY, &entry) == -1){
-		Con_DPrintf("ioctl cdromreadtocentry failed\n");
-		return;
-	}
-	if(entry.cdte_ctrl == CDROM_DATA_TRACK){
-		Con_Printf("CDAudio: track %d 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(cdfd, CDROMPLAYTRKIND, &ti) == -1) {
-		Con_DPrintf("ioctl cdromplaytrkind failed\n");
-		return;
-	}
-	if(ioctl(cdfd, 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(cdfd == -1 || !enabled || !playing)
-		return;
-	wasPlaying = false;
-	playing = false;
-}
-
-void CDAudio_Pause (void)
-{
-	if(cdfd == -1 || !enabled || !playing)
-		return;
-	wasPlaying = playing;
-	playing = false;
-}
-
-void CDAudio_Resume (void)
-{
-	if(cdfd == -1 || !enabled || !cdValid || !wasPlaying)
-		return;
-	playing = true;
-}
-
-void CD_f (void)
-{
-	int ret, n;
-	char *command;
-
-	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("  %ud -> %ud\n", n, remap[n]);
-			return;
-		}
-		for(n = 1; n <= ret; n++)
-			remap[n] = Q_atoi(Cmd_Argv(n+1));
-		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, "info") == 0){
-		Con_Printf("%ud tracks\n", maxTrack);
-		if(playing)
-			Con_Printf("Currently %s track %ud\n", playLooping ? "looping" : "playing", playTrack);
-		else if(wasPlaying)
-			Con_Printf("Paused %s track %ud\n", playLooping ? "looping" : "playing", playTrack);
-		Con_Printf("Volume is %f\n", cdvolume);
-		return;
-	}
-}
-
-void CDAudio_Update (void)
-{
-	static long 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(nil)){
-		lastchk = time(nil) + 2;	//two seconds between chks
-
-		Con_DPrintf("CDAudio_Update: PORTME\n");
-
-		/*
-		struct cdrom_subchnl subchnl;
-
-		subchnl.cdsc_format = CDROM_MSF;
-		if(ioctl(cdfd, 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((cdfd = open(cd_dev, OREAD)) == -1){
-		Con_Printf("CDAudio_Init failed: %r\n");
-		cdfd = -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(cdfd);
-	cdfd = -1;
-}
--- a/chase.c
+++ b/chase.c
@@ -35,7 +35,7 @@
 {
 	trace_t	trace;
 
-	memset (&trace, 0, sizeof(trace));
+	memset(&trace, 0, sizeof trace);
 	SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1, start, end, &trace);
 
 	VectorCopy (trace.endpos, impact);
--- a/cl_input.c
+++ b/cl_input.c
@@ -140,7 +140,11 @@
 void IN_JumpDown (void) {KeyDown(&in_jump);}
 void IN_JumpUp (void) {KeyUp(&in_jump);}
 
-void IN_Impulse (void) {in_impulse=Q_atoi(Cmd_Argv(1));}
+void
+IN_Impulse(void)
+{
+	in_impulse = atoi(Cmd_Argv(1));
+}
 
 /*
 ===============
@@ -271,7 +275,7 @@
 			
 	CL_AdjustAngles ();
 	
-	Q_memset (cmd, 0, sizeof(*cmd));
+	memset(cmd, 0, sizeof *cmd);
 	
 	if (in_strafe.state & 1)
 	{
--- a/cl_main.c
+++ b/cl_main.c
@@ -51,17 +51,17 @@
 		Host_ClearMemory ();
 
 // wipe the entire cl structure
-	memset (&cl, 0, sizeof(cl));
+	memset(&cl, 0, sizeof cl);
 
 	SZ_Clear (&cls.message);
 
 // clear other arrays	
-	memset (cl_efrags, 0, sizeof(cl_efrags));
-	memset (cl_entities, 0, sizeof(cl_entities));
-	memset (cl_dlights, 0, sizeof(cl_dlights));
-	memset (cl_lightstyle, 0, sizeof(cl_lightstyle));
-	memset (cl_temp_entities, 0, sizeof(cl_temp_entities));
-	memset (cl_beams, 0, sizeof(cl_beams));
+	memset(cl_efrags, 0, sizeof cl_efrags);
+	memset(cl_entities, 0, sizeof cl_entities);
+	memset(cl_dlights, 0, sizeof cl_dlights);
+	memset(cl_lightstyle, 0, sizeof cl_lightstyle);
+	memset(cl_temp_entities, 0, sizeof cl_temp_entities);
+	memset(cl_beams, 0, sizeof cl_beams);
 
 //
 // allocate the efrags and chain together into a free list
@@ -311,7 +311,7 @@
 		{
 			if (dl->key == key)
 			{
-				memset (dl, 0, sizeof(*dl));
+				memset(dl, 0, sizeof *dl);
 				dl->key = key;
 				return dl;
 			}
@@ -324,7 +324,7 @@
 	{
 		if (dl->die < cl.time)
 		{
-			memset (dl, 0, sizeof(*dl));
+			memset(dl, 0, sizeof *dl);
 			dl->key = key;
 			return dl;
 		}
@@ -331,7 +331,7 @@
 	}
 
 	dl = &cl_dlights[0];
-	memset (dl, 0, sizeof(*dl));
+	memset(dl, 0, sizeof *dl);
 	dl->key = key;
 	return dl;
 }
--- a/cl_parse.c
+++ b/cl_parse.c
@@ -214,7 +214,7 @@
 		Con_Printf("Bad maxclients (%ud) from server\n", cl.maxclients);
 		return;
 	}
-	cl.scores = Hunk_AllocName (cl.maxclients*sizeof(*cl.scores), "scores");
+	cl.scores = Hunk_AllocName(cl.maxclients * sizeof *cl.scores, "scores");
 
 // parse gametype
 	cl.gametype = MSG_ReadByte ();
@@ -234,7 +234,7 @@
 //
 
 // precache models
-	memset (cl.model_precache, 0, sizeof(cl.model_precache));
+	memset(cl.model_precache, 0, sizeof cl.model_precache);
 	for (nummodels=1 ; ; nummodels++)
 	{
 		str = MSG_ReadString ();
@@ -250,7 +250,7 @@
 	}
 
 // precache sounds
-	memset (cl.sound_precache, 0, sizeof(cl.sound_precache));
+	memset(cl.sound_precache, 0, sizeof cl.sound_precache);
 	for (numsounds=1 ; ; numsounds++)
 	{
 		str = MSG_ReadString ();
@@ -602,7 +602,7 @@
 		Sys_Error ("CL_NewTranslation: slot > cl.maxclients");
 	dest = cl.scores[slot].translations;
 	source = vid.colormap;
-	memcpy (dest, vid.colormap, sizeof(cl.scores[slot].translations));
+	memcpy(dest, vid.colormap, sizeof cl.scores[slot].translations);
 	top = cl.scores[slot].colors & 0xf0;
 	bottom = (cl.scores[slot].colors &15)<<4;
 
@@ -785,8 +785,8 @@
 			i = MSG_ReadByte ();
 			if (i >= MAX_LIGHTSTYLES)
 				Sys_Error ("svc_lightstyle > MAX_LIGHTSTYLES");
-			Q_strcpy (cl_lightstyle[i].map,  MSG_ReadString());
-			cl_lightstyle[i].length = Q_strlen(cl_lightstyle[i].map);
+			strcpy(cl_lightstyle[i].map,  MSG_ReadString());
+			cl_lightstyle[i].length = strlen(cl_lightstyle[i].map);
 			break;
 			
 		case svc_sound:
--- a/cl_tent.c
+++ b/cl_tent.c
@@ -249,7 +249,7 @@
 	if (num_temp_entities == MAX_TEMP_ENTITIES)
 		return nil;
 	ent = &cl_temp_entities[num_temp_entities];
-	memset (ent, 0, sizeof(*ent));
+	memset(ent, 0, sizeof *ent);
 	num_temp_entities++;
 	cl_visedicts[cl_numvisedicts] = ent;
 	cl_numvisedicts++;
--- a/cmd.c
+++ b/cmd.c
@@ -71,7 +71,7 @@
 {
 	int		l;
 	
-	l = Q_strlen (text);
+	l = strlen(text);
 
 	if (cmd_text.cursize + l >= cmd_text.maxsize)
 	{
@@ -79,7 +79,7 @@
 		return;
 	}
 
-	SZ_Write (&cmd_text, text, Q_strlen (text));
+	SZ_Write (&cmd_text, text, strlen(text));
 }
 
 
@@ -102,7 +102,7 @@
 	if (templen)
 	{
 		temp = Z_Malloc (templen);
-		Q_memcpy (temp, cmd_text.data, templen);
+		memcpy(temp, cmd_text.data, templen);
 		SZ_Clear (&cmd_text);
 	}
 		
@@ -128,7 +128,7 @@
 	char	*text;
 	char	line[1024];
 	int		quotes;
-	
+
 	while (cmd_text.cursize)
 	{
 // find a \n or ; line break
@@ -159,7 +159,7 @@
 		{
 			i++;
 			cmd_text.cursize -= i;
-			Q_memcpy (text, text+i, cmd_text.cursize);
+			memcpy(text, text+i, cmd_text.cursize);
 		}
 
 // execute the command line
@@ -210,7 +210,7 @@
 	{
 		if (!com_argv[i])
 			continue;		// NEXTSTEP nulls out -NXHost
-		s += Q_strlen (com_argv[i]) + 1;
+		s += strlen(com_argv[i]) + 1;
 	}
 	if (!s)
 		return;
@@ -221,9 +221,9 @@
 	{
 		if (!com_argv[i])
 			continue;		// NEXTSTEP nulls out -NXHost
-		Q_strcat (text,com_argv[i]);
+		strcat(text, com_argv[i]);
 		if (i != com_argc-1)
-			Q_strcat (text, " ");
+			strcat(text, " ");
 	}
 	
 // pull out the commands
@@ -242,8 +242,8 @@
 			c = text[j];
 			text[j] = 0;
 			
-			Q_strcat (build, text+i);
-			Q_strcat (build, "\n");
+			strcat(build, text+i);
+			strcat(build, "\n");
 			text[j] = c;
 			i = j-1;
 		}
@@ -345,7 +345,7 @@
 	// if the alias allready exists, reuse it
 	for (a = cmd_alias ; a ; a=a->next)
 	{
-		if (!strcmp(s, a->name))
+		if(strcmp(s, a->name) == 0)
 		{
 			Z_Free (a->value);
 			break;
@@ -352,9 +352,9 @@
 		}
 	}
 
-	if (!a)
+	if (a == nil)
 	{
-		a = Z_Malloc (sizeof(cmdalias_t));
+		a = Z_Malloc(sizeof *a);
 		a->next = cmd_alias;
 		cmd_alias = a;
 	}
@@ -494,8 +494,8 @@
 
 		if (cmd_argc < MAX_ARGS)
 		{
-			cmd_argv[cmd_argc] = Z_Malloc (Q_strlen(com_token)+1);
-			Q_strcpy (cmd_argv[cmd_argc], com_token);
+			cmd_argv[cmd_argc] = Z_Malloc(strlen(com_token)+1);
+			strcpy(cmd_argv[cmd_argc], com_token);
 			cmd_argc++;
 		}
 	}
@@ -524,7 +524,7 @@
 // fail if the command already exists
 	for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
 	{
-		if (!Q_strcmp (cmd_name, cmd->name))
+		if(strcmp(cmd_name, cmd->name) == 0)
 		{
 			Con_Printf ("Cmd_AddCommand: %s already defined\n", cmd_name);
 			return;
@@ -531,7 +531,7 @@
 		}
 	}
 
-	cmd = Hunk_Alloc (sizeof(cmd_function_t));
+	cmd = Hunk_Alloc(sizeof *cmd);
 	cmd->name = cmd_name;
 	cmd->function = function;
 	cmd->next = cmd_functions;
@@ -549,7 +549,7 @@
 
 	for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
 	{
-		if (!Q_strcmp (cmd_name,cmd->name))
+		if(strcmp(cmd_name, cmd->name) == 0)
 			return true;
 	}
 
@@ -568,7 +568,7 @@
 	cmd_function_t	*cmd;
 	int				len;
 	
-	len = Q_strlen(partial);
+	len = strlen(partial);
 	
 	if (!len)
 		return nil;
@@ -575,7 +575,7 @@
 		
 // check functions
 	for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
-		if (!Q_strncmp (partial,cmd->name, len))
+		if(strncmp(partial, cmd->name, len) == 0)
 			return cmd->name;
 
 	return nil;
@@ -604,7 +604,7 @@
 // check functions
 	for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
 	{
-		if (!Q_strcasecmp (cmd_argv[0],cmd->name))
+		if(cistrcmp(cmd_argv[0],cmd->name) == 0)
 		{
 			cmd->function ();
 			return;
@@ -614,7 +614,7 @@
 // check alias
 	for (a=cmd_alias ; a ; a=a->next)
 	{
-		if (!Q_strcasecmp (cmd_argv[0], a->name))
+		if(cistrcmp(cmd_argv[0], a->name) == 0)
 		{
 			Cbuf_InsertText (a->value);
 			return;
@@ -647,7 +647,7 @@
 		return;		// not really connected
 
 	MSG_WriteByte (&cls.message, clc_stringcmd);
-	if (Q_strcasecmp(Cmd_Argv(0), "cmd") != 0)
+	if(cistrcmp(Cmd_Argv(0), "cmd") != 0)
 	{
 		SZ_Print (&cls.message, Cmd_Argv(0));
 		SZ_Print (&cls.message, " ");
@@ -676,8 +676,8 @@
 		Sys_Error ("Cmd_CheckParm: nil");
 
 	for (i = 1; i < Cmd_Argc (); i++)
-		if (! Q_strcasecmp (parm, Cmd_Argv (i)))
+		if(cistrcmp(parm, Cmd_Argv(i)) == 0)
 			return i;
-			
+
 	return 0;
 }
--- a/common.c
+++ b/common.c
@@ -114,292 +114,6 @@
 /*
 ============================================================================
 
-					LIBRARY REPLACEMENT FUNCTIONS
-
-============================================================================
-*/
-
-void Q_memset (void *dest, int fill, int count)
-{
-	int             i;
-	
-	if ( ((uintptr)dest | count) & 3 == 0)
-	{
-		count >>= 2;
-		fill = fill | (fill<<8) | (fill<<16) | (fill<<24);
-		for (i=0 ; i<count ; i++)
-			((int *)dest)[i] = fill;
-	}
-	else
-		for (i=0 ; i<count ; i++)
-			((byte *)dest)[i] = fill;
-}
-
-void Q_memcpy (void *dest, void *src, int count)
-{
-	int             i;
-	
-	if (( ( (uintptr)dest | (uintptr)src | count) & 3) == 0 )
-	{
-		count>>=2;
-		for (i=0 ; i<count ; i++)
-			((int *)dest)[i] = ((int *)src)[i];
-	}
-	else
-		for (i=0 ; i<count ; i++)
-			((byte *)dest)[i] = ((byte *)src)[i];
-}
-
-int Q_memcmp (void *m1, void *m2, int count)
-{
-	while(count)
-	{
-		count--;
-		if (((byte *)m1)[count] != ((byte *)m2)[count])
-			return -1;
-	}
-	return 0;
-}
-
-void Q_strcpy (char *dest, char *src)
-{
-	while (*src)
-	{
-		*dest++ = *src++;
-	}
-	*dest = 0;
-}
-
-void Q_strncpy (char *dest, char *src, int count)
-{
-	while (*src && count--)
-	{
-		*dest++ = *src++;
-	}
-	if (count)
-		*dest = 0;
-}
-
-int Q_strlen (char *str)
-{
-	int             count;
-	
-	count = 0;
-	while (str[count])
-		count++;
-
-	return count;
-}
-
-char *Q_strrchr(char *s, char c)
-{
-    int len = Q_strlen(s);
-    s += len;
-    while (len--)
-	if (*--s == c) return s;
-    return 0;
-}
-
-void Q_strcat (char *dest, char *src)
-{
-	dest += Q_strlen(dest);
-	Q_strcpy (dest, src);
-}
-
-int Q_strcmp (char *s1, char *s2)
-{
-	while (1)
-	{
-		if (*s1 != *s2)
-			return -1;              // strings not equal    
-		if (!*s1)
-			return 0;               // strings are equal
-		s1++;
-		s2++;
-	}
-}
-
-int Q_strncmp (char *s1, char *s2, int count)
-{
-	while (1)
-	{
-		if (!count--)
-			return 0;
-		if (*s1 != *s2)
-			return -1;              // strings not equal    
-		if (!*s1)
-			return 0;               // strings are equal
-		s1++;
-		s2++;
-	}
-}
-
-int Q_strncasecmp (char *s1, char *s2, int n)
-{
-	int             c1, c2;
-	
-	while (1)
-	{
-		c1 = *s1++;
-		c2 = *s2++;
-
-		if (!n--)
-			return 0;               // strings are equal until end point
-		
-		if (c1 != c2)
-		{
-			if (c1 >= 'a' && c1 <= 'z')
-				c1 -= ('a' - 'A');
-			if (c2 >= 'a' && c2 <= 'z')
-				c2 -= ('a' - 'A');
-			if (c1 != c2)
-				return -1;              // strings not equal
-		}
-		if (!c1)
-			return 0;               // strings are equal
-	}
-}
-
-int Q_strcasecmp (char *s1, char *s2)
-{
-	return Q_strncasecmp (s1, s2, 99999);
-}
-
-int Q_atoi (char *str)
-{
-	int             val;
-	int             sign;
-	int             c;
-	
-	if (*str == '-')
-	{
-		sign = -1;
-		str++;
-	}
-	else
-		sign = 1;
-		
-	val = 0;
-
-//
-// check for hex
-//
-	if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X') )
-	{
-		str += 2;
-		while (1)
-		{
-			c = *str++;
-			if (c >= '0' && c <= '9')
-				val = (val<<4) + c - '0';
-			else if (c >= 'a' && c <= 'f')
-				val = (val<<4) + c - 'a' + 10;
-			else if (c >= 'A' && c <= 'F')
-				val = (val<<4) + c - 'A' + 10;
-			else
-				return val*sign;
-		}
-	}
-	
-//
-// check for character
-//
-	if (str[0] == '\'')
-	{
-		return sign * str[1];
-	}
-	
-//
-// assume decimal
-//
-	while (1)
-	{
-		c = *str++;
-		if (c <'0' || c > '9')
-			return val*sign;
-		val = val*10 + c - '0';
-	}
-}
-
-
-float Q_atof (char *str)
-{
-	double			val;
-	int             sign;
-	int             c;
-	int             decimal, total;
-	
-	if (*str == '-')
-	{
-		sign = -1;
-		str++;
-	}
-	else
-		sign = 1;
-		
-	val = 0;
-
-//
-// check for hex
-//
-	if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X') )
-	{
-		str += 2;
-		while (1)
-		{
-			c = *str++;
-			if (c >= '0' && c <= '9')
-				val = (val*16) + c - '0';
-			else if (c >= 'a' && c <= 'f')
-				val = (val*16) + c - 'a' + 10;
-			else if (c >= 'A' && c <= 'F')
-				val = (val*16) + c - 'A' + 10;
-			else
-				return val*sign;
-		}
-	}
-	
-//
-// check for character
-//
-	if (str[0] == '\'')
-	{
-		return sign * str[1];
-	}
-	
-//
-// assume decimal
-//
-	decimal = -1;
-	total = 0;
-	while (1)
-	{
-		c = *str++;
-		if (c == '.')
-		{
-			decimal = total;
-			continue;
-		}
-		if (c <'0' || c > '9')
-			break;
-		val = val*10 + c - '0';
-		total++;
-	}
-
-	if (decimal == -1)
-		return val*sign;
-	while (total > decimal)
-	{
-		val /= 10;
-		total--;
-	}
-	
-	return val*sign;
-}
-
-/*
-============================================================================
-
 					BYTE ORDER FUNCTIONS
 
 ============================================================================
@@ -552,7 +266,7 @@
 	if (!s)
 		SZ_Write (sb, "", 1);
 	else
-		SZ_Write (sb, s, Q_strlen(s)+1);
+		SZ_Write (sb, s, strlen(s)+1);
 }
 
 void MSG_WriteCoord (sizebuf_t *sb, float f)
@@ -702,17 +416,19 @@
 
 //===========================================================================
 
-void SZ_Alloc (sizebuf_t *buf, int startsize)
+void
+SZ_Alloc(sizebuf_t *buf, int startsize)
 {
-	if (startsize < 256)
+	if(startsize < 256)
 		startsize = 256;
-	buf->data = Hunk_AllocName (startsize, "sizebuf");
+	buf->data = Hunk_AllocName(startsize, "sizebuf");
 	buf->maxsize = startsize;
 	buf->cursize = 0;
 }
 
 
-void SZ_Free (sizebuf_t *buf)
+void
+SZ_Free(sizebuf_t *buf)
 {
 //      Z_Free (buf->data);
 //      buf->data = nil;
@@ -720,50 +436,49 @@
 	buf->cursize = 0;
 }
 
-void SZ_Clear (sizebuf_t *buf)
+void
+SZ_Clear(sizebuf_t *buf)
 {
 	buf->cursize = 0;
 }
 
-void *SZ_GetSpace (sizebuf_t *buf, int length)
+void *
+SZ_GetSpace(sizebuf_t *buf, int length)
 {
-	void    *data;
+	void *data;
 	
-	if (buf->cursize + length > buf->maxsize)
-	{
-		if (!buf->allowoverflow)
-			Sys_Error ("SZ_GetSpace: overflow without allowoverflow set");
-		
-		if (length > buf->maxsize)
-			Sys_Error ("SZ_GetSpace: %d is > full buffer size", length);
-			
+	if(buf->cursize + length > buf->maxsize){
+		if(!buf->allowoverflow)
+			Sys_Error("SZ_GetSpace: overflow without allowoverflow set");
+		if(length > buf->maxsize)
+			Sys_Error("SZ_GetSpace: %d is > full buffer size", length);
 		buf->overflowed = true;
-		Con_Printf ("SZ_GetSpace: overflow");
-		SZ_Clear (buf); 
+		Con_Printf("SZ_GetSpace: overflow");
+		SZ_Clear(buf); 
 	}
-
 	data = buf->data + buf->cursize;
 	buf->cursize += length;
-	
+
 	return data;
 }
 
-void SZ_Write (sizebuf_t *buf, void *data, int length)
+void
+SZ_Write(sizebuf_t *buf, void *data, int length)
 {
-	Q_memcpy (SZ_GetSpace(buf,length),data,length);         
+	memcpy(SZ_GetSpace(buf, length), data, length);
 }
 
-void SZ_Print (sizebuf_t *buf, char *data)
+void
+SZ_Print(sizebuf_t *buf, char *data)
 {
-	int             len;
-	
-	len = Q_strlen(data)+1;
+	int len;
 
-// byte * cast to keep VC++ happy
-	if (buf->data[buf->cursize-1])
-		Q_memcpy ((byte *)SZ_GetSpace(buf, len),data,len); // no trailing 0
+	len = strlen(data)+1;
+
+	if(buf->data[buf->cursize-1])
+		memcpy(SZ_GetSpace(buf, len), data, len);	// no trailing 0
 	else
-		Q_memcpy ((byte *)SZ_GetSpace(buf, len-1)-1,data,len); // write over trailing 0
+		memcpy((uchar *)SZ_GetSpace(buf, len-1)-1, data, len);	// write over trailing 0
 }
 
 
@@ -969,7 +684,7 @@
 	{
 		if (!com_argv[i])
 			continue;               // NEXTSTEP sometimes clears appkit vars.
-		if (!Q_strcmp (parm,com_argv[i]))
+		if(strcmp(parm, com_argv[i]) == 0)
 			return i;
 	}
 		
@@ -1003,7 +718,7 @@
 		return;
 	}
 
-	Sys_FileRead (h, check, sizeof(check));
+	eread(h, check, sizeof check);
 	COM_CloseFile (h);
 	
 	for (i=0 ; i<128 ; i++)
@@ -1056,7 +771,7 @@
 		 com_argc++)
 	{
 		largv[com_argc] = argv[com_argc];
-		if (!Q_strcmp ("-safe", argv[com_argc]))
+		if(strcmp("-safe", argv[com_argc]) == 0)
 			safe = true;
 	}
 
@@ -1137,16 +852,17 @@
 FIXME: make this buffer size safe someday
 ============
 */
-char    *va(char *format, ...)
+char *
+va(char *fmt, ...)
 {
-	va_list         argptr;
-	static char             string[1024];
-	
-	va_start (argptr, format);
-	vseprint (string,string+sizeof(string),format,argptr);
-	va_end (argptr);
+	va_list arg;
+	static char s[1024];
 
-	return string;  
+	va_start(arg, fmt);
+	vsnprint(s, sizeof s, fmt, arg);
+	va_end(arg);
+
+	return s;  
 }
 
 
@@ -1242,33 +958,21 @@
 	}
 }
 
-/*
-============
-COM_WriteFile
-
-The filename will be prefixed by the current game directory
-============
-*/
-void COM_WriteFile (char *filename, void *data, int len)
+void
+COM_WriteFile(char *filename, void *data, int len)
 {
-	int             handle;
-	char    name[MAX_OSPATH];
-	
-	sprint (name, "%s/%s", com_gamedir, filename);
+	int fd;
+	char path[MAX_OSPATH];
 
-	handle = Sys_FileOpenWrite (name);
-	if (handle == -1)
-	{
-		Sys_Printf ("COM_WriteFile: failed on %s\n", name);
-		return;
-	}
-	
-	Sys_Printf ("COM_WriteFile: %s\n", name);
-	Sys_FileWrite (handle, data, len);
-	Sys_FileClose (handle);
+	snprint(path, sizeof path, "%s/%s", com_gamedir, filename);
+	if((fd = create(path, OWRITE, 0666)) < 0)
+		sysfatal("COM_WriteFile:create: %r");
+
+	Sys_Printf("COM_WriteFile: %s\n", path);
+	ewrite(fd, data, len);
+	close(fd);
 }
 
-
 /*
 ============
 COM_CreatePath
@@ -1291,39 +995,36 @@
 	}
 }
 
-
-/*
-===========
-COM_CopyFile
-
-Copies a file over from the net to the local cache, creating any directories
-needed.  This is for the convenience of developers using ISDN from home.
-===========
-*/
-void COM_CopyFile (char *netpath, char *cachepath)
+/* Copies a file over from the net to the local cache, creating any directories
+ * needed. This is for the convenience of developers using ISDN from home. */
+void
+COM_CopyFile(char *netpath, char *cachepath)
 {
 	int             in, out;
 	int             count;
 	vlong		remaining;
 	char    buf[4096];
-	
-	remaining = Sys_FileOpenRead (netpath, &in);            
-	COM_CreatePath (cachepath);     // create directories up to the cache file
-	out = Sys_FileOpenWrite (cachepath);
-	
-	while (remaining)
-	{
-		if (remaining < sizeof(buf))
+
+	if((in = open(netpath, OREAD)) < 0)
+		sysfatal("COM_CopyFile:open: %r");
+	remaining = flen(in);
+
+	COM_CreatePath(cachepath);	// create directories up to the cache file
+	if((out = create(cachepath, OWRITE, 0666)) < 0)
+		sysfatal("COM_CopyFile:create: %r");
+
+	while(remaining){
+		if(remaining < sizeof buf)
 			count = remaining;
 		else
-			count = sizeof(buf);
-		Sys_FileRead (in, buf, count);
-		Sys_FileWrite (out, buf, count);
+			count = sizeof buf;
+		eread(in, buf, count);
+		ewrite(out, buf, count);
 		remaining -= count;
 	}
 
-	Sys_FileClose (in);
-	Sys_FileClose (out);    
+	close(in);
+	close(out);    
 }
 
 /*
@@ -1354,7 +1055,7 @@
 	search = com_searchpaths;
 	if (proghack)
 	{	// gross hack to use quake 1 progs with quake 2 maps
-		if (!strcmp(filename, "progs.dat"))
+		if(strcmp(filename, "progs.dat") == 0)
 			search = search->next;
 	}
 
@@ -1366,13 +1067,13 @@
 		// look through all the pak file elements
 			pak = search->pack;
 			for (i=0 ; i<pak->numfiles ; i++)
-				if (!strcmp (pak->files[i].name, filename))
+				if(strcmp(pak->files[i].name, filename) == 0)
 				{       // found it!
 					Sys_Printf ("PackFile: %s : %s\n",pak->filename, filename);
 					if (handle)
 					{
 						*handle = pak->handle;
-						Sys_FileSeek (pak->handle, pak->files[i].filepos);
+						seek(pak->handle, pak->files[i].filepos, 0);
 					}
 					else
 					{       // open a new file on the pakfile
@@ -1392,13 +1093,13 @@
 				if ( strchr (filename, '/') || strchr (filename,'\\'))
 					continue;
 			}
-			
-			sprint (netpath, "%s/%s",search->filename, filename);
-			
+
+			snprint(netpath, sizeof netpath, "%s/%s", search->filename, filename);
+
 			findtime = Sys_FileTime (netpath);
 			if (findtime == -1)
 				continue;
-				
+	
 		// see if the file needs to be updated in the cache
 			if (!com_cachedir[0])
 				strcpy (cachepath, netpath);
@@ -1411,15 +1112,20 @@
 				if (cachetime < findtime)
 					COM_CopyFile (netpath, cachepath);
 				strcpy (netpath, cachepath);
-			}	
+			}
 
-			Sys_Printf ("FindFile: %s\n",netpath);
-			com_filesize = Sys_FileOpenRead (netpath, &i);
-			if (handle)
+			Sys_Printf("FindFile: %s\n", netpath);
+			com_filesize = -1;
+			if((i = open(netpath, OREAD)) < 0)
+				fprint(2, "COM_FindFile:open: %r\n");
+			else
+				com_filesize = flen(i);
+
+			if(handle != nil)
 				*handle = i;
 			else
 			{
-				Sys_FileClose (i);
+				close(i);
 				*file = fopen (netpath, "rb");
 			}
 			return com_filesize;
@@ -1480,7 +1186,7 @@
 		if (s->pack && s->pack->handle == h)
 			return;
 			
-	Sys_FileClose (h);
+	close(h);
 }
 
 
@@ -1536,7 +1242,7 @@
 	((byte *)buf)[len] = 0;
 
 	Draw_BeginDisc ();
-	Sys_FileRead (h, buf, len);                     
+	eread(h, buf, len);
 	COM_CloseFile (h);
 	Draw_EndDisc ();
 
@@ -1592,12 +1298,11 @@
 	dpackfile_t             info[MAX_FILES_IN_PACK];
 	unsigned short          crc;
 
-	if (Sys_FileOpenRead (packfile, &packhandle) == -1)
-	{
-//              Con_Printf ("Couldn't open %s\n", packfile);
+	if((packhandle = open(packfile, OREAD)) < 0){
+		fprint(2, "open: %r\n");
 		return nil;
 	}
-	Sys_FileRead (packhandle, (void *)&header, sizeof(header));
+	eread(packhandle, &header, sizeof header);
 	if (header.id[0] != 'P' || header.id[1] != 'A'
 	|| header.id[2] != 'C' || header.id[3] != 'K')
 		Sys_Error ("%s is not a packfile", packfile);
@@ -1612,10 +1317,10 @@
 	if (numpackfiles != PAK0_COUNT)
 		com_modified = true;    // not the original file
 
-	newfiles = Hunk_AllocName (numpackfiles * sizeof(packfile_t), "packfile");
+	newfiles = Hunk_AllocName(numpackfiles * sizeof *newfiles, "packfile");
 
-	Sys_FileSeek (packhandle, header.dirofs);
-	Sys_FileRead (packhandle, (void *)info, header.dirlen);
+	seek(packhandle, header.dirofs, 0);
+	eread(packhandle, info, header.dirlen);
 
 // crc the directory to check for modifications
 	CRC_Init (&crc);
@@ -1632,7 +1337,7 @@
 		newfiles[i].filelen = LittleLong(info[i].filelen);
 	}
 
-	pack = Hunk_Alloc (sizeof (pack_t));
+	pack = Hunk_Alloc(sizeof *pack);
 	strcpy (pack->filename, packfile);
 	pack->handle = packhandle;
 	pack->numfiles = numpackfiles;
@@ -1663,7 +1368,7 @@
 //
 // add the directory to the search path
 //
-	search = Hunk_Alloc (sizeof(searchpath_t));
+	search = Hunk_Alloc(sizeof *search);
 	strcpy (search->filename, dir);
 	search->next = com_searchpaths;
 	com_searchpaths = search;
@@ -1677,7 +1382,7 @@
 		pak = COM_LoadPackFile (pakfile);
 		if (!pak)
 			break;
-		search = Hunk_Alloc (sizeof(searchpath_t));
+		search = Hunk_Alloc(sizeof *search);
 		search->pack = pak;
 		search->next = com_searchpaths;
 		com_searchpaths = search;               
@@ -1771,8 +1476,8 @@
 			if (!com_argv[i] || com_argv[i][0] == '+' || com_argv[i][0] == '-')
 				break;
 			
-			search = Hunk_Alloc (sizeof(searchpath_t));
-			if ( !strcmp(COM_FileExtension(com_argv[i]), "pak") )
+			search = Hunk_Alloc(sizeof *search);
+			if(strcmp(COM_FileExtension(com_argv[i]), "pak") == 0)
 			{
 				search->pack = COM_LoadPackFile (com_argv[i]);
 				if (!search->pack)
@@ -1788,5 +1493,3 @@
 	if (COM_CheckParm ("-proghack"))
 		proghack = true;
 }
-
-
--- a/common.h
+++ b/common.h
@@ -102,23 +102,6 @@
 
 //============================================================================
 
-void Q_memset (void *dest, int fill, int count);
-void Q_memcpy (void *dest, void *src, int count);
-int Q_memcmp (void *m1, void *m2, int count);
-void Q_strcpy (char *dest, char *src);
-void Q_strncpy (char *dest, char *src, int count);
-int Q_strlen (char *str);
-char *Q_strrchr (char *s, char c);
-void Q_strcat (char *dest, char *src);
-int Q_strcmp (char *s1, char *s2);
-int Q_strncmp (char *s1, char *s2, int count);
-int Q_strcasecmp (char *s1, char *s2);
-int Q_strncasecmp (char *s1, char *s2, int n);
-int	Q_atoi (char *str);
-float Q_atof (char *str);
-
-//============================================================================
-
 extern	char		com_token[1024];
 extern	qboolean	com_eof;
 
--- a/console.c
+++ b/console.c
@@ -61,20 +61,15 @@
 		key_dest = key_console;
 	
 	SCR_EndLoadingPlaque ();
-	memset (con_times, 0, sizeof(con_times));
+	memset(con_times, 0, sizeof con_times);
 }
 
-/*
-================
-Con_Clear_f
-================
-*/
-void Con_Clear_f (void)
+void
+Con_Clear_f(void)
 {
-	if (con_text)
-		Q_memset (con_text, ' ', CON_TEXTSIZE);
+	if(con_text)
+		memset(con_text, ' ', CON_TEXTSIZE);
 }
-
 						
 /*
 ================
@@ -138,7 +133,7 @@
 		width = 38;
 		con_linewidth = width;
 		con_totallines = CON_TEXTSIZE / con_linewidth;
-		Q_memset (con_text, ' ', CON_TEXTSIZE);
+		memset(con_text, ' ', CON_TEXTSIZE);
 	}
 	else
 	{
@@ -156,8 +151,8 @@
 		if (con_linewidth < numchars)
 			numchars = con_linewidth;
 
-		Q_memcpy (tbuf, con_text, CON_TEXTSIZE);
-		Q_memset (con_text, ' ', CON_TEXTSIZE);
+		memcpy(tbuf, con_text, CON_TEXTSIZE);
+		memset(con_text, ' ', CON_TEXTSIZE);
 
 		for (i=0 ; i<numlines ; i++)
 		{
@@ -185,7 +180,7 @@
 void Con_Init (void)
 {
 	con_text = Hunk_AllocName (CON_TEXTSIZE, "context");
-	Q_memset (con_text, ' ', CON_TEXTSIZE);
+	memset(con_text, ' ', CON_TEXTSIZE);
 	con_linewidth = -1;
 	Con_CheckResize ();
 	
@@ -213,8 +208,7 @@
 {
 	con_x = 0;
 	con_current++;
-	Q_memset (&con_text[(con_current%con_totallines)*con_linewidth]
-	, ' ', con_linewidth);
+	memset(&con_text[(con_current%con_totallines)*con_linewidth], ' ', con_linewidth);
 }
 
 /*
@@ -303,108 +297,66 @@
 }
 
 
-/*
-================
-Con_Printf
-
-Handles cursor positioning, line wrapping, etc
-================
-*/
 #define	MAXPRINTMSG	4096
-// FIXME: make a buffer size safe vsprintf?
-void Con_Printf (char *fmt, ...)
+
+/* Handles cursor positioning, line wrapping, etc */
+void
+Con_Printf(char *fmt, ...)
 {
-	va_list		argptr;
-	char		msg[MAXPRINTMSG];
+	va_list arg;
+	char c, *p, msg[MAXPRINTMSG];
 	static qboolean	inupdate;
-	char c, *p;
 
-	/* FIXME: Con_Print uses 1<<7 bit for color; this bit is used in zB rogue to print team names
-	 * in color. for some reason, if this bit is set, print(2) goes apeshit. using vseprint et al
-	 * results in a badly formed string. I've noticed some really fucked up behavior when mixing
-	 * vsnprintf with print. so, we use stdio here instead of vseprint + Sys_Printf for echoing
-	 * to 1 */
-	va_start(argptr, fmt);
-	vsnprintf(msg, sizeof(msg), fmt, argptr);
-	va_end(argptr);
+	/* FIXME: Con_Print() above uses 1<<7 bit for color printing select
+	 * letters, notably in mods. this does not amuse print(2) (dofmt()?). */
+	va_start(arg, fmt);
+	vsnprintf(msg, sizeof msg, fmt, arg);
+	va_end(arg);
 	for(p = msg; *p; p++){
 		c = *p & 0x7f;
 		if(c < 32 && c != 10 && c != 13 && c != 9)
-			printf("[%02x]", c);
+			print("[%02x]", c);
 		else
-			printf("%c", c);
+			print("%c", c);
 	}
 
-	if (!con_initialized)
+	if(!con_initialized)
 		return;
-		
-	if (cls.state == ca_dedicated)
+
+	if(cls.state == ca_dedicated)
 		return;		// no graphics mode
 
 // write it to the scrollable buffer
-	Con_Print (msg);
+	Con_Print(msg);
 	
 // update the screen if the console is displayed
-	if (cls.signon != SIGNONS && !scr_disabled_for_loading )
-	{
-	// protect against infinite loop if something in SCR_UpdateScreen calls
-	// Con_Printd
-		if (!inupdate)
-		{
+	if(cls.signon != SIGNONS && !scr_disabled_for_loading){
+		/* protect against infinite loop if something in
+		 * SCR_UpdateScreen() calls Con_Printf() */
+		if(!inupdate){
 			inupdate = true;
-			SCR_UpdateScreen ();
+			SCR_UpdateScreen();
 			inupdate = false;
 		}
 	}
 }
 
-/*
-================
-Con_DPrintf
-
-A Con_Printf that only shows up if the "developer" cvar is set
-================
-*/
-void Con_DPrintf (char *fmt, ...)
+void
+Con_DPrintf(char *fmt, ...)
 {
-	va_list		argptr;
-	char		msg[MAXPRINTMSG];
-		
-	if (!developer.value)
-		return;			// don't confuse non-developers with techie stuff...
+	va_list arg;
+	char s[MAXPRINTMSG];
 
-	va_start (argptr,fmt);
-	vseprint (msg,msg+sizeof(msg),fmt,argptr);
-	va_end (argptr);
-	
-	Con_Printf ("%s", msg);
-}
+	if(!developer.value)
+		return;	// don't confuse non-developers with techie stuff...
 
+	va_start(arg, fmt);
+	vsnprint(s, sizeof s, fmt, arg);
+	va_end(arg);
 
-/*
-==================
-Con_SafePrintf
-
-Okay to call even when the screen can't be updated
-==================
-*/
-void Con_SafePrintf (char *fmt, ...)
-{
-	va_list		argptr;
-	char		msg[1024];
-	int			temp;
-		
-	va_start (argptr,fmt);
-	vseprint (msg,msg+sizeof(msg),fmt,argptr);
-	va_end (argptr);
-
-	temp = scr_disabled_for_loading;
-	scr_disabled_for_loading = true;
-	Con_Printf ("%s", msg);
-	scr_disabled_for_loading = temp;
+	Con_Printf("%s", s);
 }
 
-
 /*
 ==============================================================================
 
@@ -589,4 +541,3 @@
 	key_dest = key_game;
 	realtime = 0;				// put the cursor back to invisible
 }
-
--- a/cvar.c
+++ b/cvar.c
@@ -18,7 +18,7 @@
 	cvar_t	*var;
 	
 	for (var=cvar_vars ; var ; var=var->next)
-		if (!Q_strcmp (var_name, var->name))
+		if(strcmp(var_name, var->name) == 0)
 			return var;
 
 	return NULL;
@@ -36,7 +36,7 @@
 	var = Cvar_FindVar (var_name);
 	if (!var)
 		return 0;
-	return Q_atof (var->string);
+	return atof(var->string);
 }
 
 
@@ -66,7 +66,7 @@
 	cvar_t		*cvar;
 	int			len;
 	
-	len = Q_strlen(partial);
+	len = strlen(partial);
 	
 	if (!len)
 		return NULL;
@@ -73,7 +73,7 @@
 		
 // check functions
 	for (cvar=cvar_vars ; cvar ; cvar=cvar->next)
-		if (!Q_strncmp (partial,cvar->name, len))
+		if(strncmp(partial, cvar->name, len) == 0)
 			return cvar->name;
 
 	return NULL;
@@ -97,13 +97,13 @@
 		return;
 	}
 
-	changed = Q_strcmp(var->string, value);
+	changed = strcmp(var->string, value);
 	
 	Z_Free (var->string);	// free the old value string
 	
-	var->string = Z_Malloc (Q_strlen(value)+1);
-	Q_strcpy (var->string, value);
-	var->value = Q_atof (var->string);
+	var->string = Z_Malloc(strlen(value)+1);
+	strcpy(var->string, value);
+	var->value = atof(var->string);
 	if (var->server && changed)
 	{
 		if (sv.active)
@@ -152,9 +152,9 @@
 		
 // copy the value off, because future sets will Z_Free it
 	oldstr = variable->string;
-	variable->string = Z_Malloc (Q_strlen(variable->string)+1);	
-	Q_strcpy (variable->string, oldstr);
-	variable->value = Q_atof (variable->string);
+	variable->string = Z_Malloc(strlen(variable->string)+1);	
+	strcpy(variable->string, oldstr);
+	variable->value = atof(variable->string);
 	
 // link the variable in
 	variable->next = cvar_vars;
--- a/d_surf.c
+++ b/d_surf.c
@@ -20,7 +20,7 @@
 
 	if (COM_CheckParm ("-surfcachesize"))
 	{
-		size = Q_atoi(com_argv[COM_CheckParm("-surfcachesize")+1]) * 1024;
+		size = atoi(com_argv[COM_CheckParm("-surfcachesize")+1]) * 1024;
 		return size;
 	}
 	
--- a/draw.c
+++ b/draw.c
@@ -288,7 +288,7 @@
 
 		for (v=0 ; v<pic->height ; v++)
 		{
-			Q_memcpy (dest, source, pic->width);
+			memcpy(dest, source, pic->width);
 			dest += vid.rowbytes;
 			source += pic->width;
 		}
--- a/host.c
+++ b/host.c
@@ -66,28 +66,27 @@
 Host_EndGame
 ================
 */
-void Host_EndGame (char *message, ...)
+void Host_EndGame (char *fmt, ...)
 {
-	va_list		argptr;
-	char		string[1024];
-	
-	va_start (argptr,message);
-	vseprint (string,string+sizeof(string),message,argptr);
-	va_end (argptr);
-	Con_DPrintf ("Host_EndGame: %s\n",string);
-	
-	if (sv.active)
-		Host_ShutdownServer (false);
+	va_list arg;
+	char s[1024];
 
-	if (cls.state == ca_dedicated)
-		Sys_Error ("Host_EndGame: %s\n",string);	// dedicated servers exit
-	
-	if (cls.demonum != -1)
-		CL_NextDemo ();
+	va_start(arg, fmt);
+	vsnprint(s, sizeof s, fmt, arg);
+	va_end(arg);
+
+	Con_DPrintf("Host_EndGame: %s\n", s);
+
+	if(sv.active)
+		Host_ShutdownServer(false);
+	if(cls.state == ca_dedicated)
+		Sys_Error("Host_EndGame: %s\n", s);	// dedicated servers exit
+	if(cls.demonum != -1)
+		CL_NextDemo();
 	else
-		CL_Disconnect ();
+		CL_Disconnect();
 
-	longjmp (host_abortserver, 1);
+	longjmp(host_abortserver, 1);
 }
 
 /*
@@ -97,35 +96,34 @@
 This shuts down both the client and server
 ================
 */
-void Host_Error (char *error, ...)
+void Host_Error (char *fmt, ...)
 {
-	va_list		argptr;
-	char		string[1024];
-	static	qboolean inerror = false;
+	va_list arg;
+	char s[1024];
+	static qboolean inerror = false;
 	
-	if (inerror)
-		Sys_Error ("Host_Error: recursively entered");
+	if(inerror)
+		Sys_Error("Host_Error: recursively entered");
 	inerror = true;
 	
-	SCR_EndLoadingPlaque ();		// reenable screen updates
+	SCR_EndLoadingPlaque();	// reenable screen updates
 
-	va_start (argptr,error);
-	vseprint (string,string+sizeof(string),error,argptr);
-	va_end (argptr);
-	Con_Printf ("Host_Error: %s\n",string);
-	
-	if (sv.active)
-		Host_ShutdownServer (false);
+	va_start(arg, fmt);
+	vsnprint(s, sizeof s, fmt, arg);
+	va_end(arg);
 
-	if (cls.state == ca_dedicated)
-		Sys_Error ("Host_Error: %s\n",string);	// dedicated servers exit
-
-	CL_Disconnect ();
+	Con_Printf("Host_Error: %s\n", s);
+	
+	if(sv.active)
+		Host_ShutdownServer(false);
+	if(cls.state == ca_dedicated)
+		Sys_Error("Host_Error: %s\n", s);	// dedicated servers exit
+	CL_Disconnect();
 	cls.demonum = -1;
 
 	inerror = false;
 
-	longjmp (host_abortserver, 1);
+	longjmp(host_abortserver, 1);
 }
 
 /*
@@ -143,10 +141,8 @@
 	if (i)
 	{
 		cls.state = ca_dedicated;
-		if (i != (com_argc - 1))
-		{
-			svs.maxclients = Q_atoi (com_argv[i+1]);
-		}
+		if(i != com_argc-1)
+			svs.maxclients = atoi(com_argv[i+1]);
 		else
 			svs.maxclients = 8;
 	}
@@ -159,7 +155,7 @@
 		if (cls.state == ca_dedicated)
 			Sys_Error ("Only one of -dedicated or -listen can be specified");
 		if (i != (com_argc - 1))
-			svs.maxclients = Q_atoi (com_argv[i+1]);
+			svs.maxclients = atoi(com_argv[i+1]);
 		else
 			svs.maxclients = 8;
 	}
@@ -171,7 +167,7 @@
 	svs.maxclientslimit = svs.maxclients;
 	if (svs.maxclientslimit < 4)
 		svs.maxclientslimit = 4;
-	svs.clients = Hunk_AllocName (svs.maxclientslimit*sizeof(client_t), "clients");
+	svs.clients = Hunk_AllocName(svs.maxclientslimit * sizeof *svs.clients, "clients");
 
 	if (svs.maxclients > 1)
 		Cvar_SetValue ("deathmatch", 1.0);
@@ -255,15 +251,15 @@
 */
 void SV_ClientPrintf (char *fmt, ...)
 {
-	va_list		argptr;
-	char		string[1024];
-	
-	va_start (argptr,fmt);
-	vseprint (string,string+sizeof(string),fmt,argptr);
-	va_end (argptr);
-	
-	MSG_WriteByte (&host_client->message, svc_print);
-	MSG_WriteString (&host_client->message, string);
+	va_list arg;
+	char s[1024];
+
+	va_start(arg, fmt);
+	vsnprint(s, sizeof s, fmt, arg);
+	va_end(arg);
+
+	MSG_WriteByte(&host_client->message, svc_print);
+	MSG_WriteString(&host_client->message, s);
 }
 
 /*
@@ -275,19 +271,18 @@
 */
 void SV_BroadcastPrintf (char *fmt, ...)
 {
-	va_list		argptr;
-	char		string[1024];
-	int			i;
+	va_list arg;
+	char s[1024];
+	int i;
 	
-	va_start (argptr,fmt);
-	vseprint (string,string+sizeof(string),fmt,argptr);
-	va_end (argptr);
+	va_start(arg, fmt);
+	vsnprint(s, sizeof s, fmt, arg);
+	va_end(arg);
 
-	for (i=0 ; i<svs.maxclients ; i++)
-		if (svs.clients[i].active && svs.clients[i].spawned)
-		{
-			MSG_WriteByte (&svs.clients[i].message, svc_print);
-			MSG_WriteString (&svs.clients[i].message, string);
+	for(i=0; i<svs.maxclients; i++)
+		if(svs.clients[i].active && svs.clients[i].spawned){
+			MSG_WriteByte(&svs.clients[i].message, svc_print);
+			MSG_WriteString(&svs.clients[i].message, s);
 		}
 }
 
@@ -300,15 +295,15 @@
 */
 void Host_ClientCommands (char *fmt, ...)
 {
-	va_list		argptr;
-	char		string[1024];
-	
-	va_start (argptr,fmt);
-	vseprint (string,string+sizeof(string),fmt,argptr);
-	va_end (argptr);
-	
-	MSG_WriteByte (&host_client->message, svc_stufftext);
-	MSG_WriteString (&host_client->message, string);
+	va_list arg;
+	char s[1024];
+
+	va_start(arg, fmt);
+	vsnprint(s, sizeof s, fmt, arg);
+	va_end(arg);
+
+	MSG_WriteByte(&host_client->message, svc_stufftext);
+	MSG_WriteString(&host_client->message, s);
 }
 
 /*
@@ -440,8 +435,8 @@
 //
 // clear structures
 //
-	memset (&sv, 0, sizeof(sv));
-	memset (svs.clients, 0, svs.maxclientslimit*sizeof(client_t));
+	memset(&sv, 0, sizeof sv);
+	memset(svs.clients, 0, svs.maxclientslimit * sizeof *svs.clients);
 }
 
 
@@ -462,8 +457,8 @@
 		Hunk_FreeToLowMark (host_hunklevel);
 
 	cls.signon = 0;
-	memset (&sv, 0, sizeof(sv));
-	memset (&cl, 0, sizeof(cl));
+	memset(&sv, 0, sizeof sv);
+	memset(&cl, 0, sizeof cl);
 }
 
 
@@ -515,7 +510,7 @@
 	while (1)
 	{
 		cmd = Sys_ConsoleInput ();
-		if (!cmd)
+		if (cmd == nil)
 			break;
 		Cbuf_AddText (cmd);
 	}
@@ -692,71 +687,6 @@
 	Con_Printf ("serverprofile: %2d clients %2d msec\n",  c,  m);
 }
 
-//============================================================================
-
-
-extern int vcrFile;
-#define	VCR_SIGNATURE	0x56435231
-// "VCR1"
-
-void Host_InitVCR (quakeparms_t *parms)
-{
-	int		i, len, n;
-	char	*p;
-	
-	if (COM_CheckParm("-playback"))
-	{
-		if (com_argc != 2)
-			Sys_Error("No other parameters allowed with -playback\n");
-
-		Sys_FileOpenRead("quake.vcr", &vcrFile);
-		if (vcrFile == -1)
-			Sys_Error("playback file not found\n");
-
-		Sys_FileRead (vcrFile, &i, sizeof(int));
-		if (i != VCR_SIGNATURE)
-			Sys_Error("Invalid signature in vcr file\n");
-
-		Sys_FileRead (vcrFile, &com_argc, sizeof(int));
-		com_argv = malloc(com_argc * sizeof(char *));
-		com_argv[0] = parms->argv[0];
-		for (i = 0; i < com_argc; i++)
-		{
-			Sys_FileRead (vcrFile, &len, sizeof(int));
-			p = malloc(len);
-			Sys_FileRead (vcrFile, p, len);
-			com_argv[i+1] = p;
-		}
-		com_argc++; /* add one for arg[0] */
-		parms->argc = com_argc;
-		parms->argv = com_argv;
-	}
-
-	if ( (n = COM_CheckParm("-record")) != 0)
-	{
-		vcrFile = Sys_FileOpenWrite("quake.vcr");
-
-		i = VCR_SIGNATURE;
-		Sys_FileWrite(vcrFile, &i, sizeof(int));
-		i = com_argc - 1;
-		Sys_FileWrite(vcrFile, &i, sizeof(int));
-		for (i = 1; i < com_argc; i++)
-		{
-			if (i == n)
-			{
-				len = 10;
-				Sys_FileWrite(vcrFile, &len, sizeof(int));
-				Sys_FileWrite(vcrFile, "-playback", len);
-				continue;
-			}
-			len = Q_strlen(com_argv[i]) + 1;
-			Sys_FileWrite(vcrFile, &len, sizeof(int));
-			Sys_FileWrite(vcrFile, com_argv[i], len);
-		}
-	}
-	
-}
-
 /*
 ====================
 Host_Init
@@ -786,7 +716,6 @@
 	Cmd_Init ();	
 	V_Init ();
 	Chase_Init ();
-	Host_InitVCR (parms);
 	COM_Init (parms->basedir);
 	Host_InitLocal ();
 	W_LoadWadFile ("gfx.wad");
@@ -813,7 +742,6 @@
 			Sys_Error ("Couldn't load gfx/colormap.lmp");
 
 		VID_Init (host_basepal);
-		IN_Init ();
 
 		Draw_Init ();
 		SCR_Init ();
@@ -823,6 +751,7 @@
 		Sbar_Init ();
 		CL_Init ();
 	}
+	IN_Init ();
 
 	Cbuf_InsertText ("exec quake.rc\n");
 
@@ -868,5 +797,6 @@
 	{
 		VID_Shutdown();
 	}
+	IN_Shutdown();
 }
 
--- a/host_cmd.c
+++ b/host_cmd.c
@@ -599,7 +599,7 @@
 		start = COM_Parse(str);
 		if (!com_token[0])
 			break;		// end of file
-		if (strcmp(com_token,"{"))
+		if(strcmp(com_token, "{") != 0)
 			Sys_Error ("First token isn't a brace");
 			
 		if (entnum == -1)
@@ -662,7 +662,7 @@
 
 	if (cmd_source == src_command)
 	{
-		if (Q_strcmp(cl_name.string, newName) == 0)
+		if(strcmp(cl_name.string, newName) == 0)
 			return;
 		Cvar_Set ("_cl_name", newName);
 		if (cls.state == ca_connected)
@@ -670,10 +670,10 @@
 		return;
 	}
 
-	if (host_client->name[0] && strcmp(host_client->name, "unconnected") )
-		if (Q_strcmp(host_client->name, newName) != 0)
+	if (host_client->name[0] && strcmp(host_client->name, "unconnected") != 0)
+		if(strcmp(host_client->name, newName) != 0)
 			Con_Printf ("%s renamed to %s\n", host_client->name, newName);
-	Q_strcpy (host_client->name, newName);
+	strcpy(host_client->name, newName);
 	host_client->edict->v.netname = host_client->name - pr_strings;
 	
 // send notification to all clients
@@ -699,9 +699,9 @@
 	if (cmd_source != src_command)
 		return;
 
-	if ((Cmd_Argc () == 3) && Q_strcmp(Cmd_Argv(1), "#") == 0)
+	if(Cmd_Argc() == 3 && strcmp(Cmd_Argv(1), "#") == 0)
 	{
-		j = Q_atof(Cmd_Argv(2)) - 1;
+		j = atof(Cmd_Argv(2)) - 1;
 		if (j < 0 || j >= svs.maxclients)
 			return;
 		if (!svs.clients[j].active)
@@ -725,7 +725,7 @@
 	{
 		if (!cl->active)
 			continue;
-		if (Q_strcasecmp(cl->name, Cmd_Argv(1)) == 0)
+		if(cistrcmp(cl->name, Cmd_Argv(1)) == 0)
 		{
 			if (cl->privileged)
 			{
@@ -776,7 +776,7 @@
 	if (*p == '"')
 	{
 		p++;
-		p[Q_strlen(p)-1] = 0;
+		p[strlen(p)-1] = 0;
 	}
 
 // turn on color set 1
@@ -785,8 +785,8 @@
 	else
 		sprint (text, "%c<%s> ", 1, hostname.string);
 
-	j = sizeof(text) - 2 - Q_strlen(text);  // -2 for /n and null terminator
-	if (Q_strlen(p) > j)
+	j = sizeof(text) - 2 - strlen(text);  // -2 for /n and null terminator
+	if(strlen(p) > j)
 		p[j] = 0;
 
 	strcat (text, p);
@@ -836,8 +836,8 @@
 	if (Cmd_Argc () < 3)
 		return;
 
-	Q_strcpy(text, host_client->name);
-	Q_strcat(text, ": ");
+	strcpy(text, host_client->name);
+	strcat(text, ": ");
 
 	p = Cmd_Args();
 
@@ -845,12 +845,12 @@
 	if (*p == '"')
 	{
 		p++;
-		p[Q_strlen(p)-1] = 0;
+		p[strlen(p)-1] = 0;
 	}
 
 // check length & truncate if necessary
-	j = sizeof(text) - 2 - Q_strlen(text);  // -2 for /n and null terminator
-	if (Q_strlen(p) > j)
+	j = sizeof(text) - 2 - strlen(text);  // -2 for /n and null terminator
+	if(strlen(p) > j)
 		p[j] = 0;
 
 	strcat (text, p);
@@ -861,7 +861,7 @@
 	{
 		if (!client->active || !client->spawned)
 			continue;
-		if (Q_strcasecmp(client->name, Cmd_Argv(1)))
+		if(cistrcmp(client->name, Cmd_Argv(1)) != 0)
 			continue;
 		host_client = client;
 		SV_ClientPrintf("%s", text);
@@ -1181,9 +1181,9 @@
 
 	save = host_client;
 
-	if (Cmd_Argc() > 2 && Q_strcmp(Cmd_Argv(1), "#") == 0)
+	if(Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
 	{
-		i = Q_atof(Cmd_Argv(2)) - 1;
+		i = atof(Cmd_Argv(2)) - 1;
 		if (i < 0 || i >= svs.maxclients)
 			return;
 		if (!svs.clients[i].active)
@@ -1197,7 +1197,7 @@
 		{
 			if (!host_client->active)
 				continue;
-			if (Q_strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
+			if(cistrcmp(host_client->name, Cmd_Argv(1)) == 0)
 				break;
 		}
 	}
@@ -1224,7 +1224,7 @@
 				message++;							// skip the #
 				while (*message == ' ')				// skip white space
 					message++;
-				message += Q_strlen(Cmd_Argv(2));	// skip the number
+				message += strlen(Cmd_Argv(2));	// skip the number
 			}
 			while (*message && *message == ' ')
 				message++;
@@ -1414,7 +1414,7 @@
 	for (i=0 ; i<sv.num_edicts ; i++)
 	{
 		e = EDICT_NUM(i);
-		if ( !strcmp (PR_Str(e->v.classname), "viewthing") )
+		if(strcmp(PR_Str(e->v.classname), "viewthing") == 0)
 			return e;
 	}
 	Con_Printf ("No viewthing on map\n");
--- /dev/null
+++ b/in.c
@@ -1,0 +1,344 @@
+#include <u.h>
+#include <libc.h>
+#include <stdio.h>
+#include <draw.h>
+#include <thread.h>
+#include <mouse.h>
+#include <keyboard.h>
+#include "quakedef.h"
+
+/* vid_9.c */
+extern int resized;
+extern Point center;
+
+typedef struct Kev Kev;
+
+enum{
+	Nbuf = 24
+};
+
+struct Kev{
+	int key;
+	int down;
+};
+static Channel *kchan;
+
+static cvar_t m_windowed = {"m_windowed", "0", true};
+static cvar_t m_filter = {"m_filter", "0", true};
+static int mouseon;
+static int oldmwin;
+static float mx;
+static float my;
+static float oldmx;
+static float oldmy;
+static int mb;
+static int oldmb;
+static int iop;
+static int pfd[2];
+
+
+char *
+Sys_ConsoleInput(void)
+{
+	char buf[256];
+
+	if(cls.state == ca_dedicated){
+		if(iop < 0)
+			return nil;
+		if(flen(pfd[1]) < 1)	/* only poll for input */
+			return nil;
+		if(read(pfd[1], buf, sizeof buf) < 0)
+			sysfatal("Sys_ConsoleInput:read: %r");
+		return buf;
+	}
+	return nil;
+}
+
+void
+Sys_SendKeyEvents(void)
+{
+	Kev ev;
+	int r;
+
+	if(kchan == nil)
+		return;
+
+	if(oldmwin != (int)m_windowed.value){
+		oldmwin = (int)m_windowed.value;
+		IN_Grabm(oldmwin);
+	}
+
+	while((r = nbrecv(kchan, &ev)) > 0)
+		Key_Event(ev.key, ev.down);
+	if(r < 0)
+		fprint(2, "Sys_SendKeyEvents:nbrecv: %r\n");
+}
+
+void
+IN_Commands(void)
+{
+	int i, r;
+
+	if(!mouseon)
+		return;
+
+	for(i=0; i<3; i++){
+		r = mb & 1<<i;
+		if(r ^ oldmb & 1<<i)
+			Key_Event(K_MOUSE1+i, r);
+	}
+	oldmb = mb;
+}
+
+void
+IN_Move(usercmd_t *cmd)
+{
+	if(!mouseon)
+		return;
+   
+	if(m_filter.value){
+		mx = (mx + oldmx) * 0.5;
+		my = (my + oldmy) * 0.5;
+	}
+	oldmx = mx;
+	oldmy = my;
+	mx *= sensitivity.value;
+	my *= sensitivity.value;
+   
+	if(in_strafe.state & 1 || lookstrafe.value && in_mlook.state & 1)
+		cmd->sidemove += m_side.value * mx;
+	else
+		cl.viewangles[YAW] -= m_yaw.value * mx;
+	if(in_mlook.state & 1)
+		V_StopPitchDrift();
+   
+	if(in_mlook.state & 1 && ~in_strafe.state & 1){
+		cl.viewangles[PITCH] += m_pitch.value * my;
+		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 * my;
+		else
+			cmd->forwardmove -= m_forward.value * my;
+	}
+	mx = my = 0.0;
+}
+
+static int
+runetokey(Rune r)
+{
+	int k = 0;
+
+	switch(r){
+	case Kpgup:	k = K_PGUP; break;
+	case Kpgdown:	k = K_PGDN; break;
+	case Khome:	k = K_HOME; break;
+	case Kend:	k = K_END; break;
+	case Kleft:	k = K_LEFTARROW; break;
+	case Kright:	k = K_RIGHTARROW; break;
+	case Kdown:	k = K_DOWNARROW; break;
+	case Kup:	k = K_UPARROW; break;
+	case Kesc:	k = K_ESCAPE; break;
+	case '\n':	k = K_ENTER; break;
+	case '\t':	k = K_TAB; break;
+	case KF|1:	k = K_F1; break;
+	case KF|2:	k = K_F2; break;
+	case KF|3:	k = K_F3; break;
+	case KF|4:	k = K_F4; break;
+	case KF|5:	k = K_F5; break;
+	case KF|6:	k = K_F6; break;
+	case KF|7:	k = K_F7; break;
+	case KF|8:	k = K_F8; break;
+	case KF|9:	k = K_F9; break;
+	case KF|10:	k = K_F10; break;
+	case KF|11:	k = K_F11; break;
+	case KF|12:	k = K_F12; break;
+	case Kbs:	k = K_BACKSPACE; break;
+	case Kdel:	k = K_DEL; break;
+	case Kbreak:	k = K_PAUSE; break;
+	case Kshift:	k = K_SHIFT; break;
+	case Kctl:	k = K_CTRL; break;
+	case Kalt:
+	case Kaltgr:	k = K_ALT; break;
+	case Kins:	k = K_INS; break;
+	default:
+		if(r < 0x80)
+			k = r;
+	}
+	return k;
+}
+
+static void
+kproc(void *)
+{
+	int n, k, fd;
+	char buf[128], kdown[128], *s;
+	Rune r;
+	Kev ev;
+
+	threadsetgrp(THin);
+
+	kdown[1] = kdown[0] = 0;
+	if((fd = open("/dev/kbd", OREAD)) < 0)
+		sysfatal("open /dev/kbd: %r");
+	while((n = read(fd, buf, sizeof buf)) > 0){
+		buf[n-1] = 0;
+		switch(*buf){
+		case 'c':
+		default:
+			continue;
+		case 'k':
+			s = buf+1;
+			while(*s){
+				s += chartorune(&r, s);
+				if(utfrune(kdown+1, r) == nil){
+					if(k = runetokey(r)){
+						ev.key = k;
+						ev.down = true;
+						if(nbsend(kchan, &ev) < 0)
+							fprint(2, "kproc:nbsend: %r\n");
+					}
+				}
+			}
+			break;
+		case 'K':
+			s = kdown+1;
+			while(*s){
+				s += chartorune(&r, s);
+				if(utfrune(buf+1, r) == nil){
+					if(k = runetokey(r)){
+						ev.key = k;
+						ev.down = false;
+						if(nbsend(kchan, &ev) < 0)
+							fprint(2, "kproc:nbsend: %r\n");
+					}
+				}
+			}
+			break;
+		}
+		strcpy(kdown, buf);
+	}
+	close(fd);
+}
+
+static void
+mproc(void *)
+{
+	int b, n, nerr, fd;
+	char buf[1+5*12];
+	float x, y;
+
+	threadsetgrp(THin);
+
+	if((fd = open("/dev/mouse", ORDWR)) < 0)
+		sysfatal("open /dev/mouse: %r");
+
+	nerr = 0;
+	for(;;){
+		if((n = read(fd, buf, sizeof buf)) != 1+4*12){
+			fprint(2, "mproc:read: bad count %d not 49: %r\n", n);
+			if(n < 0 || ++nerr > 10)
+				break;
+			continue;
+		}
+		nerr = 0;
+		switch(*buf){
+		case 'r':
+			resized = 1;
+			/* fall through */
+		case 'm':
+			if(!mouseon)
+				break;
+
+			x = atoi(buf+1+0*12) - center.x;
+			y = atoi(buf+1+1*12) - center.y;
+			b = atoi(buf+1+2*12);
+
+			mx += x;
+			my += y;
+			if(x != 0.0 ||  y != 0.0)
+				fprint(fd, "m%d %d", center.x, center.y);
+
+			mb = b&1 | (b&2)<<1 | (b&4)>>1;
+			break;
+		}
+	}
+	close(fd);
+}
+
+static void
+iproc(void *)
+{
+	int n;
+	char s[256];
+
+	threadsetgrp(THin);
+
+	if((iop = pipe(pfd)) < 0)
+		sysfatal("iproc:pipe: %r");
+	for(;;){
+		if((n = read(0, s, sizeof s)) <= 0)
+			break;
+		s[n-1] = 0;
+		if((write(pfd[0], s, n)) != n)
+			break;
+	}
+	fprint(2, "iproc %d: %r\n", threadpid(threadid()));
+}
+
+void
+IN_Grabm(int on)
+{
+	static char nocurs[2*4+2*2*16];
+	static int fd = -1;
+
+	if(mouseon == on)
+		return;
+	if(mouseon = on && m_windowed.value){
+		if((fd = open("/dev/cursor", ORDWR|OCEXEC)) < 0){
+			fprint(2, "IN_Grabm:open: %r\n");
+			return;
+		}
+		write(fd, nocurs, sizeof nocurs);
+	}else if(fd >= 0){
+		close(fd);
+		fd = -1;
+	}
+}
+
+void
+IN_Shutdown(void)
+{
+	IN_Grabm(0);
+	threadkillgrp(THin);
+	close(pfd[0]);
+	close(pfd[1]);
+	if(kchan != nil){
+		chanfree(kchan);
+		kchan = nil;
+	}
+}
+
+void
+IN_Init(void)
+{
+	if(cls.state == ca_dedicated){
+		if(proccreate(iproc, nil, 8192) < 0)
+			sysfatal("proccreate iproc: %r");
+		return;
+	}
+	Cvar_RegisterVariable(&m_windowed);
+	Cvar_RegisterVariable(&m_filter);
+	if((kchan = chancreate(sizeof(Kev), Nbuf)) == nil)
+		sysfatal("chancreate kchan: %r");
+	if(proccreate(kproc, nil, 8192) < 0)
+		sysfatal("proccreate kproc: %r");
+	if(COM_CheckParm("-nomouse"))
+		return;
+	if(proccreate(mproc, nil, 8192) < 0)
+		sysfatal("proccreate mproc: %r");
+	mx = my = 0.0;
+}
--- a/in_9.c
+++ /dev/null
@@ -1,288 +1,0 @@
-#include <u.h>
-#include <libc.h>
-#include <stdio.h>
-#include <draw.h>
-#include <thread.h>
-#include <mouse.h>
-#include <keyboard.h>
-#include "quakedef.h"
-
-typedef struct Kev Kev;
-struct Kev{
-	int key;
-	int down;
-};
-enum{
-	Nbuf	= 64
-};
-
-cvar_t m_windowed = {"m_windowed","0", true};
-cvar_t m_filter = {"m_filter","0", true};
-float oldm_windowed;
-int mouse_buttons = 3;
-int mouse_buttonstate, mouse_oldbuttonstate;
-float mouse_x, mouse_y, old_mouse_x, old_mouse_y;
-int mouseon;
-int ktid = -1, mtid = -1;
-Channel *kchan;
-
-/* vid_9.c */
-extern int config_notify;
-extern Point center;
-extern Rectangle grabout;
-
-
-void Sys_SendKeyEvents(void)
-{
-	Kev ev;
-	int r;
-
-	if(oldm_windowed != m_windowed.value){
-		oldm_windowed = m_windowed.value;
-		IN_Grabm(m_windowed.value);
-	}
-
-	while((r = nbrecv(kchan, &ev)) > 0)
-		Key_Event(ev.key, ev.down);
-	if(r < 0)
-		Con_Printf("Sys_SendKeyEvents:nbrecv: %r\n");
-}
-
-void IN_Commands (void)
-{
-	int i;
-
-	if(!mouseon)
-		return;
-
-	/* FIXMEGASHIT */
-	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(!mouseon)
-		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;
-}
-
-int runetokey (Rune r)
-{
-	int k = 0;
-
-	switch(r){
-	case Kpgup:	k = K_PGUP; break;
-	case Kpgdown:	k = K_PGDN; break;
-	case Khome:	k = K_HOME; break;
-	case Kend:	k = K_END; break;
-	case Kleft:	k = K_LEFTARROW; break;
-	case Kright:	k = K_RIGHTARROW; break;
-	case Kdown:	k = K_DOWNARROW; break;
-	case Kup:	k = K_UPARROW; break;
-	case Kesc:	k = K_ESCAPE; break;
-	case '\n':	k = K_ENTER; break;
-	case '\t':	k = K_TAB; break;
-	case KF|1:	k = K_F1; break;
-	case KF|2:	k = K_F2; break;
-	case KF|3:	k = K_F3; break;
-	case KF|4:	k = K_F4; break;
-	case KF|5:	k = K_F5; break;
-	case KF|6:	k = K_F6; break;
-	case KF|7:	k = K_F7; break;
-	case KF|8:	k = K_F8; break;
-	case KF|9:	k = K_F9; break;
-	case KF|10:	k = K_F10; break;
-	case KF|11:	k = K_F11; break;
-	case KF|12:	k = K_F12; break;
-	case Kbs:	k = K_BACKSPACE; break;
-	case Kdel:	k = K_DEL; break;
-	case Kbreak:	k = K_PAUSE; break;
-	case Kshift:	k = K_SHIFT; break;
-	case Kctl:	k = K_CTRL; break;
-	case Kalt:
-	case Kaltgr:	k = K_ALT; break;
-	case Kins:	k = K_INS; break;
-	default:
-		if(r < 0x80)
-			k = r;
-	}
-	return k;
-}
-
-void kproc (void *)
-{
-	int n, k, fd;
-	char buf[128], kdown[128] = {0}, *s;
-	Rune r;
-	Kev ev;
-
-	if((fd = open("/dev/kbd", OREAD)) < 0)
-		sysfatal("open /dev/kbd: %r");
-
-	while((n = read(fd, buf, sizeof(buf))) > 0){
-		buf[n-1] = 0;
-		switch(*buf){
-		case 'c':
-		default:
-			continue;
-		case 'k':
-			s = buf+1;
-			while(*s){
-				s += chartorune(&r, s);
-				if(utfrune(kdown+1, r) == nil){
-					if(k = runetokey(r)){
-						ev.key = k;
-						ev.down = true;
-						if(nbsend(kchan, &ev) < 0)
-							Con_Printf("kproc:nbsend: %r\n");
-					}
-				}
-			}
-			break;
-		case 'K':
-			s = kdown+1;
-			while(*s){
-				s += chartorune(&r, s);
-				if(utfrune(buf+1, r) == nil){
-					if(k = runetokey(r)){
-						ev.key = k;
-						ev.down = false;
-						if(nbsend(kchan, &ev) < 0)
-							Con_Printf("kproc:nbsend: %r\n");
-					}
-				}
-			}
-			break;
-		}
-		strcpy(kdown, buf);
-	}
-	close(fd);
-}
-
-void mproc (void *)
-{
-	int b, n, nerr, fd;
-	char buf[1+5*12];
-	float x, y;
-
-	if((fd = open("/dev/mouse", ORDWR)) < 0)
-		sysfatal("open /dev/mouse: %r");
-
-	nerr = 0;
-	for(;;){
-		if((n = read(fd, buf, sizeof buf)) != 1+4*12){
-			Con_Printf("mproc:read: bad count %d not 49: %r\n", n);
-			if(n < 0 || ++nerr > 10)
-				break;
-			continue;
-		}
-		nerr = 0;
-		switch(*buf){
-		case 'r':
-			config_notify = 1;
-			/* fall through */
-		case 'm':
-			if(!mouseon)
-				break;
-
-			x = atoi(buf+1+0*12) - center.x;
-			y = atoi(buf+1+1*12) - center.y;
-			b = atoi(buf+1+2*12);
-
-			mouse_x += x;
-			mouse_y += y;
-			if(x != 0.0 ||  y != 0.0)
-				fprint(fd, "m%d %d", center.x, center.y);
-
-			mouse_buttonstate = b&1 | (b&2)<<1 | (b&4)>>1;
-			break;
-		}
-	}
-	close(fd);
-}
-
-void IN_Grabm (int on)
-{
-	static char nocurs[2*4+2*2*16];
-	static int fd = -1;
-
-	if(mouseon == on)
-		return;
-	if(mouseon = on && m_windowed.value){
-		if((fd = open("/dev/cursor", ORDWR|OCEXEC)) < 0){
-			Con_Printf("IN_Grabm:open: %r\n");
-			return;
-		}
-		write(fd, nocurs, sizeof(nocurs));
-	}else if(fd >= 0){
-		close(fd);
-		fd = -1;
-	}
-}
-
-void IN_Shutdown (void)
-{
-	IN_Grabm(0);
-	if(ktid != -1){
-		threadkill(ktid);
-		ktid = -1;
-	}
-	if(mtid != -1){
-		threadkill(mtid);
-		mtid = -1;
-	}
-	if(kchan != nil){
-		chanfree(kchan);
-		kchan = nil;
-	}
-	mouseon = 0;
-}
-
-void IN_Init (void)
-{
-	Cvar_RegisterVariable(&m_windowed);
-	Cvar_RegisterVariable(&m_filter);
-	kchan = chancreate(sizeof(Kev), Nbuf);
-	if((ktid = proccreate(kproc, nil, 8192)) < 0)
-		sysfatal("proccreate kproc: %r");
-	if(COM_CheckParm("-nomouse"))
-		return;
-	if((mtid = proccreate(mproc, nil, 8192)) < 0)
-		sysfatal("proccreate mproc: %r");
-	mouse_x = mouse_y = 0.0;
-}
--- a/keys.c
+++ b/keys.c
@@ -28,7 +28,6 @@
 qboolean	menubound[256];	// if true, can't be rebound while in menu
 int		keyshift[256];		// key to map to if shift held down in console
 int		key_repeats[256];	// if > 1, it is autorepeating
-qboolean	keydown[256];
 
 typedef struct
 {
@@ -166,8 +165,8 @@
 			cmd = Cvar_CompleteVariable (key_lines[edit_line]+1);
 		if (cmd)
 		{
-			Q_strcpy (key_lines[edit_line]+1, cmd);
-			key_linepos = Q_strlen(cmd)+1;
+			strcpy(key_lines[edit_line]+1, cmd);
+			key_linepos = strlen(cmd)+1;
 			key_lines[edit_line][key_linepos] = ' ';
 			key_linepos++;
 			key_lines[edit_line][key_linepos] = 0;
@@ -191,8 +190,8 @@
 				&& !key_lines[history_line][1]);
 		if (history_line == edit_line)
 			history_line = (edit_line+1)&31;
-		Q_strcpy(key_lines[edit_line], key_lines[history_line]);
-		key_linepos = Q_strlen(key_lines[edit_line]);
+		strcpy(key_lines[edit_line], key_lines[history_line]);
+		key_linepos = strlen(key_lines[edit_line]);
 		return;
 	}
 
@@ -212,8 +211,8 @@
 		}
 		else
 		{
-			Q_strcpy(key_lines[edit_line], key_lines[history_line]);
-			key_linepos = Q_strlen(key_lines[edit_line]);
+			strcpy(key_lines[edit_line], key_lines[history_line]);
+			key_linepos = strlen(key_lines[edit_line]);
 		}
 		return;
 	}
@@ -310,32 +309,22 @@
 	chat_buffer[chat_bufferlen] = 0;
 }
 
-//============================================================================
-
-
-/*
-===================
-Key_StringToKeynum
-
-Returns a key number to be used to index keybindings[] by looking at
-the given string.  Single ascii characters return themselves, while
-the K_* names are matched up.
-===================
-*/
-int Key_StringToKeynum (char *str)
+/* Returns a key number to be used to index keybindings[] by looking at the
+ * given string. Single ascii characters return themselves, while the K_* names
+ * are matched up. */
+int
+Key_StringToKeynum(char *s)
 {
-	keyname_t	*kn;
+	keyname_t *k;
 	
-	if (!str || !str[0])
+	if(s == nil || s[0] == 0)
 		return -1;
-	if (!str[1])
-		return str[0];
+	if(s[1] == 0)
+		return s[0];
 
-	for (kn=keynames ; kn->name ; kn++)
-	{
-		if (!Q_strcasecmp(str,kn->name))
-			return kn->keynum;
-	}
+	for(k = keynames; k->name != nil; k++)
+		if(cistrcmp(s, k->name) == 0)
+			return k->keynum;
 	return -1;
 }
 
@@ -391,9 +380,9 @@
 	}
 			
 // allocate memory for new binding
-	l = Q_strlen (binding);	
+	l = strlen(binding);	
 	new = Z_Malloc (l+1);
-	Q_strcpy (new, binding);
+	strcpy(new, binding);
 	new[l] = 0;
 	keybindings[keynum] = new;	
 }
@@ -585,8 +574,6 @@
 	char	*kb;
 	char	cmd[1024];
 
-	keydown[key] = down;
-
 	if (!down)
 		key_repeats[key] = 0;
 
@@ -724,20 +711,11 @@
 	}
 }
 
-
-/*
-===================
-Key_ClearStates
-===================
-*/
-void Key_ClearStates (void)
+void
+Key_ClearStates(void)
 {
-	int		i;
+	int i;
 
-	for (i=0 ; i<256 ; i++)
-	{
-		keydown[i] = false;
+	for(i=0; i<256; i++)
 		key_repeats[i] = 0;
-	}
 }
-
--- a/mathlib.c
+++ b/mathlib.c
@@ -97,7 +97,7 @@
 	m[1][2] = vf[1];
 	m[2][2] = vf[2];
 
-	memcpy( im, m, sizeof( im ) );
+	memcpy(im, m, sizeof im);
 
 	im[0][1] = m[1][0];
 	im[0][2] = m[2][0];
@@ -106,7 +106,7 @@
 	im[2][0] = m[0][2];
 	im[2][1] = m[1][2];
 
-	memset( zrot, 0, sizeof( zrot ) );
+	memset(zrot, 0, sizeof zrot);
 	zrot[0][0] = zrot[1][1] = zrot[2][2] = 1.0F;
 
 	zrot[0][0] = cos( DEG2RAD( degrees ) );
@@ -383,16 +383,6 @@
 	out[1] = in[1]*scale;
 	out[2] = in[2]*scale;
 }
-
-
-int Q_log2(int val)
-{
-	int answer=0;
-	while (val>>=1)
-		answer++;
-	return answer;
-}
-
 
 /*
 ================
--- a/mathlib.h
+++ b/mathlib.h
@@ -37,7 +37,6 @@
 float VectorNormalize (vec3_t v);		// returns vector length
 void VectorInverse (vec3_t v);
 void VectorScale (vec3_t in, vec_t scale, vec3_t out);
-int Q_log2(int val);
 
 void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3]);
 void R_ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4]);
--- a/menu.c
+++ b/menu.c
@@ -681,8 +681,8 @@
 	key_dest = key_menu;
 	m_state = m_setup;
 	m_entersound = true;
-	Q_strcpy(setup_myname, cl_name.string);
-	Q_strcpy(setup_hostname, hostname.string);
+	strcpy(setup_myname, cl_name.string);
+	strcpy(setup_hostname, hostname.string);
 	setup_top = setup_oldtop = ((int)cl_color.value) >> 4;
 	setup_bottom = setup_oldbottom = ((int)cl_color.value) & 15;
 }
@@ -778,12 +778,12 @@
 			goto forward;
 
 		// setup_cursor == 4 (OK)
-		if (Q_strcmp(cl_name.string, setup_myname) != 0)
+		if(strcmp(cl_name.string, setup_myname) != 0)
 			Cbuf_AddText ( va ("name \"%s\"\n", setup_myname) );
-		if (Q_strcmp(hostname.string, setup_hostname) != 0)
+		if(strcmp(hostname.string, setup_hostname) != 0)
 			Cvar_Set("hostname", setup_hostname);
-		if (setup_top != setup_oldtop || setup_bottom != setup_oldbottom)
-			Cbuf_AddText( va ("color %d %d\n", setup_top, setup_bottom) );
+		if(setup_top != setup_oldtop || setup_bottom != setup_oldbottom)
+			Cbuf_AddText(va("color %d %d\n", setup_top, setup_bottom));
 		m_entersound = true;
 		M_Menu_MultiPlayer_f ();
 		break;
@@ -1292,7 +1292,7 @@
 		b = keybindings[j];
 		if (!b)
 			continue;
-		if (!strncmp (b, command, l) )
+		if(strncmp(b, command, l) == 0)
 		{
 			twokeys[count] = j;
 			count++;
@@ -1315,7 +1315,7 @@
 		b = keybindings[j];
 		if (!b)
 			continue;
-		if (!strncmp (b, command, l) )
+		if(strncmp(b, command, l) == 0)
 			Key_SetBinding (j, "");
 	}
 }
@@ -1591,16 +1591,16 @@
 
 }
 
-
-void M_Quit_Draw (void)
+void
+M_Quit_Draw(void)
 {
-	if (wasInMenus)
-	{
+	if(wasInMenus){
 		m_state = m_quit_prevstate;
 		m_recursiveDraw = true;
-		M_Draw ();
+		M_Draw();
 		m_state = m_quit;
 	}
+
 	M_DrawTextBox (56, 76, 24, 4);
 	M_Print (64, 84,  quitMessage[msgNumber*4+0]);
 	M_Print (64, 92,  quitMessage[msgNumber*4+1]);
@@ -2263,7 +2263,7 @@
 		else
 			lanConfig_cursor = 0;
 
-	l =  Q_atoi(lanConfig_portname);
+	l = atoi(lanConfig_portname);
 	if (l < 65535)
 		lanConfig_port = l;
 	sprint(lanConfig_portname, "%ud", (uint)lanConfig_port);	/* FIXME */
@@ -2806,23 +2806,22 @@
 
 void M_ServerList_Draw (void)
 {
-	int		n;
+	int n, i, j;
 	char	string [64];
 	qpic_t	*p;
+	hostcache_t temp;
 
 	if (!slist_sorted)
 	{
 		if (hostCacheCount > 1)
 		{
-			int	i,j;
-			hostcache_t temp;
 			for (i = 0; i < hostCacheCount; i++)
 				for (j = i+1; j < hostCacheCount; j++)
-					if (strcmp(hostcache[j].name, hostcache[i].name) < 0)
+					if(strcmp(hostcache[j].name, hostcache[i].name) < 0)
 					{
-						Q_memcpy(&temp, &hostcache[j], sizeof(hostcache_t));
-						Q_memcpy(&hostcache[j], &hostcache[i], sizeof(hostcache_t));
-						Q_memcpy(&hostcache[i], &temp, sizeof(hostcache_t));
+						memcpy(&temp, &hostcache[j], sizeof temp);
+						memcpy(&hostcache[j], &hostcache[i], sizeof temp);
+						memcpy(&hostcache[i], &temp, sizeof temp);
 					}
 		}
 		slist_sorted = true;
--- a/mkfile
+++ b/mkfile
@@ -36,7 +36,6 @@
 	model.$O\
 	net_loop.$O\
 	net_main.$O\
-	net_vcr.$O\
 	net_dgrm.$O\
 	net_bsd.$O\
 	nonintel.$O\
@@ -70,11 +69,11 @@
 	snd_dma.$O\
 	snd_mem.$O\
 	snd_mix.$O\
-	in_9.$O\
-	sys_9.$O\
-	vid_9.$O\
-	snd_9.$O\
-	cd_9.$O\
+	in.$O\
+	sys.$O\
+	vid.$O\
+	snd.$O\
+	cd.$O\
 	net_udp.$O\
 
 HFILES=\
--- a/model.c
+++ b/model.c
@@ -27,14 +27,10 @@
 #define NL_NEEDS_LOADED	1
 #define NL_UNREFERENCED	2
 
-/*
-===============
-Mod_Init
-===============
-*/
-void Mod_Init (void)
+void
+Mod_Init(void)
 {
-	memset (mod_novis, 0xff, sizeof(mod_novis));
+	memset(mod_novis, 0xff, sizeof mod_novis);
 }
 
 /*
@@ -178,9 +174,9 @@
 //
 	for (i=0 , mod=mod_known ; i<mod_numknown ; i++, mod++)
 	{
-		if (!strcmp (mod->name, name) )
+		if(strcmp(mod->name, name) == 0)
 			break;
-		if (mod->needload == NL_UNREFERENCED)
+		if(mod->needload == NL_UNREFERENCED)
 			if (!avail || mod->type != mod_alias)
 				avail = mod;
 	}
@@ -260,7 +256,7 @@
 //
 // load the file
 //
-	buf = (unsigned *)COM_LoadStackFile (mod->name, stackbuf, sizeof(stackbuf));
+	buf = (uint *)COM_LoadStackFile(mod->name, stackbuf, sizeof stackbuf);
 	if (!buf)
 	{
 		if (crash)
@@ -352,7 +348,7 @@
 	m->nummiptex = LittleLong (m->nummiptex);
 	
 	loadmodel->numtextures = m->nummiptex;
-	loadmodel->textures = Hunk_AllocName (m->nummiptex * sizeof(*loadmodel->textures) , loadname);
+	loadmodel->textures = Hunk_AllocName(m->nummiptex * sizeof *loadmodel->textures, loadname);
 
 	for (i=0 ; i<m->nummiptex ; i++)
 	{
@@ -368,18 +364,18 @@
 		if ( (mt->width & 15) || (mt->height & 15) )
 			Sys_Error ("Texture %s is not 16 aligned", mt->name);
 		pixels = mt->width*mt->height/64*85;
-		tx = Hunk_AllocName (sizeof(texture_t) +pixels, loadname );
+		tx = Hunk_AllocName(pixels + sizeof *tx, loadname);
 		loadmodel->textures[i] = tx;
 
-		memcpy (tx->name, mt->name, sizeof(tx->name));
+		memcpy(tx->name, mt->name, sizeof tx->name);
 		tx->width = mt->width;
 		tx->height = mt->height;
 		for (j=0 ; j<MIPLEVELS ; j++)
 			tx->offsets[j] = mt->offsets[j] + sizeof(texture_t) - sizeof(miptex_t);
 		// the pixels immediately follow the structures
-		memcpy ( tx+1, mt+1, pixels);
+		memcpy(tx+1, mt+1, pixels);
 		
-		if (!Q_strncmp(mt->name,"sky",3))	
+		if(strncmp(mt->name, "sky", 3) == 0)	
 			R_InitSky (tx);
 	}
 
@@ -395,8 +391,8 @@
 			continue;	// allready sequenced
 
 	// find the number of frames in the animation
-		memset (anims, 0, sizeof(anims));
-		memset (altanims, 0, sizeof(altanims));
+		memset(anims, 0, sizeof anims);
+		memset(altanims, 0, sizeof altanims);
 
 		max = tx->name[1];
 		altmax = 0;
@@ -424,7 +420,7 @@
 			tx2 = loadmodel->textures[j];
 			if (!tx2 || tx2->name[0] != '+')
 				continue;
-			if (strcmp (tx2->name+2, tx->name+2))
+			if(strcmp(tx2->name+2, tx->name+2) != 0)
 				continue;
 
 			num = tx2->name[1];
@@ -454,7 +450,7 @@
 		{
 			tx2 = anims[j];
 			if (!tx2)
-				Sys_Error ("Missing frame %d of %s",j, tx->name);
+				Sys_Error("Missing frame %d of %s", j, tx->name);
 			tx2->anim_total = max * ANIM_CYCLE;
 			tx2->anim_min = j * ANIM_CYCLE;
 			tx2->anim_max = (j+1) * ANIM_CYCLE;
@@ -466,7 +462,7 @@
 		{
 			tx2 = altanims[j];
 			if (!tx2)
-				Sys_Error ("Missing frame %d of %s",j, tx->name);
+				Sys_Error("Missing frame %d of %s", j, tx->name);
 			tx2->anim_total = altmax * ANIM_CYCLE;
 			tx2->anim_min = j * ANIM_CYCLE;
 			tx2->anim_max = (j+1) * ANIM_CYCLE;
@@ -489,8 +485,8 @@
 		loadmodel->lightdata = nil;
 		return;
 	}
-	loadmodel->lightdata = Hunk_AllocName ( l->filelen, loadname);	
-	memcpy (loadmodel->lightdata, mod_base + l->fileofs, l->filelen);
+	loadmodel->lightdata = Hunk_AllocName(l->filelen, loadname);
+	memcpy(loadmodel->lightdata, mod_base + l->fileofs, l->filelen);
 }
 
 
@@ -506,8 +502,8 @@
 		loadmodel->visdata = nil;
 		return;
 	}
-	loadmodel->visdata = Hunk_AllocName ( l->filelen, loadname);	
-	memcpy (loadmodel->visdata, mod_base + l->fileofs, l->filelen);
+	loadmodel->visdata = Hunk_AllocName(l->filelen, loadname);
+	memcpy(loadmodel->visdata, mod_base + l->fileofs, l->filelen);
 }
 
 
@@ -523,8 +519,8 @@
 		loadmodel->entities = nil;
 		return;
 	}
-	loadmodel->entities = Hunk_AllocName ( l->filelen, loadname);	
-	memcpy (loadmodel->entities, mod_base + l->fileofs, l->filelen);
+	loadmodel->entities = Hunk_AllocName(l->filelen, loadname);
+	memcpy(loadmodel->entities, mod_base + l->fileofs, l->filelen);
 }
 
 
@@ -541,9 +537,9 @@
 
 	in = (void *)(mod_base + l->fileofs);
 	if (l->filelen % sizeof(*in))
-		Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+		Sys_Error("Mod_LoadVertexes: funny lump size in %s", loadmodel->name);
 	count = l->filelen / sizeof(*in);
-	out = Hunk_AllocName ( count*sizeof(*out), loadname);	
+	out = Hunk_AllocName(count * sizeof *out, loadname);
 
 	loadmodel->vertexes = out;
 	loadmodel->numvertexes = count;
@@ -569,9 +565,9 @@
 
 	in = (void *)(mod_base + l->fileofs);
 	if (l->filelen % sizeof(*in))
-		Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+		Sys_Error("Mod_LoadSubmodels: funny lump size in %s", loadmodel->name);
 	count = l->filelen / sizeof(*in);
-	out = Hunk_AllocName ( count*sizeof(*out), loadname);	
+	out = Hunk_AllocName(count * sizeof *out, loadname);
 
 	loadmodel->submodels = out;
 	loadmodel->numsubmodels = count;
@@ -605,9 +601,9 @@
 
 	in = (void *)(mod_base + l->fileofs);
 	if (l->filelen % sizeof(*in))
-		Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+		Sys_Error("Mod_LoadEdges: funny lump size in %s", loadmodel->name);
 	count = l->filelen / sizeof(*in);
-	out = Hunk_AllocName ( (count + 1) * sizeof(*out), loadname);	
+	out = Hunk_AllocName((count+1) * sizeof *out, loadname);
 
 	loadmodel->edges = out;
 	loadmodel->numedges = count;
@@ -634,9 +630,9 @@
 
 	in = (void *)(mod_base + l->fileofs);
 	if (l->filelen % sizeof(*in))
-		Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+		Sys_Error("Mod_LoadTexInfo: funny lump size in %s", loadmodel->name);
 	count = l->filelen / sizeof(*in);
-	out = Hunk_AllocName ( count*sizeof(*out), loadname);	
+	out = Hunk_AllocName(count * sizeof *out, loadname);
 
 	loadmodel->texinfo = out;
 	loadmodel->numtexinfo = count;
@@ -753,9 +749,9 @@
 
 	in = (void *)(mod_base + l->fileofs);
 	if (l->filelen % sizeof(*in))
-		Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+		Sys_Error("Mod_LoadFaces: funny lump size in %s", loadmodel->name);
 	count = l->filelen / sizeof(*in);
-	out = Hunk_AllocName ( count*sizeof(*out), loadname);	
+	out = Hunk_AllocName(count * sizeof *out, loadname);
 
 	loadmodel->surfaces = out;
 	loadmodel->numsurfaces = count;
@@ -789,13 +785,13 @@
 		
 	// set the drawing flags flag
 		
-		if (!Q_strncmp(out->texinfo->texture->name,"sky",3))	// sky
+		if(strncmp(out->texinfo->texture->name, "sky", 3) == 0)
 		{
 			out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED);
 			continue;
 		}
 		
-		if (!Q_strncmp(out->texinfo->texture->name,"*",1))		// turbulent
+		if(strncmp(out->texinfo->texture->name, "*", 1) == 0)	// turbulent
 		{
 			out->flags |= (SURF_DRAWTURB | SURF_DRAWTILED);
 			for (i=0 ; i<2 ; i++)
@@ -836,9 +832,9 @@
 
 	in = (void *)(mod_base + l->fileofs);
 	if (l->filelen % sizeof(*in))
-		Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+		Sys_Error("Mod_LoadNodes: funny lump size in %s", loadmodel->name);
 	count = l->filelen / sizeof(*in);
-	out = Hunk_AllocName ( count*sizeof(*out), loadname);	
+	out = Hunk_AllocName(count * sizeof *out, loadname);
 
 	loadmodel->nodes = out;
 	loadmodel->numnodes = count;
@@ -883,9 +879,9 @@
 
 	in = (void *)(mod_base + l->fileofs);
 	if (l->filelen % sizeof(*in))
-		Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+		Sys_Error("Mod_LoadLeafs: funny lump size in %s", loadmodel->name);
 	count = l->filelen / sizeof(*in);
-	out = Hunk_AllocName ( count*sizeof(*out), loadname);	
+	out = Hunk_AllocName(count * sizeof *out, loadname);
 
 	loadmodel->leafs = out;
 	loadmodel->numleafs = count;
@@ -930,9 +926,9 @@
 
 	in = (void *)(mod_base + l->fileofs);
 	if (l->filelen % sizeof(*in))
-		Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+		Sys_Error("Mod_LoadClipnodes: funny lump size in %s", loadmodel->name);
 	count = l->filelen / sizeof(*in);
-	out = Hunk_AllocName ( count*sizeof(*out), loadname);	
+	out = Hunk_AllocName(count * sizeof *out, loadname);
 
 	loadmodel->clipnodes = out;
 	loadmodel->numclipnodes = count;
@@ -987,7 +983,7 @@
 	
 	in = loadmodel->nodes;
 	count = loadmodel->numnodes;
-	out = Hunk_AllocName ( count*sizeof(*out), loadname);	
+	out = Hunk_AllocName(count * sizeof *out, loadname);
 
 	hull->clipnodes = out;
 	hull->firstclipnode = 0;
@@ -1021,9 +1017,9 @@
 	
 	in = (void *)(mod_base + l->fileofs);
 	if (l->filelen % sizeof(*in))
-		Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+		Sys_Error("Mod_LoadMarksurfaces: funny lump size in %s", loadmodel->name);
 	count = l->filelen / sizeof(*in);
-	out = Hunk_AllocName ( count*sizeof(*out), loadname);	
+	out = Hunk_AllocName(count * sizeof *out, loadname);
 
 	loadmodel->marksurfaces = out;
 	loadmodel->nummarksurfaces = count;
@@ -1049,9 +1045,9 @@
 	
 	in = (void *)(mod_base + l->fileofs);
 	if (l->filelen % sizeof(*in))
-		Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+		Sys_Error("Mod_LoadSurfedges: funny lump size in %s", loadmodel->name);
 	count = l->filelen / sizeof(*in);
-	out = Hunk_AllocName ( count*sizeof(*out), loadname);	
+	out = Hunk_AllocName(count * sizeof *out, loadname);
 
 	loadmodel->surfedges = out;
 	loadmodel->numsurfedges = count;
@@ -1075,10 +1071,10 @@
 	
 	in = (void *)(mod_base + l->fileofs);
 	if (l->filelen % sizeof(*in))
-		Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+		Sys_Error("Mod_LoadPlanes: funny lump size in %s", loadmodel->name);
 	count = l->filelen / sizeof(*in);
-	out = Hunk_AllocName ( count*2*sizeof(*out), loadname);	
-	
+	out = Hunk_AllocName(count * 2 * sizeof *out, loadname);
+
 	loadmodel->planes = out;
 	loadmodel->numplanes = count;
 
@@ -1133,7 +1129,7 @@
 
 	i = LittleLong (header->version);
 	if (i != BSPVERSION)
-		Sys_Error ("Mod_LoadBrushModel: %s has wrong version number (%d should be %d)", mod->name, i, BSPVERSION);
+		Sys_Error("Mod_LoadBrushModel: %s has wrong version number (%d should be %d)", mod->name, i, BSPVERSION);
 
 // swap all the lumps
 	mod_base = (byte *)header;
@@ -1233,7 +1229,7 @@
 	}
 
 	pinframe = (trivertx_t *)(pdaliasframe + 1);
-	pframe = Hunk_AllocName (numv * sizeof(*pframe), loadname);
+	pframe = Hunk_AllocName(numv * sizeof *pframe, loadname);
 
 	*pframeindex = (byte *)pframe - (byte *)pheader;
 
@@ -1275,8 +1271,8 @@
 
 	numframes = LittleLong (pingroup->numframes);
 
-	paliasgroup = Hunk_AllocName (sizeof (maliasgroup_t) +
-			(numframes - 1) * sizeof (paliasgroup->frames[0]), loadname);
+	paliasgroup = Hunk_AllocName(sizeof(*paliasgroup) +
+			(numframes - 1) * sizeof paliasgroup->frames[0], loadname);
 
 	paliasgroup->numframes = numframes;
 
@@ -1291,7 +1287,7 @@
 
 	pin_intervals = (daliasinterval_t *)(pingroup + 1);
 
-	poutintervals = Hunk_AllocName (numframes * sizeof (float), loadname);
+	poutintervals = Hunk_AllocName(numframes * sizeof *poutintervals, loadname);
 
 	paliasgroup->intervals = (byte *)poutintervals - (byte *)pheader;
 
@@ -1320,43 +1316,29 @@
 	return ptemp;
 }
 
-
-/*
-=================
-Mod_LoadAliasSkin
-=================
-*/
-void * Mod_LoadAliasSkin (void * pin, int *pskinindex, int skinsize,
-	aliashdr_t *pheader)
+void *
+Mod_LoadAliasSkin(void * pin, int *pskinindex, int skinsize, aliashdr_t *pheader)
 {
-	int		i;
-	byte	*pskin, *pinskin;
-	unsigned short	*pusskin;
+	int i;
+	uchar *pskin, *pinskin;
+	ushort *pusskin;
 
-	pskin = Hunk_AllocName (skinsize * r_pixbytes, loadname);
-	pinskin = (byte *)pin;
-	*pskinindex = (byte *)pskin - (byte *)pheader;
+	pskin = Hunk_AllocName(skinsize * r_pixbytes, loadname);
+	pinskin = (uchar *)pin;
+	*pskinindex = (uchar *)pskin - (uchar *)pheader;
 
-	if (r_pixbytes == 1)
-	{
-		Q_memcpy (pskin, pinskin, skinsize);
-	}
-	else if (r_pixbytes == 2)
-	{
-		pusskin = (unsigned short *)pskin;
-
-		for (i=0 ; i<skinsize ; i++)
+	if(r_pixbytes == 1)
+		memcpy(pskin, pinskin, skinsize);
+	else if(r_pixbytes == 2){
+		pusskin = (ushort *)pskin;
+		for(i=0; i<skinsize; i++)
 			pusskin[i] = d_8to16table[pinskin[i]];
-	}
-	else
-	{
-		Sys_Error ("Mod_LoadAliasSkin: driver set invalid r_pixbytes: %d\n",
-				 r_pixbytes);
-	}
+	}else
+		Sys_Error("Mod_LoadAliasSkin: invalid r_pixbytes: %d\n", r_pixbytes);
 
 	pinskin += skinsize;
 
-	return ((void *)pinskin);
+	return (void *)pinskin;
 }
 
 
@@ -1379,9 +1361,8 @@
 
 	numskins = LittleLong (pinskingroup->numskins);
 
-	paliasskingroup = Hunk_AllocName (sizeof (maliasskingroup_t) +
-			(numskins - 1) * sizeof (paliasskingroup->skindescs[0]),
-			loadname);
+	paliasskingroup = Hunk_AllocName(sizeof(*paliasskingroup) +
+		(numskins - 1) * sizeof paliasskingroup->skindescs[0], loadname);
 
 	paliasskingroup->numskins = numskins;
 
@@ -1389,7 +1370,8 @@
 
 	pinskinintervals = (daliasskininterval_t *)(pinskingroup + 1);
 
-	poutskinintervals = Hunk_AllocName (numskins * sizeof (float),loadname);
+	poutskinintervals = Hunk_AllocName(numskins * sizeof *poutskinintervals,
+		loadname);
 
 	paliasskingroup->intervals = (byte *)poutskinintervals - (byte *)pheader;
 
@@ -1455,7 +1437,7 @@
 			LittleLong (pinmodel->numverts) * sizeof (stvert_t) +
 			LittleLong (pinmodel->numtris) * sizeof (mtriangle_t);
 
-	pheader = Hunk_AllocName (size, loadname);
+	pheader = Hunk_AllocName(size, loadname);
 	pmodel = (mdl_t *) ((byte *)&pheader[1] +
 			(LittleLong (pinmodel->numframes) - 1) *
 			 sizeof (pheader->frames[0]));
@@ -1518,8 +1500,7 @@
 
 	pskintype = (daliasskintype_t *)&pinmodel[1];
 
-	pskindesc = Hunk_AllocName (numskins * sizeof (maliasskindesc_t),
-								loadname);
+	pskindesc = Hunk_AllocName(numskins * sizeof *pskindesc, loadname);
 
 	pheader->skindesc = (byte *)pskindesc - (byte *)pheader;
 
@@ -1635,36 +1616,29 @@
 	Cache_Alloc (&mod->cache, total, loadname);
 	if (!mod->cache.data)
 		return;
-	memcpy (mod->cache.data, pheader, total);
+	memcpy(mod->cache.data, pheader, total);
 
 	Hunk_FreeToLowMark (start);
 }
 
-//=============================================================================
-
-/*
-=================
-Mod_LoadSpriteFrame
-=================
-*/
-void * Mod_LoadSpriteFrame (void * pin, mspriteframe_t **ppframe)
+void *
+Mod_LoadSpriteFrame(void * pin, mspriteframe_t **ppframe)
 {
-	dspriteframe_t		*pinframe;
-	mspriteframe_t		*pspriteframe;
-	int					i, width, height, size, origin[2];
-	unsigned short		*ppixout;
-	byte				*ppixin;
+	int i, width, height, size, origin[2];
+	ushort *ppixout;
+	uchar *ppixin;
+	dspriteframe_t *pinframe;
+	mspriteframe_t *pspriteframe;
 
 	pinframe = (dspriteframe_t *)pin;
 
-	width = LittleLong (pinframe->width);
-	height = LittleLong (pinframe->height);
+	width = LittleLong(pinframe->width);
+	height = LittleLong(pinframe->height);
 	size = width * height;
 
-	pspriteframe = Hunk_AllocName (sizeof (mspriteframe_t) + size*r_pixbytes,
-								   loadname);
+	pspriteframe = Hunk_AllocName(size*r_pixbytes + sizeof *pspriteframe, loadname);
 
-	Q_memset (pspriteframe, 0, sizeof (mspriteframe_t) + size);
+	memset(pspriteframe, 0, size + sizeof *pspriteframe);
 	*ppframe = pspriteframe;
 
 	pspriteframe->width = width;
@@ -1677,25 +1651,18 @@
 	pspriteframe->left = origin[0];
 	pspriteframe->right = width + origin[0];
 
-	if (r_pixbytes == 1)
-	{
-		Q_memcpy (&pspriteframe->pixels[0], (byte *)(pinframe + 1), size);
-	}
-	else if (r_pixbytes == 2)
-	{
-		ppixin = (byte *)(pinframe + 1);
-		ppixout = (unsigned short *)&pspriteframe->pixels[0];
+	if(r_pixbytes == 1)
+		memcpy(&pspriteframe->pixels[0], (uchar *)(pinframe + 1), size);
+	else if(r_pixbytes == 2){
+		ppixin = (uchar *)(pinframe + 1);
+		ppixout = (ushort *)&pspriteframe->pixels[0];
 
-		for (i=0 ; i<size ; i++)
+		for(i=0 ; i<size ; i++)
 			ppixout[i] = d_8to16table[ppixin[i]];
-	}
-	else
-	{
-		Sys_Error ("Mod_LoadSpriteFrame: driver set invalid r_pixbytes: %d\n",
-				 r_pixbytes);
-	}
+	}else
+		Sys_Error("Mod_LoadSpriteFrame: invalid r_pixbytes: %d\n", r_pixbytes);
 
-	return (void *)((byte *)pinframe + sizeof (dspriteframe_t) + size);
+	return (void *)((byte *)pinframe + size + sizeof *pinframe);
 }
 
 
@@ -1717,8 +1684,8 @@
 
 	numframes = LittleLong (pingroup->numframes);
 
-	pspritegroup = Hunk_AllocName (sizeof (mspritegroup_t) +
-				(numframes - 1) * sizeof (pspritegroup->frames[0]), loadname);
+	pspritegroup = Hunk_AllocName(sizeof(*pspritegroup) +
+		(numframes - 1) * sizeof pspritegroup->frames[0], loadname);
 
 	pspritegroup->numframes = numframes;
 
@@ -1726,7 +1693,7 @@
 
 	pin_intervals = (dspriteinterval_t *)(pingroup + 1);
 
-	poutintervals = Hunk_AllocName (numframes * sizeof (float), loadname);
+	poutintervals = Hunk_AllocName(numframes * sizeof *poutintervals, loadname);
 
 	pspritegroup->intervals = poutintervals;
 
@@ -1777,7 +1744,7 @@
 
 	size = sizeof (msprite_t) +	(numframes - 1) * sizeof (psprite->frames);
 
-	psprite = Hunk_AllocName (size, loadname);
+	psprite = Hunk_AllocName(size, loadname);
 
 	mod->cache.data = psprite;
 
--- a/model.h
+++ b/model.h
@@ -1,5 +1,4 @@
-#ifndef __MODEL__
-#define __MODEL__
+typedef enum {ST_SYNC, ST_RAND} synctype_t;
 
 #include "modelgen.h"
 #include "spritegn.h"
@@ -358,5 +357,3 @@
 
 mleaf_t *Mod_PointInLeaf (float *p, model_t *model);
 byte	*Mod_LeafPVS (mleaf_t *leaf, model_t *model);
-
-#endif	// __MODEL__
--- a/modelgen.h
+++ b/modelgen.h
@@ -1,28 +1,13 @@
-//
 // modelgen.h: header file for model generation program
-//
 
-// *********************************************************
-// * This file must be identical in the modelgen directory *
-// * and in the Quake directory, because it's used to      *
-// * pass data from one to the other via model files.      *
-// *********************************************************
-
 #define ALIAS_VERSION	6
 
-/* defined in r_shared.h */
-//#define ALIAS_ONSEAM				0x0020
-
-// must match definition in spritegn.h
-#ifndef SYNCTYPE_T
-#define SYNCTYPE_T
-typedef enum {ST_SYNC=0, ST_RAND } synctype_t;
-#endif
-
 typedef enum { ALIAS_SINGLE=0, ALIAS_GROUP } aliasframetype_t;
 
 typedef enum { ALIAS_SKIN_SINGLE=0, ALIAS_SKIN_GROUP } aliasskintype_t;
 
+#pragma pack on
+
 typedef struct {
 	int			ident;
 	int			version;
@@ -99,3 +84,4 @@
 #define IDPOLYHEADER	(('O'<<24)+('P'<<16)+('D'<<8)+'I')
 														// little-endian "IDPO"
 
+#pragma pack off
--- a/net.h
+++ b/net.h
@@ -343,24 +343,6 @@
 void		Loop_Close (qsocket_t *sock);
 void		Loop_Shutdown (void);
 
-/* vcr */
-#define VCR_OP_CONNECT		1
-#define VCR_OP_GETMESSAGE	2
-#define VCR_OP_SENDMESSAGE	3
-#define VCR_OP_CANSENDMESSAGE	4
-#define VCR_MAX_MESSAGE		4
-
-int			VCR_Init (void);
-void		VCR_Listen (qboolean state);
-void		VCR_SearchForHosts (qboolean xmit);
-qsocket_t 	*VCR_Connect (char *host);
-qsocket_t 	*VCR_CheckNewConnections (void);
-int			VCR_GetMessage (qsocket_t *sock);
-int			VCR_SendMessage (qsocket_t *sock, sizebuf_t *data);
-qboolean	VCR_CanSendMessage (qsocket_t *sock);
-void		VCR_Close (qsocket_t *sock);
-void		VCR_Shutdown (void);
-
 /* udp */
 int  UDP_Init (void);
 void UDP_Shutdown (void);
--- a/net_dgrm.c
+++ b/net_dgrm.c
@@ -104,8 +104,8 @@
 		case 1:
 			if (((struct in_addr *)&banAddr)->s_addr)
 			{
-				Q_strcpy(addrStr, inet_ntoa(*(struct in_addr *)&banAddr));
-				Q_strcpy(maskStr, inet_ntoa(*(struct in_addr *)&banMask));
+				strcpy(addrStr, inet_ntoa(*(struct in_addr *)&banAddr));
+				strcpy(maskStr, inet_ntoa(*(struct in_addr *)&banMask));
 				print("Banning %s [%s]\n", addrStr, maskStr);
 			}
 			else
@@ -113,7 +113,7 @@
 			break;
 
 		case 2:
-			if (Q_strcasecmp(Cmd_Argv(1), "off") == 0)
+			if(cistrcmp(Cmd_Argv(1), "off") == 0)
 				banAddr = 0x00000000;
 			else
 				banAddr = inet_addr(Cmd_Argv(1));
@@ -150,7 +150,7 @@
 		Sys_Error("SendMessage: called with canSend == false\n");
 #endif
 
-	Q_memcpy(sock->sendMessage, data->data, data->cursize);
+	memcpy(sock->sendMessage, data->data, data->cursize);
 	sock->sendMessageLength = data->cursize;
 
 	if (data->cursize <= MAX_DATAGRAM)
@@ -167,7 +167,7 @@
 
 	packetBuffer.length = BigLong(packetLen | (NETFLAG_DATA | eom));
 	packetBuffer.sequence = BigLong(sock->sendSequence++);
-	Q_memcpy (packetBuffer.data, sock->sendMessage, dataLen);
+	memcpy(packetBuffer.data, sock->sendMessage, dataLen);
 
 	sock->canSend = false;
 
@@ -200,7 +200,7 @@
 
 	packetBuffer.length = BigLong(packetLen | (NETFLAG_DATA | eom));
 	packetBuffer.sequence = BigLong(sock->sendSequence++);
-	Q_memcpy (packetBuffer.data, sock->sendMessage, dataLen);
+	memcpy(packetBuffer.data, sock->sendMessage, dataLen);
 
 	sock->sendNext = false;
 
@@ -233,7 +233,7 @@
 
 	packetBuffer.length = BigLong(packetLen | (NETFLAG_DATA | eom));
 	packetBuffer.sequence = BigLong(sock->sendSequence - 1);
-	Q_memcpy (packetBuffer.data, sock->sendMessage, dataLen);
+	memcpy(packetBuffer.data, sock->sendMessage, dataLen);
 
 	sock->sendNext = false;
 
@@ -277,7 +277,7 @@
 
 	packetBuffer.length = BigLong(packetLen | NETFLAG_UNRELIABLE);
 	packetBuffer.sequence = BigLong(sock->unreliableSendSequence++);
-	Q_memcpy (packetBuffer.data, data->data, data->cursize);
+	memcpy(packetBuffer.data, data->data, data->cursize);
 
 	if (sfunc.Write (sock->socket, (byte *)&packetBuffer, packetLen, &sock->addr) == -1)
 		return -1;
@@ -388,7 +388,7 @@
 			sock->sendMessageLength -= MAX_DATAGRAM;
 			if (sock->sendMessageLength > 0)
 			{
-				Q_memcpy(sock->sendMessage, sock->sendMessage+MAX_DATAGRAM, sock->sendMessageLength);
+				memcpy(sock->sendMessage, sock->sendMessage+MAX_DATAGRAM, sock->sendMessageLength);
 				sock->sendNext = true;
 			}
 			else
@@ -425,7 +425,7 @@
 				break;
 			}
 
-			Q_memcpy(sock->receiveMessage + sock->receiveMessageLength, packetBuffer.data, length);
+			memcpy(sock->receiveMessage + sock->receiveMessageLength, packetBuffer.data, length);
 			sock->receiveMessageLength += length;
 			continue;
 		}
@@ -463,7 +463,7 @@
 		Con_Printf("shortPacketCount           = %d\n", shortPacketCount);
 		Con_Printf("droppedDatagrams           = %d\n", droppedDatagrams);
 	}
-	else if (Q_strcmp(Cmd_Argv(1), "*") == 0)
+	else if(strcmp(Cmd_Argv(1), "*") == 0)
 	{
 		for (s = net_activeSockets; s; s = s->next)
 			PrintStats(s);
@@ -473,11 +473,11 @@
 	else
 	{
 		for (s = net_activeSockets; s; s = s->next)
-			if (Q_strcasecmp(Cmd_Argv(1), s->address) == 0)
+			if(cistrcmp(Cmd_Argv(1), s->address) == 0)
 				break;
 		if (s == nil)
 			for (s = net_freeSockets; s; s = s->next)
-				if (Q_strcasecmp(Cmd_Argv(1), s->address) == 0)
+				if(cistrcmp(Cmd_Argv(1), s->address) == 0)
 					break;
 		if (s == nil)
 			return;
@@ -529,11 +529,11 @@
 			Sys_Error("Unexpected repsonse to Player Info request\n");
 
 		MSG_ReadByte();	/* playerNumber */
-		Q_strcpy(name, MSG_ReadString());
+		strcpy(name, MSG_ReadString());
 		colors = MSG_ReadLong();
 		frags = MSG_ReadLong();
 		connectTime = MSG_ReadLong();
-		Q_strcpy(address, MSG_ReadString());
+		strcpy(address, MSG_ReadString());
 
 		Con_Printf("%s\n  frags:%3d  colors:%ud %ud  time:%ud\n  %s\n", name, frags, colors >> 4, colors & 0x0f, connectTime / 60, address);
 	}
@@ -565,13 +565,13 @@
 	if (host && hostCacheCount)
 	{
 		for (n = 0; n < hostCacheCount; n++)
-			if (Q_strcasecmp (host, hostcache[n].name) == 0)
+			if(cistrcmp(host, hostcache[n].name) == 0)
 			{
 				if (hostcache[n].driver != myDriverLevel)
 					continue;
 				net_landriverlevel = hostcache[n].ldriver;
 				max = hostcache[n].maxusers;
-				Q_memcpy(&sendaddr, &hostcache[n].addr, sizeof(struct qsockaddr));
+				memcpy(&sendaddr, &hostcache[n].addr, sizeof sendaddr);
 				break;
 			}
 		if (n < hostCacheCount)
@@ -651,10 +651,10 @@
 	if (MSG_ReadByte() != CCREP_RULE_INFO)
 		goto Error;
 
-	Q_strcpy(name, MSG_ReadString());
+	strcpy(name, MSG_ReadString());
 	if (name[0] == 0)
 		goto Done;
-	Q_strcpy(value, MSG_ReadString());
+	strcpy(value, MSG_ReadString());
 
 	Con_Printf("%-16.16s  %-16.16s\n", name, value);
 
@@ -693,12 +693,12 @@
 	if (host && hostCacheCount)
 	{
 		for (n = 0; n < hostCacheCount; n++)
-			if (Q_strcasecmp (host, hostcache[n].name) == 0)
+			if(cistrcmp(host, hostcache[n].name) == 0)
 			{
 				if (hostcache[n].driver != myDriverLevel)
 					continue;
 				net_landriverlevel = hostcache[n].ldriver;
-				Q_memcpy(&sendaddr, &hostcache[n].addr, sizeof(struct qsockaddr));
+				memcpy(&sendaddr, &hostcache[n].addr, sizeof sendaddr);
 				break;
 			}
 		if (n < hostCacheCount)
@@ -838,7 +838,7 @@
 	command = MSG_ReadByte();
 	if (command == CCREQ_SERVER_INFO)
 	{
-		if (Q_strcmp(MSG_ReadString(), "QUAKE") != 0)
+		if(strcmp(MSG_ReadString(), "QUAKE") != 0)
 			return nil;
 
 		SZ_Clear(&net_message);
@@ -942,7 +942,7 @@
 	if (command != CCREQ_CONNECT)
 		return nil;
 
-	if (Q_strcmp(MSG_ReadString(), "QUAKE") != 0)
+	if(strcmp(MSG_ReadString(), "QUAKE") != 0)
 		return nil;
 
 	if (MSG_ReadByte() != NET_PROTOCOL_VERSION)
@@ -1045,7 +1045,7 @@
 	sock->socket = newsock;
 	sock->landriver = net_landriverlevel;
 	sock->addr = clientaddr;
-	Q_strcpy(sock->address, dfunc.AddrToString(&clientaddr));
+	strcpy(sock->address, dfunc.AddrToString(&clientaddr));
 
 	// send him back the info about the server connection he has been allocated
 	SZ_Clear(&net_message);
@@ -1136,21 +1136,21 @@
 
 		// add it
 		hostCacheCount++;
-		Q_strcpy(hostcache[n].name, MSG_ReadString());
-		Q_strcpy(hostcache[n].map, MSG_ReadString());
+		strcpy(hostcache[n].name, MSG_ReadString());
+		strcpy(hostcache[n].map, MSG_ReadString());
 		hostcache[n].users = MSG_ReadByte();
 		hostcache[n].maxusers = MSG_ReadByte();
 		if (MSG_ReadByte() != NET_PROTOCOL_VERSION)
 		{
-			Q_strcpy(hostcache[n].cname, hostcache[n].name);
+			strcpy(hostcache[n].cname, hostcache[n].name);
 			hostcache[n].cname[14] = 0;
-			Q_strcpy(hostcache[n].name, "*");
-			Q_strcat(hostcache[n].name, hostcache[n].cname);
+			strcpy(hostcache[n].name, "*");
+			strcat(hostcache[n].name, hostcache[n].cname);
 		}
-		Q_memcpy(&hostcache[n].addr, &readaddr, sizeof(struct qsockaddr));
+		memcpy(&hostcache[n].addr, &readaddr, sizeof readaddr);
 		hostcache[n].driver = net_driverlevel;
 		hostcache[n].ldriver = net_landriverlevel;
-		Q_strcpy(hostcache[n].cname, dfunc.AddrToString(&readaddr));
+		strcpy(hostcache[n].cname, dfunc.AddrToString(&readaddr));
 
 		// check for a name conflict
 		for (i = 0; i < hostCacheCount; i++)
@@ -1157,9 +1157,9 @@
 		{
 			if (i == n)
 				continue;
-			if (Q_strcasecmp (hostcache[n].name, hostcache[i].name) == 0)
+			if(cistrcmp(hostcache[n].name, hostcache[i].name) == 0)
 			{
-				i = Q_strlen(hostcache[n].name);
+				i = strlen(hostcache[n].name);
 				if (i < 15 && hostcache[n].name[i-1] > '8')
 				{
 					hostcache[n].name[i] = '0';
@@ -1288,7 +1288,7 @@
 	{
 		reason = "No Response";
 		Con_Printf("%s\n", reason);
-		Q_strcpy(m_return_reason, reason);
+		strcpy(m_return_reason, reason);
 		goto ErrorReturn;
 	}
 
@@ -1296,7 +1296,7 @@
 	{
 		reason = "Network Error";
 		Con_Printf("%s\n", reason);
-		Q_strcpy(m_return_reason, reason);
+		strcpy(m_return_reason, reason);
 		goto ErrorReturn;
 	}
 
@@ -1305,13 +1305,13 @@
 	{
 		reason = MSG_ReadString();
 		Con_Printf(reason);
-		Q_strncpy(m_return_reason, reason, 31);
+		strncpy(m_return_reason, reason, 31);
 		goto ErrorReturn;
 	}
 
 	if (ret == CCREP_ACCEPT)
 	{
-		Q_memcpy(&sock->addr, &sendaddr, sizeof(struct qsockaddr));
+		memcpy(&sock->addr, &sendaddr, sizeof sendaddr);
 		dfunc.SetSocketPort (&sock->addr, MSG_ReadLong());
 	}
 	else
@@ -1318,7 +1318,7 @@
 	{
 		reason = "Bad Response";
 		Con_Printf("%s\n", reason);
-		Q_strcpy(m_return_reason, reason);
+		strcpy(m_return_reason, reason);
 		goto ErrorReturn;
 	}
 
@@ -1332,7 +1332,7 @@
 	{
 		reason = "Connect to Game failed";
 		Con_Printf("%s\n", reason);
-		Q_strcpy(m_return_reason, reason);
+		strcpy(m_return_reason, reason);
 		goto ErrorReturn;
 	}
 
--- a/net_loop.c
+++ b/net_loop.c
@@ -31,21 +31,21 @@
 		return;
 
 	hostCacheCount = 1;
-	if (Q_strcmp(hostname.string, "UNNAMED") == 0)
-		Q_strcpy(hostcache[0].name, "local");
+	if(strcmp(hostname.string, "UNNAMED") == 0)
+		strcpy(hostcache[0].name, "local");
 	else
-		Q_strcpy(hostcache[0].name, hostname.string);
-	Q_strcpy(hostcache[0].map, sv.name);
+		strcpy(hostcache[0].name, hostname.string);
+	strcpy(hostcache[0].map, sv.name);
 	hostcache[0].users = net_activeconnections;
 	hostcache[0].maxusers = svs.maxclients;
 	hostcache[0].driver = net_driverlevel;
-	Q_strcpy(hostcache[0].cname, "local");
+	strcpy(hostcache[0].cname, "local");
 }
 
 
 qsocket_t *Loop_Connect (char *host)
 {
-	if (Q_strcmp(host,"local") != 0)
+	if(strcmp(host, "local") != 0)
 		return nil;
 	
 	localconnectpending = true;
@@ -57,7 +57,7 @@
 			Con_Printf("Loop_Connect: no qsocket available\n");
 			return nil;
 		}
-		Q_strcpy (loop_client->address, "localhost");
+		strcpy(loop_client->address, "localhost");
 	}
 	loop_client->receiveMessageLength = 0;
 	loop_client->sendMessageLength = 0;
@@ -70,7 +70,7 @@
 			Con_Printf("Loop_Connect: no qsocket available\n");
 			return nil;
 		}
-		Q_strcpy (loop_server->address, "LOCAL");
+		strcpy(loop_server->address, "LOCAL");
 	}
 	loop_server->receiveMessageLength = 0;
 	loop_server->sendMessageLength = 0;
@@ -123,7 +123,7 @@
 	sock->receiveMessageLength -= length;
 
 	if (sock->receiveMessageLength)
-		Q_memcpy(sock->receiveMessage, &sock->receiveMessage[length], sock->receiveMessageLength);
+		memcpy(sock->receiveMessage, &sock->receiveMessage[length], sock->receiveMessageLength);
 
 	if (sock->driverdata && ret == 1)
 		((qsocket_t *)sock->driverdata)->canSend = true;
@@ -158,7 +158,7 @@
 	buffer++;
 
 	// message
-	Q_memcpy(buffer, data->data, data->cursize);
+	memcpy(buffer, data->data, data->cursize);
 	*bufferLength = IntAlign(*bufferLength + data->cursize + 4);
 
 	sock->canSend = false;
@@ -192,7 +192,7 @@
 	buffer++;
 
 	// message
-	Q_memcpy(buffer, data->data, data->cursize);
+	memcpy(buffer, data->data, data->cursize);
 	*bufferLength = IntAlign(*bufferLength + data->cursize + 4);
 	return 1;
 }
--- a/net_main.c
+++ b/net_main.c
@@ -61,9 +61,6 @@
 cvar_t	idgods = {"idgods", "0"};
 #endif
 
-int	vcrFile = -1;
-qboolean recording = false;
-
 // these two macros are to make the code more readable
 #define sfunc	net_drivers[sock->driver]
 #define dfunc	net_drivers[net_driverlevel]
@@ -108,7 +105,7 @@
 
 	sock->disconnected = false;
 	sock->connecttime = net_time;
-	Q_strcpy (sock->address,"UNSET ADDRESS");
+	strcpy(sock->address,"UNSET ADDRESS");
 	sock->driver = net_driverlevel;
 	sock->socket = 0;
 	sock->driverdata = nil;
@@ -161,7 +158,7 @@
 		return;
 	}
 
-	listening = Q_atoi(Cmd_Argv(1)) ? true : false;
+	listening = atoi(Cmd_Argv(1)) ? true : false;
 
 	for (net_driverlevel=0 ; net_driverlevel<net_numdrivers; net_driverlevel++)
 	{
@@ -188,7 +185,7 @@
 		return;
 	}
 
-	n = Q_atoi(Cmd_Argv(1));
+	n = atoi(Cmd_Argv(1));
 	if (n < 1)
 		n = 1;
 	if (n > svs.maxclientslimit)
@@ -221,7 +218,7 @@
 		return;
 	}
 
-	n = Q_atoi(Cmd_Argv(1));
+	n = atoi(Cmd_Argv(1));
 	if (n < 1 || n > 65534)
 	{
 		Con_Printf ("Bad value, must be between 1 and 65534\n");
@@ -359,7 +356,7 @@
 
 	if (host)
 	{
-		if (Q_strcasecmp (host, "local") == 0)
+		if(cistrcmp(host, "local") == 0)
 		{
 			numdrivers = 1;
 			goto JustDoIt;
@@ -368,7 +365,7 @@
 		if (hostCacheCount)
 		{
 			for (n = 0; n < hostCacheCount; n++)
-				if (Q_strcasecmp (host, hostcache[n].name) == 0)
+				if(cistrcmp(host, hostcache[n].name) == 0)
 				{
 					host = hostcache[n].cname;
 					break;
@@ -394,7 +391,7 @@
 
 	if (hostCacheCount)
 		for (n = 0; n < hostCacheCount; n++)
-			if (Q_strcasecmp (host, hostcache[n].name) == 0)
+			if(cistrcmp(host, hostcache[n].name) == 0)
 			{
 				host = hostcache[n].cname;
 				break;
@@ -421,20 +418,6 @@
 	return nil;
 }
 
-
-/*
-===================
-NET_CheckNewConnections
-===================
-*/
-
-struct
-{
-	double	time;
-	int		op;
-	int	session;
-} vcrConnect;
-
 qsocket_t *NET_CheckNewConnections (void)
 {
 	qsocket_t	*ret;
@@ -448,27 +431,9 @@
 		if (net_driverlevel && listening == false)
 			continue;
 		ret = dfunc.CheckNewConnections ();
-		if (ret)
-		{
-			if (recording)
-			{
-				vcrConnect.time = host_time;
-				vcrConnect.op = VCR_OP_CONNECT;
-				vcrConnect.session = (uintptr)ret;
-				Sys_FileWrite (vcrFile, &vcrConnect, sizeof(vcrConnect));
-				Sys_FileWrite (vcrFile, ret->address, NET_NAMELEN);
-			}
+		if(ret)
 			return ret;
-		}
 	}
-	
-	if (recording)
-	{
-		vcrConnect.time = host_time;
-		vcrConnect.op = VCR_OP_CONNECT;
-		vcrConnect.session = 0;
-		Sys_FileWrite (vcrFile, &vcrConnect, sizeof(vcrConnect));
-	}
 
 	return nil;
 }
@@ -507,16 +472,6 @@
 =================
 */
 
-struct
-{
-	double	time;
-	int		op;
-	/* FIXME: different size -> vcr problems? */
-	uintptr	session;
-	int		ret;
-	int		len;
-} vcrGetMessage;
-
 extern void PrintStats(qsocket_t *s);
 
 int	NET_GetMessage (qsocket_t *sock)
@@ -557,29 +512,7 @@
 			else if (ret == 2)
 				unreliableMessagesReceived++;
 		}
-
-		if (recording)
-		{
-			vcrGetMessage.time = host_time;
-			vcrGetMessage.op = VCR_OP_GETMESSAGE;
-			vcrGetMessage.session = (uintptr)sock;
-			vcrGetMessage.ret = ret;
-			vcrGetMessage.len = net_message.cursize;
-			Sys_FileWrite (vcrFile, &vcrGetMessage, 24);
-			Sys_FileWrite (vcrFile, net_message.data, net_message.cursize);
-		}
 	}
-	else
-	{
-		if (recording)
-		{
-			vcrGetMessage.time = host_time;
-			vcrGetMessage.op = VCR_OP_GETMESSAGE;
-			vcrGetMessage.session = (uintptr)sock;
-			vcrGetMessage.ret = ret;
-			Sys_FileWrite (vcrFile, &vcrGetMessage, 20);
-		}
-	}
 
 	return ret;
 }
@@ -596,14 +529,6 @@
 returns -1 if the connection died
 ==================
 */
-struct
-{
-	double	time;
-	int		op;
-	/* FIXME: different size -> vcr problems? */
-	uintptr	session;
-	int		r;
-} vcrSendMessage;
 
 int NET_SendMessage (qsocket_t *sock, sizebuf_t *data)
 {
@@ -623,15 +548,6 @@
 	if (r == 1 && sock->driver)
 		messagesSent++;
 
-	if (recording)
-	{
-		vcrSendMessage.time = host_time;
-		vcrSendMessage.op = VCR_OP_SENDMESSAGE;
-		vcrSendMessage.session = (uintptr)sock;
-		vcrSendMessage.r = r;
-		Sys_FileWrite (vcrFile, &vcrSendMessage, 20);
-	}
-	
 	return r;
 }
 
@@ -653,15 +569,6 @@
 	r = sfunc.SendUnreliableMessage(sock, data);
 	if (r == 1 && sock->driver)
 		unreliableMessagesSent++;
-
-	if (recording)
-	{
-		vcrSendMessage.time = host_time;
-		vcrSendMessage.op = VCR_OP_SENDMESSAGE;
-		vcrSendMessage.session = (uintptr)sock;
-		vcrSendMessage.r = r;
-		Sys_FileWrite (vcrFile, &vcrSendMessage, 20);
-	}
 	
 	return r;
 }
@@ -688,16 +595,7 @@
 	SetNetTime();
 
 	r = sfunc.CanSendMessage(sock);
-	
-	if (recording)
-	{
-		vcrSendMessage.time = host_time;
-		vcrSendMessage.op = VCR_OP_CANSENDMESSAGE;
-		vcrSendMessage.session = (uintptr)sock;
-		vcrSendMessage.r = r;
-		Sys_FileWrite (vcrFile, &vcrSendMessage, 20);
-	}
-	
+
 	return r;
 }
 
@@ -790,15 +688,6 @@
 	int			controlSocket;
 	qsocket_t	*s;
 
-	if (COM_CheckParm("-playback"))
-	{
-		net_numdrivers = 1;
-		net_drivers[0].Init = VCR_Init;
-	}
-
-	if (COM_CheckParm("-record"))
-		recording = true;
-
 	i = COM_CheckParm ("-port");
 	if (!i)
 		i = COM_CheckParm ("-udpport");
@@ -808,7 +697,7 @@
 	if (i)
 	{
 		if (i < com_argc-1)
-			DEFAULTnet_hostport = Q_atoi (com_argv[i+1]);
+			DEFAULTnet_hostport = atoi(com_argv[i+1]);
 		else
 			Sys_Error ("NET_Init: you must specify a number after -port");
 	}
@@ -824,7 +713,7 @@
 
 	for (i = 0; i < net_numsockets; i++)
 	{
-		s = (qsocket_t *)Hunk_AllocName(sizeof(qsocket_t), "qsocket");
+		s = Hunk_AllocName(sizeof *s, "qsocket");
 		s->next = net_freeSockets;
 		net_freeSockets = s;
 		s->disconnected = true;
@@ -895,12 +784,6 @@
 			net_drivers[net_driverlevel].Shutdown ();
 			net_drivers[net_driverlevel].initialized = false;
 		}
-	}
-
-	if (vcrFile != -1)
-	{
-		Con_Printf ("Closing vcrfile.\n");
-		Sys_FileClose(vcrFile);
 	}
 }
 
--- a/net_udp.c
+++ b/net_udp.c
@@ -19,6 +19,9 @@
 static u32int myAddr;
 */
 
+int net_controlsocket;
+
+
 int UDP_Init (void)
 {
 	/*
@@ -35,7 +38,7 @@
 	myAddr = *(int *)local->h_addr_list[0];
 
 	// if the quake hostname isn't set, set it to the machine name
-	if (Q_strcmp(hostname.string, "UNNAMED") == 0)
+	if(strcmp(hostname.string, "UNNAMED") == 0)
 	{
 		buff[15] = 0;
 		Cvar_Set ("hostname", buff);
@@ -49,8 +52,8 @@
 	((struct sockaddr_in *)&broadcastaddr)->sin_port = htons(net_hostport);
 
 	UDP_GetSocketAddr (net_controlsocket, &addr);
-	Q_strcpy(my_tcpip_address,  UDP_AddrToString (&addr));
-	colon = Q_strrchr (my_tcpip_address, ':');
+	strcpy(my_tcpip_address, UDP_AddrToString(&addr));
+	colon = strrchr(my_tcpip_address, ':');
 	if (colon)
 		*colon = 0;
 
@@ -64,10 +67,8 @@
 
 void UDP_Shutdown (void)
 {
-	/*
-	UDP_Listen (false);
-	UDP_CloseSocket (net_controlsocket);
-	*/
+	UDP_Listen(false);
+	UDP_CloseSocket(net_controlsocket);
 }
 
 void UDP_Listen (qboolean /*state*/)
@@ -176,7 +177,7 @@
 	}
 	
 	if (*b++ == ':')
-		port = Q_atoi(b);
+		port = atoi(b);
 	else
 		port = net_hostport;
 
@@ -311,7 +312,7 @@
 	int addrlen = sizeof(struct qsockaddr);
 	unsigned int a;
 
-	Q_memset(addr, 0, sizeof(struct qsockaddr));
+	memset(addr, 0, sizeof(struct qsockaddr));
 	getsockname(socket, (struct sockaddr *)addr, &addrlen);
 	a = ((struct sockaddr_in *)addr)->sin_addr.s_addr;
 	if (a == 0 || a == inet_addr("127.0.0.1"))
@@ -330,11 +331,11 @@
 	hostentry = gethostbyaddr ((char *)&((struct sockaddr_in *)addr)->sin_addr, sizeof(struct in_addr), AF_INET);
 	if (hostentry)
 	{
-		Q_strncpy (name, (char *)hostentry->h_name, NET_NAMELEN - 1);
+		strncpy(name, (char *)hostentry->h_name, NET_NAMELEN - 1);
 		return 0;
 	}
 
-	Q_strcpy (name, UDP_AddrToString (addr));
+	strcpy(name, UDP_AddrToString (addr));
 	return 0;
 	*/
 	return -1;
--- a/net_vcr.c
+++ /dev/null
@@ -1,148 +1,0 @@
-#include <u.h>
-#include <libc.h>
-#include <stdio.h>
-#include "quakedef.h"
-
-extern int vcrFile;
-
-// This is the playback portion of the VCR.  It reads the file produced
-// by the recorder and plays it back to the host.  The recording contains
-// everything necessary (events, timestamps, and data) to duplicate the game
-// from the viewpoint of everything above the network layer.
-
-static struct
-{
-	double	time;
-	int		op;
-	int	session;
-}	next;
-
-int VCR_Init (void)
-{
-	net_drivers[0].Init = VCR_Init;
-
-	net_drivers[0].SearchForHosts = VCR_SearchForHosts;
-	net_drivers[0].Connect = VCR_Connect;
-	net_drivers[0].CheckNewConnections = VCR_CheckNewConnections;
-	net_drivers[0].QGetMessage = VCR_GetMessage;
-	net_drivers[0].QSendMessage = VCR_SendMessage;
-	net_drivers[0].CanSendMessage = VCR_CanSendMessage;
-	net_drivers[0].Close = VCR_Close;
-	net_drivers[0].Shutdown = VCR_Shutdown;
-
-	Sys_FileRead(vcrFile, &next, sizeof(next));
-	return 0;
-}
-
-void VCR_ReadNext (void)
-{
-	if (Sys_FileRead(vcrFile, &next, sizeof(next)) == 0)
-	{
-		next.op = 255;
-		Sys_Error ("=== END OF PLAYBACK===\n");
-	}
-	if (next.op < 1 || next.op > VCR_MAX_MESSAGE)
-		Sys_Error ("VCR_ReadNext: bad op");
-}
-
-
-void VCR_Listen (qboolean) /*state*/
-{
-}
-
-
-void VCR_Shutdown (void)
-{
-}
-
-
-int VCR_GetMessage (qsocket_t *sock)
-{
-	int	ret;
-	
-	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));
-	if (ret != 1)
-	{
-		VCR_ReadNext ();
-		return ret;
-	}
-
-	Sys_FileRead(vcrFile, &net_message.cursize, sizeof(int));
-	Sys_FileRead(vcrFile, net_message.data, net_message.cursize);
-
-	VCR_ReadNext ();
-
-	return 1;
-}
-
-
-int VCR_SendMessage (qsocket_t *sock, sizebuf_t *) /*data*/
-{
-	int	ret;
-
-	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));
-
-	VCR_ReadNext ();
-
-	return ret;
-}
-
-
-qboolean VCR_CanSendMessage (qsocket_t *sock)
-{
-	qboolean	ret;
-
-	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));
-
-	VCR_ReadNext ();
-
-	return ret;
-}
-
-
-void VCR_Close (qsocket_t *) /*sock*/
-{
-}
-
-
-void VCR_SearchForHosts (qboolean) /*xmit*/
-{
-}
-
-
-qsocket_t *VCR_Connect (char *) /*host*/
-{
-	return nil;
-}
-
-
-qsocket_t *VCR_CheckNewConnections (void)
-{
-	qsocket_t	*sock;
-
-	if (host_time != next.time || next.op != VCR_OP_CONNECT)
-		Sys_Error ("VCR missmatch");
-
-	if (!next.session)
-	{
-		VCR_ReadNext ();
-		return nil;
-	}
-
-	sock = NET_NewQSocket ();
-	*(int *)(&sock->driverdata) = next.session;
-
-	Sys_FileRead (vcrFile, sock->address, NET_NAMELEN);
-	VCR_ReadNext ();
-
-	return sock;
-}
--- a/pr_comp.h
+++ b/pr_comp.h
@@ -97,6 +97,7 @@
 	OP_BITOR
 };
 
+#pragma pack on
 
 typedef struct statement_s
 {
@@ -158,3 +159,4 @@
 	int		entityfields;
 } dprograms_t;
 
+#pragma pack off
--- a/pr_edict.c
+++ b/pr_edict.c
@@ -546,7 +546,7 @@
 {
 	int		i;
 	
-	i = Q_atoi (Cmd_Argv(1));
+	i = atoi(Cmd_Argv(1));
 	if (i >= sv.num_edicts)
 	{
 		Con_Printf("Bad edict number\n");
@@ -1010,7 +1010,7 @@
 	pr_global_struct = (globalvars_t *)((byte *)progs + progs->ofs_globals);
 	pr_globals = (float *)pr_global_struct;
 	
-	pr_edict_size = progs->entityfields * 4 + sizeof (edict_t) - sizeof(entvars_t);
+	pr_edict_size = progs->entityfields * 4 + sizeof(edict_t) - sizeof(entvars_t);
 	
 // byte swap the lumps
 	for (i=0 ; i<progs->numstatements ; i++)
--- a/pr_exec.c
+++ b/pr_exec.c
@@ -241,22 +241,21 @@
 Aborts the currently executing function
 ============
 */
-void PR_RunError (char *error, ...)
+void PR_RunError (char *fmt, ...)
 {
-	va_list		argptr;
-	char		string[1024];
+	va_list arg;
+	char s[1024];
 
-	va_start (argptr,error);
-	vseprint (string,string+sizeof(string),error,argptr);
-	va_end (argptr);
+	va_start(arg, fmt);
+	vsnprint(s, sizeof s, fmt, arg);
+	va_end(arg);
 
-	PR_PrintStatement (pr_statements + pr_xstatement);
-	PR_StackTrace ();
-	Con_Printf ("%s\n", string);
+	PR_PrintStatement(pr_statements + pr_xstatement);
+	PR_StackTrace();
+	Con_Printf("%s\n", s);
 	
-	pr_depth = 0;		// dump the stack so host_error can shutdown functions
-
-	Host_Error ("Program error");
+	pr_depth = 0;	// dump the stack so host_error can shutdown functions
+	Host_Error("Program error");
 }
 
 /*
--- a/quakedef.h
+++ b/quakedef.h
@@ -147,9 +147,6 @@
 // Use for multiplayer testing only - VERY dangerous!!!
 // #define IDGODS
 
-/* FIXME: if hj no dicks, struct sizes screw up lump loading, see zB model.c errors */
-#pragma pack on
-
 #include "common.h"
 #include "bspfile.h"
 #include "vid.h"
@@ -167,7 +164,6 @@
 	int		skin;
 	int		effects;
 } entity_state_t;
-
 
 #include "wad.h"
 #include "draw.h"
--- a/r_main.c
+++ b/r_main.c
@@ -134,10 +134,10 @@
 	byte	*dest;
 	
 // create a simple checkerboard texture for the default
-	r_notexture_mip = Hunk_AllocName (sizeof(texture_t) + 16*16+8*8+4*4+2*2, "notexture");
+	r_notexture_mip = Hunk_AllocName(16*16+8*8+4*4+2*2 + sizeof *r_notexture_mip, "notexture");
 	
 	r_notexture_mip->width = r_notexture_mip->height = 16;
-	r_notexture_mip->offsets[0] = sizeof(texture_t);
+	r_notexture_mip->offsets[0] = sizeof *r_notexture_mip;
 	r_notexture_mip->offsets[1] = r_notexture_mip->offsets[0] + 16*16;
 	r_notexture_mip->offsets[2] = r_notexture_mip->offsets[1] + 8*8;
 	r_notexture_mip->offsets[3] = r_notexture_mip->offsets[2] + 4*4;
@@ -237,7 +237,7 @@
 
 	if (r_cnumsurfs > NUMSTACKSURFACES)
 	{
-		surfaces = Hunk_AllocName (r_cnumsurfs * sizeof(surf_t), "surfaces");
+		surfaces = Hunk_AllocName(r_cnumsurfs * sizeof *surfaces, "surfaces");
 		surface_p = surfaces;
 		surf_max = &surfaces[r_cnumsurfs];
 		r_surfsonstack = false;
@@ -265,8 +265,7 @@
 	}
 	else
 	{
-		auxedges = Hunk_AllocName (r_numallocatededges * sizeof(edge_t),
-								   "edges");
+		auxedges = Hunk_AllocName(r_numallocatededges * sizeof *auxedges, "edges");
 	}
 
 	r_dowarpold = false;
--- a/r_part.c
+++ b/r_part.c
@@ -20,32 +20,20 @@
 vec3_t			r_pright, r_pup, r_ppn;
 
 
-/*
-===============
-R_InitParticles
-===============
-*/
-void R_InitParticles (void)
+void
+R_InitParticles(void)
 {
-	int		i;
+	int i;
 
-	i = COM_CheckParm ("-particles");
-
-	if (i)
-	{
-		r_numparticles = (int)(Q_atoi(com_argv[i+1]));
-		if (r_numparticles < ABSOLUTE_MIN_PARTICLES)
+	if((i = COM_CheckParm("-particles")) != 0){
+		r_numparticles = atoi(com_argv[i+1]);
+		if(r_numparticles < ABSOLUTE_MIN_PARTICLES)
 			r_numparticles = ABSOLUTE_MIN_PARTICLES;
-	}
-	else
-	{
+	}else
 		r_numparticles = MAX_PARTICLES;
-	}
 
-	particles = (particle_t *)
-			Hunk_AllocName (r_numparticles * sizeof(particle_t), "particles");
+	particles = Hunk_AllocName(r_numparticles * sizeof *particles, "particles");
 }
-
 
 /*
 ===============
--- a/r_sprite.c
+++ b/r_sprite.c
@@ -68,7 +68,7 @@
 	
 // handle wraparound case
 	dists[nump] = dists[0];
-	Q_memcpy (instep, in, sizeof (vec5_t));
+	memcpy(instep, in, sizeof(vec5_t));
 
 
 // clip the winding
@@ -79,7 +79,7 @@
 	{
 		if (dists[i] >= 0)
 		{
-			Q_memcpy (outstep, instep, sizeof (vec5_t));
+			memcpy(outstep, instep, sizeof(vec5_t));
 			outstep += sizeof (vec5_t) / sizeof (float);
 			outcount++;
 		}
--- a/sbar.c
+++ b/sbar.c
@@ -416,7 +416,7 @@
 	Sbar_SortFrags ();
 
 // draw the text
-	memset (scoreboardtext, 0, sizeof(scoreboardtext));
+	memset(scoreboardtext, 0, sizeof scoreboardtext);
 
 	for (i=0 ; i<scoreboardlines; i++)
 	{
--- a/screen.c
+++ b/screen.c
@@ -551,11 +551,11 @@
 	pcx->ymax = LittleShort((short)(height-1));
 	pcx->hres = LittleShort((short)width);
 	pcx->vres = LittleShort((short)height);
-	Q_memset (pcx->palette,0,sizeof(pcx->palette));
+	memset(pcx->palette, 0, sizeof pcx->palette);
 	pcx->color_planes = 1;		// chunky image
 	pcx->bytes_per_line = LittleShort((short)width);
 	pcx->palette_type = LittleShort(2);		// not a grey scale
-	Q_memset (pcx->filler,0,sizeof(pcx->filler));
+	memset(pcx->filler, 0, sizeof pcx->filler);
 
 // pack the image
 	pack = &pcx->data;
@@ -575,7 +575,7 @@
 
 		data += rowbytes - width;
 	}
-			
+	
 // write the palette
 	*pack++ = 0x0c;	// palette ID byte
 	for (i=0 ; i<768 ; i++)
@@ -609,8 +609,8 @@
 		pcxname[5] = i/10 + '0'; 
 		pcxname[6] = i%10 + '0'; 
 		sprint (checkname, "%s/%s", com_gamedir, pcxname);
-		if (Sys_FileTime(checkname) == -1)
-			break;	// file doesn't exist
+		if(access(checkname, AEXIST) == -1)
+			break;
 	} 
 	if (i==100) 
 	{
--- /dev/null
+++ b/snd.c
@@ -1,0 +1,115 @@
+#include <u.h>
+#include <libc.h>
+#include <stdio.h>
+#include <thread.h>
+#include "quakedef.h"
+
+enum{
+	Nbuf	= 8
+};
+static int afd;
+static int sndon;
+static uint wpos;
+static Channel *schan;
+static QLock sndlock;
+
+
+static void
+sproc(void *)
+{
+	int n, sz;
+
+	threadsetgrp(THsnd);
+
+	for(;;){
+		if(recv(schan, nil) < 0)
+			break;
+		sz = shm->samplebits/8 * shm->samples;
+		if((n = write(afd, shm->buffer, sz)) != sz)
+			break;
+		qlock(&sndlock);
+		wpos += n;
+		qunlock(&sndlock);
+	}
+	fprint(2, "sproc %d: %r\n", threadpid(threadid()));
+}
+
+qboolean
+SNDDMA_Init(void)
+{
+	int i;
+
+	sndon = 0;
+
+	if((afd = open("/dev/audio", OWRITE)) < 0){
+		fprint(2, "open: %r\n");
+		return 0;
+	}
+
+	shm = &sn;
+	shm->splitbuffer = 0;
+
+	if((i = COM_CheckParm("-sndbits")) != 0)
+		shm->samplebits = atoi(com_argv[i+1]);
+	if(shm->samplebits != 16 && shm->samplebits != 8)
+		shm->samplebits = 16;
+
+	if((i = COM_CheckParm("-sndspeed")) != 0)
+		shm->speed = atoi(com_argv[i+1]);
+	else
+		shm->speed = 44100;
+
+	shm->channels = 2;
+	if(COM_CheckParm("-sndmono") != 0)
+		shm->channels = 1;
+
+	shm->samples = 4096;
+	shm->submission_chunk = 1;
+
+	if((shm->buffer = mallocz(shm->samplebits/8 * shm->samples, 1)) == nil)
+		sysfatal("SNDDMA_Init:mallocz: %r\n");
+	shm->samplepos = 0;
+	sndon = 1;
+	wpos = 0;
+	if((schan = chancreate(sizeof(int), Nbuf)) == nil)
+		sysfatal("SNDDMA_Init:chancreate: %r");
+	if(proccreate(sproc, nil, 8192) < 0)
+		sysfatal("SNDDMA_Init:proccreate: %r");
+	return 1;
+}
+
+uint
+SNDDMA_GetDMAPos(void)
+{
+	if(!sndon)
+		return 0;
+	qlock(&sndlock);
+	shm->samplepos = wpos / (shm->samplebits/8);
+	qunlock(&sndlock);
+	return shm->samplepos;
+}
+
+void
+SNDDMA_Shutdown(void)
+{
+	if(!sndon)
+		return;
+
+	threadkillgrp(THsnd);
+	close(afd);
+	free(shm->buffer);
+	if(schan != nil){
+		chanfree(schan);
+		schan = nil;
+	}
+	sndon = 0;
+}
+
+void
+SNDDMA_Submit(void)
+{
+	if(nbsend(schan, nil) < 0){
+		fprint(2, "SNDDMA_Submit:nbsend: %r\n");
+		SNDDMA_Shutdown();
+	}
+}
--- a/snd_9.c
+++ /dev/null
@@ -1,111 +1,0 @@
-#include <u.h>
-#include <libc.h>
-#include <stdio.h>
-#include <thread.h>
-#include "quakedef.h"
-
-int audio_fd;
-int sndon;
-uint wpos;
-int stid = -1;
-enum{
-	Nbuf	= 16
-};
-Channel *schan;
-
-
-void sproc (void *)
-{
-	int n;
-
-	for(;;){
-		if(recv(schan, nil) < 0){
-			Con_Printf("sproc:recv %r\n");
-			break;
-		}
-		if((n = write(audio_fd, shm->buffer, shm->samplebits/8 * shm->samples)) < 0){
-			Con_Printf("sproc:write: %r\n");
-			break;
-		}
-		wpos += n;
-	}
-	stid = -1;
-}
-
-qboolean SNDDMA_Init(void)
-{
-	int i;
-
-	sndon = 0;
-
-	if((audio_fd = open("/dev/audio", OWRITE)) < 0){
-		Con_Printf("Could not open /dev/audio: %r\n");
-		return 0;
-	}
-
-	shm = &sn;
-	shm->splitbuffer = 0;
-
-	if((i = COM_CheckParm("-sndbits")) != 0)
-		shm->samplebits = atoi(com_argv[i+1]);
-	if(shm->samplebits != 16 && shm->samplebits != 8)
-		shm->samplebits = 16;
-
-	if((i = COM_CheckParm("-sndspeed")) != 0)
-		shm->speed = atoi(com_argv[i+1]);
-	else
-		shm->speed = 44100;
-
-	shm->channels = 2;
-	if(COM_CheckParm("-sndmono") != 0)
-		shm->channels = 1;
-
-	shm->samples = 4096;
-	shm->submission_chunk = 1;
-
-	if((shm->buffer = mallocz(shm->samplebits/8 * shm->samples, 1)) == nil)
-		Sys_Error("SNDDMA_Init:mallocz: %r\n");
-	shm->samplepos = 0;
-	sndon = 1;
-	schan = chancreate(sizeof(int), Nbuf);
-	if((stid = proccreate(sproc, nil, 8192)) < 0){
-		stid = -1;
-		SNDDMA_Shutdown();
-		Sys_Error("SNDDMA_Init:proccreate: %r\n");
-	}
-	return 1;
-}
-
-uint SNDDMA_GetDMAPos(void)
-{
-	if(!sndon)
-		return 0;
-	shm->samplepos = wpos / (shm->samplebits/8);
-	return shm->samplepos;
-}
-
-void SNDDMA_Shutdown(void)
-{
-	if(!sndon)
-		return;
-
-	close(audio_fd);
-	free(shm->buffer);
-	if(stid != -1){
-		threadkill(stid);
-		stid = -1;
-	}
-	if(schan != nil){
-		chanfree(schan);
-		schan = nil;
-	}
-	sndon = 0;
-}
-
-void SNDDMA_Submit(void)
-{
-	if(nbsend(schan, nil) < 0){
-		Con_Printf("SNDDMA_Submit:nbsend: %r\n");
-		SNDDMA_Shutdown();
-	}
-}
--- a/snd_dma.c
+++ b/snd_dma.c
@@ -24,7 +24,7 @@
 qboolean		snd_initialized = false;
 
 // pointer should go away
-volatile dma_t  *shm = 0;
+volatile dma_t *shm;
 volatile dma_t sn;
 
 vec3_t		listener_origin;
@@ -177,8 +177,6 @@
 		Con_Printf ("loading all sounds as 8bit\n");
 	}
 
-
-
 	snd_initialized = true;
 
 	S_Startup ();
@@ -185,7 +183,7 @@
 
 	SND_InitScaletable ();
 
-	known_sfx = Hunk_AllocName (MAX_SFX*sizeof(sfx_t), "sfx_t");
+	known_sfx = Hunk_AllocName(MAX_SFX * sizeof *known_sfx, "sfx_t");
 	num_sfx = 0;
 
 // create a piece of DMA memory
@@ -192,7 +190,7 @@
 
 	if (fakedma)
 	{
-		shm = (void *) Hunk_AllocName(sizeof(*shm), "shm");
+		shm = Hunk_AllocName(sizeof *shm, "shm");
 		shm->splitbuffer = 0;
 		shm->samplebits = 16;
 		shm->speed = 22050;
@@ -226,18 +224,14 @@
 
 void S_Shutdown(void)
 {
-
-	if (!sound_started)
+	if(!sound_started)
 		return;
-
-	if (shm)
+	if(shm != nil)
 		shm->gamealive = 0;
-
-	//shm = 0;	/* why? */
-	sound_started = 0;
-
-	if (!fakedma)
+	if(!fakedma)
 		SNDDMA_Shutdown();
+	shm = nil;
+	sound_started = 0;
 }
 
 
@@ -259,15 +253,13 @@
 	if (name == nil)
 		Sys_Error ("S_FindName: NULL\n");
 
-	if (Q_strlen(name) >= MAX_QPATH)
+	if(strlen(name) >= MAX_QPATH)
 		Sys_Error ("Sound name too long: %s", name);
 
 // see if already loaded
 	for (i=0 ; i < num_sfx ; i++)
-		if (!Q_strcmp(known_sfx[i].name, name))
-		{
+		if(strcmp(known_sfx[i].name, name) == 0)
 			return &known_sfx[i];
-		}
 
 	if (num_sfx == MAX_SFX)
 		Sys_Error ("S_FindName: out of sfx_t");
@@ -448,7 +440,7 @@
 		return;
 		
 // spatialize
-	memset (target_chan, 0, sizeof(*target_chan));
+	memset(target_chan, 0, sizeof *target_chan);
 	VectorCopy(origin, target_chan->origin);
 	target_chan->dist_mult = attenuation / sound_nominal_clip_dist;
 	target_chan->master_vol = vol;
@@ -520,7 +512,7 @@
 		if (channels[i].sfx)
 			channels[i].sfx = nil;
 
-	Q_memset(channels, 0, MAX_CHANNELS * sizeof(channel_t));
+	memset(channels, 0, sizeof channels);
 
 	if (clear)
 		S_ClearBuffer ();
@@ -535,7 +527,7 @@
 {
 	int		clear;
 		
-	if (!sound_started || !shm || !shm->buffer)
+	if (!sound_started || shm == nil || shm->buffer == nil)
 		return;
 
 	if (shm->samplebits == 8)
@@ -543,7 +535,7 @@
 	else
 		clear = 0;
 
-	Q_memset(shm->buffer, clear, shm->samples * shm->samplebits/8);
+	memset(shm->buffer, clear, shm->samples * shm->samplebits/8);
 }
 
 
@@ -827,13 +819,13 @@
 	i = 1;
 	while (i<Cmd_Argc())
 	{
-		if (!Q_strrchr(Cmd_Argv(i), '.'))
+		if(strrchr(Cmd_Argv(i), '.') == nil)
 		{
-			Q_strcpy(name, Cmd_Argv(i));
-			Q_strcat(name, ".wav");
+			strcpy(name, Cmd_Argv(i));
+			strcat(name, ".wav");
 		}
 		else
-			Q_strcpy(name, Cmd_Argv(i));
+			strcpy(name, Cmd_Argv(i));
 		sfx = S_PrecacheSound(name);
 		S_StartSound(hash++, 0, sfx, listener_origin, 1.0, 1.0);
 		i++;
@@ -851,15 +843,15 @@
 	i = 1;
 	while (i<Cmd_Argc())
 	{
-		if (!Q_strrchr(Cmd_Argv(i), '.'))
+		if(strrchr(Cmd_Argv(i), '.') == nil)
 		{
-			Q_strcpy(name, Cmd_Argv(i));
-			Q_strcat(name, ".wav");
+			strcpy(name, Cmd_Argv(i));
+			strcat(name, ".wav");
 		}
 		else
-			Q_strcpy(name, Cmd_Argv(i));
+			strcpy(name, Cmd_Argv(i));
 		sfx = S_PrecacheSound(name);
-		vol = Q_atof(Cmd_Argv(i+1));
+		vol = atof(Cmd_Argv(i+1));
 		S_StartSound(hash++, 0, sfx, listener_origin, vol, 1.0);
 		i+=2;
 	}
--- a/snd_mem.c
+++ b/snd_mem.c
@@ -95,12 +95,12 @@
 
 //Con_Printf ("S_LoadSound: %x\n", (int)stackbuf);
 // load it in
-    Q_strcpy(namebuffer, "sound/");
-    Q_strcat(namebuffer, s->name);
+	strcpy(namebuffer, "sound/");
+	strcat(namebuffer, s->name);
 
 //	Con_Printf ("loading %s\n",namebuffer);
 
-	data = COM_LoadStackFile(namebuffer, stackbuf, sizeof(stackbuf));
+	data = COM_LoadStackFile(namebuffer, stackbuf, sizeof stackbuf);
 
 	if (!data)
 	{
@@ -120,7 +120,7 @@
 
 	len = len * info.width * info.channels;
 
-	sc = Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name);
+	sc = Cache_Alloc(&s->cache, len + sizeof *sc, s->name);
 	if (!sc)
 		return nil;
 	
@@ -198,7 +198,7 @@
 //			Sys_Error ("FindNextChunk: %d 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((char *)data_p, name, 4))
+		if(strncmp((char *)data_p, name, 4) == 0)
 			return;
 	}
 }
@@ -238,7 +238,7 @@
 	int     format;
 	int		samples;
 
-	memset (&info, 0, sizeof(info));
+	memset(&info, 0, sizeof info);
 
 	if (!wav)
 		return info;
@@ -248,7 +248,7 @@
 
 // find "RIFF" chunk
 	FindChunk("RIFF");
-	if (!(data_p && !Q_strncmp((char *)data_p+8, "WAVE", 4)))
+	if(!(data_p && strncmp((char *)data_p+8, "WAVE", 4) == 0))
 	{
 		Con_Printf("Missing RIFF/WAVE chunks\n");
 		return info;
@@ -289,7 +289,7 @@
 		FindNextChunk ("LIST");
 		if (data_p)
 		{
-			if (!strncmp ((char *)data_p+28, "mark", 4))
+			if(strncmp((char *)data_p+28, "mark", 4) == 0)
 			{	// 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
@@ -13,7 +13,6 @@
 int 	*snd_p, snd_linear_count, snd_vol;
 short	*snd_out;
 
-void Snd_WriteLinearBlastStereo16 (void);
 
 void Snd_WriteLinearBlastStereo16 (void)
 {
@@ -45,7 +44,7 @@
 	int		lpos;
 	int		lpaintedtime;
 	DWORD	*pbuf;
-	
+
 	snd_vol = volume.value*256;
 
 	snd_p = (int *) paintbuffer;
@@ -160,7 +159,7 @@
 			end = paintedtime + PAINTBUFFER_SIZE;
 
 	// clear the paint buffer
-		Q_memset(paintbuffer, 0, (end - paintedtime) * sizeof(portable_samplepair_t));
+		memset(paintbuffer, 0, (end - paintedtime) * sizeof *paintbuffer);
 
 	// paint in the channels.
 		ch = channels;
--- a/spritegn.h
+++ b/spritegn.h
@@ -1,35 +1,8 @@
-//
 // spritegn.h: header file for sprite generation program
-//
 
-// **********************************************************
-// * This file must be identical in the spritegen directory *
-// * and in the Quake directory, because it's used to       *
-// * pass data from one to the other via .spr files.        *
-// **********************************************************
-
-//-------------------------------------------------------
-// This program generates .spr sprite package files.
-// The format of the files is as follows:
-//
-// dsprite_t file header structure
-// <repeat dsprite_t.numframes times>
-//   <if spritegroup, repeat dspritegroup_t.numframes times>
-//     dspriteframe_t frame header structure
-//     sprite bitmap
-//   <else (single sprite frame)>
-//     dspriteframe_t frame header structure
-//     sprite bitmap
-// <endrepeat>
-//-------------------------------------------------------
-
 #define SPRITE_VERSION	1
 
-// must match definition in modelgen.h
-#ifndef SYNCTYPE_T
-#define SYNCTYPE_T
-typedef enum {ST_SYNC=0, ST_RAND } synctype_t;
-#endif
+#pragma pack on
 
 // TODO: shorten these?
 typedef struct {
@@ -73,3 +46,4 @@
 #define IDSPRITEHEADER	(('P'<<24)+('S'<<16)+('D'<<8)+'I')
 														// little-endian "IDSP"
 
+#pragma pack off
--- a/sv_main.c
+++ b/sv_main.c
@@ -226,16 +226,15 @@
 */
 void SV_ConnectClient (int clientnum)
 {
-	edict_t			*ent;
-	client_t		*client;
-	int				edictnum;
+	int i, edictnum;
+	float spawn_parms[NUM_SPAWN_PARMS];
+	edict_t *ent;
+	client_t *client;
 	struct qsocket_s *netconnection;
-	int				i;
-	float			spawn_parms[NUM_SPAWN_PARMS];
 
 	client = svs.clients + clientnum;
 
-	Con_DPrintf ("Client %s connected\n", client->netconnection->address);
+	Con_DPrintf("Client %s connected\n", client->netconnection->address);
 
 	edictnum = clientnum+1;
 
@@ -244,17 +243,17 @@
 // set up the client_t
 	netconnection = client->netconnection;
 	
-	if (sv.loadgame)
-		memcpy (spawn_parms, client->spawn_parms, sizeof(spawn_parms));
-	memset (client, 0, sizeof(*client));
+	if(sv.loadgame)
+		memcpy(spawn_parms, client->spawn_parms, sizeof spawn_parms);
+	memset(client, 0, sizeof *client);
 	client->netconnection = netconnection;
 
-	strcpy (client->name, "unconnected");
+	strcpy(client->name, "unconnected");
 	client->active = true;
 	client->spawned = false;
 	client->edict = ent;
 	client->message.data = client->msgbuf;
-	client->message.maxsize = sizeof(client->msgbuf);
+	client->message.maxsize = sizeof client->msgbuf;
 	client->message.allowoverflow = true;		// we can catch it
 
 #ifdef IDGODS
@@ -264,17 +263,16 @@
 	client->privileged = false;				
 #endif
 
-	if (sv.loadgame)
-		memcpy (client->spawn_parms, spawn_parms, sizeof(spawn_parms));
-	else
-	{
-	// call the progs to get default spawn parms for the new client
-		PR_ExecuteProgram (pr_global_struct->SetNewParms);
-		for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
+	if(sv.loadgame)
+		memcpy(client->spawn_parms, spawn_parms, sizeof spawn_parms);
+	else{
+		// call the progs to get default spawn parms for the new client
+		PR_ExecuteProgram(pr_global_struct->SetNewParms);
+		for(i=0; i<NUM_SPAWN_PARMS; i++)
 			client->spawn_parms[i] = (&pr_global_struct->parm1)[i];
 	}
 
-	SV_SendServerinfo (client);
+	SV_SendServerinfo(client);
 }
 
 
@@ -395,7 +393,7 @@
 byte *SV_FatPVS (vec3_t org)
 {
 	fatbytes = (sv.worldmodel->numleafs+31)>>3;
-	Q_memset (fatpvs, 0, fatbytes);
+	memset(fatpvs, 0, fatbytes);
 	SV_AddToFatPVS (org, sv.worldmodel->nodes);
 	return fatpvs;
 }
@@ -696,7 +694,7 @@
 	sizebuf_t	msg;
 	
 	msg.data = buf;
-	msg.maxsize = sizeof(buf);
+	msg.maxsize = sizeof buf;
 	msg.cursize = 0;
 
 	MSG_WriteByte (&msg, svc_time);
@@ -774,7 +772,7 @@
 	byte		buf[4];
 	
 	msg.data = buf;
-	msg.maxsize = sizeof(buf);
+	msg.maxsize = sizeof buf;
 	msg.cursize = 0;
 
 	MSG_WriteChar (&msg, svc_nop);
@@ -962,7 +960,7 @@
 
 	msg.data = data;
 	msg.cursize = 0;
-	msg.maxsize = sizeof(data);
+	msg.maxsize = sizeof data;
 
 	MSG_WriteChar (&msg, svc_stufftext);
 	MSG_WriteString (&msg, "reconnect\n");
@@ -1049,9 +1047,9 @@
 //
 	Host_ClearMemory ();
 
-	memset (&sv, 0, sizeof(sv));
+	memset(&sv, 0, sizeof sv);
 
-	strcpy (sv.name, server);
+	strcpy(sv.name, server);
 
 // load progs to get entity field count
 	PR_LoadProgs ();
@@ -1061,15 +1059,15 @@
 	
 	sv.edicts = Hunk_AllocName (sv.max_edicts*pr_edict_size, "edicts");
 
-	sv.datagram.maxsize = sizeof(sv.datagram_buf);
+	sv.datagram.maxsize = sizeof sv.datagram_buf;
 	sv.datagram.cursize = 0;
 	sv.datagram.data = sv.datagram_buf;
 	
-	sv.reliable_datagram.maxsize = sizeof(sv.reliable_datagram_buf);
+	sv.reliable_datagram.maxsize = sizeof sv.reliable_datagram_buf;
 	sv.reliable_datagram.cursize = 0;
 	sv.reliable_datagram.data = sv.reliable_datagram_buf;
 	
-	sv.signon.maxsize = sizeof(sv.signon_buf);
+	sv.signon.maxsize = sizeof sv.signon_buf;
 	sv.signon.cursize = 0;
 	sv.signon.data = sv.signon_buf;
 	
@@ -1116,7 +1114,7 @@
 // load the rest of the entities
 //	
 	ent = EDICT_NUM(0);
-	memset (&ent->v, 0, progs->entityfields * 4);
+	memset(&ent->v, 0, progs->entityfields * 4);
 	ent->free = false;
 	ent->v.model = sv.worldmodel->name - pr_strings;
 	ent->v.modelindex = 1;		// world model
--- a/sv_user.c
+++ b/sv_user.c
@@ -510,43 +510,43 @@
 					ret = 2;
 				else
 					ret = 0;
-				if (Q_strncasecmp(s, "status", 6) == 0)
+				if (cistrncmp(s, "status", 6) == 0)
 					ret = 1;
-				else if (Q_strncasecmp(s, "god", 3) == 0)
+				else if (cistrncmp(s, "god", 3) == 0)
 					ret = 1;
-				else if (Q_strncasecmp(s, "notarget", 8) == 0)
+				else if (cistrncmp(s, "notarget", 8) == 0)
 					ret = 1;
-				else if (Q_strncasecmp(s, "fly", 3) == 0)
+				else if (cistrncmp(s, "fly", 3) == 0)
 					ret = 1;
-				else if (Q_strncasecmp(s, "name", 4) == 0)
+				else if (cistrncmp(s, "name", 4) == 0)
 					ret = 1;
-				else if (Q_strncasecmp(s, "noclip", 6) == 0)
+				else if (cistrncmp(s, "noclip", 6) == 0)
 					ret = 1;
-				else if (Q_strncasecmp(s, "say", 3) == 0)
+				else if (cistrncmp(s, "say", 3) == 0)
 					ret = 1;
-				else if (Q_strncasecmp(s, "say_team", 8) == 0)
+				else if (cistrncmp(s, "say_team", 8) == 0)
 					ret = 1;
-				else if (Q_strncasecmp(s, "tell", 4) == 0)
+				else if (cistrncmp(s, "tell", 4) == 0)
 					ret = 1;
-				else if (Q_strncasecmp(s, "color", 5) == 0)
+				else if (cistrncmp(s, "color", 5) == 0)
 					ret = 1;
-				else if (Q_strncasecmp(s, "kill", 4) == 0)
+				else if (cistrncmp(s, "kill", 4) == 0)
 					ret = 1;
-				else if (Q_strncasecmp(s, "pause", 5) == 0)
+				else if (cistrncmp(s, "pause", 5) == 0)
 					ret = 1;
-				else if (Q_strncasecmp(s, "spawn", 5) == 0)
+				else if (cistrncmp(s, "spawn", 5) == 0)
 					ret = 1;
-				else if (Q_strncasecmp(s, "begin", 5) == 0)
+				else if (cistrncmp(s, "begin", 5) == 0)
 					ret = 1;
-				else if (Q_strncasecmp(s, "prespawn", 8) == 0)
+				else if (cistrncmp(s, "prespawn", 8) == 0)
 					ret = 1;
-				else if (Q_strncasecmp(s, "kick", 4) == 0)
+				else if (cistrncmp(s, "kick", 4) == 0)
 					ret = 1;
-				else if (Q_strncasecmp(s, "ping", 4) == 0)
+				else if (cistrncmp(s, "ping", 4) == 0)
 					ret = 1;
-				else if (Q_strncasecmp(s, "give", 4) == 0)
+				else if (cistrncmp(s, "give", 4) == 0)
 					ret = 1;
-				else if (Q_strncasecmp(s, "ban", 3) == 0)
+				else if (cistrncmp(s, "ban", 3) == 0)
 					ret = 1;
 				if (ret == 2)
 					Cbuf_InsertText (s);
@@ -596,7 +596,7 @@
 		if (!host_client->spawned)
 		{
 		// clear client movement until a new packet is received
-			memset (&host_client->cmd, 0, sizeof(host_client->cmd));
+			memset(&host_client->cmd, 0, sizeof host_client->cmd);
 			continue;
 		}
 
--- /dev/null
+++ b/sys.c
@@ -1,0 +1,255 @@
+#include <u.h>
+#include <libc.h>
+#include <stdio.h>
+#include <thread.h>
+#include "quakedef.h"
+
+qboolean isDedicated;
+mainstacksize = 512*1024;
+
+static char end1[] =
+	"                QUAKE: The Doomed Dimension by id Software\n"
+	"  ----------------------------------------------------------------------------\n"
+	"           CALL 1-800-IDGAMES TO ORDER OR FOR TECHNICAL SUPPORT\n"
+	"             PRICE: $45.00 (PRICES MAY VARY OUTSIDE THE US.)\n"
+	"\n"
+	"  Yes! You only have one fourth of this incredible epic. That is because most\n"
+	"   of you have paid us nothing or at most, very little. You could steal the\n"
+	"   game from a friend. But we both know you'll be punished by God if you do.\n"
+	"        WHY RISK ETERNAL DAMNATION? CALL 1-800-IDGAMES AND BUY NOW!\n"
+	"             Remember, we love you almost as much as He does.\n"
+	"\n"
+	"            Programming: John Carmack, Michael Abrash, John Cash\n"
+	"      Design: John Romero, Sandy Petersen, American McGee, Tim Willits\n"
+	"                     Art: Adrian Carmack, Kevin Cloud\n"
+	"               Biz: Jay Wilbur, Mike Wilson, Donna Jackson\n"
+	"            Projects: Shawn Green   Support: Barrett Alexander\n"
+	"              Sound Effects: Trent Reznor and Nine Inch Nails\n"
+	"  For other information or details on ordering outside the US, check out the\n"
+	"     files accompanying QUAKE or our website at http://www.idsoftware.com.\n"
+	"    Quake is a trademark of Id Software, inc., (c)1996 Id Software, inc.\n"
+	"     All rights reserved. NIN logo is a registered trademark licensed to\n"
+	"                 Nothing Interactive, Inc. All rights reserved.\n";
+static char end2[] =
+	"        QUAKE by id Software\n"
+	" -----------------------------------------------------------------------------\n"
+	"        Why did you quit from the registered version of QUAKE? Did the\n"
+	"        scary monsters frighten you? Or did Mr. Sandman tug at your\n"
+	"        little lids? No matter! What is important is you love our\n"
+	"        game, and gave us your money. Congratulations, you are probably\n"
+	"        not a thief.\n"
+	"                                                           Thank You.\n"
+	"        id Software is:\n"
+	"        PROGRAMMING: John Carmack, Michael Abrash, John Cash\n"
+	"        DESIGN: John Romero, Sandy Petersen, American McGee, Tim Willits\n"
+	"        ART: Adrian Carmack, Kevin Cloud\n"
+	"        BIZ: Jay Wilbur, Mike Wilson     PROJECTS MAN: Shawn Green\n"
+	"        BIZ ASSIST: Donna Jackson        SUPPORT: Barrett Alexander\n"
+	"        SOUND EFFECTS AND MUSIC: Trent Reznor and Nine Inch Nails\n"
+	"\n"
+	"        If you need help running QUAKE refer to the text files in the\n"
+	"        QUAKE directory, or our website at http://www.idsoftware.com.\n"
+	"        If all else fails, call our technical support at 1-800-IDGAMES.\n"
+	"      Quake is a trademark of Id Software, inc., (c)1996 Id Software, inc.\n"
+	"        All rights reserved. NIN logo is a registered trademark licensed\n"
+	"             to Nothing Interactive, Inc. All rights reserved.\n";
+
+
+void
+Sys_Printf(char *fmt, ...)
+{
+	char buf[1024], *p;
+	va_list arg;
+
+	va_start(arg, fmt);
+	vsnprint(buf, sizeof buf, fmt, arg);
+	va_end(arg);
+
+	for(p = buf; *p; p++){
+		*p &= 0x7f;
+		if(*p < 32 && *p != 10 && *p != 13 && *p != 9)
+			print("[%02x]", *p);
+		else
+			print("%c", *p);
+	}
+}
+
+void
+Sys_Quit(void)
+{
+	Host_Shutdown();
+	print("\n");
+	if(registered.value)
+		print("%s\n", end2);
+	else
+		print("%s\n", end1);
+	threadexitsall(nil);
+}
+
+void
+Sys_Error(char *fmt, ...)
+{
+	char buf[1024], *p;
+	va_list arg;
+
+	va_start(arg, fmt);
+	p = vseprint(buf, buf+sizeof buf, fmt, arg);
+	va_end(arg);
+	p = seprint(p, buf+sizeof buf, "\n");
+	ewrite(2, buf, p-buf);
+	Host_Shutdown();
+	sysfatal("ending.");
+} 
+
+ulong
+Sys_FileTime(char *path)
+{
+	ulong t;
+	Dir *d;
+
+	if((d = dirstat(path)) == nil){
+		fprint(2, "dirstat: %r");
+		return -1;
+	}
+	t = d->mtime;
+	free(d);
+	return t;
+}
+
+void
+Sys_mkdir(char *path)
+{
+	int d;
+
+	/* don't care if it isn't a directory, caller doesn't check */
+	if(access(path, AEXIST) == 0)
+		return;
+	if((d = create(path, OREAD, DMDIR|0777)) < 0)
+		fprint(2, "Sys_mkdir:create: %r\n");
+	else
+		close(d);
+}
+
+vlong
+flen(int fd)
+{
+	vlong l;
+	Dir *d;
+
+	if((d = dirfstat(fd)) == nil)	/* file assumed extant and readable */ 
+		sysfatal("flen: %r");
+	l = d->length;
+	free(d);
+	return l;
+}
+
+void
+eread(int fd, void *buf, long n)
+{
+	if(read(fd, buf, n) <= 0)
+		sysfatal("eread: %r");
+}
+
+void
+ewrite(int fd, void *buf, long n)
+{
+	if(write(fd, buf, n) != n)
+		sysfatal("ewrite: %r");
+}
+
+double
+Sys_FloatTime(void)
+{
+	static long secbase;
+
+	if(secbase == 0)
+		secbase = time(nil);
+	return nsec()/1000000000.0 - secbase;
+}
+
+void *
+emalloc(ulong b)
+{
+	void *p;
+
+	if((p = malloc(b)) == nil)
+		sysfatal("malloc %lud: %r", b);
+	return p;
+}
+
+void
+Sys_HighFPPrecision(void)
+{
+}
+
+void
+Sys_LowFPPrecision(void)
+{
+}
+
+static void
+croak(void *, char *note)
+{
+	if(strncmp(note, "sys:", 4) == 0){
+		IN_Shutdown();
+		SNDDMA_Shutdown();
+	}
+	noted(NDFLT);
+}
+
+void
+threadmain(int c, char **v)
+{
+	static char basedir[1024];
+	int j;
+	char *home;
+	double time, oldtime, newtime;
+	quakeparms_t parms;
+
+	memset(&parms, 0, sizeof parms);
+
+	/* ignore fp exceptions: rendering shit assumes they are */
+	setfcr(getfcr() & ~(FPOVFL|FPUNFL|FPINVAL|FPZDIV));
+	notify(croak);
+
+	COM_InitArgv(c, v);
+	parms.argc = com_argc;
+	parms.argv = com_argv;
+	argv0 = *v;
+
+	parms.memsize = 8*1024*1024;
+	if(j = COM_CheckParm("-mem"))
+		parms.memsize = atoi(com_argv[j+1]) * 1024*1024;
+	parms.membase = emalloc(parms.memsize);
+
+	if(home = getenv("home")){
+		snprint(basedir, sizeof basedir, "%s/lib/quake", home);
+		free(home);
+	}else
+		snprint(basedir, sizeof basedir, "/sys/lib/quake");
+	parms.basedir = basedir;
+
+	Host_Init(&parms);
+
+	oldtime = Sys_FloatTime() - 0.1;
+	for(;;){
+		// 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){
+				//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);
+	}
+}
--- a/sys.h
+++ b/sys.h
@@ -1,29 +1,22 @@
 // sys.h -- non-portable functions
 
-//
-// file IO
-//
-// returns the file size, -1 if file not found
-vlong Sys_FileOpenRead (char *path, int *hndl);
-int Sys_FileOpenWrite (char *path);
-void Sys_FileClose (int handle);
-void Sys_FileSeek (int handle, int position);
-int Sys_FileRead (int handle, void *dest, int count);
-int Sys_FileWrite (int handle, void *data, int count);
-int Sys_FileTime (char *path);
-void Sys_mkdir (char *path);
+enum{
+	THin	= 1,
+	THsnd	= 2,
+	THnet	= 3
+};
 
-//
-// system IO
-//
-void Sys_Error (char *error, ...);
-void Sys_Printf (char *fmt, ...);
-void Sys_Quit (void);
-double Sys_FloatTime (void);
-char *Sys_ConsoleInput (void);
-
-void Sys_SendKeyEvents (void);
-// Perform Key_Event () callbacks until the input que is empty
-
-void Sys_LowFPPrecision (void);
-void Sys_HighFPPrecision (void);
+void	Sys_Error(char *, ...);
+void	Sys_Printf(char *, ...);
+void	Sys_Quit(void);
+void	Sys_LowFPPrecision(void);
+void	Sys_HighFPPrecision(void);
+void*	emalloc(ulong);
+ulong	Sys_FileTime(char *);
+void	Sys_mkdir(char *);
+vlong	flen(int);
+void	eread(int, void *, long);
+void	ewrite(int, void *, long);
+double	Sys_FloatTime(void);
+char*	Sys_ConsoleInput(void);
+void	Sys_SendKeyEvents(void);	// call Key_Event() until the input queue is empty
--- a/sys_9.c
+++ /dev/null
@@ -1,263 +1,0 @@
-#include <u.h>
-#include <libc.h>
-#include <stdio.h>
-#include <thread.h>
-#include "quakedef.h"
-
-qboolean isDedicated;
-mainstacksize = 512*1024;	/* FIXME */
-char end1[] =
-	"                QUAKE: The Doomed Dimension by id Software\n"
-	"  ----------------------------------------------------------------------------\n"
-	"           CALL 1-800-IDGAMES TO ORDER OR FOR TECHNICAL SUPPORT\n"
-	"             PRICE: $45.00 (PRICES MAY VARY OUTSIDE THE US.)\n"
-	"\n"
-	"  Yes! You only have one fourth of this incredible epic. That is because most\n"
-	"   of you have paid us nothing or at most, very little. You could steal the\n"
-	"   game from a friend. But we both know you'll be punished by God if you do.\n"
-	"        WHY RISK ETERNAL DAMNATION? CALL 1-800-IDGAMES AND BUY NOW!\n"
-	"             Remember, we love you almost as much as He does.\n"
-	"\n"
-	"            Programming: John Carmack, Michael Abrash, John Cash\n"
-	"      Design: John Romero, Sandy Petersen, American McGee, Tim Willits\n"
-	"                     Art: Adrian Carmack, Kevin Cloud\n"
-	"               Biz: Jay Wilbur, Mike Wilson, Donna Jackson\n"
-	"            Projects: Shawn Green   Support: Barrett Alexander\n"
-	"              Sound Effects: Trent Reznor and Nine Inch Nails\n"
-	"  For other information or details on ordering outside the US, check out the\n"
-	"     files accompanying QUAKE or our website at http://www.idsoftware.com.\n"
-	"    Quake is a trademark of Id Software, inc., (c)1996 Id Software, inc.\n"
-	"     All rights reserved. NIN logo is a registered trademark licensed to\n"
-	"                 Nothing Interactive, Inc. All rights reserved.\n";
-char end2[] =
-	"        QUAKE by id Software\n"
-	" -----------------------------------------------------------------------------\n"
-	"        Why did you quit from the registered version of QUAKE? Did the\n"
-	"        scary monsters frighten you? Or did Mr. Sandman tug at your\n"
-	"        little lids? No matter! What is important is you love our\n"
-	"        game, and gave us your money. Congratulations, you are probably\n"
-	"        not a thief.\n"
-	"                                                           Thank You.\n"
-	"        id Software is:\n"
-	"        PROGRAMMING: John Carmack, Michael Abrash, John Cash\n"
-	"        DESIGN: John Romero, Sandy Petersen, American McGee, Tim Willits\n"
-	"        ART: Adrian Carmack, Kevin Cloud\n"
-	"        BIZ: Jay Wilbur, Mike Wilson     PROJECTS MAN: Shawn Green\n"
-	"        BIZ ASSIST: Donna Jackson        SUPPORT: Barrett Alexander\n"
-	"        SOUND EFFECTS AND MUSIC: Trent Reznor and Nine Inch Nails\n"
-	"\n"
-	"        If you need help running QUAKE refer to the text files in the\n"
-	"        QUAKE directory, or our website at http://www.idsoftware.com.\n"
-	"        If all else fails, call our technical support at 1-800-IDGAMES.\n"
-	"      Quake is a trademark of Id Software, inc., (c)1996 Id Software, inc.\n"
-	"        All rights reserved. NIN logo is a registered trademark licensed\n"
-	"             to Nothing Interactive, Inc. All rights reserved.\n";
-
-
-void Sys_Printf (char *fmt, ...)
-{
-	char buf[1024];
-	char *p;
-	va_list arg;
-
-	va_start(arg, fmt);
-	vseprint(buf, buf+sizeof(buf), fmt, arg);
-	va_end(arg);
-
-	for(p = buf; *p; p++){
-		*p &= 0x7f;
-		if(*p < 32 && *p != 10 && *p != 13 && *p != 9)
-			print("[%02x]", *p);
-		else
-			print("%c", *p);
-	}
-}
-
-void Sys_Quit (void)
-{
-	Host_Shutdown();
-	print("\n");
-	if(registered.value)
-		print("%s\n", end2);
-	else
-		print("%s\n", end1);
-	threadexitsall(nil);
-}
-
-void Sys_Error (char *error, ...)
-{
-	char buf[1024], *out;
-	va_list arg;
-
-	va_start(arg, error);
-	out = vseprint(buf, buf+sizeof(buf), error, arg);
-	va_end(arg);
-	out = seprint(out, buf+sizeof(buf), "\n");
-	write(2, buf, out-buf);
-	Host_Shutdown();
-	sysfatal("ending.");
-} 
-
-int Sys_FileTime (char *path)
-{
-	uchar	sb[1024];
-
-	if(stat(path, sb, sizeof sb) < 0){
-		Sys_Printf("Sys_FileTime:stat: %r\n");
-		return -1;
-	}
-	return *((int *)(sb+25));
-}
-
-void Sys_mkdir (char *path)
-{
-	int d;
-
-	if((d = create(path, OREAD, DMDIR|0777)) < 0)
-		Sys_Printf("Sys_mkdir:create: %r\n");
-	else
-		close(d);
-}
-
-vlong Sys_FileOpenRead (char *path, int *handle)
-{
-	int d;
-	uchar bs[1024];
-
-	d = open (path, OREAD);
-	*handle = d;
-	if(d < 0)
-		return -1;
-	if(fstat(d, bs, sizeof bs) < 0)
-		Sys_Error("Sys_FileOpenRead:fstat: %r\n");
-	return *((vlong *)(bs+33));
-}
-
-int Sys_FileOpenWrite (char *path)
-{
-	int d;
-
-	if((d = open(path, OREAD|OTRUNC)) < 0)
-		Sys_Error("Sys_FileOpenWrite:open: %r\n");
-	return d;
-}
-
-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)
-{
-	seek(handle, position, 0);
-}
-
-int Sys_FileRead (int handle, void *dest, int count)
-{
-	return read(handle, dest, count);
-}
-
-double Sys_FloatTime (void)
-{
-	static long	secbase;
-
-	if(secbase == 0)
-		secbase = time(nil);
-	return nsec()/1000000000.0 - secbase;
-}
-
-char *Sys_ConsoleInput(void)
-{
-	static char	text[256];
-	int     len;
-
-	if(cls.state == ca_dedicated){
-		if((len = read(0, text, sizeof(text))) < 1)
-			return nil;
-		text[len-1] = '\0';
-		return text;
-	}
-	return nil;
-}
-
-void Sys_HighFPPrecision (void)
-{
-}
-
-void Sys_LowFPPrecision (void)
-{
-}
-
-void croak (void *, char *note)
-{
-	if(!strncmp(note, "sys:", 4)){
-		IN_Shutdown();
-		SNDDMA_Shutdown();
-	}
-	noted(NDFLT);
-}
-
-void threadmain (int c, char **v)
-{
-	static char basedir[1024];
-	int j;
-	char *home;
-	double time, oldtime, newtime;
-	quakeparms_t parms;
-	extern int vcrFile;
-	extern int recording;
-
-	memset(&parms, 0, sizeof(parms));
-
-	/* ignore fp exceptions (bad), rendering shit assumes they are */
-	setfcr(getfcr() & ~(FPOVFL|FPUNFL|FPINVAL|FPZDIV));	/* FIXME */
-	notify(croak);
-
-	COM_InitArgv(c, v);
-	parms.argc = com_argc;
-	parms.argv = com_argv;
-	argv0 = *v;
-
-	parms.memsize = 8*1024*1024;
-	if(j = COM_CheckParm("-mem"))
-		parms.memsize = (int)(Q_atof(com_argv[j+1]) * 1024*1024);
-	parms.membase = malloc(parms.memsize);
-
-	if(home = getenv("home")){
-		snprint(basedir, sizeof basedir, "%s/lib/quake", home);
-		free(home);
-	}else
-		snprint(basedir, sizeof basedir, "/sys/lib/quake");
-	parms.basedir = basedir;
-
-	Host_Init(&parms);
-
-	print("(9)quake %4.2f\n", (float)VERSION);
-
-	oldtime = Sys_FloatTime() - 0.1;
-	for(;;){
-		// 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);
-	}
-}
--- /dev/null
+++ b/vid.c
@@ -1,0 +1,233 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <stdio.h>
+#include "quakedef.h"
+
+viddef_t vid;		/* global video state */
+int resized;
+Point center;		/* of window */
+int d_con_indirect;
+void (*vid_menudrawfn)(void);
+void (*vid_menukeyfn)(int key);
+
+typedef u32int px24;
+px24 st2d_8to24table[256];
+ushort d_8to16table[256];
+
+enum{
+	Rmask	= 0xff0000,
+	Gmask	= 0xff00,
+	Bmask	= 0xff
+};
+static int shifton;
+static int rshift;
+static int gshift;
+static int bshift;
+static uchar *framebuf;	/* draw buffer */
+static Image *fbim;	/* framebuf image */
+
+
+static void
+mkmasks(void)
+{
+	uint x;
+
+	for(rshift = -8, x = 1; x < Rmask; x <<= 1)
+		rshift++;
+	for(gshift = -8, x = 1; x < Gmask; x <<= 1)
+		gshift++;
+	for(bshift = -8, x = 1; x < Bmask; x <<= 1)
+		bshift++;
+	shifton = 1;
+}
+
+static px24
+rgb24(int r, int g, int b)
+{
+	px24 p = 0;
+
+	if(!shifton)
+		mkmasks();
+
+	if(rshift > 0)
+		p = r<<rshift & Rmask;
+	else if(rshift < 0)
+		p = r>>-rshift & Rmask;
+	else
+		p |= r & Rmask;
+	if(gshift > 0)
+		p |= g<<gshift & Gmask;
+	else if(gshift < 0)
+		p |= g>>-gshift & Gmask;
+	else
+		p |= g & Gmask;
+	if(bshift > 0)
+		p |= b<<bshift & Bmask;
+	else if(bshift < 0)
+		p |= b>>-bshift & Bmask;
+	else
+		p |= b & Bmask;
+	return p;
+}
+
+static void
+st3_fixup(uchar *data, int x, int y, int width, int height)
+{
+	int yi;
+	uchar *src;
+	px24 *dest;
+	register int count, n;
+
+	if(x < 0 || y < 0)
+		return;
+
+	for(yi = y; yi < y+height; yi++){
+		src = &data[yi*vid.rowbytes];
+
+		// Duff's Device
+		count = width;
+		n = (count+7) / 8;
+		dest = ((px24 *)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_8to24table[src[xi]];
+	}
+}
+
+/* vid.height and vid.width must be set correctly before this call */
+static void
+resetfb(void)
+{
+	static int highhunk;
+	void *surfcache;
+	int hunkvbuf, scachesz;
+
+	if(d_pzbuffer != nil){
+		D_FlushCaches();
+		Hunk_FreeToHighMark(highhunk);
+		d_pzbuffer = nil;
+	}
+
+	highhunk = Hunk_HighMark();
+	// alloc an extra line in case we want to wrap, and allocate the z-buffer
+	hunkvbuf = vid.width * vid.height * sizeof *d_pzbuffer;
+	scachesz = D_SurfaceCacheForRes(vid.width, vid.height);
+	hunkvbuf += scachesz;
+	if((d_pzbuffer = Hunk_HighAllocName(hunkvbuf, "video")) == nil)
+		sysfatal("Not enough memory for video mode\n");
+	surfcache = (byte *)d_pzbuffer + vid.width * vid.height * sizeof *d_pzbuffer;
+	D_InitCaches(surfcache, scachesz);
+
+	free(framebuf);
+	framebuf = emalloc(Dx(screen->r) * Dy(screen->r) * screen->depth/8 * sizeof *framebuf);
+	vid.buffer = framebuf;
+	vid.rowbytes = Dx(screen->r) * screen->depth/8;
+	vid.aspect = (float)vid.height / (float)vid.width * (320.0/240.0);
+	vid.conbuffer = vid.buffer;
+	vid.conrowbytes = vid.rowbytes;
+	vid.conwidth = vid.width;
+	vid.conheight = vid.height;
+	center = addpt(screen->r.min, Pt(Dx(screen->r)/2, Dy(screen->r)/2));
+	freeimage(fbim);
+	if((fbim = allocimage(display, Rect(0, 0, vid.width, vid.height), screen->chan, 1, DNofill)) == nil)
+		sysfatal("resetfb:allocimage: %r");
+}
+
+// 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(uchar */*palette*/)
+{
+	vid.maxwarpwidth = WARP_WIDTH;
+	vid.maxwarpheight = WARP_HEIGHT;
+	vid.numpages = 2;
+	vid.colormap = host_colormap;
+	vid.fullbright = 256 - LittleLong(*((int *)vid.colormap + 2048));
+
+	srand(getpid());
+
+	if(initdraw(nil, nil, "quake") < 0)
+		sysfatal("initdraw: %r\n");
+	vid.width = Dx(screen->r);
+	vid.height = Dy(screen->r);
+	resetfb();
+	vid.direct = 0;
+}
+
+void
+VID_ShiftPalette(uchar *p)
+{
+	VID_SetPalette(p);
+}
+
+void
+VID_SetPalette(uchar *palette)
+{
+	int i;
+
+	for(i = 0; i < 256; i++)
+		st2d_8to24table[i] = rgb24(palette[i*3], palette[i*3+1], palette[i*3+2]);
+}
+
+void
+VID_Shutdown(void)
+{
+	Con_Printf("VID_Shutdown\n");
+	free(framebuf);
+	freeimage(fbim);
+}
+
+/* flush given rectangles from view buffer to the screen */
+void
+VID_Update(vrect_t *rects)
+{
+	if(resized){		/* skip this frame if window resize */
+		resized = 0;
+		if(getwindow(display, Refnone) < 0)
+			sysfatal("getwindow: %r");
+		vid.width = Dx(screen->r);
+		vid.height = Dy(screen->r);
+		resetfb();
+		vid.recalc_refdef = 1;	/* force a surface cache flush */
+		Con_CheckResize();
+		Con_Clear_f();
+		return;
+	}
+
+	scr_fullupdate = 0;	/* force full update if not 8bit (cf. screen.h) */
+
+	while(rects){
+		st3_fixup(framebuf, rects->x, rects->y, rects->width, rects->height);
+		rects = rects->pnext;
+	}
+	loadimage(fbim, fbim->r, framebuf, vid.height * vid.rowbytes);
+	draw(screen, screen->r, fbim, nil, ZP);
+	flushimage(display, 1);
+}
+
+/* direct drawing of the "accessing disk" icon */
+void
+D_BeginDirectRect(int x, int y, byte *pbitmap, int width, int height)
+{
+	USED(x, y, pbitmap, width, height);
+}
+
+void
+D_EndDirectRect(int x, int y, int width, int height)
+{
+	USED(x, y, width, height);
+}
--- a/vid_9.c
+++ /dev/null
@@ -1,231 +1,0 @@
-#include <u.h>
-#include <libc.h>
-#include <draw.h>
-#include <stdio.h>
-#include "quakedef.h"
-extern int scr_fullupdate;
-
-int config_notify;
-int ignorenext;
-viddef_t vid;	// global video state
-unsigned short d_8to16table[256];
-int d_con_indirect = 0;
-uchar *framebuf;	/* draw buffer */
-Image *fbim;	/* framebuf image */
-byte current_palette[768];
-int X11_highhunkmark;
-int X11_buffersize;
-int vid_surfcachesize;
-void *vid_surfcache;
-Point center;		/* of window */
-Rectangle grabout;	/* center mouse outside of this if cvar set */
-
-
-typedef u32int PIXEL24;
-PIXEL24 st2d_8to24table[256];
-int shiftmask_fl = 0;
-int r_shift, g_shift, b_shift;
-uint r_mask, g_mask, b_mask;
-
-void (*vid_menudrawfn)(void);
-void (*vid_menukeyfn)(int key);
-
-void shiftmask_init (void)
-{
-	uint x;
-
-	r_mask = 0xff0000;
-	g_mask = 0xff00;
-	b_mask = 0xff;
-	for(r_shift = -8, x = 1; x < r_mask; x <<= 1)
-		r_shift++;
-	for(g_shift = -8, x = 1; x < g_mask; x <<= 1)
-		g_shift++;
-	for(b_shift = -8, x = 1; x < b_mask; x <<= 1)
-		b_shift++;
-	shiftmask_fl = 1;
-}
-
-PIXEL24 rgb24 (int r, int g, int b)
-{
-	PIXEL24 p = 0;
-
-	if(shiftmask_fl == 0)
-		shiftmask_init();
-	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 st3_fixup (uchar *data, int x, int y, int width, int height)
-{
-	int yi;
-	uchar *src;
-	PIXEL24 *dest;
-	register int count, n;
-
-	if(x < 0 || y < 0)
-		return;
-
-	for(yi = y; yi < y+height; yi++){
-		src = &data[yi*vid.rowbytes];
-
-		// 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_8to24table[src[xi]];
-	}
-}
-
-/* vid.height and vid.width must be set correctly before this call */
-void ResetFrameBuffer (void)
-{
-	if(framebuf != nil){
-		free(framebuf);
-		framebuf = nil;
-	}
-
-	if(d_pzbuffer){
-		D_FlushCaches();
-		Hunk_FreeToHighMark(X11_highhunkmark);
-		d_pzbuffer = nil;
-	}
-	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;
-	if((d_pzbuffer = Hunk_HighAllocName(X11_buffersize, "video")) == nil)
-		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);
-
-	framebuf = malloc(sizeof *framebuf * Dx(screen->r) * Dy(screen->r) * screen->depth/8);
-	vid.buffer = framebuf;
-	vid.rowbytes = Dx(screen->r) * screen->depth/8;
-	vid.aspect = (float)vid.height / (float)vid.width * (320.0/240.0);	/* FIXME */
-	vid.conbuffer = vid.buffer;
-	vid.conrowbytes = vid.rowbytes;
-	vid.conwidth = vid.width;
-	vid.conheight = vid.height;
-	center = addpt(screen->r.min, Pt(Dx(screen->r)/2, Dy(screen->r)/2));
-	grabout = insetrect(screen->r, Dx(screen->r)/8);
-	if(fbim != nil)
-		freeimage(fbim);
-	/* FIXME: seems to crash later with DBlack rather than DNofill, why? */
-	fbim = allocimage(display, Rect(0, 0, vid.width, vid.height), screen->chan, 1, DNofill);
-}
-
-// 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 (uchar */*palette*/)
-{
-	ignorenext = 0;
-	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));
-
-	srand(getpid());
-
-	if(initdraw(nil, nil, "quake") < 0)
-		Sys_Error("VID_Init:initdraw: %r\n");
-	vid.width = Dx(screen->r);
-	vid.height = Dy(screen->r);
-	ResetFrameBuffer();
-	vid.direct = 0;
-}
-
-void VID_ShiftPalette (uchar *p)
-{
-	VID_SetPalette(p);
-}
-
-void VID_SetPalette (uchar *palette)
-{
-	int i;
-
-	for(i = 0; i < 256; i++)
-		st2d_8to24table[i] = rgb24(palette[i*3], palette[i*3+1], palette[i*3+2]);
-}
-
-void VID_Shutdown (void)
-{
-	Con_Printf("VID_Shutdown\n");
-	free(framebuf);
-	freeimage(fbim);
-}
-
-/* flush given rectangles from view buffer to the screen */
-void VID_Update (vrect_t *rects)
-{
-	if(config_notify){		/* skip this frame if window resize */
-		config_notify = 0;
-		if(getwindow(display, Refnone) < 0)
-			Sys_Error("VID_Update:getwindow: %r\n");
-		vid.width = Dx(screen->r);
-		vid.height = Dy(screen->r);
-		ResetFrameBuffer();
-		vid.recalc_refdef = 1;			// force a surface cache flush
-		Con_CheckResize();
-		Con_Clear_f();
-		return;
-	}
-
-	scr_fullupdate = 0;	/* force full update if not 8bit (cf. screen.h) */
-
-	while(rects){
-		st3_fixup(framebuf, rects->x, rects->y, rects->width, rects->height);
-		rects = rects->pnext;
-	}
-	loadimage(fbim, fbim->r, framebuf, vid.height * vid.rowbytes);
-	draw(screen, screen->r, fbim, nil, ZP);
-	flushimage(display, 1);
-}
-
-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
-	USED(x, y, pbitmap, width, height);
-}
-
-void D_EndDirectRect (int x, int y, int width, int height)
-{
-	// direct drawing of the "accessing disk" icon isn't supported under Linux
-	USED(x, y, width, height);
-}
--- a/world.c
+++ b/world.c
@@ -230,9 +230,9 @@
 */
 void SV_ClearWorld (void)
 {
-	SV_InitBoxHull ();
-	
-	memset (sv_areanodes, 0, sizeof(sv_areanodes));
+	SV_InitBoxHull();
+
+	memset(sv_areanodes, 0, sizeof sv_areanodes);
 	sv_numareanodes = 0;
 	SV_CreateAreaNode (0, sv.worldmodel->mins, sv.worldmodel->maxs);
 }
@@ -677,7 +677,7 @@
 	hull_t		*hull;
 
 // fill in a default trace
-	memset (&trace, 0, sizeof(trace_t));
+	memset(&trace, 0, sizeof trace);
 	trace.fraction = 1;
 	trace.allsolid = true;
 	VectorCopy (end, trace.endpos);
@@ -824,7 +824,7 @@
 	moveclip_t	clip;
 	int			i;
 
-	memset ( &clip, 0, sizeof ( moveclip_t ) );
+	memset(&clip, 0, sizeof clip);
 
 // clip to world
 	clip.trace = SV_ClipMoveToEntity ( sv.edicts, start, mins, maxs, end );
--- a/zone.c
+++ b/zone.c
@@ -60,7 +60,7 @@
 // set the entire zone to one free block
 
 	zone->blocklist.next = zone->blocklist.prev = block =
-		(memblock_t *)( (byte *)zone + sizeof(memzone_t) );
+		(memblock_t *)((byte *)zone + sizeof(memzone_t));
 	zone->blocklist.tag = 1;	// in use block
 	zone->blocklist.id = 0;
 	zone->blocklist.size = 0;
@@ -85,7 +85,7 @@
 	if (!ptr)
 		Sys_Error ("Z_Free: NULL pointer");
 
-	block = (memblock_t *) ( (byte *)ptr - sizeof(memblock_t));
+	block = (memblock_t *)((uchar *)ptr - sizeof(memblock_t));
 	if (block->id != ZONEID)
 		Sys_Error ("Z_Free: freed a pointer without ZONEID");
 	if (block->tag == 0)
@@ -115,22 +115,16 @@
 	}
 }
 
-
-/*
-========================
-Z_Malloc
-========================
-*/
-void *Z_Malloc (int size)
+void *
+Z_Malloc(int size)
 {
-	void	*buf;
-	
-Z_CheckHeap ();	// DEBUG
-	buf = Z_TagMalloc (size, 1);
-	if (!buf)
-		Sys_Error ("Z_Malloc: failed on allocation of %d bytes",size);
-	Q_memset (buf, 0, size);
+	void *buf;
 
+	Z_CheckHeap();	// DEBUG
+	if((buf = Z_TagMalloc(size, 1)) == nil)
+		Sys_Error("Z_Malloc: failed on allocation of %d bytes", size);
+	memset(buf, 0, size);
+
 	return buf;
 }
 
@@ -349,7 +343,7 @@
 	//
 	// print the single block
 	//
-		memcpy (name, h->name, 8);
+		memcpy(name, h->name, 8);
 		if (all)
 			Con_Printf ("%8p :%8d %8s\n",h, h->size, name);
 			
@@ -399,11 +393,11 @@
 
 	Cache_FreeLow (hunk_low_used);
 
-	memset (h, 0, size);
+	memset(h, 0, size);
 	
 	h->size = size;
 	h->sentinal = HUNK_SENTINAL;
-	Q_strncpy (h->name, name, 8);
+	strncpy(h->name, name, 8);
 	
 	return (void *)(h+1);
 }
@@ -427,7 +421,7 @@
 {
 	if (mark < 0 || mark > hunk_low_used)
 		Sys_Error ("Hunk_FreeToLowMark: bad mark %d", mark);
-	memset (hunk_base + mark, 0, hunk_low_used - mark);
+	memset(hunk_base + mark, 0, hunk_low_used - mark);
 	hunk_low_used = mark;
 }
 
@@ -451,7 +445,7 @@
 	}
 	if (mark < 0 || mark > hunk_high_used)
 		Sys_Error ("Hunk_FreeToHighMark: bad mark %d", mark);
-	memset (hunk_base + hunk_size - hunk_high_used, 0, hunk_high_used - mark);
+	memset(hunk_base + hunk_size - hunk_high_used, 0, hunk_high_used - mark);
 	hunk_high_used = mark;
 }
 
@@ -491,10 +485,10 @@
 
 	h = (hunk_t *)(hunk_base + hunk_size - hunk_high_used);
 
-	memset (h, 0, size);
+	memset(h, 0, size);
 	h->size = size;
 	h->sentinal = HUNK_SENTINAL;
-	Q_strncpy (h->name, name, 8);
+	strncpy(h->name, name, 8);
 
 	return (void *)(h+1);
 }
@@ -564,9 +558,9 @@
 	{
 //		Con_Printf ("cache_move ok\n");
 
-		Q_memcpy ( new+1, c+1, c->size - sizeof(cache_system_t) );
+		memcpy(new+1, c+1, c->size - sizeof *new);
 		new->user = c->user;
-		Q_memcpy (new->name, c->name, sizeof(new->name));
+		memcpy(new->name, c->name, sizeof new->name);
 		Cache_Free (c->user);
 		new->user->data = (void *)(new+1);
 	}
@@ -671,7 +665,7 @@
 			Sys_Error ("Cache_TryAlloc: %d is greater then free hunk", size);
 
 		new = (cache_system_t *) (hunk_base + hunk_low_used);
-		memset (new, 0, sizeof(*new));
+		memset(new, 0, sizeof *new);
 		new->size = size;
 
 		cache_head.prev = cache_head.next = new;
@@ -692,7 +686,7 @@
 		{
 			if ( (byte *)cs - (byte *)new >= size)
 			{	// found space
-				memset (new, 0, sizeof(*new));
+				memset(new, 0, sizeof *new);
 				new->size = size;
 				
 				new->next = cs;
@@ -715,7 +709,7 @@
 // try to allocate one at the very end
 	if ( hunk_base + hunk_size - hunk_high_used - (byte *)new >= size)
 	{
-		memset (new, 0, sizeof(*new));
+		memset(new, 0, sizeof *new);
 		new->size = size;
 		
 		new->next = &cache_head;
@@ -860,7 +854,7 @@
 	if (size <= 0)
 		Sys_Error ("Cache_Alloc: size %d", size);
 
-	size = (size + sizeof(cache_system_t) + 15) & ~15;
+	size = (size + sizeof(*cs) + 15) & ~15;
 
 // find memory for it	
 	while (1)
@@ -907,7 +901,7 @@
 	if (p)
 	{
 		if (p < com_argc-1)
-			zonesize = Q_atoi (com_argv[p+1]) * 1024;
+			zonesize = atoi(com_argv[p+1]) * 1024;
 		else
 			Sys_Error ("Memory_Init: you must specify a size in KB after -zone");
 	}