shithub: qk1

Download patch

ref: 6214f75fcfebb25f277b7063ba215924c81f6dd4
parent: dfc609a2f90e1e1a3d107007b2adb0845ebf78f0
author: Konstantinn Bonnet <[email protected]>
date: Sat Mar 11 22:43:37 EST 2017

clean up initialization code

- move sys stuff to qk1.c
- remove some useless variables and checks
- fs: handle basedir in initns and minimal error checking when adding dirs
- reduce redundancy in error messages originating from openlmp
- misc typos

--- a/cl_demo.c
+++ b/cl_demo.c
@@ -158,7 +158,7 @@
 	CL_Disconnect();
 	a = Cmd_Argv(1);
 	s = va("%s%s", a, ext(a, ".dem"));
-	dprint("playdemo: writing to file %s\n", s);
+	dprint("playdemo: reading file %s\n", s);
 	if(loaddm(s) < 0){
 		Con_Printf("playdemo: %r\n");
 		cls.demonum = -1;
--- a/cl_parse.c
+++ b/cl_parse.c
@@ -166,7 +166,7 @@
 	memcpy (net_message.data, olddata, net_message.cursize);
 
 // check time
-	time = Sys_FloatTime ();
+	time = dtime ();
 	if (time - lastmsg < 5)
 		return;
 	lastmsg = time;
--- a/cmd.c
+++ b/cmd.c
@@ -275,7 +275,7 @@
 	mark = Hunk_LowMark ();
 	f = loadhunklmp(Cmd_Argv(1), nil);
 	if(f == nil){
-		Con_Printf("couldn't exec %s: %r\n", Cmd_Argv(1));
+		Con_Printf("exec: %r\n");
 		return;
 	}
 	Con_Printf ("execing %s\n",Cmd_Argv(1));
--- a/dat.h
+++ b/dat.h
@@ -1,5 +1,8 @@
 typedef struct Sfx Sfx;
 
+extern uchar *membase;
+extern int memsize;
+
 enum{
 	Npath = 64,
 	Nfspath = 128,
--- a/draw.c
+++ b/draw.c
@@ -70,7 +70,7 @@
 //
 	dat = loadcachelmp(path, &pic->cache);
 	if(dat == nil)
-		fatal("Draw_CachePic: failed to load %s: %r", path);
+		fatal("Draw_CachePic: %r");
 
 	SwapPic (dat);
 
--- a/fns.h
+++ b/fns.h
@@ -1,3 +1,5 @@
+char*	Sys_ConsoleInput(void);
+void	Sys_SendKeyEvents(void);
 void	stepcd(void);
 void	stepsnd(vec3_t, vec3_t, vec3_t, vec3_t);
 void	stopcd(void);
@@ -43,6 +45,12 @@
 void	initfs(void);
 void	dprint(char*, ...);
 void	fatal(char*, ...);
+void*	emalloc(ulong);
+vlong	flen(int);
+double	dtime(void);
+void	fppsgl(void);
+void	fppdbl(void);
+void	shutdown(void);
 
 #pragma	varargck	argpos	dprint	1
 #pragma varargck	argpos	fatal	1
--- a/fs.c
+++ b/fs.c
@@ -315,11 +315,8 @@
 			continue;
 		}
 		snprint(d, sizeof d, "%s/%s", pl->f, f);
-		if(access(d, AREAD) < 0)
+		if(bf = bopen(d, OREAD, 1), bf == nil)
 			continue;
-		bf = bopen(d, OREAD, 1);
-		if(bf == nil)
-			return nil;
 		if(len != nil)
 			*len = bsize(bf);
 		return bf;
@@ -449,7 +446,7 @@
 {
 	Biobuf *bf;
 
-	if(!host_initialized || isDedicated)
+	if(!host_initialized)
 		return;
 	bf = bopen(va("%s/config.cfg", fsdir), OWRITE, 1);
 	if(bf == nil){
@@ -543,7 +540,7 @@
 		if(t != ev_string && t != ev_float && t != ev_entity)
 			continue;
 		Bprint(bf, "\"%s\" \"%s\"\n", PR_Str(d->s_name),
-			PR_UglyValueString(t, (eval_t *)&pr_globals[d->ofs]));		
+			PR_UglyValueString(t, (eval_t *)&pr_globals[d->ofs]));
 	}
 	Bprint(bf, "}\n");
 }
@@ -843,7 +840,7 @@
 		pl = Hunk_Alloc(sizeof *pl);
 		pl->p = p;
 		pl->pl = pkl;
-		pkl = pl;       
+		pkl = pl;
 	}
 }
 
@@ -851,17 +848,27 @@
 initns(void)
 {
 	int i;
-	char d[Nfspath], *e;
+	char d[Nfspath], *e, *home;
 
 	memset(d, 0, sizeof d);
 	i = COM_CheckParm("-basedir");
-	if(i != 0 && i < com_argc - 1)
+	if(i != 0 && i < com_argc - 1){
 		strncpy(d, com_argv[i+1], sizeof(d)-1);
-	else
-		strncpy(d, host_parms.basedir, sizeof(d)-1);
-	e = d + strlen(d) - 1;
-	if(e > d && *e == '/')
-		*e = 0;
+		e = d + strlen(d) - 1;
+		if(e > d && *e == '/')
+			*e = 0;
+	}else if(home = getenv("home"), home != nil){
+		snprint(d, sizeof d, "%s/lib/quake", home);
+		free(home);
+	}
+	if(strlen(d) == 0 || access(d, AREAD) < 0){
+		strncpy(d, "/sys/games/lib/quake", sizeof(d)-1);
+		if(access(d, AREAD) < 0){
+			strncpy(d, "/sys/lib/quake", sizeof(d)-1);
+			if(access(d, AREAD) < 0)
+				fatal("no accessible game directory");
+		}
+	}
 	pakdir(va("%s%s", d, "/id1"));
 	if(COM_CheckParm("-rogue"))
 		pakdir(va("%s%s", d, "/rogue"));
--- a/host.c
+++ b/host.c
@@ -15,8 +15,6 @@
 
 */
 
-quakeparms_t host_parms;
-
 qboolean	host_initialized;		// true if into command execution
 
 double		host_frametime;
@@ -27,8 +25,6 @@
 
 int			host_hunklevel;
 
-int			minimum_memory;
-
 client_t	*host_client;			// current client
 
 jmp_buf 	host_abortserver;
@@ -358,7 +354,7 @@
 		CL_Disconnect ();
 
 // flush any pending messages - like the score!!!
-	start = Sys_FloatTime();
+	start = dtime();
 	do
 	{
 		count = 0;
@@ -378,7 +374,7 @@
 				}
 			}
 		}
-		if ((Sys_FloatTime() - start) > 3.0)
+		if ((dtime() - start) > 3.0f)
 			break;
 	}
 	while (count);
@@ -554,12 +550,12 @@
 
 // update video
 	if (host_speeds.value)
-		time1 = Sys_FloatTime ();
+		time1 = dtime ();
 		
 	SCR_UpdateScreen ();
 
 	if (host_speeds.value)
-		time2 = Sys_FloatTime ();
+		time2 = dtime ();
 		
 // update audio
 	if (cls.signon == SIGNONS)
@@ -575,7 +571,7 @@
 	if (host_speeds.value)
 	{
 		pass1 = (time1 - time3)*1000;
-		time3 = Sys_FloatTime ();
+		time3 = dtime ();
 		pass2 = (time2 - time1)*1000;
 		pass3 = (time3 - time2)*1000;
 		Con_Printf ("%3d tot %3d server %3d gfx %3d snd\n",
@@ -598,9 +594,9 @@
 		return;
 	}
 	
-	time1 = Sys_FloatTime ();
+	time1 = dtime ();
 	_Host_Frame (time);
-	time2 = Sys_FloatTime ();	
+	time2 = dtime ();	
 	
 	timetotal += time2 - time1;
 	timecount++;
@@ -626,26 +622,9 @@
 Host_Init
 ====================
 */
-void Host_Init (quakeparms_t *parms)
+void Host_Init (void)
 {
-
-	if (standard_quake)
-		minimum_memory = MINIMUM_MEMORY;
-	else
-		minimum_memory = MINIMUM_MEMORY_LEVELPAK;
-
-	if (COM_CheckParm ("-minmemory"))
-		parms->memsize = minimum_memory;
-
-	host_parms = *parms;
-
-	if (parms->memsize < minimum_memory)
-		fatal ("Only %4.1f megs of memory available, can't execute game", parms->memsize / (float)0x100000);
-
-	com_argc = parms->argc;
-	com_argv = parms->argv;
-
-	Memory_Init (parms->membase, parms->memsize);
+	Memory_Init();
 	Cbuf_Init ();
 	Cmd_Init ();	
 	V_Init ();
@@ -660,10 +639,7 @@
 	Mod_Init ();
 	NET_Init ();
 	SV_Init ();
-
-	Con_Printf ("Exe: 00:00:00 Jun 22 1996\n");
-	Con_Printf ("%4.1f megabyte heap\n",parms->memsize/ (1024*1024.0));
-	
+	dprint("%4.1f megabyte heap\n", memsize / (1024 * 1024.0));
 	R_InitTextures ();		// needed even for dedicated servers
  
 	if (cls.state != ca_dedicated)
@@ -670,10 +646,10 @@
 	{
 		host_basepal = loadhunklmp("gfx/palette.lmp", nil);
 		if(host_basepal == nil)
-			fatal("Host_Init: failed to load gfx/palette.lmp: %r");
+			fatal("Host_Init: %r");
 		host_colormap = loadhunklmp("gfx/colormap.lmp", nil);
 		if(host_colormap == nil)
-			fatal("Host_Init: failed to load gfx/colormap.lmp: %r");
+			fatal("Host_Init: %r");
 
 		VID_Init (host_basepal);
 
@@ -702,7 +678,7 @@
 ===============
 Host_Shutdown
 
-FIXME: this is a callback from Sys_Quit and fatal.  It would be better
+FIXME: this is a callback from shutdown and fatal.  It would be better
 to run quit through here before the final handoff to the sys code.
 ===============
 */
--- a/host_cmd.c
+++ b/host_cmd.c
@@ -24,7 +24,7 @@
 	CL_Disconnect ();
 	Host_ShutdownServer(false);		
 
-	Sys_Quit ();
+	shutdown ();
 }
 
 
@@ -773,7 +773,7 @@
 		pr_global_struct->self = EDICT_TO_PROG(sv_player);
 		PR_ExecuteProgram (pr_global_struct->ClientConnect);
 
-		if ((Sys_FloatTime() - host_client->netconnection->connecttime) <= sv.time)
+		if ((dtime() - host_client->netconnection->connecttime) <= sv.time)
 			print("%s entered the game\n", host_client->name);
 
 		PR_ExecuteProgram (pr_global_struct->PutClientInServer);	
--- a/in.c
+++ b/in.c
@@ -177,7 +177,7 @@
 	Rune r;
 	Kev ev;
 
-	threadsetgrp(THin);
+	threadsetgrp(1);
 
 	kdown[1] = kdown[0] = 0;
 	if((fd = open("/dev/kbd", OREAD)) < 0)
@@ -228,7 +228,7 @@
 	char buf[1+5*12];
 	float x, y;
 
-	threadsetgrp(THin);
+	threadsetgrp(1);
 
 	if((fd = open("/dev/mouse", ORDWR)) < 0)
 		sysfatal("open /dev/mouse: %r");
@@ -274,7 +274,7 @@
 	int n;
 	char s[256];
 
-	threadsetgrp(THin);
+	threadsetgrp(1);
 
 	for(;;){
 		if((n = read(0, s, sizeof s)) <= 0)
@@ -309,7 +309,7 @@
 IN_Shutdown(void)
 {
 	IN_Grabm(0);
-	threadintgrp(THin);
+	threadintgrp(1);
 	if(pfd[0] > 0)
 		close(pfd[0]);
 	if(pfd[1] > 0)
--- a/mkfile
+++ b/mkfile
@@ -65,7 +65,6 @@
 	sv_move.$O\
 	sv_phys.$O\
 	sv_user.$O\
-	sys.$O\
 	vid.$O\
 	view.$O\
 	wad.$O\
@@ -105,7 +104,6 @@
 	screen.h\
 	server.h\
 	spritegn.h\
-	sys.h\
 	vid.h\
 	view.h\
 	wad.h\
--- a/net_main.c
+++ b/net_main.c
@@ -73,7 +73,7 @@
 
 double SetNetTime(void)
 {
-	net_time = Sys_FloatTime();
+	net_time = dtime();
 	return net_time;
 }
 
@@ -282,7 +282,7 @@
 	}
 
 	slistInProgress = true;
-	slistStartTime = Sys_FloatTime();
+	slistStartTime = dtime();
 
 	SchedulePollProcedure(&slistSendProcedure, 0.0);
 	SchedulePollProcedure(&slistPollProcedure, 0.1);
@@ -302,7 +302,7 @@
 		dfunc.SearchForHosts (true);
 	}
 
-	if ((Sys_FloatTime() - slistStartTime) < 0.5)
+	if ((dtime() - slistStartTime) < 0.5)
 		SchedulePollProcedure(&slistSendProcedure, 0.75);
 }
 
@@ -321,7 +321,7 @@
 	if (! slistSilent)
 		PrintSlist();
 
-	if ((Sys_FloatTime() - slistStartTime) < 1.5)
+	if ((dtime() - slistStartTime) < 1.5)
 	{
 		SchedulePollProcedure(&slistPollProcedure, 0.1);
 		return;
@@ -633,7 +633,7 @@
 		}
 	}
 
-	start = Sys_FloatTime();
+	start = dtime();
 	while (count)
 	{
 		count = 0;
@@ -668,7 +668,7 @@
 				continue;
 			}
 		}
-		if ((Sys_FloatTime() - start) > blocktime)
+		if ((dtime() - start) > blocktime)
 			break;
 	}
 	return count;
@@ -826,7 +826,7 @@
 {
 	PollProcedure *pp, *prev;
 
-	proc->nextTime = Sys_FloatTime() + timeOffset;
+	proc->nextTime = dtime() + timeOffset;
 	for (pp = pollProcedureList, prev = nil; pp; pp = pp->next)
 	{
 		if (pp->nextTime >= proc->nextTime)
--- a/qk1.c
+++ b/qk1.c
@@ -1,9 +1,19 @@
 #include <u.h>
 #include <libc.h>
+#include <thread.h>
 #include "dat.h"
 #include "quakedef.h"
 #include "fns.h"
 
+mainstacksize = 512*1024;
+uchar *membase;
+int memsize;
+
+enum{
+	KB = 1024*1024,
+	Nmem = 8 * KB
+};
+
 static int debug;
 
 void
@@ -33,4 +43,96 @@
 	Host_Shutdown();
 	fprint(2, "%s: %s\n", argv0, s);
 	exits(s);
+}
+
+void *
+emalloc(ulong n)
+{
+	void *p;
+
+	if(p = mallocz(n, 1), p == nil)
+		sysfatal("emalloc %r");
+	setmalloctag(p, getcallerpc(&n));
+	return p;
+}
+
+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;
+}
+
+double
+dtime(void)
+{
+	static double t0;
+
+	if(t0 == 0.0)
+		t0 = time(nil);
+	return nsec() / 1000000000.0 - t0;
+}
+
+void
+fppdbl(void)
+{
+}
+
+void
+fppsgl(void)
+{
+}
+
+void
+shutdown(void)
+{
+	Host_Shutdown();
+	threadexitsall(nil);
+}
+
+static void
+croak(void *, char *note)
+{
+	if(strncmp(note, "sys:", 4) == 0)
+		IN_Grabm(0);
+	noted(NDFLT);
+}
+
+void
+threadmain(int c, char **v)
+{
+	int n;
+	double t, t´, Δt;
+
+	/* ignore fp exceptions: rendering shit assumes they are */
+	setfcr(getfcr() & ~(FPOVFL|FPUNFL|FPINVAL|FPZDIV));
+	notify(croak);
+	COM_InitArgv(c, v);
+	argv0 = *v;
+	memsize = Nmem;
+	if(n = COM_CheckParm("-mem"))
+		memsize = atoi(com_argv[n+1]) * KB;
+	membase = emalloc(memsize);
+	Host_Init();
+	t = dtime() - 1.0 / Fpsmax;
+	for(;;){
+		t´ = dtime();
+		Δt = t´ - t;
+		if(cls.state == ca_dedicated){
+			if(Δt < sys_ticrate.value)
+				continue;
+			Δt = sys_ticrate.value;
+        	}
+		if(Δt > sys_ticrate.value * 2)
+			t = t´;
+		else
+			t += Δt;
+		Host_Frame(Δt);
+	}
 }
--- a/quakedef.h
+++ b/quakedef.h
@@ -13,10 +13,6 @@
 // !!! if this is changed, it must be changed in d_ifacea.h too !!!
 #define CACHE_SIZE	32		// used to align key data structures
 
-/* FIXME? wrong on !386? */
-#define	MINIMUM_MEMORY			0x550000
-#define	MINIMUM_MEMORY_LEVELPAK	(MINIMUM_MEMORY + 0x100000)
-
 #define MAX_NUM_ARGVS	50
 
 // up / down
@@ -145,7 +141,6 @@
 #include "common.h"
 #include "bspfile.h"
 #include "vid.h"
-#include "sys.h"
 #include "zone.h"
 #include "mathlib.h"
 
@@ -193,26 +188,6 @@
 #include "r_local.h"
 #include "d_local.h"
 
-//=============================================================================
-
-// the host system specifies the base of the directory tree, the
-// command line parms passed to the program, and the amount of memory
-// available for the program to use
-
-typedef struct
-{
-	char	*basedir;
-	int		argc;
-	char	**argv;
-	void	*membase;
-	int		memsize;
-} quakeparms_t;
-
-
-//=============================================================================
-
-
-
 extern qboolean noclip_anglehack;
 
 
@@ -219,8 +194,6 @@
 //
 // host
 //
-extern	quakeparms_t host_parms;
-
 extern	cvar_t		sys_ticrate;
 
 extern	qboolean	host_initialized;		// true if into command execution
@@ -234,7 +207,7 @@
 void Host_ClearMemory (void);
 void Host_ServerFrame (void);
 void Host_InitCommands (void);
-void Host_Init (quakeparms_t *parms);
+void Host_Init (void);
 void Host_Shutdown(void);
 void Host_Error (char *error, ...);
 void Host_EndGame (char *message, ...);
@@ -249,10 +222,6 @@
 extern int			current_skill;		// skill level for currently loaded level (in case
 										//  the user changes the cvar while the level is
 										//  running, this reflects the level actually in use)
-
-extern qboolean		isDedicated;
-
-extern int			minimum_memory;
 
 //
 // chase
--- a/r_main.c
+++ b/r_main.c
@@ -856,7 +856,7 @@
 
 	if (r_dspeeds.value)
 	{
-		rw_time1 = Sys_FloatTime ();
+		rw_time1 = dtime ();
 	}
 
 	R_RenderWorld ();
@@ -870,7 +870,7 @@
 
 	if (r_dspeeds.value)
 	{
-		rw_time2 = Sys_FloatTime ();
+		rw_time2 = dtime ();
 		db_time1 = rw_time2;
 	}
 
@@ -878,7 +878,7 @@
 
 	if (r_dspeeds.value)
 	{
-		db_time2 = Sys_FloatTime ();
+		db_time2 = dtime ();
 		se_time1 = db_time2;
 	}
 	
@@ -901,7 +901,7 @@
 	r_warpbuffer = warpbuffer;
 
 	if (r_timegraph.value || r_speeds.value || r_dspeeds.value)
-		r_time1 = Sys_FloatTime ();
+		r_time1 = dtime ();
 
 	R_SetupFrame ();
 
@@ -916,7 +916,7 @@
 // while, so we don't do it globally.  This also sets chop mode, and we do it
 // here so that setup stuff like the refresh area calculations match what's
 // done in screen.c
-	Sys_LowFPPrecision ();
+	fppsgl ();
 
 	if (!cl_entities[0].model || !cl.worldmodel)
 		fatal ("R_RenderView: NULL worldmodel");
@@ -925,7 +925,7 @@
 	
 	if (r_dspeeds.value)
 	{
-		se_time2 = Sys_FloatTime ();
+		se_time2 = dtime ();
 		de_time1 = se_time2;
 	}
 
@@ -933,7 +933,7 @@
 
 	if (r_dspeeds.value)
 	{
-		de_time2 = Sys_FloatTime ();
+		de_time2 = dtime ();
 		dv_time1 = de_time2;
 	}
 
@@ -941,14 +941,14 @@
 
 	if (r_dspeeds.value)
 	{
-		dv_time2 = Sys_FloatTime ();
-		dp_time1 = Sys_FloatTime ();
+		dv_time2 = dtime ();
+		dp_time1 = dtime ();
 	}
 
 	R_DrawParticles ();
 
 	if (r_dspeeds.value)
-		dp_time2 = Sys_FloatTime ();
+		dp_time2 = dtime ();
 
 	if (r_dowarp)
 		D_WarpScreen ();
@@ -974,7 +974,7 @@
 		Con_Printf ("Short roughly %d edges\n", r_outofedges * 2 / 3);
 
 // back to high floating-point precision
-	Sys_HighFPPrecision ();
+	fppdbl ();
 }
 
 void R_RenderView (void)
--- a/r_misc.c
+++ b/r_misc.c
@@ -56,7 +56,7 @@
 
 	startangle = r_refdef.viewangles[1];
 	
-	start = Sys_FloatTime ();
+	start = dtime ();
 	for (i=0 ; i<128 ; i++)
 	{
 		r_refdef.viewangles[1] = i/128.0*360.0;
@@ -74,7 +74,7 @@
 		vr.pnext = nil;
 		VID_Update (&vr);
 	}
-	stop = Sys_FloatTime ();
+	stop = dtime ();
 	time = stop-start;
 	Con_Printf ("%f seconds (%f fps)\n", time, 128/time);
 	
@@ -136,7 +136,7 @@
 	static byte	r_timings[MAX_TIMINGS];
 	int		x;
 	
-	r_time2 = Sys_FloatTime ();
+	r_time2 = dtime ();
 
 	a = (r_time2-r_time1)/0.01;
 //a = fabs(mouse_y * 0.05);
@@ -177,7 +177,7 @@
 	float	r_time2;
 	float		ms;
 
-	r_time2 = Sys_FloatTime ();
+	r_time2 = dtime ();
 
 	ms = 1000* (r_time2 - r_time1);
 	
@@ -196,7 +196,7 @@
 {
 	float	ms, dp_time, r_time2, rw_time, db_time, se_time, de_time, dv_time;
 
-	r_time2 = Sys_FloatTime ();
+	r_time2 = dtime ();
 
 	dp_time = (dp_time2 - dp_time1) * 1000;
 	rw_time = (rw_time2 - rw_time1) * 1000;
--- a/snd.c
+++ b/snd.c
@@ -607,7 +607,7 @@
 		return;
 	nt -= 1;	/* d001 assumed part of track list */
 	if(nt < 1 || nt > ntrk){
-		fprint(2, "startcd: invalid track number %ud\n", nt);
+		fprint(2, "startcd: invalid track number %d\n", nt);
 		return;
 	}
 	if(cdfd = open(va("%s%03d", cdfile, nt), OREAD), cdfd < 0){
@@ -972,7 +972,7 @@
 	Cvar_RegisterVariable(&ambient_level);
 	Cvar_RegisterVariable(&ambient_fade);
 
-	if(host_parms.memsize < 0x800000){
+	if(memsize < 0x800000){
 		setcvar("loadas8bit", "1");
 		fprint(2, "initsnd: forcing 8bit width\n");
 	}
--- a/sys.c
+++ /dev/null
@@ -1,124 +1,0 @@
-#include <u.h>
-#include <libc.h>
-#include <thread.h>
-#include "dat.h"
-#include "quakedef.h"
-#include "fns.h"
-
-qboolean isDedicated;
-mainstacksize = 512*1024;
-
-void
-Sys_Quit(void)
-{
-	Host_Shutdown();
-	threadexitsall(nil);
-}
-
-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;
-}
-
-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();
-	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() - 1.0 / Fpsmax;
-	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
+++ /dev/null
@@ -1,15 +1,0 @@
-// sys.h -- non-portable functions
-
-enum{
-	THin	= 1,
-	THnet	= 3
-};
-
-void	Sys_Quit(void);
-void	Sys_LowFPPrecision(void);
-void	Sys_HighFPPrecision(void);
-void*	emalloc(ulong);
-vlong	flen(int);
-double	Sys_FloatTime(void);
-char*	Sys_ConsoleInput(void);
-void	Sys_SendKeyEvents(void);	// call Key_Event() until the input queue is empty
--- a/wad.c
+++ b/wad.c
@@ -57,7 +57,7 @@
 
 	wad_base = loadhunklmp(filename, nil);
 	if(wad_base == nil)
-		fatal("W_LoadWadFile: failed to load %s: %r", filename);
+		fatal("W_LoadWadFile: %r");
 
 	header = (wadinfo_t *)wad_base;
 	
--- a/zone.c
+++ b/zone.c
@@ -249,9 +249,6 @@
 	char	name[8];
 } hunk_t;
 
-byte	*hunk_base;
-int		hunk_size;
-
 int		hunk_low_used;
 int		hunk_high_used;
 
@@ -271,11 +268,11 @@
 {
 	hunk_t	*h;
 	
-	for (h = (hunk_t *)hunk_base ; (byte *)h != hunk_base + hunk_low_used ; )
+	for (h = (hunk_t *)membase ; (byte *)h != membase + hunk_low_used ; )
 	{
 		if (h->sentinal != HUNK_SENTINAL)
 			fatal ("Hunk_Check: trahsed sentinal");
-		if (h->size < 16 || h->size + (byte *)h - hunk_base > hunk_size)
+		if (h->size < 16 || h->size + (byte *)h - membase > memsize)
 			fatal ("Hunk_Check: bad size");
 		h = (hunk_t *)((byte *)h+h->size);
 	}
@@ -301,12 +298,12 @@
 	sum = 0;
 	totalblocks = 0;
 	
-	h = (hunk_t *)hunk_base;
-	endlow = (hunk_t *)(hunk_base + hunk_low_used);
-	starthigh = (hunk_t *)(hunk_base + hunk_size - hunk_high_used);
-	endhigh = (hunk_t *)(hunk_base + hunk_size);
+	h = (hunk_t *)membase;
+	endlow = (hunk_t *)(membase + hunk_low_used);
+	starthigh = (hunk_t *)(membase + memsize - hunk_high_used);
+	endhigh = (hunk_t *)(membase + memsize);
 
-	Con_Printf ("          :%8d total hunk size\n", hunk_size);
+	Con_Printf ("          :%8d total hunk size\n", memsize);
 	Con_Printf ("-------------------------\n");
 
 	while (1)
@@ -317,7 +314,7 @@
 		if ( h == endlow )
 		{
 			Con_Printf ("-------------------------\n");
-			Con_Printf ("          :%8d REMAINING\n", hunk_size - hunk_low_used - hunk_high_used);
+			Con_Printf ("          :%8d REMAINING\n", memsize - hunk_low_used - hunk_high_used);
 			Con_Printf ("-------------------------\n");
 			h = starthigh;
 		}
@@ -333,7 +330,7 @@
 	//
 		if (h->sentinal != HUNK_SENTINAL)
 			fatal ("Hunk_Check: trahsed sentinal");
-		if (h->size < 16 || h->size + (byte *)h - hunk_base > hunk_size)
+		if (h->size < 16 || h->size + (byte *)h - membase > memsize)
 			fatal ("Hunk_Check: bad size");
 			
 		next = (hunk_t *)((byte *)h+h->size);
@@ -386,10 +383,10 @@
 		
 	size = sizeof(hunk_t) + ((size+15)&~15);
 	
-	if (hunk_size - hunk_low_used - hunk_high_used < size)
+	if (memsize - hunk_low_used - hunk_high_used < size)
 		fatal ("Hunk_Alloc: failed on %d bytes",size);
 	
-	h = (hunk_t *)(hunk_base + hunk_low_used);
+	h = (hunk_t *)(membase + hunk_low_used);
 	hunk_low_used += size;
 
 	Cache_FreeLow (hunk_low_used);
@@ -422,7 +419,7 @@
 {
 	if (mark < 0 || mark > hunk_low_used)
 		fatal ("Hunk_FreeToLowMark: bad mark %d", mark);
-	memset(hunk_base + mark, 0, hunk_low_used - mark);
+	memset(membase + mark, 0, hunk_low_used - mark);
 	hunk_low_used = mark;
 }
 
@@ -446,7 +443,7 @@
 	}
 	if (mark < 0 || mark > hunk_high_used)
 		fatal ("Hunk_FreeToHighMark: bad mark %d", mark);
-	memset(hunk_base + hunk_size - hunk_high_used, 0, hunk_high_used - mark);
+	memset(membase + memsize - hunk_high_used, 0, hunk_high_used - mark);
 	hunk_high_used = mark;
 }
 
@@ -475,7 +472,7 @@
 
 	size = sizeof(hunk_t) + ((size+15)&~15);
 
-	if (hunk_size - hunk_low_used - hunk_high_used < size)
+	if (memsize - hunk_low_used - hunk_high_used < size)
 	{
 		Con_Printf ("Hunk_HighAlloc: failed on %d bytes\n",size);
 		return nil;
@@ -484,7 +481,7 @@
 	hunk_high_used += size;
 	Cache_FreeHigh (hunk_high_used);
 
-	h = (hunk_t *)(hunk_base + hunk_size - hunk_high_used);
+	h = (hunk_t *)(membase + memsize - hunk_high_used);
 
 	memset(h, 0, size);
 	h->size = size;
@@ -589,7 +586,7 @@
 		c = cache_head.next;
 		if (c == &cache_head)
 			return;		// nothing in cache at all
-		if ((byte *)c >= hunk_base + new_low_hunk)
+		if ((byte *)c >= membase + new_low_hunk)
 			return;		// there is space to grow the hunk
 		Cache_Move ( c );	// reclaim the space
 	}
@@ -612,7 +609,7 @@
 		c = cache_head.prev;
 		if (c == &cache_head)
 			return;		// nothing in cache at all
-		if ( (byte *)c + c->size <= hunk_base + hunk_size - new_high_hunk)
+		if ( (byte *)c + c->size <= membase + memsize - new_high_hunk)
 			return;		// there is space to grow the hunk
 		if (c == prev)
 			Cache_Free (c->user);	// didn't move out of the way
@@ -662,10 +659,10 @@
 
 	if (!nobottom && cache_head.prev == &cache_head)
 	{
-		if (hunk_size - hunk_high_used - hunk_low_used < size)
+		if (memsize - hunk_high_used - hunk_low_used < size)
 			fatal ("Cache_TryAlloc: %d is greater then free hunk", size);
 
-		new = (cache_system_t *) (hunk_base + hunk_low_used);
+		new = (cache_system_t *) (membase + hunk_low_used);
 		memset(new, 0, sizeof *new);
 		new->size = size;
 
@@ -678,7 +675,7 @@
 	
 // search from the bottom up for space
 
-	new = (cache_system_t *) (hunk_base + hunk_low_used);
+	new = (cache_system_t *) (membase + hunk_low_used);
 	cs = cache_head.next;
 	
 	do
@@ -708,7 +705,7 @@
 	} while (cs != &cache_head);
 	
 // try to allocate one at the very end
-	if ( hunk_base + hunk_size - hunk_high_used - (byte *)new >= size)
+	if ( membase + memsize - hunk_high_used - (byte *)new >= size)
 	{
 		memset(new, 0, sizeof *new);
 		new->size = size;
@@ -743,7 +740,7 @@
 Cache_Report(void)
 {
 	print("%4.1f megabyte data cache\n",
-		(hunk_size - hunk_high_used - hunk_low_used)
+		(memsize - hunk_high_used - hunk_low_used)
 		/ (float)(1024*1024));
 }
 
@@ -849,21 +846,11 @@
 	return Cache_Check (c);
 }
 
-//============================================================================
-
-
-/*
-========================
-Memory_Init
-========================
-*/
-void Memory_Init (void *buf, int size)
+void Memory_Init (void)
 {
 	int p;
 	int zonesize = DYNAMIC_SIZE;
 
-	hunk_base = buf;
-	hunk_size = size;
 	hunk_low_used = 0;
 	hunk_high_used = 0;
 	
@@ -879,4 +866,3 @@
 	mainzone = Hunk_AllocName (zonesize, "zone" );
 	Z_ClearZone (mainzone, zonesize);
 }
-
--- a/zone.h
+++ b/zone.h
@@ -64,7 +64,7 @@
 
 */
 
-void Memory_Init (void *buf, int size);
+void Memory_Init (void);
 
 void Z_Free (void *ptr);
 void *Z_Malloc (int size);			// returns 0 filled memory