shithub: wl3d

Download patch

ref: 3364baa681f3f9c2e4b60405bfcf81dd6f825e37
parent: a12936c5120110c9dc786581cac43e86efe21ba9
author: Konstantinn Bonnet <qu7uux@gmail.com>
date: Wed Mar 16 10:39:52 EDT 2016

implement loading data and handle versions

- one executable for all supported versions: wl1, wl6, sdm, sod, sd2, sd3
- nuke caching and memory management, uncompressing and loading all useful data
  into memory directly on startup: still below 5M, which is hardly a concern on
  a 9front system
- arrange data on load to deal with the differences between versions
- nuke useless code, jukebox (sorry robert), music names; rename sounds and pics,
  purge unused

--- a/act1.c
+++ b/act1.c
@@ -472,7 +472,7 @@
 			+doorobjlist[door].tilex)-AREATILE;
 	if (areabyplayer[area])
 	{
-		PlaySoundLocTile(CLOSEDOORSND,doorobjlist[door].tilex,doorobjlist[door].tiley);	// JAB
+		PlaySoundLocTile(Sclosedoor,doorobjlist[door].tilex,doorobjlist[door].tiley);	// JAB
 	}
 
 	doorobjlist[door].action = dr_closing;
@@ -504,7 +504,7 @@
 	{
 		if ( ! (gamestate.keys & (1 << (lock-dr_lock1) ) ) )
 		{
-			SD_PlaySound (NOWAYSND);		// locked
+			SD_PlaySound (Snoway);		// locked
 			return;
 		}
 	}
@@ -583,7 +583,7 @@
 		ConnectAreas ();
 		if (areabyplayer[area1])
 		{
-			PlaySoundLocTile(OPENDOORSND,doorobjlist[door].tilex,doorobjlist[door].tiley);	// JAB
+			PlaySoundLocTile(Sopendoor,doorobjlist[door].tilex,doorobjlist[door].tiley);	// JAB
 		}
 	}
 
@@ -746,7 +746,7 @@
 	case di_north:
 		if (actorat[checkx][checky-1])
 		{
-			SD_PlaySound (NOWAYSND);
+			SD_PlaySound (Snoway);
 			return;
 		}
 		(u16int)actorat[checkx][checky-1] =
@@ -756,7 +756,7 @@
 	case di_east:
 		if (actorat[checkx+1][checky])
 		{
-			SD_PlaySound (NOWAYSND);
+			SD_PlaySound (Snoway);
 			return;
 		}
 		(u16int)actorat[checkx+1][checky] =
@@ -766,7 +766,7 @@
 	case di_south:
 		if (actorat[checkx][checky+1])
 		{
-			SD_PlaySound (NOWAYSND);
+			SD_PlaySound (Snoway);
 			return;
 		}
 		(u16int)actorat[checkx][checky+1] =
@@ -776,7 +776,7 @@
 	case di_west:
 		if (actorat[checkx-1][checky])
 		{
-			SD_PlaySound (NOWAYSND);
+			SD_PlaySound (Snoway);
 			return;
 		}
 		(u16int)actorat[checkx-1][checky] =
@@ -793,7 +793,7 @@
 	tilemap[pwallx][pwally] |= 0xc0;
 	*(mapsegs[1]+farmapylookup[pwally]+pwallx) = 0;	// remove P tile info
 
-	SD_PlaySound (PUSHWALLSND);
+	SD_PlaySound (Spushwall);
 }
 
 
--- a/act2.c
+++ b/act2.c
@@ -325,13 +325,13 @@
 	{
 		if (ob->obclass == rocketobj)
 		{
-			PlaySoundLocActor(MISSILEHITSND,ob);
+			PlaySoundLocActor(Smissilehit,ob);
 			ob->state = &s_boom1;
 		}
 #ifdef SPEAR
 		else if (ob->obclass == hrocketobj)
 		{
-			PlaySoundLocActor(MISSILEHITSND,ob);
+			PlaySoundLocActor(Srockethit,ob);
 			ob->state = &s_hboom1;
 		}
 #endif
@@ -1074,7 +1074,7 @@
 	  case officerobj:
 	  case ssobj:
 	  case dogobj:
-		PlaySoundLocActor(DEATHSCREAM6SND,ob);
+		PlaySoundLocActor(Sscream6,ob);
 		return;
 	 }
 	}
@@ -1083,19 +1083,19 @@
 	switch (ob->obclass)
 	{
 	case mutantobj:
-		PlaySoundLocActor(AHHHGSND,ob);
+		PlaySoundLocActor(Smutdeath,ob);
 		break;
 
 	case guardobj:
 		{
-		 s16int sounds[9]={ DEATHSCREAM1SND,
-				 DEATHSCREAM2SND,
-				 DEATHSCREAM3SND,
-				 DEATHSCREAM4SND,
-				 DEATHSCREAM5SND,
-				 DEATHSCREAM7SND,
-				 DEATHSCREAM8SND,
-				 DEATHSCREAM9SND
+		 s16int sounds[9]={ Sscream1,
+				 Sscream2,
+				 Sscream3,
+				 Sscream4,
+				 Sscream5,
+				 Sscream7,
+				 Sscream8,
+				 Sscream9
 				 };
 
 		 #ifndef UPLOAD
@@ -1106,57 +1106,57 @@
 		}
 		break;
 	case officerobj:
-		PlaySoundLocActor(NEINSOVASSND,ob);
+		PlaySoundLocActor(Soffcdeath,ob);
 		break;
 	case ssobj:
-		PlaySoundLocActor(LEBENSND,ob);	// JAB
+		PlaySoundLocActor(Sssdeath,ob);	// JAB
 		break;
 	case dogobj:
-		PlaySoundLocActor(DOGDEATHSND,ob);	// JAB
+		PlaySoundLocActor(Sdogdeath,ob);	// JAB
 		break;
 #ifndef SPEAR
 	case bossobj:
-		SD_PlaySound(MUTTISND);				// JAB
+		SD_PlaySound(Shansdeath);				// JAB
 		break;
 	case schabbobj:
-		SD_PlaySound(MEINGOTTSND);
+		SD_PlaySound(Sschbdeath);
 		break;
 	case fakeobj:
-		SD_PlaySound(HITLERHASND);
+		SD_PlaySound(Shilter);
 		break;
 	case mechahitlerobj:
-		SD_PlaySound(SCHEISTSND);
+		SD_PlaySound(Smechadeath);
 		break;
 	case realhitlerobj:
-		SD_PlaySound(EVASND);
+		SD_PlaySound(Seva);
 		break;
 	case gretelobj:
-		SD_PlaySound(MEINSND);
+		SD_PlaySound(Sgreteldeath);
 		break;
 	case giftobj:
-		SD_PlaySound(DONNERSND);
+		SD_PlaySound(Sottodeath);
 		break;
 	case fatobj:
-		SD_PlaySound(ROSESND);
+		SD_PlaySound(Sfettdeath);
 		break;
 #else
 	case spectreobj:
-		SD_PlaySound(GHOSTFADESND);
+		SD_PlaySound(Sghostdeath);
 		break;
 	case angelobj:
-		SD_PlaySound(ANGELDEATHSND);
+		SD_PlaySound(Sangeldeath);
 		break;
 	case transobj:
-		SD_PlaySound(TRANSDEATHSND);
+		SD_PlaySound(Stransdeath);
 		break;
 	case uberobj:
-		SD_PlaySound(UBERDEATHSND);
+		SD_PlaySound(Suberdeath);
 		break;
 	case willobj:
-		SD_PlaySound(WILHELMDEATHSND);
+		SD_PlaySound(Swilhdeath);
 		break;
 	case deathobj:
-		SD_PlaySound(KNIGHTDEATHSND);
+		SD_PlaySound(Sknightdeath);
 		break;
 #endif
 	}
@@ -1664,15 +1664,15 @@
 	case deathobj:
 		new->state = &s_hrocket;
 		new->obclass = hrocketobj;
-		PlaySoundLocActor (KNIGHTMISSILESND,new);
+		PlaySoundLocActor (Sknightmissile,new);
 		break;
 	case angelobj:
 		new->state = &s_spark1;
 		new->obclass = sparkobj;
-		PlaySoundLocActor (ANGELFIRESND,new);
+		PlaySoundLocActor (Sangelfire,new);
 		break;
 	default:
-		PlaySoundLocActor (MISSILEFIRESND,new);
+		PlaySoundLocActor (Sthrow,new);
 	}
 
 	new->dir = nodir;
@@ -1774,13 +1774,13 @@
 #pragma argsused
 void A_Slurpie (objtype *ob)
 {
- SD_PlaySound(SLURPIESND);
+ SD_PlaySound(Sslurp);
 }
 
 #pragma argsused
 void A_Breathing (objtype *ob)
 {
- SD_PlaySound(ANGELTIREDSND);
+ SD_PlaySound(Sangeltired);
 }
 
 /*
@@ -2325,7 +2325,7 @@
 	new->flags = FL_NONMARK;
 	new->active = true;
 
-	PlaySoundLocActor (SCHABBSTHROWSND,new);
+	PlaySoundLocActor (Sthrow,new);
 }
 
 /*
@@ -2364,7 +2364,7 @@
 	new->flags = FL_NONMARK;
 	new->active = true;
 
-	PlaySoundLocActor (MISSILEFIRESND,new);
+	PlaySoundLocActor (Smissile,new);
 }
 
 
@@ -2912,7 +2912,7 @@
 void A_MechaSound (objtype *ob)
 {
 	if (areabyplayer[ob->areanumber])
-		PlaySoundLocActor (MECHSTEPSND,ob);
+		PlaySoundLocActor (Smechwalk,ob);
 }
 
 
@@ -2919,7 +2919,7 @@
 #pragma argsused
 void A_Slurpie (objtype *ob)
 {
- SD_PlaySound(SLURPIESND);
+ SD_PlaySound(Sslurp);
 }
 
 /*
@@ -2958,7 +2958,7 @@
 	new->flags = FL_NEVERMARK;
 	new->active = true;
 
-	PlaySoundLocActor (FLAMETHROWERSND,new);
+	PlaySoundLocActor (Sflame,new);
 }
 
 
@@ -3493,27 +3493,27 @@
 	switch(ob->obclass)
 	{
 	 case ssobj:
-	   PlaySoundLocActor(SSFIRESND,ob);
+	   PlaySoundLocActor(Sssfire,ob);
 	   break;
 #ifndef SPEAR
 	 case giftobj:
 	 case fatobj:
-	   PlaySoundLocActor(MISSILEFIRESND,ob);
+	   PlaySoundLocActor(Smissile,ob);
 	   break;
 	 case mechahitlerobj:
 	 case realhitlerobj:
 	 case bossobj:
-	   PlaySoundLocActor(BOSSFIRESND,ob);
+	   PlaySoundLocActor(Shansfire,ob);
 	   break;
 	 case schabbobj:
-	   PlaySoundLocActor(SCHABBSTHROWSND,ob);
+	   PlaySoundLocActor(Sthrow,ob);
 	   break;
 	 case fakeobj:
-	   PlaySoundLocActor(FLAMETHROWERSND,ob);
+	   PlaySoundLocActor(Sflame,ob);
 	   break;
 #endif
 	 default:
-	   PlaySoundLocActor(NAZIFIRESND,ob);
+	   PlaySoundLocActor(Sgdfire,ob);
 	}
 
 }
@@ -3533,7 +3533,7 @@
 	s16int	hitchance,damage;
 
 
-	PlaySoundLocActor(DOGATTACKSND,ob);	// JAB
+	PlaySoundLocActor(Sdogfire,ob);	// JAB
 
 	dx = player->x - ob->x;
 	if (dx<0)
@@ -3697,7 +3697,7 @@
 
 void T_BJYell (objtype *ob)
 {
-	PlaySoundLocActor(YEAHSND,ob);	// JAB
+	PlaySoundLocActor(Syeah,ob);	// JAB
 }
 
 
@@ -3786,7 +3786,6 @@
 
 	PM_UnlockMainMem ();
 	CA_UpLevel ();
-	CacheLump(LEVELEND_LUMP_START,LEVELEND_LUMP_END);
 	Write(0,7,STR_SEEAGAIN);
 	CA_DownLevel ();
 	PM_CheckMainMem ();
--- a/agent.c
+++ b/agent.c
@@ -273,10 +273,10 @@
 	{
 		#ifdef SPEAR
 		if (godmode)
-			StatusDrawPic (17,4,GODMODEFACE1PIC+gamestate.faceframe);
+			StatusDrawPic (17,4,Pgod+gamestate.faceframe);
 		else
 		#endif
-		StatusDrawPic (17,4,FACE1APIC+3*((100-gamestate.health)/16)+gamestate.faceframe);
+		StatusDrawPic (17,4,Pface1+3*((100-gamestate.health)/16)+gamestate.faceframe);
 	}
 	else
 	{
@@ -285,7 +285,7 @@
 	   StatusDrawPic (17,4,MUTANTBJPIC);
 	 else
 #endif
-	   StatusDrawPic (17,4,FACE8APIC);
+	   StatusDrawPic (17,4,Pface8);
 	}
 }
 
@@ -307,7 +307,7 @@
 void	UpdateFace (void)
 {
 
-	if (SD_SoundPlaying() == GETGATLINGSND)
+	if (SD_SoundPlaying() == Sgetgatling)
 	  return;
 
 	facecount += tics;
@@ -345,7 +345,7 @@
 
 	while (length<width)
 	{
-		StatusDrawPic (x,y,N_BLANKPIC);
+		StatusDrawPic (x,y,Pblank);
 		x++;
 		width--;
 	}
@@ -354,7 +354,7 @@
 
 	while (c<length)
 	{
-		StatusDrawPic (x,y,str[c]-'0'+ N_0PIC);
+		StatusDrawPic (x,y,str[c]-'0'+ Pn0);
 		x++;
 		c++;
 	}
@@ -415,7 +415,7 @@
 	#ifdef SPEAR
 	if (points > 30 && gamestate.health!=0 && !godmode)
 	{
-		StatusDrawPic (17,4,BJOUCHPIC);
+		StatusDrawPic (17,4,Pouch);
 		facecount = 0;
 	}
 	#endif
@@ -494,7 +494,7 @@
 	if (gamestate.lives<9)
 		gamestate.lives++;
 	DrawLives ();
-	SD_PlaySound (BONUS1UPSND);
+	SD_PlaySound (S1up);
 }
 
 //===========================================================================
@@ -543,7 +543,7 @@
 
 void DrawWeapon (void)
 {
-	StatusDrawPic (32,8,KNIFEPIC+gamestate.weapon);
+	StatusDrawPic (32,8,Pknife+gamestate.weapon);
 }
 
 
@@ -558,14 +558,14 @@
 void DrawKeys (void)
 {
 	if (gamestate.keys & 1)
-		StatusDrawPic (30,4,GOLDKEYPIC);
+		StatusDrawPic (30,4,Pgkey);
 	else
-		StatusDrawPic (30,4,NOKEYPIC);
+		StatusDrawPic (30,4,Pnokey);
 
 	if (gamestate.keys & 2)
-		StatusDrawPic (30,20,SILVERKEYPIC);
+		StatusDrawPic (30,20,Pskey);
 	else
-		StatusDrawPic (30,20,NOKEYPIC);
+		StatusDrawPic (30,20,Pnokey);
 }
 
 
@@ -672,7 +672,7 @@
 		if (gamestate.health == 100)
 			return;
 
-		SD_PlaySound (HEALTH2SND);
+		SD_PlaySound (Shealth2);
 		HealSelf (25);
 		break;
 
@@ -681,26 +681,26 @@
 	case	bo_key3:
 	case	bo_key4:
 		GiveKey (check->itemnumber - bo_key1);
-		SD_PlaySound (GETKEYSND);
+		SD_PlaySound (Sgetkey);
 		break;
 
 	case	bo_cross:
-		SD_PlaySound (BONUS1SND);
+		SD_PlaySound (Sbonus1);
 		GivePoints (100);
 		gamestate.treasurecount++;
 		break;
 	case	bo_chalice:
-		SD_PlaySound (BONUS2SND);
+		SD_PlaySound (Sbonus2);
 		GivePoints (500);
 		gamestate.treasurecount++;
 		break;
 	case	bo_bible:
-		SD_PlaySound (BONUS3SND);
+		SD_PlaySound (Sbonus3);
 		GivePoints (1000);
 		gamestate.treasurecount++;
 		break;
 	case	bo_crown:
-		SD_PlaySound (BONUS4SND);
+		SD_PlaySound (Sbonus4);
 		GivePoints (5000);
 		gamestate.treasurecount++;
 		break;
@@ -709,7 +709,7 @@
 		if (gamestate.ammo == 99)
 			return;
 
-		SD_PlaySound (GETAMMOSND);
+		SD_PlaySound (Sgetammo);
 		GiveAmmo (8);
 		break;
 	case	bo_clip2:
@@ -716,7 +716,7 @@
 		if (gamestate.ammo == 99)
 			return;
 
-		SD_PlaySound (GETAMMOSND);
+		SD_PlaySound (Sgetammo);
 		GiveAmmo (4);
 		break;
 
@@ -725,26 +725,26 @@
 		if (gamestate.ammo == 99)
 		  return;
 
-		SD_PlaySound (GETAMMOBOXSND);
+		SD_PlaySound (Sammobox);
 		GiveAmmo (25);
 		break;
 #endif
 
 	case	bo_machinegun:
-		SD_PlaySound (GETMACHINESND);
+		SD_PlaySound (Sgetmg);
 		GiveWeapon (wp_machinegun);
 		break;
 	case	bo_chaingun:
-		SD_PlaySound (GETGATLINGSND);
+		SD_PlaySound (Sgetgatling);
 		GiveWeapon (wp_chaingun);
 
-		StatusDrawPic (17,4,GOTGATLINGPIC);
+		StatusDrawPic (17,4,Pgat);
 		facecount = 0;
 		gotgatgun = 1;
 		break;
 
 	case	bo_fullheal:
-		SD_PlaySound (BONUS1UPSND);
+		SD_PlaySound (S1up);
 		HealSelf (99);
 		GiveAmmo (25);
 		GiveExtraMan ();
@@ -755,7 +755,7 @@
 		if (gamestate.health == 100)
 			return;
 
-		SD_PlaySound (HEALTH1SND);
+		SD_PlaySound (Shealth1);
 		HealSelf (10);
 		break;
 
@@ -763,7 +763,7 @@
 		if (gamestate.health == 100)
 			return;
 
-		SD_PlaySound (HEALTH1SND);
+		SD_PlaySound (Shealth1);
 		HealSelf (4);
 		break;
 
@@ -771,7 +771,7 @@
 		if (gamestate.health >10)
 			return;
 
-		SD_PlaySound (SLURPIESND);
+		SD_PlaySound (Sslurp);
 		HealSelf (1);
 		break;
 
@@ -881,7 +881,7 @@
 		return;		// walk through walls
 
 	if (!SD_SoundPlaying())
-		SD_PlaySound (HITWALLSND);
+		SD_PlaySound (Shitwall);
 
 	ob->x = basex+xmove;
 	ob->y = basey;
@@ -1066,7 +1066,7 @@
 			playstate = ex_secretlevel;
 		else
 			playstate = ex_completed;
-		SD_PlaySound (LEVELDONESND);
+		SD_PlaySound (Slvlend);
 		SD_WaitSoundDone();
 	}
 	else if (!buttonheld[bt_use] && doornum & 0x80)
@@ -1075,7 +1075,7 @@
 		OperateDoor (doornum & ~0x80);
 	}
 	else
-		SD_PlaySound (DONOTHINGSND);
+		SD_PlaySound (Snope);
 
 }
 
@@ -1135,7 +1135,7 @@
 	objtype *check,*closest;
 	s32int	dist;
 
-	SD_PlaySound (ATKKNIFESND);
+	SD_PlaySound (Sknife);
 // actually fire
 	dist = 0x7fffffff;
 	closest = NULL;
@@ -1175,13 +1175,13 @@
 	switch (gamestate.weapon)
 	{
 	case wp_pistol:
-		SD_PlaySound (ATKPISTOLSND);
+		SD_PlaySound (Spistol);
 		break;
 	case wp_machinegun:
-		SD_PlaySound (ATKMACHINEGUNSND);
+		SD_PlaySound (Smg);
 		break;
 	case wp_chaingun:
-		SD_PlaySound (ATKGATLINGSND);
+		SD_PlaySound (Sgatling);
 		break;
 	}
 
--- a/audio.h
+++ /dev/null
@@ -1,206 +1,0 @@
-/*#define UPLOAD*/	/* wolf3d demo */
-/*#define SPEAR*/	/* sod */
-/*#define SPEARDEMO*/	/* sod demo, needs SPEAR defined */
-
-typedef enum{
-	/* wl? sfx */
-	HITWALLSND,
-	SELECTWPNSND,
-	SELECTITEMSND,
-	HEARTBEATSND,
-	MOVEGUN2SND,
-	MOVEGUN1SND,
-	NOWAYSND,
-	NAZIHITPLAYERSND,
-	SCHABBSTHROWSND,
-	PLAYERDEATHSND,
-	DOGDEATHSND,
-	ATKGATLINGSND,
-	GETKEYSND,
-	NOITEMSND,
-	WALK1SND,
-	WALK2SND,
-	TAKEDAMAGESND,
-	GAMEOVERSND,
-	OPENDOORSND,
-	CLOSEDOORSND,
-	DONOTHINGSND,
-	HALTSND,
-	DEATHSCREAM2SND,
-	ATKKNIFESND,
-	ATKPISTOLSND,
-	DEATHSCREAM3SND,
-	ATKMACHINEGUNSND,
-	HITENEMYSND,
-	SHOOTDOORSND,
-	DEATHSCREAM1SND,
-	GETMACHINESND,
-	GETAMMOSND,
-	SHOOTSND,
-	HEALTH1SND,
-	HEALTH2SND,
-	BONUS1SND,
-	BONUS2SND,
-	BONUS3SND,
-	GETGATLINGSND,
-	ESCPRESSEDSND,
-	LEVELDONESND,
-	DOGBARKSND,
-	ENDBONUS1SND,
-	ENDBONUS2SND,
-	BONUS1UPSND,
-	BONUS4SND,
-	PUSHWALLSND,
-	NOBONUSSND,
-	PERCENT100SND,
-	BOSSACTIVESND,
-	MUTTISND,
-	SCHUTZADSND,
-	AHHHGSND,
-	DIESND,
-	EVASND,
-	GUTENTAGSND,
-	LEBENSND,
-	SCHEISTSND,
-	NAZIFIRESND,
-	BOSSFIRESND,
-	SSFIRESND,
-	SLURPIESND,
-	TOT_HUNDSND,
-	MEINGOTTSND,
-	SCHABBSHASND,
-	HITLERHASND,
-	SPIONSND,
-	NEINSOVASSND,
-	DOGATTACKSND,
-	FLAMETHROWERSND,
-	MECHSTEPSND,
-	GOOBSSND,
-	YEAHSND,
-	DEATHSCREAM4SND,
-	DEATHSCREAM5SND,
-	DEATHSCREAM6SND,
-	DEATHSCREAM7SND,
-	DEATHSCREAM8SND,
-	DEATHSCREAM9SND,
-	DONNERSND,
-	EINESND,
-	ERLAUBENSND,
-	KEINSND,
-	MEINSND,
-	ROSESND,
-	MISSILEFIRESND,
-	MISSILEHITSND,
-	SEND,
-
-	/* wl1 specific */
-	NAZIMISSSND = SCHABBSTHROWSND,
-	BOSSDIESSND = MUTTISND,
-	MUTTI1SND = SCHEISTSND,
-	S1END = FLAMETHROWERSND,
-
-	/* sod specific */
-	MISSILEHITSSND = SELECTWPNSND,
-	GHOSTSIGHTSND = HEARTBEATSND,
-	MISSILEFIRESSND = SCHABBSTHROWSND,
-	DEATHSCREAM4SSND = MUTTISND,
-	DEATHSCREAM5SSND = DIESND,
-	DEATHSCREAM7SSND = EVASND,
-	DEATHSCREAM8SSND = GUTENTAGSND,
-	DEATHSCREAM6SSND = SCHEISTSND,
-	GHOSTFADESND = TOT_HUNDSND,
-	DEATHSCREAM9SSND = MEINGOTTSND,
-	GETAMMOBOXSND = SCHABBSHASND,
-	ANGELSIGHTSND = HITLERHASND,
-	ANGELFIRESND = FLAMETHROWERSND,
-	TRANSSIGHTSND = MECHSTEPSND,
-	TRANSDEATHSND = GOOBSSND,
-	WILHELMSIGHTSND = YEAHSND,
-	WILHELMDEATHSND = DEATHSCREAM4SND,
-	UBERDEATHSND = DEATHSCREAM5SND,
-	KNIGHTSIGHTSND = DEATHSCREAM6SND,
-	KNIGHTDEATHSND = DEATHSCREAM7SND,
-	ANGELDEATHSND = DEATHSCREAM8SND,
-	KNIGHTMISSILESND = DEATHSCREAM9SND,
-	GETSPEARSND = DONNERSND,
-	ANGELTIREDSND = EINESND,
-	SSEND = ERLAUBENSND
-}soundnames;
-
-typedef enum{
-	/* wl? imf */
-	CORNER_MUS,
-	DUNGEON_MUS,
-	WARMARCH_MUS,
-	GETTHEM_MUS,
-	HEADACHE_MUS,
-	HITLWLTZ_MUS,
-	INTROCW3_MUS,
-	NAZI_NOR_MUS,
-	NAZI_OMI_MUS,
-	POW_MUS,
-	SALUTE_MUS,
-	SEARCHN_MUS,
-	SUSPENSE_MUS,
-	VICTORS_MUS,
-	WONDERIN_MUS,
-	FUNKYOU_MUS,
-	ENDLEVEL_MUS,
-	GOINGAFT_MUS,
-	PREGNANT_MUS,
-	ULTIMATE_MUS,
-	NAZI_RAP_MUS,
-	ZEROHOUR_MUS,
-	TWELFTH_MUS,
-	ROSTER_MUS,
-	URAHERO_MUS,
-	VICMARCH_MUS,
-	PACMAN_MUS,
-	MEND,
-
-	/* wl1 specific */
-	GETOUT_MUS = WARMARCH_MUS,
-	WARMRCH1_MUS = PACMAN_MUS,
-	M1END = MEND,
-
-	/* sod specific */
-	XFUNKIE_MUS = CORNER_MUS,
-	XDEATH_MUS = WARMARCH_MUS,
-	XTIPTOE_MUS = HEADACHE_MUS,
-	GOINGAFTS_MUS = HITLWLTZ_MUS,
-	URAHEROS_MUS = INTROCW3_MUS,
-	XTHEEND_MUS = NAZI_NOR_MUS,
-	TWELFTHS_MUS = SALUTE_MUS,
-	ZEROHOURS_MUS = VICTORS_MUS,
-	ULTIMATES_MUS = FUNKYOU_MUS,
-	XEVIL_MUS = GOINGAFT_MUS,
-	XJAZNAZI_MUS = PREGNANT_MUS,
-	COPYPRO_MUS = ULTIMATE_MUS,
-	XAWARD_MUS = NAZI_RAP_MUS,
-	XPUTIT_MUS = ZEROHOUR_MUS,
-	XGETYOU_MUS = TWELFTH_MUS,
-	XTOWER2_MUS = ROSTER_MUS,
-	MSEND = URAHERO_MUS
-}musicnames;
-
-enum{
-#ifdef SPEAR
-	LASTSOUND = SSEND,
-	LASTMUSIC = MSEND,
-#endif
-#ifdef UPLOAD
-	LASTSOUND = S1END,
-	LASTMUSIC = M1END,
-#endif
-#ifndef SPEAR
-#ifndef UPLOAD
-	LASTSOUND = SEND,
-	LASTMUSIC = MEND,
-#endif
-#endif
-	STARTPCSOUNDS = 0,
-	STARTADLIBSOUNDS = LASTSOUND,
-	STARTMUSIC = LASTSOUND * 3,
-	NUMSOUNDS = LASTSOUND,
-	NUMSNDCHUNKS = STARTMUSIC + LASTMUSIC
-};
--- a/ca.c
+++ b/ca.c
@@ -1,124 +1,14 @@
-// ID_CA.C
-
-// this has been customized for WOLF
-
-/*
-=============================================================================
-
-Id Software Caching Manager
----------------------------
-
-Must be started BEFORE the memory manager, because it needs to get the headers
-loaded into the data segment
-
-=============================================================================
-*/
-
-#include "ID_HEADS.H"
-#pragma hdrstop
-
-#pragma warn -pro
-#pragma warn -use
-
-#define THREEBYTEGRSTARTS
-
-/*
-=============================================================================
-
-						 LOCAL CONSTANTS
-
-=============================================================================
-*/
-
-typedef struct
-{
-  u16int bit0,bit1;	// 0-255 is a character, > is a pointer to a node
-} huffnode;
-
-
-typedef struct
-{
-	u16int	RLEWtag;
-	s32int		headeroffsets[100];
-	u8int		tileinfo[];
-} mapfiletype;
-
-
-/*
-=============================================================================
-
-						 GLOBAL VARIABLES
-
-=============================================================================
-*/
-
-u8int 		_seg	*tinf;
 s16int			mapon;
 
-u16int	_seg	*mapsegs[MAPPLANES];
-maptype		_seg	*mapheaderseg[NUMMAPS];
-u8int		_seg	*audiosegs[NUMSNDCHUNKS];
 void		_seg	*grsegs[NUMCHUNKS];
 
 u8int		far	grneeded[NUMCHUNKS];
 u8int		ca_levelbit,ca_levelnum;
 
-s16int			profilehandle,debughandle;
-
-char		audioname[13]="AUDIO.";
-
-/*
-=============================================================================
-
-						 LOCAL VARIABLES
-
-=============================================================================
-*/
-
-extern	s32int	far	CGAhead;
-extern	s32int	far	EGAhead;
-extern	u8int	CGAdict;
-extern	u8int	EGAdict;
-extern	u8int	far	maphead;
-extern	u8int	mapdict;
-extern	u8int	far	audiohead;
-extern	u8int	audiodict;
-
-
-char extension[5],	// Need a string, not constant to change cache files
-     gheadname[10]=GREXT"HEAD.",
-     gfilename[10]=GREXT"GRAPH.",
-     gdictname[10]=GREXT"DICT.",
-     mheadname[10]="MAPHEAD.",
-     mfilename[10]="MAPTEMP.",
-     aheadname[10]="AUDIOHED.",
-     afilename[10]="AUDIOT.";
-
-void CA_CannotOpen(char *string);
-
 s32int		_seg *grstarts;	// array of offsets in egagraph, -1 for sparse
-s32int		_seg *audiostarts;	// array of offsets in audio / audiot
-
-huffnode	grhuffman[255];
-huffnode	audiohuffman[255];
-
 s16int			grhandle;		// handle to EGAGRAPH
-s16int			maphandle;		// handle to MAPTEMP / GAMEMAPS
-s16int			audiohandle;	// handle to AUDIOT / AUDIO
-
 s32int		chunkcomplen,chunkexplen;
 
-SDMode		oldsoundmode;
-
-
-
-void	CAL_CarmackExpand (u16int far *source, u16int far *dest,
-		u16int length);
-
-
-#ifdef THREEBYTEGRSTARTS
-#define FILEPOSSIZE	3
-//#define	GRFILEPOS(c) (*(s32int far *)(((u8int far *)grstarts)+(c)*3)&0xffffff)
 s32int GRFILEPOS(s16int c)
 {
 	s32int value;
@@ -135,265 +25,8 @@
 
 	return value;
 };
-#else
-#define FILEPOSSIZE	4
-#define	GRFILEPOS(c) (grstarts[c])
-#endif
 
 /*
-=============================================================================
-
-					   LOW LEVEL ROUTINES
-
-=============================================================================
-*/
-
-/*
-============================
-=
-= CA_OpenDebug / CA_CloseDebug
-=
-= Opens a binary file with the handle "debughandle"
-=
-============================
-*/
-
-void CA_OpenDebug (void)
-{
-	unlink ("DEBUG.TXT");
-	debughandle = open("DEBUG.TXT", O_CREAT | O_WRONLY | O_TEXT);
-}
-
-void CA_CloseDebug (void)
-{
-	close (debughandle);
-}
-
-
-
-/*
-============================
-=
-= CAL_GetGrChunkLength
-=
-= Gets the length of an explicit length chunk (not tiles)
-= The file pointer is positioned so the compressed data can be read in next.
-=
-============================
-*/
-
-void CAL_GetGrChunkLength (s16int chunk)
-{
-	lseek(grhandle,GRFILEPOS(chunk),SEEK_SET);
-	read(grhandle,&chunkexplen,sizeof(chunkexplen));
-	chunkcomplen = GRFILEPOS(chunk+1)-GRFILEPOS(chunk)-4;
-}
-
-
-/*
-==========================
-=
-= CA_FarRead
-=
-= Read from a file to a far pointer
-=
-==========================
-*/
-
-int CA_FarRead (s16int handle, u8int far *dest, s32int length)
-{
-	if (length>0xffffl)
-		Quit ("CA_FarRead doesn't support 64K reads yet!");
-
-asm		push	ds
-asm		mov	bx,[handle]
-asm		mov	cx,[WORD PTR length]
-asm		mov	dx,[WORD PTR dest]
-asm		mov	ds,[WORD PTR dest+2]
-asm		mov	ah,0x3f				// READ w/handle
-asm		int	21h
-asm		pop	ds
-asm		jnc	good
-	errno = _AX;
-	return	false;
-good:
-asm		cmp	ax,[WORD PTR length]
-asm		je	done
-	errno = EINVFMT;			// user manager knows this is bad read
-	return	false;
-done:
-	return	true;
-}
-
-
-/*
-==========================
-=
-= CA_SegWrite
-=
-= Write from a file to a far pointer
-=
-==========================
-*/
-
-int CA_FarWrite (s16int handle, u8int far *source, s32int length)
-{
-	if (length>0xffffl)
-		Quit ("CA_FarWrite doesn't support 64K reads yet!");
-
-asm		push	ds
-asm		mov	bx,[handle]
-asm		mov	cx,[WORD PTR length]
-asm		mov	dx,[WORD PTR source]
-asm		mov	ds,[WORD PTR source+2]
-asm		mov	ah,0x40			// WRITE w/handle
-asm		int	21h
-asm		pop	ds
-asm		jnc	good
-	errno = _AX;
-	return	false;
-good:
-asm		cmp	ax,[WORD PTR length]
-asm		je	done
-	errno = ENOMEM;				// user manager knows this is bad write
-	return	false;
-
-done:
-	return	true;
-}
-
-
-/*
-==========================
-=
-= CA_ReadFile
-=
-= Reads a file into an allready allocated buffer
-=
-==========================
-*/
-
-int CA_ReadFile (char *filename, uchar **ptr)
-{
-	s16int handle;
-	s32int size;
-
-	if ((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1)
-		return false;
-
-	size = filelength (handle);
-	if (!CA_FarRead (handle,*ptr,size))
-	{
-		close (handle);
-		return false;
-	}
-	close (handle);
-	return true;
-}
-
-
-/*
-==========================
-=
-= CA_WriteFile
-=
-= Writes a file from a memory buffer
-=
-==========================
-*/
-
-int CA_WriteFile (char *filename, void far *ptr, s32int length)
-{
-	s16int handle;
-	s32int size;
-
-	handle = open(filename,O_CREAT | O_BINARY | O_WRONLY,
-				S_IREAD | S_IWRITE | S_IFREG);
-
-	if (handle == -1)
-		return false;
-
-	if (!CA_FarWrite (handle,ptr,length))
-	{
-		close (handle);
-		return false;
-	}
-	close (handle);
-	return true;
-}
-
-
-
-/*
-==========================
-=
-= CA_LoadFile
-=
-= Allocate space for and load a file
-=
-==========================
-*/
-
-int CA_LoadFile (char *filename, uchar **ptr)
-{
-	s16int handle;
-	s32int size;
-
-	if ((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1)
-		return false;
-
-	size = filelength (handle);
-	MM_GetPtr (ptr,size);
-	if (!CA_FarRead (handle,*ptr,size))
-	{
-		close (handle);
-		return false;
-	}
-	close (handle);
-	return true;
-}
-
-/*
-============================================================================
-
-		COMPRESSION routines, see JHUFF.C for more
-
-============================================================================
-*/
-
-
-
-/*
-===============
-=
-= CAL_OptimizeNodes
-=
-= Goes through a huffman table and changes the 256-511 node numbers to the
-= actular address of the node.  Must be called before CAL_HuffExpand
-=
-===============
-*/
-
-void CAL_OptimizeNodes (huffnode *table)
-{
-  huffnode *node;
-  s16int i;
-
-  node = table;
-
-  for (i=0;i<255;i++)
-  {
-	if (node->bit0 >= 256)
-	  node->bit0 = (u16int)(table+(node->bit0-256));
-	if (node->bit1 >= 256)
-	  node->bit1 = (u16int)(table+(node->bit1-256));
-	node++;
-  }
-}
-
-
-
-/*
 ======================
 =
 = CAL_HuffExpand
@@ -408,19 +41,12 @@
 void CAL_HuffExpand (u8int huge *source, u8int huge *dest,
   s32int length,huffnode *hufftable, int screenhack)
 {
-//  u16int bit,byte,node,code;
   u16int sourceseg,sourceoff,destseg,destoff,endoff;
   huffnode *headptr;
   u8int		mapmask;
-//  huffnode *nodeon;
 
   headptr = hufftable+254;	// head node is allways node 254
 
-  source++;	// normalize
-  source--;
-  dest++;
-  dest--;
-
   if (screenhack)
   {
 	mapmask = 1;
@@ -430,72 +56,12 @@
 	length >>= 2;
   }
 
-  sourceseg = FP_SEG(source);
-  sourceoff = FP_OFF(source);
-  destseg = FP_SEG(dest);
-  destoff = FP_OFF(dest);
-  endoff = destoff+length;
-
-//
-// ds:si source
-// es:di dest
-// ss:bx node pointer
-//
-
-	if (length <0xfff0)
+	// setup
+expandshort:
 	{
+		// loop
+	}
 
-//--------------------------
-// expand less than 64k of data
-//--------------------------
-
-asm mov	bx,[headptr]
-
-asm	mov	si,[sourceoff]
-asm	mov	di,[destoff]
-asm	mov	es,[destseg]
-asm	mov	ds,[sourceseg]
-asm	mov	ax,[endoff]
-
-asm	mov	ch,[si]				// load first byte
-asm	inc	si
-asm	mov	cl,1
-
-expandshort:
-asm	test	ch,cl			// bit set?
-asm	jnz	bit1short
-asm	mov	dx,[ss:bx]			// take bit0 path from node
-asm	shl	cl,1				// advance to next bit position
-asm	jc	newbyteshort
-asm	jnc	sourceupshort
-
-bit1short:
-asm	mov	dx,[ss:bx+2]		// take bit1 path
-asm	shl	cl,1				// advance to next bit position
-asm	jnc	sourceupshort
-
-newbyteshort:
-asm	mov	ch,[si]				// load next byte
-asm	inc	si
-asm	mov	cl,1				// back to first bit
-
-sourceupshort:
-asm	or	dh,dh				// if dx<256 its a byte, else move node
-asm	jz	storebyteshort
-asm	mov	bx,dx				// next node = (huffnode *)code
-asm	jmp	expandshort
-
-storebyteshort:
-asm	mov	[es:di],dl
-asm	inc	di					// write a decopmpressed byte out
-asm	mov	bx,[headptr]		// back to the head node for next bit
-
-asm	cmp	di,ax				// done?
-asm	jne	expandshort
-
-//
-// perform screenhack if needed
-//
 asm	test	[screenhack],1
 asm	jz	notscreen
 asm	shl	[mapmask],1
@@ -510,773 +76,18 @@
 asm	jmp	expandshort
 
 notscreen:;
-	}
-	else
-	{
-
-//--------------------------
-// expand more than 64k of data
-//--------------------------
-
-  length--;
-
-asm mov	bx,[headptr]
-asm	mov	cl,1
-
-asm	mov	si,[sourceoff]
-asm	mov	di,[destoff]
-asm	mov	es,[destseg]
-asm	mov	ds,[sourceseg]
-
-asm	lodsb			// load first byte
-
-expand:
-asm	test	al,cl		// bit set?
-asm	jnz	bit1
-asm	mov	dx,[ss:bx]	// take bit0 path from node
-asm	jmp	gotcode
-bit1:
-asm	mov	dx,[ss:bx+2]	// take bit1 path
-
-gotcode:
-asm	shl	cl,1		// advance to next bit position
-asm	jnc	sourceup
-asm	lodsb
-asm	cmp	si,0x10		// normalize ds:si
-asm  	jb	sinorm
-asm	mov	cx,ds
-asm	inc	cx
-asm	mov	ds,cx
-asm	xor	si,si
-sinorm:
-asm	mov	cl,1		// back to first bit
-
-sourceup:
-asm	or	dh,dh		// if dx<256 its a byte, else move node
-asm	jz	storebyte
-asm	mov	bx,dx		// next node = (huffnode *)code
-asm	jmp	expand
-
-storebyte:
-asm	mov	[es:di],dl
-asm	inc	di		// write a decopmpressed byte out
-asm	mov	bx,[headptr]	// back to the head node for next bit
-
-asm	cmp	di,0x10		// normalize es:di
-asm  	jb	dinorm
-asm	mov	dx,es
-asm	inc	dx
-asm	mov	es,dx
-asm	xor	di,di
-dinorm:
-
-asm	sub	[WORD PTR ss:length],1
-asm	jnc	expand
-asm  	dec	[WORD PTR ss:length+2]
-asm	jns	expand		// when length = ffff ffff, done
-
-	}
-
-asm	mov	ax,ss
-asm	mov	ds,ax
-
 }
 
-
-/*
-======================
-=
-= CAL_CarmackExpand
-=
-= Length is the length of the EXPANDED data
-=
-======================
-*/
-
-#define NEARTAG	0xa7
-#define FARTAG	0xa8
-
-void CAL_CarmackExpand (u16int far *source, u16int far *dest, u16int length)
-{
-	u16int	ch,chhigh,count,offset;
-	u16int	far *copyptr, far *inptr, far *outptr;
-
-	length/=2;
-
-	inptr = source;
-	outptr = dest;
-
-	while (length)
-	{
-		ch = *inptr++;
-		chhigh = ch>>8;
-		if (chhigh == NEARTAG)
-		{
-			count = ch&0xff;
-			if (!count)
-			{				// have to insert a word containing the tag byte
-				ch |= *((uchar far *)inptr)++;
-				*outptr++ = ch;
-				length--;
-			}
-			else
-			{
-				offset = *((uchar far *)inptr)++;
-				copyptr = outptr - offset;
-				length -= count;
-				while (count--)
-					*outptr++ = *copyptr++;
-			}
-		}
-		else if (chhigh == FARTAG)
-		{
-			count = ch&0xff;
-			if (!count)
-			{				// have to insert a word containing the tag byte
-				ch |= *((uchar far *)inptr)++;
-				*outptr++ = ch;
-				length --;
-			}
-			else
-			{
-				offset = *inptr++;
-				copyptr = dest + offset;
-				length -= count;
-				while (count--)
-					*outptr++ = *copyptr++;
-			}
-		}
-		else
-		{
-			*outptr++ = ch;
-			length --;
-		}
-	}
-}
-
-
-
-/*
-======================
-=
-= CA_RLEWcompress
-=
-======================
-*/
-
-s32int CA_RLEWCompress (u16int huge *source, s32int length, u16int huge *dest,
-  u16int rlewtag)
-{
-  s32int complength;
-  u16int value,count,i;
-  u16int huge *start,huge *end;
-
-  start = dest;
-
-  end = source + (length+1)/2;
-
-//
-// compress it
-//
-  do
-  {
-	count = 1;
-	value = *source++;
-	while (*source == value && source<end)
-	{
-	  count++;
-	  source++;
-	}
-	if (count>3 || value == rlewtag)
-	{
-    //
-    // send a tag / count / value string
-    //
-      *dest++ = rlewtag;
-      *dest++ = count;
-      *dest++ = value;
-    }
-    else
-    {
-    //
-    // send word without compressing
-    //
-      for (i=1;i<=count;i++)
-	*dest++ = value;
-	}
-
-  } while (source<end);
-
-  complength = 2*(dest-start);
-  return complength;
-}
-
-
-/*
-======================
-=
-= CA_RLEWexpand
-= length is EXPANDED length
-=
-======================
-*/
-
-void CA_RLEWexpand (u16int huge *source, u16int huge *dest,s32int length,
-  u16int rlewtag)
-{
-//  u16int value,count,i;
-  u16int huge *end;
-  u16int sourceseg,sourceoff,destseg,destoff,endseg,endoff;
-
-
-//
-// expand it
-//
-#if 0
-  do
-  {
-	value = *source++;
-	if (value != rlewtag)
-	//
-	// uncompressed
-	//
-	  *dest++=value;
-	else
-	{
-	//
-	// compressed string
-	//
-	  count = *source++;
-	  value = *source++;
-	  for (i=1;i<=count;i++)
-	*dest++ = value;
-	}
-  } while (dest<end);
-#endif
-
-  end = dest + (length)/2;
-  sourceseg = FP_SEG(source);
-  sourceoff = FP_OFF(source);
-  destseg = FP_SEG(dest);
-  destoff = FP_OFF(dest);
-  endseg = FP_SEG(end);
-  endoff = FP_OFF(end);
-
-
-//
-// ax = source value
-// bx = tag value
-// cx = repeat counts
-// dx = scratch
-//
-// NOTE: A repeat count that produces 0xfff0 bytes can blow this!
-//
-
-asm	mov	bx,rlewtag
-asm	mov	si,sourceoff
-asm	mov	di,destoff
-asm	mov	es,destseg
-asm	mov	ds,sourceseg
-
-expand:
-asm	lodsw
-asm	cmp	ax,bx
-asm	je	repeat
-asm	stosw
-asm	jmp	next
-
-repeat:
-asm	lodsw
-asm	mov	cx,ax		// repeat count
-asm	lodsw			// repeat value
-asm	rep stosw
-
-next:
-
-asm	cmp	si,0x10		// normalize ds:si
-asm  	jb	sinorm
-asm	mov	ax,si
-asm	shr	ax,1
-asm	shr	ax,1
-asm	shr	ax,1
-asm	shr	ax,1
-asm	mov	dx,ds
-asm	add	dx,ax
-asm	mov	ds,dx
-asm	and	si,0xf
-sinorm:
-asm	cmp	di,0x10		// normalize es:di
-asm  	jb	dinorm
-asm	mov	ax,di
-asm	shr	ax,1
-asm	shr	ax,1
-asm	shr	ax,1
-asm	shr	ax,1
-asm	mov	dx,es
-asm	add	dx,ax
-asm	mov	es,dx
-asm	and	di,0xf
-dinorm:
-
-asm	cmp     di,ss:endoff
-asm	jne	expand
-asm	mov	ax,es
-asm	cmp	ax,ss:endseg
-asm	jb	expand
-
-asm	mov	ax,ss
-asm	mov	ds,ax
-
-}
-
-
-
-/*
-=============================================================================
-
-					 CACHE MANAGER ROUTINES
-
-=============================================================================
-*/
-
-
-/*
-======================
-=
-= CAL_SetupGrFile
-=
-======================
-*/
-
-void CAL_SetupGrFile (void)
-{
-	char fname[13];
-	s16int handle;
-	uchar *compseg;
-
-//
-// load ???dict.ext (huffman dictionary for graphics files)
-//
-
-	strcpy(fname,gdictname);
-	strcat(fname,extension);
-
-	if ((handle = open(fname,
-		 O_RDONLY | O_BINARY, S_IREAD)) == -1)
-		CA_CannotOpen(fname);
-
-	read(handle, &grhuffman, sizeof(grhuffman));
-	close(handle);
-	CAL_OptimizeNodes (grhuffman);
-//
-// load the data offsets from ???head.ext
-//
-	MM_GetPtr (&(uchar *)grstarts,(NUMCHUNKS+1)*FILEPOSSIZE);
-
-	strcpy(fname,gheadname);
-	strcat(fname,extension);
-
-	if ((handle = open(fname,
-		 O_RDONLY | O_BINARY, S_IREAD)) == -1)
-		CA_CannotOpen(fname);
-
-	CA_FarRead(handle, (uchar *)grstarts, (NUMCHUNKS+1)*FILEPOSSIZE);
-
-	close(handle);
-
-//
-// Open the graphics file, leaving it open until the game is finished
-//
-	strcpy(fname,gfilename);
-	strcat(fname,extension);
-
-	grhandle = open(fname, O_RDONLY | O_BINARY);
-	if (grhandle == -1)
-		CA_CannotOpen(fname);
-
-
-//
-// load the pic and sprite headers into the arrays in the data segment
-//
-	MM_GetPtr(&(uchar *)pictable,NUMPICS*sizeof(pictabletype));
-	CAL_GetGrChunkLength(STRUCTPIC);		// position file pointer
-	MM_GetPtr(&compseg,chunkcomplen);
-	CA_FarRead (grhandle,compseg,chunkcomplen);
-	CAL_HuffExpand (compseg, (u8int huge *)pictable,NUMPICS*sizeof(pictabletype),grhuffman,false);
-	MM_FreePtr(&compseg);
-}
-
-//==========================================================================
-
-
-/*
-======================
-=
-= CAL_SetupMapFile
-=
-======================
-*/
-
-void CAL_SetupMapFile (void)
-{
-	s16int	i;
-	s16int handle;
-	s32int length,pos;
-	char fname[13];
-
-//
-// load maphead.ext (offsets and tileinfo for map file)
-//
-	strcpy(fname,mheadname);
-	strcat(fname,extension);
-
-	if ((handle = open(fname,
-		 O_RDONLY | O_BINARY, S_IREAD)) == -1)
-		CA_CannotOpen(fname);
-
-	length = filelength(handle);
-	MM_GetPtr (&(uchar *)tinf,length);
-	CA_FarRead(handle, tinf, length);
-	close(handle);
-
-//
-// open the data file
-//
-	strcpy(fname,"GAMEMAPS.");
-	strcat(fname,extension);
-
-	if ((maphandle = open(fname,
-		 O_RDONLY | O_BINARY, S_IREAD)) == -1)
-		CA_CannotOpen(fname);
-
-//
-// load all map header
-//
-	for (i=0;i<NUMMAPS;i++)
-	{
-		pos = ((mapfiletype	_seg *)tinf)->headeroffsets[i];
-		if (pos<0)						// $FFFFFFFF start is a sparse map
-			continue;
-
-		MM_GetPtr(&(uchar *)mapheaderseg[i],sizeof(maptype));
-		MM_SetLock(&(uchar *)mapheaderseg[i],true);
-		lseek(maphandle,pos,SEEK_SET);
-		CA_FarRead (maphandle,(uchar *)mapheaderseg[i],sizeof(maptype));
-	}
-
-//
-// allocate space for 3 64*64 planes
-//
-	for (i=0;i<MAPPLANES;i++)
-	{
-		MM_GetPtr (&(uchar *)mapsegs[i],64*64*2);
-		MM_SetLock (&(uchar *)mapsegs[i],true);
-	}
-}
-
-
-//==========================================================================
-
-
-/*
-======================
-=
-= CAL_SetupAudioFile
-=
-======================
-*/
-
-void CAL_SetupAudioFile (void)
-{
-	s16int handle;
-	s32int length;
-	char fname[13];
-
-//
-// load maphead.ext (offsets and tileinfo for map file)
-//
-	strcpy(fname,aheadname);
-	strcat(fname,extension);
-
-	if ((handle = open(fname,
-		 O_RDONLY | O_BINARY, S_IREAD)) == -1)
-		CA_CannotOpen(fname);
-
-	length = filelength(handle);
-	MM_GetPtr (&(uchar *)audiostarts,length);
-	CA_FarRead(handle, (u8int far *)audiostarts, length);
-	close(handle);
-
-//
-// open the data file
-//
-	strcpy(fname,afilename);
-	strcat(fname,extension);
-
-	if ((audiohandle = open(fname,
-		 O_RDONLY | O_BINARY, S_IREAD)) == -1)
-		CA_CannotOpen(fname);
-}
-
-//==========================================================================
-
-
-/*
-======================
-=
-= CA_Startup
-=
-= Open all files and load in headers
-=
-======================
-*/
-
 void CA_Startup (void)
 {
-	CAL_SetupMapFile ();
-	CAL_SetupGrFile ();
-	CAL_SetupAudioFile ();
-
 	mapon = -1;
 	ca_levelbit = 1;
 	ca_levelnum = 0;
-
 }
 
-//==========================================================================
-
-
 /*
 ======================
 =
-= CA_Shutdown
-=
-= Closes all files
-=
-======================
-*/
-
-void CA_Shutdown (void)
-{
-	close (maphandle);
-	close (grhandle);
-	close (audiohandle);
-}
-
-//===========================================================================
-
-/*
-======================
-=
-= CA_CacheAudioChunk
-=
-======================
-*/
-
-void CA_CacheAudioChunk (s16int chunk)
-{
-	s32int	pos,compressed;
-
-	if (audiosegs[chunk])
-	{
-		MM_SetPurge (&(uchar *)audiosegs[chunk],0);
-		return;							// allready in memory
-	}
-
-//
-// load the chunk into a buffer, either the miscbuffer if it fits, or allocate
-// a larger buffer
-//
-	pos = audiostarts[chunk];
-	compressed = audiostarts[chunk+1]-pos;
-
-	lseek(audiohandle,pos,SEEK_SET);
-
-	MM_GetPtr (&(uchar *)audiosegs[chunk],compressed);
-	if (mmerror)
-		return;
-
-	CA_FarRead(audiohandle,audiosegs[chunk],compressed);
-}
-
-//===========================================================================
-
-/*
-======================
-=
-= CA_LoadAllSounds
-=
-= Purges all sounds, then loads all new ones (mode switch)
-=
-======================
-*/
-
-void CA_LoadAllSounds (void)
-{
-	u16int	start,i;
-
-	switch (oldsoundmode)
-	{
-	case sdm_Off:
-		goto cachein;
-	case sdm_PC:
-		start = STARTPCSOUNDS;
-		break;
-	case sdm_AdLib:
-		start = STARTADLIBSOUNDS;
-		break;
-	}
-
-	for (i=0;i<NUMSOUNDS;i++,start++)
-		if (audiosegs[start])
-			MM_SetPurge (&(uchar *)audiosegs[start],3);		// make purgable
-
-cachein:
-
-	switch (SoundMode)
-	{
-	case sdm_Off:
-		return;
-	case sdm_PC:
-		start = STARTPCSOUNDS;
-		break;
-	case sdm_AdLib:
-		start = STARTADLIBSOUNDS;
-		break;
-	}
-
-	for (i=0;i<NUMSOUNDS;i++,start++)
-		CA_CacheAudioChunk (start);
-
-	oldsoundmode = SoundMode;
-}
-
-//===========================================================================
-
-
-/*
-======================
-=
-= CAL_ExpandGrChunk
-=
-= Does whatever is needed with a pointer to a compressed chunk
-=
-======================
-*/
-
-void CAL_ExpandGrChunk (s16int chunk, u8int far *source)
-{
-	s32int	expanded;
-
-
-	if (chunk >= STARTTILE8 && chunk < STARTEXTERNS)
-	{
-	//
-	// expanded sizes of tile8/16/32 are implicit
-	//
-
-#define BLOCK		64
-#define MASKBLOCK	128
-
-		if (chunk<STARTTILE8M)			// tile 8s are all in one chunk!
-			expanded = BLOCK*NUMTILE8;
-		else if (chunk<STARTTILE16)
-			expanded = MASKBLOCK*NUMTILE8M;
-		else if (chunk<STARTTILE16M)	// all other tiles are one/chunk
-			expanded = BLOCK*4;
-		else if (chunk<STARTTILE32)
-			expanded = MASKBLOCK*4;
-		else if (chunk<STARTTILE32M)
-			expanded = BLOCK*16;
-		else
-			expanded = MASKBLOCK*16;
-	}
-	else
-	{
-	//
-	// everything else has an explicit size u32int
-	//
-		expanded = *(s32int far *)source;
-		source += 4;			// skip over length
-	}
-
-//
-// allocate final space, decompress it, and free bigbuffer
-// Sprites need to have shifts made and various other junk
-//
-	MM_GetPtr (&grsegs[chunk],expanded);
-	if (mmerror)
-		return;
-	CAL_HuffExpand (source,grsegs[chunk],expanded,grhuffman,false);
-}
-
-
-/*
-======================
-=
-= CA_CacheGrChunk
-=
-= Makes sure a given chunk is in memory, loadiing it if needed
-=
-======================
-*/
-
-void CA_CacheGrChunk (s16int chunk)
-{
-	s32int	pos,compressed;
-	uchar *bigbufferseg;
-	u8int	far *source;
-	s16int		next;
-
-	grneeded[chunk] |= ca_levelbit;		// make sure it doesn't get removed
-	if (grsegs[chunk])
-	{
-		MM_SetPurge (&grsegs[chunk],0);
-		return;							// allready in memory
-	}
-
-//
-// load the chunk into a buffer, either the miscbuffer if it fits, or allocate
-// a larger buffer
-//
-	pos = GRFILEPOS(chunk);
-	if (pos<0)							// $FFFFFFFF start is a sparse tile
-	  return;
-
-	next = chunk +1;
-	while (GRFILEPOS(next) == -1)		// skip past any sparse tiles
-		next++;
-
-	compressed = GRFILEPOS(next)-pos;
-
-	lseek(grhandle,pos,SEEK_SET);
-
-	if (compressed<=BUFFERSIZE)
-	{
-		CA_FarRead(grhandle,bufferseg,compressed);
-		source = bufferseg;
-	}
-	else
-	{
-		MM_GetPtr(&bigbufferseg,compressed);
-		MM_SetLock (&bigbufferseg,true);
-		CA_FarRead(grhandle,bigbufferseg,compressed);
-		source = bigbufferseg;
-	}
-
-	CAL_ExpandGrChunk (chunk,source);
-
-	if (compressed>BUFFERSIZE)
-		MM_FreePtr(&bigbufferseg);
-}
-
-
-
-//==========================================================================
-
-/*
-======================
-=
 = CA_CacheScreen
 =
 = Decompresses a chunk from disk straight onto the screen
@@ -1319,77 +130,9 @@
 	MM_FreePtr(&bigbufferseg);
 }
 
-//==========================================================================
-
 /*
 ======================
 =
-= CA_CacheMap
-=
-= WOLF: This is specialized for a 64*64 map size
-=
-======================
-*/
-
-void CA_CacheMap (s16int mapnum)
-{
-	s32int	pos,compressed;
-	s16int		plane;
-	uchar **dest,bigbufferseg;
-	u16int	size;
-	u16int	far	*source;
-	uchar *buffer2seg;
-	s32int	expanded;
-
-	mapon = mapnum;
-
-//
-// load the planes into the allready allocated buffers
-//
-	size = 64*64*2;
-
-	for (plane = 0; plane<MAPPLANES; plane++)
-	{
-		pos = mapheaderseg[mapnum]->planestart[plane];
-		compressed = mapheaderseg[mapnum]->planelength[plane];
-
-		dest = &(uchar *)mapsegs[plane];
-
-		lseek(maphandle,pos,SEEK_SET);
-		if (compressed<=BUFFERSIZE)
-			source = bufferseg;
-		else
-		{
-			MM_GetPtr(&bigbufferseg,compressed);
-			MM_SetLock (&bigbufferseg,true);
-			source = bigbufferseg;
-		}
-
-		CA_FarRead(maphandle,(u8int far *)source,compressed);
-		//
-		// unhuffman, then unRLEW
-		// The huffman'd chunk has a two byte expanded length first
-		// The resulting RLEW chunk also does, even though it's not really
-		// needed
-		//
-		expanded = *source;
-		source++;
-		MM_GetPtr (&buffer2seg,expanded);
-		CAL_CarmackExpand (source, (u16int far *)buffer2seg,expanded);
-		CA_RLEWexpand (((u16int far *)buffer2seg)+1,*dest,size,
-		((mapfiletype _seg *)tinf)->RLEWtag);
-		MM_FreePtr (&buffer2seg);
-
-		if (compressed>BUFFERSIZE)
-			MM_FreePtr(&bigbufferseg);
-	}
-}
-
-//===========================================================================
-
-/*
-======================
-=
 = CA_UpLevel
 =
 = Goes up a bit level in the needed lists and clears it out.
@@ -1434,109 +177,9 @@
 	CA_CacheMarks();
 }
 
-//===========================================================================
-
 /*
 ======================
 =
-= CA_ClearMarks
-=
-= Clears out all the marks at the current level
-=
-======================
-*/
-
-void CA_ClearMarks (void)
-{
-	s16int i;
-
-	for (i=0;i<NUMCHUNKS;i++)
-		grneeded[i]&=~ca_levelbit;
-}
-
-
-//===========================================================================
-
-/*
-======================
-=
-= CA_ClearAllMarks
-=
-= Clears out all the marks on all the levels
-=
-======================
-*/
-
-void CA_ClearAllMarks (void)
-{
-	_fmemset (grneeded,0,sizeof(grneeded));
-	ca_levelbit = 1;
-	ca_levelnum = 0;
-}
-
-
-//===========================================================================
-
-
-/*
-======================
-=
-= CA_FreeGraphics
-=
-======================
-*/
-
-
-void CA_SetGrPurge (void)
-{
-	s16int i;
-
-//
-// free graphics
-//
-	CA_ClearMarks ();
-
-	for (i=0;i<NUMCHUNKS;i++)
-		if (grsegs[i])
-			MM_SetPurge (&(uchar *)grsegs[i],3);
-}
-
-
-
-/*
-======================
-=
-= CA_SetAllPurge
-=
-= Make everything possible purgable
-=
-======================
-*/
-
-void CA_SetAllPurge (void)
-{
-	s16int i;
-
-
-//
-// free sounds
-//
-	for (i=0;i<NUMSNDCHUNKS;i++)
-		if (audiosegs[i])
-			MM_SetPurge (&(uchar *)audiosegs[i],3);
-
-//
-// free graphics
-//
-	CA_SetGrPurge ();
-}
-
-
-//===========================================================================
-
-/*
-======================
-=
 = CA_CacheMarks
 =
 ======================
@@ -1651,13 +294,3 @@
 
 		}
 }
-
-void CA_CannotOpen(char *string)
-{
- char str[30];
-
- strcpy(str,"Can't open ");
- strcat(str,string);
- strcat(str,"!\n");
- Quit (str);
-}
\ No newline at end of file
--- a/ca.h
+++ b/ca.h
@@ -1,101 +1,13 @@
-// ID_CA.H
-//===========================================================================
-
-#define NUMMAPS		60
-#define MAPPLANES	2
-
-#define UNCACHEGRCHUNK(chunk)	{MM_FreePtr(&grsegs[chunk]);grneeded[chunk]&=~ca_levelbit;}
-
-//===========================================================================
-
-typedef	struct
-{
-	s32int		planestart[3];
-	u16int	planelength[3];
-	u16int	width,height;
-	char		name[16];
-} maptype;
-
-//===========================================================================
-
-extern	char		audioname[13];
-
-extern	u8int 		_seg	*tinf;
 extern	s16int			mapon;
-
-extern	u16int	_seg	*mapsegs[MAPPLANES];
-extern	maptype		_seg	*mapheaderseg[NUMMAPS];
-extern	u8int		_seg	*audiosegs[NUMSNDCHUNKS];
 extern	void		_seg	*grsegs[NUMCHUNKS];
-
 extern	u8int		far	grneeded[NUMCHUNKS];
 extern	u8int		ca_levelbit,ca_levelnum;
-
 extern	char		*titleptr[8];
 
-extern	s16int			profilehandle,debughandle;
-
-extern	char		extension[5],
-			gheadname[10],
-			gfilename[10],
-			gdictname[10],
-			mheadname[10],
-			mfilename[10],
-			aheadname[10],
-			afilename[10];
-
-extern s32int		_seg *grstarts;	// array of offsets in egagraph, -1 for sparse
-extern s32int		_seg *audiostarts;	// array of offsets in audio / audiot
-//
-// hooks for custom cache dialogs
-//
-extern	void	(*drawcachebox)		(char *title, u16int numcache);
-extern	void	(*updatecachebox)	(void);
-extern	void	(*finishcachebox)	(void);
-
-//===========================================================================
-
-// just for the score box reshifting
-
-void CAL_ShiftSprite (u16int segment,u16int source,u16int dest,
-	u16int width, u16int height, u16int pixshift);
-
-//===========================================================================
-
-void CA_OpenDebug (void);
-void CA_CloseDebug (void);
-int CA_FarRead (s16int handle, u8int far *dest, s32int length);
-int CA_FarWrite (s16int handle, u8int far *source, s32int length);
-int CA_ReadFile (char *filename, uchar **ptr);
-int CA_LoadFile (char *filename, uchar **ptr);
-int CA_WriteFile (char *filename, void far *ptr, s32int length);
-
-s32int CA_RLEWCompress (u16int huge *source, s32int length, u16int huge *dest,
-  u16int rlewtag);
-
-void CA_RLEWexpand (u16int huge *source, u16int huge *dest,s32int length,
-  u16int rlewtag);
-
 void CA_Startup (void);
-void CA_Shutdown (void);
-
-void CA_SetGrPurge (void);
-void CA_CacheAudioChunk (s16int chunk);
-void CA_LoadAllSounds (void);
-
 void CA_UpLevel (void);
 void CA_DownLevel (void);
-
-void CA_SetAllPurge (void);
-
 void CA_ClearMarks (void);
 void CA_ClearAllMarks (void);
-
-#define CA_MarkGrChunk(chunk)	grneeded[chunk]|=ca_levelbit
-
-void CA_CacheGrChunk (s16int chunk);
-void CA_CacheMap (s16int mapnum);
-
 void CA_CacheMarks (void);
-
 void CA_CacheScreen (s16int chunk);
--- a/dat.h
+++ b/dat.h
@@ -1,12 +1,248 @@
 typedef short s16int;
 typedef int s32int;
 
-extern int sod;
-extern int sdm;
-extern int wl1;
 extern char *ext;
+extern int debug;
+extern int skipintro;
 
+typedef struct Dat Dat;
+typedef struct Pic Pic;
+typedef struct Fnt Fnt;
+typedef struct Sfx Sfx;
+
+struct Dat{
+	u16int sz;
+	uchar *p;
+};
+extern Dat *wals, *sprs, *spre;
+extern Dat *imfs, *imfe;
+extern Dat *maps, *mape, *map;
+extern Dat *exts, *exte;
+extern Dat *dems, *deme, *epis;
+
+struct Pic{
+	int x;
+	int y;
+	Dat;
+};
+extern Pic *pics, *pice;
+extern uchar *pict;
+
+struct Fnt{
+	s16int h;
+	s16int ofs[256];
+	char w[256];
+	Dat;
+};
+extern Fnt fnts[];
+
+struct Sfx{
+	Dat pc;
+	Dat al;
+	Dat *pcm;
+};
+extern Sfx *sfxs, *sfxe;
+
 extern u32int pal[];
 extern u8int intro[];
 
-#include "audio.h"
+enum{
+	Shitwall,
+	Srockethit,
+	Sghost = Srockethit+2,
+	Sdrawgun2,
+	Sdrawgun1,
+	Snoway,
+	Sthrow = Snoway+2,
+	Sdeath,
+	Sdogdeath,
+	Sgatling,
+	Sgetkey,
+	Sopendoor = Sgetkey+6,
+	Sclosedoor,
+	Snope,
+	Sgd,
+	Sscream2,
+	Sknife,
+	Spistol,
+	Sscream3,
+	Smg,
+	Shitdoor = Smg+2,
+	Sscream1,
+	Sgetmg,
+	Sgetammo,
+	Sshoot,
+	Shealth1,
+	Shealth2,
+	Sbonus1,
+	Sbonus2,
+	Sbonus3,
+	Sgetgatling,
+	Sesc,
+	Slvlend,
+	Sdogbark,
+	Sendb1,
+	Sendb2,
+	S1up,
+	Sbonus4,
+	Spushwall,
+	Snobonus,
+	S100,
+	Shansdeath = S100+2,
+	Sss,
+	Smutdeath,
+	Shitlerdeath,
+	Seva,
+	Shans,
+	Sssdeath,
+	Smechadeath,
+	Sgdfire,
+	Shansfire,
+	Sssfire,
+	Sslurp,
+	Sfake,
+	Sschbdeath,
+	Sschb,
+	Shitler,
+	Soffc,
+	Soffcdeath,
+	Sdogfire,
+	Sflame,
+	Smechwalk,
+	Stransdeath,
+	Syeah,
+	Sscream4,
+	Sscream5,
+	Sscream6,
+	Sscream7,
+	Sscream8,
+	Sscream9,
+	Sottodeath,
+	Sotto,
+	Sfett,
+	Sgretel,
+	Sgreteldeath,
+	Sfettdeath,
+	Smissile,
+	Smissilehit,
+	Send,
+
+	Sghostdeath = Sfake,
+	Sammobox = Sschb,
+	Sangel = Shitler,
+	Sangelfire = Sflame,
+	Strans = Smechwalk,
+	Swilh = Syeah,
+	Swilhdeath = Shansdeath,
+	Suberdeath = Shitlerdeath,
+	Sknight = Smechadeath,
+	Sknightdeath = Seva,
+	Sangeldeath = Shans,
+	Sknightmissile = Sschbdeath,
+	Spear = Sottodeath,
+	Sangeltired = Sotto,
+	Ssend = Sfett,
+
+	Pbackdrop = 0,
+	Pmouselback,
+	Pcur1,
+	Pcur2,
+	Punsel,
+	Psel,
+	Pcustom,
+	Pmouse,
+	Pjs,
+	Pkb,
+	Pctl,
+	Popt,
+	Psfx,
+	Ppcm,
+	Pmus,
+	Pdiffc,
+	Pbaby,
+	Pread1,
+	Pload,
+	Psave,
+	Pscores,
+	Pspear,
+	Pcollapse,
+	Pguy,
+	Pcolon,
+	P0,
+	P1,
+	P2,
+	P3,
+	P4,
+	P5,
+	P6,
+	P7,
+	P8,
+	P9,
+	Ppercent,
+	Pa,
+	Pb,
+	Pc,
+	Pd,
+	Pe,
+	Pf,
+	Pg,
+	Ph,
+	Pi,
+	Pj,
+	Pk,
+	Pl,
+	Pm,
+	Pn,
+	Po,
+	Pp,
+	Pq,
+	Pr,
+	Ps,
+	Pt,
+	Pu,
+	Pv,
+	Pw,
+	Px,
+	Py,
+	Pz,
+	Pexcl,
+	Papo,
+	Pguy2,
+	Pwin,
+	Ptitle1,
+	Ptitle2,
+	Pend1,
+	Pstat,
+	Ppg13,
+	Pcreds,
+	Pid1,
+	Pid2,
+	Pknife,
+	Pnokey,
+	Pgkey,
+	Pskey,
+	Pblank,
+	Pn0,
+	Pface1,
+	Pface8,
+	Pgat,
+	Pgod,
+	Pwait,
+	Pouch,
+	Ppause,
+	Ppsyched,
+	Pend,
+
+	Pep1 = Pmouse,
+	Ptc = Pjs,
+	Plvl = Pkb,
+	Pname = Pdiffc,
+	Phigh = Pspear,
+	Pmut = Pcollapse,
+
+	Eorder = 0,
+	Eerror,
+	Etitpal,
+	Eend1,
+	Eid = 12
+};
--- a/debug.c
+++ b/debug.c
@@ -56,7 +56,6 @@
 	s16int	i;
 	char    scratch[80],str[10];
 	s32int	mem;
-	spritetype _seg	*block;
 
 	CenterWindow (16,7);
 
@@ -124,96 +123,6 @@
 	IN_Ack ();
 }
 
-//===========================================================================
-
-/*
-================
-=
-= PicturePause
-=
-================
-*/
-
-void PicturePause (void)
-{
-	s16int			i;
-	u8int		p;
-	u16int	x;
-	u8int		far	*dest,far *src;
-	uchar *buffer;
-
-	VW_ColorBorder (15);
-	FinishPaletteShifts ();
-
-	LastScan = 0;
-	while (!LastScan)
-	;
-	if (LastScan != sc_Enter)
-	{
-		VW_ColorBorder (0);
-		return;
-	}
-
-	VW_ColorBorder (1);
-	VW_SetScreen (0,0);
-//
-// vga stuff...
-//
-
-	ClearMemory ();
-	CA_SetAllPurge();
-	MM_GetPtr (&buffer,64000);
-	for (p=0;p<4;p++)
-	{
-	   src = MK_FP(0xa000,displayofs);
-	   dest = (u8int far *)buffer+p;
-	   VGAREADMAP(p);
-	   for (x=0;x<16000;x++,dest+=4)
-		   *dest = *src++;
-	}
-
-
-#if 0
-	for (p=0;p<4;p++)
-	{
-		src = MK_FP(0xa000,0);
-		dest = (u8int far *)buffer+51200+p;
-		VGAREADMAP(p);
-		for (x=0;x<3200;x++,dest+=4)
-			*dest = *src++;
-	}
-#endif
-
-	asm	mov	ax,0x13
-	asm	int	0x10
-
-	dest = MK_FP(0xa000,0);
-	_fmemcpy (dest,buffer,64000);
-
-	VL_SetPalette (&gamepal);
-
-
-	IN_Shutdown ();
-
-	VW_WaitVBL(70);
-	bioskey(0);
-	VW_WaitVBL(70);
-	Quit (NULL);
-}
-
-
-//===========================================================================
-
-
-/*
-================
-=
-= ShapeTest
-=
-================
-*/
-
-#pragma warn -pia
 void ShapeTest (void)
 {
 extern	u16int	NumDigi;
@@ -520,11 +429,6 @@
 		return 1;
 	}
 #endif
-	else if (Keyboard[sc_P])			// P = pause with no screen disruptioon
-	{
-		PicturePause ();
-		return 1;
-	}
 	else if (Keyboard[sc_Q])			// Q = fast quit
 		Quit (NULL);
 	else if (Keyboard[sc_S])			// S = slow motion
--- a/def.h
+++ b/def.h
@@ -745,13 +745,7 @@
 =============================================================================
 */
 
-extern	int		MS_CheckParm (char far *string);
-
 extern	char		str[80],str2[20];
-extern	s16int			tedlevelnum;
-extern	int		tedlevel;
-extern	int		nospr;
-extern	int		IsA386;
 
 extern	u8int far	*scalermemory;
 
@@ -765,7 +759,7 @@
 
 extern	s16int			dirangle[9];
 
-extern	int         startgame,loadedgame,virtualreality;
+extern	int         startgame,loadedgame;
 extern	s16int		mouseadjustment;
 //
 // math tables
@@ -941,7 +935,6 @@
 */
 
 s16int DebugKeys (void);
-void PicturePause (void);
 
 
 /*
--- a/f_spear.h
+++ b/f_spear.h
@@ -12,76 +12,3 @@
 #define STR_ENDGAME2	"You have served your country well."
 #define STR_ENDGAME3	"With the spear gone, the Allies will finally"
 #define STR_ENDGAME4	"by able to destroy Hitler..."
-
-#define STR_COPY1		"That's close, but not close enough to get"
-#define STR_COPY2		"you into the game."
-
-#define STR_COPY3		"Wow, you must have the early version of the"
-#define STR_COPY4		"manual with the totally false information in it."
-
-#define STR_COPY5		"I would let you into the game, but seeing"
-#define STR_COPY6		"as that was not at all the right answer..."
-
-#define STR_COPY7		"It's just too bad we can't get together on"
-#define STR_COPY8		"this one.  Sorry."
-
-#define STR_COPY9		"Hey, you're just SO off base!"
-
-#define STR_COPY10		"You know, I once typed that myself when"
-#define STR_COPY11		"I was your age."
-
-#define STR_COPY12		"Nops.  Zero points.  Zugga."
-
-#define STR_COPY13		"Yeah...right."
-
-#define STR_COPY14		"You must like these quizzes."
-
-#define STR_COPY15		"Could be called \"PixelMeister\"?"
-
-#define STR_COPY16		"Might engineer some software?"
-
-#define STR_COPY17		"Would be found"
-#define STR_COPY18		"directing creatively?"
-
-#define STR_COPY19		"Might be found"
-#define STR_COPY20		"handling operations?"
-
-#define STR_COPY21		"Has a name familiar"
-#define STR_COPY22		"to your weatherman?"
-
-#define STR_NOPE1		"Welcome to the DOS prompt, pirate!"
-#define STR_NOPE2		"Eat hot DOS prompt, goober!"
-#define STR_NOPE3		"Ya know, this program doesn't cost that much."
-#define STR_NOPE4		"Hey...weren't you just AT this DOS prompt?"
-#define STR_NOPE5		"What's a nice user like you doin' at a DOS prompt like this?"
-#define STR_NOPE6		"Well, I'm sure you just \"misplaced\" the manual..."
-#define STR_NOPE7		"Run me again when you've boned up on your manual a bit."
-#define STR_NOPE8		"Nice try, but no Spear."
-#define STR_NOPE9		"That information is in the Spear of Destiny manual, by the way."
-
-#define STR_MISC1		"Under \"Killing the Enemy\", what"
-#define STR_MISC2		"type of enemy is pictured?"
-
-#define STR_MISC3		"How many eyelets are on B.J.'s"
-#define STR_MISC4		"boots? (see page 2)"
-
-#define STR_MISC5		"The word \"minister\" appears in"
-#define STR_MISC6		"what gray shape on page 2?"
-
-#define STR_MISC7		"How many bullets does B.J. have"
-#define STR_MISC8		"on the screen-shot in the middle"
-#define STR_MISC9		"of page 9?"
-
-#define STR_STAR	"star"
-#define STR_DEBRIEF	" DEBRIEFING\n SESSION\n"
-#define STR_ENEMY1	"Name the member of the"
-#define STR_ENEMY2	"enemy forces shown above"
-
-#define STR_CHECKMAN	"CHECK YER MANUAL!"
-#define STR_MAN1	"Which manual page"
-#define STR_MAN2	"is the Options Menu"
-#define STR_MAN3	"function"
-#define STR_MAN4	"on?"
-
-#define STR_ID1		"Which member of Id Software:"
-
\ No newline at end of file
--- a/fns.h
+++ b/fns.h
@@ -1,0 +1,3 @@
+void*	emalloc(ulong);
+void*	erealloc(void *, ulong);
+void	dat(char *);
--- /dev/null
+++ b/fs.c
@@ -1,0 +1,549 @@
+#include <u.h>
+#include <libc.h>
+#include <bio.h>
+#include "dat.h"
+#include "fns.h"
+
+/* what bullshit. */
+uchar *pict;
+static uchar picts[4][Pend]={ {
+	3, 15, 8, 9, 10, 11, 24, 27, 34, 35, 23, 7, 12, 13, 14, 36, 16, 21, 25,
+	26, 87, 37, 129, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
+	54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
+	72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 0, 0, 83, 85, 86, 0, 0,
+	88, 92, 93, 94, 95, 96, 106, 127, 128, 0, 0, 0, 130, 131
+	},{
+	14, 27, 20, 21, 22, 23, 36, 39, 46, 47, 35, 19, 24, 25, 26, 48, 28, 33,
+	37, 38, 99, 49, 141, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
+	65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
+	83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 96, 0, 0, 95, 97, 98, 0,
+	0, 100, 104, 105, 106, 107, 108, 118, 139, 140, 0, 0, 0, 142, 143
+	},{
+	0, 1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 22, 24, 25,
+	26, 27, 0, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
+	43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
+	61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 0, 73, 74, 75, 0, 0, 76,
+	80, 81, 82, 83, 84, 94, 115, 116, 117, 120, 122, 123, 124
+	},{
+	0, 1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 22, 24, 25,
+	26, 27, 28, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+	48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65,
+	66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 87, 88, 89, 90, 91,
+	98, 102, 103, 104, 105, 106, 116, 137, 138, 139, 142, 144, 145, 146
+	}
+};
+static uchar pcmt[2][46]={ {
+	Sgd, Sdogbark, Sclosedoor, Sopendoor, Smg, Spistol, Sgatling, Sss, Shans,
+	Shansdeath, Shansfire, Sssfire, Sscream1, Sscream2, Send, Spushwall,
+	Sdogdeath, Smutdeath, Shitlerdeath, Seva, Sssdeath, Sgdfire, Sslurp,
+	Sfake, Sschbdeath, Sschb, Shitler, Soffc, Soffcdeath, Sdogfire, Slvlend,
+	Smechwalk, Syeah, Smechadeath, Sscream4, Sscream5, Sottodeath, Sotto,
+	Sfett, Sscream6, Sscream7, Sscream8, Sscream9, Sgretel, Sgreteldeath,
+	Sfettdeath
+	},{
+	Sgd, Sdogbark, Sclosedoor, Sopendoor, Smg, Spistol, Sgatling, Sss,
+	Shansfire, Sssfire, Sscream1, Sscream2, Send, Spushwall, Sdogdeath,
+	Smutdeath, Sssdeath, Sgdfire, Sslurp, Soffc, Soffcdeath, Sdogfire,
+	Slvlend, Sscream4, Sscream5, Sscream6, Sscream7, Sscream8, Sscream9,
+	Strans, Stransdeath, Swilh, Swilhdeath, Suberdeath, Sknight,
+	Sknightdeath, Sangel, Sangeldeath, Sgetgatling, Spear
+	}
+};
+
+enum{
+	WL6,
+	WL1,
+	SDM,
+	SOD,
+	Nplane = 2,
+	Mapdxy = 64,
+	Planesz = Mapdxy * Mapdxy * Nplane,
+	Mapsz = Planesz * Nplane
+};
+static int ver;
+static Dat *snds;
+static uchar *swpb, *sndb, *mapb;
+static int alofs;
+static u16int rlewtag;
+
+#define	GBIT16(p)	((p)[0]|((p)[1]<<8))
+
+static Biobuf *
+bopen(char *f, int m)
+{
+	char s[16];
+	Biobuf *bf;
+
+	snprint(s, sizeof s, "%s%s", f, ext);
+	bf = Bopen(s, m);
+	if(bf == nil)
+		sysfatal("bopen: %r");
+	Blethal(bf, nil);
+	return bf;
+}
+
+static long
+eread(Biobuf *bf, void *u, long n)
+{
+	if(Bread(bf, u, n) != n)
+		sysfatal("eread: short read: %r");
+	return n;
+}
+
+static u8int
+get8(Biobuf *bf)
+{
+	u8int v;
+
+	eread(bf, &v, 1);
+	return v;
+}
+
+static u16int
+get16(Biobuf *bf)
+{
+	u16int v;
+
+	v = get8(bf);
+	return v | get8(bf)<<8;
+}
+
+static u32int
+get24(Biobuf *bf)
+{
+	u32int v;
+
+	v = get16(bf);
+	return v | get8(bf)<<16;
+}
+
+static u32int
+get32(Biobuf *bf)
+{
+	u32int v;
+
+	v = get16(bf);
+	return v | get16(bf)<<16;
+}
+
+static vlong
+bsize(Biobuf *bf)
+{
+	vlong n;
+	Dir *d;
+
+	d = dirfstat(Bfildes(bf));
+	if(d == nil)
+		sysfatal("bstat: %r");
+	n = d->length;
+	free(d);
+	return n;
+}
+
+static int
+unrlew(u16int *d, u16int *s)
+{
+	u16int n, v, *e;
+	s++;
+	e = d + Planesz/Nplane;
+	while(d < e){
+		v = *s++;
+		if(v == rlewtag){
+			n = *s++;
+			v = *s++;
+			while(n-- > 0)
+				*d++ = v;
+		}else
+			*d++ = v;
+	}
+	return Planesz;
+}
+
+static int
+uncarmack(Biobuf *bf, u16int *u, u32int ofs)
+{
+	int len;
+	u16int v, a[Planesz/2], *p, *cp, *e;
+	u8int n;
+
+	Bseek(bf, ofs, 0);
+	p = a;
+	e = a + get16(bf) / 2;
+	while(p < e){
+		v = get16(bf);
+		n = v & 0xff;
+		switch(v >> 8){
+		tag:
+			*p++ = v | get8(bf);
+			break;
+		copy:
+			while(n-- > 0)
+				*p++ = *cp++;
+			break;
+		case 0xa7:
+			if(n == 0)
+				goto tag;
+			cp = p - get8(bf);
+			if(cp < a)
+				sysfatal("uncarmack: bad offset");
+			goto copy;
+		case 0xa8:
+			if(n == 0)
+				goto tag;
+			cp = a + get16(bf);
+			if(cp > p)
+				sysfatal("uncarmack: bad offset");
+			goto copy;
+		default:
+			*p++ = v;
+		}
+	}
+	len = unrlew(u, a);
+	if(len != Planesz)
+		sysfatal("uncarmack: truncated lump");
+	return len;
+}
+
+static void
+unhuff(Biobuf* bf, u16int hf[], uchar *u, int len)
+{
+	int k;
+	uchar *e, b;
+	u16int *h, v;
+
+	h = hf+2*254;
+	e = u+len;
+	k = 1;
+	b = get8(bf);
+	while(u < e){
+		v = h[b & k ? 1 : 0];
+		k <<= 1;
+		if(k & 0x100){
+			b = get8(bf);
+			k = 1;
+		}
+		if(v < 256){
+			*u++ = v & 0xff;
+			h = hf+2*254;
+		}else
+			h = hf+2*(v-256);
+	}
+}
+
+static void
+packpcm(Biobuf *bf, Dat *e, u16int so, u16int po)
+{
+	u16int n;
+	Dat *p, *s;
+
+	p = s = wals+po;
+	while(++p < e){
+		Bseek(bf, 2, 1);
+		n = get16(bf);
+		while(s->sz < n)
+			s->sz += p++->sz;
+		while(p->sz == 0 && p < e-1)
+			p++;
+		s++;
+		s->sz = p->sz;
+		s->p = p->p;
+	}
+	n = s-wals;
+	wals = erealloc(wals, n * sizeof *wals);
+	sprs = wals + so;
+	spre = wals + po;
+}
+
+static void
+vswap(void)
+{
+	u16int n, v, w;
+	u32int *o, *p;
+	uchar *u;
+	Dat *s, *e;
+	Biobuf *bf;
+
+	bf = bopen("vswap.", OREAD);
+	n = get16(bf);
+	wals = emalloc((n-1) * sizeof *wals);
+	e = wals + n-1;
+	v = get16(bf);
+	w = get16(bf);
+	p = o = emalloc(n * sizeof *o);
+
+	while(p < o+n)
+		*p++ = get32(bf);
+	for(s=wals; s<wals+n-1; s++)
+		s->sz = get16(bf);
+	u = swpb = emalloc(bsize(bf) - Bseek(bf, 0, 1));
+	Bseek(bf, 2, 1);
+	for(p=o, s=wals; s<e; s++, p++){
+		if(s->sz == 0)
+			continue;
+		Bseek(bf, *p, 0);
+		s->p = u;
+		u += eread(bf, u, s->sz);
+	}
+	Bseek(bf, *p, 0);
+	free(o);
+	swpb = erealloc(swpb, u-swpb);
+
+	packpcm(bf, e-1, v, w);
+	Bterm(bf);
+}
+
+static void
+gamemaps(void)
+{
+	int n;
+	u32int v, p0, p1;
+	uchar *u;
+	Biobuf *hed, *dat;
+
+	hed = bopen("maphead.", OREAD);
+	dat = bopen("gamemaps.", OREAD);
+	n = ver==WL6 ? 60 : ver==WL1 ? 10 : ver==SDM ? 2 : 20;
+	rlewtag = get16(hed);
+	maps = emalloc(n * sizeof *maps);
+	mapb = emalloc(n * Mapsz);
+
+	for(mape=maps, u=mapb; mape<maps+n; mape++){
+		v = get32(hed);
+		if(v == 0xffffffff)
+			sysfatal("sparse map %zud", mape-maps);
+		Bseek(dat, v, 0);
+		p0 = get32(dat);
+		p1 = get32(dat);
+		Bseek(dat, 10, 1);
+		if(get16(dat) != Mapdxy || get16(dat) != Mapdxy)
+			sysfatal("invalid map size");
+		mape->p = u;
+		u += uncarmack(dat, (u16int*)u, p0);
+		u += uncarmack(dat, (u16int*)u, p1);
+		mape->sz = u - mape->p;
+	}
+	Bterm(hed);
+	Bterm(dat);
+}
+
+static void
+swap(Sfx *a, Sfx *b)
+{
+	Sfx c;
+
+	memcpy(&c, a, sizeof c);
+	memcpy(a, b, sizeof c);
+	memcpy(b, &c, sizeof c);
+}
+
+static void
+mungesfx(void)
+{
+	uchar *p, *e;
+	Dat *pcm;
+
+	if(ver >= SDM){
+		swap(sfxs+Sscream4, sfxs+Shansdeath);
+		swap(sfxs+Sscream5, sfxs+Shitlerdeath);
+		swap(sfxs+Sscream7, sfxs+Seva);
+		swap(sfxs+Sscream8, sfxs+Shans);
+		swap(sfxs+Sscream6, sfxs+Smechadeath);
+		swap(sfxs+Sscream9, sfxs+Sschbdeath);
+	}
+	p = pcmt[ver<SDM ? 0 : 1];
+	e = p + (ver==WL6 ? 46 : ver==WL1 ? 21 : ver==SDM ? 26 : 40);
+	for(pcm=spre; p<e; p++, pcm++)
+		if(*p != Send)
+			sfxs[*p].pcm = pcm;
+	sfxs[Sscream3].pcm = sfxs[ver<SDM ? Sscream2 : Sscream4].pcm;	/* why */
+}
+
+static void
+audiot(void)
+{
+	int n, c;
+	u32int v, w;
+	uchar *u;
+	Sfx *s;
+	Biobuf *hed, *dat;
+
+	hed = bopen("audiohed.", OREAD);
+	dat = bopen("audiot.", OREAD);
+	n = ver < SDM ? Send : Ssend;
+	sfxs = emalloc(n * sizeof *sfxs);
+	sfxe = sfxs + n;
+	u = sndb = emalloc(bsize(dat));
+	v = get32(hed);
+	for(c=0, s=sfxs; s<sfxe; s++){
+		w = get32(hed);
+		Bseek(dat, v, 0);
+		if(c++ < n){
+			s->pc.sz = w-v;
+			s->pc.p = u;
+		}else{
+			s->al.sz = w-v;
+			s->al.p = u;
+		}
+		u += eread(dat, u, w-v);
+		v = w;
+		if(c == n)
+			s = sfxs-1;
+	}
+
+	Bseek(hed, (n-1)*4, 1);
+	n = ver < SDM ? 27 : 24;
+	imfs = emalloc(n * sizeof *imfs);
+	v = get32(hed);
+	for(imfe=imfs; imfe<imfs+n; imfe++){
+		w = get32(hed);
+		Bseek(dat, v, 0);
+		imfe->sz = w-v;
+		imfe->p = u;
+		u += eread(dat, u, w-v);
+		v = w;
+	}
+	Bterm(hed);
+	Bterm(dat);
+
+	mungesfx();
+}
+
+static void
+piched(Biobuf *dat, Biobuf *aux, u16int hf[])
+{
+	u32int v, n;
+	uchar *u, *p;
+
+	v = get24(aux);
+	Bseek(dat, v, 0);
+	n = get32(dat);
+	p = u = emalloc(n);
+	n /= 4;
+	pics = emalloc(n * sizeof *pics);
+	unhuff(dat, hf, u, n);
+	for(pice=pics; pice<pics+n; pice++){
+		pice->x = GBIT16(p), p+=2;
+		pice->y = GBIT16(p), p+=2;
+	}
+	free(u);
+}
+
+static void
+getpics(Biobuf *dat, Biobuf *aux, u16int hf[])
+{
+	u32int v, n;
+	uchar *u;
+	Pic *s;
+
+	for(s=pics; s<pice; s++){
+		v = get24(aux);
+		Bseek(dat, v, 0);
+		n = get32(dat);
+		u = emalloc(n);
+		unhuff(dat, hf, u, n);
+		s->p = u;
+		s->sz = n;
+	}
+	pict = picts[ver];
+}
+
+static void
+getfnts(Biobuf *dat, Biobuf *aux, u16int hf[])
+{
+	s16int *o;
+	u32int v, n;
+	uchar *u, *p;
+	char *w;
+	Fnt *f;
+
+	for(f=fnts; f<fnts+2; f++){
+		v = get24(aux);
+		Bseek(dat, v, 0);
+		n = get32(dat);
+		p = u = emalloc(n);
+		unhuff(dat, hf, u, n);
+		f->h = GBIT16(p), p+=2;
+		for(o=f->ofs; o < f->ofs+nelem(f->ofs); o++)
+			*o = GBIT16(p), p+=2;
+		for(w=f->w; w < f->w+nelem(f->w); w++)
+			*w = *p++;
+		n -= p-u;
+		f->p = emalloc(n);
+		f->sz = n;
+		memcpy(f->p, p, n);
+		free(u);
+	}
+}
+
+static void
+getexts(Biobuf *dat, Biobuf *aux, u16int hf[])
+{
+	int n, m;
+	uchar *u;
+	u32int v;
+
+	n = (bsize(aux) - Bseek(aux, 0, 1)) / 3 - 1;
+	exts = emalloc(n * sizeof *exts);
+	for(exte=exts; exte<exts+n; exte++){
+		v = get24(aux);
+		Bseek(dat, v, 0);
+		m = get32(dat);
+		u = emalloc(m);
+		unhuff(dat, hf, u, m);
+		exte->p = u;
+		exte->sz = m;
+	}
+	dems = exts + (ver==WL6 || ver==SDM ? 3 : ver==SOD ? 13 : 0);
+	deme = dems + (ver==WL6 || ver==SOD ? 4 : ver==SDM ? 1 : 0);
+	epis = exts + (ver==WL6 ? 7 : 17);
+}
+
+static void
+gfx(void)
+{
+	u16int hf[512], *h;
+	Biobuf *dat, *aux;
+
+	aux = bopen("vgadict.", OREAD);
+	for(h=hf; h<hf+nelem(hf); h++)
+		*h = get16(aux);
+	Bterm(aux);
+
+	aux = bopen("vgahead.", OREAD);
+	dat = bopen("vgagraph.", OREAD);
+	piched(dat, aux, hf);
+	getfnts(dat, aux, hf);
+	getpics(dat, aux, hf);
+	get24(aux);	/* ignore bullshit tile lump full of lies */
+	getexts(dat, aux, hf);
+	Bterm(aux);
+	Bterm(dat);
+}
+
+static void
+version(void)
+{
+	if(strcmp(ext, "wl6") == 0)
+		ver = WL6;
+	else if(strcmp(ext, "wl1") == 0)
+		ver = WL1;
+	else if(strcmp(ext, "sdm") == 0)
+		ver = SDM;
+	else
+		ver = SOD;
+}
+
+void
+dat(char *dir)
+{
+	rfork(RFNAMEG);
+	if(bind(".", dir, MBEFORE|MCREATE) < 0 || chdir(dir) < 0)
+		fprint(2, "dat: %r\n");
+	version();
+	vswap();
+	gamemaps();
+	if(ver == SOD)
+		ext = "sod";
+	audiot();
+	gfx();
+}
--- a/game.c
+++ b/game.c
@@ -870,19 +870,15 @@
 
 	temp = bufferofs;
 
-	CA_CacheGrChunk (STATUSBARPIC);
-
 	for (i=0;i<3;i++)
 	{
 		bufferofs = screenloc[i];
 		DrawPlayBorder ();
-		VWB_DrawPic (0,200-STATUSLINES,STATUSBARPIC);
+		VWB_DrawPic (0,200-STATUSLINES,Pstat);
 	}
 
 	bufferofs = temp;
 
-	UNCACHEGRCHUNK (STATUSBARPIC);
-
 	DrawFace ();
 	DrawHealth ();
 	DrawLives ();
@@ -1041,17 +1037,9 @@
 {
 	s16int length;
 
-// debug: load chunk
-#ifndef SPEARDEMO
-	s16int dems[4]={T_DEMO0,T_DEMO1,T_DEMO2,T_DEMO3};
-#else
-	s16int dems[1]={T_DEMO0};
-#endif
+	/* deme==dems → no demos, etc. */
+	demoptr = dems+demonumber;
 
-	CA_CacheGrChunk(dems[demonumber]);
-	demoptr = grsegs[dems[demonumber]];
-	MM_SetLock (&grsegs[dems[demonumber]],true);
-
 	NewGame (1,0);
 	gamestate.mapon = *demoptr++;
 	gamestate.difficulty = gd_hard;
@@ -1075,8 +1063,6 @@
 
 	PlayLoop ();
 
-	UNCACHEGRCHUNK(dems[demonumber]);
-
 	demoplayback = false;
 
 	StopMusic ();
@@ -1103,7 +1089,7 @@
 	s16int		iangle,curangle,clockwise,counter,change;
 
 	gamestate.weapon = -1;			// take away weapon
-	SD_PlaySound (PLAYERDEATHSND);
+	SD_PlaySound (Sdeath);
 //
 // swing around to face attacker
 //
@@ -1270,7 +1256,7 @@
 		if (spearflag)
 		{
 			SD_StopSound();
-			SD_PlaySound(GETSPEARSND);
+			SD_PlaySound(Spear);
 			if (DigiMode != sds_Off)
 			{
 				s32int lasttimecount = TimeCount;
--- a/gfxv_sdm.h
+++ /dev/null
@@ -1,224 +1,0 @@
-//////////////////////////////////////
-//
-// Graphics .H file for .SDM
-// IGRAB-ed on Mon Sep 21 14:20:19 1992
-//
-//////////////////////////////////////
-
-typedef enum {
-		// Lump Start
-		C_BACKDROPPIC=3,
-		C_MOUSELBACKPIC,                     // 4
-		C_CURSOR1PIC,                        // 5
-		C_CURSOR2PIC,                        // 6
-		C_NOTSELECTEDPIC,                    // 7
-		C_SELECTEDPIC,                       // 8
-		// Lump Start
-		C_CUSTOMIZEPIC,                      // 9
-		C_JOY1PIC,                           // 10
-		C_JOY2PIC,                           // 11
-		C_MOUSEPIC,                          // 12
-		C_JOYSTICKPIC,                       // 13
-		C_KEYBOARDPIC,                       // 14
-		C_CONTROLPIC,                        // 15
-		// Lump Start
-		C_OPTIONSPIC,                        // 16
-		// Lump Start
-		C_FXTITLEPIC,                        // 17
-		C_DIGITITLEPIC,                      // 18
-		C_MUSICTITLEPIC,                     // 19
-		// Lump Start
-		C_HOWTOUGHPIC,                       // 20
-		C_BABYMODEPIC,                       // 21
-		C_EASYPIC,                           // 22
-		C_NORMALPIC,                         // 23
-		C_HARDPIC,                           // 24
-		// Lump Start
-		C_DISKLOADING1PIC,                   // 25
-		C_DISKLOADING2PIC,                   // 26
-		C_LOADGAMEPIC,                       // 27
-		C_SAVEGAMEPIC,                       // 28
-		// Lump Start
-		HIGHSCORESPIC,                       // 29
-		C_WONSPEARPIC,                       // 30
-		// Lump Start
-		L_GUYPIC,                            // 31
-		L_COLONPIC,                          // 32
-		L_NUM0PIC,                           // 33
-		L_NUM1PIC,                           // 34
-		L_NUM2PIC,                           // 35
-		L_NUM3PIC,                           // 36
-		L_NUM4PIC,                           // 37
-		L_NUM5PIC,                           // 38
-		L_NUM6PIC,                           // 39
-		L_NUM7PIC,                           // 40
-		L_NUM8PIC,                           // 41
-		L_NUM9PIC,                           // 42
-		L_PERCENTPIC,                        // 43
-		L_APIC,                              // 44
-		L_BPIC,                              // 45
-		L_CPIC,                              // 46
-		L_DPIC,                              // 47
-		L_EPIC,                              // 48
-		L_FPIC,                              // 49
-		L_GPIC,                              // 50
-		L_HPIC,                              // 51
-		L_IPIC,                              // 52
-		L_JPIC,                              // 53
-		L_KPIC,                              // 54
-		L_LPIC,                              // 55
-		L_MPIC,                              // 56
-		L_NPIC,                              // 57
-		L_OPIC,                              // 58
-		L_PPIC,                              // 59
-		L_QPIC,                              // 60
-		L_RPIC,                              // 61
-		L_SPIC,                              // 62
-		L_TPIC,                              // 63
-		L_UPIC,                              // 64
-		L_VPIC,                              // 65
-		L_WPIC,                              // 66
-		L_XPIC,                              // 67
-		L_YPIC,                              // 68
-		L_ZPIC,                              // 69
-		L_EXPOINTPIC,                        // 70
-		L_APOSTROPHEPIC,                     // 71
-		L_GUY2PIC,                           // 72
-		L_BJWINSPIC,                         // 73
-		// Lump Start
-		TITLE1PIC,                           // 74
-		TITLE2PIC,                           // 75
-		STATUSBARPIC,                        // 76
-		PG13PIC,                             // 77
-		CREDITSPIC,                          // 78
-		// Lump Start
-		KNIFEPIC,                            // 79
-		GUNPIC,                              // 80
-		MACHINEGUNPIC,                       // 81
-		GATLINGGUNPIC,                       // 82
-		NOKEYPIC,                            // 83
-		GOLDKEYPIC,                          // 84
-		SILVERKEYPIC,                        // 85
-		N_BLANKPIC,                          // 86
-		N_0PIC,                              // 87
-		N_1PIC,                              // 88
-		N_2PIC,                              // 89
-		N_3PIC,                              // 90
-		N_4PIC,                              // 91
-		N_5PIC,                              // 92
-		N_6PIC,                              // 93
-		N_7PIC,                              // 94
-		N_8PIC,                              // 95
-		N_9PIC,                              // 96
-		FACE1APIC,                           // 97
-		FACE1BPIC,                           // 98
-		FACE1CPIC,                           // 99
-		FACE2APIC,                           // 100
-		FACE2BPIC,                           // 101
-		FACE2CPIC,                           // 102
-		FACE3APIC,                           // 103
-		FACE3BPIC,                           // 104
-		FACE3CPIC,                           // 105
-		FACE4APIC,                           // 106
-		FACE4BPIC,                           // 107
-		FACE4CPIC,                           // 108
-		FACE5APIC,                           // 109
-		FACE5BPIC,                           // 110
-		FACE5CPIC,                           // 111
-		FACE6APIC,                           // 112
-		FACE6BPIC,                           // 113
-		FACE6CPIC,                           // 114
-		FACE7APIC,                           // 115
-		FACE7BPIC,                           // 116
-		FACE7CPIC,                           // 117
-		FACE8APIC,                           // 118
-		GOTGATLINGPIC,                       // 119
-		GODMODEFACE1PIC,                     // 120
-		GODMODEFACE2PIC,                     // 121
-		GODMODEFACE3PIC,                     // 122
-		BJWAITING1PIC,                       // 123
-		BJWAITING2PIC,                       // 124
-		BJOUCHPIC,                           // 125
-		PAUSEDPIC,                           // 126
-		GETPSYCHEDPIC,                       // 127
-
-
-
-		ORDERSCREEN=129,
-		ERRORSCREEN,                         // 130
-		TITLEPALETTE,                        // 131
-		T_DEMO0,                             // 132
-		ENUMEND
-	     } graphicnums;
-
-//
-// Data LUMPs
-//
-#define BACKDROP_LUMP_START		3
-#define BACKDROP_LUMP_END		8
-
-#define CONTROL_LUMP_START		9
-#define CONTROL_LUMP_END		15
-
-#define OPTIONS_LUMP_START		16
-#define OPTIONS_LUMP_END		16
-
-#define SOUND_LUMP_START		17
-#define SOUND_LUMP_END			19
-
-#define NEWGAME_LUMP_START		20
-#define NEWGAME_LUMP_END		24
-
-#define LOADSAVE_LUMP_START		25
-#define LOADSAVE_LUMP_END		28
-
-#define HIGHSCORES_LUMP_START		29
-#define HIGHSCORES_LUMP_END		30
-
-#define LEVELEND_LUMP_START		31
-#define LEVELEND_LUMP_END		73
-
-#define TITLESCREEN_LUMP_START		74
-#define TITLESCREEN_LUMP_END		75
-
-#define LATCHPICS_LUMP_START		79
-#define LATCHPICS_LUMP_END		127
-
-
-//
-// Amount of each data item
-//
-#define NUMCHUNKS    133
-#define NUMFONT      2
-#define NUMFONTM     0
-#define NUMPICS      125
-#define NUMPICM      0
-#define NUMSPRITES   0
-#define NUMTILE8     72
-#define NUMTILE8M    0
-#define NUMTILE16    0
-#define NUMTILE16M   0
-#define NUMTILE32    0
-#define NUMTILE32M   0
-#define NUMEXTERNS   4
-//
-// File offsets for data items
-//
-#define STRUCTPIC    0
-
-#define STARTFONT    1
-#define STARTFONTM   3
-#define STARTPICS    3
-#define STARTPICM    128
-#define STARTSPRITES 128
-#define STARTTILE8   128
-#define STARTTILE8M  129
-#define STARTTILE16  129
-#define STARTTILE16M 129
-#define STARTTILE32  129
-#define STARTTILE32M 129
-#define STARTEXTERNS 129
-
-//
-// Thank you for using IGRAB!
-//
--- a/gfxv_sod.h
+++ /dev/null
@@ -1,280 +1,0 @@
-//////////////////////////////////////
-//
-// Graphics .H file for .SOD
-// IGRAB-ed on Thu Oct 08 20:38:29 1992
-//
-//////////////////////////////////////
-
-typedef enum {
-		// Lump Start
-		C_BACKDROPPIC=3,
-		C_MOUSELBACKPIC,                     // 4
-		C_CURSOR1PIC,                        // 5
-		C_CURSOR2PIC,                        // 6
-		C_NOTSELECTEDPIC,                    // 7
-		C_SELECTEDPIC,                       // 8
-		// Lump Start
-		C_CUSTOMIZEPIC,                      // 9
-		C_JOY1PIC,                           // 10
-		C_JOY2PIC,                           // 11
-		C_MOUSEPIC,                          // 12
-		C_JOYSTICKPIC,                       // 13
-		C_KEYBOARDPIC,                       // 14
-		C_CONTROLPIC,                        // 15
-		// Lump Start
-		C_OPTIONSPIC,                        // 16
-		// Lump Start
-		C_FXTITLEPIC,                        // 17
-		C_DIGITITLEPIC,                      // 18
-		C_MUSICTITLEPIC,                     // 19
-		// Lump Start
-		C_HOWTOUGHPIC,                       // 20
-		C_BABYMODEPIC,                       // 21
-		C_EASYPIC,                           // 22
-		C_NORMALPIC,                         // 23
-		C_HARDPIC,                           // 24
-		// Lump Start
-		C_DISKLOADING1PIC,                   // 25
-		C_DISKLOADING2PIC,                   // 26
-		C_LOADGAMEPIC,                       // 27
-		C_SAVEGAMEPIC,                       // 28
-		// Lump Start
-		HIGHSCORESPIC,                       // 29
-		C_WONSPEARPIC,                       // 30
-		// Lump Start
-		BJCOLLAPSE1PIC,                      // 31
-		BJCOLLAPSE2PIC,                      // 32
-		BJCOLLAPSE3PIC,                      // 33
-		BJCOLLAPSE4PIC,                      // 34
-		ENDPICPIC,                           // 35
-		// Lump Start
-		L_GUYPIC,                            // 36
-		L_COLONPIC,                          // 37
-		L_NUM0PIC,                           // 38
-		L_NUM1PIC,                           // 39
-		L_NUM2PIC,                           // 40
-		L_NUM3PIC,                           // 41
-		L_NUM4PIC,                           // 42
-		L_NUM5PIC,                           // 43
-		L_NUM6PIC,                           // 44
-		L_NUM7PIC,                           // 45
-		L_NUM8PIC,                           // 46
-		L_NUM9PIC,                           // 47
-		L_PERCENTPIC,                        // 48
-		L_APIC,                              // 49
-		L_BPIC,                              // 50
-		L_CPIC,                              // 51
-		L_DPIC,                              // 52
-		L_EPIC,                              // 53
-		L_FPIC,                              // 54
-		L_GPIC,                              // 55
-		L_HPIC,                              // 56
-		L_IPIC,                              // 57
-		L_JPIC,                              // 58
-		L_KPIC,                              // 59
-		L_LPIC,                              // 60
-		L_MPIC,                              // 61
-		L_NPIC,                              // 62
-		L_OPIC,                              // 63
-		L_PPIC,                              // 64
-		L_QPIC,                              // 65
-		L_RPIC,                              // 66
-		L_SPIC,                              // 67
-		L_TPIC,                              // 68
-		L_UPIC,                              // 69
-		L_VPIC,                              // 70
-		L_WPIC,                              // 71
-		L_XPIC,                              // 72
-		L_YPIC,                              // 73
-		L_ZPIC,                              // 74
-		L_EXPOINTPIC,                        // 75
-		L_APOSTROPHEPIC,                     // 76
-		L_GUY2PIC,                           // 77
-		L_BJWINSPIC,                         // 78
-		// Lump Start
-		TITLE1PIC,                           // 79
-		TITLE2PIC,                           // 80
-		// Lump Start
-		ENDSCREEN11PIC,                      // 81
-		// Lump Start
-		ENDSCREEN12PIC,                      // 82
-		ENDSCREEN3PIC,                       // 83
-		ENDSCREEN4PIC,                       // 84
-		ENDSCREEN5PIC,                       // 85
-		ENDSCREEN6PIC,                       // 86
-		ENDSCREEN7PIC,                       // 87
-		ENDSCREEN8PIC,                       // 88
-		ENDSCREEN9PIC,                       // 89
-		STATUSBARPIC,                        // 90
-		PG13PIC,                             // 91
-		CREDITSPIC,                          // 92
-		// Lump Start
-		IDGUYS1PIC,                          // 93
-		IDGUYS2PIC,                          // 94
-		// Lump Start
-		COPYPROTTOPPIC,                      // 95
-		COPYPROTBOXPIC,                      // 96
-		BOSSPIC1PIC,                         // 97
-		BOSSPIC2PIC,                         // 98
-		BOSSPIC3PIC,                         // 99
-		BOSSPIC4PIC,                         // 100
-		// Lump Start
-		KNIFEPIC,                            // 101
-		GUNPIC,                              // 102
-		MACHINEGUNPIC,                       // 103
-		GATLINGGUNPIC,                       // 104
-		NOKEYPIC,                            // 105
-		GOLDKEYPIC,                          // 106
-		SILVERKEYPIC,                        // 107
-		N_BLANKPIC,                          // 108
-		N_0PIC,                              // 109
-		N_1PIC,                              // 110
-		N_2PIC,                              // 111
-		N_3PIC,                              // 112
-		N_4PIC,                              // 113
-		N_5PIC,                              // 114
-		N_6PIC,                              // 115
-		N_7PIC,                              // 116
-		N_8PIC,                              // 117
-		N_9PIC,                              // 118
-		FACE1APIC,                           // 119
-		FACE1BPIC,                           // 120
-		FACE1CPIC,                           // 121
-		FACE2APIC,                           // 122
-		FACE2BPIC,                           // 123
-		FACE2CPIC,                           // 124
-		FACE3APIC,                           // 125
-		FACE3BPIC,                           // 126
-		FACE3CPIC,                           // 127
-		FACE4APIC,                           // 128
-		FACE4BPIC,                           // 129
-		FACE4CPIC,                           // 130
-		FACE5APIC,                           // 131
-		FACE5BPIC,                           // 132
-		FACE5CPIC,                           // 133
-		FACE6APIC,                           // 134
-		FACE6BPIC,                           // 135
-		FACE6CPIC,                           // 136
-		FACE7APIC,                           // 137
-		FACE7BPIC,                           // 138
-		FACE7CPIC,                           // 139
-		FACE8APIC,                           // 140
-		GOTGATLINGPIC,                       // 141
-		GODMODEFACE1PIC,                     // 142
-		GODMODEFACE2PIC,                     // 143
-		GODMODEFACE3PIC,                     // 144
-		BJWAITING1PIC,                       // 145
-		BJWAITING2PIC,                       // 146
-		BJOUCHPIC,                           // 147
-		PAUSEDPIC,                           // 148
-		GETPSYCHEDPIC,                       // 149
-
-
-
-		ORDERSCREEN=151,
-		ERRORSCREEN,                         // 152
-		TITLEPALETTE,                        // 153
-		END1PALETTE,                         // 154
-		END2PALETTE,                         // 155
-		END3PALETTE,                         // 156
-		END4PALETTE,                         // 157
-		END5PALETTE,                         // 158
-		END6PALETTE,                         // 159
-		END7PALETTE,                         // 160
-		END8PALETTE,                         // 161
-		END9PALETTE,                         // 162
-		IDGUYSPALETTE,                       // 163
-		T_DEMO0,                             // 164
-		T_DEMO1,                             // 165
-		T_DEMO2,                             // 166
-		T_DEMO3,                             // 167
-		T_ENDART1,                           // 168
-		ENUMEND
-	     } graphicnums;
-
-//
-// Data LUMPs
-//
-#define BACKDROP_LUMP_START		3
-#define BACKDROP_LUMP_END		8
-
-#define CONTROL_LUMP_START		9
-#define CONTROL_LUMP_END		15
-
-#define OPTIONS_LUMP_START		16
-#define OPTIONS_LUMP_END		16
-
-#define SOUND_LUMP_START		17
-#define SOUND_LUMP_END			19
-
-#define NEWGAME_LUMP_START		20
-#define NEWGAME_LUMP_END		24
-
-#define LOADSAVE_LUMP_START		25
-#define LOADSAVE_LUMP_END		28
-
-#define HIGHSCORES_LUMP_START		29
-#define HIGHSCORES_LUMP_END		30
-
-#define ENDGAME_LUMP_START		31
-#define ENDGAME_LUMP_END		35
-
-#define LEVELEND_LUMP_START		36
-#define LEVELEND_LUMP_END		78
-
-#define TITLESCREEN_LUMP_START		79
-#define TITLESCREEN_LUMP_END		80
-
-#define ENDGAME1_LUMP_START		81
-#define ENDGAME1_LUMP_END		81
-
-#define ENDGAME2_LUMP_START		82
-#define ENDGAME2_LUMP_END		82
-
-#define EASTEREGG_LUMP_START		93
-#define EASTEREGG_LUMP_END		94
-
-#define COPYPROT_LUMP_START		95
-#define COPYPROT_LUMP_END		100
-
-#define LATCHPICS_LUMP_START		101
-#define LATCHPICS_LUMP_END		149
-
-
-//
-// Amount of each data item
-//
-#define NUMCHUNKS    169
-#define NUMFONT      2
-#define NUMFONTM     0
-#define NUMPICS      147
-#define NUMPICM      0
-#define NUMSPRITES   0
-#define NUMTILE8     72
-#define NUMTILE8M    0
-#define NUMTILE16    0
-#define NUMTILE16M   0
-#define NUMTILE32    0
-#define NUMTILE32M   0
-#define NUMEXTERNS   18
-//
-// File offsets for data items
-//
-#define STRUCTPIC    0
-
-#define STARTFONT    1
-#define STARTFONTM   3
-#define STARTPICS    3
-#define STARTPICM    150
-#define STARTSPRITES 150
-#define STARTTILE8   150
-#define STARTTILE8M  151
-#define STARTTILE16  151
-#define STARTTILE16M 151
-#define STARTTILE32  151
-#define STARTTILE32M 151
-#define STARTEXTERNS 151
-
-//
-// Thank you for using IGRAB!
-//
--- a/gfxv_wl1.h
+++ /dev/null
@@ -1,209 +1,0 @@
-//////////////////////////////////////
-//
-// Graphics .H file for .WL1
-// IGRAB-ed on Sun May 03 01:19:32 1992
-//
-//////////////////////////////////////
-
-typedef enum {
-		// Lump Start
-		H_BJPIC=3,
-		H_CASTLEPIC,                 // 4
-		H_KEYBOARDPIC,               // 5
-		H_JOYPIC,                    // 6
-		H_HEALPIC,                   // 7
-		H_TREASUREPIC,               // 8
-		H_GUNPIC,                    // 9
-		H_KEYPIC,                    // 10
-		H_BLAZEPIC,                  // 11
-		H_WEAPON1234PIC,             // 12
-		H_WOLFLOGOPIC,               // 13
-		H_VISAPIC,                   // 14
-		H_MCPIC,                     // 15
-		H_IDLOGOPIC,                 // 16
-		H_TOPWINDOWPIC,              // 17
-		H_LEFTWINDOWPIC,             // 18
-		H_RIGHTWINDOWPIC,            // 19
-		H_BOTTOMINFOPIC,             // 20
-		// Lump Start
-		C_OPTIONSPIC,                // 21
-		C_CURSOR1PIC,                // 22
-		C_CURSOR2PIC,                // 23
-		C_NOTSELECTEDPIC,            // 24
-		C_SELECTEDPIC,               // 25
-		C_FXTITLEPIC,                // 26
-		C_DIGITITLEPIC,              // 27
-		C_MUSICTITLEPIC,             // 28
-		C_MOUSELBACKPIC,             // 29
-		C_BABYMODEPIC,               // 30
-		C_EASYPIC,                   // 31
-		C_NORMALPIC,                 // 32
-		C_HARDPIC,                   // 33
-		C_LOADSAVEDISKPIC,           // 34
-		C_DISKLOADING1PIC,           // 35
-		C_DISKLOADING2PIC,           // 36
-		C_CONTROLPIC,                // 37
-		C_CUSTOMIZEPIC,              // 38
-		C_LOADGAMEPIC,               // 39
-		C_SAVEGAMEPIC,               // 40
-		C_EPISODE1PIC,               // 41
-		C_EPISODE2PIC,               // 42
-		C_EPISODE3PIC,               // 43
-		C_EPISODE4PIC,               // 44
-		C_EPISODE5PIC,               // 45
-		C_EPISODE6PIC,               // 46
-		C_CODEPIC,                   // 47
-		// Lump Start
-		L_GUYPIC,                    // 48
-		L_COLONPIC,                  // 49
-		L_NUM0PIC,                   // 50
-		L_NUM1PIC,                   // 51
-		L_NUM2PIC,                   // 52
-		L_NUM3PIC,                   // 53
-		L_NUM4PIC,                   // 54
-		L_NUM5PIC,                   // 55
-		L_NUM6PIC,                   // 56
-		L_NUM7PIC,                   // 57
-		L_NUM8PIC,                   // 58
-		L_NUM9PIC,                   // 59
-		L_PERCENTPIC,                // 60
-		L_APIC,                      // 61
-		L_BPIC,                      // 62
-		L_CPIC,                      // 63
-		L_DPIC,                      // 64
-		L_EPIC,                      // 65
-		L_FPIC,                      // 66
-		L_GPIC,                      // 67
-		L_HPIC,                      // 68
-		L_IPIC,                      // 69
-		L_JPIC,                      // 70
-		L_KPIC,                      // 71
-		L_LPIC,                      // 72
-		L_MPIC,                      // 73
-		L_NPIC,                      // 74
-		L_OPIC,                      // 75
-		L_PPIC,                      // 76
-		L_QPIC,                      // 77
-		L_RPIC,                      // 78
-		L_SPIC,                      // 79
-		L_TPIC,                      // 80
-		L_UPIC,                      // 81
-		L_VPIC,                      // 82
-		L_WPIC,                      // 83
-		L_XPIC,                      // 84
-		L_YPIC,                      // 85
-		L_ZPIC,                      // 86
-		L_EXPOINTPIC,                // 87
-		L_GUY2PIC,                   // 88
-		L_BJWINSPIC,                 // 89
-		STATUSBARPIC,                // 90
-		TITLEPIC,                    // 91
-		PG13PIC,                     // 92
-		CREDITSPIC,                  // 93
-		HIGHSCORESPIC,               // 94
-		// Lump Start
-		KNIFEPIC,                    // 95
-		GUNPIC,                      // 96
-		MACHINEGUNPIC,               // 97
-		GATLINGGUNPIC,               // 98
-		NOKEYPIC,                    // 99
-		GOLDKEYPIC,                  // 100
-		SILVERKEYPIC,                // 101
-		N_BLANKPIC,                  // 102
-		N_0PIC,                      // 103
-		N_1PIC,                      // 104
-		N_2PIC,                      // 105
-		N_3PIC,                      // 106
-		N_4PIC,                      // 107
-		N_5PIC,                      // 108
-		N_6PIC,                      // 109
-		N_7PIC,                      // 110
-		N_8PIC,                      // 111
-		N_9PIC,                      // 112
-		FACE1APIC,                   // 113
-		FACE1BPIC,                   // 114
-		FACE1CPIC,                   // 115
-		FACE2APIC,                   // 116
-		FACE2BPIC,                   // 117
-		FACE2CPIC,                   // 118
-		FACE3APIC,                   // 119
-		FACE3BPIC,                   // 120
-		FACE3CPIC,                   // 121
-		FACE4APIC,                   // 122
-		FACE4BPIC,                   // 123
-		FACE4CPIC,                   // 124
-		FACE5APIC,                   // 125
-		FACE5BPIC,                   // 126
-		FACE5CPIC,                   // 127
-		FACE6APIC,                   // 128
-		FACE6BPIC,                   // 129
-		FACE6CPIC,                   // 130
-		FACE7APIC,                   // 131
-		FACE7BPIC,                   // 132
-		FACE7CPIC,                   // 133
-		FACE8APIC,                   // 134
-		GOTGATLINGPIC,               // 135
-		MUTANTBJPIC,                 // 136
-		PAUSEDPIC,                   // 137
-		GETPSYCHEDPIC,               // 138
-
-
-
-		ORDERSCREEN=554,
-		ERRORSCREEN,                 // 555
-		ENUMEND
-	     } graphicnums;
-
-//
-// Data LUMPs
-//
-#define README_LUMP_START		3
-#define README_LUMP_END			20
-
-#define CONTROLS_LUMP_START		21
-#define CONTROLS_LUMP_END		47
-
-#define LEVELEND_LUMP_START		48
-#define LEVELEND_LUMP_END		89
-
-#define LATCHPICS_LUMP_START		95
-#define LATCHPICS_LUMP_END		138
-
-
-//
-// Amount of each data item
-//
-#define NUMCHUNKS    556
-#define NUMFONT      2
-#define NUMFONTM     0
-#define NUMPICS      136
-#define NUMPICM      0
-#define NUMSPRITES   0
-#define NUMTILE8     72
-#define NUMTILE8M    0
-#define NUMTILE16    144
-#define NUMTILE16M   270
-#define NUMTILE32    0
-#define NUMTILE32M   0
-#define NUMEXTERNS   2
-//
-// File offsets for data items
-//
-#define STRUCTPIC    0
-
-#define STARTFONT    1
-#define STARTFONTM   3
-#define STARTPICS    3
-#define STARTPICM    139
-#define STARTSPRITES 139
-#define STARTTILE8   139
-#define STARTTILE8M  140
-#define STARTTILE16  140
-#define STARTTILE16M 284
-#define STARTTILE32  554
-#define STARTTILE32M 554
-#define STARTEXTERNS 554
-
-//
-// Thank you for using IGRAB!
-//
--- a/gfxv_wl6.h
+++ /dev/null
@@ -1,216 +1,0 @@
-//////////////////////////////////////
-//
-// Graphics .H file for .WL6
-// IGRAB-ed on Wed Apr 13 06:58:44 1994
-//
-//////////////////////////////////////
-
-typedef enum {
-		// Lump Start
-		H_BJPIC=3,
-		H_CASTLEPIC,                         // 4
-		H_BLAZEPIC,                          // 5
-		H_TOPWINDOWPIC,                      // 6
-		H_LEFTWINDOWPIC,                     // 7
-		H_RIGHTWINDOWPIC,                    // 8
-		H_BOTTOMINFOPIC,                     // 9
-		// Lump Start
-		C_OPTIONSPIC,                        // 10
-		C_CURSOR1PIC,                        // 11
-		C_CURSOR2PIC,                        // 12
-		C_NOTSELECTEDPIC,                    // 13
-		C_SELECTEDPIC,                       // 14
-		C_FXTITLEPIC,                        // 15
-		C_DIGITITLEPIC,                      // 16
-		C_MUSICTITLEPIC,                     // 17
-		C_MOUSELBACKPIC,                     // 18
-		C_BABYMODEPIC,                       // 19
-		C_EASYPIC,                           // 20
-		C_NORMALPIC,                         // 21
-		C_HARDPIC,                           // 22
-		C_LOADSAVEDISKPIC,                   // 23
-		C_DISKLOADING1PIC,                   // 24
-		C_DISKLOADING2PIC,                   // 25
-		C_CONTROLPIC,                        // 26
-		C_CUSTOMIZEPIC,                      // 27
-		C_LOADGAMEPIC,                       // 28
-		C_SAVEGAMEPIC,                       // 29
-		C_EPISODE1PIC,                       // 30
-		C_EPISODE2PIC,                       // 31
-		C_EPISODE3PIC,                       // 32
-		C_EPISODE4PIC,                       // 33
-		C_EPISODE5PIC,                       // 34
-		C_EPISODE6PIC,                       // 35
-		C_CODEPIC,                           // 36
-		C_TIMECODEPIC,                       // 37
-		C_LEVELPIC,                          // 38
-		C_NAMEPIC,                           // 39
-		C_SCOREPIC,                          // 40
-		C_JOY1PIC,                           // 41
-		C_JOY2PIC,                           // 42
-		// Lump Start
-		L_GUYPIC,                            // 43
-		L_COLONPIC,                          // 44
-		L_NUM0PIC,                           // 45
-		L_NUM1PIC,                           // 46
-		L_NUM2PIC,                           // 47
-		L_NUM3PIC,                           // 48
-		L_NUM4PIC,                           // 49
-		L_NUM5PIC,                           // 50
-		L_NUM6PIC,                           // 51
-		L_NUM7PIC,                           // 52
-		L_NUM8PIC,                           // 53
-		L_NUM9PIC,                           // 54
-		L_PERCENTPIC,                        // 55
-		L_APIC,                              // 56
-		L_BPIC,                              // 57
-		L_CPIC,                              // 58
-		L_DPIC,                              // 59
-		L_EPIC,                              // 60
-		L_FPIC,                              // 61
-		L_GPIC,                              // 62
-		L_HPIC,                              // 63
-		L_IPIC,                              // 64
-		L_JPIC,                              // 65
-		L_KPIC,                              // 66
-		L_LPIC,                              // 67
-		L_MPIC,                              // 68
-		L_NPIC,                              // 69
-		L_OPIC,                              // 70
-		L_PPIC,                              // 71
-		L_QPIC,                              // 72
-		L_RPIC,                              // 73
-		L_SPIC,                              // 74
-		L_TPIC,                              // 75
-		L_UPIC,                              // 76
-		L_VPIC,                              // 77
-		L_WPIC,                              // 78
-		L_XPIC,                              // 79
-		L_YPIC,                              // 80
-		L_ZPIC,                              // 81
-		L_EXPOINTPIC,                        // 82
-		L_APOSTROPHEPIC,                     // 83
-		L_GUY2PIC,                           // 84
-		L_BJWINSPIC,                         // 85
-		STATUSBARPIC,                        // 86
-		TITLEPIC,                            // 87
-		PG13PIC,                             // 88
-		CREDITSPIC,                          // 89
-		HIGHSCORESPIC,                       // 90
-		// Lump Start
-		KNIFEPIC,                            // 91
-		GUNPIC,                              // 92
-		MACHINEGUNPIC,                       // 93
-		GATLINGGUNPIC,                       // 94
-		NOKEYPIC,                            // 95
-		GOLDKEYPIC,                          // 96
-		SILVERKEYPIC,                        // 97
-		N_BLANKPIC,                          // 98
-		N_0PIC,                              // 99
-		N_1PIC,                              // 100
-		N_2PIC,                              // 101
-		N_3PIC,                              // 102
-		N_4PIC,                              // 103
-		N_5PIC,                              // 104
-		N_6PIC,                              // 105
-		N_7PIC,                              // 106
-		N_8PIC,                              // 107
-		N_9PIC,                              // 108
-		FACE1APIC,                           // 109
-		FACE1BPIC,                           // 110
-		FACE1CPIC,                           // 111
-		FACE2APIC,                           // 112
-		FACE2BPIC,                           // 113
-		FACE2CPIC,                           // 114
-		FACE3APIC,                           // 115
-		FACE3BPIC,                           // 116
-		FACE3CPIC,                           // 117
-		FACE4APIC,                           // 118
-		FACE4BPIC,                           // 119
-		FACE4CPIC,                           // 120
-		FACE5APIC,                           // 121
-		FACE5BPIC,                           // 122
-		FACE5CPIC,                           // 123
-		FACE6APIC,                           // 124
-		FACE6BPIC,                           // 125
-		FACE6CPIC,                           // 126
-		FACE7APIC,                           // 127
-		FACE7BPIC,                           // 128
-		FACE7CPIC,                           // 129
-		FACE8APIC,                           // 130
-		GOTGATLINGPIC,                       // 131
-		MUTANTBJPIC,                         // 132
-		PAUSEDPIC,                           // 133
-		GETPSYCHEDPIC,                       // 134
-
-
-
-		ORDERSCREEN=136,
-		ERRORSCREEN,                         // 137
-		T_HELPART,                           // 138
-		T_DEMO0,                             // 139
-		T_DEMO1,                             // 140
-		T_DEMO2,                             // 141
-		T_DEMO3,                             // 142
-		T_ENDART1,                           // 143
-		T_ENDART2,                           // 144
-		T_ENDART3,                           // 145
-		T_ENDART4,                           // 146
-		T_ENDART5,                           // 147
-		T_ENDART6,                           // 148
-		ENUMEND
-	     } graphicnums;
-
-//
-// Data LUMPs
-//
-#define README_LUMP_START		3
-#define README_LUMP_END			9
-
-#define CONTROLS_LUMP_START		10
-#define CONTROLS_LUMP_END		42
-
-#define LEVELEND_LUMP_START		43
-#define LEVELEND_LUMP_END		85
-
-#define LATCHPICS_LUMP_START		91
-#define LATCHPICS_LUMP_END		134
-
-
-//
-// Amount of each data item
-//
-#define NUMCHUNKS    149
-#define NUMFONT      2
-#define NUMFONTM     0
-#define NUMPICS      132
-#define NUMPICM      0
-#define NUMSPRITES   0
-#define NUMTILE8     72
-#define NUMTILE8M    0
-#define NUMTILE16    0
-#define NUMTILE16M   0
-#define NUMTILE32    0
-#define NUMTILE32M   0
-#define NUMEXTERNS   13
-//
-// File offsets for data items
-//
-#define STRUCTPIC    0
-
-#define STARTFONT    1
-#define STARTFONTM   3
-#define STARTPICS    3
-#define STARTPICM    135
-#define STARTSPRITES 135
-#define STARTTILE8   135
-#define STARTTILE8M  136
-#define STARTTILE16  136
-#define STARTTILE16M 136
-#define STARTTILE32  136
-#define STARTTILE32M 136
-#define STARTEXTERNS 136
-
-//
-// Thank you for using IGRAB!
-//
--- /dev/null
+++ b/gm.c
@@ -1,0 +1,4 @@
+#include <u.h>
+#include <libc.h>
+#include "dat.h"
+#include "fns.h"
--- a/in.c
+++ b/in.c
@@ -1,44 +1,6 @@
-//
-//	ID Engine
-//	ID_IN.c - Input Manager
-//	v1.0d1
-//	By Jason Blochowiak
-//
-
-//
-//	This module handles dealing with the various input devices
-//
-//	Depends on: Memory Mgr (for demo recording), Sound Mgr (for timing stuff),
-//				User Mgr (for command line parms)
-//
-//	Globals:
-//		LastScan - The keyboard scan code of the last key pressed
-//		LastASCII - The ASCII value of the last key pressed
-//	DEBUG - there are more globals
-//
-
-#include "ID_HEADS.H"
-#pragma	hdrstop
-
 #define	KeyInt		9	// The keyboard ISR number
 
-//
-// mouse constants
-//
-#define	MReset		0
-#define	MButtons	3
-#define	MDelta		11
 
-#define	MouseInt	0x33
-#define	Mouse(x)	_AX = x,geninterrupt(MouseInt)
-
-//
-// joystick constants
-//
-#define	JoyScaleMax		32768
-#define	JoyScaleShift	8
-#define	MaxJoyValue		5000
-
 /*
 =============================================================================
 
@@ -51,8 +13,6 @@
 // configuration variables
 //
 int			MousePresent;
-int			JoysPresent[MaxJoys];
-int			JoyPadPresent;
 
 
 // 	Global variables
@@ -62,7 +22,6 @@
 		u8int	LastScan;
 
 		KeyboardDef	KbdDefs = {0x1d,0x38,0x47,0x48,0x49,0x4b,0x4d,0x4f,0x50,0x51};
-		JoystickDef	JoyDefs[MaxJoys];
 		ControlType	Controls[MaxPlayers];
 
 		u32int MouseDownCount;
@@ -130,8 +89,6 @@
 static	void			(*INL_KeyHook)(void);
 static	void interrupt	(*OldKeyVect)(void);
 
-static	char			*ParmStrings[] = {"nojoys","nomouse",nil};
-
 //	Internal routines
 
 ///////////////////////////////////////////////////////////////////////////
@@ -240,189 +197,6 @@
 
 ///////////////////////////////////////////////////////////////////////////
 //
-//	IN_GetJoyAbs() - Reads the absolute position of the specified joystick
-//
-///////////////////////////////////////////////////////////////////////////
-void
-IN_GetJoyAbs(u16int joy,u16int *xp,u16int *yp)
-{
-	u8int	xb,yb,
-			xs,ys;
-	u16int	x,y;
-
-	x = y = 0;
-	xs = joy? 2 : 0;		// Find shift value for x axis
-	xb = 1 << xs;			// Use shift value to get x bit mask
-	ys = joy? 3 : 1;		// Do the same for y axis
-	yb = 1 << ys;
-
-// Read the absolute joystick values
-asm		pushf				// Save some registers
-asm		push	si
-asm		push	di
-asm		cli					// Make sure an interrupt doesn't screw the timings
-
-
-asm		mov		dx,0x201
-asm		in		al,dx
-asm		out		dx,al		// Clear the resistors
-
-asm		mov		ah,[xb]		// Get masks into registers
-asm		mov		ch,[yb]
-
-asm		xor		si,si		// Clear count registers
-asm		xor		di,di
-asm		xor		bh,bh		// Clear high byte of bx for later
-
-asm		push	bp			// Don't mess up stack frame
-asm		mov		bp,MaxJoyValue
-
-loop:
-asm		in		al,dx		// Get bits indicating whether all are finished
-
-asm		dec		bp			// Check bounding register
-asm		jz		done		// We have a silly value - abort
-
-asm		mov		bl,al		// Duplicate the bits
-asm		and		bl,ah		// Mask off useless bits (in [xb])
-asm		add		si,bx		// Possibly increment count register
-asm		mov		cl,bl		// Save for testing later
-
-asm		mov		bl,al
-asm		and		bl,ch		// [yb]
-asm		add		di,bx
-
-asm		add		cl,bl
-asm		jnz		loop 		// If both bits were 0, drop out
-
-done:
-asm     pop		bp
-
-asm		mov		cl,[xs]		// Get the number of bits to shift
-asm		shr		si,cl		//  and shift the count that many times
-
-asm		mov		cl,[ys]
-asm		shr		di,cl
-
-asm		mov		[x],si		// Store the values into the variables
-asm		mov		[y],di
-
-asm		pop		di
-asm		pop		si
-asm		popf				// Restore the registers
-
-	*xp = x;
-	*yp = y;
-}
-
-///////////////////////////////////////////////////////////////////////////
-//
-//	INL_GetJoyDelta() - Returns the relative movement of the specified
-//		joystick (from +/-127)
-//
-///////////////////////////////////////////////////////////////////////////
-void INL_GetJoyDelta(u16int joy,s16int *dx,s16int *dy)
-{
-	u16int		x,y;
-	u32int time;
-	JoystickDef	*def;
-	static u32int lasttime;
-
-	IN_GetJoyAbs(joy,&x,&y);
-	def = JoyDefs + joy;
-
-	if (x < def->threshMinX)
-	{
-		if (x < def->joyMinX)
-			x = def->joyMinX;
-
-		x = -(x - def->threshMinX);
-		x *= def->joyMultXL;
-		x >>= JoyScaleShift;
-		*dx = (x > 127)? -127 : -x;
-	}
-	else if (x > def->threshMaxX)
-	{
-		if (x > def->joyMaxX)
-			x = def->joyMaxX;
-
-		x = x - def->threshMaxX;
-		x *= def->joyMultXH;
-		x >>= JoyScaleShift;
-		*dx = (x > 127)? 127 : x;
-	}
-	else
-		*dx = 0;
-
-	if (y < def->threshMinY)
-	{
-		if (y < def->joyMinY)
-			y = def->joyMinY;
-
-		y = -(y - def->threshMinY);
-		y *= def->joyMultYL;
-		y >>= JoyScaleShift;
-		*dy = (y > 127)? -127 : -y;
-	}
-	else if (y > def->threshMaxY)
-	{
-		if (y > def->joyMaxY)
-			y = def->joyMaxY;
-
-		y = y - def->threshMaxY;
-		y *= def->joyMultYH;
-		y >>= JoyScaleShift;
-		*dy = (y > 127)? 127 : y;
-	}
-	else
-		*dy = 0;
-
-	lasttime = TimeCount;
-}
-
-///////////////////////////////////////////////////////////////////////////
-//
-//	INL_GetJoyButtons() - Returns the button status of the specified
-//		joystick
-//
-///////////////////////////////////////////////////////////////////////////
-static u16int
-INL_GetJoyButtons(u16int joy)
-{
-register	u16int	result;
-
-	result = inportb(0x201);	// Get all the joystick buttons
-	result >>= joy? 6 : 4;	// Shift into bits 0-1
-	result &= 3;				// Mask off the useless bits
-	result ^= 3;
-	return(result);
-}
-
-///////////////////////////////////////////////////////////////////////////
-//
-//	IN_GetJoyButtonsDB() - Returns the de-bounced button status of the
-//		specified joystick
-//
-///////////////////////////////////////////////////////////////////////////
-u16int
-IN_GetJoyButtonsDB(u16int joy)
-{
-	u32int lasttime;
-	u16int		result1,result2;
-
-	do
-	{
-		result1 = INL_GetJoyButtons(joy);
-		lasttime = TimeCount;
-		while (TimeCount == lasttime)
-			;
-		result2 = INL_GetJoyButtons(joy);
-	} while (result1 != result2);
-	return(result1);
-}
-
-///////////////////////////////////////////////////////////////////////////
-//
 //	INL_StartKbd() - Sets up my keyboard stuff for use
 //
 ///////////////////////////////////////////////////////////////////////////
@@ -491,92 +265,9 @@
 {
 }
 
-//
-//	INL_SetJoyScale() - Sets up scaling values for the specified joystick
-//
-static void
-INL_SetJoyScale(u16int joy)
-{
-	JoystickDef	*def;
 
-	def = &JoyDefs[joy];
-	def->joyMultXL = JoyScaleMax / (def->threshMinX - def->joyMinX);
-	def->joyMultXH = JoyScaleMax / (def->joyMaxX - def->threshMaxX);
-	def->joyMultYL = JoyScaleMax / (def->threshMinY - def->joyMinY);
-	def->joyMultYH = JoyScaleMax / (def->joyMaxY - def->threshMaxY);
-}
-
 ///////////////////////////////////////////////////////////////////////////
 //
-//	IN_SetupJoy() - Sets up thresholding values and calls INL_SetJoyScale()
-//		to set up scaling values
-//
-///////////////////////////////////////////////////////////////////////////
-void
-IN_SetupJoy(u16int joy,u16int minx,u16int maxx,u16int miny,u16int maxy)
-{
-	u16int		d,r;
-	JoystickDef	*def;
-
-	def = &JoyDefs[joy];
-
-	def->joyMinX = minx;
-	def->joyMaxX = maxx;
-	r = maxx - minx;
-	d = r / 3;
-	def->threshMinX = ((r / 2) - d) + minx;
-	def->threshMaxX = ((r / 2) + d) + minx;
-
-	def->joyMinY = miny;
-	def->joyMaxY = maxy;
-	r = maxy - miny;
-	d = r / 3;
-	def->threshMinY = ((r / 2) - d) + miny;
-	def->threshMaxY = ((r / 2) + d) + miny;
-
-	INL_SetJoyScale(joy);
-}
-
-///////////////////////////////////////////////////////////////////////////
-//
-//	INL_StartJoy() - Detects & auto-configures the specified joystick
-//					The auto-config assumes the joystick is centered
-//
-///////////////////////////////////////////////////////////////////////////
-static int
-INL_StartJoy(u16int joy)
-{
-	u16int		x,y;
-
-	IN_GetJoyAbs(joy,&x,&y);
-
-	if
-	(
-		((x == 0) || (x > MaxJoyValue - 10))
-	||	((y == 0) || (y > MaxJoyValue - 10))
-	)
-		return(false);
-	else
-	{
-		IN_SetupJoy(joy,0,x * 2,0,y * 2);
-		return(true);
-	}
-}
-
-///////////////////////////////////////////////////////////////////////////
-//
-//	INL_ShutJoy() - Cleans up the joystick stuff
-//
-///////////////////////////////////////////////////////////////////////////
-static void
-INL_ShutJoy(u16int joy)
-{
-	JoysPresent[joy] = false;
-}
-
-
-///////////////////////////////////////////////////////////////////////////
-//
 //	IN_Startup() - Starts up the Input Mgr
 //
 ///////////////////////////////////////////////////////////////////////////
@@ -583,33 +274,12 @@
 void
 IN_Startup(void)
 {
-	int	checkjoys,checkmouse;
-	u16int	i;
-
 	if (IN_Started)
 		return;
 
-	checkjoys = true;
-	checkmouse = true;
-	for (i = 1;i < _argc;i++)
-	{
-		switch (US_CheckParm(_argv[i],ParmStrings))
-		{
-		case 0:
-			checkjoys = false;
-			break;
-		case 1:
-			checkmouse = false;
-			break;
-		}
-	}
-
 	INL_StartKbd();
-	MousePresent = checkmouse? INL_StartMouse() : false;
+	INL_StartMouse();
 
-	for (i = 0;i < MaxJoys;i++)
-		JoysPresent[i] = checkjoys? INL_StartJoy(i) : false;
-
 	IN_Started = true;
 }
 
@@ -624,8 +294,6 @@
 	if
 	(
 		(!gotit)
-	|| 	((in == ctrl_Joystick1) && !JoysPresent[0])
-	|| 	((in == ctrl_Joystick2) && !JoysPresent[1])
 	|| 	((in == ctrl_Mouse) && !MousePresent)
 	)
 		in = ctrl_Keyboard1;
@@ -646,8 +314,6 @@
 		return;
 
 	INL_ShutMouse();
-	for (i = 0;i < MaxJoys;i++)
-		INL_ShutJoy(i);
 	INL_ShutKbd();
 
 	IN_Started = false;
@@ -752,12 +418,6 @@
 				buttons += 1 << 1;
 			realdelta = false;
 			break;
-		case ctrl_Joystick1:
-		case ctrl_Joystick2:
-			INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy);
-			buttons = INL_GetJoyButtons(type - ctrl_Joystick);
-			realdelta = true;
-			break;
 		case ctrl_Mouse:
 			INL_GetMouseDelta(&dx,&dy);
 			buttons = INL_GetMouseButtons();
@@ -878,7 +538,6 @@
 	IN_ClearKeysDown();
 	memset (btnstate,0,sizeof(btnstate));
 
-	buttons = IN_JoyButtons () << 4;
 	if (MousePresent)
 		buttons |= IN_MouseButtons ();
 
@@ -898,7 +557,6 @@
 	if (LastScan)
 		return true;
 
-	buttons = IN_JoyButtons () << 4;
 	if (MousePresent)
 		buttons |= IN_MouseButtons ();
 
@@ -966,25 +624,3 @@
 	else
 		return 0;
 }
-
-
-/*
-===================
-=
-= IN_JoyButtons
-=
-===================
-*/
-
-u8int	IN_JoyButtons (void)
-{
-	u16int joybits;
-
-	joybits = inportb(0x201);	// Get all the joystick buttons
-	joybits >>= 4;				// only the high bits are useful
-	joybits ^= 15;				// return with 1=pressed
-
-	return joybits;
-}
-
-
--- a/in.h
+++ b/in.h
@@ -7,7 +7,6 @@
 
 #define	MaxPlayers	4
 #define	MaxKbds		2
-#define	MaxJoys		2
 #define	NumCodes	128
 
 #define	sc_None			0
@@ -107,8 +106,6 @@
 typedef	enum		{
 						ctrl_Keyboard,
 							ctrl_Keyboard1 = ctrl_Keyboard,ctrl_Keyboard2,
-						ctrl_Joystick,
-							ctrl_Joystick1 = ctrl_Joystick,ctrl_Joystick2,
 						ctrl_Mouse
 					} ControlType;
 typedef	enum		{
@@ -136,23 +133,12 @@
 									left,				right,
 									downleft,	down,	downright;
 					} KeyboardDef;
-typedef	struct		{
-						u16int		joyMinX,joyMinY,
-									threshMinX,threshMinY,
-									threshMaxX,threshMaxY,
-									joyMaxX,joyMaxY,
-									joyMultXL,joyMultYL,
-									joyMultXH,joyMultYH;
-					} JoystickDef;
 // Global variables
-extern	int		Keyboard[],
-					MousePresent,
-					JoysPresent[];
+extern	int		Keyboard[], MousePresent;
 extern	int		Paused;
 extern	char		LastASCII;
 extern	u8int	LastScan;
 extern	KeyboardDef	KbdDefs;
-extern	JoystickDef	JoyDefs[];
 extern	ControlType	Controls[MaxPlayers];
 
 extern	Demo		DemoMode;
@@ -172,21 +158,15 @@
 					IN_ReadCursor(CursorInfo *),
 					IN_ReadControl(s16int,ControlInfo *),
 					IN_SetControlType(s16int,ControlType),
-					IN_GetJoyAbs(u16int joy,u16int *xp,u16int *yp),
-					IN_SetupJoy(u16int joy,u16int minx,u16int maxx,
-								u16int miny,u16int maxy),
 					IN_StopDemo(void),IN_FreeDemoBuffer(void),
 					IN_Ack(void),IN_AckBack(void);
 extern	int		IN_UserInput(u32int delay);
 extern	char		IN_WaitForASCII(void);
 extern	u8int	IN_WaitForKey(void);
-extern	u16int		IN_GetJoyButtonsDB(u16int joy);
 extern	u8int		*IN_GetScanName(u8int);
 
 
 u8int	IN_MouseButtons (void);
-u8int	IN_JoyButtons (void);
 
-void INL_GetJoyDelta(u16int joy,s16int *dx,s16int *dy);
 void IN_StartAck(void);
 int IN_CheckAck (void);
--- a/inter.c
+++ b/inter.c
@@ -38,9 +38,7 @@
 {
 	CA_CacheScreen (screen);
 	VW_UpdateScreen ();
-	CA_CacheGrChunk (palette);
 	VL_FadeIn(0,255,grsegs[palette],30);
-	UNCACHEGRCHUNK (palette);
 	IN_ClearKeysDown ();
 	IN_Ack ();
 	VW_FadeOut ();
@@ -49,13 +47,11 @@
 
 void EndSpear(void)
 {
-	EndScreen (END1PALETTE, ENDSCREEN11PIC);
+	EndScreen (Eend1, Pend1);
 
-	CA_CacheScreen (ENDSCREEN3PIC);
+	CA_CacheScreen (Pend1+2);
 	VW_UpdateScreen ();
-	CA_CacheGrChunk (END3PALETTE);
-	VL_FadeIn(0,255,grsegs[END3PALETTE],30);
-	UNCACHEGRCHUNK (END3PALETTE);
+	VL_FadeIn(0,255,Eend1+2,30);
 	fontnumber = 0;
 	fontcolor = 0xd0;
 	WindowX = 0;
@@ -81,15 +77,14 @@
 
 	VW_FadeOut ();
 
-	EndScreen (END4PALETTE, ENDSCREEN4PIC);
-	EndScreen (END5PALETTE, ENDSCREEN5PIC);
-	EndScreen (END6PALETTE, ENDSCREEN6PIC);
-	EndScreen (END7PALETTE, ENDSCREEN7PIC);
-	EndScreen (END8PALETTE, ENDSCREEN8PIC);
-	EndScreen (END9PALETTE, ENDSCREEN9PIC);
+	EndScreen (Eend1+3, Pend1+3);
+	EndScreen (Eend1+4, Pend1+4);
+	EndScreen (Eend1+5, Pend1+5);
+	EndScreen (Eend1+6, Pend1+6);
+	EndScreen (Eend1+7, Pend1+7);
+	EndScreen (Eend1+8, Pend1+8);
+	EndScreen (Eend1+1, Pend1+1);
 
-	EndScreen (END2PALETTE, ENDSCREEN12PIC);
-
 	MainMenu[savegame].active = 0;
 }
 #endif
@@ -119,45 +114,33 @@
 
 
 #ifdef SPEAR
-	StartCPMusic (XTHEEND_MUS);
+	StartCPMusic (7);
 
-	CA_CacheGrChunk(BJCOLLAPSE1PIC);
-	CA_CacheGrChunk(BJCOLLAPSE2PIC);
-	CA_CacheGrChunk(BJCOLLAPSE3PIC);
-	CA_CacheGrChunk(BJCOLLAPSE4PIC);
-
 	VWB_Bar(0,0,320,200,VIEWCOLOR);
-	VWB_DrawPic (124,44,BJCOLLAPSE1PIC);
+	VWB_DrawPic (124,44,Pcollapse);
 	VW_UpdateScreen ();
 	VW_FadeIn ();
 	VW_WaitVBL(2*70);
-	VWB_DrawPic (124,44,BJCOLLAPSE2PIC);
+	VWB_DrawPic (124,44,Pcollapse+1);
 	VW_UpdateScreen ();
 	VW_WaitVBL(105);
-	VWB_DrawPic (124,44,BJCOLLAPSE3PIC);
+	VWB_DrawPic (124,44,Pcollapse+2);
 	VW_UpdateScreen ();
 	VW_WaitVBL(105);
-	VWB_DrawPic (124,44,BJCOLLAPSE4PIC);
+	VWB_DrawPic (124,44,Pcollapse+3);
 	VW_UpdateScreen ();
 	VW_WaitVBL(3*70);
 
-	UNCACHEGRCHUNK(BJCOLLAPSE1PIC);
-	UNCACHEGRCHUNK(BJCOLLAPSE2PIC);
-	UNCACHEGRCHUNK(BJCOLLAPSE3PIC);
-	UNCACHEGRCHUNK(BJCOLLAPSE4PIC);
 	VL_FadeOut (0,255,0,17,17,5);
 #endif
 
-	StartCPMusic (URAHERO_MUS);
-	ClearSplitVWB ();
-	CacheLump(LEVELEND_LUMP_START,LEVELEND_LUMP_END);
-	CA_CacheGrChunk(STARTFONT);
-
 #ifndef SPEAR
-	CA_CacheGrChunk(C_TIMECODEPIC);
+	StartCPMusic (24);
+#else
+	StartCPMusic (6);
 #endif
+	ClearSplitVWB ();
 
-
 	VWB_Bar (0,0,320,200-STATUSLINES,127);
 	Write(18,2,STR_YOUWIN);
 
@@ -169,7 +152,7 @@
 	Write(RATIOX+4,RATIOY+2,  STR_RATSECRET);
 	Write(RATIOX,  RATIOY+4,STR_RATTREASURE);
 
-	VWB_DrawPic (8,4,L_BJWINSPIC);
+	VWB_DrawPic (8,4,Pwin);
 
 #ifndef SPEAR
 	for (kr = sr = tr = sec = i = 0;i < 8;i++)
@@ -200,15 +183,15 @@
 		min = sec = 99;
 
 	i = TIMEX*8+1;
-	VWB_DrawPic(i,TIMEY*8,L_NUM0PIC+(min/10));
+	VWB_DrawPic(i,TIMEY*8,P0+(min/10));
 	i += 2*8;
-	VWB_DrawPic(i,TIMEY*8,L_NUM0PIC+(min%10));
+	VWB_DrawPic(i,TIMEY*8,P0+(min%10));
 	i += 2*8;
 	Write(i/8,TIMEY,":");
 	i += 1*8;
-	VWB_DrawPic(i,TIMEY*8,L_NUM0PIC+(sec/10));
+	VWB_DrawPic(i,TIMEY*8,P0+(sec/10));
 	i += 2*8;
-	VWB_DrawPic(i,TIMEY*8,L_NUM0PIC+(sec%10));
+	VWB_DrawPic(i,TIMEY*8,P0+(sec%10));
 	VW_UpdateScreen ();
 
 	itoa(kr,tempstr,10);
@@ -231,7 +214,7 @@
 	//
 	if (gamestate.difficulty>=gd_medium)
 	{
-		VWB_DrawPic (30*8,TIMEY*8,C_TIMECODEPIC);
+		VWB_DrawPic (30*8,TIMEY*8,Ptc);
 		fontnumber = 0;
 		fontcolor = READHCOLOR;
 		PrintX = 30*8-3;
@@ -254,19 +237,9 @@
 
 	IN_Ack();
 
-	#ifndef SPEAR
-	if (Keyboard[sc_P] && MS_CheckParm("goobers"))
-		PicturePause();
-	#endif
-
 	VW_FadeOut ();
 
 #ifndef SPEAR
-	UNCACHEGRCHUNK(C_TIMECODEPIC);
-#endif
-	UnCacheLump(LEVELEND_LUMP_START,LEVELEND_LUMP_END);
-
-#ifndef SPEAR
 	EndText();
 #else
 	EndSpear();
@@ -291,12 +264,9 @@
 	VW_FadeOut();
 	VWB_Bar(0,0,320,200,0x82);			// background
 
-	CA_CacheGrChunk (PG13PIC);
-	VWB_DrawPic (216,110,PG13PIC);
+	VWB_DrawPic (216,110,Ppg13);
 	VW_UpdateScreen ();
 
-	UNCACHEGRCHUNK (PG13PIC);
-
 	VW_FadeIn();
 	IN_UserInput(TickBase*7);
 
@@ -308,11 +278,11 @@
 
 void Write(s16int x,s16int y,char *string)
 {
- s16int alpha[]={L_NUM0PIC,L_NUM1PIC,L_NUM2PIC,L_NUM3PIC,L_NUM4PIC,L_NUM5PIC,
-	L_NUM6PIC,L_NUM7PIC,L_NUM8PIC,L_NUM9PIC,L_COLONPIC,0,0,0,0,0,0,L_APIC,L_BPIC,
-	L_CPIC,L_DPIC,L_EPIC,L_FPIC,L_GPIC,L_HPIC,L_IPIC,L_JPIC,L_KPIC,
-	L_LPIC,L_MPIC,L_NPIC,L_OPIC,L_PPIC,L_QPIC,L_RPIC,L_SPIC,L_TPIC,
-	L_UPIC,L_VPIC,L_WPIC,L_XPIC,L_YPIC,L_ZPIC};
+ s16int alpha[]={P0,P1,P2,P3,P4,P5,
+	P6,P7,P8,P9,Pcolon,0,0,0,0,0,0,Pa,Pb,
+	Pc,Pd,Pe,Pf,Pg,Ph,Pi,Pj,Pk,
+	Pl,Pm,Pn,Po,Pp,Pq,Pr,Ps,Pt,
+	Pu,Pv,Pw,Px,Py,Pz};
 
  s16int i,ox,nx,ny;
  char ch;
@@ -336,12 +306,12 @@
 	switch(string[i])
 	{
 	 case '!':
-	   VWB_DrawPic(nx,ny,L_EXPOINTPIC);
+	   VWB_DrawPic(nx,ny,Pexcl);
 	   nx+=8;
 	   continue;
 
 	 case '\'':
-	   VWB_DrawPic(nx,ny,L_APOSTROPHEPIC);
+	   VWB_DrawPic(nx,ny,Papo);
 	   nx+=8;
 	   continue;
 
@@ -348,12 +318,12 @@
 	 case ' ': break;
 	 case 0x3a:	// ':'
 
-	   VWB_DrawPic(nx,ny,L_COLONPIC);
+	   VWB_DrawPic(nx,ny,Pcolon);
 	   nx+=8;
 	   continue;
 
 	 case '%':
-	   VWB_DrawPic(nx,ny,L_PERCENTPIC);
+	   VWB_DrawPic(nx,ny,Ppercent);
 	   break;
 
 	 default:
@@ -370,7 +340,7 @@
 void BJ_Breathe(void)
 {
 	static s16int which=0,max=10;
-	s16int pics[2]={L_GUYPIC,L_GUY2PIC};
+	s16int pics[2]={Pguy,Pguy2};
 
 
 	if (TimeCount>max)
@@ -531,12 +501,9 @@
 #endif
 	};
 
-
-
-	CacheLump(LEVELEND_LUMP_START,LEVELEND_LUMP_END);
 	ClearSplitVWB ();			// set up for double buffering in split screen
 	VWB_Bar (0,0,320,200-STATUSLINES,127);
-	StartCPMusic(ENDLEVEL_MUS);
+	StartCPMusic(16);
 
 //
 // do the intermission
@@ -544,7 +511,7 @@
 	IN_ClearKeysDown();
 	IN_StartAck();
 
-	VWB_DrawPic(0,16,L_GUYPIC);
+	VWB_DrawPic(0,16,Pguy);
 
 #ifndef SPEAR
 	if (mapon<8)
@@ -584,15 +551,15 @@
 	 sec%=60;
 
 	 i=26*8;
-	 VWB_DrawPic(i,10*8,L_NUM0PIC+(min/10));
+	 VWB_DrawPic(i,10*8,P0+(min/10));
 	 i+=2*8;
-	 VWB_DrawPic(i,10*8,L_NUM0PIC+(min%10));
+	 VWB_DrawPic(i,10*8,P0+(min%10));
 	 i+=2*8;
 	 Write(i/8,10,":");
 	 i+=1*8;
-	 VWB_DrawPic(i,10*8,L_NUM0PIC+(sec/10));
+	 VWB_DrawPic(i,10*8,P0+(sec/10));
 	 i+=2*8;
-	 VWB_DrawPic(i,10*8,L_NUM0PIC+(sec%10));
+	 VWB_DrawPic(i,10*8,P0+(sec%10));
 
 	 VW_UpdateScreen ();
 	 VW_FadeIn ();
@@ -622,7 +589,7 @@
 	   x=36-strlen(tempstr)*2;
 	   Write(x,7,tempstr);
 	   if (!(i%(PAR_AMOUNT/10)))
-		 SD_PlaySound(ENDBONUS1SND);
+		 SD_PlaySound(Sendb1);
 	   VW_UpdateScreen();
 	   while(SD_SoundPlaying())
 		 BJ_Breathe();
@@ -631,7 +598,7 @@
 	  }
 
 	  VW_UpdateScreen();
-	  SD_PlaySound(ENDBONUS2SND);
+	  SD_PlaySound(Sendb2);
 	  while(SD_SoundPlaying())
 		BJ_Breathe();
 	 }
@@ -648,7 +615,7 @@
 	  x=RATIOXX-strlen(tempstr)*2;
 	  Write(x,14,tempstr);
 	  if (!(i%10))
-		SD_PlaySound(ENDBONUS1SND);
+		SD_PlaySound(Sendb1);
 	  VW_UpdateScreen ();
 	  while(SD_SoundPlaying())
 		BJ_Breathe();
@@ -665,7 +632,7 @@
 	   x=(RATIOXX-1)-strlen(tempstr)*2;
 	   Write(x,7,tempstr);
 	   VW_UpdateScreen();
-	   SD_PlaySound(PERCENT100SND);
+	   SD_PlaySound(S100);
 	 }
 	 else
 	 if (!ratio)
@@ -672,10 +639,10 @@
 	 {
 	   VW_WaitVBL(VBLWAIT);
 	   SD_StopSound();
-	   SD_PlaySound(NOBONUSSND);
+	   SD_PlaySound(Snobonus);
 	 }
 	 else
-	 SD_PlaySound(ENDBONUS2SND);
+	 SD_PlaySound(Sendb2);
 
 	 VW_UpdateScreen();
 	 while(SD_SoundPlaying())
@@ -692,7 +659,7 @@
 	  x=RATIOXX-strlen(tempstr)*2;
 	  Write(x,16,tempstr);
 	  if (!(i%10))
-		SD_PlaySound(ENDBONUS1SND);
+		SD_PlaySound(Sendb1);
 	  VW_UpdateScreen ();
 	  while(SD_SoundPlaying())
 		BJ_Breathe();
@@ -710,7 +677,7 @@
 	   x=(RATIOXX-1)-strlen(tempstr)*2;
 	   Write(x,7,tempstr);
 	   VW_UpdateScreen();
-	   SD_PlaySound(PERCENT100SND);
+	   SD_PlaySound(S100);
 	 }
 	 else
 	 if (!ratio)
@@ -717,10 +684,10 @@
 	 {
 	   VW_WaitVBL(VBLWAIT);
 	   SD_StopSound();
-	   SD_PlaySound(NOBONUSSND);
+	   SD_PlaySound(Snobonus);
 	 }
 	 else
-	   SD_PlaySound(ENDBONUS2SND);
+	   SD_PlaySound(Sendb2);
 	 VW_UpdateScreen();
 	 while(SD_SoundPlaying())
 	   BJ_Breathe();
@@ -736,7 +703,7 @@
 	  x=RATIOXX-strlen(tempstr)*2;
 	  Write(x,18,tempstr);
 	  if (!(i%10))
-		SD_PlaySound(ENDBONUS1SND);
+		SD_PlaySound(Sendb1);
 	  VW_UpdateScreen ();
 	  while(SD_SoundPlaying())
 		BJ_Breathe();
@@ -752,7 +719,7 @@
 	   x=(RATIOXX-1)-strlen(tempstr)*2;
 	   Write(x,7,tempstr);
 	   VW_UpdateScreen();
-	   SD_PlaySound(PERCENT100SND);
+	   SD_PlaySound(S100);
 	 }
 	 else
 	 if (!ratio)
@@ -759,10 +726,10 @@
 	 {
 	   VW_WaitVBL(VBLWAIT);
 	   SD_StopSound();
-	   SD_PlaySound(NOBONUSSND);
+	   SD_PlaySound(Snobonus);
 	 }
 	 else
-	 SD_PlaySound(ENDBONUS2SND);
+	 SD_PlaySound(Sendb2);
 	 VW_UpdateScreen();
 	 while(SD_SoundPlaying())
 	   BJ_Breathe();
@@ -855,14 +822,11 @@
 #ifdef SPEARDEMO
 	if (gamestate.mapon == 1)
 	{
-		SD_PlaySound (BONUS1UPSND);
-
-		CA_CacheGrChunk (STARTFONT+1);
+		SD_PlaySound (S1up);
 		Message ("This concludes your demo\n"
 				 "of Spear of Destiny! Now,\n"
 				 "go to your local software\n"
 				 "store and buy it!");
-		UNCACHEGRCHUNK (STARTFONT+1);
 
 		IN_ClearKeysDown();
 		IN_Ack();
@@ -869,11 +833,6 @@
 	}
 #endif
 
-	#ifndef SPEAR
-	if (Keyboard[sc_P] && MS_CheckParm("goobers"))
-		PicturePause();
-	#endif
-
 	VW_FadeOut ();
 	temp = bufferofs;
 	for (i=0;i<3;i++)
@@ -882,8 +841,6 @@
 		DrawPlayBorder ();
 	}
 	bufferofs = temp;
-
-	UnCacheLump(LEVELEND_LUMP_START,LEVELEND_LUMP_END);
 }
 
 
@@ -915,13 +872,7 @@
 
 	}
 	VW_UpdateScreen();
-//	if (LastScan == sc_Escape)
-//	{
-//		IN_ClearKeysDown();
-//		return(true);
-//	}
-//	else
-		return(false);
+	return false;
 }
 
 void PreloadGraphics(void)
@@ -931,7 +882,7 @@
 
 	VWB_Bar (0,0,320,200-STATUSLINES,127);
 
-	LatchDrawPic (20-14,80-3*8,GETPSYCHEDPIC);
+	LatchDrawPic (20-14,80-3*8,Ppsyched);
 
 	WindowX = 160-14*8;
 	WindowY = 80-3*8;
@@ -972,36 +923,22 @@
 	MM_SortMem ();
 
 #ifndef SPEAR
-//	CA_CacheGrChunk (C_CODEPIC);
-	CA_CacheGrChunk (HIGHSCORESPIC);
-	CA_CacheGrChunk (STARTFONT);
-	CA_CacheGrChunk (C_LEVELPIC);
-	CA_CacheGrChunk (C_SCOREPIC);
-	CA_CacheGrChunk (C_NAMEPIC);
-
 	ClearMScreen();
 	DrawStripes(10);
 
-	VWB_DrawPic(48,0,HIGHSCORESPIC);
-	UNCACHEGRCHUNK (HIGHSCORESPIC);
+	VWB_DrawPic(48,0,Pscores);
 
-	VWB_DrawPic(4*8,68,C_NAMEPIC);
-	VWB_DrawPic(20*8,68,C_LEVELPIC);
+	VWB_DrawPic(4*8,68,Pname);
+	VWB_DrawPic(20*8,68,Plvl);
 	VWB_DrawPic(28*8,68,C_SCOREPIC);
-#ifndef UPLOAD
-//	VWB_DrawPic(35*8,68,C_CODEPIC);
-#endif
 	fontnumber=0;
 
 #else
-	CacheLump (BACKDROP_LUMP_START,BACKDROP_LUMP_END);
 	ClearMScreen();
 	DrawStripes(10);
-	UnCacheLump (BACKDROP_LUMP_START,BACKDROP_LUMP_END);
 
-	CacheLump (HIGHSCORES_LUMP_START,HIGHSCORES_LUMP_END);
 	CA_CacheGrChunk (STARTFONT+1);
-	VWB_DrawPic (0,0,HIGHSCORESPIC);
+	VWB_DrawPic (0,0,Pscores);
 
 	fontnumber = 1;
 #endif
@@ -1053,7 +990,7 @@
 
 #ifdef SPEAR
 		if (s->completed == 21)
-			VWB_DrawPic (PrintX+8,PrintY-1,C_WONSPEARPIC);
+			VWB_DrawPic (PrintX+8,PrintY-1,Pspear);
 		else
 #endif
 		US_Print(buffer);
@@ -1108,7 +1045,6 @@
 	VW_UpdateScreen ();
 
 #ifdef SPEAR
-	UnCacheLump (HIGHSCORES_LUMP_START,HIGHSCORES_LUMP_END);
 	fontnumber = 0;
 #endif
 }
@@ -1155,9 +1091,9 @@
 	}
 
 #ifdef SPEAR
-	StartCPMusic (XAWARD_MUS);
+	StartCPMusic (20);
 #else
-	StartCPMusic (ROSTER_MUS);
+	StartCPMusic (23);
 #endif
 	DrawHighScores ();
 
@@ -1191,440 +1127,3 @@
 	}
 
 }
-
-
-#ifndef UPLOAD
-#ifndef SPEAR
-////////////////////////////////////////////////////////
-//
-// NON-SHAREWARE NOTICE
-//
-////////////////////////////////////////////////////////
-void NonShareware(void)
-{
-	VW_FadeOut();
-
-	ClearMScreen();
-	DrawStripes(10);
-
-	CA_CacheGrChunk(STARTFONT+1);
-	fontnumber = 1;
-
-	SETFONTCOLOR(READHCOLOR,BKGDCOLOR);
-	PrintX=110;
-	PrintY=15;
-
-	US_Print("Attention");
-
-	SETFONTCOLOR(HIGHLIGHT,BKGDCOLOR);
-	WindowX=PrintX=40;
-	PrintY=60;
-	US_Print("This game is NOT shareware.\n");
-	US_Print("Please do not distribute it.\n");
-	US_Print("Thanks.\n\n");
-	US_Print("        Id Software\n");
-
-	VW_UpdateScreen ();
-	VW_FadeIn();
-	IN_Ack();
-}
-#endif
-#endif
-
-#ifdef SPEAR
-#ifndef SPEARDEMO
-////////////////////////////////////////////////////////
-//
-// COPY PROTECTION FOR FormGen
-//
-////////////////////////////////////////////////////////
-char 	far CopyProFailedStrs[][100] = {
-			STR_COPY1,
-			STR_COPY2,
-
-			STR_COPY3,
-			STR_COPY4,
-
-			STR_COPY5,
-			STR_COPY6,
-
-			STR_COPY7,
-			STR_COPY8,
-
-			STR_COPY9,
-			"",
-
-			STR_COPY10,
-			STR_COPY11,
-
-			STR_COPY12,
-			"",
-
-			STR_COPY13,
-			"",
-
-			STR_COPY14,
-			""
-			},
-
-		far BackDoorStrs[5][16] = {
-			"a spoon?",
-			"bite me!",
-			"joshua",
-			"pelt",
-			"snoops"
-			},
-
-		far GoodBoyStrs[10][40] = {
-			"...is the CORRECT ANSWER!",
-			"",
-
-			"Consider yourself bitten, sir.",
-			"",
-
-			"Greetings Professor Falken, would you",
-			"like to play Spear of Destiny?",
-
-			"Do you have any gold spray paint?",
-			"",
-
-			"I wish I had a 21\" monitor...",
-			""
-			},
-
-		far bossstrs[4][24] = {
-			"DEATH KNIGHT",
-			"BARNACLE WILHELM",
-			"UBERMUTANTUBER MUTANT",
-			"TRANS GROSSE"
-			},
-
-		far WordStr[5][20] = {
-			"New Game",
-			"Sound...F4",
-			"Control...F6",
-			"Change View...F5",
-			"Quit...F10"},
-
-		far	WordCorrect[5][2] = {"3","4","4","5","5"},
-
-		far MemberStr[10][40] = {
-			STR_COPY15,
-			"",
-
-			STR_COPY16,
-			"",
-
-			STR_COPY17,
-			STR_COPY18,
-
-			STR_COPY19,
-			STR_COPY20,
-
-			STR_COPY21,
-			STR_COPY22},
-
-		far MemberCorrect[5][24] = {
-			"adrian carmack",
-			"john carmackjohn romero",
-			"tom hall",
-			"jay wilbur",
-			"kevin cloud"},
-
-		far DosMessages[9][80] = {
-			STR_NOPE1,
-			STR_NOPE2,
-			STR_NOPE3,
-			STR_NOPE4,
-			STR_NOPE5,
-			STR_NOPE6,
-			STR_NOPE7,
-			STR_NOPE8,
-			STR_NOPE9},
-
-		far MiscTitle[4][20] = {
-			"BLOOD TEST",
-			"STRAIGHT-LACED",
-			"QUITE SHAPELY",
-			"I AM WHAT I AMMO"
-			},
-
-		far MiscStr[12][40] = {
-			STR_MISC1,
-			STR_MISC2,
-			"",
-
-			STR_MISC3,
-			STR_MISC4,
-			"",
-
-			STR_MISC5,
-			STR_MISC6,
-			"",
-
-			STR_MISC7,
-			STR_MISC8,
-			STR_MISC9
-			},
-
-		far MiscCorrect[4][5] = {"ss","8",STR_STAR,"45"};
-
-
-s16int  BackDoor(char *s)
-{
-	s16int i;
-
-
-	strlwr(s);
-
-	for (i=0;i<5;i++)
-		if (!_fstrcmp(s,BackDoorStrs[i]))
-		{
-			SETFONTCOLOR(14,15);
-			fontnumber = 0;
-			PrintY = 175;
-			VWB_DrawPic (0,20*8,COPYPROTBOXPIC);
-			US_CPrint(GoodBoyStrs[i*2]);
-			US_CPrint(GoodBoyStrs[i*2+1]);
-			VW_UpdateScreen();
-			return 1;
-		}
-
-	return 0;
-}
-
-
-void CopyProtection(void)
-{
-#define TYPEBOX_Y		177
-#define TYPEBOX_BKGD	0x9c
-#define PRINTCOLOR		HIGHLIGHT
-
-	s16int	i,match,whichboss,bossnum,try,whichline,enemypicked[4]={0,0,0,0},
-		bosses[4] = { BOSSPIC1PIC,BOSSPIC2PIC,BOSSPIC3PIC,BOSSPIC4PIC },
-		whichone,whichpicked[4]={0,0,0,0},quiztype,whichmem,
-		memberpicked[5]={0,0,0,0,0},wordpicked[5]={0,0,0,0,0},whichword;
-
-	char	inputbuffer[20],
-			message[80];
-
-	enum
-	{
-		debriefing,
-		checkmanual,
-		staffquiz,
-		miscquiz,
-
-		totaltypes
-	};
-
-
-
-	try = 0;
-	VW_FadeOut();
-	CA_CacheGrChunk(C_BACKDROPPIC);
-	CacheLump(COPYPROT_LUMP_START,COPYPROT_LUMP_END);
-	CA_CacheGrChunk(STARTFONT+1);
-	CA_LoadAllSounds();
-	StartCPMusic(COPYPRO_MUS);
-	US_InitRndT(true);
-
-	while (try<3)
-	{
-		fontnumber = 1;
-		SETFONTCOLOR(PRINTCOLOR-2,15);
-		VWB_DrawPic (0,0,C_BACKDROPPIC);
-		VWB_DrawPic (0,0,COPYPROTTOPPIC);
-		VWB_DrawPic (0,20*8,COPYPROTBOXPIC);
-		WindowX = WindowY = 0;
-		WindowW = 320;
-		WindowH = 200;
-		PrintY = 65;
-
-		quiztype = US_RndT()%totaltypes;
-		switch(quiztype)
-		{
-			//
-			// BOSSES QUIZ
-			//
-			case debriefing:
-				PrintX = 0;
-				US_Print(STR_DEBRIEF);
-				SETFONTCOLOR(PRINTCOLOR,15);
-
-				while (enemypicked[whichboss = US_RndT()&3]);
-				enemypicked[whichboss] = 1;
-				bossnum = bosses[whichboss];
-				VWB_DrawPic(128,60,bossnum);
-				fontnumber = 0;
-				PrintY = 130;
-				US_CPrint(STR_ENEMY1"\n");
-				US_CPrint(STR_ENEMY2"\n\n");
-
-				VW_UpdateScreen();
-				VW_FadeIn();
-
-				PrintX = 100;
-				fontcolor = 15;
-				backcolor = TYPEBOX_BKGD;
-				inputbuffer[0] = 0;
-				PrintY = TYPEBOX_Y;
-				fontnumber = 1;
-				US_LineInput(PrintX,PrintY,inputbuffer,nil,true,20,100);
-
-				match = 0;
-				for (i=0;i<_fstrlen(bossstrs[whichboss]);i++)
-					if (!_fstrnicmp(inputbuffer,bossstrs[whichboss]+i,strlen(inputbuffer)) &&
-						strlen(inputbuffer)>3)
-						match = 1;
-
-				match += BackDoor(inputbuffer);
-				break;
-
-			//
-			// MANUAL CHECK
-			//
-			case checkmanual:
-				while (wordpicked[whichword = US_RndT()%5]);
-				wordpicked[whichword] = 1;
-				US_CPrint(STR_CHECKMAN);
-				SETFONTCOLOR(PRINTCOLOR,15);
-				PrintY += 25;
-				US_CPrint(STR_MAN1);
-				US_CPrint(STR_MAN2);
-				_fstrcpy(message,STR_MAN3" \"");
-				_fstrcat(message,WordStr[whichword]);
-				_fstrcat(message,"\" "STR_MAN4);
-				US_CPrint(message);
-				VW_UpdateScreen();
-				VW_FadeIn();
-
-				PrintX = 146;
-				fontcolor = 15;
-				backcolor = TYPEBOX_BKGD;
-				inputbuffer[0] = 0;
-				PrintY = TYPEBOX_Y;
-				US_LineInput(PrintX,PrintY,inputbuffer,nil,true,6,100);
-
-				strlwr(inputbuffer);
-				match = 1-(_fstrcmp(inputbuffer,WordCorrect[whichword])!=0);
-				match += BackDoor(inputbuffer);
-				break;
-
-			//
-			// STAFF QUIZ
-			//
-			case staffquiz:
-				while (memberpicked[whichmem = US_RndT()%5]);
-				memberpicked[whichmem] = 1;
-				US_CPrint(STR_ID1);
-				SETFONTCOLOR(PRINTCOLOR,15);
-				PrintY += 25;
-				US_CPrint(MemberStr[whichmem*2]);
-				US_CPrint(MemberStr[whichmem*2+1]);
-				VW_UpdateScreen();
-				VW_FadeIn();
-
-				PrintX = 100;
-				fontcolor = 15;
-				backcolor = TYPEBOX_BKGD;
-				inputbuffer[0] = 0;
-				PrintY = TYPEBOX_Y;
-				US_LineInput(PrintX,PrintY,inputbuffer,nil,true,20,120);
-
-				strlwr(inputbuffer);
-				match = 0;
-				for (i=0;i<_fstrlen(MemberCorrect[whichmem]);i++)
-					if (!_fstrnicmp(inputbuffer,MemberCorrect[whichmem]+i,strlen(inputbuffer)) &&
-						strlen(inputbuffer)>2)
-							match = 1;
-				match += BackDoor(inputbuffer);
-				break;
-
-			//
-			// MISCELLANEOUS QUESTIONS
-			//
-			case miscquiz:
-				while (whichpicked[whichone = US_RndT()&3]);
-				whichpicked[whichone] = 1;
-				US_CPrint(MiscTitle[whichone]);
-				SETFONTCOLOR(PRINTCOLOR,15);
-				PrintY += 25;
-				US_CPrint(MiscStr[whichone*3]);
-				US_CPrint(MiscStr[whichone*3+1]);
-				US_CPrint(MiscStr[whichone*3+2]);
-				VW_UpdateScreen();
-				VW_FadeIn();
-
-				PrintX = 146;
-				fontcolor = 15;
-				backcolor = TYPEBOX_BKGD;
-				inputbuffer[0] = 0;
-				PrintY = TYPEBOX_Y;
-				US_LineInput(PrintX,PrintY,inputbuffer,nil,true,6,100);
-
-				strlwr(inputbuffer);
-				match = 1-(_fstrcmp(inputbuffer,MiscCorrect[whichone])!=0);
-				match += BackDoor(inputbuffer);
-				break;
-			}
-
-		//
-		// IF NO MATCH, WE'VE GOT A (MINOR) PROBLEM!
-		//
-
-		if (!match)
-		{
-			whichline = 2*(US_RndT()%9);
-			SETFONTCOLOR(14,15);
-			fontnumber = 0;
-			PrintY = 175;
-			VWB_DrawPic (0,20*8,COPYPROTBOXPIC);
-			US_CPrint(CopyProFailedStrs[whichline]);
-			US_CPrint(CopyProFailedStrs[whichline+1]);
-
-			VW_UpdateScreen();
-			SD_PlaySound(NOWAYSND);
-			IN_UserInput(TickBase*3);
-			VW_FadeOut();
-			try++;
-		}
-		else
-		{
-			s16int start;
-
-
-			SD_PlaySound(BONUS1UPSND);
-			SD_WaitSoundDone();
-			UNCACHEGRCHUNK (STARTFONT+1);
-			UNCACHEGRCHUNK (C_BACKDROPPIC);
-			UnCacheLump (COPYPROT_LUMP_START,COPYPROT_LUMP_END);
-
-			switch(SoundMode)
-			{
-				case sdm_Off: return;
-				case sdm_PC: start = STARTPCSOUNDS; break;
-				case sdm_AdLib: start = STARTADLIBSOUNDS;
-			}
-
-			for (i=0;i<NUMSOUNDS;i++,start++)
-				MM_FreePtr ((uchar **)&audiosegs[start]);
-			return;
-		}
-	}
-
-	ClearMemory();
-	ShutdownId();
-
-	_fstrcpy(message,DosMessages[US_RndT()%9]);
-
-	_AX = 3;
-	geninterrupt(0x10);
-
-	printf("%s\n",message);
-	exit(1);
-}
-
-#endif // SPEARDEMO
-#endif // SPEAR
-//===========================================================================
--- a/main.c
+++ b/main.c
@@ -29,9 +29,6 @@
 #define FOCALLENGTH     (0x5700l)               // in global coordinates
 #define VIEWGLOBAL      0x10000                 // globals visable flush to wall
 
-#define VIEWWIDTH       256                     // size of view window
-#define VIEWHEIGHT      144
-
 /*
 =============================================================================
 
@@ -43,8 +40,6 @@
 char            str[80],str2[20];
 s16int				tedlevelnum;
 int         tedlevel;
-int         nospr;
-int         IsA386;
 s16int                     dirangle[9] = {0,ANGLES/8,2*ANGLES/8,3*ANGLES/8,4*ANGLES/8,
 	5*ANGLES/8,6*ANGLES/8,7*ANGLES/8,ANGLES};
 
@@ -64,7 +59,7 @@
 
 void            Quit (char *error);
 
-int         startgame,loadedgame,virtualreality;
+int         startgame,loadedgame;
 s16int             mouseadjustment;
 
 char	configname[13]="CONFIG.";
@@ -134,8 +129,6 @@
 
 		if (!MousePresent)
 			mouseenabled = false;
-		if (!JoysPresent[joystickport])
-			joystickenabled = false;
 
 		MainMenu[6].active=1;
 		MainItems.curpos=0;
@@ -166,11 +159,6 @@
 		if (MousePresent)
 			mouseenabled = true;
 
-		joystickenabled = false;
-		joypadenabled = false;
-		joystickport = 0;
-		joystickprogressive = false;
-
 		viewsize = 15;
 		mouseadjustment=5;
 	}
@@ -223,47 +211,7 @@
 	}
 }
 
-
-//===========================================================================
-
-
 /*
-========================
-=
-= Patch386
-=
-= Patch ldiv to use 32 bit instructions
-=
-========================
-*/
-
-char    *JHParmStrings[] = {"no386",nil};
-void Patch386 (void)
-{
-extern void far jabhack2(void);
-extern s16int far  CheckIs386(void);
-
-	s16int     i;
-
-	for (i = 1;i < _argc;i++)
-		if (US_CheckParm(_argv[i],JHParmStrings) == 0)
-		{
-			IsA386 = false;
-			return;
-		}
-
-	if (CheckIs386())
-	{
-		IsA386 = true;
-		jabhack2();
-	}
-	else
-		IsA386 = false;
-}
-
-//===========================================================================
-
-/*
 =====================
 =
 = NewGame
@@ -295,7 +243,7 @@
  static char which=0;
  if (!x && !y)
    return;
- VWB_DrawPic(x,y,C_DISKLOADING1PIC+which);
+ VWB_DrawPic(x,y,Pread1+which);
  VW_UpdateScreen();
  which^=1;
 }
@@ -558,11 +506,7 @@
 {
 	US_Shutdown ();
 	SD_Shutdown ();
-	PM_Shutdown ();
 	IN_Shutdown ();
-	VW_Shutdown ();
-	CA_Shutdown ();
-	MM_Shutdown ();
 }
 
 
@@ -732,13 +676,10 @@
 	VL_TestPaletteSet ();
 	VL_SetPalette (&gamepal);
 
-	if (!virtualreality)
-	{
-		VW_SetScreen(0x8000,0);
-		VL_MungePic (&introscn,320,200);
-		VL_MemToScreen (&introscn,320,200,0,0);
-		VW_SetScreen(0,0);
-	}
+	VW_SetScreen(0x8000,0);
+	VL_MungePic (&introscn,320,200);
+	VL_MemToScreen (&introscn,320,200,0,0);
+	VW_SetScreen(0,0);
 
 //
 // reclaim the memory from the linked in signon screen
@@ -790,333 +731,7 @@
 #endif
 }
 
-//===========================================================================
-
 /*
-=================
-=
-= MS_CheckParm
-=
-=================
-*/
-
-int MS_CheckParm (char far *check)
-{
-	s16int             i;
-	char    *parm;
-
-	for (i = 1;i<_argc;i++)
-	{
-		parm = _argv[i];
-
-		while ( !isalpha(*parm) )       // skip - / \ etc.. in front of parm
-			if (!*parm++)
-				break;                          // hit end of string without an alphanum
-
-		if ( !_fstricmp(check,parm) )
-			return true;
-	}
-
-	return false;
-}
-
-//===========================================================================
-
-/*
-=====================
-=
-= InitDigiMap
-=
-=====================
-*/
-
-static  s16int     wolfdigimap[] =
-		{
-			// These first sounds are in the upload version
-#ifndef SPEAR
-			HALTSND,                0,
-			DOGBARKSND,             1,
-			CLOSEDOORSND,           2,
-			OPENDOORSND,            3,
-			ATKMACHINEGUNSND,       4,
-			ATKPISTOLSND,           5,
-			ATKGATLINGSND,          6,
-			SCHUTZADSND,            7,
-			GUTENTAGSND,            8,
-			MUTTISND,               9,
-			BOSSFIRESND,            10,
-			SSFIRESND,              11,
-			DEATHSCREAM1SND,        12,
-			DEATHSCREAM2SND,        13,
-			DEATHSCREAM3SND,        13,
-			TAKEDAMAGESND,          14,
-			PUSHWALLSND,            15,
-
-			LEBENSND,               20,
-			NAZIFIRESND,            21,
-			SLURPIESND,             22,
-
-			YEAHSND,				32,
-
-#ifndef UPLOAD
-			// These are in all other episodes
-			DOGDEATHSND,            16,
-			AHHHGSND,               17,
-			DIESND,                 18,
-			EVASND,                 19,
-
-			TOT_HUNDSND,            23,
-			MEINGOTTSND,            24,
-			SCHABBSHASND,           25,
-			HITLERHASND,            26,
-			SPIONSND,               27,
-			NEINSOVASSND,           28,
-			DOGATTACKSND,           29,
-			LEVELDONESND,           30,
-			MECHSTEPSND,			31,
-
-			SCHEISTSND,				33,
-			DEATHSCREAM4SND,		34,		// AIIEEE
-			DEATHSCREAM5SND,		35,		// DEE-DEE
-			DONNERSND,				36,		// EPISODE 4 BOSS DIE
-			EINESND,				37,		// EPISODE 4 BOSS SIGHTING
-			ERLAUBENSND,			38,		// EPISODE 6 BOSS SIGHTING
-			DEATHSCREAM6SND,		39,		// FART
-			DEATHSCREAM7SND,		40,		// GASP
-			DEATHSCREAM8SND,		41,		// GUH-BOY!
-			DEATHSCREAM9SND,		42,		// AH GEEZ!
-			KEINSND,				43,		// EPISODE 5 BOSS SIGHTING
-			MEINSND,				44,		// EPISODE 6 BOSS DIE
-			ROSESND,				45,		// EPISODE 5 BOSS DIE
-
-#endif
-#else
-//
-// SPEAR OF DESTINY DIGISOUNDS
-//
-			HALTSND,                0,
-			CLOSEDOORSND,           2,
-			OPENDOORSND,            3,
-			ATKMACHINEGUNSND,       4,
-			ATKPISTOLSND,           5,
-			ATKGATLINGSND,          6,
-			SCHUTZADSND,            7,
-			BOSSFIRESND,            8,
-			SSFIRESND,              9,
-			DEATHSCREAM1SND,        10,
-			DEATHSCREAM2SND,        11,
-			TAKEDAMAGESND,          12,
-			PUSHWALLSND,            13,
-			AHHHGSND,               15,
-			LEBENSND,               16,
-			NAZIFIRESND,            17,
-			SLURPIESND,             18,
-			LEVELDONESND,           22,
-			DEATHSCREAM4SND,		23,		// AIIEEE
-			DEATHSCREAM3SND,        23,		// DOUBLY-MAPPED!!!
-			DEATHSCREAM5SND,		24,		// DEE-DEE
-			DEATHSCREAM6SND,		25,		// FART
-			DEATHSCREAM7SND,		26,		// GASP
-			DEATHSCREAM8SND,		27,		// GUH-BOY!
-			DEATHSCREAM9SND,		28,		// AH GEEZ!
-			GETGATLINGSND,			38,		// Got Gat replacement
-
-#ifndef SPEARDEMO
-			DOGBARKSND,             1,
-			DOGDEATHSND,            14,
-			SPIONSND,               19,
-			NEINSOVASSND,           20,
-			DOGATTACKSND,           21,
-			TRANSSIGHTSND,			29,		// Trans Sight
-			TRANSDEATHSND,			30,		// Trans Death
-			WILHELMSIGHTSND,		31,		// Wilhelm Sight
-			WILHELMDEATHSND,		32,		// Wilhelm Death
-			UBERDEATHSND,			33,		// Uber Death
-			KNIGHTSIGHTSND,			34,		// Death Knight Sight
-			KNIGHTDEATHSND,			35,		// Death Knight Death
-			ANGELSIGHTSND,			36,		// Angel Sight
-			ANGELDEATHSND,			37,		// Angel Death
-			GETSPEARSND,			39,		// Got Spear replacement
-#endif
-#endif
-			LASTSOUND
-		};
-
-
-void InitDigiMap (void)
-{
-	s16int                     *map;
-
-	for (map = wolfdigimap;*map != LASTSOUND;map += 2)
-		DigiMap[map[0]] = map[1];
-
-
-}
-
-
-#ifndef SPEAR
-CP_iteminfo	MusicItems={CTL_X,CTL_Y,6,0,32};
-CP_itemtype far MusicMenu[]=
-	{
-		{1,"Get Them!",0},
-		{1,"Searching",0},
-		{1,"P.O.W.",0},
-		{1,"Suspense",0},
-		{1,"War March",0},
-		{1,"Around The Corner!",0},
-
-		{1,"Nazi Anthem",0},
-		{1,"Lurking...",0},
-		{1,"Going After Hitler",0},
-		{1,"Pounding Headache",0},
-		{1,"Into the Dungeons",0},
-		{1,"Ultimate Conquest",0},
-
-		{1,"Kill the S.O.B.",0},
-		{1,"The Nazi Rap",0},
-		{1,"Twelfth Hour",0},
-		{1,"Zero Hour",0},
-		{1,"Ultimate Conquest",0},
-		{1,"Wolfpack",0}
-	};
-#else
-CP_iteminfo MusicItems={CTL_X,CTL_Y-20,9,0,32};
-CP_itemtype far MusicMenu[]=
-   {
-		{1,"Funky Colonel Bill",0},
-		{1,"Death To The Nazis",0},
-		{1,"Tiptoeing Around",0},
-		{1,"Is This THE END?",0},
-		{1,"Evil Incarnate",0},
-		{1,"Jazzin' Them Nazis",0},
-		{1,"Puttin' It To The Enemy",0},
-		{1,"The SS Gonna Get You",0},
-		{1,"Towering Above",0}
-	};
-#endif
-
-#ifndef SPEARDEMO
-void DoJukebox(void)
-{
-	s16int which,lastsong=-1;
-	u16int start,songs[]=
-		{
-#ifndef SPEAR
-			GETTHEM_MUS,
-			SEARCHN_MUS,
-			POW_MUS,
-			SUSPENSE_MUS,
-			WARMARCH_MUS,
-			CORNER_MUS,
-
-			NAZI_OMI_MUS,
-			PREGNANT_MUS,
-			GOINGAFT_MUS,
-			HEADACHE_MUS,
-			DUNGEON_MUS,
-			ULTIMATE_MUS,
-
-			INTROCW3_MUS,
-			NAZI_RAP_MUS,
-			TWELFTH_MUS,
-			ZEROHOUR_MUS,
-			ULTIMATE_MUS,
-			PACMAN_MUS
-#else
-			XFUNKIE_MUS,             // 0
-			XDEATH_MUS,              // 2
-			XTIPTOE_MUS,             // 4
-			XTHEEND_MUS,             // 7
-			XEVIL_MUS,               // 17
-			XJAZNAZI_MUS,            // 18
-			XPUTIT_MUS,              // 21
-			XGETYOU_MUS,             // 22
-			XTOWER2_MUS              // 23
-#endif
-		};
-	struct dostime_t time;
-
-
-
-	IN_ClearKeysDown();
-	if (!AdLibPresent && !SoundBlasterPresent)
-		return;
-
-
-	MenuFadeOut();
-
-#ifndef SPEAR
-#ifndef UPLOAD
-	_dos_gettime(&time);
-	start = (time.hsecond%3)*6;
-#else
-	start = 0;
-#endif
-#else
-	start = 0;
-#endif
-
-
-	CA_CacheGrChunk (STARTFONT+1);
-#ifdef SPEAR
-	CacheLump (BACKDROP_LUMP_START,BACKDROP_LUMP_END);
-#else
-	CacheLump (CONTROLS_LUMP_START,CONTROLS_LUMP_END);
-#endif
-	CA_LoadAllSounds ();
-
-	fontnumber=1;
-	ClearMScreen ();
-	VWB_DrawPic(112,184,C_MOUSELBACKPIC);
-	DrawStripes (10);
-	SETFONTCOLOR (TEXTCOLOR,BKGDCOLOR);
-
-#ifndef SPEAR
-	DrawWindow (CTL_X-2,CTL_Y-6,280,13*7,BKGDCOLOR);
-#else
-	DrawWindow (CTL_X-2,CTL_Y-26,280,13*10,BKGDCOLOR);
-#endif
-
-	DrawMenu (&MusicItems,&MusicMenu[start]);
-
-	SETFONTCOLOR (READHCOLOR,BKGDCOLOR);
-	PrintY=15;
-	WindowX = 0;
-	WindowY = 320;
-	US_CPrint ("Robert's Jukebox");
-
-	SETFONTCOLOR (TEXTCOLOR,BKGDCOLOR);
-	VW_UpdateScreen();
-	MenuFadeIn();
-
-	do
-	{
-		which = HandleMenu(&MusicItems,&MusicMenu[start],NULL);
-		if (which>=0)
-		{
-			if (lastsong >= 0)
-				MusicMenu[start+lastsong].active = 1;
-
-			StartCPMusic(songs[start + which]);
-			MusicMenu[start+which].active = 2;
-			DrawMenu (&MusicItems,&MusicMenu[start]);
-			VW_UpdateScreen();
-			lastsong = which;
-		}
-	} while(which>=0);
-
-	MenuFadeOut();
-	IN_ClearKeysDown();
-#ifdef SPEAR
-	UnCacheLump (BACKDROP_LUMP_START,BACKDROP_LUMP_END);
-#else
-	UnCacheLump (CONTROLS_LUMP_START,CONTROLS_LUMP_END);
-#endif
-}
-#endif
-
-
-/*
 ==========================
 =
 = InitGame
@@ -1131,45 +746,16 @@
 	s16int                     i,x,y;
 	u16int        *blockstart;
 
-	if (MS_CheckParm ("virtual"))
-		virtualreality = true;
-	else
-		virtualreality = false;
-
-	MM_Startup ();                  // so the signon screen can be freed
-
 	SignonScreen ();
 
-	VW_Startup ();
 	IN_Startup ();
-	PM_Startup ();
-	PM_UnlockMainMem ();
 	SD_Startup ();
 	CA_Startup ();
 	US_Startup ();
 
-
-#ifndef SPEAR
-	if (mminfo.mainmem < 235000L)
-#else
-	if (mminfo.mainmem < 257000L && !MS_CheckParm("debugmode"))
-#endif
-	{
-		uchar *screen;
-
-		CA_CacheGrChunk (ERRORSCREEN);
-		screen = grsegs[ERRORSCREEN];
-		ShutdownId();
-		movedata ((u16int)screen,7+7*160,0xb800,0,17*160);
-		gotoxy (1,23);
-		exit(1);
-	}
-
-
 //
 // build some tables
 //
-	InitDigiMap ();
 
 	for (i=0;i<MAPSIZE;i++)
 	{
@@ -1191,22 +777,9 @@
 	displayofs = 0;
 	ReadConfig ();
 
+	IntroScreen ();
 
 //
-// HOLDING DOWN 'M' KEY?
-//
-#ifndef SPEARDEMO
-	if (Keyboard[sc_M])
-	  DoJukebox();
-	else
-#endif
-//
-// draw intro screen stuff
-//
-	if (!virtualreality)
-		IntroScreen ();
-
-//
 // load in and lock down some basic chunks
 //
 
@@ -1217,18 +790,6 @@
 	BuildTables ();          // trig tables
 	SetupWalls ();
 
-#if 0
-{
-s16int temp,i;
-temp = viewsize;
-	profilehandle = open("SCALERS.TXT", O_CREAT | O_WRONLY | O_TEXT);
-for (i=1;i<20;i++)
-	NewViewSize(i);
-viewsize = temp;
-close(profilehandle);
-}
-#endif
-
 	NewViewSize (viewsize);
 
 
@@ -1236,17 +797,10 @@
 // initialize variables
 //
 	InitRedShifts ();
-	if (!virtualreality)
-		FinishSignon();
+	FinishSignon();
 
 	displayofs = PAGE1START;
 	bufferofs = PAGE2START;
-
-	if (virtualreality)
-	{
-		NoWait = true;
-		geninterrupt(0x60);
-	}
 }
 
 //===========================================================================
@@ -1332,20 +886,15 @@
 	u16int        finscreen;
 	uchar *screen;
 
-	if (virtualreality)
-		geninterrupt(0x61);
-
 	ClearMemory ();
 	if (!*error)
 	{
-	 CA_CacheGrChunk (ORDERSCREEN);
-	 screen = grsegs[ORDERSCREEN];
+	 screen = Eorder;
 	 WriteConfig ();
 	}
 	else
 	{
-	 CA_CacheGrChunk (ERRORSCREEN);
-	 screen = grsegs[ERRORSCREEN];
+	 screen = Eerror;
 	}
 
 	ShutdownId ();
@@ -1386,8 +935,6 @@
 =====================
 */
 
-static  char *ParmStrings[] = {"baby","easy","normal","hard",""};
-
 void    DemoLoop (void)
 {
 	static s16int LastDemo;
@@ -1398,19 +945,14 @@
 //
 // check for launch from ted
 //
+	/* → if warping to map [tedlevel] */
 	if (tedlevel)
 	{
 		NoWait = true;
 		NewGame(1,0);
 
-		for (i = 1;i < _argc;i++)
-		{
-			if ( (level = US_CheckParm(_argv[i],ParmStrings)) != -1)
-			{
-			 gamestate.difficulty=level;
-			 break;
-			}
-		}
+		/* → set difficulty level 1-4 if parameter passed as
+		 * gamestate.difficulty */
 
 #ifndef SPEAR
 		gamestate.episode = tedlevelnum/10;
@@ -1447,21 +989,12 @@
 			MM_SortMem ();
 
 #ifdef SPEAR
-			CA_CacheGrChunk (TITLEPALETTE);
-
-			CA_CacheGrChunk (TITLE1PIC);
-			VWB_DrawPic (0,0,TITLE1PIC);
-			UNCACHEGRCHUNK (TITLE1PIC);
-
-			CA_CacheGrChunk (TITLE2PIC);
-			VWB_DrawPic (0,80,TITLE2PIC);
-			UNCACHEGRCHUNK (TITLE2PIC);
+			VWB_DrawPic (0,0,Ptitle1);
+			VWB_DrawPic (0,80,Ptitle2);
 			VW_UpdateScreen ();
-			VL_FadeIn(0,255,grsegs[TITLEPALETTE],30);
-
-			UNCACHEGRCHUNK (TITLEPALETTE);
+			VL_FadeIn(0,255,Etitpal,30);
 #else
-			CA_CacheScreen (TITLEPIC);
+			CA_CacheScreen (Ptitle1);
 			VW_UpdateScreen ();
 			VW_FadeIn();
 #endif
@@ -1471,7 +1004,7 @@
 //
 // credits page
 //
-			CA_CacheScreen (CREDITSPIC);
+			CA_CacheScreen (Pcreds);
 			VW_UpdateScreen();
 			VW_FadeIn ();
 			if (IN_UserInput(TickBase*10))
@@ -1503,11 +1036,7 @@
 
 		VW_FadeOut ();
 
-#ifndef SPEAR
-		if (Keyboard[sc_Tab] && MS_CheckParm("goobers"))
-#else
-		if (Keyboard[sc_Tab] && MS_CheckParm("debugmode"))
-#endif
+		if (Keyboard[sc_Tab] && debug)
 			RecordDemo ();
 		else
 			US_ControlPanel (0);
@@ -1533,15 +1062,21 @@
 ==========================
 */
 
-char    *nosprtxt[] = {"nospr",nil};
-
 void main (void)
 {
-	s16int     i;
-
-	CheckForEpisodes();
-
-	Patch386 ();
+	if (wl6)
+	{
+		NewEmenu[2].active =
+		NewEmenu[4].active =
+		NewEmenu[6].active =
+		NewEmenu[8].active =
+		NewEmenu[10].active =
+		EpisodeSelect[1] =
+		EpisodeSelect[2] =
+		EpisodeSelect[3] =
+		EpisodeSelect[4] =
+		EpisodeSelect[5] = 1;
+	}
 
 	InitGame ();
 
--- /dev/null
+++ b/map.c
@@ -1,0 +1,6 @@
+#include <u.h>
+#include <libc.h>
+#include "dat.h"
+#include "fns.h"
+
+Dat *maps, *mape, *map;
--- a/mapssdm.h
+++ /dev/null
@@ -1,14 +1,0 @@
-///////////////////////////////////////
-//
-// TED5 Map Header for SDM
-//
-///////////////////////////////////////
-
-//
-// Map Names
-//
-typedef enum {
-		TUNNELS_1_MAP,           // 0
-		TUNNELS_2_MAP,           // 1
-		LASTMAP
-	     } mapnames;
--- a/mapssod.h
+++ /dev/null
@@ -1,33 +1,0 @@
-///////////////////////////////////////
-//
-// TED5 Map Header for SOD
-//
-///////////////////////////////////////
-
-//
-// Map Names
-//
-typedef enum {
-		TUNNELS_1_MAP,           // 0
-		TUNNELS_2_MAP,           // 1
-		TUNNELS_3_MAP,           // 2
-		TUNNELS_4_MAP,           // 3
-		TUNNEL_BOSS_MAP,         // 4
-		DUNGEONS_1_MAP,          // 5
-		DUNGEONS_2_MAP,          // 6
-		DUNGEONS_3_MAP,          // 7
-		DUNGEONS_4_MAP,          // 8
-		DUNGEON_BOSS_MAP,        // 9
-		CASTLE_1_MAP,            // 10
-		CASTLE_2_MAP,            // 11
-		CASTLE_3_MAP,            // 12
-		CASTLE_4_MAP,            // 13
-		CASTLE_5_MAP,            // 14
-		CASTLE_BOSS_MAP,         // 15
-		RAMPARTS_MAP,            // 16
-		DEATH_KNIGHT_MAP,        // 17
-		SECRET_1_MAP,            // 18
-		SECRET_2_MAP,            // 19
-		ANGEL_OF_DEATH_MAP,      // 20
-		LASTMAP
-	     } mapnames;
--- a/mapswl1.h
+++ /dev/null
@@ -1,42 +1,0 @@
-///////////////////////////////////////
-//
-// TED5 Map Header for WL1
-//
-///////////////////////////////////////
-
-//
-// Map Names
-//
-typedef enum {
-		WOLF1_MAP1_MAP,          // 0
-		WOLF1_MAP2_MAP,          // 1
-		WOLF1_MAP3_MAP,          // 2
-		WOLF1_MAP4_MAP,          // 3
-		WOLF1_MAP5_MAP,          // 4
-		WOLF1_MAP6_MAP,          // 5
-		WOLF1_MAP7_MAP,          // 6
-		WOLF1_MAP8_MAP,          // 7
-		WOLF1_BOSS_MAP,          // 8
-		WOLF1_SECRET_MAP,        // 9
-		WOLF2_MAP1_MAP,          // 10
-		WOLF2_MAP2_MAP,          // 11
-		WOLF2_MAP3_MAP,          // 12
-		WOLF2_MAP4_MAP,          // 13
-		WOLF2_MAP5_MAP,          // 14
-		WOLF2_MAP6_MAP,          // 15
-		WOLF2_MAP7_MAP,          // 16
-		WOLF2_MAP8_MAP,          // 17
-		WOLF2_BOSS_MAP,          // 18
-		WOLF2_SECRET_MAP,        // 19
-		WOLF3_MAP1_MAP,          // 20
-		WOLF3_MAP2_MAP,          // 21
-		WOLF3_MAP3_MAP,          // 22
-		WOLF3_MAP4_MAP,          // 23
-		WOLF3_MAP5_MAP,          // 24
-		WOLF3_MAP6_MAP,          // 25
-		WOLF3_MAP7_MAP,          // 26
-		WOLF3_MAP8_MAP,          // 27
-		WOLF3_BOSS_MAP,          // 28
-		WOLF3_SECRET_MAP,        // 29
-		LASTMAP
-	     } mapnames;
--- a/mapswl6.h
+++ /dev/null
@@ -1,73 +1,0 @@
-///////////////////////////////////////
-//
-// TED5 Map Header for WL6
-//
-///////////////////////////////////////
-
-//
-// Map Names
-//
-typedef enum {
-		WOLF1_MAP1_MAP,          // 0
-		WOLF1_MAP2_MAP,          // 1
-		WOLF1_MAP3_MAP,          // 2
-		WOLF1_MAP4_MAP,          // 3
-		WOLF1_MAP5_MAP,          // 4
-		WOLF1_MAP6_MAP,          // 5
-		WOLF1_MAP7_MAP,          // 6
-		WOLF1_MAP8_MAP,          // 7
-		WOLF1_BOSS_MAP,          // 8
-		WOLF1_SECRET_MAP,        // 9
-		WOLF2_MAP1_MAP,          // 10
-		WOLF2_MAP2_MAP,          // 11
-		WOLF2_MAP3_MAP,          // 12
-		WOLF2_MAP4_MAP,          // 13
-		WOLF2_MAP5_MAP,          // 14
-		WOLF2_MAP6_MAP,          // 15
-		WOLF2_MAP7_MAP,          // 16
-		WOLF2_MAP8_MAP,          // 17
-		WOLF2_BOSS_MAP,          // 18
-		WOLF2_SECRET_MAP,        // 19
-		WOLF3_MAP1_MAP,          // 20
-		WOLF3_MAP2_MAP,          // 21
-		WOLF3_MAP3_MAP,          // 22
-		WOLF3_MAP4_MAP,          // 23
-		WOLF3_MAP5_MAP,          // 24
-		WOLF3_MAP6_MAP,          // 25
-		WOLF3_MAP7_MAP,          // 26
-		WOLF3_MAP8_MAP,          // 27
-		WOLF3_BOSS_MAP,          // 28
-		WOLF3_SECRET_MAP,        // 29
-		WOLF4_MAP_1_MAP,         // 30
-		WOLF4_MAP_2_MAP,         // 31
-		WOLF4_MAP_3_MAP,         // 32
-		WOLF4_MAP_4_MAP,         // 33
-		WOLF4_MAP_5_MAP,         // 34
-		WOLF4_MAP_6_MAP,         // 35
-		WOLF4_MAP_7_MAP,         // 36
-		WOLF4_MAP_8_MAP,         // 37
-		WOLF4_BOSS_MAP,          // 38
-		WOLF4_SECRET_MAP,        // 39
-		WOLF5_MAP_1_MAP,         // 40
-		WOLF5_MAP_2_MAP,         // 41
-		WOLF5_MAP_3_MAP,         // 42
-		WOLF5_MAP_4_MAP,         // 43
-		WOLF5_MAP_5_MAP,         // 44
-		WOLF5_MAP_6_MAP,         // 45
-		WOLF5_MAP_7_MAP,         // 46
-		WOLF5_MAP_8_MAP,         // 47
-		WOLF5_BOSS_MAP,          // 48
-		WOLF5_SECRET_MAP,        // 49
-		WOLF6_MAP_1_MAP,         // 50
-		WOLF6_MAP_2_MAP,         // 51
-		WOLF6_MAP_3_MAP,         // 52
-		WOLF6_MAP_4_MAP,         // 53
-		WOLF6_MAP_5_MAP,         // 54
-		WOLF6_MAP_6_MAP,         // 55
-		WOLF6_MAP_7_MAP,         // 56
-		WOLF6_MAP_8_MAP,         // 57
-		WOLF6_BOSS_MAP,          // 58
-		WOLF6_SECRET_MAP,        // 59
-		MAP4L10PATH_MAP,         // 60
-		LASTMAP
-	     } mapnames;
--- a/menu.c
+++ b/menu.c
@@ -259,16 +259,9 @@
 
 		finishup:
 			CleanupControlPanel();
-			#ifdef SPEAR
-			UnCacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
-			#endif
 			return;
 	}
 
-#ifdef SPEAR
-	CacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
-#endif
-
 	DrawMainMenu();
 	MenuFadeIn();
 	StartGame=0;
@@ -288,26 +281,16 @@
 		if (Keyboard[sc_I] && Keyboard[sc_D])
 		{
 			VW_FadeOut();
-			StartCPMusic (XJAZNAZI_MUS);
-			UnCacheLump(OPTIONS_LUMP_START,OPTIONS_LUMP_END);
-			UnCacheLump(BACKDROP_LUMP_START,BACKDROP_LUMP_END);
+			StartCPMusic (18);
 			MM_SortMem ();
 			ClearMemory ();
 
+			VWB_DrawPic(0,0,Pid1);
+			VWB_DrawPic(0,80,Pid2);
 
-			CA_CacheGrChunk (IDGUYS1PIC);
-			VWB_DrawPic(0,0,IDGUYS1PIC);
-			UNCACHEGRCHUNK(IDGUYS1PIC);
-
-			CA_CacheGrChunk (IDGUYS2PIC);
-			VWB_DrawPic(0,80,IDGUYS2PIC);
-			UNCACHEGRCHUNK(IDGUYS2PIC);
-
 			VW_UpdateScreen();
 
-			CA_CacheGrChunk (IDGUYSPALETTE);
-			VL_FadeIn(0,255,grsegs[IDGUYSPALETTE],30);
-			UNCACHEGRCHUNK(IDGUYSPALETTE);
+			VL_FadeIn(0,255,Eid,30);	/* sod only */
 
 			while (Keyboard[sc_I] || Keyboard[sc_D]);
 			IN_ClearKeysDown();
@@ -315,8 +298,6 @@
 
 			VW_FadeOut();
 
-			CacheLump(BACKDROP_LUMP_START,BACKDROP_LUMP_END);
-			CacheLump(OPTIONS_LUMP_START,OPTIONS_LUMP_END);
 			DrawMainMenu();
 			StartCPMusic (MENUSONG);
 			MenuFadeIn();
@@ -336,29 +317,6 @@
 				break;
 
 			case backtodemo:
-				#ifdef SPEAR
-				if (!ingame)
-				{
-					//
-					// DEALLOCATE ALL SOUNDS!
-					//
-					switch (SoundMode)
-					{
-						case sdm_PC:
-							start = STARTPCSOUNDS;
-							break;
-						case sdm_AdLib:
-							start = STARTADLIBSOUNDS;
-							break;
-					}
-
-					if (SoundMode != sdm_Off)
-						for (i=0;i<NUMSOUNDS;i++,start++)
-							if (audiosegs[start])
-								MM_SetPurge (&(uchar *)audiosegs[start],3);		// make purgable
-				}
-				#endif
-
 				MM_SortMem();
 				StartGame=1;
 				if (!ingame)
@@ -399,13 +357,6 @@
 		_fstrcpy(MainMenu[viewscores].string,STR_EG);
 		#pragma warn +sus
 	}
-
-	// RETURN/START GAME EXECUTION
-
-#ifdef SPEAR
-	UnCacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
-	MM_SortMem ();
-#endif
 }
 
 
@@ -417,9 +368,9 @@
 {
 	ClearMScreen();
 
-	VWB_DrawPic(112,184,C_MOUSELBACKPIC);
+	VWB_DrawPic(112,184,Pmouselback);
 	DrawStripes(10);
-	VWB_DrawPic(84,0,C_OPTIONSPIC);
+	VWB_DrawPic(84,0,Popt);
 
 	DrawWindow(MENU_X-8,MENU_Y-3,MENU_W,MENU_H,BKGDCOLOR);
 
@@ -448,7 +399,7 @@
 ////////////////////////////////////////////////////////////////////
 void CP_ReadThis(void)
 {
-	StartCPMusic(CORNER_MUS);
+	StartCPMusic(0);
 	HelpScreens();
 	StartCPMusic(MENUSONG);
 }
@@ -495,19 +446,6 @@
 			}
 			else
 			{
-				#ifndef SPEAR
-				CA_CacheGrChunk(STARTFONT+1);
-				CA_CacheGrChunk(C_CURSOR1PIC);
-				CA_CacheGrChunk(C_CURSOR2PIC);
-				CA_CacheGrChunk(C_DISKLOADING1PIC);
-				CA_CacheGrChunk(C_DISKLOADING2PIC);
-				CA_CacheGrChunk(C_SAVEGAMEPIC);
-				CA_CacheGrChunk(C_MOUSELBACKPIC);
-				#else
-				CacheLump (BACKDROP_LUMP_START,BACKDROP_LUMP_END);
-				CA_CacheGrChunk(C_CURSOR1PIC);
-				#endif
-
 				VW_FadeOut ();
 
 				StartCPMusic(MENUSONG);
@@ -531,17 +469,6 @@
 					Mouse(MDelta);	// Clear accumulated mouse movement
 
 				PM_CheckMainMem ();
-
-				#ifndef SPEAR
-				UNCACHEGRCHUNK(C_CURSOR1PIC);
-				UNCACHEGRCHUNK(C_CURSOR2PIC);
-				UNCACHEGRCHUNK(C_DISKLOADING1PIC);
-				UNCACHEGRCHUNK(C_DISKLOADING2PIC);
-				UNCACHEGRCHUNK(C_SAVEGAMEPIC);
-				UNCACHEGRCHUNK(C_MOUSELBACKPIC);
-				#else
-				UnCacheLump (BACKDROP_LUMP_START,BACKDROP_LUMP_END);
-				#endif
 			}
 			return 1;
 
@@ -568,19 +495,6 @@
 			}
 			else
 			{
-				#ifndef SPEAR
-				CA_CacheGrChunk(STARTFONT+1);
-				CA_CacheGrChunk(C_CURSOR1PIC);
-				CA_CacheGrChunk(C_CURSOR2PIC);
-				CA_CacheGrChunk(C_DISKLOADING1PIC);
-				CA_CacheGrChunk(C_DISKLOADING2PIC);
-				CA_CacheGrChunk(C_LOADGAMEPIC);
-				CA_CacheGrChunk(C_MOUSELBACKPIC);
-				#else
-				CA_CacheGrChunk(C_CURSOR1PIC);
-				CacheLump (BACKDROP_LUMP_START,BACKDROP_LUMP_END);
-				#endif
-
 				VW_FadeOut ();
 
 				StartCPMusic(MENUSONG);
@@ -604,17 +518,6 @@
 				if (MousePresent)
 					Mouse(MDelta);	// Clear accumulated mouse movement
 				PM_CheckMainMem ();
-
-				#ifndef SPEAR
-				UNCACHEGRCHUNK(C_CURSOR1PIC);
-				UNCACHEGRCHUNK(C_CURSOR2PIC);
-				UNCACHEGRCHUNK(C_DISKLOADING1PIC);
-				UNCACHEGRCHUNK(C_DISKLOADING2PIC);
-				UNCACHEGRCHUNK(C_LOADGAMEPIC);
-				UNCACHEGRCHUNK(C_MOUSELBACKPIC);
-				#else
-				UnCacheLump (BACKDROP_LUMP_START,BACKDROP_LUMP_END);
-				#endif
 			}
 			return 1;
 
@@ -688,10 +591,9 @@
 	fontnumber=0;
 
 #ifdef SPEAR
-	UnCacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
-	StartCPMusic (XAWARD_MUS);
+	StartCPMusic (20);
 #else
-	StartCPMusic (ROSTER_MUS);
+	StartCPMusic (23);
 #endif
 
 	DrawHighScores ();
@@ -703,11 +605,6 @@
 
 	StartCPMusic(MENUSONG);
 	MenuFadeOut();
-
-#ifdef SPEAR
-	CacheLump (BACKDROP_LUMP_START,BACKDROP_LUMP_END);
-	CacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
-#endif
 }
 
 
@@ -720,11 +617,6 @@
 {
 	s16int which,episode;
 
-#ifdef SPEAR
-	UnCacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
-#endif
-
-
 #ifndef SPEAR
 firstpart:
 
@@ -741,7 +633,7 @@
 			default:
 				if (!EpisodeSelect[which/2])
 				{
-					SD_PlaySound (NOWAYSND);
+					SD_PlaySound (Snoway);
 					Message("Please select \"Read This!\"\n"
 							"from the Options menu to\n"
 							"find out how to order this\n"
@@ -781,14 +673,11 @@
 	//
 	// ALREADY IN A GAME?
 	//
-	CacheLump (NEWGAME_LUMP_START,NEWGAME_LUMP_END);
 	DrawNewGame();
 	if (ingame)
 		if (!Confirm(CURGAME))
 		{
 			MenuFadeOut();
-			UnCacheLump (NEWGAME_LUMP_START,NEWGAME_LUMP_END);
-			CacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
 			return;
 		}
 
@@ -802,8 +691,6 @@
 		#ifndef SPEAR
 		goto firstpart;
 		#else
-		UnCacheLump (NEWGAME_LUMP_START,NEWGAME_LUMP_END);
-		CacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
 		return;
 		#endif
 	}
@@ -821,11 +708,6 @@
 	#endif
 
 	pickquick = 0;
-
-#ifdef SPEAR
-	UnCacheLump (NEWGAME_LUMP_START,NEWGAME_LUMP_END);
-	CacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
-#endif
 }
 
 
@@ -839,7 +721,7 @@
 	s16int i;
 
 	ClearMScreen();
-	VWB_DrawPic(112,184,C_MOUSELBACKPIC);
+	VWB_DrawPic(112,184,Pmouselback);
 
 	DrawWindow(NE_X-4,NE_Y-4,NE_W+8,NE_H+8,BKGDCOLOR);
 	SETFONTCOLOR(READHCOLOR,BKGDCOLOR);
@@ -851,7 +733,7 @@
 	DrawMenu(&NewEitems,&NewEmenu[0]);
 
 	for (i=0;i<6;i++)
-		VWB_DrawPic(NE_X+32,NE_Y+i*26,C_EPISODE1PIC+i);
+		VWB_DrawPic(NE_X+32,NE_Y+i*26,Pep1+i);
 
 	VW_UpdateScreen();
 	MenuFadeIn();
@@ -866,7 +748,7 @@
 void DrawNewGame(void)
 {
 	ClearMScreen();
-	VWB_DrawPic(112,184,C_MOUSELBACKPIC);
+	VWB_DrawPic(112,184,Pmouselback);
 
 	SETFONTCOLOR(READHCOLOR,BKGDCOLOR);
 	PrintX=NM_X+20;
@@ -875,7 +757,7 @@
 #ifndef SPEAR
 	US_Print("How tough are you?");
 #else
-	VWB_DrawPic (PrintX,PrintY,C_HOWTOUGHPIC);
+	VWB_DrawPic (PrintX,PrintY,Pdiffc);
 #endif
 
 	DrawWindow(NM_X-5,NM_Y-10,NM_W,NM_H,BKGDCOLOR);
@@ -894,7 +776,7 @@
 //
 void DrawNewGameDiff(s16int w)
 {
-	VWB_DrawPic(NM_X+185,NM_Y+7,w+C_BABYMODEPIC);
+	VWB_DrawPic(NM_X+185,NM_Y+7,w+Pbaby);
 }
 
 
@@ -907,12 +789,6 @@
 {
 	s16int which,i;
 
-
-#ifdef SPEAR
-	UnCacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
-	CacheLump (SOUND_LUMP_START,SOUND_LUMP_END);
-#endif
-
 	DrawSoundMenu();
 	MenuFadeIn();
 	WaitKeyUp();
@@ -1008,11 +884,6 @@
 	} while(which>=0);
 
 	MenuFadeOut();
-
-#ifdef SPEAR
-	UnCacheLump (SOUND_LUMP_START,SOUND_LUMP_END);
-	CacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
-#endif
 }
 
 
@@ -1028,7 +899,7 @@
 	// DRAW SOUND MENU
 	//
 	ClearMScreen();
-	VWB_DrawPic(112,184,C_MOUSELBACKPIC);
+	VWB_DrawPic(112,184,Pmouselback);
 
 	DrawWindow(SM_X-8,SM_Y1-3,SM_W,SM_H1,BKGDCOLOR);
 	DrawWindow(SM_X-8,SM_Y2-3,SM_W,SM_H2,BKGDCOLOR);
@@ -1052,9 +923,9 @@
 		SndMenu[5].active=0;
 
 	DrawMenu(&SndItems,&SndMenu[0]);
-	VWB_DrawPic(100,SM_Y1-20,C_FXTITLEPIC);
-	VWB_DrawPic(100,SM_Y2-20,C_DIGITITLEPIC);
-	VWB_DrawPic(100,SM_Y3-20,C_MUSICTITLEPIC);
+	VWB_DrawPic(100,SM_Y1-20,Psfx);
+	VWB_DrawPic(100,SM_Y2-20,Ppcm);
+	VWB_DrawPic(100,SM_Y3-20,Pmus);
 
 	for (i=0;i<SndItems.amount;i++)
 		if (SndMenu[i].string[0])
@@ -1087,9 +958,9 @@
 			}
 
 			if (on)
-				VWB_DrawPic(SM_X+24,SM_Y1+i*13+2,C_SELECTEDPIC);
+				VWB_DrawPic(SM_X+24,SM_Y1+i*13+2,Psel);
 			else
-				VWB_DrawPic(SM_X+24,SM_Y1+i*13+2,C_NOTSELECTEDPIC);
+				VWB_DrawPic(SM_X+24,SM_Y1+i*13+2,Punsel);
 		}
 
 	DrawMenuGun(&SndItems);
@@ -1109,7 +980,7 @@
 
 	DrawWindow(LSA_X,LSA_Y,LSA_W,LSA_H,TEXTCOLOR);
 	DrawOutline(LSA_X,LSA_Y,LSA_W,LSA_H,0,HIGHLIGHT);
-	VWB_DrawPic(LSA_X+8,LSA_Y+5,C_DISKLOADING1PIC);
+	VWB_DrawPic(LSA_X+8,LSA_Y+5,Pread1);
 
 	fontnumber=1;
 	SETFONTCOLOR(0,TEXTCOLOR);
@@ -1167,12 +1038,6 @@
 		}
 	}
 
-
-#ifdef SPEAR
-	UnCacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
-	CacheLump (LOADSAVE_LUMP_START,LOADSAVE_LUMP_END);
-#endif
-
 	DrawLoadSaveScreen(0);
 
 	do
@@ -1209,11 +1074,6 @@
 
 	MenuFadeOut();
 
-#ifdef SPEAR
-	UnCacheLump (LOADSAVE_LUMP_START,LOADSAVE_LUMP_END);
-	CacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
-#endif
-
 	return exit;
 }
 
@@ -1247,14 +1107,14 @@
 
 	ClearMScreen();
 	fontnumber=1;
-	VWB_DrawPic(112,184,C_MOUSELBACKPIC);
+	VWB_DrawPic(112,184,Pmouselback);
 	DrawWindow(LSM_X-10,LSM_Y-5,LSM_W,LSM_H,BKGDCOLOR);
 	DrawStripes(10);
 
 	if (!loadsave)
-		VWB_DrawPic(60,0,C_LOADGAMEPIC);
+		VWB_DrawPic(60,0,Pload);
 	else
-		VWB_DrawPic(60,0,C_SAVEGAMEPIC);
+		VWB_DrawPic(60,0,Psave);
 
 	for (i=0;i<10;i++)
 		PrintLSEntry(i,TEXTCOLOR);
@@ -1325,12 +1185,6 @@
 		}
 	}
 
-
-#ifdef SPEAR
-	UnCacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
-	CacheLump (LOADSAVE_LUMP_START,LOADSAVE_LUMP_END);
-#endif
-
 	DrawLoadSaveScreen(1);
 
 	do
@@ -1387,7 +1241,7 @@
 				VWB_Bar(LSM_X+LSItems.indent+1,LSM_Y+which*13+1,LSM_W-LSItems.indent-16,10,BKGDCOLOR);
 				PrintLSEntry(which,HIGHLIGHT);
 				VW_UpdateScreen();
-				SD_PlaySound(ESCPRESSEDSND);
+				SD_PlaySound(Sesc);
 				continue;
 			}
 
@@ -1399,107 +1253,11 @@
 
 	MenuFadeOut();
 
-#ifdef SPEAR
-	UnCacheLump (LOADSAVE_LUMP_START,LOADSAVE_LUMP_END);
-	CacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
-#endif
-
 	return exit;
 }
 
-
 ////////////////////////////////////////////////////////////////////
 //
-// CALIBRATE JOYSTICK
-//
-////////////////////////////////////////////////////////////////////
-s16int CalibrateJoystick(void)
-{
-	#define CALX	85
-	#define CALY	40
-	#define CALW	158
-	#define CALH	140
-
-	u16int xmin,ymin,xmax,ymax,jb;
-
-
-
-	DrawWindow(CALX-5,CALY-5,CALW,CALH,TEXTCOLOR);
-	DrawOutline(CALX-5,CALY-5,CALW,CALH,0,HIGHLIGHT);
-	SETFONTCOLOR(0,TEXTCOLOR);
-
-	WindowX = PrintX = CALX;
-	WindowW = CALW;
-	WindowH = CALH;
-	WindowY = PrintY = CALY;
-	US_Print("    "STR_CALIB"\n    "STR_JOYST"\n");
-	VWB_DrawPic(CALX+40,CALY+30,C_JOY1PIC);
-	PrintY = CALY+80;
-	US_Print(STR_MOVEJOY);
-	SETFONTCOLOR(BKGDCOLOR,TEXTCOLOR);
-	US_Print("   "STR_ESCEXIT);
-	VW_UpdateScreen();
-
-	do
-	{
-		jb=IN_JoyButtons();
-		if (Keyboard[sc_Escape])
-			return 0;
-		#ifndef SPEAR
-		if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("goobers"))
-			PicturePause();
-		#endif
-
-	} while(!(jb&1));
-
-	SD_PlaySound(SHOOTSND);
-	IN_GetJoyAbs(joystickport,&xmin,&ymin);
-
-
-	DrawWindow(CALX-5,CALY-5,CALW,CALH,TEXTCOLOR);
-	DrawOutline(CALX-5,CALY-5,CALW,CALH,0,HIGHLIGHT);
-	SETFONTCOLOR(0,TEXTCOLOR);
-
-	PrintX = CALX;
-	PrintY = CALY;
-	US_Print("    "STR_CALIB"\n    "STR_JOYST"\n");
-	VWB_DrawPic(CALX+40,CALY+30,C_JOY2PIC);
-	PrintY = CALY+80;
-	US_Print(STR_MOVEJOY2);
-	SETFONTCOLOR(BKGDCOLOR,TEXTCOLOR);
-	US_Print("   "STR_ESCEXIT);
-	VW_UpdateScreen();
-
-	do
-	{
-		jb=IN_JoyButtons();
-		if (Keyboard[sc_Escape])
-			return 0;
-		#ifndef SPEAR
-		if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("goobers"))
-			PicturePause();
-		#endif
-	} while(!(jb&2));
-
-	IN_GetJoyAbs(joystickport,&xmax,&ymax);
-	SD_PlaySound(SHOOTSND);
-
-	while (IN_JoyButtons());
-
-	//
-	// ASSIGN ACTUAL VALUES HERE
-	//
-	if ((xmin != xmax) && (ymin != ymax))
-		IN_SetupJoy(joystickport,xmin,xmax,ymin,ymax);
-	else
-		return 0;
-
-	return 1;
-}
-
-
-////////////////////////////////////////////////////////////////////
-//
 // DEFINE CONTROLS
 //
 ////////////////////////////////////////////////////////////////////
@@ -1509,12 +1267,6 @@
 	enum {MOUSEENABLE,JOYENABLE,USEPORT2,PADENABLE,MOUSESENS,CUSTOMIZE};
 	s16int i,which;
 
-
-#ifdef SPEAR
-	UnCacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
-	CacheLump (CONTROL_LUMP_START,CONTROL_LUMP_END);
-#endif
-
 	DrawCtlScreen();
 	MenuFadeIn();
 	WaitKeyUp();
@@ -1535,9 +1287,6 @@
 
 			case JOYENABLE:
 				joystickenabled^=1;
-				if (joystickenabled)
-					if (!CalibrateJoystick())
-						joystickenabled = 0;
 				DrawCtlScreen();
 				CusItems.curpos=-1;
 				ShootSnd();
@@ -1565,11 +1314,6 @@
 	} while(which>=0);
 
 	MenuFadeOut();
-
-#ifdef SPEAR
-	UnCacheLump (CONTROL_LUMP_START,CONTROL_LUMP_END);
-	CacheLump (OPTIONS_LUMP_START,OPTIONS_LUMP_END);
-#endif
 }
 
 
@@ -1580,7 +1324,7 @@
 void DrawMouseSens(void)
 {
 	ClearMScreen();
-	VWB_DrawPic(112,184,C_MOUSELBACKPIC);
+	VWB_DrawPic(112,184,Pmouselback);
 	DrawWindow(10,80,300,30,BKGDCOLOR);
 
 	WindowX=0;
@@ -1633,7 +1377,7 @@
 					DrawOutline(60+20*mouseadjustment,97,20,10,0,READCOLOR);
 					VWB_Bar(61+20*mouseadjustment,98,19,9,READHCOLOR);
 					VW_UpdateScreen();
-					SD_PlaySound(MOVEGUN1SND);
+					SD_PlaySound(Sdrawgun1);
 					while(Keyboard[sc_LeftArrow]);
 					WaitKeyUp();
 				}
@@ -1649,7 +1393,7 @@
 					DrawOutline(60+20*mouseadjustment,97,20,10,0,READCOLOR);
 					VWB_Bar(61+20*mouseadjustment,98,19,9,READHCOLOR);
 					VW_UpdateScreen();
-					SD_PlaySound(MOVEGUN1SND);
+					SD_PlaySound(Sdrawgun1);
 					while(Keyboard[sc_RightArrow]);
 					WaitKeyUp();
 				}
@@ -1656,13 +1400,6 @@
 				break;
 		}
 
-		#ifndef SPEAR
-		if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("goobers"))
-		#else
-		if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("debugmode"))
-		#endif
-			PicturePause();
-
 		if (ci.button0 || Keyboard[sc_Space] || Keyboard[sc_Enter])
 			exit=1;
 		else
@@ -1674,10 +1411,10 @@
 	if (exit==2)
 	{
 		mouseadjustment=oldMA;
-		SD_PlaySound(ESCPRESSEDSND);
+		SD_PlaySound(Sesc);
 	}
 	else
-		SD_PlaySound(SHOOTSND);
+		SD_PlaySound(Sshoot);
 
 	WaitKeyUp();
 	MenuFadeOut();
@@ -1694,17 +1431,19 @@
 
  ClearMScreen();
  DrawStripes(10);
- VWB_DrawPic(80,0,C_CONTROLPIC);
- VWB_DrawPic(112,184,C_MOUSELBACKPIC);
+ VWB_DrawPic(80,0,Pctl);
+ VWB_DrawPic(112,184,Pmouselback);
  DrawWindow(CTL_X-8,CTL_Y-5,CTL_W,CTL_H,BKGDCOLOR);
  WindowX=0;
  WindowW=320;
  SETFONTCOLOR(TEXTCOLOR,BKGDCOLOR);
 
+/*
  if (JoysPresent[0])
    CtlMenu[1].active=
    CtlMenu[2].active=
    CtlMenu[3].active=1;
+*/
 
  CtlMenu[2].active=CtlMenu[3].active=joystickenabled;
 
@@ -1723,27 +1462,27 @@
  x=CTL_X+CtlItems.indent-24;
  y=CTL_Y+3;
  if (mouseenabled)
-   VWB_DrawPic(x,y,C_SELECTEDPIC);
+   VWB_DrawPic(x,y,Psel);
  else
-   VWB_DrawPic(x,y,C_NOTSELECTEDPIC);
+   VWB_DrawPic(x,y,Punsel);
 
  y=CTL_Y+16;
  if (joystickenabled)
-   VWB_DrawPic(x,y,C_SELECTEDPIC);
+   VWB_DrawPic(x,y,Psel);
  else
-   VWB_DrawPic(x,y,C_NOTSELECTEDPIC);
+   VWB_DrawPic(x,y,Punsel);
 
  y=CTL_Y+29;
  if (joystickport)
-   VWB_DrawPic(x,y,C_SELECTEDPIC);
+   VWB_DrawPic(x,y,Psel);
  else
-   VWB_DrawPic(x,y,C_NOTSELECTEDPIC);
+   VWB_DrawPic(x,y,Punsel);
 
  y=CTL_Y+42;
  if (joypadenabled)
-   VWB_DrawPic(x,y,C_SELECTEDPIC);
+   VWB_DrawPic(x,y,Psel);
  else
-   VWB_DrawPic(x,y,C_NOTSELECTEDPIC);
+   VWB_DrawPic(x,y,Punsel);
 
  //
  // PICK FIRST AVAILABLE SPOT
@@ -1787,8 +1526,7 @@
 	 DrawCustMouse(1);
 	 break;
    case 3:
-	 DefineJoyBtns();
-	 DrawCustJoy(0);
+	 // joystick
 	 break;
    case 6:
 	 DefineKeyBtns();
@@ -1819,17 +1557,6 @@
 
 ////////////////////////
 //
-// DEFINE THE JOYSTICK BUTTONS
-//
-void DefineJoyBtns(void)
-{
- CustomCtrls joyallowed={1,1,1,1};
- EnterCtrlData(5,&joyallowed,DrawCustJoy,PrintCustJoy,JOYSTICK);
-}
-
-
-////////////////////////
-//
 // DEFINE THE KEYBOARD BUTTONS
 //
 void DefineKeyBtns(void)
@@ -1936,7 +1663,7 @@
 	  case 1:
 	PrintX=x;
 	US_Print("?");
-	SD_PlaySound(HITWALLSND);
+	SD_PlaySound(Shitwall);
 	 }
 	 tick^=1;
 	 TimeCount=0;
@@ -1972,7 +1699,7 @@
 
 	buttonmouse[result-1]=order[which];
 	picked=1;
-	SD_PlaySound(SHOOTDOORSND);
+	SD_PlaySound(Shitdoor);
 	   }
 	   break;
 
@@ -1999,7 +1726,7 @@
 
 	buttonjoy[result-1]=order[which];
 	picked=1;
-	SD_PlaySound(SHOOTDOORSND);
+	SD_PlaySound(Shitdoor);
 	   }
 	   break;
 
@@ -2057,7 +1784,7 @@
 	which=3;
 	 } while(!cust->allowed[which]);
 	 redraw=1;
-	 SD_PlaySound(MOVEGUN1SND);
+	 SD_PlaySound(Sdrawgun1);
 	 while(ReadAnyControl(&ci),ci.dir!=dir_None);
 	 IN_ClearKeysDown();
 	 break;
@@ -2070,7 +1797,7 @@
 	which=0;
 	 } while(!cust->allowed[which]);
 	 redraw=1;
-	 SD_PlaySound(MOVEGUN1SND);
+	 SD_PlaySound(Sdrawgun1);
 	 while(ReadAnyControl(&ci),ci.dir!=dir_None);
 	 IN_ClearKeysDown();
 	 break;
@@ -2080,7 +1807,7 @@
   }
  } while(!exit);
 
- SD_PlaySound(ESCPRESSEDSND);
+ SD_PlaySound(Sesc);
  WaitKeyUp();
  DrawWindow(5,PrintY-1,310,13,BKGDCOLOR);
 }
@@ -2109,7 +1836,7 @@
 	switch(w)
 	{
 		case 0: DrawCustMouse(1); break;
-		case 3: DrawCustJoy(1); break;
+		case 3: /* joystick */ break;
 		case 6: DrawCustKeybd(1); break;
 		case 8: DrawCustKeys(1);
 	}
@@ -2132,7 +1859,7 @@
 			switch(lastwhich)
 			{
 				case 0: DrawCustMouse(0); break;
-				case 3: DrawCustJoy(0); break;
+				case 3: /* joystick */ break;
 				case 6: DrawCustKeybd(0); break;
 				case 8: DrawCustKeys(0);
 			}
@@ -2153,9 +1880,9 @@
 	ClearMScreen();
 	WindowX=0;
 	WindowW=320;
-	VWB_DrawPic(112,184,C_MOUSELBACKPIC);
+	VWB_DrawPic(112,184,Pmouselback);
 	DrawStripes(10);
-	VWB_DrawPic(80,0,C_CUSTOMIZEPIC);
+	VWB_DrawPic(80,0,Pcustom);
 
 	//
 	// MOUSE
@@ -2169,7 +1896,7 @@
 	US_CPrint("Mouse\n");
 #else
 	PrintY = CST_Y+13;
-	VWB_DrawPic (128,48,C_MOUSEPIC);
+	VWB_DrawPic (128,48,Pmouse);
 #endif
 
 	SETFONTCOLOR(TEXTCOLOR,BKGDCOLOR);
@@ -2195,11 +1922,11 @@
 	US_CPrint("Joystick/Gravis GamePad\n");
 #else
 	PrintY += 13;
-	VWB_DrawPic (40,88,C_JOYSTICKPIC);
+	VWB_DrawPic (40,88,Pjs);
 #endif
 
 #ifdef SPEAR
-	VWB_DrawPic (112,120,C_KEYBOARDPIC);
+	VWB_DrawPic (112,120,Pkb);
 #endif
 
 	SETFONTCOLOR(TEXTCOLOR,BKGDCOLOR);
@@ -2212,7 +1939,7 @@
 	PrintX=CST_START+CST_SPC*3;
 	US_Print(STR_CSTRAFE"\n");
 	DrawWindow(5,PrintY-1,310,13,BKGDCOLOR);
-	DrawCustJoy(0);
+	//DrawCustJoy(0);
 	US_Print("\n");
 
 
@@ -2306,43 +2033,6 @@
 		PrintCustMouse(i);
 }
 
-void PrintCustJoy(s16int i)
-{
-	s16int j;
-
-	for (j=0;j<4;j++)
-		if (order[i]==buttonjoy[j])
-		{
-			PrintX=CST_START+CST_SPC*i;
-			US_Print(mbarray[j]);
-			break;
-		}
-}
-
-void DrawCustJoy(s16int hilight)
-{
-	s16int i,color;
-
-
-	color=TEXTCOLOR;
-	if (hilight)
-		color=HIGHLIGHT;
-	SETFONTCOLOR(color,BKGDCOLOR);
-
-	if (!joystickenabled)
-	{
-		SETFONTCOLOR(DEACTIVE,BKGDCOLOR);
-		CusMenu[3].active=0;
-	}
-	else
-		CusMenu[3].active=1;
-
-	PrintY=CST_Y+13*5;
-	for (i=0;i<4;i++)
-		PrintCustJoy(i);
-}
-
-
 void PrintCustKeybd(s16int i)
 {
 	PrintX=CST_START+CST_SPC*i;
@@ -2416,7 +2106,7 @@
 				newview=4;
 			ShowViewSize(newview);
 			VW_UpdateScreen();
-			SD_PlaySound(HITWALLSND);
+			SD_PlaySound(Shitwall);
 			TicDelay(10);
 			break;
 
@@ -2427,18 +2117,11 @@
 				newview=19;
 			ShowViewSize(newview);
 			VW_UpdateScreen();
-			SD_PlaySound(HITWALLSND);
+			SD_PlaySound(Shitwall);
 			TicDelay(10);
 			break;
 		}
 
-		#ifndef SPEAR
-		if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("goobers"))
-		#else
-		if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("debugmode"))
-		#endif
-			PicturePause();
-
 		if (ci.button0 || Keyboard[sc_Enter])
 			exit=1;
 		else
@@ -2445,7 +2128,7 @@
 		if (ci.button1 || Keyboard[sc_Escape])
 		{
 			viewwidth=oldview*16;
-			SD_PlaySound(ESCPRESSEDSND);
+			SD_PlaySound(Sesc);
 			MenuFadeOut();
 			return;
 		}
@@ -2455,7 +2138,7 @@
 
 	if (oldview!=newview)
 	{
-		SD_PlaySound (SHOOTSND);
+		SD_PlaySound (Sshoot);
 		Message(STR_THINK"...");
 		NewViewSize(newview);
 	}
@@ -2580,9 +2263,6 @@
 	if (MousePresent)
 		VWB_Bar(164,82,12,2,FILLCOLOR);
 
-	if (JoysPresent[0] || JoysPresent[1])
-		VWB_Bar(164,105,12,2,FILLCOLOR);
-
 	if (AdLibPresent && !SoundBlasterPresent)
 		VWB_Bar(164,128,12,2,FILLCOLOR);
 
@@ -2612,37 +2292,12 @@
 #ifndef SPEAR
 	VWB_Bar(0,0,320,200,BORDCOLOR);
 #else
-	VWB_DrawPic(0,0,C_BACKDROPPIC);
+	VWB_DrawPic(0,0,Pbackdrop);
 #endif
 }
 
-
 ////////////////////////////////////////////////////////////////////
 //
-// Un/Cache a LUMP of graphics
-//
-////////////////////////////////////////////////////////////////////
-void CacheLump(s16int lumpstart,s16int lumpend)
-{
- s16int i;
-
- for (i=lumpstart;i<=lumpend;i++)
-   CA_CacheGrChunk(i);
-}
-
-
-void UnCacheLump(s16int lumpstart,s16int lumpend)
-{
- s16int i;
-
- for (i=lumpstart;i<=lumpend;i++)
-	if (grsegs[i])
-		UNCACHEGRCHUNK(i);
-}
-
-
-////////////////////////////////////////////////////////////////////
-//
 // Draw a window for a menu
 //
 ////////////////////////////////////////////////////////////////////
@@ -2677,12 +2332,6 @@
 	//
 	// CACHE GRAPHICS & SOUNDS
 	//
-	CA_CacheGrChunk(STARTFONT+1);
-#ifndef SPEAR
-	CacheLump(CONTROLS_LUMP_START,CONTROLS_LUMP_END);
-#else
-	CacheLump(BACKDROP_LUMP_START,BACKDROP_LUMP_END);
-#endif
 
 	SETFONTCOLOR(TEXTCOLOR,BKGDCOLOR);
 	fontnumber=1;
@@ -2729,12 +2378,6 @@
 ////////////////////////////////////////////////////////////////////
 void CleanupControlPanel(void)
 {
-#ifndef SPEAR
-	UnCacheLump(CONTROLS_LUMP_START,CONTROLS_LUMP_END);
-#else
-	UnCacheLump (BACKDROP_LUMP_START,BACKDROP_LUMP_END);
-#endif
-
 	fontnumber = 0;
 }
 
@@ -2757,7 +2400,7 @@
 	basey=item_i->y-2;
 	y=basey+which*13;
 
-	VWB_DrawPic(x,y,C_CURSOR1PIC);
+	VWB_DrawPic(x,y,Pcur1);
 	SetTextColor(items+which,1);
 	if (redrawitem)
 	{
@@ -2772,7 +2415,7 @@
 		routine(which);
 	VW_UpdateScreen();
 
-	shape=C_CURSOR1PIC;
+	shape=Pcur1;
 	timer=8;
 	exit=0;
 	TimeCount=0;
@@ -2787,14 +2430,14 @@
 		if (TimeCount>timer)
 		{
 			TimeCount=0;
-			if (shape==C_CURSOR1PIC)
+			if (shape==Pcur1)
 			{
-				shape=C_CURSOR2PIC;
+				shape=Pcur2;
 				timer=8;
 			}
 			else
 			{
-				shape=C_CURSOR1PIC;
+				shape=Pcur1;
 				timer=70;
 			}
 			VWB_DrawPic(x,y,shape);
@@ -2813,17 +2456,6 @@
 		{
 			s16int ok=0;
 
-			//
-			// CHECK FOR SCREEN CAPTURE
-			//
-			#ifndef SPEAR
-			if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("goobers"))
-			#else
-			if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("debugmode"))
-			#endif
-				PicturePause();
-
-
 			if (key>='a')
 				key-='a'-'A';
 
@@ -2979,7 +2611,7 @@
 			return which;
 
 		case 2:
-			SD_PlaySound(ESCPRESSEDSND);
+			SD_PlaySound(Sesc);
 			return -1;
 	}
 
@@ -3007,9 +2639,9 @@
 //
 void DrawHalfStep(s16int x,s16int y)
 {
-	VWB_DrawPic(x,y,C_CURSOR1PIC);
+	VWB_DrawPic(x,y,Pcur1);
 	VW_UpdateScreen();
-	SD_PlaySound(MOVEGUN1SND);
+	SD_PlaySound(Sdrawgun1);
 	TimeCount=0;
 	while(TimeCount<8);
 }
@@ -3022,7 +2654,7 @@
 {
 	VWB_Bar(x-1,*y,25,16,BKGDCOLOR);
 	*y=basey+which*13;
-	VWB_DrawPic(x,*y,C_CURSOR1PIC);
+	VWB_DrawPic(x,*y,Pcur1);
 	SetTextColor(items+which,1);
 
 	PrintX=item_i->x+item_i->indent;
@@ -3035,7 +2667,7 @@
 	if (routine)
 		routine(which);
 	VW_UpdateScreen();
-	SD_PlaySound(MOVEGUN2SND);
+	SD_PlaySound(Sdrawgun2);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -3189,39 +2821,6 @@
 			mouseactive=1;
 		}
 	}
-
-	if (joystickenabled && !mouseactive)
-	{
-		s16int jx,jy,jb;
-
-
-		INL_GetJoyDelta(joystickport,&jx,&jy);
-		if (jy<-SENSITIVE)
-			ci->dir=dir_North;
-		else
-		if (jy>SENSITIVE)
-			ci->dir=dir_South;
-
-		if (jx<-SENSITIVE)
-			ci->dir=dir_West;
-		else
-		if (jx>SENSITIVE)
-			ci->dir=dir_East;
-
-		jb=IN_JoyButtons();
-		if (jb)
-		{
-			ci->button0=jb&1;
-			ci->button1=jb&2;
-			if (joypadenabled)
-			{
-				ci->button2=jb&4;
-				ci->button3=jb&8;
-			}
-			else
-				ci->button2=ci->button3=false;
-		}
-	}
 }
 
 
@@ -3232,7 +2831,7 @@
 ////////////////////////////////////////////////////////////////////
 s16int Confirm(char far *string)
 {
-	s16int xit=0,i,x,y,tick=0,time,whichsnd[2]={ESCPRESSEDSND,SHOOTSND};
+	s16int xit=0,i,x,y,tick=0,time,whichsnd[2]={Sesc,Sshoot};
 
 
 	Message(string);
@@ -3263,11 +2862,6 @@
 			tick^=1;
 			TimeCount=0;
 		}
-
-		#ifndef SPEAR
-		if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("goobers"))
-			PicturePause();
-		#endif
 	} while(!Keyboard[sc_Y] && !Keyboard[sc_N] && !Keyboard[sc_Escape]);
 
 	if (Keyboard[sc_Y])
@@ -3322,44 +2916,12 @@
 	VW_UpdateScreen();
 }
 
-
-////////////////////////////////////////////////////////////////////
-//
-// THIS MAY BE FIXED A LITTLE LATER...
-//
-////////////////////////////////////////////////////////////////////
-static	s16int	lastmusic;
-
 void StartCPMusic(s16int song)
 {
-	musicnames	chunk;
-
-	if (audiosegs[STARTMUSIC + lastmusic])	// JDC
-		MM_FreePtr ((uchar **)&audiosegs[STARTMUSIC + lastmusic]);
-	lastmusic = song;
-
 	SD_MusicOff();
-	chunk =	song;
-
-	MM_BombOnError (false);
-	CA_CacheAudioChunk(STARTMUSIC + chunk);
-	MM_BombOnError (true);
-	if (mmerror)
-		mmerror = false;
-	else
-	{
-		MM_SetLock(&((uchar *)audiosegs[STARTMUSIC + chunk]),true);
-		SD_StartMusic((MusicGroup far *)audiosegs[STARTMUSIC + chunk]);
-	}
+	SD_StartMusic((MusicGroup far *)audiosegs[STARTMUSIC + song]);
 }
 
-void FreeMusic (void)
-{
-	if (audiosegs[STARTMUSIC + lastmusic])	// JDC
-		MM_FreePtr ((uchar **)&audiosegs[STARTMUSIC + lastmusic]);
-}
-
-
 ///////////////////////////////////////////////////////////////////////////
 //
 //	IN_GetScanName() - Returns a string containing the name of the
@@ -3415,7 +2977,7 @@
 
 	x=iteminfo->x;
 	y=iteminfo->y+iteminfo->curpos*13-2;
-	VWB_DrawPic(x,y,C_CURSOR1PIC);
+	VWB_DrawPic(x,y,Pcur1);
 }
 
 
@@ -3437,81 +2999,5 @@
 
 void ShootSnd(void)
 {
-	SD_PlaySound(SHOOTSND);
-}
-
-
-///////////////////////////////////////////////////////////////////////////
-//
-// CHECK FOR EPISODES
-//
-///////////////////////////////////////////////////////////////////////////
-void CheckForEpisodes(void)
-{
-	struct ffblk f;
-//
-// ENGLISH
-//
-#ifndef UPLOAD
-#ifndef SPEAR
-	if (!findfirst("*.WL6",&f,FA_ARCH))
-	{
-		strcpy(extension,"WL6");
-		NewEmenu[2].active =
-		NewEmenu[4].active =
-		NewEmenu[6].active =
-		NewEmenu[8].active =
-		NewEmenu[10].active =
-		EpisodeSelect[1] =
-		EpisodeSelect[2] =
-		EpisodeSelect[3] =
-		EpisodeSelect[4] =
-		EpisodeSelect[5] = 1;
-	}
-	else
-	if (!findfirst("*.WL3",&f,FA_ARCH))
-	{
-		strcpy(extension,"WL3");
-		NewEmenu[2].active =
-		NewEmenu[4].active =
-		EpisodeSelect[1] =
-		EpisodeSelect[2] = 1;
-	}
-	else
-#endif
-#endif
-
-
-
-#ifdef SPEAR
-#ifndef SPEARDEMO
-	if (!findfirst("*.SOD",&f,FA_ARCH))
-	{
-		strcpy(extension,"SOD");
-	}
-	else
-		Quit("NO SPEAR OF DESTINY DATA FILES TO BE FOUND!");
-#else
-	if (!findfirst("*.SDM",&f,FA_ARCH))
-	{
-		strcpy(extension,"SDM");
-	}
-	else
-		Quit("NO SPEAR OF DESTINY DEMO DATA FILES TO BE FOUND!");
-#endif
-
-#else
-	if (!findfirst("*.WL1",&f,FA_ARCH))
-	{
-		strcpy(extension,"WL1");
-	}
-	else
-		Quit("NO WOLFENSTEIN 3-D DATA FILES to be found!");
-#endif
-
-	strcat(configname,extension);
-	strcat(SaveName,extension);
-	strcat(PageFileName,extension);
-	strcat(audioname,extension);
-	strcat(demoname,extension);
+	SD_PlaySound(Sshoot);
 }
--- a/menu.h
+++ b/menu.h
@@ -31,12 +31,12 @@
 #define MenuFadeIn()	VL_FadeIn(0,255,&gamepal,10)
 
 
-#define MENUSONG	WONDERIN_MUS
+#define MENUSONG	14
 
 #ifndef SPEAR
-#define INTROSONG	NAZI_NOR_MUS
+#define INTROSONG	7
 #else
-#define INTROSONG	XTOWER2_MUS
+#define INTROSONG	23
 #endif
 
 #define SENSITIVE	60
@@ -123,8 +123,6 @@
 void WaitKeyUp(void);
 void ReadAnyControl(ControlInfo *ci);
 void TicDelay(s16int count);
-void CacheLump(s16int lumpstart,s16int lumpend);
-void UnCacheLump(s16int lumpstart,s16int lumpend);
 void StartCPMusic(s16int song);
 s16int  Confirm(char far *string);
 void Message(char far *string);
@@ -141,7 +139,6 @@
 void DrawStripes(s16int y);
 
 void DefineMouseBtns(void);
-void DefineJoyBtns(void);
 void DefineKeyBtns(void);
 void DefineKeyMove(void);
 void EnterCtrlData(s16int index,CustomCtrls *cust,void (*DrawRtn)(s16int),void (*PrintRtn)(s16int),s16int type);
@@ -157,11 +154,9 @@
 void DrawCustomScreen(void);
 void DrawLSAction(s16int which);
 void DrawCustMouse(s16int hilight);
-void DrawCustJoy(s16int hilight);
 void DrawCustKeybd(s16int hilight);
 void DrawCustKeys(s16int hilight);
 void PrintCustMouse(s16int i);
-void PrintCustJoy(s16int i);
 void PrintCustKeybd(s16int i);
 void PrintCustKeys(s16int i);
 
@@ -183,8 +178,6 @@
 s16int  CP_CheckQuick(u16int scancode);
 void CustomControls(void);
 void MouseSensitivity(void);
-
-void CheckForEpisodes(void);
 
 //
 // VARIABLES
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,17 @@
+</$objtype/mkfile
+
+BIN=$home/bin/$objtype
+TARG=wl3d
+
+OFILES=\
+	dat.$O\
+	fs.$O\
+	gm.$O\
+	map.$O\
+	rend.$O\
+	snd.$O\
+	wl3d.$O\
+
+HFILES= dat.h fns.h
+
+</sys/src/cmd/mkone
--- a/mm.c
+++ /dev/null
@@ -1,953 +1,0 @@
-// NEWMM.C
-
-/*
-=============================================================================
-
-		   ID software memory manager
-		   --------------------------
-
-Primary coder: John Carmack
-
-RELIES ON
----------
-Quit (char *error) function
-
-
-WORK TO DO
-----------
-MM_SizePtr to change the size of a given pointer
-
-Multiple purge levels utilized
-
-EMS / XMS unmanaged routines
-
-=============================================================================
-*/
-
-#include "ID_HEADS.H"
-#pragma hdrstop
-
-#pragma warn -pro
-#pragma warn -use
-
-/*
-=============================================================================
-
-							LOCAL INFO
-
-=============================================================================
-*/
-
-#define LOCKBIT		0x80	// if set in attributes, block cannot be moved
-#define PURGEBITS	3		// 0-3 level, 0= unpurgable, 3= purge first
-#define PURGEMASK	0xfffc
-#define BASEATTRIBUTES	0	// unlocked, non purgable
-
-#define MAXUMBS		10
-
-typedef struct mmblockstruct
-{
-	u16int	start,length;
-	u16int	attributes;
-	uchar **useptr;	// pointer to the segment start
-	struct mmblockstruct far *next;
-} mmblocktype;
-
-
-//#define GETNEWBLOCK {if(!(mmnew=mmfree))Quit("MM_GETNEWBLOCK: No free blocks!")\
-//	;mmfree=mmfree->next;}
-
-#define GETNEWBLOCK {if(!mmfree)MML_ClearBlock();mmnew=mmfree;mmfree=mmfree->next;}
-
-#define FREEBLOCK(x) {*x->useptr=NULL;x->next=mmfree;mmfree=x;}
-
-/*
-=============================================================================
-
-						 GLOBAL VARIABLES
-
-=============================================================================
-*/
-
-mminfotype	mminfo;
-uchar *bufferseg;
-int		mmerror;
-
-void		(* beforesort) (void);
-void		(* aftersort) (void);
-
-/*
-=============================================================================
-
-						 LOCAL VARIABLES
-
-=============================================================================
-*/
-
-int		mmstarted;
-
-void far	*farheap;
-void		*nearheap;
-
-mmblocktype	far mmblocks[MAXBLOCKS]
-			,far *mmhead,far *mmfree,far *mmrover,far *mmnew;
-
-int		bombonerror;
-
-//u16int	totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
-
-void		(* XMSaddr) (void);		// far pointer to XMS driver
-
-u16int	numUMBs,UMBbase[MAXUMBS];
-
-//==========================================================================
-
-//
-// local prototypes
-//
-
-int		MML_CheckForEMS (void);
-void 		MML_ShutdownEMS (void);
-void 		MM_MapEMS (void);
-int 	MML_CheckForXMS (void);
-void 		MML_ShutdownXMS (void);
-void		MML_UseSpace (u16int segstart, u16int seglength);
-void 		MML_ClearBlock (void);
-
-//==========================================================================
-
-/*
-======================
-=
-= MML_CheckForXMS
-=
-= Check for XMM driver
-=
-=======================
-*/
-
-int MML_CheckForXMS (void)
-{
-	numUMBs = 0;
-
-asm {
-	mov	ax,0x4300
-	int	0x2f				// query status of installed diver
-	cmp	al,0x80
-	je	good
-	}
-
-	return false;
-good:
-	return true;
-}
-
-
-/*
-======================
-=
-= MML_SetupXMS
-=
-= Try to allocate all upper memory block
-=
-=======================
-*/
-
-void MML_SetupXMS (void)
-{
-	u16int	base,size;
-
-asm	{
-	mov	ax,0x4310
-	int	0x2f
-	mov	[WORD PTR XMSaddr],bx
-	mov	[WORD PTR XMSaddr+2],es		// function pointer to XMS driver
-	}
-
-getmemory:
-asm	{
-	mov	ah,XMS_ALLOCUMB
-	mov	dx,0xffff					// try for largest block possible
-	call	[DWORD PTR XMSaddr]
-	or	ax,ax
-	jnz	gotone
-
-	cmp	bl,0xb0						// error: smaller UMB is available
-	jne	done;
-
-	mov	ah,XMS_ALLOCUMB
-	call	[DWORD PTR XMSaddr]		// DX holds largest available UMB
-	or	ax,ax
-	jz	done						// another error...
-	}
-
-gotone:
-asm	{
-	mov	[base],bx
-	mov	[size],dx
-	}
-	MML_UseSpace (base,size);
-	mminfo.XMSmem += size*16;
-	UMBbase[numUMBs] = base;
-	numUMBs++;
-	if (numUMBs < MAXUMBS)
-		goto getmemory;
-
-done:;
-}
-
-
-/*
-======================
-=
-= MML_ShutdownXMS
-=
-======================
-*/
-
-void MML_ShutdownXMS (void)
-{
-	s16int	i;
-	u16int	base;
-
-	for (i=0;i<numUMBs;i++)
-	{
-		base = UMBbase[i];
-
-asm	mov	ah,XMS_FREEUMB
-asm	mov	dx,[base]
-asm	call	[DWORD PTR XMSaddr]
-	}
-}
-
-//==========================================================================
-
-/*
-======================
-=
-= MML_UseSpace
-=
-= Marks a range of paragraphs as usable by the memory manager
-= This is used to mark space for the near heap, far heap, ems page frame,
-= and upper memory blocks
-=
-======================
-*/
-
-void MML_UseSpace (u16int segstart, u16int seglength)
-{
-	mmblocktype far *scan,far *last;
-	u16int	oldend;
-	s32int		extra;
-
-	scan = last = mmhead;
-	mmrover = mmhead;		// reset rover to start of memory
-
-//
-// search for the block that contains the range of segments
-//
-	while (scan->start+scan->length < segstart)
-	{
-		last = scan;
-		scan = scan->next;
-	}
-
-//
-// take the given range out of the block
-//
-	oldend = scan->start + scan->length;
-	extra = oldend - (segstart+seglength);
-	if (extra < 0)
-		Quit ("MML_UseSpace: Segment spans two blocks!");
-
-	if (segstart == scan->start)
-	{
-		last->next = scan->next;			// unlink block
-		FREEBLOCK(scan);
-		scan = last;
-	}
-	else
-		scan->length = segstart-scan->start;	// shorten block
-
-	if (extra > 0)
-	{
-		GETNEWBLOCK;
-		mmnew->useptr = NULL;
-
-		mmnew->next = scan->next;
-		scan->next = mmnew;
-		mmnew->start = segstart+seglength;
-		mmnew->length = extra;
-		mmnew->attributes = LOCKBIT;
-	}
-
-}
-
-//==========================================================================
-
-/*
-====================
-=
-= MML_ClearBlock
-=
-= We are out of blocks, so free a purgable block
-=
-====================
-*/
-
-void MML_ClearBlock (void)
-{
-	mmblocktype far *scan,far *last;
-
-	scan = mmhead->next;
-
-	while (scan)
-	{
-		if (!(scan->attributes&LOCKBIT) && (scan->attributes&PURGEBITS) )
-		{
-			MM_FreePtr(scan->useptr);
-			return;
-		}
-		scan = scan->next;
-	}
-
-	Quit ("MM_ClearBlock: No purgable blocks!");
-}
-
-
-//==========================================================================
-
-/*
-===================
-=
-= MM_Startup
-=
-= Grabs all space from turbo with malloc/farmalloc
-= Allocates bufferseg misc buffer
-=
-===================
-*/
-
-static	char *ParmStrings[] = {"noems","noxms",""};
-
-void MM_Startup (void)
-{
-	s16int i;
-	u32int length;
-	void far 	*start;
-	u16int 	segstart,seglength,endfree;
-
-	if (mmstarted)
-		MM_Shutdown ();
-
-
-	mmstarted = true;
-	bombonerror = true;
-//
-// set up the linked list (everything in the free list;
-//
-	mmhead = NULL;
-	mmfree = &mmblocks[0];
-	for (i=0;i<MAXBLOCKS-1;i++)
-		mmblocks[i].next = &mmblocks[i+1];
-	mmblocks[i].next = NULL;
-
-//
-// locked block of all memory until we punch out free space
-//
-	GETNEWBLOCK;
-	mmhead = mmnew;				// this will allways be the first node
-	mmnew->start = 0;
-	mmnew->length = 0xffff;
-	mmnew->attributes = LOCKBIT;
-	mmnew->next = NULL;
-	mmrover = mmhead;
-
-
-//
-// get all available near conventional memory segments
-//
-	length=coreleft();
-	start = (void far *)(nearheap = malloc(length));
-
-	length -= 16-(FP_OFF(start)&15);
-	length -= SAVENEARHEAP;
-	seglength = length / 16;			// now in paragraphs
-	segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
-	MML_UseSpace (segstart,seglength);
-	mminfo.nearheap = length;
-
-//
-// get all available far conventional memory segments
-//
-	length=farcoreleft();
-	start = farheap = farmalloc(length);
-	length -= 16-(FP_OFF(start)&15);
-	length -= SAVEFARHEAP;
-	seglength = length / 16;			// now in paragraphs
-	segstart = FP_SEG(start)+(FP_OFF(start)+15)/16;
-	MML_UseSpace (segstart,seglength);
-	mminfo.farheap = length;
-	mminfo.mainmem = mminfo.nearheap + mminfo.farheap;
-
-//
-// allocate the misc buffer
-//
-	mmrover = mmhead;		// start looking for space after low block
-
-	MM_GetPtr (&bufferseg,BUFFERSIZE);
-}
-
-//==========================================================================
-
-/*
-====================
-=
-= MM_Shutdown
-=
-= Frees all conventional, EMS, and XMS allocated
-=
-====================
-*/
-
-void MM_Shutdown (void)
-{
-  if (!mmstarted)
-	return;
-
-  farfree (farheap);
-  free (nearheap);
-//  MML_ShutdownXMS ();
-}
-
-//==========================================================================
-
-/*
-====================
-=
-= MM_GetPtr
-=
-= Allocates an unlocked, unpurgable block
-=
-====================
-*/
-
-void MM_GetPtr (uchar **baseptr,u32int size)
-{
-	mmblocktype far *scan,far *lastscan,far *endscan
-				,far *purge,far *next;
-	s16int			search;
-	u16int	needed,startseg;
-
-	needed = (size+15)/16;		// convert size from bytes to paragraphs
-
-	GETNEWBLOCK;				// fill in start and next after a spot is found
-	mmnew->length = needed;
-	mmnew->useptr = baseptr;
-	mmnew->attributes = BASEATTRIBUTES;
-
-tryagain:
-	for (search = 0; search<3; search++)
-	{
-	//
-	// first search:	try to allocate right after the rover, then on up
-	// second search: 	search from the head pointer up to the rover
-	// third search:	compress memory, then scan from start
-		if (search == 1 && mmrover == mmhead)
-			search++;
-
-		switch (search)
-		{
-		case 0:
-			lastscan = mmrover;
-			scan = mmrover->next;
-			endscan = NULL;
-			break;
-		case 1:
-			lastscan = mmhead;
-			scan = mmhead->next;
-			endscan = mmrover;
-			break;
-		case 2:
-			MM_SortMem ();
-			lastscan = mmhead;
-			scan = mmhead->next;
-			endscan = NULL;
-			break;
-		}
-
-		startseg = lastscan->start + lastscan->length;
-
-		while (scan != endscan)
-		{
-			if (scan->start - startseg >= needed)
-			{
-			//
-			// got enough space between the end of lastscan and
-			// the start of scan, so throw out anything in the middle
-			// and allocate the new block
-			//
-				purge = lastscan->next;
-				lastscan->next = mmnew;
-				mmnew->start = *(u16int *)baseptr = startseg;
-				mmnew->next = scan;
-				while ( purge != scan)
-				{	// free the purgable block
-					next = purge->next;
-					FREEBLOCK(purge);
-					purge = next;		// purge another if not at scan
-				}
-				mmrover = mmnew;
-				return;	// good allocation!
-			}
-
-			//
-			// if this block is purge level zero or locked, skip past it
-			//
-			if ( (scan->attributes & LOCKBIT)
-				|| !(scan->attributes & PURGEBITS) )
-			{
-				lastscan = scan;
-				startseg = lastscan->start + lastscan->length;
-			}
-
-
-			scan=scan->next;		// look at next line
-		}
-	}
-
-	if (bombonerror)
-	{
-
-extern char configname[];
-extern	int	insetupscaling;
-extern	s16int	viewsize;
-int SetViewSize (u16int width, u16int height);
-#define HEIGHTRATIO		0.50
-//
-// wolf hack -- size the view down
-//
-		if (!insetupscaling && viewsize>10)
-		{
-mmblocktype	far *savedmmnew;
-			savedmmnew = mmnew;
-			viewsize -= 2;
-			SetViewSize (viewsize*16,viewsize*16*HEIGHTRATIO);
-			mmnew = savedmmnew;
-			goto tryagain;
-		}
-
-//		unlink(configname);
-		Quit ("MM_GetPtr: Out of memory!");
-	}
-	else
-		mmerror = true;
-}
-
-//==========================================================================
-
-/*
-====================
-=
-= MM_FreePtr
-=
-= Deallocates an unlocked, purgable block
-=
-====================
-*/
-
-void MM_FreePtr (uchar **baseptr)
-{
-	mmblocktype far *scan,far *last;
-
-	last = mmhead;
-	scan = last->next;
-
-	if (baseptr == mmrover->useptr)	// removed the last allocated block
-		mmrover = mmhead;
-
-	while (scan->useptr != baseptr && scan)
-	{
-		last = scan;
-		scan = scan->next;
-	}
-
-	if (!scan)
-		Quit ("MM_FreePtr: Block not found!");
-
-	last->next = scan->next;
-
-	FREEBLOCK(scan);
-}
-//==========================================================================
-
-/*
-=====================
-=
-= MM_SetPurge
-=
-= Sets the purge level for a block (locked blocks cannot be made purgable)
-=
-=====================
-*/
-
-void MM_SetPurge (uchar **baseptr, s16int purge)
-{
-	mmblocktype far *start;
-
-	start = mmrover;
-
-	do
-	{
-		if (mmrover->useptr == baseptr)
-			break;
-
-		mmrover = mmrover->next;
-
-		if (!mmrover)
-			mmrover = mmhead;
-		else if (mmrover == start)
-			Quit ("MM_SetPurge: Block not found!");
-
-	} while (1);
-
-	mmrover->attributes &= ~PURGEBITS;
-	mmrover->attributes |= purge;
-}
-
-//==========================================================================
-
-/*
-=====================
-=
-= MM_SetLock
-=
-= Locks / unlocks the block
-=
-=====================
-*/
-
-void MM_SetLock (uchar **baseptr, int locked)
-{
-	mmblocktype far *start;
-
-	start = mmrover;
-
-	do
-	{
-		if (mmrover->useptr == baseptr)
-			break;
-
-		mmrover = mmrover->next;
-
-		if (!mmrover)
-			mmrover = mmhead;
-		else if (mmrover == start)
-			Quit ("MM_SetLock: Block not found!");
-
-	} while (1);
-
-	mmrover->attributes &= ~LOCKBIT;
-	mmrover->attributes |= locked*LOCKBIT;
-}
-
-//==========================================================================
-
-/*
-=====================
-=
-= MM_SortMem
-=
-= Throws out all purgable stuff and compresses movable blocks
-=
-=====================
-*/
-
-void MM_SortMem (void)
-{
-	mmblocktype far *scan,far *last,far *next;
-	u16int	start,length,source,dest;
-	s16int			playing;
-
-	//
-	// lock down a currently playing sound
-	//
-	playing = SD_SoundPlaying ();
-	if (playing)
-	{
-		switch (SoundMode)
-		{
-		case sdm_PC:
-			playing += STARTPCSOUNDS;
-			break;
-		case sdm_AdLib:
-			playing += STARTADLIBSOUNDS;
-			break;
-		}
-		MM_SetLock(&(uchar *)audiosegs[playing],true);
-	}
-
-
-	SD_StopSound();
-
-	if (beforesort)
-		beforesort();
-
-	scan = mmhead;
-
-	last = NULL;		// shut up compiler warning
-
-	while (scan)
-	{
-		if (scan->attributes & LOCKBIT)
-		{
-		//
-		// block is locked, so try to pile later blocks right after it
-		//
-			start = scan->start + scan->length;
-		}
-		else
-		{
-			if (scan->attributes & PURGEBITS)
-			{
-			//
-			// throw out the purgable block
-			//
-				next = scan->next;
-				FREEBLOCK(scan);
-				last->next = next;
-				scan = next;
-				continue;
-			}
-			else
-			{
-			//
-			// push the non purgable block on top of the last moved block
-			//
-				if (scan->start != start)
-				{
-					length = scan->length;
-					source = scan->start;
-					dest = start;
-					while (length > 0xf00)
-					{
-						movedata(source,0,dest,0,0xf00*16);
-						length -= 0xf00;
-						source += 0xf00;
-						dest += 0xf00;
-					}
-					movedata(source,0,dest,0,length*16);
-
-					scan->start = start;
-					*(u16int *)scan->useptr = start;
-				}
-				start = scan->start + scan->length;
-			}
-		}
-
-		last = scan;
-		scan = scan->next;		// go to next block
-	}
-
-	mmrover = mmhead;
-
-	if (aftersort)
-		aftersort();
-
-	if (playing)
-		MM_SetLock(&(uchar *)audiosegs[playing],false);
-}
-
-
-//==========================================================================
-
-/*
-=====================
-=
-= MM_ShowMemory
-=
-=====================
-*/
-
-void MM_ShowMemory (void)
-{
-	mmblocktype far *scan;
-	u16int color,temp,x,y;
-	s32int	end,owner;
-	char    scratch[80],str[10];
-
-	temp = bufferofs;
-	bufferofs = displayofs;
-	scan = mmhead;
-
-	end = -1;
-
-	while (scan)
-	{
-		if (scan->attributes & PURGEBITS)
-			color = 5;		// dark purple = purgable
-		else
-			color = 9;		// medium blue = non purgable
-		if (scan->attributes & LOCKBIT)
-			color = 12;		// red = locked
-		if (scan->start<=end)
-			Quit ("MM_ShowMemory: Memory block order currupted!");
-		end = scan->length-1;
-		y = scan->start/320;
-		x = scan->start%320;
-		VW_Hlin(x,x+end,y,color);
-		VW_Plot(x,y,15);
-		if (scan->next && scan->next->start > end+1)
-			VW_Hlin(x+end+1,x+(scan->next->start-scan->start),y,0);	// black = free
-
-		scan = scan->next;
-	}
-
-	VW_FadeIn ();
-	IN_Ack();
-
-	bufferofs = temp;
-}
-
-//==========================================================================
-
-/*
-=====================
-=
-= MM_DumpData
-=
-=====================
-*/
-
-void MM_DumpData (void)
-{
-	mmblocktype far *scan,far *best;
-	s32int	lowest,oldlowest;
-	u16int	owner;
-	char	lock,purge;
-	FILE	*dumpfile;
-
-
-	free (nearheap);
-	dumpfile = fopen ("MMDUMP.TXT","w");
-	if (!dumpfile)
-		Quit ("MM_DumpData: Couldn't open MMDUMP.TXT!");
-
-	lowest = -1;
-	do
-	{
-		oldlowest = lowest;
-		lowest = 0xffff;
-
-		scan = mmhead;
-		while (scan)
-		{
-			owner = (u16int)scan->useptr;
-
-			if (owner && owner<lowest && owner > oldlowest)
-			{
-				best = scan;
-				lowest = owner;
-			}
-
-			scan = scan->next;
-		}
-
-		if (lowest != 0xffff)
-		{
-			if (best->attributes & PURGEBITS)
-				purge = 'P';
-			else
-				purge = '-';
-			if (best->attributes & LOCKBIT)
-				lock = 'L';
-			else
-				lock = '-';
-			fprintf (dumpfile,"0x%p (%c%c) = %u\n"
-			,(u16int)lowest,lock,purge,best->length);
-		}
-
-	} while (lowest != 0xffff);
-
-	fclose (dumpfile);
-	Quit ("MMDUMP.TXT created.");
-}
-
-//==========================================================================
-
-
-/*
-======================
-=
-= MM_UnusedMemory
-=
-= Returns the total free space without purging
-=
-======================
-*/
-
-s32int MM_UnusedMemory (void)
-{
-	u16int free;
-	mmblocktype far *scan;
-
-	free = 0;
-	scan = mmhead;
-
-	while (scan->next)
-	{
-		free += scan->next->start - (scan->start + scan->length);
-		scan = scan->next;
-	}
-
-	return free*16l;
-}
-
-//==========================================================================
-
-
-/*
-======================
-=
-= MM_TotalFree
-=
-= Returns the total free space with purging
-=
-======================
-*/
-
-s32int MM_TotalFree (void)
-{
-	u16int free;
-	mmblocktype far *scan;
-
-	free = 0;
-	scan = mmhead;
-
-	while (scan->next)
-	{
-		if ((scan->attributes&PURGEBITS) && !(scan->attributes&LOCKBIT))
-			free += scan->length;
-		free += scan->next->start - (scan->start + scan->length);
-		scan = scan->next;
-	}
-
-	return free*16l;
-}
-
-//==========================================================================
-
-/*
-=====================
-=
-= MM_BombOnError
-=
-=====================
-*/
-
-void MM_BombOnError (int bomb)
-{
-	bombonerror = bomb;
-}
-
-
--- a/mm.h
+++ /dev/null
@@ -1,86 +1,0 @@
-#define SAVENEARHEAP	0x400		// space to leave in data segment
-#define SAVEFARHEAP		0			// space to leave in far heap
-
-#define	BUFFERSIZE		0x1000		// miscelanious, allways available buffer
-
-#define MAXBLOCKS		700
-
-
-//--------
-
-#define	EMS_INT			0x67
-
-#define	EMS_STATUS		0x40
-#define	EMS_GETFRAME	0x41
-#define	EMS_GETPAGES	0x42
-#define	EMS_ALLOCPAGES	0x43
-#define	EMS_MAPPAGE		0x44
-#define	EMS_FREEPAGES	0x45
-#define	EMS_VERSION		0x46
-
-//--------
-
-#define	XMS_INT			0x2f
-#define	XMS_CALL(v)		_AH = (v);\
-						asm call [DWORD PTR XMSDriver]
-
-#define	XMS_VERSION		0x00
-
-#define	XMS_ALLOCHMA	0x01
-#define	XMS_FREEHMA		0x02
-
-#define	XMS_GENABLEA20	0x03
-#define	XMS_GDISABLEA20	0x04
-#define	XMS_LENABLEA20	0x05
-#define	XMS_LDISABLEA20	0x06
-#define	XMS_QUERYA20	0x07
-
-#define	XMS_QUERYFREE	0x08
-#define	XMS_ALLOC		0x09
-#define	XMS_FREE		0x0A
-#define	XMS_MOVE		0x0B
-#define	XMS_LOCK		0x0C
-#define	XMS_UNLOCK		0x0D
-#define	XMS_GETINFO		0x0E
-#define	XMS_RESIZE		0x0F
-
-#define	XMS_ALLOCUMB	0x10
-#define	XMS_FREEUMB		0x11
-
-//==========================================================================
-
-typedef struct
-{
-	s32int	nearheap,farheap,EMSmem,XMSmem,mainmem;
-} mminfotype;
-
-//==========================================================================
-
-extern	mminfotype	mminfo;
-extern	uchar *bufferseg;
-extern	int		mmerror;
-
-extern	void		(* beforesort) (void);
-extern	void		(* aftersort) (void);
-
-//==========================================================================
-
-void MM_Startup (void);
-void MM_Shutdown (void);
-void MM_MapEMS (void);
-
-void MM_GetPtr (uchar **baseptr,u32int size);
-void MM_FreePtr (uchar **baseptr);
-
-void MM_SetPurge (uchar **baseptr, s16int purge);
-void MM_SetLock (uchar **baseptr, int locked);
-void MM_SortMem (void);
-
-void MM_ShowMemory (void);
-
-s32int MM_UnusedMemory (void);
-s32int MM_TotalFree (void);
-
-void MM_BombOnError (int bomb);
-
-void MML_UseSpace (u16int segstart, u16int seglength);
--- a/play.c
+++ b/play.c
@@ -110,92 +110,92 @@
  //
  // Episode One
  //
- GETTHEM_MUS,
- SEARCHN_MUS,
- POW_MUS,
- SUSPENSE_MUS,
- GETTHEM_MUS,
- SEARCHN_MUS,
- POW_MUS,
- SUSPENSE_MUS,
+ 3,
+ 11,
+ 9,
+ 12,
+ 3,
+ 11,
+ 9,
+ 12,
 
- WARMARCH_MUS,	// Boss level
- CORNER_MUS,	// Secret level
+ 2,	// Boss level
+ 0,	// Secret level
 
  //
  // Episode Two
  //
- NAZI_OMI_MUS,
- PREGNANT_MUS,
- GOINGAFT_MUS,
- HEADACHE_MUS,
- NAZI_OMI_MUS,
- PREGNANT_MUS,
- HEADACHE_MUS,
- GOINGAFT_MUS,
+ 8,
+ 18,
+ 17,
+ 4,
+ 8,
+ 18,
+ 4,
+ 17,
 
- WARMARCH_MUS,	// Boss level
- DUNGEON_MUS,	// Secret level
+ 2,	// Boss level
+ 1,	// Secret level
 
  //
  // Episode Three
  //
- INTROCW3_MUS,
- NAZI_RAP_MUS,
- TWELFTH_MUS,
- ZEROHOUR_MUS,
- INTROCW3_MUS,
- NAZI_RAP_MUS,
- TWELFTH_MUS,
- ZEROHOUR_MUS,
+ 6,
+ 20,
+ 22,
+ 21,
+ 6,
+ 20,
+ 22,
+ 21,
 
- ULTIMATE_MUS,	// Boss level
- PACMAN_MUS,	// Secret level
+ 19,	// Boss level
+ 26,	// Secret level
 
  //
  // Episode Four
  //
- GETTHEM_MUS,
- SEARCHN_MUS,
- POW_MUS,
- SUSPENSE_MUS,
- GETTHEM_MUS,
- SEARCHN_MUS,
- POW_MUS,
- SUSPENSE_MUS,
+ 3,
+ 11,
+ 9,
+ 12,
+ 3,
+ 11,
+ 9,
+ 12,
 
- WARMARCH_MUS,	// Boss level
- CORNER_MUS,	// Secret level
+ 2,	// Boss level
+ 0,	// Secret level
 
  //
  // Episode Five
  //
- NAZI_OMI_MUS,
- PREGNANT_MUS,
- GOINGAFT_MUS,
- HEADACHE_MUS,
- NAZI_OMI_MUS,
- PREGNANT_MUS,
- HEADACHE_MUS,
- GOINGAFT_MUS,
+ 8,
+ 18,
+ 17,
+ 4,
+ 8,
+ 18,
+ 4,
+ 17,
 
- WARMARCH_MUS,	// Boss level
- DUNGEON_MUS,	// Secret level
+ 2,	// Boss level
+ 1,	// Secret level
 
  //
  // Episode Six
  //
- INTROCW3_MUS,
- NAZI_RAP_MUS,
- TWELFTH_MUS,
- ZEROHOUR_MUS,
- INTROCW3_MUS,
- NAZI_RAP_MUS,
- TWELFTH_MUS,
- ZEROHOUR_MUS,
+ 6,
+ 20,
+ 22,
+ 21,
+ 6,
+ 20,
+ 22,
+ 21,
 
- ULTIMATE_MUS,	// Boss level
- FUNKYOU_MUS		// Secret level
+ 19,	// Boss level
+ 15		// Secret level
 #else
 
  //////////////////////////////////////////////////////////////
@@ -203,32 +203,32 @@
  // SPEAR OF DESTINY TRACKS
  //
  //////////////////////////////////////////////////////////////
- XTIPTOE_MUS,
- XFUNKIE_MUS,
- XDEATH_MUS,
- XGETYOU_MUS,		// DON'T KNOW
- ULTIMATE_MUS,	// Trans Gr�sse
+ 4,
+ 0,
+ 2,
+ 22,		// DON'T KNOW
+ 15,	// Trans Gr�sse
 
- DUNGEON_MUS,
- GOINGAFT_MUS,
- POW_MUS,
- TWELFTH_MUS,
- ULTIMATE_MUS,	// Barnacle Wilhelm BOSS
+ 1,
+ HITLWLTZ_MUS,
+ 9,
+ 10,
+ 15,	// Barnacle Wilhelm BOSS
 
- NAZI_OMI_MUS,
- GETTHEM_MUS,
- SUSPENSE_MUS,
- SEARCHN_MUS,
- ZEROHOUR_MUS,
- ULTIMATE_MUS,	// Super Mutant BOSS
+ 8,
+ 3,
+ 12,
+ 11,
+ 13,
+ 15,	// Super Mutant BOSS
 
- XPUTIT_MUS,
- ULTIMATE_MUS,	// Death Knight BOSS
+ 21,
+ 15,	// Death Knight BOSS
 
- XJAZNAZI_MUS,	// Secret level
- XFUNKIE_MUS,	// Secret level (DON'T KNOW)
+ 18,	// Secret level
+ 0,	// Secret level (DON'T KNOW)
 
- XEVIL_MUS		// Angel of Death BOSS
+ 17		// Angel of Death BOSS
 
 #endif
 };
@@ -290,49 +290,9 @@
 		buttonstate[buttonmouse[2]] = true;
 }
 
-
-
 /*
 ===================
 =
-= PollJoystickButtons
-=
-===================
-*/
-
-void PollJoystickButtons (void)
-{
-	s16int	buttons;
-
-	buttons = IN_JoyButtons ();
-
-	if (joystickport && !joypadenabled)
-	{
-		if (buttons&4)
-			buttonstate[buttonjoy[0]] = true;
-		if (buttons&8)
-			buttonstate[buttonjoy[1]] = true;
-	}
-	else
-	{
-		if (buttons&1)
-			buttonstate[buttonjoy[0]] = true;
-		if (buttons&2)
-			buttonstate[buttonjoy[1]] = true;
-		if (joypadenabled)
-		{
-			if (buttons&4)
-				buttonstate[buttonjoy[2]] = true;
-			if (buttons&8)
-				buttonstate[buttonjoy[3]] = true;
-		}
-	}
-}
-
-
-/*
-===================
-=
 = PollKeyboardMove
 =
 ===================
@@ -385,61 +345,9 @@
 	controly += mouseymove*20/(13-mouseadjustment);
 }
 
-
-
 /*
 ===================
 =
-= PollJoystickMove
-=
-===================
-*/
-
-void PollJoystickMove (void)
-{
-	s16int	joyx,joyy;
-
-	INL_GetJoyDelta(joystickport,&joyx,&joyy);
-
-	if (joystickprogressive)
-	{
-		if (joyx > 64)
-			controlx += (joyx-64)*JOYSCALE*tics;
-		else if (joyx < -64)
-			controlx -= (-joyx-64)*JOYSCALE*tics;
-		if (joyy > 64)
-			controlx += (joyy-64)*JOYSCALE*tics;
-		else if (joyy < -64)
-			controly -= (-joyy-64)*JOYSCALE*tics;
-	}
-	else if (buttonstate[bt_run])
-	{
-		if (joyx > 64)
-			controlx += RUNMOVE*tics;
-		else if (joyx < -64)
-			controlx -= RUNMOVE*tics;
-		if (joyy > 64)
-			controly += RUNMOVE*tics;
-		else if (joyy < -64)
-			controly -= RUNMOVE*tics;
-	}
-	else
-	{
-		if (joyx > 64)
-			controlx += BASEMOVE*tics;
-		else if (joyx < -64)
-			controlx -= BASEMOVE*tics;
-		if (joyy > 64)
-			controly += BASEMOVE*tics;
-		else if (joyy < -64)
-			controly -= BASEMOVE*tics;
-	}
-}
-
-
-/*
-===================
-=
 = PollControls
 =
 = Gets user or demo input, call once each frame
@@ -520,9 +428,6 @@
 	if (mouseenabled)
 		PollMouseButtons ();
 
-	if (joystickenabled)
-		PollJoystickButtons ();
-
 //
 // get movements
 //
@@ -531,9 +436,6 @@
 	if (mouseenabled)
 		PollMouseMove ();
 
-	if (joystickenabled)
-		PollJoystickMove ();
-
 //
 // bound movement to a maximum
 //
@@ -636,12 +538,12 @@
 		if (godmode)
 		{
 			Message ("God mode OFF");
-			SD_PlaySound (NOBONUSSND);
+			SD_PlaySound (Snobonus);
 		}
 		else
 		{
 			Message ("God mode ON");
-			SD_PlaySound (ENDBONUS2SND);
+			SD_PlaySound (Sendb2);
 		}
 
 		IN_Ack();
@@ -674,7 +576,6 @@
 		DrawScore();
 
 		ClearMemory ();
-		CA_CacheGrChunk (STARTFONT+1);
 		ClearSplitVWB ();
 		VW_ScreenToScreen (displayofs,bufferofs,80,160);
 
@@ -683,8 +584,6 @@
 				STR_CHEATER3"\n"
 				STR_CHEATER4"\n"
 				STR_CHEATER5);
-
-		UNCACHEGRCHUNK(STARTFONT+1);
 		PM_CheckMainMem ();
 		IN_ClearKeysDown();
 		IN_Ack();
@@ -695,25 +594,16 @@
 	//
 	// OPEN UP DEBUG KEYS
 	//
-#ifndef SPEAR
 	if (Keyboard[sc_BackSpace] &&
 		Keyboard[sc_LShift] &&
 		Keyboard[sc_Alt] &&
-		MS_CheckParm("goobers"))
-#else
-	if (Keyboard[sc_BackSpace] &&
-		Keyboard[sc_LShift] &&
-		Keyboard[sc_Alt] &&
-		MS_CheckParm("debugmode"))
-#endif
+		debug)
 	{
 	 ClearMemory ();
-	 CA_CacheGrChunk (STARTFONT+1);
 	 ClearSplitVWB ();
 	 VW_ScreenToScreen (displayofs,bufferofs,80,160);
 
 	 Message("Debugging keys are\nnow available!");
-	 UNCACHEGRCHUNK(STARTFONT+1);
 	 PM_CheckMainMem ();
 	 IN_ClearKeysDown();
 	 IN_Ack();
@@ -730,7 +620,6 @@
 		Keyboard[sc_T])
 	{
 	 ClearMemory ();
-	 CA_CacheGrChunk (STARTFONT+1);
 	 ClearSplitVWB ();
 	 VW_ScreenToScreen (displayofs,bufferofs,80,160);
 
@@ -739,7 +628,6 @@
 			 "then, you already know\n"
 			 "that - right, Cheatmeister?!");
 
-	 UNCACHEGRCHUNK(STARTFONT+1);
 	 PM_CheckMainMem ();
 	 IN_ClearKeysDown();
 	 IN_Ack();
@@ -753,7 +641,7 @@
 	if (Paused)
 	{
 		bufferofs = displayofs;
-		LatchDrawPic (20-4,80-2*8,PAUSEDPIC);
+		LatchDrawPic (20-4,80-2*8,Ppause);
 		SD_MusicOff();
 		IN_Ack();
 		IN_ClearKeysDown ();
@@ -1385,15 +1273,6 @@
 
 	do
 	{
-		if (virtualreality)
-		{
-			helmetangle = peek (0x40,0xf0);
-			player->angle += helmetangle;
-			if (player->angle >= ANGLES)
-				player->angle -= ANGLES;
-		}
-
-
 		PollControls();
 
 //
@@ -1419,7 +1298,7 @@
 		if (funnyticount > 30l*70)
 		{
 			funnyticount = 0;
-			StatusDrawPic (17,4,BJWAITING1PIC+(US_RndT()&1));
+			StatusDrawPic (17,4,Pwait+(US_RndT()&1));
 			facecount = 0;
 		}
 		#endif
@@ -1453,15 +1332,6 @@
 				playstate = ex_abort;
 			}
 		}
-
-
-		if (virtualreality)
-		{
-			player->angle -= helmetangle;
-			if (player->angle < 0)
-				player->angle += ANGLES;
-		}
-
 	}while (!playstate && !startgame);
 
 	if (playstate != ex_died)
--- a/pm.c
+++ /dev/null
@@ -1,1199 +1,0 @@
-//
-//	ID_PM.C
-//	Id Engine's Page Manager v1.0
-//	Primary coder: Jason Blochowiak
-//
-
-#include "ID_HEADS.H"
-#pragma hdrstop
-
-//	Main Mem specific variables
-	int			MainPresent;
-	uchar *MainMemPages[PMMaxMainMem];
-	PMBlockAttr		MainMemUsed[PMMaxMainMem];
-	s16int				MainPagesAvail;
-
-//	EMS specific variables
-	int			EMSPresent;
-	u16int			EMSAvail,EMSPagesAvail,EMSHandle,
-					EMSPageFrame,EMSPhysicalPage;
-	EMSListStruct	EMSList[EMSFrameCount];
-
-//	XMS specific variables
-	int			XMSPresent;
-	u16int			XMSAvail,XMSPagesAvail,XMSHandle;
-	u32int		XMSDriver;
-	s16int				XMSProtectPage = -1;
-
-//	File specific variables
-	char			PageFileName[13] = {"VSWAP."};
-	s16int				PageFile = -1;
-	u16int			ChunksInFile;
-	u16int			PMSpriteStart,PMSoundStart;
-
-//	General usage variables
-	int			PMStarted,
-					PMPanicMode,
-					PMThrashing;
-	u16int			XMSPagesUsed,
-					EMSPagesUsed,
-					MainPagesUsed,
-					PMNumBlocks;
-	s32int			PMFrameCount;
-	PageListStruct	far *PMPages,
-					_seg *PMSegPages;
-
-static	char		*ParmStrings[] = {"nomain","noems","noxms",nil};
-
-/////////////////////////////////////////////////////////////////////////////
-//
-//	EMS Management code
-//
-/////////////////////////////////////////////////////////////////////////////
-
-//
-//	PML_MapEMS() - Maps a logical page to a physical page
-//
-void
-PML_MapEMS(u16int logical,u16int physical)
-{
-	_AL = physical;
-	_BX = logical;
-	_DX = EMSHandle;
-	_AH = EMS_MAPPAGE;
-asm	int	EMS_INT
-
-	if (_AH)
-		Quit("PML_MapEMS: Page mapping failed");
-}
-
-//
-//	PML_StartupEMS() - Sets up EMS for Page Mgr's use
-//		Checks to see if EMS driver is present
-//      Verifies that EMS hardware is present
-//		Make sure that EMS version is 3.2 or later
-//		If there's more than our minimum (2 pages) available, allocate it (up
-//			to the maximum we need)
-//
-
-	char	EMMDriverName[9] = "EMMXXXX0";
-
-int
-PML_StartupEMS(void)
-{
-	s16int		i;
-	s32int	size;
-
-	EMSPresent = false;			// Assume that we'll fail
-	EMSAvail = 0;
-
-	_DX = (u16int)EMMDriverName;
-	_AX = 0x3d00;
-	geninterrupt(0x21);			// try to open EMMXXXX0 device
-asm	jnc	gothandle
-	goto error;
-
-gothandle:
-	_BX = _AX;
-	_AX = 0x4400;
-	geninterrupt(0x21);			// get device info
-asm	jnc	gotinfo;
-	goto error;
-
-gotinfo:
-asm	and	dx,0x80
-	if (!_DX)
-		goto error;
-
-	_AX = 0x4407;
-	geninterrupt(0x21);			// get status
-asm	jc	error
-	if (!_AL)
-		goto error;
-
-	_AH = 0x3e;
-	geninterrupt(0x21);			// close handle
-
-	_AH = EMS_STATUS;
-	geninterrupt(EMS_INT);
-	if (_AH)
-		goto error;				// make sure EMS hardware is present
-
-	_AH = EMS_VERSION;
-	geninterrupt(EMS_INT);
-	if (_AH || (_AL < 0x32))	// only work on EMS 3.2 or greater (silly, but...)
-		goto error;
-
-	_AH = EMS_GETFRAME;
-	geninterrupt(EMS_INT);
-	if (_AH)
-		goto error;				// find the page frame address
-	EMSPageFrame = _BX;
-
-	_AH = EMS_GETPAGES;
-	geninterrupt(EMS_INT);
-	if (_AH)
-		goto error;
-	if (_BX < 2)
-		goto error;         	// Require at least 2 pages (32k)
-	EMSAvail = _BX;
-
-	// Don't hog all available EMS
-	size = EMSAvail * (s32int)EMSPageSize;
-	if (size - (EMSPageSize * 2) > (ChunksInFile * (s32int)PMPageSize))
-	{
-		size = (ChunksInFile * (s32int)PMPageSize) + EMSPageSize;
-		EMSAvail = size / EMSPageSize;
-	}
-
-	_AH = EMS_ALLOCPAGES;
-	_BX = EMSAvail;
-	geninterrupt(EMS_INT);
-	if (_AH)
-		goto error;
-	EMSHandle = _DX;
-
-	mminfo.EMSmem += EMSAvail * (s32int)EMSPageSize;
-
-	// Initialize EMS mapping cache
-	for (i = 0;i < EMSFrameCount;i++)
-		EMSList[i].baseEMSPage = -1;
-
-	EMSPresent = true;			// We have EMS
-
-error:
-	return(EMSPresent);
-}
-
-//
-//	PML_ShutdownEMS() - If EMS was used, deallocate it
-//
-void
-PML_ShutdownEMS(void)
-{
-	if (EMSPresent)
-	{
-	asm	mov	ah,EMS_FREEPAGES
-	asm	mov	dx,[EMSHandle]
-	asm	int	EMS_INT
-		if (_AH)
-			Quit ("PML_ShutdownEMS: Error freeing EMS");
-	}
-}
-
-/////////////////////////////////////////////////////////////////////////////
-//
-//	XMS Management code
-//
-/////////////////////////////////////////////////////////////////////////////
-
-//
-//	PML_StartupXMS() - Starts up XMS for the Page Mgr's use
-//		Checks for presence of an XMS driver
-//		Makes sure that there's at least a page of XMS available
-//		Allocates any remaining XMS (rounded down to the nearest page size)
-//
-int
-PML_StartupXMS(void)
-{
-	XMSPresent = false;					// Assume failure
-	XMSAvail = 0;
-
-asm	mov	ax,0x4300
-asm	int	XMS_INT         				// Check for presence of XMS driver
-	if (_AL != 0x80)
-		goto error;
-
-
-asm	mov	ax,0x4310
-asm	int	XMS_INT							// Get address of XMS driver
-asm	mov	[WORD PTR XMSDriver],bx
-asm	mov	[WORD PTR XMSDriver+2],es		// function pointer to XMS driver
-
-	XMS_CALL(XMS_QUERYFREE);			// Find out how much XMS is available
-	XMSAvail = _AX;
-	if (!_AX)				// AJR: bugfix 10/8/92
-		goto error;
-
-	XMSAvail &= ~(PMPageSizeKB - 1);	// Round off to nearest page size
-	if (XMSAvail < (PMPageSizeKB * 2))	// Need at least 2 pages
-		goto error;
-
-	_DX = XMSAvail;
-	XMS_CALL(XMS_ALLOC);				// And do the allocation
-	XMSHandle = _DX;
-
-	if (!_AX)				// AJR: bugfix 10/8/92
-	{
-		XMSAvail = 0;
-		goto error;
-	}
-
-	mminfo.XMSmem += XMSAvail * 1024;
-
-	XMSPresent = true;
-error:
-	return(XMSPresent);
-}
-
-//
-//	PML_XMSCopy() - Copies a main/EMS page to or from XMS
-//		Will round an odd-length request up to the next even value
-//
-void
-PML_XMSCopy(int toxms,u8int far *addr,u16int xmspage,u16int length)
-{
-	u32int	xoffset;
-	struct
-	{
-		u32int	length;
-		u16int		source_handle;
-		u32int	source_offset;
-		u16int		target_handle;
-		u32int	target_offset;
-	} copy;
-
-	if (!addr)
-		Quit("PML_XMSCopy: zero address");
-
-	xoffset = (u32int)xmspage * PMPageSize;
-
-	copy.length = (length + 1) & ~1;
-	copy.source_handle = toxms? 0 : XMSHandle;
-	copy.source_offset = toxms? (s32int)addr : xoffset;
-	copy.target_handle = toxms? XMSHandle : 0;
-	copy.target_offset = toxms? xoffset : (s32int)addr;
-
-asm	push si
-	_SI = (u16int)&copy;
-	XMS_CALL(XMS_MOVE);
-asm	pop	si
-	if (!_AX)
-		Quit("PML_XMSCopy: Error on copy");
-}
-
-#if 1
-#define	PML_CopyToXMS(s,t,l)	PML_XMSCopy(true,(s),(t),(l))
-#define	PML_CopyFromXMS(t,s,l)	PML_XMSCopy(false,(t),(s),(l))
-#else
-//
-//	PML_CopyToXMS() - Copies the specified number of bytes from the real mode
-//		segment address to the specified XMS page
-//
-void
-PML_CopyToXMS(u8int far *source,s16int targetpage,u16int length)
-{
-	PML_XMSCopy(true,source,targetpage,length);
-}
-
-//
-//	PML_CopyFromXMS() - Copies the specified number of bytes from an XMS
-//		page to the specified real mode address
-//
-void
-PML_CopyFromXMS(u8int far *target,s16int sourcepage,u16int length)
-{
-	PML_XMSCopy(false,target,sourcepage,length);
-}
-#endif
-
-//
-//	PML_ShutdownXMS()
-//
-void
-PML_ShutdownXMS(void)
-{
-	if (XMSPresent)
-	{
-		_DX = XMSHandle;
-		XMS_CALL(XMS_FREE);
-		if (_BL)
-			Quit("PML_ShutdownXMS: Error freeing XMS");
-	}
-}
-
-/////////////////////////////////////////////////////////////////////////////
-//
-//	Main memory code
-//
-/////////////////////////////////////////////////////////////////////////////
-
-//
-//	PM_SetMainMemPurge() - Sets the purge level for all allocated main memory
-//		blocks. This shouldn't be called directly - the PM_LockMainMem() and
-//		PM_UnlockMainMem() macros should be used instead.
-//
-void
-PM_SetMainMemPurge(s16int level)
-{
-	s16int	i;
-
-	for (i = 0;i < PMMaxMainMem;i++)
-		if (MainMemPages[i])
-			MM_SetPurge(&MainMemPages[i],level);
-}
-
-//
-//	PM_CheckMainMem() - If something besides the Page Mgr makes requests of
-//		the Memory Mgr, some of the Page Mgr's blocks may have been purged,
-//		so this function runs through the block list and checks to see if
-//		any of the blocks have been purged. If so, it marks the corresponding
-//		page as purged & unlocked, then goes through the block list and
-//		tries to reallocate any blocks that have been purged.
-//	This routine now calls PM_LockMainMem() to make sure that any allocation
-//		attempts made during the block reallocation sweep don't purge any
-//		of the other blocks. Because PM_LockMainMem() is called,
-//		PM_UnlockMainMem() needs to be called before any other part of the
-//		program makes allocation requests of the Memory Mgr.
-//
-void
-PM_CheckMainMem(void)
-{
-	int			allocfailed;
-	s16int				i,n;
-	uchar **p;
-	PMBlockAttr		*used;
-	PageListStruct	far *page;
-
-	if (!MainPresent)
-		return;
-
-	for (i = 0,page = PMPages;i < ChunksInFile;i++,page++)
-	{
-		n = page->mainPage;
-		if (n != -1)						// Is the page using main memory?
-		{
-			if (!MainMemPages[n])			// Yep, was the block purged?
-			{
-				page->mainPage = -1;		// Yes, mark page as purged & unlocked
-				page->locked = pml_Unlocked;
-			}
-		}
-	}
-
-	// Prevent allocation attempts from purging any of our other blocks
-	PM_LockMainMem();
-	allocfailed = false;
-	for (i = 0,p = MainMemPages,used = MainMemUsed;i < PMMaxMainMem;i++,p++,used++)
-	{
-		if (!*p)							// If the page got purged
-		{
-			if (*used & pmba_Allocated)		// If it was allocated
-			{
-				*used &= ~pmba_Allocated;	// Mark as unallocated
-				MainPagesAvail--;			// and decrease available count
-			}
-
-			if (*used & pmba_Used)			// If it was used
-			{
-				*used &= ~pmba_Used;		// Mark as unused
-				MainPagesUsed--;			// and decrease used count
-			}
-
-			if (!allocfailed)
-			{
-				MM_BombOnError(false);
-				MM_GetPtr(p,PMPageSize);		// Try to reallocate
-				if (mmerror)					// If it failed,
-					allocfailed = true;			//  don't try any more allocations
-				else							// If it worked,
-				{
-					*used |= pmba_Allocated;	// Mark as allocated
-					MainPagesAvail++;			// and increase available count
-				}
-				MM_BombOnError(true);
-			}
-		}
-	}
-	if (mmerror)
-		mmerror = false;
-}
-
-//
-//	PML_StartupMainMem() - Allocates as much main memory as is possible for
-//		the Page Mgr. The memory is allocated as non-purgeable, so if it's
-//		necessary to make requests of the Memory Mgr, PM_UnlockMainMem()
-//		needs to be called.
-//
-void
-PML_StartupMainMem(void)
-{
-	s16int		i,n;
-	uchar **p;
-
-	MainPagesAvail = 0;
-	MM_BombOnError(false);
-	for (i = 0,p = MainMemPages;i < PMMaxMainMem;i++,p++)
-	{
-		MM_GetPtr(p,PMPageSize);
-		if (mmerror)
-			break;
-
-		MainPagesAvail++;
-		MainMemUsed[i] = pmba_Allocated;
-	}
-	MM_BombOnError(true);
-	if (mmerror)
-		mmerror = false;
-	if (MainPagesAvail < PMMinMainMem)
-		Quit("PM_SetupMainMem: Not enough main memory");
-	MainPresent = true;
-}
-
-//
-//	PML_ShutdownMainMem() - Frees all of the main memory blocks used by the
-//		Page Mgr.
-//
-void
-PML_ShutdownMainMem(void)
-{
-	s16int		i;
-	uchar **p;
-
-	// DEBUG - mark pages as unallocated & decrease page count as appropriate
-	for (i = 0,p = MainMemPages;i < PMMaxMainMem;i++,p++)
-		if (*p)
-			MM_FreePtr(p);
-}
-
-/////////////////////////////////////////////////////////////////////////////
-//
-//	File management code
-//
-/////////////////////////////////////////////////////////////////////////////
-
-//
-//	PML_ReadFromFile() - Reads some data in from the page file
-//
-void
-PML_ReadFromFile(u8int far *buf,s32int offset,u16int length)
-{
-	if (!buf)
-		Quit("PML_ReadFromFile: Null pointer");
-	if (!offset)
-		Quit("PML_ReadFromFile: Zero offset");
-	if (lseek(PageFile,offset,SEEK_SET) != offset)
-		Quit("PML_ReadFromFile: Seek failed");
-	if (!CA_FarRead(PageFile,buf,length))
-		Quit("PML_ReadFromFile: Read failed");
-}
-
-//
-//	PML_OpenPageFile() - Opens the page file and sets up the page info
-//
-void
-PML_OpenPageFile(void)
-{
-	s16int				i;
-	s32int			size;
-	void			_seg *buf;
-	u32int		far *offsetptr;
-	u16int			far *lengthptr;
-	PageListStruct	far *page;
-
-	PageFile = open(PageFileName,O_RDONLY + O_BINARY);
-	if (PageFile == -1)
-		Quit("PML_OpenPageFile: Unable to open page file");
-
-	// Read in header variables
-	read(PageFile,&ChunksInFile,sizeof(ChunksInFile));
-	read(PageFile,&PMSpriteStart,sizeof(PMSpriteStart));
-	read(PageFile,&PMSoundStart,sizeof(PMSoundStart));
-
-	// Allocate and clear the page list
-	PMNumBlocks = ChunksInFile;
-	MM_GetPtr(&(uchar *)PMSegPages,sizeof(PageListStruct) * PMNumBlocks);
-	MM_SetLock(&(uchar *)PMSegPages,true);
-	PMPages = (PageListStruct far *)PMSegPages;
-	_fmemset(PMPages,0,sizeof(PageListStruct) * PMNumBlocks);
-
-	// Read in the chunk offsets
-	size = sizeof(u32int) * ChunksInFile;
-	MM_GetPtr(&buf,size);
-	if (!CA_FarRead(PageFile,(u8int far *)buf,size))
-		Quit("PML_OpenPageFile: Offset read failed");
-	offsetptr = (u32int far *)buf;
-	for (i = 0,page = PMPages;i < ChunksInFile;i++,page++)
-		page->offset = *offsetptr++;
-	MM_FreePtr(&buf);
-
-	// Read in the chunk lengths
-	size = sizeof(u16int) * ChunksInFile;
-	MM_GetPtr(&buf,size);
-	if (!CA_FarRead(PageFile,(u8int far *)buf,size))
-		Quit("PML_OpenPageFile: Length read failed");
-	lengthptr = (u16int far *)buf;
-	for (i = 0,page = PMPages;i < ChunksInFile;i++,page++)
-		page->length = *lengthptr++;
-	MM_FreePtr(&buf);
-}
-
-//
-//  PML_ClosePageFile() - Closes the page file
-//
-void
-PML_ClosePageFile(void)
-{
-	if (PageFile != -1)
-		close(PageFile);
-	if (PMSegPages)
-	{
-		MM_SetLock(&(uchar *)PMSegPages,false);
-		MM_FreePtr(&(void _seg *)PMSegPages);
-	}
-}
-
-/////////////////////////////////////////////////////////////////////////////
-//
-//	Allocation, etc., code
-//
-/////////////////////////////////////////////////////////////////////////////
-
-//
-//	PML_GetEMSAddress()
-//
-// 		Page is in EMS, so figure out which EMS physical page should be used
-//  		to map our page in. If normal page, use EMS physical page 3, else
-//  		use the physical page specified by the lock type
-//
-#if 1
-#pragma argsused	// DEBUG - remove lock parameter
-uchar *
-PML_GetEMSAddress(s16int page,PMLockType lock)
-{
-	s16int		i,emspage;
-	u16int	emsoff,emsbase,offset;
-
-	emsoff = page & (PMEMSSubPage - 1);
-	emsbase = page - emsoff;
-
-	emspage = -1;
-	// See if this page is already mapped in
-	for (i = 0;i < EMSFrameCount;i++)
-	{
-		if (EMSList[i].baseEMSPage == emsbase)
-		{
-			emspage = i;	// Yep - don't do a redundant remapping
-			break;
-		}
-	}
-
-	// If page isn't already mapped in, find LRU EMS frame, and use it
-	if (emspage == -1)
-	{
-		u32int last = MAXLONG;
-		for (i = 0;i < EMSFrameCount;i++)
-		{
-			if (EMSList[i].lastHit < last)
-			{
-				emspage = i;
-				last = EMSList[i].lastHit;
-			}
-		}
-
-		EMSList[emspage].baseEMSPage = emsbase;
-		PML_MapEMS(page / PMEMSSubPage,emspage);
-	}
-
-	if (emspage == -1)
-		Quit("PML_GetEMSAddress: EMS find failed");
-
-	EMSList[emspage].lastHit = PMFrameCount;
-	offset = emspage * EMSPageSizeSeg;
-	offset += emsoff * PMPageSizeSeg;
-	return((uchar *)(EMSPageFrame + offset));
-}
-#else
-uchar *
-PML_GetEMSAddress(s16int page,PMLockType lock)
-{
-	u16int	emspage;
-
-	emspage = (lock < pml_EMSLock)? 3 : (lock - pml_EMSLock);
-
-	PML_MapEMS(page / PMEMSSubPage,emspage);
-
-	return((uchar *)(EMSPageFrame + (emspage * EMSPageSizeSeg)
-			+ ((page & (PMEMSSubPage - 1)) * PMPageSizeSeg)));
-}
-#endif
-
-//
-//	PM_GetPageAddress() - Returns the address of a given page
-//		Maps in EMS if necessary
-//		Returns nil if block isn't cached into Main Memory or EMS
-//
-//
-uchar *
-PM_GetPageAddress(s16int pagenum)
-{
-	PageListStruct	far *page;
-
-	page = &PMPages[pagenum];
-	if (page->mainPage != -1)
-		return(MainMemPages[page->mainPage]);
-	else if (page->emsPage != -1)
-		return(PML_GetEMSAddress(page->emsPage,page->locked));
-	else
-		return(nil);
-}
-
-//
-//	PML_GiveLRUPage() - Returns the page # of the least recently used
-//		present & unlocked main/EMS page (or main page if mainonly is true)
-//
-int
-PML_GiveLRUPage(int mainonly)
-{
-	s16int				i,lru;
-	s32int			last;
-	PageListStruct	far *page;
-
-	for (i = 0,page = PMPages,lru = -1,last = MAXLONG;i < ChunksInFile;i++,page++)
-	{
-		if
-		(
-			(page->lastHit < last)
-		&&	((page->emsPage != -1) || (page->mainPage != -1))
-		&& 	(page->locked == pml_Unlocked)
-		&&	(!(mainonly && (page->mainPage == -1)))
-		)
-		{
-			last = page->lastHit;
-			lru = i;
-		}
-	}
-
-	if (lru == -1)
-		Quit("PML_GiveLRUPage: LRU Search failed");
-	return(lru);
-}
-
-//
-//	PML_GiveLRUXMSPage() - Returns the page # of the least recently used
-//		(and present) XMS page.
-//	This routine won't return the XMS page protected (by XMSProtectPage)
-//
-int
-PML_GiveLRUXMSPage(void)
-{
-	s16int				i,lru;
-	s32int			last;
-	PageListStruct	far *page;
-
-	for (i = 0,page = PMPages,lru = -1,last = MAXLONG;i < ChunksInFile;i++,page++)
-	{
-		if
-		(
-			(page->xmsPage != -1)
-		&&	(page->lastHit < last)
-		&&	(i != XMSProtectPage)
-		)
-		{
-			last = page->lastHit;
-			lru = i;
-		}
-	}
-	return(lru);
-}
-
-//
-//	PML_PutPageInXMS() - If page isn't in XMS, find LRU XMS page and replace
-//		it with the main/EMS page
-//
-void
-PML_PutPageInXMS(s16int pagenum)
-{
-	s16int				usexms;
-	PageListStruct	far *page;
-
-	if (!XMSPresent)
-		return;
-
-	page = &PMPages[pagenum];
-	if (page->xmsPage != -1)
-		return;					// Already in XMS
-
-	if (XMSPagesUsed < XMSPagesAvail)
-		page->xmsPage = XMSPagesUsed++;
-	else
-	{
-		usexms = PML_GiveLRUXMSPage();
-		if (usexms == -1)
-			Quit("PML_PutPageInXMS: No XMS LRU");
-		page->xmsPage = PMPages[usexms].xmsPage;
-		PMPages[usexms].xmsPage = -1;
-	}
-	PML_CopyToXMS(PM_GetPageAddress(pagenum),page->xmsPage,page->length);
-}
-
-//
-//	PML_TransferPageSpace() - A page is being replaced, so give the new page
-//		the old one's address space. Returns the address of the new page.
-//
-uchar *
-PML_TransferPageSpace(s16int orig,s16int new)
-{
-	uchar *addr;
-	PageListStruct	far *origpage,far *newpage;
-
-	if (orig == new)
-		Quit("PML_TransferPageSpace: Identity replacement");
-
-	origpage = &PMPages[orig];
-	newpage = &PMPages[new];
-
-	if (origpage->locked != pml_Unlocked)
-		Quit("PML_TransferPageSpace: Killing locked page");
-
-	if ((origpage->emsPage == -1) && (origpage->mainPage == -1))
-		Quit("PML_TransferPageSpace: Reusing non-existent page");
-
-	// Copy page that's about to be purged into XMS
-	PML_PutPageInXMS(orig);
-
-	// Get the address, and force EMS into a physical page if necessary
-	addr = PM_GetPageAddress(orig);
-
-	// Steal the address
-	newpage->emsPage = origpage->emsPage;
-	newpage->mainPage = origpage->mainPage;
-
-	// Mark replaced page as purged
-	origpage->mainPage = origpage->emsPage = -1;
-
-	if (!addr)
-		Quit("PML_TransferPageSpace: Zero replacement");
-
-	return(addr);
-}
-
-//
-//	PML_GetAPageBuffer() - A page buffer is needed. Either get it from the
-//		main/EMS free pool, or use PML_GiveLRUPage() to find which page to
-//		steal the buffer from. Returns a far pointer to the page buffer, and
-//		sets the fields inside the given page structure appropriately.
-//		If mainonly is true, free EMS will be ignored, and only main pages
-//		will be looked at by PML_GiveLRUPage().
-//
-u8int far *
-PML_GetAPageBuffer(s16int pagenum,int mainonly)
-{
-	u8int			far *addr = nil;
-	s16int				i,n;
-	PMBlockAttr		*used;
-	PageListStruct	far *page;
-
-	page = &PMPages[pagenum];
-	if ((EMSPagesUsed < EMSPagesAvail) && !mainonly)
-	{
-		// There's remaining EMS - use it
-		page->emsPage = EMSPagesUsed++;
-		addr = PML_GetEMSAddress(page->emsPage,page->locked);
-	}
-	else if (MainPagesUsed < MainPagesAvail)
-	{
-		// There's remaining main memory - use it
-		for (i = 0,n = -1,used = MainMemUsed;i < PMMaxMainMem;i++,used++)
-		{
-			if ((*used & pmba_Allocated) && !(*used & pmba_Used))
-			{
-				n = i;
-				*used |= pmba_Used;
-				break;
-			}
-		}
-		if (n == -1)
-			Quit("PML_GetPageBuffer: MainPagesAvail lied");
-		addr = MainMemPages[n];
-		if (!addr)
-			Quit("PML_GetPageBuffer: Purged main block");
-		page->mainPage = n;
-		MainPagesUsed++;
-	}
-	else
-		addr = PML_TransferPageSpace(PML_GiveLRUPage(mainonly),pagenum);
-
-	if (!addr)
-		Quit("PML_GetPageBuffer: Search failed");
-	return(addr);
-}
-
-//
-//	PML_GetPageFromXMS() - If page is in XMS, find LRU main/EMS page and
-//		replace it with the page from XMS. If mainonly is true, will only
-//		search for LRU main page.
-//	XMSProtectPage is set to the page to be retrieved from XMS, so that if
-//		the page from which we're stealing the main/EMS from isn't in XMS,
-//		it won't copy over the page that we're trying to get from XMS.
-//		(pages that are being purged are copied into XMS, if possible)
-//
-uchar *
-PML_GetPageFromXMS(s16int pagenum,int mainonly)
-{
-	u8int			far *checkaddr;
-	uchar *addr = nil;
-	PageListStruct	far *page;
-
-	page = &PMPages[pagenum];
-	if (XMSPresent && (page->xmsPage != -1))
-	{
-		XMSProtectPage = pagenum;
-		checkaddr = PML_GetAPageBuffer(pagenum,mainonly);
-		if (FP_OFF(checkaddr))
-			Quit("PML_GetPageFromXMS: Non segment pointer");
-		addr = (uchar *)FP_SEG(checkaddr);
-		PML_CopyFromXMS(addr,page->xmsPage,page->length);
-		XMSProtectPage = -1;
-	}
-
-	return(addr);
-}
-
-//
-//	PML_LoadPage() - A page is not in main/EMS memory, and it's not in XMS.
-//		Load it into either main or EMS. If mainonly is true, the page will
-//		only be loaded into main.
-//
-void
-PML_LoadPage(s16int pagenum,int mainonly)
-{
-	u8int			far *addr;
-	PageListStruct	far *page;
-
-	addr = PML_GetAPageBuffer(pagenum,mainonly);
-	page = &PMPages[pagenum];
-	PML_ReadFromFile(addr,page->offset,page->length);
-}
-
-//
-//	PM_GetPage() - Returns the address of the page, loading it if necessary
-//		First, check if in Main Memory or EMS
-//		Then, check XMS
-//		If not in XMS, load into Main Memory or EMS
-//
-#pragma warn -pia
-uchar *
-PM_GetPage(s16int pagenum)
-{
-	uchar *result;
-
-	if (pagenum >= ChunksInFile)
-		Quit("PM_GetPage: Invalid page request");
-
-#if 0	// for debugging
-asm	mov	dx,STATUS_REGISTER_1
-asm	in	al,dx
-asm	mov	dx,ATR_INDEX
-asm	mov	al,ATR_OVERSCAN
-asm	out	dx,al
-asm	mov	al,10	// bright green
-asm	out	dx,al
-#endif
-
-	if (!(result = PM_GetPageAddress(pagenum)))
-	{
-		int mainonly = (pagenum >= PMSoundStart);
-if (!PMPages[pagenum].offset)	// JDC: sparse page
-	Quit ("Tried to load a sparse page!");
-		if (!(result = PML_GetPageFromXMS(pagenum,mainonly)))
-		{
-			if (PMPages[pagenum].lastHit == PMFrameCount)
-				PMThrashing++;
-
-			PML_LoadPage(pagenum,mainonly);
-			result = PM_GetPageAddress(pagenum);
-		}
-	}
-	PMPages[pagenum].lastHit = PMFrameCount;
-
-#if 0	// for debugging
-asm	mov	dx,STATUS_REGISTER_1
-asm	in	al,dx
-asm	mov	dx,ATR_INDEX
-asm	mov	al,ATR_OVERSCAN
-asm	out	dx,al
-asm	mov	al,3	// blue
-asm	out	dx,al
-asm	mov	al,0x20	// normal
-asm	out	dx,al
-#endif
-
-	return(result);
-}
-#pragma warn +pia
-
-//
-//	PM_SetPageLock() - Sets the lock type on a given page
-//		pml_Unlocked: Normal, page can be purged
-//		pml_Locked: Cannot be purged
-//		pml_EMS?: Same as pml_Locked, but if in EMS, use the physical page
-//					specified when returning the address. For sound stuff.
-//
-void
-PM_SetPageLock(s16int pagenum,PMLockType lock)
-{
-	if (pagenum < PMSoundStart)
-		Quit("PM_SetPageLock: Locking/unlocking non-sound page");
-
-	PMPages[pagenum].locked = lock;
-}
-
-//
-//	PM_Preload() - Loads as many pages as possible into all types of memory.
-//		Calls the update function after each load, indicating the current
-//		page, and the total pages that need to be loaded (for thermometer).
-//
-void
-PM_Preload(int (*update)(u16int current,u16int total))
-{
-	s16int				i,j,
-					page,oogypage;
-	u16int			current,total,
-					totalnonxms,totalxms,
-					mainfree,maintotal,
-					emsfree,emstotal,
-					xmsfree,xmstotal;
-	uchar *addr;
-	PageListStruct	far *p;
-
-	mainfree = (MainPagesAvail - MainPagesUsed) + (EMSPagesAvail - EMSPagesUsed);
-	xmsfree = (XMSPagesAvail - XMSPagesUsed);
-
-	xmstotal = maintotal = 0;
-
-	for (i = 0;i < ChunksInFile;i++)
-	{
-		if (!PMPages[i].offset)
-			continue;			// sparse
-
-		if ( PMPages[i].emsPage != -1 || PMPages[i].mainPage != -1 )
-			continue;			// already in main mem
-
-		if ( mainfree )
-		{
-			maintotal++;
-			mainfree--;
-		}
-		else if ( xmsfree && (PMPages[i].xmsPage == -1) )
-		{
-			xmstotal++;
-			xmsfree--;
-		}
-	}
-
-
-	total = maintotal + xmstotal;
-
-	if (!total)
-		return;
-
-	page = 0;
-	current = 0;
-
-//
-// cache main/ems blocks
-//
-	while (maintotal)
-	{
-		while ( !PMPages[page].offset || PMPages[page].mainPage != -1
-			||	PMPages[page].emsPage != -1 )
-			page++;
-
-		if (page >= ChunksInFile)
-			Quit ("PM_Preload: Pages>=ChunksInFile");
-
-		PM_GetPage(page);
-
-		page++;
-		current++;
-		maintotal--;
-		update(current,total);
-	}
-
-//
-// load stuff to XMS
-//
-	if (xmstotal)
-	{
-		for (oogypage = 0 ; PMPages[oogypage].mainPage == -1 ; oogypage++)
-		;
-		addr = PM_GetPage(oogypage);
-		if (!addr)
-			Quit("PM_Preload: XMS buffer failed");
-
-		while (xmstotal)
-		{
-			while ( !PMPages[page].offset || PMPages[page].xmsPage != -1 )
-				page++;
-
-			if (page >= ChunksInFile)
-				Quit ("PM_Preload: Pages>=ChunksInFile");
-
-			p = &PMPages[page];
-
-			p->xmsPage = XMSPagesUsed++;
-			if (XMSPagesUsed > XMSPagesAvail)
-				Quit("PM_Preload: Exceeded XMS pages");
-			if (p->length > PMPageSize)
-				Quit("PM_Preload: Page too long");
-
-			PML_ReadFromFile((u8int far *)addr,p->offset,p->length);
-			PML_CopyToXMS((u8int far *)addr,p->xmsPage,p->length);
-
-			page++;
-			current++;
-			xmstotal--;
-			update(current,total);
-		}
-
-		p = &PMPages[oogypage];
-		PML_ReadFromFile((u8int far *)addr,p->offset,p->length);
-	}
-
-	update(total,total);
-}
-
-/////////////////////////////////////////////////////////////////////////////
-//
-//	General code
-//
-/////////////////////////////////////////////////////////////////////////////
-
-//
-//	PM_NextFrame() - Increments the frame counter and adjusts the thrash
-//		avoidence variables
-//
-//		If currently in panic mode (to avoid thrashing), check to see if the
-//			appropriate number of frames have passed since the last time that
-//			we would have thrashed. If so, take us out of panic mode.
-//
-//
-void
-PM_NextFrame(void)
-{
-	s16int	i;
-
-	// Frame count overrun - kill the LRU hit entries & reset frame count
-	if (++PMFrameCount >= MAXLONG - 4)
-	{
-		for (i = 0;i < PMNumBlocks;i++)
-			PMPages[i].lastHit = 0;
-		PMFrameCount = 0;
-	}
-
-#if 0
-	for (i = 0;i < PMSoundStart;i++)
-	{
-		if (PMPages[i].locked)
-		{
-			char buf[40];
-			sprintf(buf,"PM_NextFrame: Page %d is locked",i);
-			Quit(buf);
-		}
-	}
-#endif
-
-	if (PMPanicMode)
-	{
-		// DEBUG - set border color
-		if ((!PMThrashing) && (!--PMPanicMode))
-		{
-			// DEBUG - reset border color
-		}
-	}
-	if (PMThrashing >= PMThrashThreshold)
-		PMPanicMode = PMUnThrashThreshold;
-	PMThrashing = false;
-}
-
-//
-//	PM_Reset() - Sets up caching structures
-//
-void
-PM_Reset(void)
-{
-	s16int				i;
-	PageListStruct	far *page;
-
-	XMSPagesAvail = XMSAvail / PMPageSizeKB;
-
-	EMSPagesAvail = EMSAvail * (EMSPageSizeKB / PMPageSizeKB);
-	EMSPhysicalPage = 0;
-
-	MainPagesUsed = EMSPagesUsed = XMSPagesUsed = 0;
-
-	PMPanicMode = false;
-
-	// Initialize page list
-	for (i = 0,page = PMPages;i < PMNumBlocks;i++,page++)
-	{
-		page->mainPage = -1;
-		page->emsPage = -1;
-		page->xmsPage = -1;
-		page->locked = false;
-	}
-}
-
-//
-//	PM_Startup() - Start up the Page Mgr
-//
-void
-PM_Startup(void)
-{
-	int	nomain,noems,noxms;
-	s16int		i;
-
-	if (PMStarted)
-		return;
-
-	nomain = noems = noxms = false;
-	for (i = 1;i < _argc;i++)
-	{
-		switch (US_CheckParm(_argv[i],ParmStrings))
-		{
-		case 0:
-			nomain = true;
-			break;
-		case 1:
-			noems = true;
-			break;
-		case 2:
-			noxms = true;
-			break;
-		}
-	}
-
-	PML_OpenPageFile();
-
-	if (!noems)
-		PML_StartupEMS();
-	if (!noxms)
-		PML_StartupXMS();
-
-	if (nomain && !EMSPresent)
-		Quit("PM_Startup: No main or EMS");
-	else
-		PML_StartupMainMem();
-
-	PM_Reset();
-
-	PMStarted = true;
-}
-
-//
-//	PM_Shutdown() - Shut down the Page Mgr
-//
-void
-PM_Shutdown(void)
-{
-	PML_ShutdownXMS();
-	PML_ShutdownEMS();
-
-	if (!PMStarted)
-		return;
-
-	PML_ClosePageFile();
-
-	PML_ShutdownMainMem();
-}
--- a/pm.h
+++ /dev/null
@@ -1,83 +1,0 @@
-//
-//	ID_PM.H
-//	Header file for Id Engine's Page Manager
-//
-
-//	NOTE! PMPageSize must be an even divisor of EMSPageSize, and >= 1024
-#define	EMSPageSize		16384
-#define	EMSPageSizeSeg	(EMSPageSize >> 4)
-#define	EMSPageSizeKB	(EMSPageSize >> 10)
-#define	EMSFrameCount	4
-#define	PMPageSize		4096
-#define	PMPageSizeSeg	(PMPageSize >> 4)
-#define	PMPageSizeKB	(PMPageSize >> 10)
-#define	PMEMSSubPage	(EMSPageSize / PMPageSize)
-
-#define	PMMinMainMem	10			// Min acceptable # of pages from main
-#define	PMMaxMainMem	100			// Max number of pages in main memory
-
-#define	PMThrashThreshold	1	// Number of page thrashes before panic mode
-#define	PMUnThrashThreshold	5	// Number of non-thrashing frames before leaving panic mode
-
-typedef	enum
-		{
-			pml_Unlocked,
-			pml_Locked
-		} PMLockType;
-
-typedef	enum
-		{
-			pmba_Unused = 0,
-			pmba_Used = 1,
-			pmba_Allocated = 2
-		} PMBlockAttr;
-
-typedef	struct
-		{
-			u32int	offset;		// Offset of chunk into file
-			u16int		length;		// Length of the chunk
-
-			s16int			xmsPage;	// If in XMS, (xmsPage * PMPageSize) gives offset into XMS handle
-
-			PMLockType	locked;		// If set, this page can't be purged
-			s16int			emsPage;	// If in EMS, logical page/offset into page
-			s16int			mainPage;	// If in Main, index into handle array
-
-			u32int	lastHit;	// Last frame number of hit
-		} PageListStruct;
-
-typedef	struct
-		{
-			s16int			baseEMSPage;	// Base EMS page for this phys frame
-			u32int	lastHit;		// Last frame number of hit
-		} EMSListStruct;
-
-extern	int			XMSPresent,EMSPresent;
-extern	u16int			XMSPagesAvail,EMSPagesAvail;
-
-extern	u16int			ChunksInFile,
-						PMSpriteStart,PMSoundStart;
-extern	PageListStruct	far *PMPages;
-
-#define	PM_GetSoundPage(v)	PM_GetPage(PMSoundStart + (v))
-#define	PM_GetSpritePage(v)	PM_GetPage(PMSpriteStart + (v))
-
-#define	PM_LockMainMem()	PM_SetMainMemPurge(0)
-#define	PM_UnlockMainMem()	PM_SetMainMemPurge(3)
-
-
-extern	char	PageFileName[13];
-
-
-extern	void	PM_Startup(void),
-				PM_Shutdown(void),
-				PM_Reset(void),
-				PM_Preload(int (*update)(u16int current,u16int total)),
-				PM_NextFrame(void),
-				PM_SetPageLock(s16int pagenum,PMLockType lock),
-				PM_SetMainPurge(s16int level),
-				PM_CheckMainMem(void);
-extern	uchar *PM_GetPageAddress(s16int pagenum),
-				PM_GetPage(s16int pagenum);		// Use this one to cache page
-
-void PM_SetMainMemPurge(s16int level);
--- /dev/null
+++ b/rend.c
@@ -1,0 +1,11 @@
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
+#include "dat.h"
+#include "fns.h"
+
+Dat *wals, *sprs, *spre;
+Pic *pics, *pice;
+Fnt fnts[2];
+Dat *exts, *exte;
+Dat *dems, *deme, *epis;
--- a/sd.c
+++ b/sd.c
@@ -62,8 +62,6 @@
 	u32int	TimeCount;
 	u16int		HackCount;
 	u16int		*SoundTable;	// Really * _seg *SoundTable, but that don't work
-	int		ssIsTandy;
-	u16int		ssPort = 2;
 	s16int			DigiMap[LASTSOUND];
 
 //	Internal variables
@@ -70,18 +68,6 @@
 static	int			SD_Started;
 		int			nextsoundpos;
 		u32int		TimerDivisor,TimerCount;
-static	char			*ParmStrings[] =
-						{
-							"noal",
-							"nosb",
-							"nopro",
-							"noss",
-							"sst",
-							"ss1",
-							"ss2",
-							"ss3",
-							nil
-						};
 static	void			(*SoundUserHook)(void);
 		soundnames		SoundNumber,DigiNumber;
 		u16int			SoundPriority,DigiPriority;
@@ -99,7 +85,6 @@
 static	u16int			DigiNextLen;
 
 //	SoundBlaster variables
-static	int					sbNoCheck,sbNoProCheck;
 static	volatile int		sbSamplePlaying;
 static	u8int					sbOldIntMask = -1;
 static	volatile u8int			huge *sbNextSegPtr;
@@ -116,7 +101,6 @@
 static	u8int					sbpOldFMMix,sbpOldVOCMix;
 
 //	SoundSource variables
-		int				ssNoCheck;
 		int				ssActive;
 		u16int				ssControl,ssStatus,ssData;
 		u8int				ssOn,ssOff;
@@ -129,7 +113,6 @@
 		u16int			pcSoundLookup[255];
 
 //	AdLib variables
-		int			alNoCheck;
 		u8int			far *alSound;
 		u16int			alBlock;
 		u32int		alLengthLeft;
@@ -543,8 +526,6 @@
 	sbOut(sbWriteData,timevalue);
 
 	SBProPresent = false;
-	if (sbNoProCheck)
-		return;
 
 	// Check to see if this is a SB Pro
 	sbOut(sbpMixerAddr,sbpmFMVol);
@@ -683,21 +664,12 @@
 static void
 SDL_StartSS(void)
 {
-	if (ssPort == 3)
-		ssControl = 0x27a;	// If using LPT3
-	else if (ssPort == 2)
-		ssControl = 0x37a;	// If using LPT2
-	else
-		ssControl = 0x3be;	// If using LPT1
+	ssControl = 0x3be;	// If using LPT1
 	ssStatus = ssControl - 1;
 	ssData = ssStatus - 1;
 
 	ssOn = 0x04;
-	if (ssIsTandy)
-		ssOff = 0x0e;				// Tandy wierdness
-	else
-		ssOff = 0x0c;				// For normal machines
-
+	ssOff = 0x0c;
 	outportb(ssControl,ssOn);		// Enable SS
 }
 
@@ -712,73 +684,7 @@
 	outportb(ssControl,ssOff);
 }
 
-///////////////////////////////////////////////////////////////////////////
 //
-//	SDL_CheckSS() - Checks to see if a Sound Source is present at the
-//		location specified by the sound source variables
-//
-///////////////////////////////////////////////////////////////////////////
-static int
-SDL_CheckSS(void)
-{
-	int		present = false;
-	u32int	lasttime;
-
-	// Turn the Sound Source on and wait awhile (4 ticks)
-	SDL_StartSS();
-
-	lasttime = TimeCount;
-	while (TimeCount < lasttime + 4)
-		;
-
-asm	mov		dx,[ssStatus]	// Check to see if FIFO is currently empty
-asm	in		al,dx
-asm	test	al,0x40
-asm	jnz		checkdone		// Nope - Sound Source not here
-
-asm	mov		cx,32			// Force FIFO overflow (FIFO is 16 bytes)
-outloop:
-asm	mov		dx,[ssData]		// Pump a neutral value out
-asm	mov		al,0x80
-asm	out		dx,al
-
-asm	mov		dx,[ssControl]	// Pulse printer select
-asm	mov		al,[ssOff]
-asm	out		dx,al
-asm	push	ax
-asm	pop		ax
-asm	mov		al,[ssOn]
-asm	out		dx,al
-
-asm	push	ax				// Delay a short while before we do this again
-asm	pop		ax
-asm	push	ax
-asm	pop		ax
-
-asm	loop	outloop
-
-asm	mov		dx,[ssStatus]	// Is FIFO overflowed now?
-asm	in		al,dx
-asm	test	al,0x40
-asm	jz		checkdone		// Nope, still not - Sound Source not here
-
-	present = true;			// Yes - it's here!
-
-checkdone:
-	SDL_ShutSS();
-	return(present);
-}
-
-static int
-SDL_DetectSoundSource(void)
-{
-	for (ssPort = 1;ssPort <= 3;ssPort++)
-		if (SDL_CheckSS())
-			return(true);
-	return(false);
-}
-
-//
 //	PC Sound code
 //
 
@@ -1793,12 +1699,6 @@
 	return(result);
 }
 
-///////////////////////////////////////////////////////////////////////////
-//
-//	SD_Startup() - starts up the Sound Mgr
-//		Detects all additional sound hardware and installs my ISR
-//
-///////////////////////////////////////////////////////////////////////////
 void
 SD_Startup(void)
 {
@@ -1809,45 +1709,6 @@
 
 	SDL_SetDS();
 
-	ssIsTandy = false;
-	ssNoCheck = false;
-	alNoCheck = false;
-	sbNoCheck = false;
-	sbNoProCheck = false;
-	for (i = 1;i < _argc;i++)
-	{
-		switch (US_CheckParm(_argv[i],ParmStrings))
-		{
-		case 0:						// No AdLib detection
-			alNoCheck = true;
-			break;
-		case 1:						// No SoundBlaster detection
-			sbNoCheck = true;
-			break;
-		case 2:						// No SoundBlaster Pro detection
-			sbNoProCheck = true;
-			break;
-		case 3:
-			ssNoCheck = true;		// No Sound Source detection
-			break;
-		case 4:						// Tandy Sound Source handling
-			ssIsTandy = true;
-			break;
-		case 5:						// Sound Source present at LPT1
-			ssPort = 1;
-			ssNoCheck = SoundSourcePresent = true;
-			break;
-		case 6:                     // Sound Source present at LPT2
-			ssPort = 2;
-			ssNoCheck = SoundSourcePresent = true;
-			break;
-		case 7:                     // Sound Source present at LPT3
-			ssPort = 3;
-			ssNoCheck = SoundSourcePresent = true;
-			break;
-		}
-	}
-
 	SoundUserHook = 0;
 
 	t0OldService = getvect(8);	// Get old timer 0 ISR
@@ -1857,13 +1718,14 @@
 	SD_SetSoundMode(sdm_Off);
 	SD_SetMusicMode(smm_Off);
 
-	if (!ssNoCheck)
-		SoundSourcePresent = SDL_DetectSoundSource();
+	/* → detect and select sound card */
 
-	if (!alNoCheck)
+	SoundSourcePresent = true;
+
+	if (1)
 	{
 		AdLibPresent = SDL_DetectAdLib();
-		if (AdLibPresent && !sbNoCheck)
+		if (AdLibPresent)
 		{
 			s16int port = -1;
 			char *env = getenv("BLASTER");
--- /dev/null
+++ b/snd.c
@@ -1,0 +1,8 @@
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
+#include "dat.h"
+#include "fns.h"
+
+Dat *imfs, *imfe;
+Sfx *sfxs, *sfxe;
--- a/state.c
+++ b/state.c
@@ -1258,13 +1258,13 @@
 	switch (ob->obclass)
 	{
 	case guardobj:
-		PlaySoundLocActor(HALTSND,ob);
+		PlaySoundLocActor(Sgd,ob);
 		NewState (ob,&s_grdchase1);
 		ob->speed *= 3;			// go faster when chasing player
 		break;
 
 	case officerobj:
-		PlaySoundLocActor(SPIONSND,ob);
+		PlaySoundLocActor(Soffc,ob);
 		NewState (ob,&s_ofcchase1);
 		ob->speed *= 5;			// go faster when chasing player
 		break;
@@ -1275,13 +1275,13 @@
 		break;
 
 	case ssobj:
-		PlaySoundLocActor(SCHUTZADSND,ob);
+		PlaySoundLocActor(Sss,ob);
 		NewState (ob,&s_sschase1);
 		ob->speed *= 4;			// go faster when chasing player
 		break;
 
 	case dogobj:
-		PlaySoundLocActor(DOGBARKSND,ob);
+		PlaySoundLocActor(Sdogbark,ob);
 		NewState (ob,&s_dogchase1);
 		ob->speed *= 2;			// go faster when chasing player
 		break;
@@ -1288,49 +1288,49 @@
 
 #ifndef SPEAR
 	case bossobj:
-		SD_PlaySound(GUTENTAGSND);
+		SD_PlaySound(Shans);
 		NewState (ob,&s_bosschase1);
 		ob->speed = SPDPATROL*3;	// go faster when chasing player
 		break;
 
 	case gretelobj:
-		SD_PlaySound(KEINSND);
+		SD_PlaySound(Sgretel);
 		NewState (ob,&s_gretelchase1);
 		ob->speed *= 3;			// go faster when chasing player
 		break;
 
 	case giftobj:
-		SD_PlaySound(EINESND);
+		SD_PlaySound(Sotto);
 		NewState (ob,&s_giftchase1);
 		ob->speed *= 3;			// go faster when chasing player
 		break;
 
 	case fatobj:
-		SD_PlaySound(ERLAUBENSND);
+		SD_PlaySound(Sfett);
 		NewState (ob,&s_fatchase1);
 		ob->speed *= 3;			// go faster when chasing player
 		break;
 
 	case schabbobj:
-		SD_PlaySound(SCHABBSHASND);
+		SD_PlaySound(Sschb);
 		NewState (ob,&s_schabbchase1);
 		ob->speed *= 3;			// go faster when chasing player
 		break;
 
 	case fakeobj:
-		SD_PlaySound(TOT_HUNDSND);
+		SD_PlaySound(Sfake);
 		NewState (ob,&s_fakechase1);
 		ob->speed *= 3;			// go faster when chasing player
 		break;
 
 	case mechahitlerobj:
-		SD_PlaySound(DIESND);
+		SD_PlaySound(Shilterdeath);
 		NewState (ob,&s_mechachase1);
 		ob->speed *= 3;			// go faster when chasing player
 		break;
 
 	case realhitlerobj:
-		SD_PlaySound(DIESND);
+		SD_PlaySound(Shilterdeath);
 		NewState (ob,&s_hitlerchase1);
 		ob->speed *= 5;			// go faster when chasing player
 		break;
@@ -1342,19 +1342,19 @@
 #else
 
 	case spectreobj:
-		SD_PlaySound(GHOSTSIGHTSND);
+		SD_PlaySound(Sghost);
 		NewState (ob,&s_spectrechase1);
 		ob->speed = 800;			// go faster when chasing player
 		break;
 
 	case angelobj:
-		SD_PlaySound(ANGELSIGHTSND);
+		SD_PlaySound(Sangel);
 		NewState (ob,&s_angelchase1);
 		ob->speed = 1536;			// go faster when chasing player
 		break;
 
 	case transobj:
-		SD_PlaySound(TRANSSIGHTSND);
+		SD_PlaySound(Strans);
 		NewState (ob,&s_transchase1);
 		ob->speed = 1536;			// go faster when chasing player
 		break;
@@ -1365,13 +1365,13 @@
 		break;
 
 	case willobj:
-		SD_PlaySound(WILHELMSIGHTSND);
+		SD_PlaySound(Swilh);
 		NewState (ob,&s_willchase1);
 		ob->speed = 2048;			// go faster when chasing player
 		break;
 
 	case deathobj:
-		SD_PlaySound(KNIGHTSIGHTSND);
+		SD_PlaySound(Sknight);
 		NewState (ob,&s_deathchase1);
 		ob->speed = 2048;			// go faster when chasing player
 		break;
--- a/text.c
+++ b/text.c
@@ -420,11 +420,12 @@
 //
 // clear the screen
 //
+	/* wl. lumps only, never used with spear */
 	VWB_Bar (0,0,320,200,BACKCOLOR);
-	VWB_DrawPic (0,0,H_TOPWINDOWPIC);
-	VWB_DrawPic (0,8,H_LEFTWINDOWPIC);
-	VWB_DrawPic (312,8,H_RIGHTWINDOWPIC);
-	VWB_DrawPic (8,176,H_BOTTOMINFOPIC);
+	VWB_DrawPic (0,0,Pbackdrop);
+	VWB_DrawPic (0,8,Pbackdrop+1);
+	VWB_DrawPic (312,8,Pbackdrop+2);
+	VWB_DrawPic (8,176,Pbackdrop+3);
 
 
 	for (i=0;i<TEXTROWS;i++)
@@ -548,10 +549,6 @@
 				numpages++;
 			if (ch == 'E')		// end of file, so load graphics and return
 			{
-				CA_MarkGrChunk(H_TOPWINDOWPIC);
-				CA_MarkGrChunk(H_LEFTWINDOWPIC);
-				CA_MarkGrChunk(H_RIGHTWINDOWPIC);
-				CA_MarkGrChunk(H_BOTTOMINFOPIC);
 				CA_CacheMarks ();
 				text = textstart;
 				return;
@@ -559,12 +556,10 @@
 			if (ch == 'G')		// draw graphic command, so mark graphics
 			{
 				ParsePicCommand ();
-				CA_MarkGrChunk (picnum);
 			}
 			if (ch == 'T')		// timed draw graphic command, so mark graphics
 			{
 				ParseTimedCommand ();
-				CA_MarkGrChunk (picnum);
 			}
 		}
 		else
@@ -592,7 +587,6 @@
 	text = article;
 	oldfontnumber = fontnumber;
 	fontnumber = 0;
-	CA_MarkGrChunk(STARTFONT);
 	VWB_Bar (0,0,320,200,BACKCOLOR);
 	CacheLayoutGraphics ();
 
@@ -641,12 +635,6 @@
 			}
 			break;
 		}
-
-		#ifndef SPEAR
-		if (Keyboard[sc_Tab] && Keyboard[sc_P] && MS_CheckParm("goobers"))
-			PicturePause();
-		#endif
-
 	} while (LastScan != sc_Escape);
 
 	IN_ClearKeysDown ();
@@ -653,14 +641,6 @@
 	fontnumber = oldfontnumber;
 }
 
-
-//===========================================================================
-
-s16int 	endextern = T_ENDART1;
-#ifndef SPEAR
-s16int		helpextern = T_HELPART;
-#endif
-
 /*
 =================
 =
@@ -671,27 +651,15 @@
 #ifndef SPEAR
 void HelpScreens (void)
 {
-	s16int			artnum;
-	char far 	*text;
 	uchar *layout;
 
 	CA_UpLevel ();
-	MM_SortMem ();
 
-	artnum = helpextern;
-	CA_CacheGrChunk (artnum);
-	text = (char _seg *)grsegs[artnum];
-	MM_SetLock (&grsegs[artnum], true);
+	ShowArticle (Etitpal);
 
-	ShowArticle (text);
-
-	MM_FreePtr (&grsegs[artnum]);
-
 	VW_FadeOut();
 
-	FreeMusic ();
 	CA_DownLevel ();
-	MM_SortMem ();
 }
 #endif
 
@@ -700,26 +668,14 @@
 //
 void EndText (void)
 {
-	s16int			artnum;
-	char far 	*text;
 	uchar *layout;
 
 
 	ClearMemory ();
-
 	CA_UpLevel ();
-	MM_SortMem ();
 
-	artnum = endextern+gamestate.episode;
-	CA_CacheGrChunk (artnum);
-	text = (char _seg *)grsegs[artnum];
-	MM_SetLock (&grsegs[artnum], true);
+	ShowArticle (epis+gamestate.episode);
 
-	ShowArticle (text);
-
-	MM_FreePtr (&grsegs[artnum]);
-
-
 	VW_FadeOut();
 	SETFONTCOLOR(0,15);
 	IN_ClearKeysDown();
@@ -726,7 +682,5 @@
 	if (MousePresent)
 		Mouse(MDelta);	// Clear accumulated mouse movement
 
-	FreeMusic ();
 	CA_DownLevel ();
-	MM_SortMem ();
 }
--- a/us.h
+++ b/us.h
@@ -99,8 +99,7 @@
 extern	int	US_UpdateCursor(void),
 				US_LineInput(s16int x,s16int y,char *buf,char *def,int escok,
 								s16int maxchars,s16int maxwidth);
-extern	s16int		US_CheckParm(char *parm,char **strings),
-				US_RndT(void);
+extern	s16int		US_RndT(void);
 
 		void	USL_PrintInCenter(char far *s,Rct r);
 		char 	*USL_GiveSaveName(u16int game);
--- a/us1.c
+++ b/us1.c
@@ -1,49 +1,8 @@
-//
-//	ID Engine
-//	ID_US_1.c - User Manager - General routines
-//	v1.1d1
-//	By Jason Blochowiak
-//	Hacked up for Catacomb 3D
-//
-
-//
-//	This module handles dealing with user input & feedback
-//
-//	Depends on: Input Mgr, View Mgr, some variables from the Sound, Caching,
-//		and Refresh Mgrs, Memory Mgr for background save/restore
-//
-//	Globals:
-//		ingame - Flag set by game indicating if a game is in progress
-//      abortgame - Flag set if the current game should be aborted (if a load
-//			game fails)
-//		loadedgame - Flag set if a game was loaded
-//		abortprogram - Normally nil, this points to a terminal error message
-//			if the program needs to abort
-//		restartgame - Normally set to gd_Continue, this is set to one of the
-//			difficulty levels if a new game should be started
-//		PrintX, PrintY - Where the User Mgr will print (global coords)
-//		WindowX,WindowY,WindowW,WindowH - The dimensions of the current
-//			window
-//
-
-#include "ID_HEADS.H"
-
-#pragma	hdrstop
-
-#pragma	warn	-pia
-
-
-//	Global variables
 		char		*abortprogram;
 		int		NoWait;
 		u16int		PrintX,PrintY;
 		u16int		WindowX,WindowY,WindowW,WindowH;
 
-//	Internal variables
-#define	ConfigVersion	1
-
-static	char		*ParmStrings[] = {"TEDLEVEL","NOWAIT"},
-					*ParmStrings2[] = {"COMP","NOCOMP"};
 static	int		US_Started;
 
 		int		Button0,Button1,
@@ -65,103 +24,8 @@
 						{"Jay Wilbur",10000,1},
 					};
 
-//	Internal routines
-
-//	Public routines
-
 ///////////////////////////////////////////////////////////////////////////
 //
-//	USL_HardError() - Handles the Abort/Retry/Fail sort of errors passed
-//			from DOS.
-//
-///////////////////////////////////////////////////////////////////////////
-#pragma	warn	-par
-#pragma	warn	-rch
-int
-USL_HardError(u16int errval,s16int ax,s16int bp,s16int si)
-{
-#define IGNORE  0
-#define RETRY   1
-#define	ABORT   2
-extern	void	ShutdownId(void);
-
-static	char		buf[32];
-static	WindowRec	wr;
-		s16int			di;
-		char		c,*s,*t;
-
-
-	di = _DI;
-
-	if (ax < 0)
-		s = "Device Error";
-	else
-	{
-		if ((di & 0x00ff) == 0)
-			s = "Drive ~ is Write Protected";
-		else
-			s = "Error on Drive ~";
-		for (t = buf;*s;s++,t++)	// Can't use sprintf()
-			if ((*t = *s) == '~')
-				*t = (ax & 0x00ff) + 'A';
-		*t = '\0';
-		s = buf;
-	}
-
-	c = peekb(0x40,0x49);	// Get the current screen mode
-	if ((c < 4) || (c == 7))
-		goto oh_kill_me;
-
-	// DEBUG - handle screen cleanup
-
-	US_SaveWindow(&wr);
-	US_CenterWindow(30,3);
-	US_CPrint(s);
-	US_CPrint("(R)etry or (A)bort?");
-	VW_UpdateScreen();
-	IN_ClearKeysDown();
-
-asm	sti	// Let the keyboard interrupts come through
-
-	while (true)
-	{
-		switch (IN_WaitForASCII())
-		{
-		case key_Escape:
-		case 'a':
-		case 'A':
-			goto oh_kill_me;
-			break;
-		case key_Return:
-		case key_Space:
-		case 'r':
-		case 'R':
-			US_ClearWindow();
-			VW_UpdateScreen();
-			US_RestoreWindow(&wr);
-			return(RETRY);
-			break;
-		}
-	}
-
-oh_kill_me:
-	abortprogram = s;
-	ShutdownId();
-	fprintf(stderr,"Terminal Error: %s\n",s);
-	if (tedlevel)
-		fprintf(stderr,"You launched from TED. I suggest that you reboot...\n");
-
-	return(ABORT);
-#undef	IGNORE
-#undef	RETRY
-#undef	ABORT
-}
-#pragma	warn	+par
-#pragma	warn	+rch
-
-
-///////////////////////////////////////////////////////////////////////////
-//
 //	US_Startup() - Starts the User Mgr
 //
 ///////////////////////////////////////////////////////////////////////////
@@ -168,46 +32,9 @@
 void
 US_Startup(void)
 {
-	s16int	i,n;
-
 	if (US_Started)
 		return;
-
-	harderr(USL_HardError);	// Install the fatal error handler
-
 	US_InitRndT(true);		// Initialize the random number generator
-
-	for (i = 1;i < _argc;i++)
-	{
-		switch (US_CheckParm(_argv[i],ParmStrings2))
-		{
-		case 0:
-			compatability = true;
-			break;
-		case 1:
-			compatability = false;
-			break;
-		}
-	}
-
-	// Check for TED launching here
-	for (i = 1;i < _argc;i++)
-	{
-		n = US_CheckParm(_argv[i],ParmStrings);
-		switch(n)
-		{
-		 case 0:
-		   tedlevelnum = atoi(_argv[i + 1]);
-		   if (tedlevelnum >= 0)
-		     tedlevel = true;
-		   break;
-
-		 case 1:
-		   NoWait = true;
-		   break;
-		}
-	}
-
 	US_Started = true;
 }
 
@@ -225,42 +52,6 @@
 
 	US_Started = false;
 }
-
-///////////////////////////////////////////////////////////////////////////
-//
-//	US_CheckParm() - checks to see if a string matches one of a set of
-//		strings. The check is case insensitive. The routine returns the
-//		index of the string that matched, or -1 if no matches were found
-//
-///////////////////////////////////////////////////////////////////////////
-int
-US_CheckParm(char *parm,char **strings)
-{
-	char	cp,cs,
-			*p,*s;
-	s16int		i;
-
-	while (!isalpha(*parm))	// Skip non-alphas
-		parm++;
-
-	for (i = 0;*strings && **strings;i++)
-	{
-		for (s = *strings++,p = parm,cs = cp = 0;cs == cp;)
-		{
-			cs = *s++;
-			if (!cs)
-				return(i);
-			cp = *p++;
-
-			if (isupper(cs))
-				cs = tolower(cs);
-			if (isupper(cp))
-				cp = tolower(cp);
-		}
-	}
-	return(-1);
-}
-
 
 //	Window/Printing routines
 
--- a/vh.c
+++ b/vh.c
@@ -1,23 +1,5 @@
-// ID_VH.C
-
-#include "ID_HEADS.H"
-
-#define	SCREENWIDTH		80
-#define CHARWIDTH		2
-#define TILEWIDTH		4
-#define GRPLANES		4
-#define BYTEPIXELS		4
-
-#define SCREENXMASK		(~3)
-#define SCREENXPLUS		(3)
-#define SCREENXDIV		(4)
-
-#define VIEWWIDTH		80
-
 #define PIXTOBLOCK		4		// 16 pixels to an update block
 
-#define UNCACHEGRCHUNK(chunk)	{MM_FreePtr(&grsegs[chunk]);grneeded[chunk]&=~ca_levelbit;}
-
 u8int	update[UPDATEHIGH][UPDATEWIDE];
 
 //==========================================================================
@@ -175,7 +157,7 @@
 	size = width*height;
 
 	if (width&3)
-		MS_Quit ("VL_MungePic: Not divisable by 4!");
+		Quit ("VL_MungePic: Not divisable by 4!");
 
 //
 // copy the pic to a temp buffer
@@ -216,13 +198,7 @@
 	VWL_MeasureString(string,width,height,(fontstruct _seg *)grsegs[STARTFONT+fontnumber]);
 }
 
-void	VW_MeasureMPropString  (char far *string, u16int *width, u16int *height)
-{
-	VWL_MeasureString(string,width,height,(fontstruct _seg *)grsegs[STARTFONTM+fontnumber]);
-}
 
-
-
 /*
 =============================================================================
 
@@ -294,13 +270,6 @@
 		LatchDrawChar(x,y,tile);
 }
 
-void VWB_DrawTile8M (s16int x, s16int y, s16int tile)
-{
-	if (VW_MarkUpdateBlock (x,y,x+7,y+7))
-		VL_MemToScreen (((u8int far *)grsegs[STARTTILE8M])+tile*64,8,8,x,y);
-}
-
-
 void VWB_DrawPic (s16int x, s16int y, s16int chunknum)
 {
 	s16int	picnum = chunknum - STARTPICS;
@@ -403,8 +372,8 @@
 //
 // tile 8s
 //
+	FIXME: fuck this
 	latchpics[0] = freelatch;
-	CA_CacheGrChunk (STARTTILE8);
 	src = (u8int _seg *)grsegs[STARTTILE8];
 	destoff = freelatch;
 
@@ -414,27 +383,8 @@
 		src += 64;
 		destoff +=16;
 	}
-	UNCACHEGRCHUNK (STARTTILE8);
 
-#if 0	// ran out of latch space!
 //
-// tile 16s
-//
-	src = (u8int _seg *)grsegs[STARTTILE16];
-	latchpics[1] = destoff;
-
-	for (i=0;i<NUMTILE16;i++)
-	{
-		CA_CacheGrChunk (STARTTILE16+i);
-		src = (u8int _seg *)grsegs[STARTTILE16+i];
-		VL_MemToLatch (src,16,16,destoff);
-		destoff+=64;
-		if (src)
-			UNCACHEGRCHUNK (STARTTILE16+i);
-	}
-#endif
-
-//
 // pics
 //
 	start = LATCHPICS_LUMP_START;
@@ -443,12 +393,10 @@
 	for (i=start;i<=end;i++)
 	{
 		latchpics[2+i-start] = destoff;
-		CA_CacheGrChunk (i);
 		width = pictable[i-STARTPICS].width;
 		height = pictable[i-STARTPICS].height;
 		VL_MemToLatch (grsegs[i],width,height,destoff);
 		destoff += width/4 *height;
-		UNCACHEGRCHUNK(i);
 	}
 
 	EGAMAPMASK(15);
--- a/vh.h
+++ b/vh.h
@@ -16,27 +16,9 @@
 
 typedef struct
 {
-  s16int	width,
-	height,
-	orgx,orgy,
-	xl,yl,xh,yh,
-	shifts;
-} spritetabletype;
-
-typedef	struct
-{
-	u16int	sourceoffset[MAXSHIFTS];
-	u16int	planesize[MAXSHIFTS];
-	u16int	width[MAXSHIFTS];
-	u8int		data[];
-} spritetype;		// the uchar* for each sprite points to this
-
-typedef struct
-{
 	s16int width,height;
 } pictabletype;
 
-
 typedef struct
 {
 	s16int height;
@@ -71,16 +53,9 @@
 //
 
 void VWB_DrawTile8 (s16int x, s16int y, s16int tile);
-void VWB_DrawTile8M (s16int x, s16int y, s16int tile);
-void VWB_DrawTile16 (s16int x, s16int y, s16int tile);
-void VWB_DrawTile16M (s16int x, s16int y, s16int tile);
 void VWB_DrawPic (s16int x, s16int y, s16int chunknum);
-void VWB_DrawMPic(s16int x, s16int y, s16int chunknum);
 void VWB_Bar (s16int x, s16int y, s16int width, s16int height, s16int color);
-
 void VWB_DrawPropString	 (char far *string);
-void VWB_DrawMPropString (char far *string);
-void VWB_DrawSprite (s16int x, s16int y, s16int chunknum);
 void VWB_Plot (s16int x, s16int y, s16int color);
 void VWB_Hlin (s16int x1, s16int x2, s16int y, s16int color);
 void VWB_Vlin (s16int y1, s16int y2, s16int x, s16int color);
@@ -93,8 +68,6 @@
 
 void VH_SetDefaultColors (void);
 
-#define VW_Startup		VL_Startup
-#define VW_Shutdown		VL_Shutdown
 #define VW_SetCRTC		VL_SetCRTC
 #define VW_SetScreen	VL_SetScreen
 #define VW_Bar			VL_Bar
@@ -113,11 +86,6 @@
 void	VW_MeasurePropString (char far *string, u16int *width, u16int *height);
 #define EGAMAPMASK(x)	VGAMAPMASK(x)
 #define EGAWRITEMODE(x)	VGAWRITEMODE(x)
-
-//#define VW_MemToScreen	VL_MemToLatch
-
-#define MS_Quit			Quit
-
 
 #define LatchDrawChar(x,y,p) VL_LatchToScreen(latchpics[0]+(p)*16,2,8,x,y)
 #define LatchDrawTile(x,y,p) VL_LatchToScreen(latchpics[1]+(p)*64,4,16,x,y)
--- a/vl.asm
+++ b/vl.asm
@@ -1,15 +1,8 @@
-; ID_VL.ASM
-
-	IDEAL
-	MODEL	MEDIUM,C
-
-	INCLUDE	'ID_VL.EQU'
-
 SCREENSEG	=	0a000h
 
 	DATASEG
 
-	EXTRN	TimeCount:WORD		; incremented every 70th of a second
+	EXTRN	TimeCount:WORD ; incremented every 70th of a second
 	EXTRN	linewidth:WORD
 
 starttime	dw	?
@@ -16,9 +9,6 @@
 
 	CODESEG
 
-;===========================================================================
-
-
 ;==============
 ;
 ; VL_WaitVBL			******** NEW *********
@@ -287,456 +277,3 @@
 	ret
 
 ENDP
-
-
-;===========================================================================
-
-
-	MASM
-;���������������������������������������������������������
-;
-; Name:	VL_VideoID
-;
-; Function:	Detects the presence of various video subsystems
-;
-; int VideoID;
-;
-; Subsystem ID values:
-; 	 0  = (none)
-; 	 1  = MDA
-; 	 2  = CGA
-; 	 3  = EGA
-; 	 4  = MCGA
-; 	 5  = VGA
-; 	80h = HGC
-; 	81h = HGC+
-; 	82h = Hercules InColor
-;
-;���������������������������������������������������������
-
-;���������������������������������������������������������
-;
-; Equates
-;
-;���������������������������������������������������������
-VIDstruct	STRUC		; corresponds to C data structure
-
-Video0Type	DB	?	; first subsystem type
-Display0Type	DB	? 	; display attached to first subsystem
-
-Video1Type	DB	?	; second subsystem type
-Display1Type	DB	?	; display attached to second subsystem
-
-VIDstruct	ENDS
-
-
-Device0	EQU	word ptr Video0Type[di]
-Device1	EQU	word ptr Video1Type[di]
-
-
-MDA	EQU	1	; subsystem types
-CGA	EQU	2
-EGA	EQU	3
-MCGA	EQU	4
-VGA	EQU	5
-HGC	EQU	80h
-HGCPlus	EQU	81h
-InColor	EQU	82h
-
-MDADisplay	EQU	1	; display types
-CGADisplay	EQU	2
-EGAColorDisplay	EQU	3
-PS2MonoDisplay	EQU	4
-PS2ColorDisplay	EQU	5
-
-TRUE	EQU	1
-FALSE	EQU	0
-
-;���������������������������������������������������������
-;
-; Program
-;
-;���������������������������������������������������������
-
-Results	VIDstruct <>	;results go here!
-
-EGADisplays	DB	CGADisplay	; 0000b, 0001b	(EGA switch values)
-	DB	EGAColorDisplay	; 0010b, 0011b
-	DB	MDADisplay	; 0100b, 0101b
-	DB	CGADisplay	; 0110b, 0111b
-	DB	EGAColorDisplay	; 1000b, 1001b
-	DB	MDADisplay	; 1010b, 1011b
-
-DCCtable	DB	0,0	; translate table for INT 10h func 1Ah
-	DB	MDA,MDADisplay
-	DB	CGA,CGADisplay
-	DB	0,0
-	DB	EGA,EGAColorDisplay
-	DB	EGA,MDADisplay
-	DB	0,0
-	DB	VGA,PS2MonoDisplay
-	DB	VGA,PS2ColorDisplay
-	DB	0,0
-	DB	MCGA,EGAColorDisplay
-	DB	MCGA,PS2MonoDisplay
-	DB	MCGA,PS2ColorDisplay
-
-TestSequence	DB	TRUE	; this list of flags and addresses
-	DW	FindPS2	;  determines the order in which this
-			;  program looks for the various
-EGAflag	DB	?	;  subsystems
-	DW	FindEGA
-
-CGAflag	DB	?
-	DW	FindCGA
-
-Monoflag	DB	?
-	DW	FindMono
-
-NumberOfTests	EQU	($-TestSequence)/3
-
-
-PUBLIC	VL_VideoID
-VL_VideoID	PROC
-
-	push	bp	; preserve caller registers
-	mov	bp,sp
-	push	ds
-	push	si
-	push	di
-
-	push	cs
-	pop	ds
-	ASSUME	DS:@Code
-
-; initialize the data structure that will contain the results
-
-	lea	di,Results	; DS:DI -> start of data structure
-
-	mov	Device0,0	; zero these variables
-	mov	Device1,0
-
-; look for the various subsystems using the subroutines whose addresses are
-; tabulated in TestSequence; each subroutine sets flags in TestSequence
-; to indicate whether subsequent subroutines need to be called
-
-	mov	byte ptr CGAflag,TRUE
-	mov	byte ptr EGAflag,TRUE
-	mov	byte ptr Monoflag,TRUE
-
-	mov	cx,NumberOfTests
-	mov	si,offset TestSequence
-
-@@L01:	lodsb		; AL := flag
-	test	al,al
-	lodsw		; AX := subroutine address
-	jz	@@L02	; skip subroutine if flag is false
-
-	push	si
-	push	cx
-	call	ax	; call subroutine to detect subsystem
-	pop	cx
-	pop	si
-
-@@L02:	loop	@@L01
-
-; determine which subsystem is active
-
-	call	FindActive
-
-	mov	al,Results.Video0Type
-	mov	ah,0	; was:  Results.Display0Type
-
-	pop	di	; restore caller registers and return
-	pop	si
-	pop	ds
-	mov	sp,bp
-	pop	bp
-	ret
-
-VL_VideoID	ENDP
-
-
-;
-; FindPS2
-;
-; This subroutine uses INT 10H function 1Ah to determine the video BIOS
-; Display Combination Code (DCC) for each video subsystem present.
-;
-
-FindPS2	PROC	near
-
-	mov	ax,1A00h
-	int	10h	; call video BIOS for info
-
-	cmp	al,1Ah
-	jne	@@L13	; exit if function not supported (i.e.,
-			;  no MCGA or VGA in system)
-
-; convert BIOS DCCs into specific subsystems & displays
-
-	mov	cx,bx
-	xor	bh,bh	; BX := DCC for active subsystem
-
-	or	ch,ch
-	jz	@@L11	; jump if only one subsystem present
-
-	mov	bl,ch	; BX := inactive DCC
-	add	bx,bx
-	mov	ax,[bx+offset DCCtable]
-
-	mov	Device1,ax
-
-	mov	bl,cl
-	xor	bh,bh	; BX := active DCC
-
-@@L11:	add	bx,bx
-	mov	ax,[bx+offset DCCtable]
-
-	mov	Device0,ax
-
-; reset flags for subsystems that have been ruled out
-
-	mov	byte ptr CGAflag,FALSE
-	mov	byte ptr EGAflag,FALSE
-	mov	byte ptr Monoflag,FALSE
-
-	lea	bx,Video0Type[di]  ; if the BIOS reported an MDA ...
-	cmp	byte ptr [bx],MDA
-	je	@@L12
-
-	lea	bx,Video1Type[di]
-	cmp	byte ptr [bx],MDA
-	jne	@@L13
-
-@@L12:	mov	word ptr [bx],0    ; ... Hercules can't be ruled out
-	mov	byte ptr Monoflag,TRUE
-
-@@L13:	ret
-
-FindPS2	ENDP
-
-
-;
-; FindEGA
-;
-; Look for an EGA.  This is done by making a call to an EGA BIOS function
-;  which doesn't exist in the default (MDA, CGA) BIOS.
-
-FindEGA	PROC	near	; Caller:	AH = flags
-			; Returns:	AH = flags
-			;		Video0Type and
-			;		 Display0Type updated
-
-	mov	bl,10h	; BL := 10h (return EGA info)
-	mov	ah,12h	; AH := INT 10H function number
-	int	10h	; call EGA BIOS for info
-			; if EGA BIOS is present,
-			;  BL <> 10H
-			;  CL = switch setting
-	cmp	bl,10h
-	je	@@L22	; jump if EGA BIOS not present
-
-	mov	al,cl
-	shr	al,1	; AL := switches/2
-	mov	bx,offset EGADisplays
-	xlat		; determine display type from switches
-	mov	ah,al	; AH := display type
-	mov	al,EGA	; AL := subystem type
-	call	FoundDevice
-
-	cmp	ah,MDADisplay
-	je	@@L21	; jump if EGA has a monochrome display
-
-	mov	CGAflag,FALSE	; no CGA if EGA has color display
-	jmp	short @@L22
-
-@@L21:	mov	Monoflag,FALSE	; EGA has a mono display, so MDA and
-			;  Hercules are ruled out
-@@L22:	ret
-
-FindEGA	ENDP
-
-;
-; FindCGA
-;
-; This is done by looking for the CGA's 6845 CRTC at I/O port 3D4H.
-;
-FindCGA	PROC	near	; Returns:	VIDstruct updated
-
-	mov	dx,3D4h	; DX := CRTC address port
-	call	Find6845
-	jc	@@L31	; jump if not present
-
-	mov	al,CGA
-	mov	ah,CGADisplay
-	call	FoundDevice
-
-@@L31:	ret
-
-FindCGA	ENDP
-
-;
-; FindMono
-;
-; This is done by looking for the MDA's 6845 CRTC at I/O port 3B4H.  If
-; a 6845 is found, the subroutine distinguishes between an MDA
-; and a Hercules adapter by monitoring bit 7 of the CRT Status byte.
-; This bit changes on Hercules adapters but does not change on an MDA.
-;
-; The various Hercules adapters are identified by bits 4 through 6 of
-; the CRT Status value:
-;
-; 000b = HGC
-; 001b = HGC+
-; 101b = InColor card
-;
-
-FindMono	PROC	near	; Returns:	VIDstruct updated
-
-	mov	dx,3B4h	; DX := CRTC address port
-	call	Find6845
-	jc	@@L44	; jump if not present
-
-	mov	dl,0BAh	; DX := 3BAh (status port)
-	in	al,dx
-	and	al,80h
-	mov	ah,al	; AH := bit 7 (vertical sync on HGC)
-
-	mov	cx,8000h	; do this 32768 times
-@@L41:	in	al,dx
-	and	al,80h	; isolate bit 7
-	cmp	ah,al
-	loope	@@L41	; wait for bit 7 to change
-	jne	@@L42	; if bit 7 changed, it's a Hercules
-
-	mov	al,MDA	; if bit 7 didn't change, it's an MDA
-	mov	ah,MDADisplay
-	call	FoundDevice
-	jmp	short @@L44
-
-@@L42:	in	al,dx
-	mov	dl,al	; DL := value from status port
-	and	dl,01110000b	; mask bits 4 thru 6
-
-	mov	ah,MDADisplay	; assume it's a monochrome display
-
-	mov	al,HGCPlus	; look for an HGC+
-	cmp	dl,00010000b
-	je	@@L43	; jump if it's an HGC+
-
-	mov	al,HGC	; look for an InColor card or HGC
-	cmp	dl,01010000b
-	jne	@@L43	; jump if it's not an InColor card
-
-	mov	al,InColor	; it's an InColor card
-	mov	ah,EGAColorDisplay
-
-@@L43:	call	FoundDevice
-
-@@L44:	ret
-
-FindMono	ENDP
-
-;
-; Find6845
-;
-; This routine detects the presence of the CRTC on a MDA, CGA or HGC.
-; The technique is to write and read register 0Fh of the chip (cursor
-; low).  If the same value is read as written, assume the chip is
-; present at the specified port addr.
-;
-
-Find6845	PROC	near	; Caller:  DX = port addr
-			; Returns: cf set if not present
-	mov	al,0Fh
-	out	dx,al	; select 6845 reg 0Fh (Cursor Low)
-	inc	dx
-	in	al,dx	; AL := current Cursor Low value
-	mov	ah,al	; preserve in AH
-	mov	al,66h	; AL := arbitrary value
-	out	dx,al	; try to write to 6845
-
-	mov	cx,100h
-@@L51:	loop	@@L51	; wait for 6845 to respond
-
-	in	al,dx
-	xchg	ah,al	; AH := returned value
-			; AL := original value
-	out	dx,al	; restore original value
-
-	cmp	ah,66h	; test whether 6845 responded
-	je	@@L52	; jump if it did (cf is reset)
-
-	stc		; set carry flag if no 6845 present
-
-@@L52:	ret
-
-Find6845	ENDP
-
-
-;
-; FindActive
-;
-; This subroutine stores the currently active device as Device0.  The
-; current video mode determines which subsystem is active.
-;
-
-FindActive	PROC	near
-
-	cmp	word ptr Device1,0
-	je	@@L63	; exit if only one subsystem
-
-	cmp	Video0Type[di],4	; exit if MCGA or VGA present
-	jge	@@L63	;  (INT 10H function 1AH
-	cmp	Video1Type[di],4	;  already did the work)
-	jge	@@L63
-
-	mov	ah,0Fh
-	int	10h	; AL := current BIOS video mode
-
-	and	al,7
-	cmp	al,7	; jump if monochrome
-	je	@@L61	;  (mode 7 or 0Fh)
-
-	cmp	Display0Type[di],MDADisplay
-	jne	@@L63	; exit if Display0 is color
-	jmp	short @@L62
-
-@@L61:	cmp	Display0Type[di],MDADisplay
-	je	@@L63	; exit if Display0 is monochrome
-
-@@L62:	mov	ax,Device0	; make Device0 currently active
-	xchg	ax,Device1
-	mov	Device0,ax
-
-@@L63:	ret
-
-FindActive	ENDP
-
-
-;
-; FoundDevice
-;
-; This routine updates the list of subsystems.
-;
-
-FoundDevice	PROC	near	; Caller:    AH = display #
-			;	     AL = subsystem #
-			; Destroys:  BX
-	lea	bx,Video0Type[di]
-	cmp	byte ptr [bx],0
-	je	@@L71	; jump if 1st subsystem
-
-	lea	bx,Video1Type[di]	; must be 2nd subsystem
-
-@@L71:	mov	[bx],ax	; update list entry
-	ret
-
-FoundDevice	ENDP
-
-IDEAL
-
-
-
-END
--- a/vl.c
+++ b/vl.c
@@ -1,17 +1,3 @@
-// ID_VL.C
-
-#include <dos.h>
-#include <alloc.h>
-#include <mem.h>
-#include <string.h>
-#include "ID_HEADS.H"
-#include "ID_VL.H"
-#pragma hdrstop
-
-//
-// SC_INDEX is expected to stay at SC_MAPMASK for proper operation
-//
-
 u16int	bufferofs;
 u16int	displayofs,pelpan;
 
@@ -30,83 +16,11 @@
 //===========================================================================
 
 // asm
-
-s16int	 VL_VideoID (void);
 void VL_SetCRTC (s16int crtc);
-void VL_SetScreen (s16int crtc, s16int pelpan);
-void VL_WaitVBL (s16int vbls);
 
-//===========================================================================
-
-
 /*
 =======================
 =
-= VL_Startup
-=
-=======================
-*/
-
-#if 0
-void	VL_Startup (void)
-{
-	if ( !MS_CheckParm ("HIDDENCARD") && VL_VideoID () != 5)
-		MS_Quit ("You need a VGA graphics card to run this!");
-
-	asm	cld;				// all string instructions assume forward
-}
-
-#endif
-
-/*
-=======================
-=
-= VL_Startup	// WOLFENSTEIN HACK
-=
-=======================
-*/
-
-static	char *ParmStrings[] = {"HIDDENCARD",""};
-
-void	VL_Startup (void)
-{
-	s16int i,videocard;
-
-	asm	cld;
-
-	videocard = VL_VideoID ();
-	for (i = 1;i < _argc;i++)
-		if (US_CheckParm(_argv[i],ParmStrings) == 0)
-		{
-			videocard = 5;
-			break;
-		}
-
-	if (videocard != 5)
-Quit ("Improper video card!  If you really have a VGA card that I am not \n"
-	  "detecting, use the -HIDDENCARD command line parameter!");
-
-}
-
-
-
-/*
-=======================
-=
-= VL_Shutdown
-=
-=======================
-*/
-
-void	VL_Shutdown (void)
-{
-	VL_SetTextMode ();
-}
-
-
-/*
-=======================
-=
 = VL_SetVGAPlaneMode
 =
 =======================
@@ -119,21 +33,6 @@
 	VL_DePlaneVGA ();
 	VGAMAPMASK(15);
 	VL_SetLineWidth (40);
-}
-
-
-/*
-=======================
-=
-= VL_SetTextMode
-=
-=======================
-*/
-
-void	VL_SetTextMode (void)
-{
-asm	mov	ax,3
-asm	int	0x10
 }
 
 //===========================================================================
--- a/vl.h
+++ b/vl.h
@@ -1,14 +1,3 @@
-// ID_VL.H
-
-// wolf compatability
-
-#define MS_Quit	Quit
-
-void Quit (char *error);
-
-//===========================================================================
-
-
 #define SC_INDEX			0x3C4
 #define SC_RESET			0
 #define SC_CLOCK			1
@@ -76,7 +65,6 @@
 #define SCREENWIDTH		80			// default screen width in bytes
 #define MAXSCANLINES	200			// size of ylookup table
 
-#define CHARWIDTH		2
 #define TILEWIDTH		4
 
 //===========================================================================
@@ -113,12 +101,7 @@
 #define VGAMAPMASK(x) asm{cli;mov dx,SC_INDEX;mov al,SC_MAPMASK;mov ah,x;out dx,ax;sti;}
 #define VGAREADMAP(x) asm{cli;mov dx,GC_INDEX;mov al,GC_READMAP;mov ah,x;out dx,ax;sti;}
 
-
-void VL_Startup (void);
-void VL_Shutdown (void);
-
 void VL_SetVGAPlane (void);
-void VL_SetTextMode (void);
 void VL_DePlaneVGA (void);
 void VL_SetVGAPlaneMode (void);
 void VL_ClearVideo (u8int color);
--- /dev/null
+++ b/wl3d.c
@@ -1,0 +1,62 @@
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
+#include "dat.h"
+#include "fns.h"
+
+mainstacksize = 16*1024;
+char *ext = "wl6";
+int debug;
+int skipintro;
+
+void *
+emalloc(ulong n)
+{
+	void *p;
+
+	p = mallocz(n, 1);
+	if(p == nil)
+		sysfatal("emalloc: %r");
+	return p;
+}
+
+/* use only for shortening buffers, no zeroing done */
+void *
+erealloc(void *p, ulong n)
+{
+	p = realloc(p, n);
+	if(p == nil)
+		sysfatal("erealloc: %r");
+	return p;
+}
+
+static void
+usage(void)
+{
+	fprint(2, "usage: %s [-23Ddios] [-m dir] [-w map] [-x difficulty]\n", argv0);
+	threadexits("usage");
+}
+
+void
+threadmain(int argc, char **argv)
+{
+	char *datdir = "/sys/games/lib/wl3d/";
+
+	ARGBEGIN{
+	case '2': ext = "sd2"; break;
+	case '3': ext = "sd3"; break;
+	case 'D': debug++; break;
+	case 'd': ext = "wl1"; break;
+	case 'i': skipintro++; break;
+	case 'm': datdir = EARGF(usage()); break;
+	case 'o': ext = "sdm"; break;
+	case 's': ext = "sod"; break;
+	case 'w': /* TODO: warp to ep, level */ break;
+	case 'x': /* TODO: set difficulty for warp */ break;
+	default:
+		usage();
+	}ARGEND;
+	dat(datdir);
+
+	threadexitsall(nil);
+}