shithub: qk1

Download patch

ref: 06eb848b99587ef882c121a5a65d2082e3b88aeb
parent: aeb39efc47911c8f992e75838b47198621ba8398
author: Konstantinn Bonnet <qu7uux@gmail.com>
date: Wed Jan 28 14:33:44 EST 2015

amd64 "fixes": some casts and pr_strings shit

no idea if this is ok, but it sort of works.
occasional segfaults when starting a net game.
errors out when starting a new game whilst already ingame (386 too).

--- a/README
+++ b/README
@@ -2,9 +2,19 @@
 =============================
 Does not work. Nothing to see here, move along.
 
-builds only with p9p on linux/386 and amd64, but amd64 build is buggered
-(pr_strings pointer shit, maybe more).
+builds only with p9p on linux/386 and amd64; bugged to hell.
 plan9 shit missing completely, asm not ungccfied.
+
+intrusive changes:
+	- pr_strings: assumed 32bit pointer arithmetic: use PR_GetStr() instead of
+	  dealing with it directly; may be ass
+
+bugs
+----
+	- compile with PARANOID -> MSG_WriteByte complains about range error and
+	  exits.  no idea why. (386/amd64)
+	- new game while already ingame -> R_RenderView: called without enough
+	  stack
 
 
 legal
--- a/common.h
+++ b/common.h
@@ -44,7 +44,7 @@
 // (type *)STRUCT_FROM_LINK(link_t *link, type, member)
 // ent = STRUCT_FROM_LINK(link,entity_t,order)
 // FIXME: remove this mess!
-#define	STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - (int)&(((t *)0)->m)))
+#define	STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - (intptr)&(((t *)0)->m)))
 
 //============================================================================
 
--- a/d_edge.c
+++ b/d_edge.c
@@ -176,7 +176,7 @@
 			d_zistepv = s->d_zistepv;
 			d_ziorigin = s->d_ziorigin;
 
-			D_DrawSolidSurface (s, (int)s->data & 0xFF);
+			D_DrawSolidSurface (s, (intptr)s->data & 0xFF);
 			D_DrawZSpans (s->spans);
 		}
 	}
--- a/d_surf.c
+++ b/d_surf.c
@@ -110,7 +110,7 @@
 D_SCAlloc
 =================
 */
-surfcache_t     *D_SCAlloc (int width, int size)
+surfcache_t     *D_SCAlloc (int width, intptr size)
 {
 	surfcache_t             *new;
 	qboolean                wrapped_this_time;
@@ -121,7 +121,7 @@
 	if ((size <= 0) || (size > 0x10000))
 		Sys_Error ("D_SCAlloc: bad cache size %d\n", size);
 	
-	size = (int)&((surfcache_t *)0)->data[size];
+	size = (intptr)&((surfcache_t *)0)->data[size];
 	size = (size + 3) & ~3;
 	if (size > sc_size)
 		Sys_Error ("D_SCAlloc: %i > cache size",size);
--- a/host_cmd.c
+++ b/host_cmd.c
@@ -918,7 +918,6 @@
 		if (Q_strcmp(host_client->name, newName) != 0)
 			Con_Printf ("%s renamed to %s\n", host_client->name, newName);
 	Q_strcpy (host_client->name, newName);
-	/* FIXME: amd64 */
 	host_client->edict->v.netname = host_client->name - pr_strings;
 	
 // send notification to all clients
@@ -1213,11 +1212,11 @@
 
 		if (sv.paused)
 		{
-			SV_BroadcastPrintf ("%s paused the game\n", pr_strings + sv_player->v.netname);
+			SV_BroadcastPrintf ("%s paused the game\n", PR_Str(sv_player->v.netname));
 		}
 		else
 		{
-			SV_BroadcastPrintf ("%s unpaused the game\n",pr_strings + sv_player->v.netname);
+			SV_BroadcastPrintf ("%s unpaused the game\n", PR_Str(sv_player->v.netname));
 		}
 
 	// send notification to all clients
@@ -1659,7 +1658,7 @@
 	for (i=0 ; i<sv.num_edicts ; i++)
 	{
 		e = EDICT_NUM(i);
-		if ( !strcmp (pr_strings + e->v.classname, "viewthing") )
+		if ( !strcmp (PR_Str(e->v.classname), "viewthing") )
 			return e;
 	}
 	Con_Printf ("No viewthing on map\n");
--- a/pr_cmds.c
+++ b/pr_cmds.c
@@ -43,7 +43,7 @@
 	
 	s = PF_VarString(0);
 	Con_Printf ("======SERVER ERROR in %s:\n%s\n"
-	,pr_strings + pr_xfunction->s_name,s);
+	, PR_Str(pr_xfunction->s_name),s);
 	ed = PROG_TO_EDICT(pr_global_struct->self);
 	ED_Print (ed);
 
@@ -67,7 +67,7 @@
 	
 	s = PF_VarString(0);
 	Con_Printf ("======OBJECT ERROR in %s:\n%s\n"
-	,pr_strings + pr_xfunction->s_name,s);
+	, PR_Str(pr_xfunction->s_name),s);
 	ed = PROG_TO_EDICT(pr_global_struct->self);
 	ED_Print (ed);
 	ED_Free (ed);
@@ -1572,7 +1572,7 @@
 
 	MSG_WriteByte (&sv.signon,svc_spawnstatic);
 
-	MSG_WriteByte (&sv.signon, SV_ModelIndex(pr_strings + ent->v.model));
+	MSG_WriteByte (&sv.signon, SV_ModelIndex(PR_Str(ent->v.model)));
 
 	MSG_WriteByte (&sv.signon, ent->v.frame);
 	MSG_WriteByte (&sv.signon, ent->v.colormap);
--- a/pr_edict.c
+++ b/pr_edict.c
@@ -43,6 +43,14 @@
 
 static gefv_cache	gefvCache[GEFV_CACHESIZE] = {{NULL, ""}, {NULL, ""}};
 
+/* amd64: kludge for assumed 32bit pointer arithmetic */
+char *PR_Str (int ofs)
+{
+	if (((uintptr)pr_strings&0xffffffff)+ofs>>32)
+		return (char *)((uintptr)pr_strings+ofs&0xffffffff);
+	return pr_strings+ofs;
+}
+
 /*
 =================
 ED_ClearEdict
@@ -174,7 +182,7 @@
 	for (i=0 ; i<progs->numfielddefs ; i++)
 	{
 		def = &pr_fielddefs[i];
-		if (!strcmp(pr_strings + def->s_name,name) )
+		if (!strcmp(PR_Str(def->s_name),name) )
 			return def;
 	}
 	return NULL;
@@ -194,7 +202,7 @@
 	for (i=0 ; i<progs->numglobaldefs ; i++)
 	{
 		def = &pr_globaldefs[i];
-		if (!strcmp(pr_strings + def->s_name,name) )
+		if (!strcmp(PR_Str(def->s_name),name) )
 			return def;
 	}
 	return NULL;
@@ -214,7 +222,7 @@
 	for (i=0 ; i<progs->numfunctions ; i++)
 	{
 		func = &pr_functions[i];
-		if (!strcmp(pr_strings + func->s_name,name) )
+		if (!strcmp(PR_Str(func->s_name),name) )
 			return func;
 	}
 	return NULL;
@@ -271,7 +279,7 @@
 	switch (type)
 	{
 	case ev_string:
-		sprintf (line, "%s", pr_strings + val->string);
+		sprintf (line, "%s", PR_Str(val->string));
 		break;
 	case ev_entity:	
 		sprintf (line, "entity %i", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)) );
@@ -278,11 +286,11 @@
 		break;
 	case ev_function:
 		f = pr_functions + val->function;
-		sprintf (line, "%s()", pr_strings + f->s_name);
+		sprintf (line, "%s()", PR_Str(f->s_name));
 		break;
 	case ev_field:
 		def = ED_FieldAtOfs ( val->_int );
-		sprintf (line, ".%s", pr_strings + def->s_name);
+		sprintf (line, ".%s", PR_Str(def->s_name));
 		break;
 	case ev_void:
 		sprintf (line, "void");
@@ -323,7 +331,7 @@
 	switch (type)
 	{
 	case ev_string:
-		sprintf (line, "%s", pr_strings + val->string);
+		sprintf (line, "%s", PR_Str(val->string));
 		break;
 	case ev_entity:	
 		sprintf (line, "%i", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)));
@@ -330,11 +338,11 @@
 		break;
 	case ev_function:
 		f = pr_functions + val->function;
-		sprintf (line, "%s", pr_strings + f->s_name);
+		sprintf (line, "%s", PR_Str(f->s_name));
 		break;
 	case ev_field:
 		def = ED_FieldAtOfs ( val->_int );
-		sprintf (line, "%s", pr_strings + def->s_name);
+		sprintf (line, "%s", PR_Str(def->s_name));
 		break;
 	case ev_void:
 		sprintf (line, "void");
@@ -376,7 +384,7 @@
 	else
 	{
 		s = PR_ValueString (def->type, val);
-		sprintf (line,"%i(%s)%s", ofs, pr_strings + def->s_name, s);
+		sprintf (line,"%i(%s)%s", ofs, PR_Str(def->s_name), s);
 	}
 	
 	i = strlen(line);
@@ -397,7 +405,7 @@
 	if (!def)
 		sprintf (line,"%i(???)", ofs);
 	else
-		sprintf (line,"%i(%s)", ofs, pr_strings + def->s_name);
+		sprintf (line,"%i(%s)", ofs, PR_Str(def->s_name));
 	
 	i = strlen(line);
 	for ( ; i<20 ; i++)
@@ -434,7 +442,7 @@
 	for (i=1 ; i<progs->numfielddefs ; i++)
 	{
 		d = &pr_fielddefs[i];
-		name = pr_strings + d->s_name;
+		name = PR_Str(d->s_name);
 		if (name[strlen(name)-2] == '_')
 			continue;	// skip _x, _y, _z vars
 			
@@ -484,7 +492,7 @@
 	for (i=1 ; i<progs->numfielddefs ; i++)
 	{
 		d = &pr_fielddefs[i];
-		name = pr_strings + d->s_name;
+		name = PR_Str(d->s_name);
 		if (name[strlen(name)-2] == '_')
 			continue;	// skip _x, _y, _z vars
 			
@@ -617,7 +625,7 @@
 		&& type != ev_entity)
 			continue;
 
-		name = pr_strings + def->s_name;		
+		name = PR_Str(def->s_name);		
 		fprintf (f,"\"%s\" ", name);
 		fprintf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs]));		
 	}
@@ -942,7 +950,7 @@
 		}
 
 	// look for the spawn function
-		func = ED_FindFunction ( pr_strings + ent->v.classname );
+		func = ED_FindFunction ( PR_Str(ent->v.classname) );
 
 		if (!func)
 		{
--- a/pr_exec.c
+++ b/pr_exec.c
@@ -190,7 +190,7 @@
 			Con_Printf ("<NO FUNCTION>\n");
 		}
 		else
-			Con_Printf ("%12s : %s\n", pr_strings + f->s_file, pr_strings + f->s_name);		
+			Con_Printf ("%12s : %s\n", PR_Str(f->s_file), PR_Str(f->s_name));		
 	}
 }
 
@@ -225,7 +225,7 @@
 		if (best)
 		{
 			if (num < 10)
-				Con_Printf ("%7i %s\n", best->profile, pr_strings+best->s_name);
+				Con_Printf ("%7i %s\n", best->profile, PR_Str(best->s_name));
 			num++;
 			best->profile = 0;
 		}
@@ -465,7 +465,7 @@
 		c->_float = !a->vector[0] && !a->vector[1] && !a->vector[2];
 		break;
 	case OP_NOT_S:
-		c->_float = !a->string || !pr_strings[a->string];
+		c->_float = !a->string || !*PR_Str(a->string);
 		break;
 	case OP_NOT_FNC:
 		c->_float = !a->function;
@@ -482,9 +482,8 @@
 					(a->vector[1] == b->vector[1]) &&
 					(a->vector[2] == b->vector[2]);
 		break;
-	/* FIXME: amd64 */
 	case OP_EQ_S:
-		c->_float = !strcmp(pr_strings+a->string,pr_strings+b->string);
+		c->_float = !strcmp(PR_Str(a->string),PR_Str(b->string));
 		break;
 	case OP_EQ_E:
 		c->_float = a->_int == b->_int;
@@ -502,9 +501,8 @@
 					(a->vector[1] != b->vector[1]) ||
 					(a->vector[2] != b->vector[2]);
 		break;
-	/* FIXME: amd64 */
 	case OP_NE_S:
-		c->_float = strcmp(pr_strings+a->string,pr_strings+b->string);
+		c->_float = strcmp(PR_Str(a->string),PR_Str(b->string));
 		break;
 	case OP_NE_E:
 		c->_float = a->_int != b->_int;
--- a/progs.h
+++ b/progs.h
@@ -48,6 +48,8 @@
 void PR_ExecuteProgram (func_t fnum);
 void PR_LoadProgs (void);
 
+char	*PR_Str (int ofs);
+
 void PR_Profile_f (void);
 
 edict_t *ED_Alloc (void);
@@ -84,7 +86,7 @@
 #define G_EDICTNUM(o) NUM_FOR_EDICT(G_EDICT(o))
 #define	G_VECTOR(o) (&pr_globals[o])
 /* FIXME: amd64 */
-#define	G_STRING(o) (pr_strings + *(string_t *)&pr_globals[o])
+#define	G_STRING(o) (PR_Str(*(string_t *)&pr_globals[o]))
 #define	G_FUNCTION(o) (*(func_t *)&pr_globals[o])
 
 #define	E_FLOAT(e,o) (((float*)&e->v)[o])
@@ -91,7 +93,7 @@
 #define	E_INT(e,o) (*(int *)&((float*)&e->v)[o])
 #define	E_VECTOR(e,o) (&((float*)&e->v)[o])
 /* FIXME: amd64 */
-#define	E_STRING(e,o) (pr_strings + *(string_t *)&((float*)&e->v)[o])
+#define	E_STRING(e,o) (PR_Str(*(string_t *)&((float*)&e->v)[o]))
 
 extern	int		type_size[8];
 
@@ -114,3 +116,7 @@
 
 eval_t *GetEdictFieldValue(edict_t *ed, char *field);
 
+void M_Init (void);
+void M_Keydown (int key);
+void M_ToggleMenu_f (void);
+void M_Draw (void);
--- a/quakedef.h
+++ b/quakedef.h
@@ -11,7 +11,7 @@
 #define	LINUX_VERSION		1.30
 #define	X11_VERSION			1.10
 
-#define	PARANOID			// speed sapping error checking
+//#define	PARANOID			// speed sapping error checking
 #define	GAMENAME	"id1"		// directory to look in by default
 
 #include <stdio.h>
--- a/snd_mem.c
+++ b/snd_mem.c
@@ -218,7 +218,7 @@
 		memcpy (str, data_p, 4);
 		data_p += 4;
 		iff_chunk_len = GetLittleLong();
-		Con_Printf ("0x%x : %s (%d)\n", (int)(data_p - 4), str, iff_chunk_len);
+		Con_Printf ("0x%x : %s (%d)\n", (intptr)(data_p - 4), str, iff_chunk_len);
 		data_p += (iff_chunk_len + 1) & ~1;
 	} while (data_p < iff_end);
 }
--- a/sv_main.c
+++ b/sv_main.c
@@ -187,7 +187,7 @@
 	else
 		MSG_WriteByte (&client->message, GAME_COOP);
 
-	sprintf (message, pr_strings+sv.edicts->v.message);
+	sprintf (message, PR_Str(sv.edicts->v.message));
 
 	MSG_WriteString (&client->message,message);
 
@@ -435,7 +435,7 @@
 		if (ent != clent)	// clent is ALLWAYS sent
 		{
 // ignore ents without visible models
-			if (!ent->v.modelindex || !pr_strings[ent->v.model])
+			if (!ent->v.modelindex || !*PR_Str(ent->v.model))
 				continue;
 
 			for (i=0 ; i < ent->num_leafs ; i++)
@@ -670,7 +670,7 @@
 	if (bits & SU_ARMOR)
 		MSG_WriteByte (msg, ent->v.armorvalue);
 	if (bits & SU_WEAPON)
-		MSG_WriteByte (msg, SV_ModelIndex(pr_strings+ent->v.weaponmodel));
+		MSG_WriteByte (msg, SV_ModelIndex(PR_Str(ent->v.weaponmodel)));
 	
 	MSG_WriteShort (msg, ent->v.health);
 	MSG_WriteByte (msg, ent->v.currentammo);
@@ -937,8 +937,7 @@
 		{
 			svent->baseline.colormap = 0;
 			svent->baseline.modelindex =
-				/* FIXME: amd64 */
-				SV_ModelIndex(pr_strings + svent->v.model);
+				SV_ModelIndex(PR_Str(svent->v.model));
 		}
 		
 	//
@@ -1142,7 +1141,6 @@
 	ent = EDICT_NUM(0);
 	memset (&ent->v, 0, progs->entityfields * 4);
 	ent->free = false;
-	/* FIXME FIXME FIXME: amd64 */
 	ent->v.model = sv.worldmodel->name - pr_strings;
 	ent->v.modelindex = 1;		// world model
 	ent->v.solid = SOLID_BSP;
--- a/sv_phys.c
+++ b/sv_phys.c
@@ -79,12 +79,12 @@
 	{
 		if (IS_NAN(ent->v.velocity[i]))
 		{
-			Con_Printf ("Got a NaN velocity on %s\n", pr_strings + ent->v.classname);
+			Con_Printf ("Got a NaN velocity on %s\n", PR_Str(ent->v.classname));
 			ent->v.velocity[i] = 0;
 		}
 		if (IS_NAN(ent->v.origin[i]))
 		{
-			Con_Printf ("Got a NaN origin on %s\n", pr_strings + ent->v.classname);
+			Con_Printf ("Got a NaN origin on %s\n", PR_Str(ent->v.classname));
 			ent->v.origin[i] = 0;
 		}
 		if (ent->v.velocity[i] > sv_maxvelocity.value)