shithub: duke3d

Download patch

ref: d795e124e7a097d8ece2e2433729535b3b1bbee7
parent: 7c2fc91403ac7c88ef4a1b0707d1568add0f6d0f
author: Fabien Sanglard <[email protected]>
date: Thu Dec 13 13:00:49 EST 2012

Completed removal of 'long' from Engine.

--- a/Engine/src/build.h
+++ b/Engine/src/build.h
@@ -8,6 +8,8 @@
 #ifndef _INCLUDE_BUILD_H_
 #define _INCLUDE_BUILD_H_
 
+#include <inttypes.h>
+
 #define MAXSECTORS 1024
 #define MAXWALLS 8192
 #define MAXSPRITES 4096
@@ -64,7 +66,7 @@
 typedef struct
 {
 	short wallptr, wallnum;
-	long ceilingz, floorz;
+	int32_t ceilingz, floorz;
 	short ceilingstat, floorstat;
 	short ceilingpicnum, ceilingheinum;
 	signed char ceilingshade;
@@ -94,7 +96,7 @@
 	/* 32 bytes */
 typedef struct
 {
-	long x, y;
+	int32_t x, y;
 	short point2, nextwall, nextsector, cstat;
 	short picnum, overpicnum;
 	signed char shade;
@@ -123,7 +125,7 @@
 	/* 44 bytes */
 typedef struct
 {
-	long x, y, z;
+	int32_t x, y, z;
 	short cstat, picnum;
 	signed char shade;
 	unsigned char pal, clipdist, filler;
@@ -146,29 +148,29 @@
 
 EXTERN unsigned short mapCRC;
 
-EXTERN long spritesortcnt;
+EXTERN int32_t spritesortcnt;
 EXTERN spritetype tsprite[MAXSPRITESONSCREEN];
 
 EXTERN char vidoption;
-EXTERN long xdim, ydim, ylookup[MAXYDIM+1], numpages;
-EXTERN long yxaspect, viewingrange;
+EXTERN int32_t xdim, ydim, ylookup[MAXYDIM+1], numpages;
+EXTERN int32_t yxaspect, viewingrange;
 
-EXTERN long validmodecnt;
+EXTERN int32_t validmodecnt;
 EXTERN short validmode[256];
-EXTERN long validmodexdim[256], validmodeydim[256];
+EXTERN int32_t validmodexdim[256], validmodeydim[256];
 
 EXTERN short numsectors, numwalls;
-EXTERN volatile long totalclock;
-EXTERN long numframes, randomseed;
+EXTERN volatile int32_t totalclock;
+EXTERN int32_t numframes, randomseed;
 EXTERN short sintable[2048];
 EXTERN unsigned char palette[768];
 EXTERN short numpalookups;
 EXTERN char *palookup[MAXPALOOKUPS];
 EXTERN char parallaxtype, showinvisibility;
-EXTERN long parallaxyoffs, parallaxyscale;
-EXTERN long visibility, parallaxvisibility;
+EXTERN int32_t parallaxyoffs, parallaxyscale;
+EXTERN int32_t visibility, parallaxvisibility;
 
-EXTERN long windowx1, windowy1, windowx2, windowy2;
+EXTERN int32_t windowx1, windowy1, windowx2, windowy2;
 EXTERN short startumost[MAXXDIM], startdmost[MAXXDIM];
 
 EXTERN short pskyoff[MAXPSKYTILES], pskybits;
@@ -179,7 +181,7 @@
 
 EXTERN short tilesizx[MAXTILES], tilesizy[MAXTILES];
 EXTERN char walock[MAXTILES];
-EXTERN long numtiles, picanm[MAXTILES], waloff[MAXTILES];
+EXTERN int32_t numtiles, picanm[MAXTILES], waloff[MAXTILES];
 
     /*
 	 * These variables are for auto-mapping with the draw2dscreen function.
--- a/Engine/src/cache1d.c
+++ b/Engine/src/cache1d.c
@@ -34,12 +34,12 @@
  *   To use this module, here's all you need to do:
  *
  *   Step 1: Allocate a nice BIG buffer, like from 1MB-4MB and
- *           Call initcache(long cachestart, long cachesize) where
+ *           Call initcache(int32_t cachestart, int32_t cachesize) where
  *
  *              cachestart = (long)(pointer to start of BIG buffer)
  *              cachesize = length of BIG buffer
  *
- *   Step 2: Call allocache(long *bufptr, long bufsiz, char *lockptr)
+ *   Step 2: Call allocache(int32_t *bufptr, int32_t bufsiz, char *lockptr)
  *              whenever you need to allocate a buffer, where:
  *
  *              *bufptr = pointer to 4-byte pointer to buffer
@@ -61,20 +61,20 @@
 
 #define MAXCACHEOBJECTS 9216
 
-static long cachesize = 0;
-long cachecount = 0;
+static int32_t cachesize = 0;
+int32_t cachecount = 0;
 unsigned char zerochar = 0;
-long cachestart = 0, cacnum = 0, agecount = 0;
-typedef struct { long *hand, leng; unsigned char *lock; } cactype;
+int32_t cachestart = 0, cacnum = 0, agecount = 0;
+typedef struct { int32_t *hand, leng; unsigned char *lock; } cactype;
 cactype cac[MAXCACHEOBJECTS];
-long lockrecip[200];
+int32_t lockrecip[200];
 
 // TC game directory
 char game_dir[512] = { '\0' };
 
-void initcache(long dacachestart, long dacachesize)
+void initcache(int32_t dacachestart, int32_t dacachesize)
 {
-	long i;
+	int32_t i;
 
 	for(i=1;i<200;i++) lockrecip[i] = (1<<28)/(200-i);
 
@@ -86,9 +86,9 @@
 	cacnum = 1;
 }
 
-void allocache (long *newhandle, long newbytes, unsigned char *newlockptr)
+void allocache (int32_t *newhandle, int32_t newbytes, unsigned char *newlockptr)
 {
-	long i, z, zz, bestz=0, daval, bestval, besto=0, o1, o2, sucklen, suckz;
+	int32_t i, z, zz, bestz=0, daval, bestval, besto=0, o1, o2, sucklen, suckz;
 
 	newbytes = ((newbytes+15)&0xfffffff0);
 
@@ -163,9 +163,9 @@
 	cac[bestz].lock = &zerochar;
 }
 
-void suckcache (long *suckptr)
+void suckcache (int32_t *suckptr)
 {
-	long i;
+	int32_t i;
 
 		/* Can't exit early, because invalid pointer might be same even though lock = 0 */
 	for(i=0;i<cacnum;i++)
@@ -191,7 +191,7 @@
 
 void agecache(void)
 {
-	long cnt;
+	int32_t cnt;
 	char ch;
 
 	if (agecount >= cacnum) agecount = cacnum-1;
@@ -209,7 +209,7 @@
 
 void reportandexit(char *errormessage)
 {
-	long i, j;
+	int32_t i, j;
 
 	setvmode(0x3);
 	j = 0;
@@ -249,18 +249,18 @@
 	0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,
 };
 
-long numgroupfiles = 0;			// number of GRP files actually used.
-long gnumfiles[MAXGROUPFILES];	// number of files on grp
-long groupfil[MAXGROUPFILES] = {-1,-1,-1,-1}; // grp file handles
-long groupfilpos[MAXGROUPFILES];
+int32_t numgroupfiles = 0;			// number of GRP files actually used.
+int32_t gnumfiles[MAXGROUPFILES];	// number of files on grp
+int32_t groupfil[MAXGROUPFILES] = {-1,-1,-1,-1}; // grp file handles
+int32_t groupfilpos[MAXGROUPFILES];
 char *gfilelist[MAXGROUPFILES];	// name list + size list of all the files in grp
-long *gfileoffs[MAXGROUPFILES];	// offset of the files
+int32_t *gfileoffs[MAXGROUPFILES];	// offset of the files
 char *groupfil_memory[MAXGROUPFILES]; // addresses of raw GRP files in memory
-long groupefil_crc32[MAXGROUPFILES];
+int32_t groupefil_crc32[MAXGROUPFILES];
 
 unsigned char filegrp[MAXOPENFILES];
-long filepos[MAXOPENFILES];
-long filehan[MAXOPENFILES] =
+int32_t filepos[MAXOPENFILES];
+int32_t filehan[MAXOPENFILES] =
 {
 	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
 	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
@@ -283,7 +283,7 @@
 #endif
 
 
-long initgroupfile(const char *filename)
+int32_t initgroupfile(const char *filename)
 {
 #if (defined USE_PHYSICSFS)
     static int initted_physfs = 0;
@@ -309,7 +309,7 @@
     return(1); /* uhh...? */
 #else
 	char buf[16];
-	long i, j, k;
+	int32_t i, j, k;
 
 	printf("Loading %s ...\n", filename);
 
@@ -341,11 +341,11 @@
 		//group file is just the raw data packed one after the other in the same order as the list 
 		//of files. - ken
 
-		gnumfiles[numgroupfiles] = BUILDSWAP_INTEL32(*((long *)&buf[12]));
+		gnumfiles[numgroupfiles] = BUILDSWAP_INTEL32(*((int32_t *)&buf[12]));
 
 		if ((gfilelist[numgroupfiles] = (char *)kmalloc(gnumfiles[numgroupfiles]<<4)) == 0)
 			{ Error(EXIT_FAILURE, "Not enough memory for file grouping system\n"); }
-		if ((gfileoffs[numgroupfiles] = (long *)kmalloc((gnumfiles[numgroupfiles]+1)<<2)) == 0)
+		if ((gfileoffs[numgroupfiles] = (int32_t *)kmalloc((gnumfiles[numgroupfiles]+1)<<2)) == 0)
 			{ Error(EXIT_FAILURE, "Not enough memory for file grouping system\n"); }
 
 		// load index (name+size)
@@ -354,7 +354,7 @@
 		j = 0;
 		for(i=0;i<gnumfiles[numgroupfiles];i++)
 		{
-			k = BUILDSWAP_INTEL32(*((long *)&gfilelist[numgroupfiles][(i<<4)+12])); // get size
+			k = BUILDSWAP_INTEL32(*((int32_t *)&gfilelist[numgroupfiles][(i<<4)+12])); // get size
 			gfilelist[numgroupfiles][(i<<4)+12] = 0;
 			gfileoffs[numgroupfiles][i] = j; // absolute offset list of all files. 0 for 1st file
 			j += k;
@@ -393,7 +393,7 @@
     PHYSFS_deinit();
     memset(filehan, '\0', sizeof (filehan));
 #else
-	long i;
+	int32_t i;
 
 	for(i=numgroupfiles-1;i>=0;i--)
 		if (groupfil[i] != -1)
@@ -555,7 +555,7 @@
       return (crc);
 }
 
-long kopen4load(const char *filename, int readfromGRP)
+int32_t kopen4load(const char *filename, int readfromGRP)
 { // FIX_00072: all files are now 1st searched in Duke's root folder and then in the GRP.
 #if (defined USE_PHYSICSFS)
     int i;
@@ -582,7 +582,7 @@
     PHYSFS_close(rc);  /* oh well. */
     return(-1);
 #else
-	long i, j, k, fil, newhandle;
+	int32_t i, j, k, fil, newhandle;
 	unsigned char bad;
 	char *gfileptr;
 
@@ -634,13 +634,13 @@
 #endif
 }
 
-long kread(long handle, void *buffer, long leng)
+int32_t kread(int32_t handle, void *buffer, int32_t leng)
 {
 #if (defined USE_PHYSICSFS)
     return(PHYSFS_read(filehan[handle], buffer, 1, leng));
 return(leng);
 #else
-	long i, filenum, groupnum;
+	int32_t i, filenum, groupnum;
 
 	filenum = filehan[handle];
 	groupnum = filegrp[handle];
@@ -669,7 +669,7 @@
 #endif
 }
 
-int kread16(long handle, short *buffer)
+int kread16(int32_t handle, short *buffer)
 {
     if (kread(handle, buffer, 2) != 2)
         return(0);
@@ -678,7 +678,7 @@
     return(1);
 }
 
-int kread32(long handle, long *buffer)
+int kread32(int32_t handle, int32_t *buffer)
 {
     if (kread(handle, buffer, 4) != 4)
         return(0);
@@ -687,7 +687,7 @@
     return(1);
 }
 
-int kread8(long handle, char *buffer)
+int kread8(int32_t handle, char *buffer)
 {
     if (kread(handle, buffer, 1) != 1)
         return(0);
@@ -695,7 +695,7 @@
     return(1);
 }
 
-long klseek(long handle, long offset, long whence)
+int32_t klseek(int32_t handle, int32_t offset, int32_t whence)
 {
 #if (defined USE_PHYSICSFS)
     if (whence == SEEK_END)  /* !!! FIXME: You can try PHYSFS_filelength(). */
@@ -711,7 +711,7 @@
 
     return(offset);
 #else
-	long i, groupnum;
+	int32_t i, groupnum;
 
 	groupnum = filegrp[handle];
 
@@ -733,7 +733,7 @@
 }
 
 #ifdef __APPLE__
-long filelength(long fd)
+int32_t filelength(int32_t fd)
 {
     struct stat stats;
     fstat(fd, &stats);
@@ -741,12 +741,12 @@
 }
 #endif
 
-long kfilelength(long handle)
+int32_t kfilelength(int32_t handle)
 {
 #if (defined USE_PHYSICSFS)
     return(PHYSFS_fileLength(filehan[handle]));
 #else
-	long i, groupnum;
+	int32_t i, groupnum;
 
 	groupnum = filegrp[handle];
 	if (groupnum == 255) return(filelength(filehan[handle]));
@@ -755,7 +755,7 @@
 #endif
 }
 
-void kclose(long handle)
+void kclose(int32_t handle)
 {
 #if (defined USE_PHYSICSFS)
     if (filehan[handle] != NULL)
@@ -779,19 +779,19 @@
 static unsigned char lzwbuflock[5];
 static short *lzwbuf2, *lzwbuf3;
 
-void kdfread(void *buffer, size_t dasizeof, size_t count, long fil)
+void kdfread(void *buffer, size_t dasizeof, size_t count, int32_t fil)
 {
 	size_t i, j;
-	long k, kgoal;
+	int32_t k, kgoal;
 	short leng;
 	char *ptr;
 
 	lzwbuflock[0] = lzwbuflock[1] = lzwbuflock[2] = lzwbuflock[3] = lzwbuflock[4] = 200;
-	if (lzwbuf1 == NULL) allocache((long *)&lzwbuf1,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[0]);
-	if (lzwbuf2 == NULL) allocache((long *)&lzwbuf2,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[1]);
-	if (lzwbuf3 == NULL) allocache((long *)&lzwbuf3,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[2]);
-	if (lzwbuf4 == NULL) allocache((long *)&lzwbuf4,LZWSIZE,&lzwbuflock[3]);
-	if (lzwbuf5 == NULL) allocache((long *)&lzwbuf5,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[4]);
+	if (lzwbuf1 == NULL) allocache((int32_t *)&lzwbuf1,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[0]);
+	if (lzwbuf2 == NULL) allocache((int32_t *)&lzwbuf2,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[1]);
+	if (lzwbuf3 == NULL) allocache((int32_t *)&lzwbuf3,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[2]);
+	if (lzwbuf4 == NULL) allocache((int32_t *)&lzwbuf4,LZWSIZE,&lzwbuflock[3]);
+	if (lzwbuf5 == NULL) allocache((int32_t *)&lzwbuf5,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[4]);
 
 	if (dasizeof > LZWSIZE) { count *= dasizeof; dasizeof = 1; }
 	ptr = (char *)buffer;
@@ -820,16 +820,16 @@
 void dfread(void *buffer, size_t dasizeof, size_t count, FILE *fil)
 {
 	size_t i, j;
-	long k, kgoal;
+	int32_t k, kgoal;
 	short leng;
 	char *ptr;
 
 	lzwbuflock[0] = lzwbuflock[1] = lzwbuflock[2] = lzwbuflock[3] = lzwbuflock[4] = 200;
-	if (lzwbuf1 == NULL) allocache((long *)&lzwbuf1,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[0]);
-	if (lzwbuf2 == NULL) allocache((long *)&lzwbuf2,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[1]);
-	if (lzwbuf3 == NULL) allocache((long *)&lzwbuf3,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[2]);
-	if (lzwbuf4 == NULL) allocache((long *)&lzwbuf4,LZWSIZE,&lzwbuflock[3]);
-	if (lzwbuf5 == NULL) allocache((long *)&lzwbuf5,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[4]);
+	if (lzwbuf1 == NULL) allocache((int32_t *)&lzwbuf1,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[0]);
+	if (lzwbuf2 == NULL) allocache((int32_t *)&lzwbuf2,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[1]);
+	if (lzwbuf3 == NULL) allocache((int32_t *)&lzwbuf3,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[2]);
+	if (lzwbuf4 == NULL) allocache((int32_t *)&lzwbuf4,LZWSIZE,&lzwbuflock[3]);
+	if (lzwbuf5 == NULL) allocache((int32_t *)&lzwbuf5,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[4]);
 
 	if (dasizeof > LZWSIZE) { count *= dasizeof; dasizeof = 1; }
 	ptr = (char *)buffer;
@@ -861,11 +861,11 @@
 	char *ptr;
 
 	lzwbuflock[0] = lzwbuflock[1] = lzwbuflock[2] = lzwbuflock[3] = lzwbuflock[4] = 200;
-	if (lzwbuf1 == NULL) allocache((long *)&lzwbuf1,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[0]);
-	if (lzwbuf2 == NULL) allocache((long *)&lzwbuf2,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[1]);
-	if (lzwbuf3 == NULL) allocache((long *)&lzwbuf3,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[2]);
-	if (lzwbuf4 == NULL) allocache((long *)&lzwbuf4,LZWSIZE,&lzwbuflock[3]);
-	if (lzwbuf5 == NULL) allocache((long *)&lzwbuf5,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[4]);
+	if (lzwbuf1 == NULL) allocache((int32_t *)&lzwbuf1,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[0]);
+	if (lzwbuf2 == NULL) allocache((int32_t *)&lzwbuf2,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[1]);
+	if (lzwbuf3 == NULL) allocache((int32_t *)&lzwbuf3,(LZWSIZE+(LZWSIZE>>4))*2,&lzwbuflock[2]);
+	if (lzwbuf4 == NULL) allocache((int32_t *)&lzwbuf4,LZWSIZE,&lzwbuflock[3]);
+	if (lzwbuf5 == NULL) allocache((int32_t *)&lzwbuf5,LZWSIZE+(LZWSIZE>>4),&lzwbuflock[4]);
 
 	if (dasizeof > LZWSIZE) { count *= dasizeof; dasizeof = 1; }
 	ptr = (char *)buffer;
@@ -898,10 +898,10 @@
 	lzwbuflock[0] = lzwbuflock[1] = lzwbuflock[2] = lzwbuflock[3] = lzwbuflock[4] = 1;
 }
 
-long compress(char *lzwinbuf, long uncompleng, char *lzwoutbuf)
+int32_t compress(char *lzwinbuf, int32_t uncompleng, char *lzwoutbuf)
 {
-	long i, addr, newaddr, addrcnt, zx, *longptr;
-	long bytecnt1, bitcnt, numbits, oneupnumbits;
+	int32_t i, addr, newaddr, addrcnt, zx, *longptr;
+	int32_t bytecnt1, bitcnt, numbits, oneupnumbits;
 	short *shortptr;
 
 	for(i=255;i>=0;i--) { lzwbuf1[i] = (char) i; lzwbuf3[i] = (short) ((i+1)&255); }
@@ -932,7 +932,7 @@
 		lzwbuf2[addrcnt] = -1;
 		lzwbuf3[addrcnt] = -1;
 
-		longptr = (long *)&lzwoutbuf[bitcnt>>3];
+		longptr = (int32_t *)&lzwoutbuf[bitcnt>>3];
 		longptr[0] |= (addr<<(bitcnt&7));
 		bitcnt += numbits;
 		if ((addr&((oneupnumbits>>1)-1)) > ((addrcnt-1)&((oneupnumbits>>1)-1)))
@@ -942,7 +942,7 @@
 		if (addrcnt > oneupnumbits) { numbits++; oneupnumbits <<= 1; }
 	} while ((bytecnt1 < uncompleng) && (bitcnt < (uncompleng<<3)));
 
-	longptr = (long *)&lzwoutbuf[bitcnt>>3];
+	longptr = (int32_t *)&lzwoutbuf[bitcnt>>3];
 	longptr[0] |= (addr<<(bitcnt&7));
 	bitcnt += numbits;
 	if ((addr&((oneupnumbits>>1)-1)) > ((addrcnt-1)&((oneupnumbits>>1)-1)))
@@ -960,10 +960,10 @@
 	return(uncompleng+4);
 }
 
-long uncompress(char *lzwinbuf, long compleng, char *lzwoutbuf)
+int32_t uncompress(char *lzwinbuf, int32_t compleng, char *lzwoutbuf)
 {
-	long strtot, currstr, numbits, oneupnumbits;
-	long i, dat, leng, bitcnt, outbytecnt, *longptr;
+	int32_t strtot, currstr, numbits, oneupnumbits;
+	int32_t i, dat, leng, bitcnt, outbytecnt, *longptr;
 	short *shortptr;
 
 	shortptr = (short *)lzwinbuf;
@@ -978,7 +978,7 @@
 	numbits = 8; oneupnumbits = (1<<8);
 	do
 	{
-		longptr = (long *)&lzwinbuf[bitcnt>>3];
+		longptr = (int32_t *)&lzwinbuf[bitcnt>>3];
 		dat = ((longptr[0]>>(bitcnt&7)) & (oneupnumbits-1));
 		bitcnt += numbits;
 		if ((dat&((oneupnumbits>>1)-1)) > ((currstr-1)&((oneupnumbits>>1)-1)))
@@ -1000,10 +1000,10 @@
 }
 
 
-long TCkopen4load(const char *filename, int readfromGRP)
+int32_t TCkopen4load(const char *filename, int readfromGRP)
 {
 	char fullfilename[512];
-	long result = 0;
+	int32_t result = 0;
  
 	if(game_dir[0] != '\0' && !readfromGRP)
 	{
--- a/Engine/src/cache1d.h
+++ b/Engine/src/cache1d.h
@@ -20,31 +20,31 @@
 #define MAXGROUPFILES 4     /* Warning: Fix groupfil if this is changed */
 #define MAXOPENFILES 64     /* Warning: Fix filehan if this is changed  */
 
-void initcache(long dacachestart, long dacachesize);
-void allocache (long *newhandle, long newbytes, unsigned char *newlockptr);
-void suckcache (long *suckptr);
+void initcache(int32_t dacachestart, int32_t dacachesize);
+void allocache (int32_t *newhandle, int32_t newbytes, unsigned char *newlockptr);
+void suckcache (int32_t *suckptr);
 void agecache(void);
 void reportandexit(char *errormessage);
-long initgroupfile(const char *filename);
+int32_t initgroupfile(const char *filename);
 void uninitgroupfile(void);
 unsigned short crc16(char *data_p, unsigned short length);
 unsigned int crc32_update(unsigned char *buf, unsigned int length, unsigned int crc_to_update);
-long kopen4load(const char *filename, int readfromGRP);
-long kread(long handle, void *buffer, long leng);
-int kread8(long handle, char *buffer);
-int kread16(long handle, short *buffer);
-int kread32(long handle, long *buffer);
-long klseek(long handle, long offset, long whence);
-long kfilelength(long handle);
-void kclose(long handle);
-void kdfread(void *buffer, size_t dasizeof, size_t count, long fil);
+int32_t kopen4load(const char *filename, int readfromGRP);
+int32_t kread(int32_t handle, void *buffer, int32_t leng);
+int kread8(int32_t handle, char *buffer);
+int kread16(int32_t handle, short *buffer);
+int kread32(int32_t handle, int32_t *buffer);
+int32_t klseek(int32_t handle, int32_t offset, int32_t whence);
+int32_t kfilelength(int32_t handle);
+void kclose(int32_t handle);
+void kdfread(void *buffer, size_t dasizeof, size_t count, int32_t fil);
 void dfread(void *buffer, size_t dasizeof, size_t count, FILE *fil);
 void dfwrite(void *buffer, size_t dasizeof, size_t count, FILE *fil);
-long compress(char *lzwinbuf, long uncompleng, char *lzwoutbuf);
-long uncompress(char *lzwinbuf, long compleng, char *lzwoutbuf);
+int32_t compress(char *lzwinbuf, int32_t uncompleng, char *lzwoutbuf);
+int32_t uncompress(char *lzwinbuf, int32_t compleng, char *lzwoutbuf);
 
 extern char game_dir[512];
-extern long TCkopen4load(const char *filename, int readfromGRP);
+extern int32_t TCkopen4load(const char *filename, int readfromGRP);
 
 #endif  /* !defined _INCLUDE_CACHE1D_H_ */
 
--- a/Engine/src/display.h
+++ b/Engine/src/display.h
@@ -71,22 +71,22 @@
 extern char **_argv;
 
 /* !!! gads, look at all the namespace polution... */
-extern long xres, yres, bytesperline, imageSize, maxpages;
+extern int32_t xres, yres, bytesperline, imageSize, maxpages;
 extern char *screen, vesachecked;
-extern long buffermode, origbuffermode, linearmode;
+extern int32_t buffermode, origbuffermode, linearmode;
 extern char permanentupdate, vgacompatible;
 extern char moustat;
-extern long *horizlookup, *horizlookup2, horizycent;
-extern long oxdimen, oviewingrange, oxyaspect;
-extern long curbrightness;
-extern long qsetmode;
-extern long frameplace, frameoffset, pageoffset, ydim16;
+extern int32_t *horizlookup, *horizlookup2, horizycent;
+extern int32_t oxdimen, oviewingrange, oxyaspect;
+extern int32_t curbrightness;
+extern int32_t qsetmode;
+extern int32_t frameplace, frameoffset, pageoffset, ydim16;
 extern char textfont[1024], smalltextfont[1024];
 extern char pow2char[8];
-extern volatile long stereomode, visualpage, activepage, whiteband, blackband;
-extern long searchx, searchy;
-extern long wx1, wy1, wx2, wy2, ydimen;
-extern long xdimen, xdimenrecip, halfxdimen, xdimenscale, xdimscale;
+extern volatile int32_t stereomode, visualpage, activepage, whiteband, blackband;
+extern int32_t searchx, searchy;
+extern int32_t wx1, wy1, wx2, wy2, ydimen;
+extern int32_t xdimen, xdimenrecip, halfxdimen, xdimenscale, xdimscale;
 
 /*
  * !!! used to be static. If we ever put the original setgamemode() back, this
@@ -96,8 +96,8 @@
 extern unsigned char permanentlock;
 
 // defined in the game project:
-extern long BFullScreen;  // defined in Game\src\config.c
-extern long ScreenMode;
+extern int32_t BFullScreen;  // defined in Game\src\config.c
+extern int32_t ScreenMode;
 
 
 /* these need to be implemented by YOUR driver. */
@@ -120,26 +120,26 @@
  * VESA replacement code: The Unix (not-actually-VESA) version of this is
  *  originally using SDL (Simple Directmedia Layer: http://www.libsdl.org/),
  *  and is stored in sdl_driver.c, but there's no reason another driver
- *  couldn't be dropped in, so long as it implements these functions. Please
+ *  couldn't be dropped in, so int32_t as it implements these functions. Please
  *  reference sdl_driver.c and ves2.h (the original code) for all the nuances
  *  and global variables that need to get set up correctly.
  */
 void getvalidvesamodes(void);
-int VBE_getPalette(long start, long num, char *dapal);
-int VBE_setPalette(long start, long num, char *palettebuffer);
-int setvesa(long x, long y);
+int VBE_getPalette(int32_t start, int32_t num, char *dapal);
+int VBE_setPalette(int32_t start, int32_t num, char *palettebuffer);
+int setvesa(int32_t x, int32_t y);
 void uninitvesa(void);
 void setvmode(int mode);
-unsigned char readpixel(long offset);
-void drawpixel(long offset, Uint8 pixel);
-void drawpixels(long offset, Uint16 pixels);
-void drawpixelses(long offset, Uint32 pixelses);
-void drawpixel16(long offset);
-void fillscreen16 (long input1, long input2, long input3);
+unsigned char readpixel(int32_t offset);
+void drawpixel(int32_t offset, Uint8 pixel);
+void drawpixels(int32_t offset, Uint16 pixels);
+void drawpixelses(int32_t offset, Uint32 pixelses);
+void drawpixel16(int32_t offset);
+void fillscreen16 (int32_t input1, int32_t input2, int32_t input3);
 void limitrate(void);
-void setactivepage(long dapagenum);
+void setactivepage(int32_t dapagenum);
 void clear2dscreen(void);
-void _updateScreenRect(long x, long y, long w, long h);
+void _updateScreenRect(int32_t x, int32_t y, int32_t w, int32_t h);
 
 /* mouse/keystuff stuff. Also implemented in sdl_driver.c ... */
 int setupmouse(void);
@@ -156,11 +156,11 @@
 void __interrupt __far timerhandler(void);
 
 /* resolution inits. sdl_driver.c ... */
-int _setgamemode(char davidoption, long daxdim, long daydim);
+int32_t _setgamemode(char davidoption, int32_t daxdim, int32_t daydim);
 
-unsigned long getticks();
+uint32_t getticks();
 
-void drawline16(long XStart, long YStart, long XEnd, long YEnd, char Color);
+void drawline16(int32_t XStart, int32_t YStart, int32_t XEnd, int32_t YEnd, char Color);
 void setcolor16(int i1);
 
 int using_opengl(void);
--- a/Engine/src/engine.c
+++ b/Engine/src/engine.c
@@ -40,8 +40,8 @@
 
 #include "engine.h"
 
-long stereowidth = 23040, stereopixelwidth = 28, ostereopixelwidth = -1;
-volatile long stereomode = 0, visualpage, activepage, whiteband, blackband;
+int32_t stereowidth = 23040, stereopixelwidth = 28, ostereopixelwidth = -1;
+volatile int32_t stereomode = 0, visualpage, activepage, whiteband, blackband;
 volatile char oa1, o3c2, ortca, ortcb, overtbits, laststereoint;
 
 #include "display.h"
@@ -75,13 +75,13 @@
 	/* MUST CALL LOADVOXEL THIS WAY BECAUSE WATCOM STINKS! */
 
 /* !!! wtf does this do?! --ryan. */
-static void loadvoxel(long voxindex)
+static void loadvoxel(int32_t voxindex)
 {
     voxindex = 0;  /* prevent compiler whining. */
 }
 
 #if ((defined __WATCOMC__) && (defined PLATFORM_DOS))
-void kloadvoxel(long voxindex);
+void kloadvoxel(int32_t voxindex);
 #pragma aux kloadvoxel =\
 	"call loadvoxel",\
 	parm [eax]\
@@ -96,22 +96,22 @@
 #define MAXZSIZ 200
 #define MAXVOXELS 512
 #define MAXVOXMIPS 5
-long voxoff[MAXVOXELS][MAXVOXMIPS], voxlock[MAXVOXELS][MAXVOXMIPS];
-static long ggxinc[MAXXSIZ+1], ggyinc[MAXXSIZ+1];
-static long lowrecip[1024], nytooclose, nytoofar;
-static unsigned long distrecip[16384];
+int32_t voxoff[MAXVOXELS][MAXVOXMIPS], voxlock[MAXVOXELS][MAXVOXMIPS];
+static int32_t ggxinc[MAXXSIZ+1], ggyinc[MAXXSIZ+1];
+static int32_t lowrecip[1024], nytooclose, nytoofar;
+static uint32_t  distrecip[16384];
 #endif
 
 /* used to be static. --ryan. */
 char moustat = 0;
 
-long transarea = 0, totalarea = 0, beforedrawrooms = 1;
+int32_t transarea = 0, totalarea = 0, beforedrawrooms = 1;
 
 /* used to be static. --ryan. */
-long oxdimen = -1, oviewingrange = -1, oxyaspect = -1;
+int32_t oxdimen = -1, oviewingrange = -1, oxyaspect = -1;
 
 /* used to be static. --ryan. */
-long curbrightness = 0;
+int32_t curbrightness = 0;
 
 	/* Textured Map variables */
 static char globalpolytype;
@@ -119,8 +119,8 @@
 
 static unsigned char tempbuf[MAXWALLS];
 
-long ebpbak, espbak;
-long slopalookup[16384];
+int32_t ebpbak, espbak;
+int32_t slopalookup[16384];
 
 /*
  * !!! used to be static. If we ever put the original setgamemode() back, this
@@ -127,18 +127,18 @@
  * !!! can be made static again.  --ryan.
  */
 unsigned char permanentlock = 255;
-long artversion, mapversion;
+int32_t artversion, mapversion;
 char *pic = NULL;
 char picsiz[MAXTILES], tilefilenum[MAXTILES];
-long lastageclock;
-long tilefileoffs[MAXTILES];
+int32_t lastageclock;
+int32_t tilefileoffs[MAXTILES];
 
-long artsize = 0, cachesize = 0;
+int32_t artsize = 0, cachesize = 0;
 
 static short radarang[1280], radarang2[MAXXDIM+1];
 static unsigned short sqrtable[4096], shlookup[4096+256];
 char pow2char[8] = {1,2,4,8,16,32,64,-128};
-long pow2long[32] =
+int32_t pow2long[32] =
 {
 	1L,2L,4L,8L,
 	16L,32L,64L,128L,
@@ -149,7 +149,7 @@
 	16777216L,33554432L,67108864L,134217728L,
 	268435456L,536870912L,1073741824L,2147483647L,
 };
-long reciptable[2048], fpuasm;
+int32_t reciptable[2048], fpuasm;
 
 char kensmessage[128];
 
@@ -175,8 +175,8 @@
 char britable[16][64];
 char textfont[1024], smalltextfont[1024];
 
-static long xb1[MAXWALLSB], yb1[MAXWALLSB], xb2[MAXWALLSB], yb2[MAXWALLSB];
-static long rx1[MAXWALLSB], ry1[MAXWALLSB], rx2[MAXWALLSB], ry2[MAXWALLSB];
+static int32_t xb1[MAXWALLSB], yb1[MAXWALLSB], xb2[MAXWALLSB], yb2[MAXWALLSB];
+static int32_t rx1[MAXWALLSB], ry1[MAXWALLSB], rx2[MAXWALLSB], ry2[MAXWALLSB];
 static short p2[MAXWALLSB], thesector[MAXWALLSB], thewall[MAXWALLSB];
 
 static short bunchfirst[MAXWALLSB], bunchlast[MAXWALLSB];
@@ -184,12 +184,12 @@
 static short smost[MAXYSAVES], smostcnt;
 static short smoststart[MAXWALLSB];
 static char smostwalltype[MAXWALLSB];
-static long smostwall[MAXWALLSB], smostwallcnt = -1L;
+static int32_t smostwall[MAXWALLSB], smostwallcnt = -1L;
 
 static short maskwall[MAXWALLSB], maskwallcnt;
-static long spritesx[MAXSPRITESONSCREEN];
-static long spritesy[MAXSPRITESONSCREEN+1];
-static long spritesz[MAXSPRITESONSCREEN];
+static int32_t spritesx[MAXSPRITESONSCREEN];
+static int32_t spritesy[MAXSPRITESONSCREEN+1];
+static int32_t spritesz[MAXSPRITESONSCREEN];
 static spritetype *tspriteptr[MAXSPRITESONSCREEN];
 
 short umost[MAXXDIM+1], dmost[MAXXDIM+1];
@@ -196,37 +196,37 @@
 static short bakumost[MAXXDIM+1], bakdmost[MAXXDIM+1];
 short uplc[MAXXDIM+1], dplc[MAXXDIM+1];
 static short uwall[MAXXDIM+1], dwall[MAXXDIM+1];
-static long swplc[MAXXDIM+1], lplc[MAXXDIM+1];
-static long swall[MAXXDIM+1], lwall[MAXXDIM+4];
-long xdimen = -1, xdimenrecip, halfxdimen, xdimenscale, xdimscale;
-long wx1, wy1, wx2, wy2, ydimen;
-long viewoffset;
+static int32_t swplc[MAXXDIM+1], lplc[MAXXDIM+1];
+static int32_t swall[MAXXDIM+1], lwall[MAXXDIM+4];
+int32_t xdimen = -1, xdimenrecip, halfxdimen, xdimenscale, xdimscale;
+int32_t wx1, wy1, wx2, wy2, ydimen;
+int32_t viewoffset;
 
-static long rxi[8], ryi[8], rzi[8], rxi2[8], ryi2[8], rzi2[8];
-static long xsi[8], ysi[8];
+static int32_t rxi[8], ryi[8], rzi[8], rxi2[8], ryi2[8], rzi2[8];
+static int32_t xsi[8], ysi[8];
 
 /* used to be static. --ryan. */
-long *horizlookup=0, *horizlookup2=0, horizycent;
+int32_t *horizlookup=0, *horizlookup2=0, horizycent;
 
-long globalposx, globalposy, globalposz, globalhoriz;
+int32_t globalposx, globalposy, globalposz, globalhoriz;
 short globalang, globalcursectnum;
-long globalpal, cosglobalang, singlobalang;
-long cosviewingrangeglobalang, sinviewingrangeglobalang;
+int32_t globalpal, cosglobalang, singlobalang;
+int32_t cosviewingrangeglobalang, sinviewingrangeglobalang;
 char *globalpalwritten;
-long globaluclip, globaldclip, globvis = 0;
-long globalvisibility, globalhisibility, globalpisibility, globalcisibility;
+int32_t globaluclip, globaldclip, globvis = 0;
+int32_t globalvisibility, globalhisibility, globalpisibility, globalcisibility;
 char globparaceilclip, globparaflorclip;
 
-long xyaspect, viewingrangerecip;
+int32_t xyaspect, viewingrangerecip;
 
-long asm1, asm2, asm3, asm4;
-long vplce[4], vince[4], palookupoffse[4], bufplce[4];
+int32_t asm1, asm2, asm3, asm4;
+int32_t vplce[4], vince[4], palookupoffse[4], bufplce[4];
 char globalxshift, globalyshift;
-long globalxpanning, globalypanning, globalshade;
+int32_t globalxpanning, globalypanning, globalshade;
 short globalpicnum, globalshiftval;
-long globalzd, globalbufplc, globalyscale, globalorientation;
-long globalx1, globaly1, globalx2, globaly2, globalx3, globaly3, globalzx;
-long globalx, globaly, globalz;
+int32_t globalzd, globalbufplc, globalyscale, globalorientation;
+int32_t globalx1, globaly1, globalx2, globaly2, globalx3, globaly3, globalzx;
+int32_t globalx, globaly, globalz;
 
 //Those two variables are using during portal flooding:
 // sectorBorder is the stack and sectorbordercnt is the stack counter.
@@ -233,25 +233,25 @@
 static short sectorborder[256], sectorbordercnt;
 
 static char tablesloaded = 0;
-long pageoffset, ydim16, qsetmode = 0;
-long startposx, startposy, startposz;
+int32_t pageoffset, ydim16, qsetmode = 0;
+int32_t startposx, startposy, startposz;
 short startang, startsectnum;
 short pointhighlight, linehighlight, highlightcnt;
-static long lastx[MAXYDIM];
+static int32_t lastx[MAXYDIM];
 char *transluc = NULL, paletteloaded = 0;
 
 #define FASTPALGRIDSIZ 8
-static long rdist[129], gdist[129], bdist[129];
+static int32_t rdist[129], gdist[129], bdist[129];
 static char colhere[((FASTPALGRIDSIZ+2)*(FASTPALGRIDSIZ+2)*(FASTPALGRIDSIZ+2))>>3];
 static char colhead[(FASTPALGRIDSIZ+2)*(FASTPALGRIDSIZ+2)*(FASTPALGRIDSIZ+2)];
-static long colnext[256];
+static int32_t colnext[256];
 static char coldist[8] = {0,1,2,3,4,3,2,1};
-static long colscan[27];
+static int32_t colscan[27];
 
 static short clipnum, hitwalls[4];
-long hitscangoalx = (1<<29)-1, hitscangoaly = (1<<29)-1;
+int32_t hitscangoalx = (1<<29)-1, hitscangoaly = (1<<29)-1;
 
-typedef struct { long x1, y1, x2, y2; } linetype;
+typedef struct { int32_t x1, y1, x2, y2; } linetype;
 static linetype clipit[MAXCLIPNUM];
 static short clipsectorlist[MAXCLIPNUM], clipsectnum;
 static short clipobjectval[MAXCLIPNUM];
@@ -258,35 +258,35 @@
 
 typedef struct
 {
-	long sx, sy, z;
+	int32_t sx, sy, z;
 	short a, picnum;
 	signed char dashade;
 	unsigned char dapalnum, dastat, pagesleft;
-	long cx1, cy1, cx2, cy2;
+	int32_t cx1, cy1, cx2, cy2;
 } permfifotype;
 static permfifotype permfifo[MAXPERMS];
-static long permhead = 0, permtail = 0;
+static int32_t permhead = 0, permtail = 0;
 
 short numscans, numhits, numbunches;
 
 short editstatus = 0;
 short searchit;
-long searchx = -1, searchy;                     /* search input  */
+int32_t searchx = -1, searchy;                     /* search input  */
 short searchsector, searchwall, searchstat;     /* search output */
 
 static char artfilename[20];
-static long numtilefiles, artfil = -1, artfilnum, artfilplc;
+static int32_t numtilefiles, artfil = -1, artfilnum, artfilplc;
 
 static char inpreparemirror = 0;
-static long mirrorsx1, mirrorsy1, mirrorsx2, mirrorsy2;
+static int32_t mirrorsx1, mirrorsy1, mirrorsx2, mirrorsy2;
 
-long totalclocklock;
+int32_t totalclocklock;
 
 unsigned short mapCRC;
 
 #include "a.h"
 
-static __inline long nsqrtasm(unsigned long param)
+static __inline int32_t nsqrtasm(uint32_t  param)
 {
     unsigned short *shlookup_a = (unsigned short*)shlookup;
     unsigned short *sqrtable_a = (unsigned short*)sqrtable;
@@ -304,14 +304,14 @@
     return param;
 }
 
-static __inline long krecipasm(long i)
+static __inline int32_t krecipasm(int32_t i)
 { // Ken did this
-	float f = (float)i; i = *(long *)&f;
+	float f = (float)i; i = *(int32_t *)&f;
 	return((reciptable[(i>>12)&2047]>>(((i-0x3f800000)>>23)&31))^(i>>31));
 }
 
 
-static __inline void setgotpic(long tilenume)
+static __inline void setgotpic(int32_t tilenume)
 {
 	if (walock[tilenume] < 200) walock[tilenume] = 199;
 	gotpic[tilenume>>3] |= pow2char[tilenume&7];
@@ -318,7 +318,7 @@
 }
 
 
-static __inline long getclipmask(long a, long b, long c, long d)
+static __inline int32_t getclipmask(int32_t a, int32_t b, int32_t c, int32_t d)
 { // Ken did this
 	d = ((a<0)*8) + ((b<0)*4) + ((c<0)*2) + (d<0);
 	return(((d<<4)^0xf0)|d);
@@ -327,7 +327,7 @@
 //
 // krecip
 //
-long krecip(long num)
+int32_t krecip(int32_t num)
 {
 	return(krecipasm(num));
 }
@@ -350,7 +350,7 @@
 {
 	walltype *wal, *wal2;
 	spritetype *spr;
-	long xs, ys, x1, y1, x2, y2, xp1, yp1, xp2=0, yp2=0, templong;
+	int32_t xs, ys, x1, y1, x2, y2, xp1, yp1, xp2=0, yp2=0, tempint;
 	short z, zz, startwall, endwall, numscansbefore, scanfirst, bunchfrst;
 	short nextsectnum;
 
@@ -405,12 +405,12 @@
                 //If this portal has not been visited.
 				if ((gotsector[nextsectnum>>3]&pow2char[nextsectnum&7]) == 0)
 				{
-					templong = x1*y2-x2*y1;
+					tempint = x1*y2-x2*y1;
                     
                     // Using cross product, determine if the portal is facing us or not.
                     // If it is: Add it to the stack and bump the stack counter.
-					if (((unsigned)templong+262144) < 524288)
-						if (mulscale5(templong,templong) <= (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
+					if (((unsigned)tempint+262144) < 524288)
+						if (mulscale5(tempint,tempint) <= (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
 							sectorborder[sectorbordercnt++] = nextsectnum;
 				}
 
@@ -453,9 +453,9 @@
 			{
 				if (xp2 < -yp2) goto skipitaddwall;
 				xb1[numscans] = 0;
-				templong = yp1-yp2+xp1-xp2;
-				if (templong == 0) goto skipitaddwall;
-				yb1[numscans] = yp1 + scale(yp2-yp1,xp1+yp1,templong);
+				tempint = yp1-yp2+xp1-xp2;
+				if (tempint == 0) goto skipitaddwall;
+				yb1[numscans] = yp1 + scale(yp2-yp1,xp1+yp1,tempint);
 			}
 			if (yb1[numscans] < 256) goto skipitaddwall;
 
@@ -471,9 +471,9 @@
 			{
 				if (xp1 > yp1) goto skipitaddwall;
 				xb2[numscans] = xdimen-1;
-				templong = xp2-xp1+yp1-yp2;
-				if (templong == 0) goto skipitaddwall;
-				yb2[numscans] = yp1 + scale(yp2-yp1,yp1-xp1,templong);
+				tempint = xp2-xp1+yp1-yp2;
+				if (tempint == 0) goto skipitaddwall;
+				yb2[numscans] = yp1 + scale(yp2-yp1,yp1-xp1,tempint);
 			}
 			if ((yb2[numscans] < 256) || (xb1[numscans] > xb2[numscans])) goto skipitaddwall;
 
@@ -505,9 +505,9 @@
 }
 
 
-static void prepwall(long z, walltype *wal)
+static void prepwall(int32_t z, walltype *wal)
 {
-	long i, l=0, ol=0, splc, sinc, x, topinc, top, botinc, bot, walxrepeat;
+	int32_t i, l=0, ol=0, splc, sinc, x, topinc, top, botinc, bot, walxrepeat;
 
 	walxrepeat = (wal->xrepeat<<3);
 
@@ -583,15 +583,15 @@
 }
 
 
-static int getpalookup(long davis, long dashade)
+static int getpalookup(int32_t davis, int32_t dashade)
 {
 	return(min(max(dashade+(davis>>8),0),numpalookups-1));
 }
 
 
-static void hline (long xr, long yp)
+static void hline (int32_t xr, int32_t yp)
 {
-	long xl, r, s;
+	int32_t xl, r, s;
 
 	xl = lastx[yp]; if (xl > xr) return;
 	r = horizlookup2[yp-globalhoriz+horizycent];
@@ -604,9 +604,9 @@
 }
 
 
-static void slowhline (long xr, long yp)
+static void slowhline (int32_t xr, int32_t yp)
 {
-	long xl, r;
+	int32_t xl, r;
 
 	xl = lastx[yp]; if (xl > xr) return;
 	r = horizlookup2[yp-globalhoriz+horizycent];
@@ -628,7 +628,7 @@
 
 static int animateoffs(short tilenum, short fakevar)
 {
-	long i, k, offs;
+	int32_t i, k, offs;
 
 	offs = 0;
 	i = (totalclocklock>>((picanm[tilenum]>>24)&15));
@@ -655,9 +655,9 @@
 
 
 /* renders non-parallaxed ceilings. --ryan. */
-static void ceilscan (long x1, long x2, long sectnum)
+static void ceilscan (int32_t x1, int32_t x2, int32_t sectnum)
 {
-	long i, j, ox, oy, x, y1, y2, twall, bwall;
+	int32_t i, j, ox, oy, x, y1, y2, twall, bwall;
 	sectortype *sec;
 
 	sec = &sector[sectnum];
@@ -823,9 +823,9 @@
 
 
 /* renders non-parallaxed floors. --ryan. */
-static void florscan (long x1, long x2, long sectnum)
+static void florscan (int32_t x1, int32_t x2, int32_t sectnum)
 {
-	long i, j, ox, oy, x, y1, y2, twall, bwall;
+	int32_t i, j, ox, oy, x, y1, y2, twall, bwall;
 	sectortype *sec;
 
 	sec = &sector[sectnum];
@@ -1014,12 +1014,12 @@
  *
  *  --ryan.
  */
-static void wallscan(long x1, long x2,
+static void wallscan(int32_t x1, int32_t x2,
                      short *uwal, short *dwal,
-                     long *swal, long *lwal)
+                     int32_t *swal, int32_t *lwal)
 {
-	long i, x, xnice, ynice, fpalookup;
-	long y1ve[4], y2ve[4], u4, d4, z, tsizx, tsizy;
+	int32_t i, x, xnice, ynice, fpalookup;
+	int32_t y1ve[4], y2ve[4], u4, d4, z, tsizx, tsizy;
 	char bad;
 
 	tsizx = tilesizx[globalpicnum];
@@ -1156,12 +1156,12 @@
 
 
 /* this renders masking sprites. See wallscan(). --ryan. */
-static void maskwallscan(long x1, long x2,
+static void maskwallscan(int32_t x1, int32_t x2,
                          short *uwal, short *dwal,
-                         long *swal, long *lwal)
+                         int32_t *swal, int32_t *lwal)
 {
-	long i, x, startx, xnice, ynice, fpalookup;
-	long y1ve[4], y2ve[4], u4, d4, dax, z, p, tsizx, tsizy;
+	int32_t i, x, startx, xnice, ynice, fpalookup;
+	int32_t y1ve[4], y2ve[4], u4, d4, dax, z, p, tsizx, tsizy;
 	char bad;
 
 	tsizx = tilesizx[globalpicnum];
@@ -1285,11 +1285,11 @@
 }
 
 /* renders parallaxed skies/floors  --ryan. */
-static void parascan(long dax1, long dax2, long sectnum,
-                     char dastat, long bunch)
+static void parascan(int32_t dax1, int32_t dax2, int32_t sectnum,
+                     char dastat, int32_t bunch)
 {
 	sectortype *sec;
-	long j, k, l, m, n, x, z, wallnum, nextsectnum, globalhorizbak;
+	int32_t j, k, l, m, n, x, z, wallnum, nextsectnum, globalhorizbak;
 	short *topptr, *botptr;
 
 	sectnum = thesector[bunchfirst[bunch]]; sec = &sector[sectnum];
@@ -1426,11 +1426,11 @@
 
 
 #define BITSOFPRECISION 3  /* Don't forget to change this in A.ASM also! */
-static void grouscan (long dax1, long dax2, long sectnum, char dastat)
+static void grouscan (int32_t dax1, int32_t dax2, int32_t sectnum, char dastat)
 {
-	long i, j, l, x, y, dx, dy, wx, wy, y1, y2, daz;
-	long daslope, dasqr;
-	long shoffs, shinc, m1, m2, *mptr1, *mptr2, *nptr1, *nptr2;
+	int32_t i, j, l, x, y, dx, dy, wx, wy, y1, y2, daz;
+	int32_t daslope, dasqr;
+	int32_t shoffs, shinc, m1, m2, *mptr1, *mptr2, *nptr1, *nptr2;
 	walltype *wal;
 	sectortype *sec;
 
@@ -1549,7 +1549,7 @@
 		/* Avoid visibility overflow by crossing horizon */
 	if (globalzd > 0) m1 += (globalzd>>16); else m1 -= (globalzd>>16);
 	m2 = m1+l;
-	mptr1 = (long *)&slopalookup[y1+(shoffs>>15)]; mptr2 = mptr1+1;
+	mptr1 = (int32_t *)&slopalookup[y1+(shoffs>>15)]; mptr2 = mptr1+1;
 
 	for(x=dax1;x<=dax2;x++)
 	{
@@ -1557,8 +1557,8 @@
 		else { y1 = max(umost[x],dplc[x]); y2 = dmost[x]-1; }
 		if (y1 <= y2)
 		{
-			nptr1 = (long *)&slopalookup[y1+(shoffs>>15)];
-			nptr2 = (long *)&slopalookup[y2+(shoffs>>15)];
+			nptr1 = (int32_t *)&slopalookup[y1+(shoffs>>15)];
+			nptr2 = (int32_t *)&slopalookup[y2+(shoffs>>15)];
 			while (nptr1 <= mptr1)
 			{
 				*mptr1-- = j + (getpalookup((long)mulscale24(krecipasm(m1),globvis),globalshade)<<8);
@@ -1585,10 +1585,10 @@
 }
 
 
-static int owallmost(short *mostbuf, long w, long z)
+static int owallmost(short *mostbuf, int32_t w, int32_t z)
 {
-	long bad, inty, xcross, y, yinc;
-	long s1, s2, s3, s4, ix1, ix2, iy1, iy2, t;
+	int32_t bad, inty, xcross, y, yinc;
+	int32_t s1, s2, s3, s4, ix1, ix2, iy1, iy2, t;
 
 	z <<= 7;
 	s1 = mulscale20(globaluclip,yb1[w]); s2 = mulscale20(globaluclip,yb2[w]);
@@ -1648,7 +1648,7 @@
 
 	y = (scale(z,xdimenscale,iy1)<<4);
 	yinc = ((scale(z,xdimenscale,iy2)<<4)-y) / (ix2-ix1+1);
-	qinterpolatedown16short((long *)&mostbuf[ix1],ix2-ix1+1,y+(globalhoriz<<16),yinc);
+	qinterpolatedown16short((int32_t *)&mostbuf[ix1],ix2-ix1+1,y+(globalhoriz<<16),yinc);
 
 	if (mostbuf[ix1] < 0) mostbuf[ix1] = 0;
 	if (mostbuf[ix1] > ydimen) mostbuf[ix1] = ydimen;
@@ -1659,11 +1659,11 @@
 }
 
 
-static int wallmost(short *mostbuf, long w, long sectnum, char dastat)
+static int wallmost(short *mostbuf, int32_t w, int32_t sectnum, char dastat)
 {
-	long bad, i, j, t, y, z, inty, intz, xcross, yinc, fw;
-	long x1, y1, z1, x2, y2, z2, xv, yv, dx, dy, dasqr, oz1, oz2;
-	long s1, s2, s3, s4, ix1, ix2, iy1, iy2;
+	int32_t bad, i, j, t, y, z, inty, intz, xcross, yinc, fw;
+	int32_t x1, y1, z1, x2, y2, z2, xv, yv, dx, dy, dasqr, oz1, oz2;
+	int32_t s1, s2, s3, s4, ix1, ix2, iy1, iy2;
 
 	if (dastat == 0)
 	{
@@ -1800,7 +1800,7 @@
 
 	y = (scale(z1,xdimenscale,iy1)<<4);
 	yinc = ((scale(z2,xdimenscale,iy2)<<4)-y) / (ix2-ix1+1);
-	qinterpolatedown16short((long *)&mostbuf[ix1],ix2-ix1+1,y+(globalhoriz<<16),yinc);
+	qinterpolatedown16short((int32_t *)&mostbuf[ix1],ix2-ix1+1,y+(globalhoriz<<16),yinc);
 
 	if (mostbuf[ix1] < 0) mostbuf[ix1] = 0;
 	if (mostbuf[ix1] > ydimen) mostbuf[ix1] = ydimen;
@@ -1811,13 +1811,13 @@
 }
 
 
-static void drawalls(long bunch)
+static void drawalls(int32_t bunch)
 {
 	sectortype *sec, *nextsec;
 	walltype *wal;
-	long i, x, x1, x2, cz[5], fz[5];
-	long z, wallnum, sectnum, nextsectnum;
-	long startsmostwallcnt, startsmostcnt, gotswall;
+	int32_t i, x, x1, x2, cz[5], fz[5];
+	int32_t z, wallnum, sectnum, nextsectnum;
+	int32_t startsmostwallcnt, startsmostcnt, gotswall;
 	char andwstat1, andwstat2;
 
 	z = bunchfirst[bunch];
@@ -1981,7 +1981,7 @@
 						smostwall[smostwallcnt] = z;
 						smostwalltype[smostwallcnt] = 1;   /* 1 for umost */
 						smostwallcnt++;
-						copybufbyte((long *)&umost[x1],(long *)&smost[smostcnt],i*sizeof(smost[0]));
+						copybufbyte((int32_t *)&umost[x1],(int32_t *)&smost[smostcnt],i*sizeof(smost[0]));
 						smostcnt += i;
 					}
 				}
@@ -2086,7 +2086,7 @@
 						smostwall[smostwallcnt] = z;
 						smostwalltype[smostwallcnt] = 2;   /* 2 for dmost */
 						smostwallcnt++;
-						copybufbyte((long *)&dmost[x1],(long *)&smost[smostcnt],i*sizeof(smost[0]));
+						copybufbyte((int32_t *)&dmost[x1],(int32_t *)&smost[smostcnt],i*sizeof(smost[0]));
 						smostcnt += i;
 					}
 				}
@@ -2169,7 +2169,7 @@
 
 static void dosetaspect(void)
 {
-	long i, j, k, x, xinc;
+	int32_t i, j, k, x, xinc;
 
 	if (xyaspect != oxyaspect)
 	{
@@ -2204,10 +2204,10 @@
 }
 
 
-int wallfront(long l1, long l2)
+int wallfront(int32_t l1, int32_t l2)
 {
 	walltype *wal;
-	long x11, y11, x21, y21, x12, y12, x22, y22, dx, dy, t1, t2;
+	int32_t x11, y11, x21, y21, x12, y12, x22, y22, dx, dy, t1, t2;
 
 	wal = &wall[thewall[l1]]; x11 = wal->x; y11 = wal->y;
 	wal = &wall[wal->point2]; x21 = wal->x; y21 = wal->y;
@@ -2239,9 +2239,9 @@
 }
 
 
-static int bunchfront(long b1, long b2)
+static int bunchfront(int32_t b1, int32_t b2)
 {
-	long x1b1, x2b1, x1b2, x2b2, b1f, b2f, i;
+	int32_t x1b1, x2b1, x1b2, x2b2, b1f, b2f, i;
 
 	b1f = bunchfirst[b1]; x1b1 = xb1[b1f]; x2b2 = xb2[bunchlast[b2]]+1;
 	if (x1b1 >= x2b2) return(-1);
@@ -2258,10 +2258,10 @@
 }
 
 
-void drawrooms(long daposx, long daposy, long daposz,
-               short daang, long dahoriz, short dacursectnum)
+void drawrooms(int32_t daposx, int32_t daposy, int32_t daposz,
+               short daang, int32_t dahoriz, short dacursectnum)
 {
-	long i, j, z, cz, fz, closest;
+	int32_t i, j, z, cz, fz, closest;
 	short *shortptr1, *shortptr2;
 
 	beforedrawrooms = 0;
@@ -2440,10 +2440,10 @@
 }
 
 
-static int spritewallfront (spritetype *s, long w)
+static int spritewallfront (spritetype *s, int32_t w)
 {
 	walltype *wal;
-	long x1, y1;
+	int32_t x1, y1;
 
 	wal = &wall[w]; x1 = wal->x; y1 = wal->y;
 	wal = &wall[wal->point2];
@@ -2451,9 +2451,9 @@
 }
 
 
-static void transmaskvline(long x)
+static void transmaskvline(int32_t x)
 {
-	long vplc, vinc, p, i, palookupoffs, bufplc;
+	int32_t vplc, vinc, p, i, palookupoffs, bufplc;
 	short y1v, y2v;
 
 	if ((x < 0) || (x >= xdimen)) return;
@@ -2479,9 +2479,9 @@
 	transarea += y2v-y1v;
 }
 
-static void transmaskvline2 (long x)
+static void transmaskvline2 (int32_t x)
 {
-	long i, y1, y2, x2;
+	int32_t i, y1, y2, x2;
 	short y1ve[2], y2ve[2];
 
 	if ((x < 0) || (x >= xdimen)) return;
@@ -2548,9 +2548,9 @@
 	faketimerhandler();
 }
 
-static void transmaskwallscan(long x1, long x2)
+static void transmaskwallscan(int32_t x1, int32_t x2)
 {
-	long x;
+	int32_t x;
 
 	setgotpic(globalpicnum);
 	if ((tilesizx[globalpicnum] <= 0) || (tilesizy[globalpicnum] <= 0)) return;
@@ -2567,8 +2567,8 @@
 	faketimerhandler();
 }
 
-int loadboard(char *filename, long *daposx, long *daposy,
-              long *daposz, short *daang, short *dacursectnum)
+int loadboard(char *filename, int32_t *daposx, int32_t *daposy,
+              int32_t *daposz, short *daang, short *dacursectnum)
 {
     int x;
 	short fil, i, numsprites;
@@ -2705,7 +2705,7 @@
 }
 
 
-static void write32(int f, long val)
+static void write32(int f, int32_t val)
 {
     val = BUILDSWAP_INTEL32(val);
     write(f, &val, 4);
@@ -2723,8 +2723,8 @@
 }
 
 
-int saveboard(char *filename, long *daposx, long *daposy,
-              long *daposz, short *daang, short *dacursectnum)
+int saveboard(char *filename, int32_t *daposx, int32_t *daposy,
+              int32_t *daposz, short *daang, short *dacursectnum)
 {
 	int fil;
     int x;
@@ -2857,7 +2857,7 @@
 
 static void initksqrt(void)
 {
-	long i, j, k;
+	int32_t i, j, k;
 
 	j = 1; k = 0;
 	for(i=0;i<4096;i++)
@@ -2872,7 +2872,7 @@
 
 static void loadtables(void)
 {
-	long i, fil;
+	int32_t i, fil;
 
 	if (tablesloaded == 0)
 	{
@@ -2899,9 +2899,9 @@
 }
 
 
-static void initfastcolorlookup(long rscale, long gscale, long bscale)
+static void initfastcolorlookup(int32_t rscale, int32_t gscale, int32_t bscale)
 {
-	long i, j, x, y, z;
+	int32_t i, j, x, y, z;
 	char *pal1;
 
 	j = 0;
@@ -2937,7 +2937,7 @@
 
 static void loadpalette(void)
 {
-	long i, j, k, dist, fil;
+	int32_t i, j, k, dist, fil;
 	char *ptr;
 
 	if (paletteloaded != 0) return;
@@ -2947,9 +2947,9 @@
 	kread16(fil,&numpalookups);
 
 	if ((palookup[0] = (char *)kkmalloc(numpalookups<<8)) == NULL)
-		allocache((long *)&palookup[0],numpalookups<<8,&permanentlock);
+		allocache((int32_t *)&palookup[0],numpalookups<<8,&permanentlock);
 	if ((transluc = (char *)kkmalloc(65536L)) == NULL)
-		allocache((long *)&transluc,65536,&permanentlock);
+		allocache((int32_t *)&transluc,65536,&permanentlock);
 
 	globalpalwritten = palookup[0]; globalpal = 0;
 	setpalookupaddress(globalpalwritten);
@@ -2961,7 +2961,7 @@
 
 	/*kread(fil,transluc,65536);*/
 	for (k = 0; k < (65536 / 4); k++)
-	    kread32(fil, ((long *) transluc) + k);
+	    kread32(fil, ((int32_t *) transluc) + k);
 
 	kclose(fil);
 
@@ -2992,7 +2992,7 @@
 
 
 
-int setgamemode(char davidoption, long daxdim, long daydim)
+int setgamemode(char davidoption, int32_t daxdim, int32_t daydim)
 {
 	strcpy(kensmessage,"!!!! BUILD engine&tools programmed by Ken Silverman of E.G. RI.  (c) Copyright 1995 Ken Silverman.  Summary:  BUILD = Ken. !!!!");
 	if (getkensmessagecrc(FP_OFF(kensmessage)) != 0x56c764d4)
@@ -3019,10 +3019,10 @@
 
 void initengine(void)
 {
-    long i;
+    int32_t i;
 
 #ifdef SUPERBUILD
-	long j;
+	int32_t j;
 #endif
 
     initengine_called = 1;
@@ -3086,9 +3086,9 @@
 
 
 	/* Assume npoints=4 with polygon on &rx1,&ry1 */
-static int clippoly4(long cx1, long cy1, long cx2, long cy2)
+static int clippoly4(int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2)
 {
-	long n, nn, z, zz, x, x1, x2, y, y1, y2, t;
+	int32_t n, nn, z, zz, x, x1, x2, y, y1, y2, t;
 
 	nn = 0; z = 0;
 	do
@@ -3139,14 +3139,14 @@
 
 
 
-static void dorotatesprite (long sx, long sy, long z, short a, short picnum,
-	signed char dashade, unsigned char dapalnum, char dastat, long cx1,
-	long cy1, long cx2, long cy2)
+static void dorotatesprite (int32_t sx, int32_t sy, int32_t z, short a, short picnum,
+	signed char dashade, unsigned char dapalnum, char dastat, int32_t cx1,
+	int32_t cy1, int32_t cx2, int32_t cy2)
 {
-	long cosang, sinang, v, nextv, dax1, dax2, oy, bx, by, ny1, ny2;
-	long i, x, y, x1, y1, x2, y2, gx1, gy1, p, bufplc, palookupoffs;
-	long xsiz, ysiz, xoff, yoff, npoints, yplc, yinc, lx, rx, xx, xend;
-	long xv, yv, xv2, yv2, obuffermode=0, qlinemode=0, y1ve[4], y2ve[4], u4, d4;
+	int32_t cosang, sinang, v, nextv, dax1, dax2, oy, bx, by, ny1, ny2;
+	int32_t i, x, y, x1, y1, x2, y2, gx1, gy1, p, bufplc, palookupoffs;
+	int32_t xsiz, ysiz, xoff, yoff, npoints, yplc, yinc, lx, rx, xx, xend;
+	int32_t xv, yv, xv2, yv2, obuffermode=0, qlinemode=0, y1ve[4], y2ve[4], u4, d4;
 	char bad;
 
 	xsiz = tilesizx[picnum]; ysiz = tilesizy[picnum];
@@ -3229,12 +3229,12 @@
 			if (dax2 > dax1)
 			{
 				yplc = y1 + mulscale16((dax1<<16)+65535-x1,yinc);
-				qinterpolatedown16short((long *)(&uplc[dax1]),dax2-dax1,yplc,yinc);
+				qinterpolatedown16short((int32_t *)(&uplc[dax1]),dax2-dax1,yplc,yinc);
 			}
 			else
 			{
 				yplc = y2 + mulscale16((dax2<<16)+65535-x2,yinc);
-				qinterpolatedown16short((long *)(&dplc[dax2]),dax1-dax2,yplc,yinc);
+				qinterpolatedown16short((int32_t *)(&dplc[dax2]),dax1-dax2,yplc,yinc);
 			}
 		}
 		nextv = v;
@@ -3536,9 +3536,9 @@
 
 void nextpage(void)
 {
-	long i;
+	int32_t i;
 	permfifotype *per;
-	/* long j,k; */
+	/* int32_t j,k; */
 
 #if 0
 	char snotbuf[32];
@@ -3598,7 +3598,7 @@
 void loadtile(short tilenume)
 {
 	char *ptr;
-	long i, dasiz;
+	int32_t i, dasiz;
 
 	if ((unsigned)tilenume >= (unsigned)MAXTILES) return;
 	dasiz = tilesizx[tilenume]*tilesizy[tilenume];
@@ -3640,9 +3640,9 @@
 }
 
 
-int allocatepermanenttile(short tilenume, long xsiz, long ysiz)
+int allocatepermanenttile(short tilenume, int32_t xsiz, int32_t ysiz)
 {
-	long j, dasiz;
+	int32_t j, dasiz;
 
 	if ((xsiz <= 0) || (ysiz <= 0) || ((unsigned)tilenume >= (unsigned)MAXTILES))
 		return(0);
@@ -3667,7 +3667,7 @@
 
 int loadpics(char *filename, char* gamedir)
 {
-	long offscount, localtilestart, localtileend, dasiz;
+	int32_t offscount, localtilestart, localtileend, dasiz;
 	short fil, i, j, k;
 	//char fullpathartfilename[512];
 
@@ -3778,9 +3778,9 @@
 }
 
 #ifdef SUPERBUILD
-void qloadkvx(long voxindex, char *filename)
+void qloadkvx(int32_t voxindex, char *filename)
 {
-	long i, fil, dasiz, lengcnt, lengtot;
+	int32_t i, fil, dasiz, lengcnt, lengtot;
 	char *ptr;
 
 	if ((fil = kopen4load(filename,0)) == -1) return;
@@ -3806,10 +3806,10 @@
 #endif
 
 
-int clipinsidebox(long x, long y, short wallnum, long walldist)
+int clipinsidebox(int32_t x, int32_t y, short wallnum, int32_t walldist)
 {
 	walltype *wal;
-	long x1, y1, x2, y2, r;
+	int32_t x1, y1, x2, y2, r;
 
 	r = (walldist<<1);
 	wal = &wall[wallnum];     x1 = wal->x+walldist-x; y1 = wal->y+walldist-y;
@@ -3832,9 +3832,9 @@
 	return((x2 >= y2)<<1);
 }
 
-static int clipinsideboxline(long x, long y, long x1, long y1, long x2, long y2, long walldist)
+static int clipinsideboxline(int32_t x, int32_t y, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t walldist)
 {
-	long r;
+	int32_t r;
 
 	r = (walldist<<1);
 
@@ -3859,9 +3859,9 @@
 }
 
 
-void drawline256 (long x1, long y1, long x2, long y2, unsigned char col)
+void drawline256 (int32_t x1, int32_t y1, int32_t x2, int32_t y2, unsigned char col)
 {
-	long dx, dy, i, j, p, inc, plc, daend;
+	int32_t dx, dy, i, j, p, inc, plc, daend;
 
 	col = palookup[0][col];
 
@@ -3934,11 +3934,11 @@
 }
 
 
-int inside(long x, long y, short sectnum)
+int inside(int32_t x, int32_t y, short sectnum)
 {
 	walltype *wal;
-	long i, x1, y1, x2, y2;
-	unsigned long cnt;
+	int32_t i, x1, y1, x2, y2;
+	uint32_t  cnt;
 
 	if ((sectnum < 0) || (sectnum >= numsectors)) return(-1);
 
@@ -3965,7 +3965,7 @@
 }
 
 
-int getangle(long xvect, long yvect)
+int getangle(int32_t xvect, int32_t yvect)
 {
 	if ((xvect|yvect) == 0) return(0);
 	if (xvect == 0) return(512+((yvect<0)<<10));
@@ -3978,17 +3978,17 @@
 }
 
 
-int ksqrt(long num)
+int ksqrt(int32_t num)
 {
 	return(nsqrtasm(num));
 }
 
 
-void copytilepiece(long tilenume1, long sx1, long sy1, long xsiz, long ysiz,
-                   long tilenume2, long sx2, long sy2)
+void copytilepiece(int32_t tilenume1, int32_t sx1, int32_t sy1, int32_t xsiz, int32_t ysiz,
+                   int32_t tilenume2, int32_t sx2, int32_t sy2)
 {
 	unsigned char *ptr1, *ptr2, dat;
-	long xsiz1, ysiz1, xsiz2, ysiz2, i, j, x1, y1, x2, y2;
+	int32_t xsiz1, ysiz1, xsiz2, ysiz2, i, j, x1, y1, x2, y2;
 
 	xsiz1 = tilesizx[tilenume1]; ysiz1 = tilesizy[tilenume1];
 	xsiz2 = tilesizx[tilenume2]; ysiz2 = tilesizy[tilenume2];
@@ -4024,7 +4024,7 @@
 
 static void drawmaskwall(short damaskwallcnt)
 {
-	long i, j, k, x, z, sectnum, z1, z2, lx, rx;
+	int32_t i, j, k, x, z, sectnum, z1, z2, lx, rx;
 	sectortype *sec, *nsec;
 	walltype *wal;
 
@@ -4115,9 +4115,9 @@
 }
 
 
-static void ceilspritehline (long x2, long y)
+static void ceilspritehline (int32_t x2, int32_t y)
 {
-	long x1, v, bx, by;
+	int32_t x1, v, bx, by;
 
 	/*
 	 * x = x1 + (x2-x1)t + (y1-y2)u  �  x = 160v
@@ -4145,9 +4145,9 @@
 }
 
 
-static void ceilspritescan (long x1, long x2)
+static void ceilspritescan (int32_t x1, int32_t x2)
 {
-	long x, y1, y2, twall, bwall;
+	int32_t x, y1, y2, twall, bwall;
 
 	y1 = uwall[x1]; y2 = y1;
 	for(x=x1;x<=x2;x++)
@@ -4181,17 +4181,17 @@
 
 
 #ifdef SUPERBUILD
-static void drawvox(long dasprx, long daspry, long dasprz, long dasprang,
-		  long daxscale, long dayscale, unsigned char daindex,
-		  signed char dashade, unsigned char dapal, long *daumost, long *dadmost)
+static void drawvox(int32_t dasprx, int32_t daspry, int32_t dasprz, int32_t dasprang,
+		  int32_t daxscale, int32_t dayscale, unsigned char daindex,
+		  signed char dashade, unsigned char dapal, int32_t *daumost, int32_t *dadmost)
 {
-	long i, j, k, x, y, syoff, ggxstart, ggystart, nxoff;
-	long cosang, sinang, sprcosang, sprsinang, backx, backy, gxinc, gyinc;
-	long daxsiz, daysiz, dazsiz, daxpivot, daypivot, dazpivot;
-	long daxscalerecip, dayscalerecip, cnt, gxstart, gystart, odayscale;
-	long l1, l2, slabxoffs, xyvoxoffs, *longptr;
-	long lx, rx, nx, ny, x1=0, y1=0, z1, x2=0, y2=0, z2, yplc, yinc=0;
-	long yoff, xs=0, ys=0, xe, ye, xi=0, yi=0, cbackx, cbacky, dagxinc, dagyinc;
+	int32_t i, j, k, x, y, syoff, ggxstart, ggystart, nxoff;
+	int32_t cosang, sinang, sprcosang, sprsinang, backx, backy, gxinc, gyinc;
+	int32_t daxsiz, daysiz, dazsiz, daxpivot, daypivot, dazpivot;
+	int32_t daxscalerecip, dayscalerecip, cnt, gxstart, gystart, odayscale;
+	int32_t l1, l2, slabxoffs, xyvoxoffs, *longptr;
+	int32_t lx, rx, nx, ny, x1=0, y1=0, z1, x2=0, y2=0, z2, yplc, yinc=0;
+	int32_t yoff, xs=0, ys=0, xe, ye, xi=0, yi=0, cbackx, cbacky, dagxinc, dagyinc;
 	short *shortptr;
 	char *voxptr, *voxend, *davoxptr, oand, oand16, oand32;
 
@@ -4223,7 +4223,7 @@
 	daxscalerecip = (1<<30)/daxscale;
 	dayscalerecip = (1<<30)/dayscale;
 
-	longptr = (long *)davoxptr;
+	longptr = (int32_t *)davoxptr;
 	daxsiz = longptr[0]; daysiz = longptr[1]; dazsiz = longptr[2];
 	daxpivot = longptr[3]; daypivot = longptr[4]; dazpivot = longptr[5];
 	davoxptr += (6<<2);
@@ -4259,7 +4259,7 @@
 	if ((klabs(globalposz-dasprz)>>10) >= klabs(odayscale)) return;
 	syoff = divscale21(globalposz-dasprz,odayscale) + (dazpivot<<7);
 	yoff = ((klabs(gxinc)+klabs(gyinc))>>1);
-	longptr = (long *)davoxptr;
+	longptr = (int32_t *)davoxptr;
 	xyvoxoffs = ((daxsiz+1)<<2);
 
 	for(cnt=0;cnt<8;cnt++)
@@ -4392,22 +4392,22 @@
 #endif
 
 
-static void drawsprite (long snum)
+static void drawsprite (int32_t snum)
 {
 	spritetype *tspr;
 	sectortype *sec;
-	long startum, startdm, sectnum, xb, yp, cstat;
-	long siz, xsiz, ysiz, xoff, yoff, xspan, yspan;
-	long x1, y1, x2, y2, lx, rx, dalx2, darx2, i, j, k, x, linum, linuminc;
-	long yinc, z, z1, z2, xp1, yp1, xp2, yp2;
-	long xv, yv, top, topinc, bot, botinc, hplc, hinc;
-	long cosang, sinang, dax, day, lpoint, lmax, rpoint, rmax, dax1, dax2, y;
-	long npoints, npoints2, zz, t, zsgn, zzsgn;
+	int32_t startum, startdm, sectnum, xb, yp, cstat;
+	int32_t siz, xsiz, ysiz, xoff, yoff, xspan, yspan;
+	int32_t x1, y1, x2, y2, lx, rx, dalx2, darx2, i, j, k, x, linum, linuminc;
+	int32_t yinc, z, z1, z2, xp1, yp1, xp2, yp2;
+	int32_t xv, yv, top, topinc, bot, botinc, hplc, hinc;
+	int32_t cosang, sinang, dax, day, lpoint, lmax, rpoint, rmax, dax1, dax2, y;
+	int32_t npoints, npoints2, zz, t, zsgn, zzsgn;
 	short tilenum, spritenum;
 	char swapped, daclip;
 
     #ifdef SUPERBUILD
-        long *longptr;
+        int32_t *longptr;
     #endif
 
 	tspr = tspriteptr[snum];
@@ -4592,7 +4592,7 @@
 			globalzd = (((globalposz-z2)*globalyscale)<<8);
 		}
 
-		qinterpolatedown16((long *)&lwall[lx],rx-lx+1,linum,linuminc);
+		qinterpolatedown16((int32_t *)&lwall[lx],rx-lx+1,linum,linuminc);
 		clearbuf(&swall[lx],rx-lx+1,mulscale19(yp,xdimscale));
 
 		if ((cstat&2) == 0)
@@ -5048,7 +5048,7 @@
 			{
 				yinc = divscale16(ysi[zz]-ysi[z],xsi[zz]-xsi[z]);
 				y = ysi[z] + mulscale16((dax1<<16)-xsi[z],yinc);
-				qinterpolatedown16short((long *)(&uwall[dax1]),dax2-dax1,y,yinc);
+				qinterpolatedown16short((int32_t *)(&uwall[dax1]),dax2-dax1,y,yinc);
 			}
 		}
 
@@ -5063,7 +5063,7 @@
 			{
 				yinc = divscale16(ysi[zz]-ysi[z],xsi[zz]-xsi[z]);
 				y = ysi[zz] + mulscale16((dax1<<16)-xsi[zz],yinc);
-				qinterpolatedown16short((long *)(&dwall[dax1]),dax2-dax1,y,yinc);
+				qinterpolatedown16short((int32_t *)(&dwall[dax1]),dax2-dax1,y,yinc);
 			}
 		}
 
@@ -5215,7 +5215,7 @@
 				break;
 			}
 
-		longptr = (long *)voxoff[tilenum][0];
+		longptr = (int32_t *)voxoff[tilenum][0];
 		//if (!(cstat&128)) tspr->z -= mulscale6(longptr[5],(long)tspr->yrepeat);
 		if (!(cstat&128))
         {
@@ -5286,8 +5286,8 @@
 
 void drawmasks(void)
 {
-	long i, j, k, l, gap, xs, ys, xp, yp, yoff, yspan;
-	/* long zs, zp; */
+	int32_t i, j, k, l, gap, xs, ys, xp, yp, yoff, yspan;
+	/* int32_t zs, zp; */
 
 	for(i=spritesortcnt-1;i>=0;i--) tspriteptr[i] = &tsprite[i];
 	for(i=spritesortcnt-1;i>=0;i--)
@@ -5319,7 +5319,7 @@
 			for(l=i;l>=0;l-=gap)
 			{
 				if (spritesy[l] <= spritesy[l+gap]) break;
-				swaplong((long *)&tspriteptr[l],(long *)&tspriteptr[l+gap]);
+				swaplong((int32_t *)&tspriteptr[l],(int32_t *)&tspriteptr[l+gap]);
 				swaplong(&spritesx[l],&spritesx[l+gap]);
 				swaplong(&spritesy[l],&spritesy[l+gap]);
 			}
@@ -5350,7 +5350,7 @@
 				for(l=i;l<k;l++)
 					if (klabs(spritesz[k]-globalposz) < klabs(spritesz[l]-globalposz))
 					{
-						swaplong((long *)&tspriteptr[k],(long *)&tspriteptr[l]);
+						swaplong((int32_t *)&tspriteptr[k],(int32_t *)&tspriteptr[l]);
 						swaplong(&spritesx[k],&spritesx[l]);
 						swaplong(&spritesy[k],&spritesy[l]);
 						swaplong(&spritesz[k],&spritesz[l]);
@@ -5359,7 +5359,7 @@
 				for(l=i;l<k;l++)
 					if (tspriteptr[k]->statnum < tspriteptr[l]->statnum)
 					{
-						swaplong((long *)&tspriteptr[k],(long *)&tspriteptr[l]);
+						swaplong((int32_t *)&tspriteptr[k],(int32_t *)&tspriteptr[l]);
 						swaplong(&spritesx[k],&spritesx[l]);
 						swaplong(&spritesy[k],&spritesy[l]);
 					}
@@ -5428,7 +5428,7 @@
 }
 
 
-int setsprite(short spritenum, long newx, long newy, long newz)
+int setsprite(short spritenum, int32_t newx, int32_t newy, int32_t newz)
 {
 	short tempsectnum;
 
@@ -5449,7 +5449,7 @@
 
 void initspritelists(void)
 {
-	long i;
+	int32_t i;
 
 	for (i=0;i<MAXSECTORS;i++)     /* Init doubly-linked sprite sector lists */
 		headspritesect[i] = -1;
@@ -5606,11 +5606,11 @@
 }
 
 
-int nextsectorneighborz(short sectnum, long thez,
+int nextsectorneighborz(short sectnum, int32_t thez,
                         short topbottom, short direction)
 {
 	walltype *wal;
-	long i, testz, nextz;
+	int32_t i, testz, nextz;
 	short sectortouse;
 
 	if (direction == 1) nextz = 0x7fffffff; else nextz = 0x80000000;
@@ -5672,13 +5672,13 @@
 }
 
 
-int cansee(long x1, long y1, long z1, short sect1,
-            long x2, long y2, long z2, short sect2)
+int cansee(int32_t x1, int32_t y1, int32_t z1, short sect1,
+            int32_t x2, int32_t y2, int32_t z2, short sect2)
 {
 	sectortype *sec;
 	walltype *wal, *wal2;
-	long i, cnt, nexts, x, y, z, cz, fz, dasectnum, dacnt, danum;
-	long x21, y21, z21, x31, y31, x34, y34, bot, t;
+	int32_t i, cnt, nexts, x, y, z, cz, fz, dasectnum, dacnt, danum;
+	int32_t x21, y21, z21, x31, y31, x34, y34, bot, t;
 
 	if ((x1 == x2) && (y1 == y2)) return(sect1 == sect2);
 
@@ -5720,11 +5720,11 @@
 }
 
 
-int lintersect(long x1, long y1, long z1, long x2, long y2, long z2,
-               long x3, long y3, long x4, long y4, long *intx,
-               long *inty, long *intz)
+int lintersect(int32_t x1, int32_t y1, int32_t z1, int32_t x2, int32_t y2, int32_t z2,
+               int32_t x3, int32_t y3, int32_t x4, int32_t y4, int32_t *intx,
+               int32_t *inty, int32_t *intz)
 {     /* p1 to p2 is a line segment */
-	long x21, y21, x34, y34, x31, y31, bot, topt, topu, t;
+	int32_t x21, y21, x34, y34, x31, y31, bot, topt, topu, t;
 
 	x21 = x2-x1; x34 = x3-x4;
 	y21 = y2-y1; y34 = y3-y4;
@@ -5750,11 +5750,11 @@
 }
 
 
-int rintersect(long x1, long y1, long z1, long vx, long vy, long vz,
-               long x3, long y3, long x4, long y4, long *intx,
-               long *inty, long *intz)
+int rintersect(int32_t x1, int32_t y1, int32_t z1, int32_t vx, int32_t vy, int32_t vz,
+               int32_t x3, int32_t y3, int32_t x4, int32_t y4, int32_t *intx,
+               int32_t *inty, int32_t *intz)
 {     /* p1 towards p2 is a ray */
-	long x34, y34, x31, y31, bot, topt, topu, t;
+	int32_t x34, y34, x31, y31, bot, topt, topu, t;
 
 	x34 = x3-x4; y34 = y3-y4;
 	bot = vx*y34 - vy*x34;
@@ -5779,19 +5779,19 @@
 }
 
 
-int hitscan(long xs, long ys, long zs, short sectnum,
-            long vx, long vy, long vz,
+int hitscan(int32_t xs, int32_t ys, int32_t zs, short sectnum,
+            int32_t vx, int32_t vy, int32_t vz,
 	        short *hitsect, short *hitwall, short *hitsprite,
-	        long *hitx, long *hity, long *hitz, unsigned long cliptype)
+	        int32_t *hitx, int32_t *hity, int32_t *hitz, uint32_t  cliptype)
 {
 	sectortype *sec;
 	walltype *wal, *wal2;
 	spritetype *spr;
-	long z, zz, x1, y1=0, z1=0, x2, y2, x3, y3, x4, y4, intx, inty, intz;
-	long topt, topu, bot, dist, offx, offy, cstat;
-	long i, j, k, l, tilenum, xoff, yoff, dax, day, daz, daz2;
-	long ang, cosang, sinang, xspan, yspan, xrepeat, yrepeat;
-	long dawalclipmask, dasprclipmask;
+	int32_t z, zz, x1, y1=0, z1=0, x2, y2, x3, y3, x4, y4, intx, inty, intz;
+	int32_t topt, topu, bot, dist, offx, offy, cstat;
+	int32_t i, j, k, l, tilenum, xoff, yoff, dax, day, daz, daz2;
+	int32_t ang, cosang, sinang, xspan, yspan, xrepeat, yrepeat;
+	int32_t dawalclipmask, dasprclipmask;
 	short tempshortcnt, tempshortnum, dasector, startwall, endwall;
 	short nextsector;
 	char clipyou;
@@ -6052,14 +6052,14 @@
 }
 
 
-int neartag(long xs, long ys, long zs, short sectnum, short ange,
+int neartag(int32_t xs, int32_t ys, int32_t zs, short sectnum, short ange,
             short *neartagsector, short *neartagwall, short *neartagsprite,
-            long *neartaghitdist, long neartagrange, char tagsearch)
+            int32_t *neartaghitdist, int32_t neartagrange, char tagsearch)
 {
 	walltype *wal, *wal2;
 	spritetype *spr;
-	long i, z, zz, xe, ye, ze, x1, y1, z1, x2, y2, intx, inty, intz;
-	long topt, topu, bot, dist, offx, offy, vx, vy, vz;
+	int32_t i, z, zz, xe, ye, ze, x1, y1, z1, x2, y2, intx, inty, intz;
+	int32_t topt, topu, bot, dist, offx, offy, vx, vy, vz;
 	short tempshortcnt, tempshortnum, dasector, startwall, endwall;
 	short nextsector, good;
 
@@ -6173,7 +6173,7 @@
 }
 
 
-void dragpoint(short pointhighlight, long dax, long day)
+void dragpoint(short pointhighlight, int32_t dax, int32_t day)
 {
 	short cnt, tempshort;
 
@@ -6218,7 +6218,7 @@
 
 int lastwall(short point)
 {
-	long i, j, cnt;
+	int32_t i, j, cnt;
 
 	if ((point > 0) && (wall[point-1].point2 == point)) return(point-1);
 	i = point;
@@ -6242,9 +6242,9 @@
 }                                                        \
 
 
-static void keepaway (long *x, long *y, long w)
+static void keepaway (int32_t *x, int32_t *y, int32_t w)
 {
-	long dx, dy, ox, oy, x1, y1;
+	int32_t dx, dy, ox, oy, x1, y1;
 	char first;
 
 	x1 = clipit[w].x1; dx = clipit[w].x2-x1;
@@ -6260,10 +6260,10 @@
 }
 
 
-static int raytrace(long x3, long y3, long *x4, long *y4)
+static int raytrace(int32_t x3, int32_t y3, int32_t *x4, int32_t *y4)
 {
-	long x1, y1, x2, y2, bot, topu, nintx, ninty, cnt, z, hitwall;
-	long x21, y21, x43, y43;
+	int32_t x1, y1, x2, y2, bot, topu, nintx, ninty, cnt, z, hitwall;
+	int32_t x21, y21, x43, y43;
 
 	hitwall = -1;
 	for(z=clipnum-1;z>=0;z--)
@@ -6295,21 +6295,21 @@
 
 
 /* !!! ugh...move this var into clipmove as a parameter, and update build2.txt! */
-long clipmoveboxtracenum = 3;
-int clipmove (long *x, long *y, long *z, short *sectnum,
-              long xvect, long yvect, long walldist, long ceildist,
-              long flordist, unsigned long cliptype)
+int32_t clipmoveboxtracenum = 3;
+int clipmove (int32_t *x, int32_t *y, int32_t *z, short *sectnum,
+              int32_t xvect, int32_t yvect, int32_t walldist, int32_t ceildist,
+              int32_t flordist, uint32_t  cliptype)
 {
 	walltype *wal, *wal2;
 	spritetype *spr;
 	sectortype *sec, *sec2;
-	long i, j, templong1, templong2;
-	long oxvect, oyvect, goalx, goaly, intx, inty, lx, ly, retval;
-	long k, l, clipsectcnt, startwall, endwall, cstat, dasect;
-	long x1, y1, x2, y2, cx, cy, rad, xmin, ymin, xmax, ymax, daz, daz2;
-	long bsz, dax, day, xoff, yoff, xspan, yspan, cosang, sinang, tilenum;
-	long xrepeat, yrepeat, gx, gy, dx, dy, dasprclipmask, dawalclipmask;
-	long hitwall, cnt, clipyou;
+	int32_t i, j, templong1, templong2;
+	int32_t oxvect, oyvect, goalx, goaly, intx, inty, lx, ly, retval;
+	int32_t k, l, clipsectcnt, startwall, endwall, cstat, dasect;
+	int32_t x1, y1, x2, y2, cx, cy, rad, xmin, ymin, xmax, ymax, daz, daz2;
+	int32_t bsz, dax, day, xoff, yoff, xspan, yspan, cosang, sinang, tilenum;
+	int32_t xrepeat, yrepeat, gx, gy, dx, dy, dasprclipmask, dawalclipmask;
+	int32_t hitwall, cnt, clipyou;
 
 	if (((xvect|yvect) == 0) || (*sectnum < 0)) return(0);
 	retval = 0;
@@ -6618,14 +6618,14 @@
 }
 
 
-int pushmove(long *x, long *y, long *z, short *sectnum,
-             long walldist, long ceildist, long flordist,
-             unsigned long cliptype)
+int pushmove(int32_t *x, int32_t *y, int32_t *z, short *sectnum,
+             int32_t walldist, int32_t ceildist, int32_t flordist,
+             uint32_t  cliptype)
 {
 	sectortype *sec, *sec2;
 	walltype *wal;
-	long i, j, k, t, dx, dy, dax, day, daz, daz2, bad, dir;
-	long dasprclipmask, dawalclipmask;
+	int32_t i, j, k, t, dx, dy, dax, day, daz, daz2, bad, dir;
+	int32_t dasprclipmask, dawalclipmask;
 	short startwall, endwall, clipsectcnt;
 	char bad2;
 
@@ -6766,10 +6766,10 @@
    Note: Inside uses cross_product and return as soon as the point switch
          from one side to the other.
  */
-void updatesector(long x, long y, short *sectnum)
+void updatesector(int32_t x, int32_t y, short *sectnum)
 {
 	walltype *wal;
-	long i, j;
+	int32_t i, j;
 
 	if (inside(x,y,*sectnum) == 1) return;
 
@@ -6802,9 +6802,9 @@
 }
 
 
-void rotatepoint(long xpivot, long ypivot, long x, long y, short daang, long *x2, long *y2)
+void rotatepoint(int32_t xpivot, int32_t ypivot, int32_t x, int32_t y, short daang, int32_t *x2, int32_t *y2)
 {
-	long dacos, dasin;
+	int32_t dacos, dasin;
 
 	dacos = sintable[(daang+2560)&2047];
 	dasin = sintable[(daang+2048)&2047];
@@ -6828,9 +6828,9 @@
 	readmousebstatus(bstatus);
 }
 
-void draw2dgrid(long posxe, long posye, short ange, long zoome, short gride)
+void draw2dgrid(int32_t posxe, int32_t posye, short ange, int32_t zoome, short gride)
 {
-	long i, xp1, yp1, xp2=0, yp2, tempy, templong;
+	int32_t i, xp1, yp1, xp2=0, yp2, tempy, tempint;
 	char mask;
 
 	if (gride > 0)
@@ -6846,7 +6846,7 @@
                         #ifdef PLATFORM_DOS
 			koutp(0x3ce,0x8);
                         #endif
-                        templong = ((yp1*640+pageoffset)>>3)+(long)_getVideoBase();
+                        tempint = ((yp1*640+pageoffset)>>3)+(int32_t)_getVideoBase();
 			tempy = yp2-yp1+1;
 			mask = 0;
 			xp1 = 320-mulscale14(posxe+131072,zoome);
@@ -6906,10 +6906,10 @@
 	}
 }
 
-void draw2dscreen(long posxe, long posye, short ange, long zoome, short gride)
+void draw2dscreen(int32_t posxe, int32_t posye, short ange, int32_t zoome, short gride)
 {
 	walltype *wal;
-	long i, j, xp1, yp1, xp2, yp2, templong;
+	int32_t i, j, xp1, yp1, xp2, yp2, tempint;
 	char col;
 
 	if (qsetmode == 200) return;
@@ -6986,32 +6986,32 @@
 					}
 
 #ifdef PLATFORM_DOS
-					templong = (mul5(200+yp1)<<7)+(320+xp1)+pageoffset;
+					tempint = (mul5(200+yp1)<<7)+(320+xp1)+pageoffset;
 #else
-					templong = (mul5(200+yp1)<<7)+(320+xp1);
+					tempint = (mul5(200+yp1)<<7)+(320+xp1);
 #endif
 
 					setcolor16((long)col);
 
-					drawpixel16(templong-2-1280);
-					drawpixel16(templong-1-1280);
-					drawpixel16(templong+0-1280);
-					drawpixel16(templong+1-1280);
-					drawpixel16(templong+2-1280);
+					drawpixel16(tempint-2-1280);
+					drawpixel16(tempint-1-1280);
+					drawpixel16(tempint+0-1280);
+					drawpixel16(tempint+1-1280);
+					drawpixel16(tempint+2-1280);
 
-					drawpixel16(templong-2+1280);
-					drawpixel16(templong-1+1280);
-					drawpixel16(templong+0+1280);
-					drawpixel16(templong+1+1280);
-					drawpixel16(templong+2+1280);
+					drawpixel16(tempint-2+1280);
+					drawpixel16(tempint-1+1280);
+					drawpixel16(tempint+0+1280);
+					drawpixel16(tempint+1+1280);
+					drawpixel16(tempint+2+1280);
 
-					drawpixel16(templong-2-640);
-					drawpixel16(templong-2+0);
-					drawpixel16(templong-2+640);
+					drawpixel16(tempint-2-640);
+					drawpixel16(tempint-2+0);
+					drawpixel16(tempint-2+640);
 
-					drawpixel16(templong+2-640);
-					drawpixel16(templong+2+0);
-					drawpixel16(templong+2+640);
+					drawpixel16(tempint+2-640);
+					drawpixel16(tempint+2+0);
+					drawpixel16(tempint+2+640);
 				}
 	}
 	faketimerhandler();
@@ -7040,32 +7040,32 @@
 						if (((200+yp1) >= 2) && ((200+yp1) <= ydim16-3))
 						{
 #ifdef PLATFORM_DOS
-							templong = (mul5(200+yp1)<<7)+(320+xp1)+pageoffset;
+							tempint = (mul5(200+yp1)<<7)+(320+xp1)+pageoffset;
 #else
-							templong = (mul5(200+yp1)<<7)+(320+xp1);
+							tempint = (mul5(200+yp1)<<7)+(320+xp1);
 #endif
 
 							setcolor16((long)col);
-							drawpixel16(templong-1-1280);
-							drawpixel16(templong+0-1280);
-							drawpixel16(templong+1-1280);
+							drawpixel16(tempint-1-1280);
+							drawpixel16(tempint+0-1280);
+							drawpixel16(tempint+1-1280);
 
-							drawpixel16(templong-1+1280);
-							drawpixel16(templong+0+1280);
-							drawpixel16(templong+1+1280);
+							drawpixel16(tempint-1+1280);
+							drawpixel16(tempint+0+1280);
+							drawpixel16(tempint+1+1280);
 
-							drawpixel16(templong-2-640);
-							drawpixel16(templong-2+0);
-							drawpixel16(templong-2+640);
+							drawpixel16(tempint-2-640);
+							drawpixel16(tempint-2+0);
+							drawpixel16(tempint-2+640);
 
-       						drawpixel16(templong+2-640);
-							drawpixel16(templong+2+0);
-							drawpixel16(templong+2+640);
+       						drawpixel16(tempint+2-640);
+							drawpixel16(tempint+2+0);
+							drawpixel16(tempint+2+640);
 
-							drawpixel16(templong+1+640);
-							drawpixel16(templong-1+640);
-							drawpixel16(templong+1-640);
-							drawpixel16(templong-1-640);
+							drawpixel16(tempint+1+640);
+							drawpixel16(tempint-1+640);
+							drawpixel16(tempint+1-640);
+							drawpixel16(tempint-1-640);
 
 							xp2 = mulscale11(sintable[(sprite[j].ang+2560)&2047],zoome) / 768;
 							yp2 = mulscale11(sintable[(sprite[j].ang+2048)&2047],zoome) / 768;
@@ -7107,9 +7107,9 @@
  *  other cause flicker, so I have this function here so the shadow can
  *  be drawn with _noupdate, and the actual string is draw with an update.
  */
-static void __printext256(long xpos, long ypos, short col, short backcol, char name[82], char fontsize, int should_update)
+static void __printext256(int32_t xpos, int32_t ypos, short col, short backcol, char name[82], char fontsize, int should_update)
 {
-	long stx, i, x, y, charxsiz;
+	int32_t stx, i, x, y, charxsiz;
 	char *fontptr, *letptr, *ptr;
 
 	stx = xpos;
@@ -7140,13 +7140,13 @@
 }
 
 
-void printext256(long xpos, long ypos, short col, short backcol, char name[82], char fontsize)
+void printext256(int32_t xpos, int32_t ypos, short col, short backcol, char name[82], char fontsize)
 {
     __printext256(xpos, ypos, col, backcol, name, fontsize, 1);
 }
 
 
-void printext256_noupdate(long xpos, long ypos, short col, short backcol, char name[82], char fontsize)
+void printext256_noupdate(int32_t xpos, int32_t ypos, short col, short backcol, char name[82], char fontsize)
 {
     __printext256(xpos, ypos, col, backcol, name, fontsize, 0);
 }
@@ -7181,21 +7181,21 @@
 	fclose(pFile);
 #endif
 
-	return(((unsigned long)randomseed)>>16);
+	return(((uint32_t )randomseed)>>16);
 }
 
 
-void getzrange(long x, long y, long z, short sectnum,
-               long *ceilz, long *ceilhit, long *florz, long *florhit,
-               long walldist, unsigned long cliptype)
+void getzrange(int32_t x, int32_t y, int32_t z, short sectnum,
+               int32_t *ceilz, int32_t *ceilhit, int32_t *florz, int32_t *florhit,
+               int32_t walldist, uint32_t  cliptype)
 {
 	sectortype *sec;
 	walltype *wal, *wal2;
 	spritetype *spr;
-	long clipsectcnt, startwall, endwall, tilenum, xoff, yoff, dax, day;
-	long xmin, ymin, xmax, ymax, i, j, k, l, daz, daz2, dx, dy;
-	long x1, y1, x2, y2, x3, y3, x4, y4, ang, cosang, sinang;
-	long xspan, yspan, xrepeat, yrepeat, dasprclipmask, dawalclipmask;
+	int32_t clipsectcnt, startwall, endwall, tilenum, xoff, yoff, dax, day;
+	int32_t xmin, ymin, xmax, ymax, i, j, k, l, daz, daz2, dx, dy;
+	int32_t x1, y1, x2, y2, x3, y3, x4, y4, ang, cosang, sinang;
+	int32_t xspan, yspan, xrepeat, yrepeat, dasprclipmask, dawalclipmask;
 	short cstat;
 	char clipyou;
 
@@ -7380,9 +7380,9 @@
 }
 
 
-void setview(long x1, long y1, long x2, long y2)
+void setview(int32_t x1, int32_t y1, int32_t x2, int32_t y2)
 {
-	long i;
+	int32_t i;
 
 	windowx1 = x1; wx1 = (x1<<12);
 	windowy1 = y1; wy1 = (y1<<12);
@@ -7412,7 +7412,7 @@
 }
 
 
-void setaspect(long daxrange, long daaspect)
+void setaspect(int32_t daxrange, int32_t daaspect)
 {
 	viewingrange = daxrange;
 	viewingrangerecip = divscale32(1L,daxrange);
@@ -7430,11 +7430,11 @@
 }
 
 
-void rotatesprite(long sx, long sy, long z, short a, short picnum,
+void rotatesprite(int32_t sx, int32_t sy, int32_t z, short a, short picnum,
                   signed char dashade, char dapalnum, char dastat,
-                  long cx1, long cy1, long cx2, long cy2)
+                  int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2)
 {
-	long i;
+	int32_t i;
 	permfifotype *per, *per2;
 
 	if ((cx1 > cx2) || (cy1 > cy2)) return;
@@ -7503,9 +7503,9 @@
 }
 
 
-static int getclosestcol(long r, long g, long b)
+static int getclosestcol(int32_t r, int32_t g, int32_t b)
 {
-	long i, j, k, dist, mindist, retcol;
+	int32_t i, j, k, dist, mindist, retcol;
 	char *pal1;
 
 	j = (r>>3)*FASTPALGRIDSIZ*FASTPALGRIDSIZ+(g>>3)*FASTPALGRIDSIZ+(b>>3)+FASTPALGRIDSIZ*FASTPALGRIDSIZ+FASTPALGRIDSIZ+1;
@@ -7551,10 +7551,10 @@
 }
 
 
-void makepalookup(long palnum, char *remapbuf, signed char r,
+void makepalookup(int32_t palnum, char *remapbuf, signed char r,
                   signed char g, signed char b, char dastat)
 {
-	long i, j, dist, palscale;
+	int32_t i, j, dist, palscale;
 	char *ptr, *ptr2;
 
 	if (paletteloaded == 0) return;
@@ -7563,7 +7563,7 @@
 	{
 			/* Allocate palookup buffer */
 		if ((palookup[palnum] = (char *)kkmalloc(numpalookups<<8)) == NULL)
-			allocache((long *)&palookup[palnum],numpalookups<<8,&permanentlock);
+			allocache((int32_t *)&palookup[palnum],numpalookups<<8,&permanentlock);
 	}
 
 	if (dastat == 0) return;
@@ -7610,7 +7610,7 @@
 
 void setbrightness(char dabrightness, unsigned char *dapal)
 {
-	long i, j, k;
+	int32_t i, j, k;
 
 	curbrightness = min(max((long)dabrightness,0),15);
 
@@ -7641,10 +7641,10 @@
 }
 
 
-static void fillpolygon(long npoints)
+static void fillpolygon(int32_t npoints)
 {
-	long z, zz, x1, y1, x2, y2, miny, maxy, y, xinc, cnt;
-	long ox, oy, bx, by, p, day1, day2;
+	int32_t z, zz, x1, y1, x2, y2, miny, maxy, y, xinc, cnt;
+	int32_t ox, oy, bx, by, p, day1, day2;
 	short *ptr, *ptr2;
 
 	miny = 0x7fffffff; maxy = 0x80000000;
@@ -7742,10 +7742,10 @@
 }
 
 
-static int clippoly (long npoints, long clipstat)
+static int clippoly (int32_t npoints, int32_t clipstat)
 {
-	long z, zz, s1, s2, t, npoints2, start2, z1, z2, z3, z4, splitcnt;
-	long cx1, cy1, cx2, cy2;
+	int32_t z, zz, s1, s2, t, npoints2, start2, z1, z2, z3, z4, splitcnt;
+	int32_t cx1, cy1, cx2, cy2;
 
 	cx1 = windowx1;
 	cy1 = windowy1;
@@ -7947,16 +7947,16 @@
 }
 
 
-void drawmapview(long dax, long day, long zoome, short ang)
+void drawmapview(int32_t dax, int32_t day, int32_t zoome, short ang)
 {
 	walltype *wal;
 	sectortype *sec;
 	spritetype *spr;
-	long tilenum, xoff, yoff, i, j, k, l, cosang, sinang, xspan, yspan;
-	long xrepeat, yrepeat, x, y, x1, y1, x2, y2, x3, y3, x4, y4, bakx1, baky1;
-	long s, w, ox, oy, startwall, cx1, cy1, cx2, cy2;
-	long bakgxvect, bakgyvect, sortnum, gap, npoints;
-	long xvect, yvect, xvect2, yvect2, daslope;
+	int32_t tilenum, xoff, yoff, i, j, k, l, cosang, sinang, xspan, yspan;
+	int32_t xrepeat, yrepeat, x, y, x1, y1, x2, y2, x3, y3, x4, y4, bakx1, baky1;
+	int32_t s, w, ox, oy, startwall, cx1, cy1, cx2, cy2;
+	int32_t bakgxvect, bakgyvect, sortnum, gap, npoints;
+	int32_t xvect, yvect, xvect2, yvect2, daslope;
 
 	beforedrawrooms = 0;
 	totalarea += (windowx2+1-windowx1)*(windowy2+1-windowy1);
@@ -8204,9 +8204,9 @@
 }
 
 
-void clearview(long dacol)
+void clearview(int32_t dacol)
 {
-	long p, y, dx;
+	int32_t p, y, dx;
 
 	if (qsetmode != 200) return;
 
@@ -8231,9 +8231,9 @@
 }
 
 
-void clearallviews(long dacol)
+void clearallviews(int32_t dacol)
 {
-	long i;
+	int32_t i;
 
 	if (qsetmode != 200) return;
 	dacol += (dacol<<8); dacol += (dacol<<16);
@@ -8258,28 +8258,28 @@
 }
 
 
-void plotpixel(long x, long y, char col)
+void plotpixel(int32_t x, int32_t y, char col)
 {
 	drawpixel(ylookup[y]+x+frameplace,(long)col);
 }
 
 
-unsigned char getpixel(long x, long y)
+unsigned char getpixel(int32_t x, int32_t y)
 {
 	return(readpixel(ylookup[y]+x+frameplace));
 }
 
 	/* MUST USE RESTOREFORDRAWROOMS AFTER DRAWING */
-static long setviewcnt = 0;
-static long bakvidoption[4];
-static long bakframeplace[4], bakxsiz[4], bakysiz[4];
-static long bakwindowx1[4], bakwindowy1[4];
-static long bakwindowx2[4], bakwindowy2[4];
+static int32_t setviewcnt = 0;
+static int32_t bakvidoption[4];
+static int32_t bakframeplace[4], bakxsiz[4], bakysiz[4];
+static int32_t bakwindowx1[4], bakwindowy1[4];
+static int32_t bakwindowx2[4], bakwindowy2[4];
 
 
-void setviewtotile(short tilenume, long xsiz, long ysiz)
+void setviewtotile(short tilenume, int32_t xsiz, int32_t ysiz)
 {
-	long i, j;
+	int32_t i, j;
 
 		/* DRAWROOMS TO TILE BACKUP&SET CODE */
 	tilesizx[tilenume] = xsiz; tilesizy[tilenume] = ysiz;
@@ -8300,7 +8300,7 @@
 
 void setviewback(void)
 {
-	long i, j, k;
+	int32_t i, j, k;
 
 	if (setviewcnt <= 0) return;
 	setviewcnt--;
@@ -8322,7 +8322,7 @@
 
 void squarerotatetile(short tilenume)
 {
-	long i, j, k, xsiz, ysiz;
+	int32_t i, j, k, xsiz, ysiz;
 	unsigned char *ptr1, *ptr2;
 
 	xsiz = tilesizx[tilenume]; ysiz = tilesizy[tilenume];
@@ -8343,12 +8343,12 @@
 }
 
 
-void preparemirror(long dax, long day, long daz,
-                   short daang, long dahoriz, short dawall,
-                   short dasector, long *tposx, long *tposy,
+void preparemirror(int32_t dax, int32_t day, int32_t daz,
+                   short daang, int32_t dahoriz, short dawall,
+                   short dasector, int32_t *tposx, int32_t *tposy,
                    short *tang)
 {
-	long i, j, x, y, dx, dy;
+	int32_t i, j, x, y, dx, dy;
 
 	x = wall[dawall].x; dx = wall[wall[dawall].point2].x-x;
 	y = wall[dawall].y; dy = wall[wall[dawall].point2].y-y;
@@ -8364,7 +8364,7 @@
 
 void completemirror(void)
 {
-	long i, dy, p;
+	int32_t i, dy, p;
 
 		/* Can't reverse with uninitialized data */
 	if (inpreparemirror) { inpreparemirror = 0; return; }
@@ -8390,7 +8390,7 @@
 
 int sectorofwall(short theline)
 {
-	long i, gap;
+	int32_t i, gap;
 
 	if ((theline < 0) || (theline >= numwalls)) return(-1);
 	i = wall[theline].nextwall; if (i >= 0) return(wall[i].nextsector);
@@ -8407,9 +8407,9 @@
 }
 
 
-int getceilzofslope(short sectnum, long dax, long day)
+int getceilzofslope(short sectnum, int32_t dax, int32_t day)
 {
-	long dx, dy, i, j;
+	int32_t dx, dy, i, j;
 	walltype *wal;
 
 	if (!(sector[sectnum].ceilingstat&2)) return(sector[sectnum].ceilingz);
@@ -8421,9 +8421,9 @@
 }
 
 
-int getflorzofslope(short sectnum, long dax, long day)
+int getflorzofslope(short sectnum, int32_t dax, int32_t day)
 {
-	long dx, dy, i, j;
+	int32_t dx, dy, i, j;
 	walltype *wal;
 
 	if (!(sector[sectnum].floorstat&2)) return(sector[sectnum].floorz);
@@ -8435,9 +8435,9 @@
 }
 
 
-void getzsofslope(short sectnum, long dax, long day, long *ceilz, long *florz)
+void getzsofslope(short sectnum, int32_t dax, int32_t day, int32_t *ceilz, int32_t *florz)
 {
-	long dx, dy, i, j;
+	int32_t dx, dy, i, j;
 	walltype *wal, *wal2;
 	sectortype *sec;
 
@@ -8455,9 +8455,9 @@
 }
 
 
-void alignceilslope(short dasect, long x, long y, long z)
+void alignceilslope(short dasect, int32_t x, int32_t y, int32_t z)
 {
-	long i, dax, day;
+	int32_t i, dax, day;
 	walltype *wal;
 
 	wal = &wall[sector[dasect].wallptr];
@@ -8473,9 +8473,9 @@
 }
 
 
-void alignflorslope(short dasect, long x, long y, long z)
+void alignflorslope(short dasect, int32_t x, int32_t y, int32_t z)
 {
-	long i, dax, day;
+	int32_t i, dax, day;
 	walltype *wal;
 
 	wal = &wall[sector[dasect].wallptr];
@@ -8493,7 +8493,7 @@
 
 int loopnumofsector(short sectnum, short wallnum)
 {
-	long i, numloops, startwall, endwall;
+	int32_t i, numloops, startwall, endwall;
 
 	numloops = 0;
 	startwall = sector[sectnum].wallptr;
@@ -8509,8 +8509,8 @@
 
 void setfirstwall(short sectnum, short newfirstwall)
 {
-	long i, j, k, numwallsofloop;
-	long startwall, endwall, danumwalls, dagoalloop;
+	int32_t i, j, k, numwallsofloop;
+	int32_t startwall, endwall, danumwalls, dagoalloop;
 
 	startwall = sector[sectnum].wallptr;
 	danumwalls = sector[sectnum].wallnum;
--- a/Engine/src/engine.h
+++ b/Engine/src/engine.h
@@ -36,13 +36,13 @@
  *  information on using these functions that may or may not be accurate. :)
  */
 int initmouse(void);
-int setgamemode(char davidoption, long daxdim, long daydim);
-int getceilzofslope(short sectnum, long dax, long day);
-int getflorzofslope(short sectnum, long dax, long day);
-void getzsofslope(short sectnum, long dax, long day, long *ceilz, long *florz);
-void setaspect(long daxrange, long daaspect);
+int setgamemode(char davidoption, int32_t daxdim, int32_t daydim);
+int getceilzofslope(short sectnum, int32_t dax, int32_t day);
+int getflorzofslope(short sectnum, int32_t dax, int32_t day);
+void getzsofslope(short sectnum, int32_t dax, int32_t day, int32_t *ceilz, int32_t *florz);
+void setaspect(int32_t daxrange, int32_t daaspect);
 int insertsprite(short sectnum, short statnum);
-void updatesector(long x, long y, short *sectnum);
+void updatesector(int32_t x, int32_t y, short *sectnum);
 int lastwall(short point);
 void initspritelists(void);
 int deletesprite(short spritenum);
@@ -56,74 +56,74 @@
 void setmmxoverlay(int isenabled);
 int getmmxoverlay(void);
 void nextpage(void);
-void drawrooms(long daposx, long daposy, long daposz,
-               short daang, long dahoriz, short dacursectnum);
-int loadboard(char *filename, long *daposx, long *daposy,
-			  long *daposz, short *daang, short *dacursectnum);
+void drawrooms(int32_t daposx, int32_t daposy, int32_t daposz,
+               short daang, int32_t dahoriz, short dacursectnum);
+int loadboard(char *filename, int32_t *daposx, int32_t *daposy,
+			  int32_t *daposz, short *daang, short *dacursectnum);
 void drawmasks(void);
-void printext256(long xpos, long ypos, short col, short backcol,
+void printext256(int32_t xpos, int32_t ypos, short col, short backcol,
 			char name[82], char fontsize);
-void printext256_noupdate(long xpos, long ypos, short col, short backcol,
+void printext256_noupdate(int32_t xpos, int32_t ypos, short col, short backcol,
 			char name[82], char fontsize);
 void initengine(void);
 void uninitengine(void);
 int loadpics(char *filename, char* gamedir);
-int saveboard(char *filename, long *daposx, long *daposy, long *daposz,
+int saveboard(char *filename, int32_t *daposx, int32_t *daposy, int32_t *daposz,
                          short *daang, short *dacursectnum);
-void plotpixel(long x, long y, char col);
-unsigned char getpixel(long x, long y);
+void plotpixel(int32_t x, int32_t y, char col);
+unsigned char getpixel(int32_t x, int32_t y);
 void setbrightness(char dabrightness, unsigned char *dapal);
 int screencapture(char *filename, char inverseit);
 void getmousevalues(short *mousx, short *mousy, short *bstatus);
-int clipmove (long *x, long *y, long *z, short *sectnum, long xvect,
-			long yvect, long walldist, long ceildist,
-			long flordist, unsigned long cliptype);
-void getzrange(long x, long y, long z, short sectnum,
-			long *ceilz, long *ceilhit, long *florz, long *florhit,
-			long walldist, unsigned long cliptype);
-int getangle(long xvect, long yvect);
-void alignceilslope(short dasect, long x, long y, long z);
-void alignflorslope(short dasect, long x, long y, long z);
-int hitscan(long xs, long ys, long zs, short sectnum,
-            long vx, long vy, long vz,
+int clipmove (int32_t *x, int32_t *y, int32_t *z, short *sectnum, int32_t xvect,
+			int32_t yvect, int32_t walldist, int32_t ceildist,
+			int32_t flordist, uint32_t  cliptype);
+void getzrange(int32_t x, int32_t y, int32_t z, short sectnum,
+			int32_t *ceilz, int32_t *ceilhit, int32_t *florz, int32_t *florhit,
+			int32_t walldist, uint32_t  cliptype);
+int getangle(int32_t xvect, int32_t yvect);
+void alignceilslope(short dasect, int32_t x, int32_t y, int32_t z);
+void alignflorslope(short dasect, int32_t x, int32_t y, int32_t z);
+int hitscan(int32_t xs, int32_t ys, int32_t zs, short sectnum,
+            int32_t vx, int32_t vy, int32_t vz,
 	        short *hitsect, short *hitwall, short *hitsprite,
-	        long *hitx, long *hity, long *hitz, unsigned long cliptype);
-int inside (long x, long y, short sectnum);
+	        int32_t *hitx, int32_t *hity, int32_t *hitz, uint32_t  cliptype);
+int inside (int32_t x, int32_t y, short sectnum);
 void setfirstwall(short sectnum, short newfirstwall);
-void rotatepoint(long xpivot, long ypivot, long x, long y, short daang,
-			long *x2, long *y2);
-int drawtilescreen(long pictopleft, long picbox);
-void clearview(long dacol);
-void clearallviews(long dacol);
-void draw2dgrid(long posxe, long posye, short ange, long zoome,
+void rotatepoint(int32_t xpivot, int32_t ypivot, int32_t x, int32_t y, short daang,
+			int32_t *x2, int32_t *y2);
+int drawtilescreen(int32_t pictopleft, int32_t picbox);
+void clearview(int32_t dacol);
+void clearallviews(int32_t dacol);
+void draw2dgrid(int32_t posxe, int32_t posye, short ange, int32_t zoome,
 			short gride);
-void draw2dscreen(long posxe, long posye, short ange, long zoome,
+void draw2dscreen(int32_t posxe, int32_t posye, short ange, int32_t zoome,
 			short gride);
 int sectorofwall(short theline);
-int setsprite(short spritenum, long newx, long newy, long newz);
-void dragpoint(short pointhighlight, long dax, long day);
-int ksqrt(long num);
+int setsprite(short spritenum, int32_t newx, int32_t newy, int32_t newz);
+void dragpoint(short pointhighlight, int32_t dax, int32_t day);
+int ksqrt(int32_t num);
 int loopnumofsector(short sectnum, short wallnum);
-int cansee(long x1, long y1, long z1, short sect1,
-            long x2, long y2, long z2, short sect2);
-int lintersect(long x1, long y1, long z1, long x2, long y2, long z2,
-               long x3, long y3, long x4, long y4, long *intx,
-               long *inty, long *intz);
-int rintersect(long x1, long y1, long z1, long vx, long vy, long vz,
-               long x3, long y3, long x4, long y4, long *intx,
-               long *inty, long *intz);
-int allocatepermanenttile(short tilenume, long xsiz, long ysiz);
-void drawline256 (long x1, long y1, long x2, long y2, unsigned char col);
-void copytilepiece(long tilenume1, long sx1, long sy1, long xsiz, long ysiz,
-                   long tilenume2, long sx2, long sy2);
-int nextsectorneighborz(short sectnum, long thez,
+int cansee(int32_t x1, int32_t y1, int32_t z1, short sect1,
+            int32_t x2, int32_t y2, int32_t z2, short sect2);
+int lintersect(int32_t x1, int32_t y1, int32_t z1, int32_t x2, int32_t y2, int32_t z2,
+               int32_t x3, int32_t y3, int32_t x4, int32_t y4, int32_t *intx,
+               int32_t *inty, int32_t *intz);
+int rintersect(int32_t x1, int32_t y1, int32_t z1, int32_t vx, int32_t vy, int32_t vz,
+               int32_t x3, int32_t y3, int32_t x4, int32_t y4, int32_t *intx,
+               int32_t *inty, int32_t *intz);
+int allocatepermanenttile(short tilenume, int32_t xsiz, int32_t ysiz);
+void drawline256 (int32_t x1, int32_t y1, int32_t x2, int32_t y2, unsigned char col);
+void copytilepiece(int32_t tilenume1, int32_t sx1, int32_t sy1, int32_t xsiz, int32_t ysiz,
+                   int32_t tilenume2, int32_t sx2, int32_t sy2);
+int nextsectorneighborz(short sectnum, int32_t thez,
                         short topbottom, short direction);
-int neartag(long xs, long ys, long zs, short sectnum, short ange,
+int neartag(int32_t xs, int32_t ys, int32_t zs, short sectnum, short ange,
             short *neartagsector, short *neartagwall, short *neartagsprite,
-            long *neartaghitdist, long neartagrange, char tagsearch);
-int pushmove(long *x, long *y, long *z, short *sectnum,
-             long walldist, long ceildist, long flordist,
-             unsigned long cliptype);
+            int32_t *neartaghitdist, int32_t neartagrange, char tagsearch);
+int pushmove(int32_t *x, int32_t *y, int32_t *z, short *sectnum,
+             int32_t walldist, int32_t ceildist, int32_t flordist,
+             uint32_t  cliptype);
 #ifdef DBGRECORD
 int krand(int line, char* file);
 #else
@@ -130,25 +130,25 @@
 int krand(void);
 #endif
 void flushperms(void);
-void rotatesprite(long sx, long sy, long z, short a, short picnum,
+void rotatesprite(int32_t sx, int32_t sy, int32_t z, short a, short picnum,
                   signed char dashade, char dapalnum, char dastat,
-                  long cx1, long cy1, long cx2, long cy2);
-void makepalookup(long palnum, char *remapbuf, signed char r,
+                  int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2);
+void makepalookup(int32_t palnum, char *remapbuf, signed char r,
                   signed char g, signed char b, char dastat);
-void drawmapview(long dax, long day, long zoome, short ang);
-void setview(long x1, long y1, long x2, long y2);
-void setviewtotile(short tilenume, long xsiz, long ysiz);
+void drawmapview(int32_t dax, int32_t day, int32_t zoome, short ang);
+void setview(int32_t x1, int32_t y1, int32_t x2, int32_t y2);
+void setviewtotile(short tilenume, int32_t xsiz, int32_t ysiz);
 void setviewback(void);
 void squarerotatetile(short tilenume);
-void preparemirror(long dax, long day, long daz,
-                   short daang, long dahoriz, short dawall,
-                   short dasector, long *tposx, long *tposy,
+void preparemirror(int32_t dax, int32_t day, int32_t daz,
+                   short daang, int32_t dahoriz, short dawall,
+                   short dasector, int32_t *tposx, int32_t *tposy,
                    short *tang);
 void completemirror(void);
-int clipinsidebox(long x, long y, short wallnum, long walldist);
+int clipinsidebox(int32_t x, int32_t y, short wallnum, int32_t walldist);
 
 #ifdef SUPERBUILD
-void qloadkvx(long voxindex, char *filename);
+void qloadkvx(int32_t voxindex, char *filename);
 #endif
 
 #ifdef __cplusplus
--- a/Engine/src/engine_protos.h
+++ b/Engine/src/engine_protos.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 */
@@ -26,37 +26,37 @@
 
 #if 0
 /* game.c */
-extern void initsb(char dadigistat, char damusistat, long dasamplerate, char danumspeakers, char dabytespersample, char daintspersec, char daquality);
+extern void initsb(char dadigistat, char damusistat, int32_t dasamplerate, char danumspeakers, char dabytespersample, char daintspersec, char daquality);
 extern void uninitsb(void);
 extern int loadsong(char *filename);
 extern void musicon(void);
 extern void musicoff(void);
-extern void wsayfollow(char *dafilename, long dafreq, long davol, long *daxplc, long *dayplc, char followstat);
-extern void wsay(char *dafilename, long dafreq, long volume1, long volume2);
+extern void wsayfollow(char *dafilename, int32_t dafreq, int32_t davol, int32_t *daxplc, int32_t *dayplc, char followstat);
+extern void wsay(char *dafilename, int32_t dafreq, int32_t volume1, int32_t volume2);
 extern void preparesndbuf(void);
-extern void setears(long daposx, long daposy, long daxvect, long dayvect);
+extern void setears(int32_t daposx, int32_t daposy, int32_t daxvect, int32_t dayvect);
 extern void timerhandler(void);
 extern void keyhandler(void);
 extern void initlava(void);
 extern void movelava(char *dapic);
-extern void drawtilebackground(long thex, long they, short tilenum, signed char shade, long cx1, long cy1, long cx2, long cy2, char dapalnum);
-extern void printext(long x, long y, char *buffer, short tilenum, char invisiblecol);
+extern void drawtilebackground(int32_t thex, int32_t they, short tilenum, signed char shade, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2, char dapalnum);
+extern void printext(int32_t x, int32_t y, char *buffer, short tilenum, char invisiblecol);
 extern void drawstatusflytime(short snum);
 extern void drawstatusbar(short snum);
 extern void setup3dscreen(void);
-extern void setinterpolation(long *posptr);
-extern void stopinterpolation(long *posptr);
+extern void setinterpolation(int32_t *posptr);
+extern void stopinterpolation(int32_t *posptr);
 extern void updateinterpolations(void);
 extern void restoreinterpolations(void);
 extern void searchmap(short startsector);
 extern void prepareboard(char *daboardfilename);
-extern long changehealth(short snum, short deltahealth);
+extern int32_t changehealth(short snum, short deltahealth);
 extern void changenumbombs(short snum, short deltanumbombs);
 extern void changenummissiles(short snum, short deltanummissiles);
 extern void changenumgrabbers(short snum, short deltanumgrabbers);
-extern void findrandomspot(long *x, long *y, short *sectnum);
+extern void findrandomspot(int32_t *x, int32_t *y, short *sectnum);
 extern void operatesector(short dasector);
-extern void shootgun(short snum, long x, long y, long z, short daang, long dahoriz, short dasectnum, char guntype);
+extern void shootgun(short snum, int32_t x, int32_t y, int32_t z, short daang, int32_t dahoriz, short dasectnum, char guntype);
 extern void operatesprite(short dasprite);
 extern void checktouchsprite(short snum, short sectnum);
 extern void checkgrabbertouchsprite(short snum, short sectnum);
@@ -66,19 +66,19 @@
 extern void fakedomovethings(void);
 extern void fakedomovethingscorrect(void);
 extern void doanimations(void);
-extern void warp(long *x, long *y, long *z, short *daang, short *dasector);
+extern void warp(int32_t *x, int32_t *y, int32_t *z, short *daang, short *dasector);
 extern void warpsprite(short spritenum);
 extern int testneighborsectors(short sect1, short sect2);
 extern void tagcode(void);
-extern void bombexplode(long i);
+extern void bombexplode(int32_t i);
 extern void statuslistcode(void);
 extern void checkmasterslaveswitch(void);
 extern void getpackets(void);
 extern void initplayersprite(short snum);
-extern void analyzesprites(long dax, long day);
-extern void updatesectorz(long x, long y, long z, short *sectnum);
-extern void drawoverheadmap(long cposx, long cposy, long czoom, short cang);
-extern void drawscreen(short snum, long dasmoothratio);
+extern void analyzesprites(int32_t dax, int32_t day);
+extern void updatesectorz(int32_t x, int32_t y, int32_t z, short *sectnum);
+extern void drawoverheadmap(int32_t cposx, int32_t cposy, int32_t czoom, short cang);
+extern void drawscreen(short snum, int32_t dasmoothratio);
 extern int loadgame(void);
 extern int savegame(void);
 extern void faketimerhandler(void);
@@ -86,23 +86,23 @@
 #endif
 
 /* cache1d.c */
-extern void initcache(long dacachestart, long dacachesize);
-extern void allocache(long *newhandle, long newbytes, unsigned char *newlockptr);
-extern void suckcache(long *suckptr);
+extern void initcache(int32_t dacachestart, int32_t dacachesize);
+extern void allocache(int32_t *newhandle, int32_t newbytes, unsigned char *newlockptr);
+extern void suckcache(int32_t *suckptr);
 extern void agecache(void);
 extern void reportandexit(char *errormessage);
-extern long initgroupfile(const char *filename);
+extern int32_t initgroupfile(const char *filename);
 extern void uninitgroupfile(void);
-extern long kopen4load(const char *filename,int readfromGRP);
-extern long kread(long handle, void *buffer, long leng);
-extern long klseek(long handle, long offset, long whence);
-extern long kfilelength(long handle);
-extern void kclose(long handle);
-extern void kdfread(void *buffer, size_t dasizeof, size_t count, long fil);
+extern int32_t kopen4load(const char *filename,int readfromGRP);
+extern int32_t kread(int32_t handle, void *buffer, int32_t leng);
+extern int32_t klseek(int32_t handle, int32_t offset, int32_t whence);
+extern int32_t kfilelength(int32_t handle);
+extern void kclose(int32_t handle);
+extern void kdfread(void *buffer, size_t dasizeof, size_t count, int32_t fil);
 extern void dfread(void *buffer, size_t dasizeof, size_t count, FILE *fil);
 extern void dfwrite(void *buffer, size_t dasizeof, size_t count, FILE *fil);
-extern long compress(char *lzwinbuf, long uncompleng, char *lzwoutbuf);
-extern long uncompress(char *lzwinbuf, long compleng, char *lzwoutbuf);
+extern int32_t compress(char *lzwinbuf, int32_t uncompleng, char *lzwoutbuf);
+extern int32_t uncompress(char *lzwinbuf, int32_t compleng, char *lzwoutbuf);
 
 /* sdl_driver.c */
 extern int using_opengl(void);
@@ -111,32 +111,32 @@
 extern int mprotect_align(const void *addr, size_t len, int prot);
 extern void unprotect_ASM_pages(void);
 extern void _platform_init(int argc, char **argv, const char *title, const char *icon);
-extern int setvesa(long x, long y);
+extern int setvesa(int32_t x, int32_t y);
 extern int screencapture(char *filename, char inverseit);
 extern void setvmode(int mode);
-extern int _setgamemode(char davidoption, long daxdim, long daydim);
+extern int _setgamemode(char davidoption, int32_t daxdim, int32_t daydim);
 extern void getvalidvesamodes(void);
-extern int VBE_setPalette(long start, long num, char *palettebuffer);
-extern int VBE_getPalette(long start, long num, char *palettebuffer);
+extern int VBE_setPalette(int32_t start, int32_t num, char *palettebuffer);
+extern int VBE_getPalette(int32_t start, int32_t num, char *palettebuffer);
 extern void _uninitengine(void);
 extern void uninitvesa(void);
 extern int setupmouse(void);
 extern void readmousexy(short *x, short *y);
 extern void readmousebstatus(short *bstatus);
-extern void _updateScreenRect(long x, long y, long w, long h);
+extern void _updateScreenRect(int32_t x, int32_t y, int32_t w, int32_t h);
 extern void _nextpage(void);
-extern unsigned char readpixel(long offset);
-extern void drawpixel(long offset, unsigned char pixel);
-extern void drawpixels(long offset, unsigned short pixels);
-extern void drawpixelses(long offset, unsigned int pixelses);
+extern unsigned char readpixel(int32_t offset);
+extern void drawpixel(int32_t offset, unsigned char pixel);
+extern void drawpixels(int32_t offset, unsigned short pixels);
+extern void drawpixelses(int32_t offset, unsigned int pixelses);
 extern void setcolor16(int col);
-extern void drawpixel16(long offset);
-extern void fillscreen16(long offset, long color, long blocksize);
-extern void drawline16(long XStart, long YStart, long XEnd, long YEnd, char Color);
+extern void drawpixel16(int32_t offset);
+extern void fillscreen16(int32_t offset, int32_t color, int32_t blocksize);
+extern void drawline16(int32_t XStart, int32_t YStart, int32_t XEnd, int32_t YEnd, char Color);
 extern void clear2dscreen(void);
 extern void _idle(void);
 extern void *_getVideoBase(void);
-extern void setactivepage(long dapagenum);
+extern void setactivepage(int32_t dapagenum);
 extern void limitrate(void);
 extern int inittimer(int);
 extern void uninittimer(void);
@@ -144,7 +144,7 @@
 extern void uninitkeys(void);
 extern void set16color_palette(void);
 extern void restore256_palette(void);
-extern unsigned long getticks(void);
+extern uint32_t  getticks(void);
 
 /* mmulti.c */
 // converted to function pointers
@@ -151,10 +151,10 @@
 /*
 void (*callcommit)(void);
 void (*initcrc)(void);
-long (*getcrc)(char *buffer, short bufleng);
+int32_t (*getcrc)(char *buffer, short bufleng);
 void (*initmultiplayers)(char damultioption, char dacomrateoption, char dapriority);
-void (*sendpacket)(long other, char *bufptr, long messleng);
-void (*setpackettimeout)(long datimeoutcount, long daresendagaincount);
+void (*sendpacket)(int32_t other, char *bufptr, int32_t messleng);
+void (*setpackettimeout)(int32_t datimeoutcount, int32_t daresendagaincount);
 void (*uninitmultiplayers)(void);
 void (*sendlogon)(void);
 void (*sendlogoff)(void);
@@ -162,14 +162,14 @@
 void (*setsocket)(short newsocket);
 short (*getpacket)(short *other, char *bufptr);
 void (*flushpackets)(void);
-void (*genericmultifunction)(long other, char *bufptr, long messleng, long command);
+void (*genericmultifunction)(int32_t other, char *bufptr, int32_t messleng, int32_t command);
 */
 void callcommit(void);
 void initcrc(void);
-long getcrc(char *buffer, short bufleng);
+int32_t getcrc(char *buffer, short bufleng);
 void initmultiplayers(char damultioption, char dacomrateoption, char dapriority);
-void sendpacket(long other, char *bufptr, long messleng);
-void setpackettimeout(long datimeoutcount, long daresendagaincount);
+void sendpacket(int32_t other, char *bufptr, int32_t messleng);
+void setpackettimeout(int32_t datimeoutcount, int32_t daresendagaincount);
 void uninitmultiplayers(void);
 void sendlogon(void);
 void sendlogoff(void);
@@ -177,16 +177,16 @@
 void setsocket(short newsocket);
 short getpacket(short *other, char *bufptr);
 void flushpackets(void);
-void genericmultifunction(long other, char *bufptr, long messleng, long command);
+void genericmultifunction(int32_t other, char *bufptr, int32_t messleng, int32_t command);
 
 /* engine.c */
-extern int setgotpic(long i1);
-//extern static __inline long getclipmask(long a, long b, long c, long d);
-extern int wallfront(long l1, long l2);
-extern void drawrooms(long daposx, long daposy, long daposz, short daang, long dahoriz, short dacursectnum);
-extern int loadboard(char *filename, long *daposx, long *daposy, long *daposz, short *daang, short *dacursectnum);
-extern int saveboard(char *filename, long *daposx, long *daposy, long *daposz, short *daang, short *dacursectnum);
-extern int setgamemode(char davidoption, long daxdim, long daydim);
+extern int setgotpic(int32_t i1);
+//extern static __inline int32_t getclipmask(int32_t a, int32_t b, int32_t c, int32_t d);
+extern int wallfront(int32_t l1, int32_t l2);
+extern void drawrooms(int32_t daposx, int32_t daposy, int32_t daposz, short daang, int32_t dahoriz, short dacursectnum);
+extern int loadboard(char *filename, int32_t *daposx, int32_t *daposy, int32_t *daposz, short *daang, short *dacursectnum);
+extern int saveboard(char *filename, int32_t *daposx, int32_t *daposy, int32_t *daposz, short *daang, short *dacursectnum);
+extern int setgamemode(char davidoption, int32_t daxdim, int32_t daydim);
 extern void setmmxoverlay(int isenabled);
 extern int getmmxoverlay(void);
 extern void initengine(void);
@@ -193,17 +193,17 @@
 extern void uninitengine(void);
 extern void nextpage(void);
 extern void loadtile(short tilenume);
-extern int allocatepermanenttile(short tilenume, long xsiz, long ysiz);
+extern int allocatepermanenttile(short tilenume, int32_t xsiz, int32_t ysiz);
 extern int loadpics(char *filename, char* gamedir);
-extern void qloadkvx(long voxindex, char *filename);
-extern int clipinsidebox(long x, long y, short wallnum, long walldist);
-extern void drawline256(long x1, long y1, long x2, long y2, unsigned char col);
-extern int inside(long x, long y, short sectnum);
-extern int getangle(long xvect, long yvect);
-extern int ksqrt(long num);
-extern void copytilepiece(long tilenume1, long sx1, long sy1, long xsiz, long ysiz, long tilenume2, long sx2, long sy2);
+extern void qloadkvx(int32_t voxindex, char *filename);
+extern int clipinsidebox(int32_t x, int32_t y, short wallnum, int32_t walldist);
+extern void drawline256(int32_t x1, int32_t y1, int32_t x2, int32_t y2, unsigned char col);
+extern int inside(int32_t x, int32_t y, short sectnum);
+extern int getangle(int32_t xvect, int32_t yvect);
+extern int ksqrt(int32_t num);
+extern void copytilepiece(int32_t tilenume1, int32_t sx1, int32_t sy1, int32_t xsiz, int32_t ysiz, int32_t tilenume2, int32_t sx2, int32_t sy2);
 extern void drawmasks(void);
-extern int setsprite(short spritenum, long newx, long newy, long newz);
+extern int setsprite(short spritenum, int32_t newx, int32_t newy, int32_t newz);
 extern void initspritelists(void);
 extern int insertsprite(short sectnum, short statnum);
 extern int insertspritesect(short sectnum);
@@ -213,51 +213,51 @@
 extern int deletespritestat(short deleteme);
 extern int changespritesect(short spritenum, short newsectnum);
 extern int changespritestat(short spritenum, short newstatnum);
-extern int nextsectorneighborz(short sectnum, long thez, short topbottom, short direction);
-extern int cansee(long x1, long y1, long z1, short sect1, long x2, long y2, long z2, short sect2);
-extern int lintersect(long x1, long y1, long z1, long x2, long y2, long z2, long x3, long y3, long x4, long y4, long *intx, long *inty, long *intz);
-extern int rintersect(long x1, long y1, long z1, long vx, long vy, long vz, long x3, long y3, long x4, long y4, long *intx, long *inty, long *intz);
-extern int hitscan(long xs, long ys, long zs, short sectnum, long vx, long vy, long vz, short *hitsect, short *hitwall, short *hitsprite, long *hitx, long *hity, long *hitz, unsigned long cliptype);
-extern int neartag(long xs, long ys, long zs, short sectnum, short ange, short *neartagsector, short *neartagwall, short *neartagsprite, long *neartaghitdist, long neartagrange, char tagsearch);
-extern void dragpoint(short pointhighlight, long dax, long day);
+extern int nextsectorneighborz(short sectnum, int32_t thez, short topbottom, short direction);
+extern int cansee(int32_t x1, int32_t y1, int32_t z1, short sect1, int32_t x2, int32_t y2, int32_t z2, short sect2);
+extern int lintersect(int32_t x1, int32_t y1, int32_t z1, int32_t x2, int32_t y2, int32_t z2, int32_t x3, int32_t y3, int32_t x4, int32_t y4, int32_t *intx, int32_t *inty, int32_t *intz);
+extern int rintersect(int32_t x1, int32_t y1, int32_t z1, int32_t vx, int32_t vy, int32_t vz, int32_t x3, int32_t y3, int32_t x4, int32_t y4, int32_t *intx, int32_t *inty, int32_t *intz);
+extern int hitscan(int32_t xs, int32_t ys, int32_t zs, short sectnum, int32_t vx, int32_t vy, int32_t vz, short *hitsect, short *hitwall, short *hitsprite, int32_t *hitx, int32_t *hity, int32_t *hitz, uint32_t  cliptype);
+extern int neartag(int32_t xs, int32_t ys, int32_t zs, short sectnum, short ange, short *neartagsector, short *neartagwall, short *neartagsprite, int32_t *neartaghitdist, int32_t neartagrange, char tagsearch);
+extern void dragpoint(short pointhighlight, int32_t dax, int32_t day);
 extern int lastwall(short point);
-extern int clipmove(long *x, long *y, long *z, short *sectnum, long xvect, long yvect, long walldist, long ceildist, long flordist, unsigned long cliptype);
-extern int pushmove(long *x, long *y, long *z, short *sectnum, long walldist, long ceildist, long flordist, unsigned long cliptype);
-extern void updatesector(long x, long y, short *sectnum);
-extern void rotatepoint(long xpivot, long ypivot, long x, long y, short daang, long *x2, long *y2);
+extern int clipmove(int32_t *x, int32_t *y, int32_t *z, short *sectnum, int32_t xvect, int32_t yvect, int32_t walldist, int32_t ceildist, int32_t flordist, uint32_t  cliptype);
+extern int pushmove(int32_t *x, int32_t *y, int32_t *z, short *sectnum, int32_t walldist, int32_t ceildist, int32_t flordist, uint32_t  cliptype);
+extern void updatesector(int32_t x, int32_t y, short *sectnum);
+extern void rotatepoint(int32_t xpivot, int32_t ypivot, int32_t x, int32_t y, short daang, int32_t *x2, int32_t *y2);
 extern int initmouse(void);
 extern void getmousevalues(short *mousx, short *mousy, short *bstatus);
-extern void draw2dgrid(long posxe, long posye, short ange, long zoome, short gride);
-extern void draw2dscreen(long posxe, long posye, short ange, long zoome, short gride);
-extern void printext256(long xpos, long ypos, short col, short backcol, char name[82], char fontsize);
-extern void printext256_noupdate(long xpos, long ypos, short col, short backcol, char name[82], char fontsize);
+extern void draw2dgrid(int32_t posxe, int32_t posye, short ange, int32_t zoome, short gride);
+extern void draw2dscreen(int32_t posxe, int32_t posye, short ange, int32_t zoome, short gride);
+extern void printext256(int32_t xpos, int32_t ypos, short col, short backcol, char name[82], char fontsize);
+extern void printext256_noupdate(int32_t xpos, int32_t ypos, short col, short backcol, char name[82], char fontsize);
 #ifdef DBGRECORD
 extern int krand(int line, char* file);
 #else
 extern int krand(void);
 #endif
-extern void getzrange(long x, long y, long z, short sectnum, long *ceilz, long *ceilhit, long *florz, long *florhit, long walldist, unsigned long cliptype);
-extern void setview(long x1, long y1, long x2, long y2);
-extern void setaspect(long daxrange, long daaspect);
+extern void getzrange(int32_t x, int32_t y, int32_t z, short sectnum, int32_t *ceilz, int32_t *ceilhit, int32_t *florz, int32_t *florhit, int32_t walldist, uint32_t  cliptype);
+extern void setview(int32_t x1, int32_t y1, int32_t x2, int32_t y2);
+extern void setaspect(int32_t daxrange, int32_t daaspect);
 extern void flushperms(void);
-extern void rotatesprite(long sx, long sy, long z, short a, short picnum, signed char dashade, char dapalnum, char dastat, long cx1, long cy1, long cx2, long cy2);
-extern void makepalookup(long palnum, char *remapbuf, signed char r, signed char g, signed char b, char dastat);
+extern void rotatesprite(int32_t sx, int32_t sy, int32_t z, short a, short picnum, signed char dashade, char dapalnum, char dastat, int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2);
+extern void makepalookup(int32_t palnum, char *remapbuf, signed char r, signed char g, signed char b, char dastat);
 extern void setbrightness(char dabrightness, unsigned char *dapal);
-extern void drawmapview(long dax, long day, long zoome, short ang);
-extern void clearview(long dacol);
-extern void clearallviews(long dacol);
-extern void plotpixel(long x, long y, char col);
-extern unsigned char getpixel(long x, long y);
-extern void setviewtotile(short tilenume, long xsiz, long ysiz);
+extern void drawmapview(int32_t dax, int32_t day, int32_t zoome, short ang);
+extern void clearview(int32_t dacol);
+extern void clearallviews(int32_t dacol);
+extern void plotpixel(int32_t x, int32_t y, char col);
+extern unsigned char getpixel(int32_t x, int32_t y);
+extern void setviewtotile(short tilenume, int32_t xsiz, int32_t ysiz);
 extern void setviewback(void);
 extern void squarerotatetile(short tilenume);
-extern void preparemirror(long dax, long day, long daz, short daang, long dahoriz, short dawall, short dasector, long *tposx, long *tposy, short *tang);
+extern void preparemirror(int32_t dax, int32_t day, int32_t daz, short daang, int32_t dahoriz, short dawall, short dasector, int32_t *tposx, int32_t *tposy, short *tang);
 extern void completemirror(void);
 extern int sectorofwall(short theline);
-extern int getceilzofslope(short sectnum, long dax, long day);
-extern int getflorzofslope(short sectnum, long dax, long day);
-extern void getzsofslope(short sectnum, long dax, long day, long *ceilz, long *florz);
-extern void alignceilslope(short dasect, long x, long y, long z);
-extern void alignflorslope(short dasect, long x, long y, long z);
+extern int getceilzofslope(short sectnum, int32_t dax, int32_t day);
+extern int getflorzofslope(short sectnum, int32_t dax, int32_t day);
+extern void getzsofslope(short sectnum, int32_t dax, int32_t day, int32_t *ceilz, int32_t *florz);
+extern void alignceilslope(short dasect, int32_t x, int32_t y, int32_t z);
+extern void alignflorslope(short dasect, int32_t x, int32_t y, int32_t z);
 extern int loopnumofsector(short sectnum, short wallnum);
 extern void setfirstwall(short sectnum, short newfirstwall);
--- a/Engine/src/pragmas.c
+++ b/Engine/src/pragmas.c
@@ -4,23 +4,23 @@
 #include "platform.h"
 #include "pragmas.h"
 
-unsigned long getkensmessagecrc(long param) {
+uint32_t getkensmessagecrc(int32_t param) {
     return(0x56c764d4);
 }
 
 
-void clearbuf(void *d, long c, long a)
+void clearbuf(void *d, int32_t c, int32_t a)
 {
-	long *p = (long*)d;
+	int32_t *p = (long*)d;
 	while ((c--) > 0) *(p++) = a;
 }
 
-void clearbufbyte(void *D, long c, long a)
+void clearbufbyte(void *D, int32_t c, int32_t a)
 { // Cringe City
 	char *p = (char*)D;
-	long m[4] = { 0xffl,0xff00l,0xff0000l,0xff000000l };
-	long n[4] = { 0,8,16,24 };
-	long z=0;
+	int32_t m[4] = { 0xffl,0xff00l,0xff0000l,0xff000000l };
+	int32_t n[4] = { 0,8,16,24 };
+	int32_t z=0;
 	while ((c--) > 0) {
 		*(p++) = (char)((a & m[z])>>n[z]);
 		z=(z+1)&3;
@@ -27,33 +27,33 @@
 	}
 }
 
-void copybuf(void *s, void *d, long c)
+void copybuf(void *s, void *d, int32_t c)
 {
-	long *p = (long*)s, *q = (long*)d;
+	int32_t *p = (long*)s, *q = (long*)d;
 	while ((c--) > 0) *(q++) = *(p++);
 }
 
-void copybufbyte(void *S, void *D, long c)
+void copybufbyte(void *S, void *D, int32_t c)
 {
 	char *p = (char*)S, *q = (char*)D;
 	while((c--) > 0) *(q++) = *(p++);
 }
 
-void copybufreverse(void *S, void *D, long c)
+void copybufreverse(void *S, void *D, int32_t c)
 {
 	char *p = (char*)S, *q = (char*)D;
 	while((c--) > 0) *(q++) = *(p--);
 }
 
-void qinterpolatedown16(long* bufptr, long num, long val, long add)
+void qinterpolatedown16(long* bufptr, int32_t num, int32_t val, int32_t add)
 { // gee, I wonder who could have provided this...
-    long i, *lptr = bufptr;
+    int32_t i, *lptr = bufptr;
     for(i=0;i<num;i++) { lptr[i] = (val>>16); val += add; }
 }
 
-void qinterpolatedown16short(long* bufptr, long num, long val, long add)
+void qinterpolatedown16short(long* bufptr, int32_t num, int32_t val, int32_t add)
 { // ...maybe the same person who provided this too?
-    long i; short *sptr = (short *)bufptr;
+    int32_t i; short *sptr = (short *)bufptr;
     for(i=0;i<num;i++) { sptr[i] = (short)(val>>16); val += add; }
 }
 
--- a/Engine/src/pragmas.h
+++ b/Engine/src/pragmas.h
@@ -14,8 +14,8 @@
 { unsigned char tmp = *p1; *p1 = *p2; *p2 = tmp; }
 static __inline void swapshort(short *p1, short *p2)
 { short tmp = *p1; *p1 = *p2; *p2 = tmp; }
-static __inline void swaplong(long *p1, long *p2)
-{ long tmp = *p1; *p1 = *p2; *p2 = tmp; }
+static __inline void swaplong(int32_t *p1, int32_t *p2)
+{ int32_t tmp = *p1; *p1 = *p2; *p2 = tmp; }
 static __inline void swapchar2(unsigned char *p1, unsigned char *p2, int xsiz)
 {
     swapchar(p1, p2);
@@ -23,11 +23,11 @@
 }
 
 
-unsigned long getkensmessagecrc(long param);
+uint32_t getkensmessagecrc(int32_t param);
 
-static __inline long msqrtasm(unsigned long c)
+static __inline int32_t msqrtasm(uint32_t c)
 {
-	unsigned long a,b;
+	uint32_t a,b;
 
 	a = 0x40000000l;		// mov eax, 0x40000000
 	b = 0x20000000l;		// mov ebx, 0x20000000
@@ -46,7 +46,7 @@
 	return a;
 }
 
-void vlin16first (long i1, long i2);
+void vlin16first (int32_t i1, int32_t i2);
 
 static inline int sqr (int input1) { return input1*input1; }
 
@@ -151,14 +151,14 @@
 static __inline int mul5 (int i1) { return i1*5; }
 static __inline int mul9 (int i1) { return i1*9; }
 
-void copybufreverse(void *S, void *D, long c);
-void copybuf(void *s, void *d, long c);
-void clearbuf(void *d, long c, long a);
-void clearbufbyte(void *D, long c, long a);
-void copybufbyte(void *S, void *D, long c);
+void copybufreverse(void *S, void *D, int32_t c);
+void copybuf(void *s, void *d, int32_t c);
+void clearbuf(void *d, int32_t c, int32_t a);
+void clearbufbyte(void *D, int32_t c, int32_t a);
+void copybufbyte(void *S, void *D, int32_t c);
 
-void qinterpolatedown16 (long* bufptr, long num, long val, long add);
-void qinterpolatedown16short (long* bufptr, long num, long val, long add);
+void qinterpolatedown16 (long* bufptr, int32_t num, int32_t val, int32_t add);
+void qinterpolatedown16short (long* bufptr, int32_t num, int32_t val, int32_t add);
 
 #endif /* !defined _INCLUDE_PRAGMAS_H_ */
 
--- a/Engine/src/sdl_driver.c
+++ b/Engine/src/sdl_driver.c
@@ -40,10 +40,10 @@
 /*
 void (*callcommit)(void);
 void (*initcrc)(void);
-long (*getcrc)(char *buffer, short bufleng);
+int32_t (*getcrc)(char *buffer, short bufleng);
 void (*initmultiplayers)(char damultioption, char dacomrateoption, char dapriority);
-void (*sendpacket)(long other, char *bufptr, long messleng);
-void (*setpackettimeout)(long datimeoutcount, long daresendagaincount);
+void (*sendpacket)(int32_t other, char *bufptr, int32_t messleng);
+void (*setpackettimeout)(int32_t datimeoutcount, int32_t daresendagaincount);
 void (*uninitmultiplayers)(void);
 void (*sendlogon)(void);
 void (*sendlogoff)(void);
@@ -51,7 +51,7 @@
 void (*setsocket)(short newsocket);
 short (*getpacket)(short *other, char *bufptr);
 void (*flushpackets)(void);
-void (*genericmultifunction)(long other, char *bufptr, long messleng, long command);
+void (*genericmultifunction)(int32_t other, char *bufptr, int32_t messleng, int32_t command);
 */
 /**/
 
@@ -115,7 +115,7 @@
 	}
 #endif
 }
-long getcrc(char *buffer, short bufleng)
+int32_t getcrc(char *buffer, short bufleng)
 {
     #ifndef USER_DUMMY_NETWORK
 	switch(nNetMode)
@@ -142,7 +142,7 @@
 	}
 #endif
 }
-void sendpacket(long other, char *bufptr, long messleng)
+void sendpacket(int32_t other, char *bufptr, int32_t messleng)
 {
 #ifndef USER_DUMMY_NETWORK
 	switch(nNetMode)
@@ -156,7 +156,7 @@
 	}
 #endif
 }
-void setpackettimeout(long datimeoutcount, long daresendagaincount)
+void setpackettimeout(int32_t datimeoutcount, int32_t daresendagaincount)
 {
 #ifndef USER_DUMMY_NETWORK
 	switch(nNetMode)
@@ -266,7 +266,7 @@
 	}
 #endif
 }
-void genericmultifunction(long other, char *bufptr, long messleng, long command)
+void genericmultifunction(int32_t other, char *bufptr, int32_t messleng, int32_t command)
 {
     #ifndef USER_DUMMY_NETWORK
 	switch(nNetMode)
@@ -324,16 +324,16 @@
 char **_argv = NULL;
 
     /* !!! move these elsewhere? */
-long xres, yres, bytesperline, frameplace, frameoffset, imageSize, maxpages;
+int32_t xres, yres, bytesperline, frameplace, frameoffset, imageSize, maxpages;
 char *screen, vesachecked;
-long buffermode, origbuffermode, linearmode;
+int32_t buffermode, origbuffermode, linearmode;
 char permanentupdate = 0, vgacompatible;
 
 SDL_Surface *surface = NULL; /* This isn't static so that we can use it elsewhere AH */
 static int debug_hall_of_mirrors = 0;
 static Uint32 sdl_flags = SDL_HWPALETTE;
-static long mouse_relative_x = 0;
-static long mouse_relative_y = 0;
+static int32_t mouse_relative_x = 0;
+static int32_t mouse_relative_y = 0;
 static short mouse_buttons = 0;
 static unsigned int lastkey = 0;
 /* so we can make use of setcolor16()... - DDOI */
@@ -341,11 +341,11 @@
 
 static unsigned int scancodes[SDLK_LAST];
 
-static long last_render_ticks = 0;
-long total_render_time = 1;
-long total_rendered_frames = 0;
+static int32_t last_render_ticks = 0;
+int32_t total_render_time = 1;
+int32_t total_rendered_frames = 0;
 
-static char *titlelong = NULL;
+static char *title = NULL;
 static char *titleshort = NULL;
 
 void restore256_palette (void);
@@ -517,7 +517,7 @@
  * !!!  titlebar caption.   --ryan.
  */
 static char screenalloctype = 255;
-static void init_new_res_vars(int davidoption)
+static void init_new_res_vars(int32_t davidoption)
 {
     int i = 0;
     int j = 0;
@@ -524,12 +524,12 @@
 
     setupmouse();
 
-    SDL_WM_SetCaption(titlelong, titleshort);
+    SDL_WM_SetCaption(title, titleshort);
 
     xdim = xres = surface->w;
     ydim = yres = surface->h;
 
-	printf("init_new_res_vars %ld %ld\n",xdim,ydim);
+	printf("init_new_res_vars %d %d\n",xdim,ydim);
 
     bytesperline = surface->w;
     vesachecked = 1;
@@ -549,7 +549,7 @@
   	if (screen != NULL)
    	{
        	if (screenalloctype == 0) kkfree((void *)screen);
-   	    if (screenalloctype == 1) suckcache((long *)screen);
+   	    if (screenalloctype == 1) suckcache((int32_t *)screen);
    		screen = NULL;
    	} /* if */
 
@@ -568,7 +568,7 @@
   //  	screenalloctype = 0;
 //	    if ((screen = (char *)kkmalloc(i+(j<<1))) == NULL)
 //    	{
-//	    	 allocache((long *)&screen,i+(j<<1),&permanentlock);
+//	    	 allocache((int32_t *)&screen,i+(j<<1),&permanentlock);
 //    		 screenalloctype = 1;
 //    	}
 
@@ -579,8 +579,8 @@
 //        else
 //        {
 //            frameplace = FP_OFF(screen);
-//          	horizlookup = (long *)(frameplace+i);
-//           	horizlookup2 = (long *)(frameplace+i+j);
+//          	horizlookup = (int32_t *)(frameplace+i);
+//           	horizlookup2 = (int32_t *)(frameplace+i+j);
 //        } /* else */
 //    } /* if */
 		if(horizlookup)
@@ -589,8 +589,8 @@
 		if(horizlookup2)
 			free(horizlookup2);
 		
-		horizlookup = (long*)malloc(j);
-		horizlookup2 = (long*)malloc(j);
+		horizlookup = (int32_t*)malloc(j);
+		horizlookup2 = (int32_t*)malloc(j);
 
     j = 0;
   	for(i = 0; i <= ydim; i++)
@@ -751,7 +751,7 @@
 //  toggle also made available from menu.
 //  Replace attempt_fullscreen_toggle(SDL_Surface **surface, Uint32 *flags)
   	
-	long int x,y;
+	int32_t x,y;
 	x = surface->w;
 	y = surface->h;
 
@@ -1036,7 +1036,7 @@
 
 
 #if (!defined __DATE__)
-#define __DATE__ "a long, long time ago"
+#define __DATE__ "a long, int32_t time ago"
 #endif
 
 static __inline void output_sdl_versions(void)
@@ -1185,7 +1185,7 @@
 void _platform_init(int argc, char **argv, const char *title, const char *icon)
 {
     int i;
-	long long timeElapsed;
+	int32_t timeElapsed;
 	char dummyString[4096];
 
     _argc = argc;
@@ -1246,7 +1246,7 @@
     if (icon == NULL)
         icon = "BUILD";
 
-    titlelong = string_dupe(title);
+    title = string_dupe(title);
     titleshort = string_dupe(icon);
 
     sdl_flags = BFullScreen ? SDL_FULLSCREEN : 0;
@@ -1380,7 +1380,7 @@
 } /* _platform_init */
 
 
-int setvesa(long x, long y)
+int setvesa(int32_t x, int32_t y)
 {
 	Error(EXIT_FAILURE, "setvesa() called in SDL driver\n");
     return(0);
@@ -1411,7 +1411,7 @@
 
 } 
 
-int _setgamemode(char davidoption, long daxdim, long daydim)
+int _setgamemode(char davidoption, int32_t daxdim, int32_t daydim)
 {
 	int validated, i;
 	SDL_Surface     *image;
@@ -1491,12 +1491,12 @@
 } /* setgamemode */
 
 
-static int get_dimensions_from_str(const char *str, long *_w, long *_h)
+static int get_dimensions_from_str(const char *str, int32_t *_w, int32_t *_h)
 {
     char *xptr = NULL;
     char *ptr = NULL;
-    long w = -1;
-    long h = -1;
+    int32_t w = -1;
+    int32_t h = -1;
 
     if (str == NULL)
         return(0);
@@ -1527,10 +1527,10 @@
 } /* get_dimensions_from_str */
 
 
-static __inline void get_max_screen_res(long *max_w, long *max_h)
+static __inline void get_max_screen_res(int32_t *max_w, int32_t *max_h)
 {
-    long w = DEFAULT_MAXRESWIDTH;
-    long h = DEFAULT_MAXRESHEIGHT;
+    int32_t w = DEFAULT_MAXRESWIDTH;
+    int32_t h = DEFAULT_MAXRESHEIGHT;
     const char *envr = getenv(BUILD_MAXSCREENRES);
 
     if (envr != NULL)
@@ -1564,8 +1564,8 @@
 /* Let the user specify a specific mode via environment variable. */
 static __inline void add_user_defined_resolution(void)
 {
-    long w;
-    long h;
+    int32_t w;
+    int32_t h;
     const char *envr = getenv(BUILD_USERSCREENRES);
 
     if (envr == NULL)
@@ -1623,8 +1623,8 @@
 
 static __inline void cull_large_vesa_modes(void)
 {
-    long max_w;
-    long max_h;
+    int32_t max_w;
+    int32_t max_h;
     int i;
 
     get_max_screen_res(&max_w, &max_h);
@@ -1668,7 +1668,7 @@
 {
     int i;
     int sorted;
-    long tmp;
+    int32_t tmp;
 
     do
     {
@@ -1759,7 +1759,7 @@
 } /* getvalidvesamodes */
 
 
-int VBE_setPalette(long start, long num, char *palettebuffer)
+int VBE_setPalette(int32_t start, int32_t num, char *palettebuffer)
 /*
  * (From Ken's docs:)
  *   Set (num) palette palette entries starting at (start)
@@ -1830,7 +1830,7 @@
 } /* VBE_setPalette */
 
 
-int VBE_getPalette(long start, long num, char *palettebuffer)
+int VBE_getPalette(int32_t start, int32_t num, char *palettebuffer)
 {
     SDL_Color *sdlp = surface->format->palette->colors + start;
     char *p = palettebuffer + (start * 4);
@@ -1912,7 +1912,7 @@
 
 static unsigned char mirrorcolor = 0;
 
-void _updateScreenRect(long x, long y, long w, long h)
+void _updateScreenRect(int32_t x, int32_t y, int32_t w, int32_t h)
 {
     if (renderer == RENDERER_SOFTWARE)
         SDL_UpdateRect(surface, x, y, w, h);
@@ -1963,12 +1963,12 @@
 } /* _nextpage */
 
 
-unsigned char readpixel(long offset)
+unsigned char readpixel(int32_t offset)
 {
     return( *((unsigned char *) offset) );
 } /* readpixel */
 
-void drawpixel(long offset, unsigned char pixel)
+void drawpixel(int32_t offset, unsigned char pixel)
 {
     *((unsigned char *) offset) = pixel;
 } /* drawpixel */
@@ -1975,7 +1975,7 @@
 
 
 /* !!! These are incorrect. */
-void drawpixels(long offset, unsigned short pixels)
+void drawpixels(int32_t offset, unsigned short pixels)
 {
     Uint8 *surface_end;
     Uint16 *pos;
@@ -1995,7 +1995,7 @@
 } /* drawpixels */
 
 
-void drawpixelses(long offset, unsigned int pixelses)
+void drawpixelses(int32_t offset, unsigned int pixelses)
 {
     Uint8 *surface_end;
     Uint32 *pos;
@@ -2021,13 +2021,13 @@
 	drawpixel_color = col;
 }
 
-void drawpixel16(long offset)
+void drawpixel16(int32_t offset)
 {
     drawpixel(((long) surface->pixels + offset), drawpixel_color);
 } /* drawpixel16 */
 
 
-void fillscreen16(long offset, long color, long blocksize)
+void fillscreen16(int32_t offset, int32_t color, int32_t blocksize)
 {
     Uint8 *surface_end;
     Uint8 *wanted_end;
@@ -2100,12 +2100,12 @@
     *ScreenPtr = WorkingScreenPtr;
 }
 
-void drawline16(long XStart, long YStart, long XEnd, long YEnd, char Color)
+void drawline16(int32_t XStart, int32_t YStart, int32_t XEnd, int32_t YEnd, char Color)
 {
     int Temp, AdjUp, AdjDown, ErrorTerm, XAdvance, XDelta, YDelta;
     int WholeStep, InitialPixelCount, FinalPixelCount, i, RunLength;
     char *ScreenPtr;
-    long dx, dy;
+    int32_t dx, dy;
 
     if (SDL_MUSTLOCK(surface))
         SDL_LockSurface(surface);
@@ -2289,7 +2289,7 @@
     return((void *) surface->pixels);
 }
 
-void setactivepage(long dapagenum)
+void setactivepage(int32_t dapagenum)
 {
 	/* !!! Is this really still needed? - DDOI */
     /*fprintf(stderr, "%s, line %d; setactivepage(): STUB.\n", __FILE__, __LINE__);*/
@@ -2318,9 +2318,9 @@
 // SDL timer was not fast/accurate enough and was slowing down the gameplay,
 // so bad
 
-typedef long long int64;
-static int64 timerfreq=0;
-static long timerlastsample=0;
+
+static int64_t timerfreq=0;
+static int32_t timerlastsample=0;
 static int timerticspersec=0;
 static void (*usertimercallback)(void) = NULL;
 
@@ -2352,7 +2352,7 @@
 
 int inittimer(int tickspersecond)
 {
-	int64 t;
+	int64_t t;
 	
     
 	if (timerfreq) return 0;	// already installed
@@ -2392,8 +2392,8 @@
 //
 void sampletimer(void)
 {
-	int64 i;
-	long n;
+	int64_t i;
+	int32_t n;
 	
 	if (!timerfreq) return;
 
@@ -2414,11 +2414,11 @@
    getticks() -- returns the windows ticks count
    FCS: This seeems to be only used in the multiplayer code
 */
-unsigned long getticks(void)
+uint32_t getticks(void)
 {
-	int64 i;
+	int64_t i;
 	TIMER_GetPlatformTicks(&i);
-	return (unsigned long)(i*(long long)(1000)/timerfreq);
+	return (uint32_t)(i*(int32_t)(1000)/timerfreq);
 }
 
 
@@ -2473,7 +2473,7 @@
 }
 
 
-//unsigned long getticks(void)
+//unsigned int32_t getticks(void)
 //{
 //    return(SDL_GetTicks());
 //} /* getticks */
--- a/Game/src/DbgHelp.h
+++ b/Game/src/DbgHelp.h
@@ -62,13 +62,13 @@
     PIMAGE_NT_HEADERS32   FileHeader;
 #endif
     PIMAGE_SECTION_HEADER LastRvaSection;
-    ULONG                 NumberOfSections;
+    Uint32_t                 NumberOfSections;
     PIMAGE_SECTION_HEADER Sections;
-    ULONG                 Characteristics;
+    Uint32_t                 Characteristics;
     BOOLEAN               fSystemImage;
     BOOLEAN               fDOSImage;
     LIST_ENTRY            Links;
-    ULONG                 SizeOfImage;
+    Uint32_t                 SizeOfImage;
 } LOADED_IMAGE, *PLOADED_IMAGE;
 
 
@@ -156,7 +156,7 @@
     IN PVOID Base,
     IN BOOLEAN MappedAsImage,
     IN USHORT DirectoryEntry,
-    OUT PULONG Size,
+    OUT PUint32_t Size,
     OUT PIMAGE_SECTION_HEADER *FoundHeader OPTIONAL
     );
 
@@ -166,7 +166,7 @@
     IN PVOID Base,
     IN BOOLEAN MappedAsImage,
     IN USHORT DirectoryEntry,
-    OUT PULONG Size
+    OUT PUint32_t Size
     );
 
 PIMAGE_SECTION_HEADER
@@ -174,7 +174,7 @@
 ImageRvaToSection(
     IN PIMAGE_NT_HEADERS NtHeaders,
     IN PVOID Base,
-    IN ULONG Rva
+    IN Uint32_t Rva
     );
 
 PVOID
@@ -182,7 +182,7 @@
 ImageRvaToVa(
     IN PIMAGE_NT_HEADERS NtHeaders,
     IN PVOID Base,
-    IN ULONG Rva,
+    IN Uint32_t Rva,
     IN OUT PIMAGE_SECTION_HEADER *LastRvaSection
     );
 
@@ -699,7 +699,7 @@
 (CALLBACK *PSYM_ENUMSYMBOLS_CALLBACK64)(
     PSTR SymbolName,
     DWORD64 SymbolAddress,
-    ULONG SymbolSize,
+    Uint32_t SymbolSize,
     PVOID UserContext
     );
 
@@ -707,7 +707,7 @@
 (CALLBACK *PSYM_ENUMSYMBOLS_CALLBACK64W)(
     PWSTR SymbolName,
     DWORD64 SymbolAddress,
-    ULONG SymbolSize,
+    Uint32_t SymbolSize,
     PVOID UserContext
     );
 
@@ -715,7 +715,7 @@
 (CALLBACK *PENUMLOADED_MODULES_CALLBACK64)(
     PSTR ModuleName,
     DWORD64 ModuleBase,
-    ULONG ModuleSize,
+    Uint32_t ModuleSize,
     PVOID UserContext
     );
 
@@ -722,7 +722,7 @@
 typedef BOOL
 (CALLBACK *PSYMBOL_REGISTERED_CALLBACK64)(
     HANDLE  hProcess,
-    ULONG   ActionCode,
+    Uint32_t   ActionCode,
     ULONG64 CallbackData,
     ULONG64 UserContext
     );
@@ -757,7 +757,7 @@
 typedef BOOL
 (CALLBACK *PSYM_ENUMMODULES_CALLBACK)(
     PSTR  ModuleName,
-    ULONG BaseOfDll,
+    Uint32_t BaseOfDll,
     PVOID UserContext
     );
 
@@ -764,8 +764,8 @@
 typedef BOOL
 (CALLBACK *PSYM_ENUMSYMBOLS_CALLBACK)(
     PSTR  SymbolName,
-    ULONG SymbolAddress,
-    ULONG SymbolSize,
+    Uint32_t SymbolAddress,
+    Uint32_t SymbolSize,
     PVOID UserContext
     );
 
@@ -772,8 +772,8 @@
 typedef BOOL
 (CALLBACK *PSYM_ENUMSYMBOLS_CALLBACKW)(
     PWSTR  SymbolName,
-    ULONG SymbolAddress,
-    ULONG SymbolSize,
+    Uint32_t SymbolAddress,
+    Uint32_t SymbolSize,
     PVOID UserContext
     );
 
@@ -780,8 +780,8 @@
 typedef BOOL
 (CALLBACK *PENUMLOADED_MODULES_CALLBACK)(
     PSTR  ModuleName,
-    ULONG ModuleBase,
-    ULONG ModuleSize,
+    Uint32_t ModuleBase,
+    Uint32_t ModuleSize,
     PVOID UserContext
     );
 
@@ -788,7 +788,7 @@
 typedef BOOL
 (CALLBACK *PSYMBOL_REGISTERED_CALLBACK)(
     HANDLE  hProcess,
-    ULONG   ActionCode,
+    Uint32_t   ActionCode,
     PVOID   CallbackData,
     PVOID   UserContext
     );
@@ -1315,7 +1315,7 @@
     IN     PSTR                 ModuleName,
     IN     PSTR                 FileName,
     IN     DWORD                dwLineNumber,
-       OUT PLONG                plDisplacement,
+       OUT Pint32_t                plDisplacement,
     IN OUT PIMAGEHLP_LINE64     Line
     );
 
@@ -1329,7 +1329,7 @@
     IN     PSTR               ModuleName,
     IN     PSTR               FileName,
     IN     DWORD              dwLineNumber,
-       OUT PLONG              plDisplacement,
+       OUT Pint32_t              plDisplacement,
     IN OUT PIMAGEHLP_LINE     Line
     );
 #endif
@@ -1539,20 +1539,20 @@
 #define IMAGEHLP_SYMBOL_FUNCTION                   SYMF_FUNCTION        // 0x800
 
 typedef struct _SYMBOL_INFO {
-    ULONG       SizeOfStruct;
-    ULONG       TypeIndex;        // Type Index of symbol
+    Uint32_t       SizeOfStruct;
+    Uint32_t       TypeIndex;        // Type Index of symbol
     ULONG64     Reserved[2];
-    ULONG       Reserved2;
-    ULONG       Size;
+    Uint32_t       Reserved2;
+    Uint32_t       Size;
     ULONG64     ModBase;          // Base Address of module comtaining this symbol
-    ULONG       Flags;
+    Uint32_t       Flags;
     ULONG64     Value;            // Value of symbol, ValuePresent should be 1
     ULONG64     Address;          // Address of symbol including base address of module
-    ULONG       Register;         // register holding value or pointer to value
-    ULONG       Scope;            // scope of the symbol
-    ULONG       Tag;              // pdb classification
-    ULONG       NameLen;          // Actual length of name
-    ULONG       MaxNameLen;
+    Uint32_t       Register;         // register holding value or pointer to value
+    Uint32_t       Scope;            // scope of the symbol
+    Uint32_t       Tag;              // pdb classification
+    Uint32_t       NameLen;          // Actual length of name
+    Uint32_t       MaxNameLen;
     CHAR        Name[1];          // Name of symbol
 } SYMBOL_INFO, *PSYMBOL_INFO;
 
@@ -1567,7 +1567,7 @@
     ULONG64 Params[4];
     ULONG64 Reserved[5];
     BOOL    Virtual;
-    ULONG   Reserved2;
+    Uint32_t   Reserved2;
 } IMAGEHLP_STACK_FRAME, *PIMAGEHLP_STACK_FRAME;
 
 typedef VOID IMAGEHLP_CONTEXT, *PIMAGEHLP_CONTEXT;
@@ -1607,7 +1607,7 @@
 typedef BOOL
 (CALLBACK *PSYM_ENUMERATESYMBOLS_CALLBACK)(
     PSYMBOL_INFO  pSymInfo,
-    ULONG         SymbolSize,
+    Uint32_t         SymbolSize,
     PVOID         UserContext
     );
 
@@ -1649,9 +1649,9 @@
 } IMAGEHLP_SYMBOL_TYPE_INFO;
 
 typedef struct _TI_FINDCHILDREN_PARAMS {
-    ULONG Count;
-    ULONG Start;
-    ULONG ChildId[1];
+    Uint32_t Count;
+    Uint32_t Start;
+    Uint32_t ChildId[1];
 } TI_FINDCHILDREN_PARAMS;
 
 BOOL
@@ -1659,7 +1659,7 @@
 SymGetTypeInfo(
     IN  HANDLE          hProcess,
     IN  DWORD64         ModBase,
-    IN  ULONG           TypeId,
+    IN  Uint32_t           TypeId,
     IN  IMAGEHLP_SYMBOL_TYPE_INFO GetType,
     OUT PVOID           pInfo
     );
@@ -2210,7 +2210,7 @@
 
 typedef struct _MINIDUMP_USER_STREAM {
     ULONG32 Type;
-    ULONG BufferSize;
+    Uint32_t BufferSize;
     PVOID Buffer;
 
 } MINIDUMP_USER_STREAM, *PMINIDUMP_USER_STREAM;
@@ -2217,7 +2217,7 @@
 
 
 typedef struct _MINIDUMP_USER_STREAM_INFORMATION {
-    ULONG UserStreamCount;
+    Uint32_t UserStreamCount;
     PMINIDUMP_USER_STREAM UserStreamArray;
 } MINIDUMP_USER_STREAM_INFORMATION, *PMINIDUMP_USER_STREAM_INFORMATION;
 
@@ -2235,10 +2235,10 @@
 
 
 typedef struct _MINIDUMP_THREAD_CALLBACK {
-    ULONG ThreadId;
+    Uint32_t ThreadId;
     HANDLE ThreadHandle;
     CONTEXT Context;
-    ULONG SizeOfContext;
+    Uint32_t SizeOfContext;
     ULONG64 StackBase;
     ULONG64 StackEnd;
 } MINIDUMP_THREAD_CALLBACK, *PMINIDUMP_THREAD_CALLBACK;
@@ -2245,10 +2245,10 @@
 
 
 typedef struct _MINIDUMP_THREAD_EX_CALLBACK {
-    ULONG ThreadId;
+    Uint32_t ThreadId;
     HANDLE ThreadHandle;
     CONTEXT Context;
-    ULONG SizeOfContext;
+    Uint32_t SizeOfContext;
     ULONG64 StackBase;
     ULONG64 StackEnd;
     ULONG64 BackingStoreBase;
@@ -2257,7 +2257,7 @@
 
 
 typedef struct _MINIDUMP_INCLUDE_THREAD_CALLBACK {
-    ULONG ThreadId;
+    Uint32_t ThreadId;
 } MINIDUMP_INCLUDE_THREAD_CALLBACK, *PMINIDUMP_INCLUDE_THREAD_CALLBACK;
 
 
@@ -2272,14 +2272,14 @@
 typedef struct _MINIDUMP_MODULE_CALLBACK {
     PWCHAR FullPath;
     ULONG64 BaseOfImage;
-    ULONG SizeOfImage;
-    ULONG CheckSum;
-    ULONG TimeDateStamp;
+    Uint32_t SizeOfImage;
+    Uint32_t CheckSum;
+    Uint32_t TimeDateStamp;
     VS_FIXEDFILEINFO VersionInfo;
     PVOID CvRecord; 
-    ULONG SizeOfCvRecord;
+    Uint32_t SizeOfCvRecord;
     PVOID MiscRecord;
-    ULONG SizeOfMiscRecord;
+    Uint32_t SizeOfMiscRecord;
 } MINIDUMP_MODULE_CALLBACK, *PMINIDUMP_MODULE_CALLBACK;
 
 
@@ -2298,9 +2298,9 @@
 
 
 typedef struct _MINIDUMP_CALLBACK_INPUT {
-    ULONG ProcessId;
+    Uint32_t ProcessId;
     HANDLE ProcessHandle;
-    ULONG CallbackType;
+    Uint32_t CallbackType;
     union {
         MINIDUMP_THREAD_CALLBACK Thread;
         MINIDUMP_THREAD_EX_CALLBACK ThreadEx;
@@ -2312,8 +2312,8 @@
 
 typedef struct _MINIDUMP_CALLBACK_OUTPUT {
     union {
-        ULONG ModuleWriteFlags;
-        ULONG ThreadWriteFlags;
+        Uint32_t ModuleWriteFlags;
+        Uint32_t ThreadWriteFlags;
     };
 } MINIDUMP_CALLBACK_OUTPUT, *PMINIDUMP_CALLBACK_OUTPUT;
 
@@ -2383,7 +2383,7 @@
 // PVOID
 // RVA_TO_ADDR(
 //     PVOID Mapping,
-//     ULONG Rva
+//     Uint32_t Rva
 //     )
 //
 // Routine Description:
@@ -2421,10 +2421,10 @@
 WINAPI
 MiniDumpReadDumpStream(
     IN PVOID BaseOfDump,
-    IN ULONG StreamNumber,
+    IN Uint32_t StreamNumber,
     OUT PMINIDUMP_DIRECTORY * Dir, OPTIONAL
     OUT PVOID * StreamPointer, OPTIONAL
-    OUT ULONG * StreamSize OPTIONAL
+    OUT Uint32_t * StreamSize OPTIONAL
     );
 
 #include <poppack.h>
--- a/Game/src/_functio.h
+++ b/Game/src/_functio.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
--- a/Game/src/_rts.h
+++ b/Game/src/_rts.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
--- a/Game/src/actors.c
+++ b/Game/src/actors.c
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
@@ -26,20 +26,20 @@
 
 #include "duke3d.h"
 
-extern long numenvsnds;
+extern int32_t numenvsnds;
 char actor_tog;
 
 void updateinterpolations()  //Stick at beginning of domovethings
 {
-	long i;
+	int32_t i;
 
 	for(i=numinterpolations-1;i>=0;i--) oldipos[i] = *curipos[i];
 }
 
 
-void setinterpolation(long *posptr)
+void setinterpolation(int32_t *posptr)
 {
-	long i;
+	int32_t i;
 
 	if (numinterpolations >= MAXINTERPOLATIONS) return;
 	for(i=numinterpolations-1;i>=0;i--)
@@ -49,9 +49,9 @@
 	numinterpolations++;
 }
 
-void stopinterpolation(long *posptr)
+void stopinterpolation(int32_t *posptr)
 {
-	long i;
+	int32_t i;
 
 	for(i=numinterpolations-1;i>=startofdynamicinterpolations;i--)
 		if (curipos[i] == posptr)
@@ -63,9 +63,9 @@
 		}
 }
 
-void dointerpolations(long smoothratio)       //Stick at beginning of drawscreen
+void dointerpolations(int32_t smoothratio)       //Stick at beginning of drawscreen
 {
-	long i, j, odelta, ndelta;
+	int32_t i, j, odelta, ndelta;
 
 	ndelta = 0; j = 0;
 	for(i=numinterpolations-1;i>=0;i--)
@@ -79,12 +79,12 @@
 
 void restoreinterpolations()  //Stick at end of drawscreen
 {
-	long i;
+	int32_t i;
 
 	for(i=numinterpolations-1;i>=0;i--) *curipos[i] = bakipos[i];
 }
 
-long ceilingspace(short sectnum)
+int32_t ceilingspace(short sectnum)
 {
     if( (sector[sectnum].ceilingstat&1) && sector[sectnum].ceilingpal == 0 )
     {
@@ -98,7 +98,7 @@
     return 0;
 }
 
-long floorspace(short sectnum)
+int32_t floorspace(short sectnum)
 {
     if( (sector[sectnum].floorstat&1) && sector[sectnum].ceilingpal == 0 )
     {
@@ -403,11 +403,11 @@
 }
    */
 
-long ifsquished(short i, short p)
+int32_t ifsquished(short i, short p)
 {
     sectortype *sc;
     char squishme;
-    long floorceildist;
+    int32_t floorceildist;
 
     if(PN == APLAYER && ud.clipping)
         return 0;
@@ -442,12 +442,12 @@
     return 0;
 }
 
-void hitradius( short i, long  r, long  hp1, long  hp2, long  hp3, long  hp4 )
+void hitradius( short i, int32_t  r, int32_t  hp1, int32_t  hp2, int32_t  hp3, int32_t  hp4 )
 {
     spritetype *s,*sj;
     walltype *wal;
-    long d, q, x1, y1;
-    long sectcnt, sectend, dasect, startwall, endwall, nextsect;
+    int32_t d, q, x1, y1;
+    int32_t sectcnt, sectend, dasect, startwall, endwall, nextsect;
     short j,k,p,x,nextj,sect;
     char statlist[] = {0,1,6,10,12,2,5};
     short *tempshort = (short *)tempbuf;
@@ -623,9 +623,9 @@
 }
 
 
-int movesprite(short spritenum, long xchange, long ychange, long zchange, unsigned long cliptype)
+int movesprite(short spritenum, int32_t xchange, int32_t ychange, int32_t zchange, uint32_t cliptype)
 {
-    long daz,h, oldx, oldy;
+    int32_t daz,h, oldx, oldy;
     short retval, dasectnum, cd;
     char bg;
 
@@ -710,10 +710,10 @@
 }
 
 
-short ssp(short i,unsigned long cliptype) //The set sprite function
+short ssp(short i,uint32_t cliptype) //The set sprite function
 {
     spritetype *s;
-    long movetype;
+    int32_t movetype;
 
     s = &sprite[i];
 
@@ -771,7 +771,7 @@
      
 void guts(spritetype *s,short gtype, short n, short p)
 {
-    long gutz,floorz;
+    int32_t gutz,floorz;
     short i,a,j;
     char sx,sy;
     signed char pal;
@@ -809,7 +809,7 @@
 
 void gutsdir(spritetype *s,short gtype, short n, short p)
 {
-    long gutz,floorz;
+    int32_t gutz,floorz;
     short i,a,j;
     char sx,sy;
 
@@ -835,7 +835,7 @@
 
 void setsectinterpolate(short i)
 {
-    long j, k, startwall,endwall;
+    int32_t j, k, startwall,endwall;
 
     startwall = sector[SECT].wallptr;
     endwall = startwall+sector[SECT].wallnum;
@@ -879,7 +879,7 @@
     //T1,T2 and T3 are used for all the sector moving stuff!!!
 
     short startwall,endwall,x;
-    long tx,ty,j,k;
+    int32_t tx,ty,j,k;
     spritetype *s;
 
     s = &sprite[i];
@@ -907,7 +907,7 @@
 
 void movefta(void)
 {
-    long x, px, py, sx, sy;
+    int32_t x, px, py, sx, sy;
     short i, j, p, psect, ssect, nexti;
     spritetype *s;
 
@@ -1179,7 +1179,7 @@
 void moveplayers(void) //Players
 {
     short i , nexti;
-    long otherx;
+    int32_t otherx;
     spritetype *s;
     struct player_struct *p;
 
@@ -1316,7 +1316,7 @@
 void movefx(void)
 {
     short i, j, nexti, p;
-    long x, ht;
+    int32_t x, ht;
     spritetype *s;
 
     i = headspritestat[11];
@@ -1419,7 +1419,7 @@
 {
     short i, nexti, sect, j;
     spritetype *s;
-    long x;
+    int32_t x;
 
     i = headspritestat[12];
     while(i >= 0)
@@ -1516,7 +1516,7 @@
 void movestandables(void)
 {
     short i, j, k, m, nexti, nextj, p, sect;
-    long l=0, x, *t;
+    int32_t l=0, x, *t;
     spritetype *s;
 
     i = headspritestat[6];
@@ -2412,7 +2412,7 @@
 
 void bounce(short i)
 {
-    long k, l, daang, dax, day, daz, xvect, yvect, zvect;
+    int32_t k, l, daang, dax, day, daz, xvect, yvect, zvect;
     short hitsect;
     spritetype *s = &sprite[i];
 
@@ -2452,8 +2452,8 @@
 void moveweapons(void)
 {
     short i, j, k, nexti, p, q;
-    long dax,day,daz, x, ll;
-    unsigned long qq;
+    int32_t dax,day,daz, x, ll;
+    uint32_t qq;
     spritetype *s;
 
     i = headspritestat[4];
@@ -2798,7 +2798,7 @@
 {
     char warpspriteto;
     short i, j, k, l, p, sect, sectlotag, nexti, nextj;
-    long ll,onfloorz,q;
+    int32_t ll,onfloorz,q;
 
     i = headspritestat[9]; //Transporters
 
@@ -3138,7 +3138,7 @@
 
 void moveactors(void)
 {
-    long x, m, l, *t;
+    int32_t x, m, l, *t;
     short a, i, j, nexti, nextj, sect, p;
     spritetype *s;
     unsigned short k;
@@ -4395,7 +4395,7 @@
 void moveexplosions(void)  // STATNUM 5
 {
     short i, j, nexti, sect, p;
-    long l, x, *t;
+    int32_t l, x, *t;
     spritetype *s;
 
     i = headspritestat[5];
@@ -4927,7 +4927,7 @@
 
 void moveeffectors(void)   //STATNUM 3
 {
-    long q=0, l, m, x, st, j, *t;
+    int32_t q=0, l, m, x, st, j, *t;
     short i, k, nexti, nextk, p, sh, nextj;
     spritetype *s;
     sectortype *sc;
@@ -4951,7 +4951,7 @@
         {
             case 0:
             {
-                long zchange = 0;
+                int32_t zchange = 0;
 
                 zchange = 0;
 
@@ -6492,17 +6492,17 @@
 
                 if( t[0] == 1 ) //Decide if the s->sectnum should go up or down
                 {
-                    s->zvel = ksgn(s->z-*(long *)l) * (SP<<4);
+                    s->zvel = ksgn(s->z-*(int32_t *)l) * (SP<<4);
                     t[0]++;
                 }
 
                 if( sc->extra == 0 )
                 {
-                    *(long *)l += s->zvel;
+                    *(int32_t *)l += s->zvel;
 
-                    if(klabs(*(long *)l-s->z) < 1024)
+                    if(klabs(*(int32_t *)l-s->z) < 1024)
                     {
-                        *(long *)l = s->z;
+                        *(int32_t *)l = s->z;
                         KILLIT(i); //All done
                     }
                 }
--- a/Game/src/animlib.c
+++ b/Game/src/animlib.c
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
--- a/Game/src/animlib.h
+++ b/Game/src/animlib.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
--- a/Game/src/audiolib/fx_man.h
+++ b/Game/src/audiolib/fx_man.h
@@ -32,6 +32,7 @@
 #define __FX_MAN_H
 
 #include "sndcards.h"
+#include <inttypes.h>
 
 typedef struct
    {
@@ -83,7 +84,7 @@
 int   FX_SetupSoundBlaster( fx_blaster_config blaster, int *MaxVoices, int *MaxSampleBits, int *MaxChannels );
 int   FX_Init( int SoundCard, int numvoices, int numchannels, int samplebits, unsigned mixrate );
 int   FX_Shutdown( void );
-int   FX_SetCallBack( void ( *function )( unsigned long ) );
+int   FX_SetCallBack( void ( *function )( uint32_t ) );
 void  FX_SetVolume( int volume );
 int   FX_GetVolume( void );
 
@@ -102,33 +103,33 @@
 int FX_SetFrequency( int handle, int frequency );
 
 int FX_PlayVOC( char *ptr, int pitchoffset, int vol, int left, int right,
-       int priority, unsigned long callbackval );
-int FX_PlayLoopedVOC( char *ptr, long loopstart, long loopend,
-       int pitchoffset, int vol, int left, int right, int priority,
-       unsigned long callbackval );
+       int priority, uint32_t callbackval );
+int FX_PlayLoopedVOC( char *ptr, int32_t loopstart, int32_t loopend,
+       int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority,
+       uint32_t callbackval );
 int FX_PlayWAV( char *ptr, int pitchoffset, int vol, int left, int right,
-       int priority, unsigned long callbackval );
-int FX_PlayLoopedWAV( char *ptr, long loopstart, long loopend,
+       int priority, uint32_t callbackval );
+int FX_PlayLoopedWAV( char *ptr, int32_t loopstart, int32_t loopend,
        int pitchoffset, int vol, int left, int right, int priority,
-       unsigned long callbackval );
-int FX_PlayVOC3D( char *ptr, int pitchoffset, int angle, int distance,
-       int priority, unsigned long callbackval );
+       uint32_t callbackval );
+int FX_PlayVOC3D( char *ptr, int32_t pitchoffset, int32_t angle, int32_t distance,
+       int priority, uint32_t callbackval );
 int FX_PlayWAV3D( char *ptr, int pitchoffset, int angle, int distance,
-       int priority, unsigned long callbackval );
-int FX_PlayRaw( char *ptr, unsigned long length, unsigned rate,
+       int priority, uint32_t callbackval );
+int FX_PlayRaw( char *ptr, uint32_t length, uint32_t rate,
        int pitchoffset, int vol, int left, int right, int priority,
-       unsigned long callbackval );
-int FX_PlayLoopedRaw( char *ptr, unsigned long length, char *loopstart,
+       uint32_t callbackval );
+int FX_PlayLoopedRaw( char *ptr, uint32_t length, char *loopstart,
        char *loopend, unsigned rate, int pitchoffset, int vol, int left,
-       int right, int priority, unsigned long callbackval );
-int FX_Pan3D( int handle, int angle, int distance );
-int FX_SoundActive( int handle );
-int FX_SoundsPlaying( void );
-int FX_StopSound( int handle );
-int FX_StopAllSounds( void );
-int FX_StartDemandFeedPlayback( void ( *function )( char **ptr, unsigned long *length ),
-       int rate, int pitchoffset, int vol, int left, int right,
-       int priority, unsigned long callbackval );
+       int right, int priority, uint32_t callbackval );
+int32_t FX_Pan3D( int handle, int angle, int distance );
+int32_t FX_SoundActive( int32_t handle );
+int32_t FX_SoundsPlaying( void );
+int32_t FX_StopSound( int handle );
+int32_t FX_StopAllSounds( void );
+int32_t FX_StartDemandFeedPlayback( void ( *function )( char **ptr, uint32_t *length ),
+       int32_t rate, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right,
+       int32_t priority, uint32_t callbackval );
 int  FX_StartRecording( int MixRate, void ( *function )( char *ptr, int length ) );
 void FX_StopRecord( void );
 
--- a/Game/src/audiolib/music.h
+++ b/Game/src/audiolib/music.h
@@ -82,8 +82,8 @@
 int   MUSIC_PlaySong( unsigned char *song, int loopflag );
 void  MUSIC_SetContext( int context );
 int   MUSIC_GetContext( void );
-void  MUSIC_SetSongTick( unsigned long PositionInTicks );
-void  MUSIC_SetSongTime( unsigned long milliseconds );
+void  MUSIC_SetSongTick( uint32_t PositionInTicks );
+void  MUSIC_SetSongTime( uint32_t milliseconds );
 void  MUSIC_SetSongPosition( int measure, int beat, int tick );
 void  MUSIC_GetSongPosition( songposition *pos );
 void  MUSIC_GetSongLength( songposition *pos );
--- a/Game/src/config.c
+++ b/Game/src/config.c
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
@@ -552,7 +552,7 @@
 
 void readsavenames(void)
 {
-    long dummy;
+    int32_t dummy;
     short i;
     char fn[] = "game_.sav";
     FILE *fil;
--- a/Game/src/config.h
+++ b/Game/src/config.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
--- a/Game/src/control.c
+++ b/Game/src/control.c
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
--- a/Game/src/control.h
+++ b/Game/src/control.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
--- a/Game/src/cvar_defs.h
+++ b/Game/src/cvar_defs.h
@@ -1,6 +1,8 @@
 #ifndef _CVARDEFS_H_
 #define _CVARDEFS_H_
 
+#include <inttypes.h>
+
 void CVARDEFS_Init();
 void CVARDEFS_Render();
 //
@@ -27,9 +29,9 @@
 int g_CV_DebugJoystick;
 int g_CV_DebugSound;
 int g_CV_DebugFileAccess;
-unsigned long sounddebugActiveSounds;
-unsigned long sounddebugAllocateSoundCalls;
-unsigned long sounddebugDeallocateSoundCalls;
+uint32_t sounddebugActiveSounds;
+uint32_t sounddebugAllocateSoundCalls;
+uint32_t sounddebugDeallocateSoundCalls;
 
 
 int g_CV_CubicInterpolation;
--- a/Game/src/develop.h
+++ b/Game/src/develop.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
--- a/Game/src/duke3d.h
+++ b/Game/src/duke3d.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
@@ -85,7 +85,7 @@
 
 extern unsigned char conVersion;
 extern unsigned char grpVersion;
-extern long groupefil_crc32[MAXGROUPFILES];
+extern int32_t groupefil_crc32[MAXGROUPFILES];
 
 #define RANCID_ID 1
 #define	XDUKE_ID  2
@@ -341,7 +341,7 @@
 {
     signed char avel, horz;
     short fvel, svel;
-    unsigned long bits;
+    uint32_t bits;
 } input;
 
 #pragma pack(pop)
@@ -351,7 +351,7 @@
 extern input inputfifo[MOVEFIFOSIZ][MAXPLAYERS], sync[MAXPLAYERS];
 extern input recsync[RECSYNCBUFSIZ];
 
-extern long movefifosendplc;
+extern int32_t movefifosendplc;
 
 typedef struct
 {
@@ -363,7 +363,7 @@
 struct animwalltype
 {
         short wallnum;
-        long tag;
+        int32_t tag;
 };
 extern struct animwalltype animwall[MAXANIMWALLS];
 extern short numanimwalls,probey,lastprobey;
@@ -371,7 +371,7 @@
 extern char *mymembuf;
 extern char typebuflen,typebuf[41];
 extern char MusicPtr[72000];
-extern long msx[2048],msy[2048];
+extern int32_t msx[2048],msy[2048];
 extern short cyclers[MAXCYCLERS][6],numcyclers;
 extern char myname[2048];
 
@@ -389,9 +389,9 @@
     short camerasprite,last_camsprite;
     short last_level,secretlevel;
 
-    long const_visibility,uw_framerate;
-    long camera_time,folfvel,folavel,folx,foly,fola;
-    long reccnt;
+    int32_t const_visibility,uw_framerate;
+    int32_t camera_time,folfvel,folavel,folx,foly,fola;
+    int32_t reccnt;
 
     int32 entered_name,screen_tilting,shadows,fta_on,executions,auto_run;
     int32 coords,tickrate,m_coop,coop,screen_size,extended_screen_size,lockout,crosshair,showweapons;
@@ -410,20 +410,20 @@
 	// FIX_00015: Backward compliance with older demos (down to demos v27, 28, 116 and 117 only)
 	char playing_demo_rev;
 
-	unsigned long groupefil_crc32[MAXPLAYERS][MAXGROUPFILES];
+	uint32_t groupefil_crc32[MAXPLAYERS][MAXGROUPFILES];
 	unsigned short conSize[MAXPLAYERS];
 
 #ifdef CHECK_XDUKE_REV
 	char rev[MAXPLAYERS][10];
 #endif
-	unsigned long mapCRC[MAXPLAYERS];
-	unsigned long exeCRC[MAXPLAYERS];
-	unsigned long conCRC[MAXPLAYERS];
+	uint32_t mapCRC[MAXPLAYERS];
+	uint32_t exeCRC[MAXPLAYERS];
+	uint32_t conCRC[MAXPLAYERS];
 };
 
 struct player_orig
 {
-    long ox,oy,oz;
+    int32_t ox,oy,oz;
     short oa,os;
 };
 
@@ -435,7 +435,7 @@
 {
 	unsigned int crc32;
 	char* name;
-	unsigned long size;
+	uint32_t size;
 } crc32_t;
 
 extern crc32_t crc32lookup[];
@@ -443,17 +443,17 @@
 void add_ammo( short, short, short, short );
 
 
-extern long fricxv,fricyv;
+extern int32_t fricxv,fricyv;
 
 struct player_struct
 {
-    long zoom,exitx,exity,loogiex[64],loogiey[64],numloogs,loogcnt;
-    long posx, posy, posz, horiz, ohoriz, ohorizoff, invdisptime;
-    long bobposx,bobposy,oposx,oposy,oposz,pyoff,opyoff;
-    long posxv,posyv,poszv,last_pissed_time,truefz,truecz;
-    long player_par,visibility;
-    long bobcounter,weapon_sway;
-    long pals_time,randomflamex,crack_time;
+    int32_t zoom,exitx,exity,loogiex[64],loogiey[64],numloogs,loogcnt;
+    int32_t posx, posy, posz, horiz, ohoriz, ohorizoff, invdisptime;
+    int32_t bobposx,bobposy,oposx,oposy,oposz,pyoff,opyoff;
+    int32_t posxv,posyv,poszv,last_pissed_time,truefz,truecz;
+    int32_t player_par,visibility;
+    int32_t bobcounter,weapon_sway;
+    int32_t pals_time,randomflamex,crack_time;
 
     int32 aim_mode;
 
@@ -472,7 +472,7 @@
     short heat_amount,actorsqu,timebeforeexit,customexitsound;
 
     short weaprecs[16],weapreccnt;
-	unsigned long interface_toggle_flag;
+	uint32_t interface_toggle_flag;
 
     short rotscrnang,dead_flag,show_empty_weapon;
     short scuba_amount,jetpack_amount,steroids_amount,shield_amount;
@@ -511,9 +511,9 @@
 
 extern unsigned char tempbuf[2048], packbuf[576];
 
-extern long gc,max_player_health,max_armour_amount,max_ammo_amount[MAX_WEAPONS];
+extern int32_t gc,max_player_health,max_armour_amount,max_ammo_amount[MAX_WEAPONS];
 
-extern long impact_damage,respawnactortime,respawnitemtime;
+extern int32_t impact_damage,respawnactortime,respawnitemtime;
 
 #define MOVFIFOSIZ 256
 
@@ -528,7 +528,7 @@
 #endif
 
 extern short int global_random;
-extern long scaredfallz;
+extern int32_t scaredfallz;
 extern char buf[80]; //My own generic input buffer
 
 extern char fta_quotes[NUMOFFIRSTTIMEACTIVE][64];
@@ -544,9 +544,9 @@
 extern char playerreadyflag[MAXPLAYERS],playerquitflag[MAXPLAYERS];
 extern char sounds[NUM_SOUNDS][14];
 
-extern long script[MAXSCRIPTSIZE],*scriptptr,*insptr,*labelcode,labelcnt;
+extern int32_t script[MAXSCRIPTSIZE],*scriptptr,*insptr,*labelcode,labelcnt;
 extern char *label,*textptr,error,warning,killit_flag;
-extern long *actorscrptr[MAXTILES],*parsing_actor;
+extern int32_t *actorscrptr[MAXTILES],*parsing_actor;
 extern char actortype[MAXTILES];
 extern char *music_pointer;
 
@@ -566,8 +566,8 @@
     short picnum,ang,extra,owner,movflag;
     short tempang,actorstayput,dispicnum;
     short timetosleep;
-    long floorz,ceilingz,lastvx,lastvy,bposx,bposy,bposz;
-    long temp_data[6];
+    int32_t floorz,ceilingz,lastvx,lastvy,bposx,bposy,bposz;
+    int32_t temp_data[6];
 };
 
 extern struct weaponhit hittype[MAXSPRITES];
@@ -574,7 +574,7 @@
 
 extern input loc;
 extern input recsync[RECSYNCBUFSIZ];
-extern long avgfvel, avgsvel, avgavel, avghorz, avgbits;
+extern int32_t avgfvel, avgsvel, avgavel, avghorz, avgbits;
 
 extern short numplayers, myconnectindex;
 extern short connecthead, connectpoint2[MAXPLAYERS];   //Player linked list variables (indeces, not connection numbers)
@@ -581,27 +581,27 @@
 extern short screenpeek;
 
 extern int current_menu;
-extern long tempwallptr,animatecnt;
-extern long lockclock,frameplace;
+extern int32_t tempwallptr,animatecnt;
+extern int32_t lockclock,frameplace;
 extern char display_mirror,rtsplaying;
 
-extern long movefifoend[MAXPLAYERS];
-extern long ototalclock;
+extern int32_t movefifoend[MAXPLAYERS];
+extern int32_t ototalclock;
 
-extern long *animateptr[MAXANIMATES], animategoal[MAXANIMATES];
-extern long animatevel[MAXANIMATES];
-// extern long oanimateval[MAXANIMATES];
+extern int32_t *animateptr[MAXANIMATES], animategoal[MAXANIMATES];
+extern int32_t animatevel[MAXANIMATES];
+// extern int32_t oanimateval[MAXANIMATES];
 extern short neartagsector, neartagwall, neartagsprite;
-extern long neartaghitdist;
+extern int32_t neartaghitdist;
 extern short animatesect[MAXANIMATES];
-extern long movefifoplc, vel,svel,angvel,horiz;
+extern int32_t movefifoplc, vel,svel,angvel,horiz;
 
 extern short mirrorwall[64], mirrorsector[64], mirrorcnt;
 
 #define NUMKEYS 19
 
-extern long frameplace, chainplace, chainnumpages;
-extern volatile long checksume;
+extern int32_t frameplace, chainplace, chainnumpages;
+extern volatile int32_t checksume;
 
 #include "funct.h"
 #include "engine_protos.h"
@@ -609,9 +609,9 @@
 extern char screencapt;
 extern short soundps[NUM_SOUNDS],soundpe[NUM_SOUNDS],soundvo[NUM_SOUNDS];
 extern char soundpr[NUM_SOUNDS],soundm[NUM_SOUNDS];
-extern long soundsiz[NUM_SOUNDS];
+extern int32_t soundsiz[NUM_SOUNDS];
 extern char level_names[44][33];
-extern long partime[44],designertime[44];
+extern int32_t partime[44],designertime[44];
 extern char volume_names[4][33];
 extern char skill_names[5][33];
 extern char level_file_names[44][128];
@@ -621,7 +621,7 @@
 extern char restorepalette;
 
 extern short buttonstat;
-extern long cachecount;
+extern int32_t cachecount;
 extern char boardfilename[128],waterpal[768],slimepal[768],titlepal[768],drealms[768],endingpal[768];
 extern char betaname[80];
 extern char cachedebug,earthquaketime;
@@ -629,13 +629,13 @@
 extern char lumplockbyte[11];
 
     //DUKE3D.H - replace the end "my's" with this
-extern long myx, omyx, myxvel, myy, omyy, myyvel, myz, omyz, myzvel;
+extern int32_t myx, omyx, myxvel, myy, omyy, myyvel, myz, omyz, myzvel;
 extern short myhoriz, omyhoriz, myhorizoff, omyhorizoff, globalskillsound;
 extern short myang, omyang, mycursectnum, myjumpingcounter;
 extern char myjumpingtoggle, myonground, myhardlanding,myreturntocenter;
-extern long fakemovefifoplc;
-extern long myxbak[MOVEFIFOSIZ], myybak[MOVEFIFOSIZ], myzbak[MOVEFIFOSIZ];
-extern long myhorizbak[MOVEFIFOSIZ];
+extern int32_t fakemovefifoplc;
+extern int32_t myxbak[MOVEFIFOSIZ], myybak[MOVEFIFOSIZ], myzbak[MOVEFIFOSIZ];
+extern int32_t myhorizbak[MOVEFIFOSIZ];
 extern short myangbak[MOVEFIFOSIZ];
 
 extern short weaponsandammosprites[15];
@@ -657,7 +657,7 @@
 
 extern STATUSBARTYPE sbar;
 extern short frags[MAXPLAYERS][MAXPLAYERS];
-extern long cameradist, cameraclock, dukefriction,show_shareware;
+extern int32_t cameradist, cameraclock, dukefriction,show_shareware;
 extern char networkmode, movesperpacket;
 extern char gamequit;
 
@@ -664,25 +664,25 @@
 extern char pus,pub,camerashitable,freezerhurtowner,lasermode;
 extern char syncstat, syncval[MAXPLAYERS][MOVEFIFOSIZ];
 extern signed char multiwho, multipos, multiwhat, multiflag;
-extern long syncvalhead[MAXPLAYERS], syncvaltail, syncvaltottail;
-extern long numfreezebounces,rpgblastradius,pipebombblastradius,tripbombblastradius,shrinkerblastradius,morterblastradius,bouncemineblastradius,seenineblastradius;
+extern int32_t syncvalhead[MAXPLAYERS], syncvaltail, syncvaltottail;
+extern int32_t numfreezebounces,rpgblastradius,pipebombblastradius,tripbombblastradius,shrinkerblastradius,morterblastradius,bouncemineblastradius,seenineblastradius;
 // CTW - MODIFICATION
 // extern char stereo,eightytwofifty,playerswhenstarted,playonten,everyothertime;
 extern char stereo,eightytwofifty,playerswhenstarted,everyothertime;
 // CTW END - MODIFICATION
-extern long myminlag[MAXPLAYERS], mymaxlag, otherminlag, bufferjitter;
+extern int32_t myminlag[MAXPLAYERS], mymaxlag, otherminlag, bufferjitter;
 
-extern long numinterpolations, startofdynamicinterpolations;
-extern long oldipos[MAXINTERPOLATIONS];
-extern long bakipos[MAXINTERPOLATIONS];
-extern long *curipos[MAXINTERPOLATIONS];
+extern int32_t numinterpolations, startofdynamicinterpolations;
+extern int32_t oldipos[MAXINTERPOLATIONS];
+extern int32_t bakipos[MAXINTERPOLATIONS];
+extern int32_t *curipos[MAXINTERPOLATIONS];
 
 extern short numclouds,clouds[128],cloudx[128],cloudy[128];
-extern long cloudtotalclock,totalmemory;
+extern int32_t cloudtotalclock,totalmemory;
 
-extern long stereomode, stereowidth, stereopixelwidth;
+extern int32_t stereomode, stereowidth, stereopixelwidth;
 
-extern long myaimmode, myaimstat, omyaimstat;
+extern int32_t myaimmode, myaimstat, omyaimstat;
 
 extern unsigned char nHostForceDisableAutoaim;
 
--- a/Game/src/dukeunix.h
+++ b/Game/src/dukeunix.h
@@ -14,9 +14,6 @@
 #define __far
 #define __interrupt
 
-#ifdef __GNUC__
-typedef long long __int64;
-#endif
 
 //#define STUBBED(x)
 #ifdef __SUNPRO_C
--- a/Game/src/dukewin.h
+++ b/Game/src/dukewin.h
@@ -2,7 +2,7 @@
 #define _INCL_DUKEWIN_H_ 1
 
 #ifndef _MSC_VER  /* might need this. */
-typedef long long __int64;
+typedef int32_t int32_t __int64;
 #endif
 
 #pragma warning(disable:4761)
@@ -29,7 +29,7 @@
 
 struct find_t
 {
-	long handle;
+	int32_t handle;
     struct _finddata_t data;
 	char name[MAX_PATH];
 };
--- a/Game/src/dummy_audiolib.c
+++ b/Game/src/dummy_audiolib.c
@@ -7,6 +7,7 @@
 //
 
 #include "audiolib/fx_man.h"
+#include <inttypes.h>
 
 char *FX_ErrorString( int ErrorNumber ){
    static char nope = '\0';
@@ -18,7 +19,7 @@
 int   FX_SetupSoundBlaster( fx_blaster_config blaster, int *MaxVoices, int *MaxSampleBits, int *MaxChannels ){return 1;}
 int   FX_Init( int SoundCard, int numvoices, int numchannels, int samplebits, unsigned mixrate ){return FX_Ok;}
 int   FX_Shutdown( void ){return 1;}
-int   FX_SetCallBack( void ( *function )( unsigned long ) ){return FX_Ok;}
+int   FX_SetCallBack( void ( *function )( uint32_t ) ){return FX_Ok;}
 void  FX_SetVolume( int volume ){}
 int   FX_GetVolume( void ){return 1;}
 
@@ -37,33 +38,33 @@
 int FX_SetFrequency( int handle, int frequency ){return 1;}
 
 int FX_PlayVOC( char *ptr, int pitchoffset, int vol, int left, int right,
-               int priority, unsigned long callbackval ){return 1;}
-int FX_PlayLoopedVOC( char *ptr, long loopstart, long loopend,
+               int priority, uint32_t callbackval ){return 1;}
+int FX_PlayLoopedVOC( char *ptr, int32_t loopstart, int32_t loopend,
                      int pitchoffset, int vol, int left, int right, int priority,
-                     unsigned long callbackval ){return 1;}
+                     uint32_t callbackval ){return 1;}
 int FX_PlayWAV( char *ptr, int pitchoffset, int vol, int left, int right,
-               int priority, unsigned long callbackval ){return 1;}
-int FX_PlayLoopedWAV( char *ptr, long loopstart, long loopend,
+               int priority, uint32_t callbackval ){return 1;}
+int FX_PlayLoopedWAV( char *ptr, int32_t loopstart, int32_t loopend,
                      int pitchoffset, int vol, int left, int right, int priority,
-                     unsigned long callbackval ){return 1;}
+                     uint32_t callbackval ){return 1;}
 int FX_PlayVOC3D( char *ptr, int pitchoffset, int angle, int distance,
-                 int priority, unsigned long callbackval ){return 1;}
+                 int priority, uint32_t callbackval ){return 1;}
 int FX_PlayWAV3D( char *ptr, int pitchoffset, int angle, int distance,
-                 int priority, unsigned long callbackval ){return 1;}
-int FX_PlayRaw( char *ptr, unsigned long length, unsigned rate,
+                 int priority, uint32_t callbackval ){return 1;}
+int FX_PlayRaw( char *ptr, uint32_t length, unsigned rate,
                int pitchoffset, int vol, int left, int right, int priority,
-               unsigned long callbackval ){return 1;}
-int FX_PlayLoopedRaw( char *ptr, unsigned long length, char *loopstart,
+               uint32_t callbackval ){return 1;}
+int FX_PlayLoopedRaw( char *ptr, uint32_t length, char *loopstart,
                      char *loopend, unsigned rate, int pitchoffset, int vol, int left,
-                     int right, int priority, unsigned long callbackval ){return 1;}
+                     int right, int priority, uint32_t callbackval ){return 1;}
 int FX_Pan3D( int handle, int angle, int distance ){return 1;}
 int FX_SoundActive( int handle ){return 1;}
 int FX_SoundsPlaying( void ){return 0;}
 int FX_StopSound( int handle ){return 1;}
 int FX_StopAllSounds( void ){return 1;}
-int FX_StartDemandFeedPlayback( void ( *function )( char **ptr, unsigned long *length ),
+int FX_StartDemandFeedPlayback( void ( *function )( char **ptr, uint32_t *length ),
                                int rate, int pitchoffset, int vol, int left, int right,
-                               int priority, unsigned long callbackval ){return 1;}
+                               int priority, uint32_t callbackval ){return 1;}
 int  FX_StartRecording( int MixRate, void ( *function )( char *ptr, int length ) ){return 1;}
 void FX_StopRecord( void ){}
 
@@ -146,11 +147,11 @@
 	return 0;
 }
 
-void MUSIC_SetSongTick(unsigned long PositionInTicks)
+void MUSIC_SetSongTick(uint32_t PositionInTicks)
 {
 }
 
-void MUSIC_SetSongTime(unsigned long milliseconds)
+void MUSIC_SetSongTime(uint32_t milliseconds)
 {
 }
 
--- a/Game/src/file_lib.h
+++ b/Game/src/file_lib.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
--- a/Game/src/funct.h
+++ b/Game/src/funct.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
@@ -39,7 +39,7 @@
 //#line "sounds.c" 166
 extern void MusicShutdown(void );
 //#line "sounds.c" 181
-extern int USRHOOKS_GetMem(char **ptr,unsigned long size);
+extern int USRHOOKS_GetMem(char **ptr,uint32_t size);
 //#line "sounds.c" 192
 extern int USRHOOKS_FreeMem(char *ptr);
 //#line "sounds.c" 200
@@ -49,7 +49,7 @@
 //#line "sounds.c" 251
 extern char loadsound(unsigned short num);
 //#line "sounds.c" 277
-extern int xyzsound(short num,short i,long x,long y,long z);
+extern int xyzsound(short num,short i,int32_t x,int32_t y,int32_t z);
 //#line "sounds.c" 407
 extern void sound(short num);
 //#line "sounds.c" 463
@@ -61,7 +61,7 @@
 //#line "sounds.c" 494
 extern void pan3dsound(void );
 //#line "sounds.c" 571
-extern void TestCallBack(long num);
+extern void TestCallBack(int32_t num);
 //#line "sector.c" 9
 extern short callsound(short sn,short whatsprite);
 //#line "sector.c" 56
@@ -75,19 +75,19 @@
 //#line "sector.c" 161
 extern short checkcursectnums(short sect);
 //#line "sector.c" 169
-extern long ldist(spritetype *s1,spritetype *s2);
+extern int32_t ldist(spritetype *s1,spritetype *s2);
 //#line "sector.c" 177
-extern long dist(spritetype *s1,spritetype *s2);
+extern int32_t dist(spritetype *s1,spritetype *s2);
 //#line "sector.c" 186
-extern short findplayer(spritetype *s,long *d);
+extern short findplayer(spritetype *s,int32_t *d);
 //#line "sector.c" 214
-extern short findotherplayer(short p,long *d);
+extern short findotherplayer(short p,int32_t *d);
 //#line "sector.c" 240
 extern void doanimations(void );
 //#line "sector.c" 301
-extern long getanimationgoal(long *animptr);
+extern int32_t getanimationgoal(int32_t *animptr);
 //#line "sector.c" 315
-extern long setanimation(short animsect,long *animptr,long thegoal,long thevel);
+extern int32_t setanimation(short animsect,int32_t *animptr,int32_t thegoal,int32_t thevel);
 //#line "sector.c" 348
 extern void animatecamsprite(void );
 //#line "sector.c" 369
@@ -105,11 +105,11 @@
 //#line "sector.c" 1104
 extern void operateforcefields(short s,short low);
 //#line "sector.c" 1140
-extern char checkhitswitch(short snum,long w,char switchtype);
+extern char checkhitswitch(short snum,int32_t w,char switchtype);
 //#line "sector.c" 1515
 extern void activatebysector(short sect,short j);
 //#line "sector.c" 1532
-extern void checkhitwall(short spr,short dawallnum,long x,long y,long z,short atwith);
+extern void checkhitwall(short spr,short dawallnum,int32_t x,int32_t y,int32_t z,short atwith);
 //#line "sector.c" 1746
 extern void checkplayerhurt(struct player_struct *p,short j);
 //#line "sector.c" 1816
@@ -170,7 +170,7 @@
 //#line "premap.c" 1077
 extern void waitforeverybody(void);
 //#line "premap.c" 1131
-extern char checksum(long sum);
+extern char checksum(int32_t sum);
 //#line "premap.c" 1163
 extern char getsound(unsigned short num);
 //#line "premap.c" 1189
@@ -190,13 +190,13 @@
 //#line "player.c" 73
 extern void forceplayerangle(struct player_struct *p);
 //#line "player.c" 85
-extern void tracers(long x1,long y1,long z1,long x2,long y2,long z2,long n);
+extern void tracers(int32_t x1,int32_t y1,int32_t z1,int32_t x2,int32_t y2,int32_t z2,int32_t n);
 //#line "player.c" 114
-extern long hits(short i);
+extern int32_t hits(short i);
 //#line "player.c" 131
-extern long hitasprite(short i,short *hitsp);
+extern int32_t hitasprite(short i,short *hitsp);
 //#line "player.c" 152
-extern long hitawall(struct player_struct *p,short *hitw);
+extern int32_t hitawall(struct player_struct *p,short *hitw);
 //#line "player.c" 163
 extern short aim(spritetype *s,short aang, short auto_aim);
 //#line "player.c" 234
@@ -228,7 +228,7 @@
 //#line "menues.c" 18
 extern void cmenu(short cm);
 //#line "menues.c" 38
-extern void savetemp(char *fn,long daptr,long dasiz);
+extern void savetemp(char *fn,int32_t daptr,int32_t dasiz);
 //#line "menues.c" 49
 extern void getangplayers(short snum);
 //#line "menues.c" 67
@@ -241,7 +241,7 @@
 extern void sendgameinfo(void );
 //#line "menues.c" 434
 extern int probe(int x,int y,int i,int n);
-extern int probeXduke(int x,int y,int i,int n, long spriteSize);
+extern int probeXduke(int x,int y,int i,int n, int32_t spriteSize);
 //#line "menues.c" 521
 extern int menutext(int x,int y,short s,short p,char *t);
 //#line "menues.c" 630
@@ -258,9 +258,9 @@
 extern void menus(void );
 void gameexitanycase(void);
 //#line "menues.c" 2414
-extern void palto(char r,char g,char b,long e);
+extern void palto(char r,char g,char b,int32_t e);
 //#line "menues.c" 2436
-extern void drawoverheadmap(long cposx,long cposy,long czoom,short cang);
+extern void drawoverheadmap(int32_t cposx,int32_t cposy,int32_t czoom,short cang);
 //#line "menues.c" 2685
 extern void playanm(char *fn,char);
 //#line "gamedef.c" 122
@@ -276,9 +276,9 @@
 //#line "gamedef.c" 243
 extern void getlabel(void );
 //#line "gamedef.c" 267
-extern long keyword(void );
+extern int32_t keyword(void );
 //#line "gamedef.c" 300
-extern long transword(void );
+extern int32_t transword(void );
 //#line "gamedef.c" 342
 extern void transnum(void );
 //#line "gamedef.c" 402
@@ -292,19 +292,19 @@
 //#line "gamedef.c" 1374
 extern short furthestangle(short i,short angs);
 //#line "gamedef.c" 1404
-extern short furthestcanseepoint(short i,spritetype *ts,long *dax,long *day);
+extern short furthestcanseepoint(short i,spritetype *ts,int32_t *dax,int32_t *day);
 //#line "gamedef.c" 1444
 extern void alterang(short a);
 //#line "gamedef.c" 1512
 extern void move(void);
 //#line "gamedef.c" 1711
-extern void parseifelse(long condition);
+extern void parseifelse(int32_t condition);
 //#line "gamedef.c" 1729
 extern char parse(void );
 //#line "gamedef.c" 2699
-extern void execute(short i,short p,long x);
+extern void execute(short i,short p,int32_t x);
 //#line "game.c" 63
-extern void overwritesprite(long thex,long they,short tilenum,signed char shade,char stat,char dapalnum);
+extern void overwritesprite(int32_t thex,int32_t they,short tilenum,signed char shade,char stat,char dapalnum);
 //#line "game.c" 70
 extern void timerhandler(void);
 //#line "game.c" 75
@@ -318,7 +318,7 @@
 //#line "game.c" 192
 extern int minitext(int x,int y,char *t,char p,char sb);
 //#line "game.c" 231
-extern void gamenumber(long x,long y,long n,char s);
+extern void gamenumber(int32_t x,int32_t y,int32_t n,char s);
 //#line "game.c" 248
 extern void ShutDown(void );
 //#line "game.c" 260
@@ -338,21 +338,21 @@
 //#line "game.c" 924
 extern short badguypic(short pn);
 //#line "game.c" 963
-extern void myos(long x,long y,short tilenum,signed char shade,char orientation);
+extern void myos(int32_t x,int32_t y,short tilenum,signed char shade,char orientation);
 //#line "game.c" 976
-extern void myospal(long x,long y,short tilenum,signed char shade,char orientation,char p);
+extern void myospal(int32_t x,int32_t y,short tilenum,signed char shade,char orientation,char p);
 //#line "game.c" 991
-extern void invennum(long x,long y,char num1,char ha,char sbits);
+extern void invennum(int32_t x,int32_t y,char num1,char ha,char sbits);
 //#line "game.c" 1021
-extern void weaponnum(short ind,long x,long y,long num1,long num2,char ha);
+extern void weaponnum(short ind,int32_t x,int32_t y,int32_t num1,int32_t num2,char ha);
 //#line "game.c" 1049
-extern void weaponnum999(char ind,long x,long y,long num1,long num2,char ha);
+extern void weaponnum999(char ind,int32_t x,int32_t y,int32_t num1,int32_t num2,char ha);
 //#line "game.c" 1088
-extern void weapon_amounts(struct player_struct *p,long x,long y,long u);
+extern void weapon_amounts(struct player_struct *p,int32_t x,int32_t y,int32_t u);
 //#line "game.c" 1197
-extern void digitalnumber(long x,long y,long n,char s,char cs);
+extern void digitalnumber(int32_t x,int32_t y,int32_t n,char s,char cs);
 //#line "game.c" 1223
-extern void scratchmarks(long x,long y,long n,char s,char p);
+extern void scratchmarks(int32_t x,int32_t y,int32_t n,char s,char p);
 //#line "game.c" 1238
 extern void displayinventory(struct player_struct *p);
 //#line "game.c" 1296
@@ -379,25 +379,25 @@
 //#line "game.c" 1752
 extern short strget(short x,short y,char *t,short dalen,short c);
 //#line "game.c" 1819
-extern void displayrest(long smoothratio);
+extern void displayrest(int32_t smoothratio);
 //#line "game.c" 2047
-extern void updatesectorz(long x,long y,long z,short *sectnum);
+extern void updatesectorz(int32_t x,int32_t y,int32_t z,short *sectnum);
 //#line "game.c" 2085
-extern void view(struct player_struct *pp,long *vx,long *vy,long *vz,short *vsectnum,short ang,short horiz);
+extern void view(struct player_struct *pp,int32_t *vx,int32_t *vy,int32_t *vz,short *vsectnum,short ang,short horiz);
 //#line "game.c" 2137
 extern void drawbackground(void );
 //#line "game.c" 2200
-extern void displayrooms(short snum,long smoothratio);
+extern void displayrooms(short snum,int32_t smoothratio);
 //#line "game.c" 2445
 extern short LocateTheLocator(short n,short sn);
 //#line "game.c" 2459
-extern short EGS(short whatsect,long s_x,long s_y,long s_z,short s_pn,signed char s_s,signed char s_xr,signed char s_yr,short s_a,short s_ve,long s_zv,short s_ow,signed char s_ss);
+extern short EGS(short whatsect,int32_t s_x,int32_t s_y,int32_t s_z,short s_pn,signed char s_s,signed char s_xr,signed char s_yr,short s_a,short s_ve,int32_t s_zv,short s_ow,signed char s_ss);
 //#line "game.c" 2537
 extern char wallswitchcheck(short i);
 //#line "game.c" 2588
 extern short spawn(short j,short pn);
 //#line "game.c" 4181
-extern void animatesprites(long x,long y,short a,long smoothratio);
+extern void animatesprites(int32_t x,int32_t y,short a,int32_t smoothratio);
 //#line "game.c" 4859
 extern void cheats(void );
 //#line "game.c" 5303
@@ -429,7 +429,7 @@
 //#line "game.c" 6626
 extern void closedemowrite(void );
 //#line "game.c" 6642
-extern long playback(void );
+extern int32_t playback(void );
 //#line "game.c" 6777
 extern char moveloop(void);
 //#line "game.c" 6796
@@ -447,7 +447,7 @@
 //#line "game.c" 7846
 extern void cameratext(short i);
 //#line "game.c" 7869
-extern void vglass(long x,long y,short a,short wn,short n);
+extern void vglass(int32_t x,int32_t y,short a,short wn,short n);
 //#line "game.c" 7882
 extern void lotsofglass(short i,short wallnum,short n);
 //#line "game.c" 7924
@@ -459,7 +459,7 @@
 //#line "game.c" 8004
 extern void SetupGameButtons(void );
 //#line "game.c" 8068
-extern long GetTime(void );
+extern int32_t GetTime(void );
 //#line "game.c" 8082
 extern void CenterCenter(void );
 //#line "game.c" 8095
@@ -521,17 +521,17 @@
 //#line "actors.c" 7
 extern void updateinterpolations(void);
 //#line "actors.c" 15
-extern void setinterpolation(long *posptr);
+extern void setinterpolation(int32_t *posptr);
 //#line "actors.c" 27
-extern void stopinterpolation(long *posptr);
+extern void stopinterpolation(int32_t *posptr);
 //#line "actors.c" 41
-extern void dointerpolations(long smoothratio);
+extern void dointerpolations(int32_t smoothratio);
 //#line "actors.c" 55
 extern void restoreinterpolations(void);
 //#line "actors.c" 63
-extern long ceilingspace(short sectnum);
+extern int32_t ceilingspace(short sectnum);
 //#line "actors.c" 77
-extern long floorspace(short sectnum);
+extern int32_t floorspace(short sectnum);
 //#line "actors.c" 91
 extern void addammo(short weapon,struct player_struct *p,short amount);
 //#line "actors.c" 99
@@ -541,13 +541,13 @@
 //#line "actors.c" 152
 extern void checkavailweapon(struct player_struct *p);
 //#line "actors.c" 301
-extern long ifsquished(short i,short p);
+extern int32_t ifsquished(short i,short p);
 //#line "actors.c" 326
-extern void hitradius(short i,long r,long hp1,long hp2,long hp3,long hp4);
+extern void hitradius(short i,int32_t r,int32_t hp1,int32_t hp2,int32_t hp3,int32_t hp4);
 //#line "actors.c" 556
-extern int movesprite(short spritenum,long xchange,long ychange,long zchange,unsigned long cliptype);
+extern int movesprite(short spritenum,int32_t xchange,int32_t ychange,int32_t zchange,uint32_t cliptype);
 //#line "actors.c" 643
-extern short ssp(short i,unsigned long cliptype);
+extern short ssp(short i,uint32_t cliptype);
 //#line "actors.c" 658
 extern void insertspriteq(short i);
 //#line "actors.c" 666
--- a/Game/src/function.h
+++ b/Game/src/function.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
--- a/Game/src/game.c
+++ b/Game/src/game.c
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
@@ -72,7 +72,7 @@
 
 #define TIMERUPDATESIZ 32
 
-long cameradist = 0, cameraclock = 0;
+int32_t cameradist = 0, cameraclock = 0;
 char eightytwofifty = 0;
 char playerswhenstarted;
 char qe,cp;
@@ -120,7 +120,7 @@
 task *TimerPtr=NULL;
 #endif
 
-extern long lastvisinc;
+extern int32_t lastvisinc;
 
 // Build Engine port implements this.  --ryan.
 #if PLATFORM_DOS
@@ -348,13 +348,13 @@
     return (x);
 }
 
-void gamenumber(long x,long y,long n,char s)
+void gamenumber(int32_t x,int32_t y,int32_t n,char s)
 {
     char b[10];
     
     
     //
-    // char * ltoa(long l, char * buffer, int radix);
+    // char * ltoa(int32_t l, char * buffer, int radix);
     // is NON-STANDARD and equivalent to STANDARD
     // (void) sprintf(buffer, "%ld", l);
     //ltoa(n,b,10);
@@ -366,7 +366,7 @@
 char recbuf[80];
 void allowtimetocorrecterrorswhenquitting(void)
 {
-     long i, j, oldtotalclock;
+     int32_t i, j, oldtotalclock;
 
      ready2send = 0;
 
@@ -387,7 +387,7 @@
 }
 
 #define MAXUSERQUOTES 4
-long quotebot, quotebotgoal;
+int32_t quotebot, quotebotgoal;
 short user_quote_time[MAXUSERQUOTES];
 char user_quote[MAXUSERQUOTES][128];
 // char typebuflen,typebuf[41];
@@ -394,7 +394,7 @@
 
 static void adduserquote(char *daquote)
 {
-    long i;
+    int32_t i;
 
     for(i=MAXUSERQUOTES-1;i>0;i--)
     {
@@ -453,7 +453,7 @@
 
 void getpackets(void)
 {
-    long i, j, k, l;
+    int32_t i, j, k, l;
     short other, packbufleng;
     input *osyn, *nsyn;
 
@@ -777,7 +777,7 @@
 
 void faketimerhandler()
 {
-    long i, j, k, l;
+    int32_t i, j, k, l;
 //    short who;
     input *osyn, *nsyn;
 
@@ -1085,8 +1085,8 @@
     }
 }
 
-extern long cacnum;
-typedef struct { long *hand, leng; char *lock; } cactype;
+extern int32_t cacnum;
+typedef struct { int32_t *hand, leng; char *lock; } cactype;
 extern cactype cac[];
 
 void caches(void)
@@ -1147,7 +1147,7 @@
 
 void checksync(void)
 {
-      long i, k;
+      int32_t i, k;
 
       for(i=connecthead;i>=0;i=connectpoint2[i])
             if (syncvalhead[i] == syncvaltottail) break;
@@ -1391,7 +1391,7 @@
 
 
 
-void myos(long x, long y, short tilenum, signed char shade, char orientation)
+void myos(int32_t x, int32_t y, short tilenum, signed char shade, char orientation)
 {
     char p;
     short a;
@@ -1404,7 +1404,7 @@
     rotatesprite(x<<16,y<<16,65536L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);
 }
 
-void myospal(long x, long y, short tilenum, signed char shade, char orientation, char p)
+void myospal(int32_t x, int32_t y, short tilenum, signed char shade, char orientation, char p)
 {
     char fp;
     short a;
@@ -1419,7 +1419,7 @@
 
 }
 
-void invennum(long x,long y,char num1,char ha,char sbits)
+void invennum(int32_t x,int32_t y,char num1,char ha,char sbits)
 {
     char dabuf[80] = {0};
     sprintf(dabuf,"%ld",num1);
@@ -1438,7 +1438,7 @@
         rotatesprite((x+4)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
 }
 
-void orderweaponnum(short ind,long x,long y,long num1, long num2,char ha)
+void orderweaponnum(short ind,int32_t x,int32_t y,int32_t num1, int32_t num2,char ha)
 {
     rotatesprite((x-7)<<16,y<<16,65536L,0,THREEBYFIVE+ind+1,ha-10,7,10+128,0,0,xdim-1,ydim-1);
     rotatesprite((x-3)<<16,y<<16,65536L,0,THREEBYFIVE+10,ha,0,10+128,0,0,xdim-1,ydim-1);
@@ -1446,7 +1446,7 @@
     minitextshade(x+1,y-4,"ORDER",26,6,2+8+16+128);
 }
 
-void weaponnum(short ind,long x,long y,long num1, long num2,char ha)
+void weaponnum(short ind,int32_t x,int32_t y,int32_t num1, int32_t num2,char ha)
 {
     char dabuf[80] = {0};
 
@@ -1474,7 +1474,7 @@
     else rotatesprite((x+13)<<16,y<<16,65536L,0,THREEBYFIVE+dabuf[0]-'0',ha,0,10+128,0,0,xdim-1,ydim-1);
 }
 
-void weaponnum999(char ind,long x,long y,long num1, long num2,char ha)
+void weaponnum999(char ind,int32_t x,int32_t y,int32_t num1, int32_t num2,char ha)
 {
     char dabuf[80] = {0};
 
@@ -1513,7 +1513,7 @@
 
 
     //REPLACE FULLY
-void weapon_amounts(struct player_struct *p,long x,long y,long u)
+void weapon_amounts(struct player_struct *p,int32_t x,int32_t y,int32_t u)
 {
      int cw;
 
@@ -1641,13 +1641,13 @@
      }
 }
 
-void digitalnumber(long x,long y,long n,char s,char cs)
+void digitalnumber(int32_t x,int32_t y,int32_t n,char s,char cs)
 {
     short i, j, k, p, c;
     char b[10];
 
     //
-    // char * ltoa(long l, char * buffer, int radix);
+    // char * ltoa(int32_t l, char * buffer, int radix);
     // is NON-STANDARD and equivalent to STANDARD
     // (void) sprintf(buffer, "%ld", l);
     //ltoa(n,b,10);
@@ -1674,9 +1674,9 @@
 
 /*
 
-void scratchmarks(long x,long y,long n,char s,char p)
+void scratchmarks(int32_t x,int32_t y,int32_t n,char s,char p)
 {
-    long i, ni;
+    int32_t i, ni;
 
     ni = n/5;
     for(i=ni;i >= 0;i--)
@@ -1874,7 +1874,7 @@
 void coolgaugetext(short snum)
 {
     struct player_struct *p;
-    long i, j, o, ss, u;
+    int32_t i, j, o, ss, u;
     char permbit;
 	short offx = 3, offy = 3, stepx=60, stepy=6;
 
@@ -2147,14 +2147,14 @@
   
 
 #define AVERAGEFRAMES 16
-static long frameval[AVERAGEFRAMES], framecnt = 0;
+static int32_t frameval[AVERAGEFRAMES], framecnt = 0;
 
 void tics(short offx, short offy, short color)
 {
-    long i;
+    int32_t i;
 	char fps[512], mapname[512];
-	long currentFps;
-	static long fpsAvg = 0, savedFps = 0;
+	int32_t currentFps;
+	static int32_t fpsAvg = 0, savedFps = 0;
 	static boolean toggle = true;
 
 	strcpy(mapname,boardfilename);
@@ -2249,7 +2249,7 @@
 
 void operatefta(void)
 {
-     long i, j, k;
+     int32_t i, j, k;
 
      if(ud.screen_size > 0) j = 200-45; else j = 200-8;
      quotebot = min(quotebot,j);
@@ -2360,7 +2360,7 @@
 void binscreen(void)
 {
 #ifdef PLATFORM_DOS
-    long fil;
+    int32_t fil;
 	if (VOLUMEONE)
 	    fil = kopen4load("dukesw.bin",1);
 	else
@@ -2672,13 +2672,13 @@
 }
 
 
-void displayrest(long smoothratio)
+void displayrest(int32_t smoothratio)
 {
-    long a, i, j;
+    int32_t a, i, j;
 
     struct player_struct *pp;
     walltype *wal;
-    long cposx,cposy,cang;
+    int32_t cposx,cposy,cang;
 
     pp = &ps[screenpeek];
 
@@ -2876,10 +2876,10 @@
 }
 
 
-void updatesectorz(long x, long y, long z, short *sectnum)
+void updatesectorz(int32_t x, int32_t y, int32_t z, short *sectnum)
 {
     walltype *wal;
-    long i, j, cz, fz;
+    int32_t i, j, cz, fz;
 
     getzsofslope(*sectnum,x,y,&cz,&fz);
     if ((z >= cz) && (z <= fz))
@@ -2914,10 +2914,10 @@
     *sectnum = -1;
 }
 
-void view(struct player_struct *pp, long *vx, long *vy,long *vz,short *vsectnum, short ang, short horiz)
+void view(struct player_struct *pp, int32_t *vx, int32_t *vy,int32_t *vz,short *vsectnum, short ang, short horiz)
 {
      spritetype *sp;
-     long i, nx, ny, nz, hx, hy, hitx, hity, hitz;
+     int32_t i, nx, ny, nz, hx, hy, hitx, hity, hitz;
      short bakcstat, hitsect, hitwall, hitsprite, daang;
 
      nx = (sintable[(ang+1536)&2047]>>4);
@@ -2976,7 +2976,7 @@
 void drawbackground(void)
 {
      short dapicnum;
-     long x,y,x1,y1,x2,y2;
+     int32_t x,y,x1,y1,x2,y2;
 
      flushperms();
 
@@ -3054,15 +3054,15 @@
 #define FOFTILE 13
 #define FOFTILEX 32
 #define FOFTILEY 32
-long tempsectorz[MAXSECTORS];
-long tempsectorpicnum[MAXSECTORS];
+int32_t tempsectorz[MAXSECTORS];
+int32_t tempsectorpicnum[MAXSECTORS];
 //short tempcursectnum;
 
-static void SE40_Draw(int spnum,long x,long y,long z,short a,short h,long smoothratio)
+static void SE40_Draw(int spnum,int32_t x,int32_t y,int32_t z,short a,short h,int32_t smoothratio)
 {
  int i=0,j=0,k=0;
  int floor1=0,floor2=0,ok=0,fofmode=0;
- long offx,offy;
+ int32_t offx,offy;
 
  if(sprite[spnum].ang!=512) return;
 
@@ -3172,7 +3172,7 @@
 
 
 
-static void se40code(long x,long y,long z,long a,long h, long smoothratio)
+static void se40code(int32_t x,int32_t y,int32_t z,int32_t a,int32_t h, int32_t smoothratio)
 {
     int i;
 
@@ -3197,14 +3197,14 @@
     }
 }
 
-static long oyrepeat=-1;
+static int32_t oyrepeat=-1;
 
-void displayrooms(short snum,long smoothratio)
+void displayrooms(short snum,int32_t smoothratio)
 {
-    long cposx,cposy,cposz,dst,j,fz,cz;
+    int32_t cposx,cposy,cposz,dst,j,fz,cz;
     short sect, cang, k, choriz;
     struct player_struct *p;
-    long tposx,tposy,i;
+    int32_t tposx,tposy,i;
     short tang;
 
     p = &ps[snum];
@@ -3266,7 +3266,7 @@
         {
             walock[MAXTILES-1] = 254;
             if (waloff[MAXTILES-1] == 0)
-                allocache((long *)&waloff[MAXTILES-1],100*160,&walock[MAXTILES-1]);
+                allocache((int32_t *)&waloff[MAXTILES-1],100*160,&walock[MAXTILES-1]);
             setviewtotile(MAXTILES-1,100L,160L);
         }
         else if( ( ud.screen_tilting && p->rotscrnang ) || ud.detail==0 )
@@ -3441,7 +3441,7 @@
     return -1;
 }
 
-short EGS(short whatsect,long s_x,long s_y,long s_z,short s_pn,signed char s_s,signed char s_xr,signed char s_yr,short s_a,short s_ve,long s_zv,short s_ow,signed char s_ss)
+short EGS(short whatsect,int32_t s_x,int32_t s_y,int32_t s_z,short s_pn,signed char s_s,signed char s_xr,signed char s_yr,short s_a,short s_ve,int32_t s_zv,short s_ow,signed char s_ss)
 {
     short i;
     spritetype *s;
@@ -3571,11 +3571,11 @@
 }
 
 
-long tempwallptr;
+int32_t tempwallptr;
 short spawn( short j, short pn )
 {
     short i, s, startwall, endwall, sect, clostest;
-    long x, y, d;
+    int32_t x, y, d;
     spritetype *sp;
 
     if(j >= 0)
@@ -4981,7 +4981,7 @@
 
                     case 20:
                     {
-                        long q;
+                        int32_t q;
 
                         startwall = sector[sect].wallptr;
                         endwall = startwall+sector[sect].wallnum;
@@ -5370,10 +5370,10 @@
 }
 
 
-void animatesprites(long x,long y,short a,long smoothratio)
+void animatesprites(int32_t x,int32_t y,short a,int32_t smoothratio)
 {
     short i, j, k, p, sect;
-    long l, t1,t3,t4;
+    int32_t l, t1,t3,t4;
     spritetype *s,*t;
 
     for(j=0;j < spritesortcnt; j++)
@@ -5872,7 +5872,7 @@
 				// Lame fix. ok for w32. Doesn't work for other plateform.
 				// How to make a differene between a timer and an address??
             {
-                l = *(long *)(t4+8);
+                l = *(int32_t *)(t4+8);
 
                 switch( l )
                 {
@@ -5920,7 +5920,7 @@
                         break;
                 }
 
-                t->picnum += k + ( *(long *)t4 ) + l * t3;
+                t->picnum += k + ( *(int32_t *)t4 ) + l * t3;
 
                 if(l > 0) while(tilesizx[t->picnum] == 0 && t->picnum > 0 )
                     t->picnum -= l;       //Hack, for actors
@@ -5943,7 +5943,7 @@
             }
             else if( ud.shadows && spritesortcnt < (MAXSPRITESONSCREEN-2))
             {
-                long daz,xrep,yrep;
+                int32_t daz,xrep,yrep;
 
                 if( (sector[sect].lotag&0xff) > 2 || s->statnum == 4 || s->statnum == 5 || s->picnum == DRONE || s->picnum == COMMANDER )
                     daz = sector[sect].floorz;
@@ -6579,11 +6579,11 @@
 }
 
 
-long nonsharedtimer;
+int32_t nonsharedtimer;
 void nonsharedkeys(void)
 {
     short i,ch, weapon;
-    long j;
+    int32_t j;
         
     if(ud.recstat == 2)
     {
@@ -7633,7 +7633,7 @@
 void loadtmb(void)
 {
     char tmb[8000];
-    long fil, l;
+    int32_t fil, l;
 
     fil = kopen4load("d3dtimbr.tmb",0);
     if(fil == -1) return;
@@ -7680,7 +7680,7 @@
 	char userconfilename[512];
 
    mymembuf = (char *)&hittype[0];
-   labelcode = (long *)&sector[0];
+   labelcode = (int32_t *)&sector[0];
    label = (char *)&sprite[0];
 
 	sprintf(userconfilename, "%s", confilename);
@@ -7951,7 +7951,7 @@
         gameexit("Please put Duke Nukem 3D Atomic Edition CD in drive.");
 }
 
-void writestring(long a1,long a2,long a3,short a4,long vx,long vy,long vz)
+void writestring(int32_t a1,int32_t a2,int32_t a3,short a4,int32_t vx,int32_t vy,int32_t vz)
 {
 
     FILE *fp;
@@ -7969,7 +7969,7 @@
 {
 #if PLATFORM_DOS
  short drive_count, drive;
- long dalen = 0;
+ int32_t dalen = 0;
  struct find_t dafilet;
  int fil;
 
@@ -8144,9 +8144,9 @@
 
 int main(int argc,char **argv)
 {
-    long i, j;
+    int32_t i, j;
 	int32 iScriptHandle;
-	long filehandle;
+	int32_t filehandle;
 
 	char HEAD[2048], HEAD2[2048], HEADA[2048];
 	char kbdKey;
@@ -8710,7 +8710,7 @@
     short i,j;
 	char firstdemofile_[512];
 	int32 dummy;
-	long groupefil_crc32_from_demo[MAXGROUPFILES];
+	int32_t groupefil_crc32_from_demo[MAXGROUPFILES];
 
     if(which_demo == 10)
         d[4] = 'x';
@@ -8765,7 +8765,7 @@
 	// FIX_00062: Better support and identification for GRP and CON files for 1.3/1.3d/1.4/1.5
 	if(ver==BYTEVERSION)
 	{
-		kread(recfilep, (long *)groupefil_crc32_from_demo, sizeof(groupefil_crc32_from_demo));
+		kread(recfilep, (int32_t *)groupefil_crc32_from_demo, sizeof(groupefil_crc32_from_demo));
 	
 		for(i=0; i<MAXGROUPFILES; i++)
 			if(groupefil_crc32_from_demo[i]!=groupefil_crc32[i])
@@ -8830,7 +8830,7 @@
 void opendemowrite(void)
 {
     char d[] = "demo1.dmo";
-    long dummylong = 0;
+    int32_t dummylong = 0;
     char ver;
     short i;
 	char fullpathdemofilename[16];
@@ -8858,7 +8858,7 @@
     fwrite(&dummylong,4,1,frecfilep);
     fwrite(&ver,sizeof(char),1,frecfilep);
 	// FIX_00062: Better support and identification for GRP and CON files for 1.3/1.3d/1.4/1.5
-	fwrite((long *)groupefil_crc32,sizeof(groupefil_crc32),1,frecfilep);
+	fwrite((int32_t *)groupefil_crc32,sizeof(groupefil_crc32),1,frecfilep);
     fwrite((char *)&ud.volume_number,sizeof(char),1,frecfilep);
     fwrite((char *)&ud.level_number,sizeof(char),1,frecfilep);
     fwrite((char *)&ud.player_skill,sizeof(char),1,frecfilep);
@@ -8940,10 +8940,10 @@
 
 char in_menu = 0;
 
-// extern long syncs[];
-long playback(void)
+// extern int32_t syncs[];
+int32_t playback(void)
 {
-    long i,j,k,l,t;
+    int32_t i,j,k,l,t;
     char foundemo;
 #ifdef DBGRECORD
 	FILE * pFile;
@@ -9143,7 +9143,7 @@
 
 char moveloop()
 {
-    long i;
+    int32_t i;
 
     if (numplayers > 1)
 	{
@@ -9169,7 +9169,7 @@
 
 void fakedomovethingscorrect(void)
 {
-     long i;
+     int32_t i;
      struct player_struct *p;
 
      if (numplayers < 2) return;
@@ -9203,8 +9203,8 @@
 {
         input *syn;
         struct player_struct *p;
-        long i, j, k, doubvel, fz, cz, hz, lz, x, y;
-        unsigned long sb_snum;
+        int32_t i, j, k, doubvel, fz, cz, hz, lz, x, y;
+        uint32_t sb_snum;
         short psect, psectlotag, tempsect, backcstat;
         char shrunk, spritebridge;
 
@@ -9510,7 +9510,7 @@
         }
         else if ( syn->avel )          //p->ang += syncangvel * constant
         {                         //ENGINE calculates angvel for you
-            long tempang;
+            int32_t tempang;
 
             tempang = syn->avel<<1;
 
@@ -9886,10 +9886,10 @@
 void dobonus(char bonusonly)
 {
     short t, tinc,gfx_offset;
-    long i, y,xfragtotal,yfragtotal;
+    int32_t i, y,xfragtotal,yfragtotal;
     short bonuscnt;
 
-    long breathe[] =
+    int32_t breathe[] =
     {
          0,  30,VICTORY1+1,176,59,
         30,  60,VICTORY1+2,176,59,
@@ -9897,7 +9897,7 @@
         90, 120,0         ,176,59
     };
 
-    long bossmove[] =
+    int32_t bossmove[] =
     {
          0, 120,VICTORY1+3,86,59,
        220, 260,VICTORY1+4,86,59,
@@ -10438,7 +10438,7 @@
 void cameratext(short i)
 {
     char flipbits;
-    long x , y;
+    int32_t x , y;
 
     if(!T1)
     {
@@ -10458,9 +10458,9 @@
     }
 }
 
-void vglass(long x,long y,short a,short wn,short n)
+void vglass(int32_t x,int32_t y,short a,short wn,short n)
 {
-    long z, zincs;
+    int32_t z, zincs;
     short sect;
 
     sect = wall[wn].nextsector;
@@ -10473,7 +10473,7 @@
 
 void lotsofglass(short i,short wallnum,short n)
 {
-     long j, xv, yv, z, x1, y1;
+     int32_t j, xv, yv, z, x1, y1;
      short sect, a;
 
      sect = -1;
@@ -10521,7 +10521,7 @@
 
 void spriteglass(short i,short n)
 {
-    long j, k, a, z;
+    int32_t j, k, a, z;
 
     for(j=n;j>0;j--)
     {
@@ -10534,7 +10534,7 @@
 
 void ceilingglass(short i,short sectnum,short n)
 {
-     long j, xv, yv, z, x1, y1;
+     int32_t j, xv, yv, z, x1, y1;
      short a,s, startwall,endwall;
 
      startwall = sector[sectnum].wallptr;
@@ -10563,7 +10563,7 @@
 
 void lotsofcolourglass(short i,short wallnum,short n)
 {
-     long j, xv, yv, z, x1, y1;
+     int32_t j, xv, yv, z, x1, y1;
      short sect = -1, a, k;
 
      if(wallnum < 0)
@@ -10664,7 +10664,7 @@
 ===================
 */
 
-long GetTime(void)
+int32_t GetTime(void)
    {
    return totalclock;
    }
--- a/Game/src/gamedef.c
+++ b/Game/src/gamedef.c
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
@@ -32,11 +32,11 @@
 static short total_lines,line_number;
 static char checking_ifelse,parsing_state,*last_used_text;
 static short num_squigilly_brackets;
-static long last_used_size;
+static int32_t last_used_size;
 
 static short g_i,g_p;
-static long g_x;
-static long *g_t;
+static int32_t g_x;
+static int32_t *g_t;
 static spritetype *g_sp;
 
 #define NUMKEYWORDS     112
@@ -204,7 +204,7 @@
 
 void getglobalz(short i)
 {
-    long hz,lz,zr;
+    int32_t hz,lz,zr;
 
     spritetype *s = &sprite[i];
 
@@ -253,7 +253,7 @@
 void makeitfall(short i)
 {
     spritetype *s = &sprite[i];
-    long hz,lz,c;
+    int32_t hz,lz,c;
 
     if( floorspace(s->sectnum) )
         c = 0;
@@ -291,7 +291,7 @@
 
 void getlabel(void)
 {
-    long i;
+    int32_t i;
 
     while( isalnum(*textptr) == 0 )
     {
@@ -308,9 +308,9 @@
     label[(labelcnt<<6)+i] = 0;
 }
 
-long keyword(void)
+int32_t keyword(void)
 {
-    long i;
+    int32_t i;
     char *temptextptr;
 
     temptextptr = textptr;
@@ -337,9 +337,9 @@
     return -1;
 }
 
-long transword(void) //Returns its code #
+int32_t transword(void) //Returns its code #
 {
-    long i, l;
+    int32_t i, l;
 
     while( isaltok(*textptr) == 0 )
     {
@@ -388,7 +388,7 @@
 
 void transnum(void)
 {
-    long i, l;
+    int32_t i, l;
 
     while( isaltok(*textptr) == 0 )
     {
@@ -444,7 +444,7 @@
 
 char parsecommand(int readfromGRP)
 {
-    long i, j, k, *tempscrptr;
+    int32_t i, j, k, *tempscrptr;
     char done, *origtptr, temp_ifelse_check, tw;
     short temp_line_number;
     int fp;
@@ -1375,7 +1375,7 @@
             return 0;
         case 60:
 		{
-			long params[30];
+			int32_t params[30];
 
 			scriptptr--;
 			for(j = 0; j < 30; j++)
@@ -1513,7 +1513,7 @@
 
 void copydefaultcons(void)
 {
-    long i, fs, fpi;
+    int32_t i, fs, fpi;
     FILE *fpo;
 
     for(i=0;i<3;i++)
@@ -1550,7 +1550,7 @@
 
 void loadefs(char *filenam, char *mptr, int readfromGRP)
 {
-    long fs,fp;
+    int32_t fs,fp;
 	char kbdKey;
 
 	memset(script, 0, sizeof(script));
@@ -1675,7 +1675,7 @@
 char dodge(spritetype *s)
 {
     short i;
-    long bx,by,mx,my,bxvect,byvect,mxvect,myvect,d;
+    int32_t bx,by,mx,my,bxvect,byvect,mxvect,myvect,d;
 
     mx = s->x;
     my = s->y;
@@ -1707,7 +1707,7 @@
 short furthestangle(short i,short angs)
 {
     short j, hitsect,hitwall,hitspr,furthest_angle, angincs;
-    long hx, hy, hz, d, greatestd;
+    int32_t hx, hy, hz, d, greatestd;
     spritetype *s = &sprite[i];
 
     greatestd = -(1<<30);
@@ -1734,10 +1734,10 @@
     return (furthest_angle&2047);
 }
 
-short furthestcanseepoint(short i,spritetype *ts,long *dax,long *day)
+short furthestcanseepoint(short i,spritetype *ts,int32_t *dax,int32_t *day)
 {
     short j, hitsect,hitwall,hitspr, angincs;
-    long hx, hy, hz, d, da;//, d, cd, ca,tempx,tempy,cx,cy;
+    int32_t hx, hy, hz, d, da;//, d, cd, ca,tempx,tempy,cx,cy;
     spritetype *s = &sprite[i];
 
     if( (g_t[0]&63) ) return -1;
@@ -1773,9 +1773,9 @@
 void alterang(short a)
 {
     short aang, angdif, goalang,j;
-    long ticselapsed, *moveptr;
+    int32_t ticselapsed, *moveptr;
 
-    moveptr = (long *)g_t[1];
+    moveptr = (int32_t *)g_t[1];
 
     ticselapsed = (g_t[0])&31;
 
@@ -1840,9 +1840,9 @@
 
 void move()
 {
-    long l, *moveptr;
+    int32_t l, *moveptr;
     short a, goalang, angdif;
-    long daxvel;
+    int32_t daxvel;
 
     a = g_sp->hitag;
 
@@ -1886,7 +1886,7 @@
 
     if(a&face_player_smart)
     {
-        long newx,newy;
+        int32_t newx,newy;
 
         newx = ps[g_p].posx+(ps[g_p].posxv/768);
         newy = ps[g_p].posy+(ps[g_p].posyv/768);
@@ -1907,7 +1907,7 @@
         return;
     }
 
-    moveptr = (long *)g_t[1];
+    moveptr = (int32_t *)g_t[1];
 
     if(a&geth) g_sp->xvel += (*moveptr-g_sp->xvel)>>1;
     if(a&getv) g_sp->zvel += ((*(moveptr+1)<<4)-g_sp->zvel)>>1;
@@ -2037,7 +2037,7 @@
 
 char parse(void);
 
-void parseifelse(long condition)
+void parseifelse(int32_t condition)
 {
     if( condition )
     {
@@ -2046,7 +2046,7 @@
     }
     else
     {
-        insptr = (long *) *(insptr+1);
+        insptr = (int32_t *) *(insptr+1);
         if(*insptr == 10)
         {
             insptr+=2;
@@ -2055,11 +2055,11 @@
     }
 }
 
-// long *it = 0x00589a04;
+// int32_t *it = 0x00589a04;
 
 char parse(void)
 {
-    long j, l, s;
+    int32_t j, l, s;
 
     if(killit_flag) return 1;
 
@@ -2196,9 +2196,9 @@
         case 24:
             insptr++;
             g_t[5] = *insptr;
-            g_t[4] = *(long *)(g_t[5]);       // Action
-            g_t[1] = *(long *)(g_t[5]+4);       // move
-            g_sp->hitag = *(long *)(g_t[5]+8);    // Ai
+            g_t[4] = *(int32_t *)(g_t[5]);       // Action
+            g_t[1] = *(int32_t *)(g_t[5]+4);       // move
+            g_sp->hitag = *(int32_t *)(g_t[5]+8);    // Ai
             g_t[0] = g_t[2] = g_t[3] = 0;
             if(g_sp->hitag&random_angle)
                 g_sp->ang = TRAND&2047;
@@ -2233,7 +2233,7 @@
                 hittype[g_i].timetosleep = SLEEPTIME;
             break;
         case 10:
-            insptr = (long *) *(insptr+1);
+            insptr = (int32_t *) *(insptr+1);
             break;
         case 100:
             insptr++;
@@ -2358,7 +2358,7 @@
             g_sp->yoffset = 0;
 //            if(!gotz)
             {
-                long c;
+                int32_t c;
 
                 if( floorspace(g_sp->sectnum) )
                     c = 0;
@@ -2582,11 +2582,11 @@
             break;
         case 17:
             {
-                long *tempscrptr;
+                int32_t *tempscrptr;
 
                 tempscrptr = insptr+2;
 
-                insptr = (long *) *(insptr+1);
+                insptr = (int32_t *) *(insptr+1);
                 while(1) if(parse()) break;
                 insptr = tempscrptr;
             }
@@ -3132,7 +3132,7 @@
     return 0;
 }
 
-void execute(short i,short p,long x)
+void execute(short i,short p,int32_t x)
 {
     char done;
 
@@ -3160,13 +3160,13 @@
     if(g_t[4])
     {
         g_sp->lotag += TICSPERFRAME;
-        if(g_sp->lotag > *(long *)(g_t[4]+16) )
+        if(g_sp->lotag > *(int32_t *)(g_t[4]+16) )
         {
             g_t[2]++;
             g_sp->lotag = 0;
-            g_t[3] +=  *(long *)( g_t[4]+12 );
+            g_t[3] +=  *(int32_t *)( g_t[4]+12 );
         }
-        if( klabs(g_t[3]) >= klabs( *(long *)(g_t[4]+4) * *(long *)(g_t[4]+12) ) )
+        if( klabs(g_t[3]) >= klabs( *(int32_t *)(g_t[4]+4) * *(int32_t *)(g_t[4]+12) ) )
             g_t[3] = 0;
     }
 
--- a/Game/src/gamedefs.h
+++ b/Game/src/gamedefs.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
--- a/Game/src/global.c
+++ b/Game/src/global.c
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
@@ -70,9 +70,9 @@
 short global_random;
 short neartagsector, neartagwall, neartagsprite;
 
-long gc,neartaghitdist,lockclock,max_player_health,max_armour_amount,max_ammo_amount[MAX_WEAPONS];
+int32_t gc,neartaghitdist,lockclock,max_player_health,max_armour_amount,max_ammo_amount[MAX_WEAPONS];
 
-// long temp_data[MAXSPRITES][6];
+// int32_t temp_data[MAXSPRITES][6];
 struct weaponhit hittype[MAXSPRITES];
 short spriteq[1024],spriteqloc,spriteqamount=64;
 
@@ -83,10 +83,10 @@
 
 struct animwalltype animwall[MAXANIMWALLS];
 short numanimwalls;
-long *animateptr[MAXANIMATES], animategoal[MAXANIMATES], animatevel[MAXANIMATES], animatecnt;
-// long oanimateval[MAXANIMATES];
+int32_t *animateptr[MAXANIMATES], animategoal[MAXANIMATES], animatevel[MAXANIMATES], animatecnt;
+// int32_t oanimateval[MAXANIMATES];
 short animatesect[MAXANIMATES];
-long msx[2048],msy[2048];
+int32_t msx[2048],msy[2048];
 short cyclers[MAXCYCLERS][6],numcyclers;
 
 char fta_quotes[NUMOFFIRSTTIMEACTIVE][64];
@@ -103,12 +103,12 @@
 char betaname[80];
 
 char level_names[44][33],level_file_names[44][128];
-long partime[44],designertime[44];
+int32_t partime[44],designertime[44];
 char volume_names[4][33] = { "L.A. MELTDOWN", "LUNAR APOCALYPSE", "SHRAPNEL CITY", "" }; // Names are not in 1.3 con files. MUST be in code.
 char skill_names[5][33] = { "PIECE OF CAKE", "LET'S ROCK", "COME GET SOME", "DAMN I'M GOOD", "" };
 
-volatile long checksume;
-long soundsiz[NUM_SOUNDS];
+volatile int32_t checksume;
+int32_t soundsiz[NUM_SOUNDS];
 
 short soundps[NUM_SOUNDS],soundpe[NUM_SOUNDS],soundvo[NUM_SOUNDS];
 char soundm[NUM_SOUNDS],soundpr[NUM_SOUNDS];
@@ -123,7 +123,7 @@
 
 char numplayersprites,earthquaketime;
 
-long fricxv,fricyv;
+int32_t fricxv,fricyv;
 struct player_orig po[MAXPLAYERS];
 struct player_struct ps[MAXPLAYERS];
 struct user_defs ud;
@@ -130,21 +130,21 @@
 
 char pus, pub;
 char syncstat, syncval[MAXPLAYERS][MOVEFIFOSIZ];
-long syncvalhead[MAXPLAYERS], syncvaltail, syncvaltottail;
+int32_t syncvalhead[MAXPLAYERS], syncvaltail, syncvaltottail;
 
 input sync[MAXPLAYERS], loc;
 input recsync[RECSYNCBUFSIZ];
-long avgfvel, avgsvel, avgavel, avghorz, avgbits;
+int32_t avgfvel, avgsvel, avgavel, avghorz, avgbits;
 
 
 input inputfifo[MOVEFIFOSIZ][MAXPLAYERS];
 input recsync[RECSYNCBUFSIZ];
 
-long movefifosendplc;
+int32_t movefifosendplc;
 
   //Multiplayer syncing variables
 short screenpeek;
-long movefifoend[MAXPLAYERS];
+int32_t movefifoend[MAXPLAYERS];
 
 
     //Game recording variables
@@ -151,10 +151,10 @@
 
 char playerreadyflag[MAXPLAYERS],ready2send;
 char playerquitflag[MAXPLAYERS];
-long vel, svel, angvel, horiz, ototalclock, respawnactortime=768, respawnitemtime=768, groupfile;
+int32_t vel, svel, angvel, horiz, ototalclock, respawnactortime=768, respawnitemtime=768, groupfile;
 
-long script[MAXSCRIPTSIZE],*scriptptr,*insptr,*labelcode,labelcnt;
-long *actorscrptr[MAXTILES],*parsing_actor;
+int32_t script[MAXSCRIPTSIZE],*scriptptr,*insptr,*labelcode,labelcnt;
+int32_t *actorscrptr[MAXTILES],*parsing_actor;
 char *label,*textptr,error,warning,killit_flag;
 char *music_pointer;
 char actortype[MAXTILES];
@@ -185,10 +185,10 @@
         FREEZEAMMO
     };
 
-long impact_damage;
+int32_t impact_damage;
 
         //GLOBAL.C - replace the end "my's" with this
-long myx, omyx, myxvel, myy, omyy, myyvel, myz, omyz, myzvel;
+int32_t myx, omyx, myxvel, myy, omyy, myyvel, myz, omyz, myzvel;
 short myhoriz, omyhoriz, myhorizoff, omyhorizoff;
 short myang, omyang, mycursectnum, myjumpingcounter,frags[MAXPLAYERS][MAXPLAYERS];
 
@@ -195,9 +195,9 @@
 char myjumpingtoggle, myonground, myhardlanding, myreturntocenter;
 signed char multiwho, multipos, multiwhat, multiflag;
 
-long fakemovefifoplc,movefifoplc;
-long myxbak[MOVEFIFOSIZ], myybak[MOVEFIFOSIZ], myzbak[MOVEFIFOSIZ];
-long myhorizbak[MOVEFIFOSIZ],dukefriction = 0xcc00, show_shareware;
+int32_t fakemovefifoplc,movefifoplc;
+int32_t myxbak[MOVEFIFOSIZ], myybak[MOVEFIFOSIZ], myzbak[MOVEFIFOSIZ];
+int32_t myhorizbak[MOVEFIFOSIZ],dukefriction = 0xcc00, show_shareware;
 
 short myangbak[MOVEFIFOSIZ];
 char myname[2048] = {"XDUKE"};
@@ -206,16 +206,16 @@
 // char networkmode = 255, movesperpacket = 1,gamequit = 0,playonten = 0,everyothertime;
 char networkmode = 255, movesperpacket = 1,gamequit = 0,everyothertime;
 // CTW END - MODIFICATION
-long numfreezebounces=3,rpgblastradius,pipebombblastradius,tripbombblastradius,shrinkerblastradius,morterblastradius,bouncemineblastradius,seenineblastradius;
+int32_t numfreezebounces=3,rpgblastradius,pipebombblastradius,tripbombblastradius,shrinkerblastradius,morterblastradius,bouncemineblastradius,seenineblastradius;
 STATUSBARTYPE sbar;
 
-long myminlag[MAXPLAYERS], mymaxlag, otherminlag, bufferjitter = 1;
+int32_t myminlag[MAXPLAYERS], mymaxlag, otherminlag, bufferjitter = 1;
 short numclouds,clouds[128],cloudx[128],cloudy[128];
-long cloudtotalclock = 0,totalmemory = 0;
-long numinterpolations = 0, startofdynamicinterpolations = 0;
-long oldipos[MAXINTERPOLATIONS];
-long bakipos[MAXINTERPOLATIONS];
-long *curipos[MAXINTERPOLATIONS];
+int32_t cloudtotalclock = 0,totalmemory = 0;
+int32_t numinterpolations = 0, startofdynamicinterpolations = 0;
+int32_t oldipos[MAXINTERPOLATIONS];
+int32_t bakipos[MAXINTERPOLATIONS];
+int32_t *curipos[MAXINTERPOLATIONS];
 
 
 // portability stuff.  --ryan.
@@ -303,7 +303,7 @@
 #elif PLATFORM_WIN32
 int _dos_findfirst(char *filename, int x, struct find_t *f)
 {
-    long rc = _findfirst(filename, &f->data);
+    int32_t rc = _findfirst(filename, &f->data);
     f->handle = rc;
     if (rc != -1)
     {
@@ -687,7 +687,7 @@
     *x = ptr;
 }
 
-void *SafeLevelMalloc (long size)
+void *SafeLevelMalloc (int32_t size)
 {
 	void *ptr;
 
@@ -745,13 +745,13 @@
 #if (BYTE_ORDER == LITTLE_ENDIAN)
 #define KeepShort IntelShort
 #define SwapShort MotoShort
-#define KeepLong IntelLong
-#define SwapLong MotoLong
+#define Keepint32_t IntelLong
+#define Swapint32_t MotoLong
 #else
 #define KeepShort MotoShort
 #define SwapShort IntelShort
-#define KeepLong MotoLong
-#define SwapLong IntelLong
+#define Keepint32_t MotoLong
+#define Swapint32_t IntelLong
 #endif
 
 short	SwapShort (short l)
@@ -770,7 +770,7 @@
 }
 
 
-int32_t	SwapLong (int32_t l)
+int32_t	Swapint32_t (int32_t l)
 {
 	byte	b1,b2,b3,b4;
 
@@ -782,7 +782,7 @@
 	return ((long)b1<<24) + ((long)b2<<16) + ((long)b3<<8) + b4;
 }
 
-int32_t	KeepLong (int32_t l)
+int32_t	Keepint32_t (int32_t l)
 {
 	return l;
 }
@@ -793,7 +793,7 @@
 #undef SwapShort
 #undef SwapLong
 
-void SwapIntelLong(long *l)
+void SwapIntelLong(int32_t *l)
 {
     *l = IntelLong(*l);
 }
@@ -803,7 +803,7 @@
     *s = IntelShort(*s);
 }
 
-void SwapIntelLongArray(long *l, int num)
+void SwapIntelLongArray(int32_t *l, int num)
 {
     while (num--) {
         SwapIntelLong(l);
@@ -868,7 +868,7 @@
 	return string;
 }
 
-char *ltoa(long value, char *string, int radix)
+char *ltoa(int32_t value, char *string, int radix)
 {
 	switch (radix) {
 		case 10:
@@ -885,7 +885,7 @@
 	return string;
 }
 
-char *ultoa(unsigned long value, char *string, int radix)
+char *ultoa(unsigned int32_t value, char *string, int radix)
 {
 	switch (radix) {
 		case 10:
--- a/Game/src/keyboard.c
+++ b/Game/src/keyboard.c
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
--- a/Game/src/keyboard.h
+++ b/Game/src/keyboard.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
--- a/Game/src/menues.c
+++ b/Game/src/menues.c
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
@@ -94,7 +94,7 @@
 /*
 void TENtext(void)
 {
-    long dacount,dalastcount;
+    int32_t dacount,dalastcount;
 
     puts("\nDuke Nukem 3D has been licensed exclusively to TEN (Total");
     puts("Entertainment Network) for wide-area networked (WAN) multiplayer");
@@ -146,7 +146,7 @@
 }
 
 
-void savetemp(char *fn,long daptr,long dasiz)
+void savetemp(char *fn,int32_t daptr,int32_t dasiz)
 {
     int fp;
 
@@ -179,8 +179,8 @@
 {
 
     char fn[] = "game0.sav";
-    long fil;
-    long bv;
+    int32_t fil;
+    int32_t bv;
 
          fn[4] = spot+'0';
 
@@ -219,7 +219,7 @@
      char fn[] = "game0.sav";
      char mpfn[] = "gameA_00.sav";
      char *fnptr, scriptptrs[MAXSCRIPTSIZE];
-     long fil, bv, i, j, x;
+     int32_t fil, bv, i, j, x;
      int32 nump;
 
      if(spot < 0)
@@ -366,7 +366,7 @@
          if(actorscrptr[i])
      {
         j = (long)actorscrptr[i]+(long)&script[0];
-        actorscrptr[i] = (long *)j;
+        actorscrptr[i] = (int32_t *)j;
      }
 
      kdfread(&scriptptrs[0],1,MAXSPRITES,fil);
@@ -387,7 +387,7 @@
          kdfread(&animatecnt,sizeof(animatecnt),1,fil);
          kdfread(&animatesect[0],2,MAXANIMATES,fil);
          kdfread(&animateptr[0],4,MAXANIMATES,fil);
-     for(i = animatecnt-1;i>=0;i--) animateptr[i] = (long *)((long)animateptr[i]+(long)(&sector[0]));
+     for(i = animatecnt-1;i>=0;i--) animateptr[i] = (int32_t *)((long)animateptr[i]+(long)(&sector[0]));
          kdfread(&animategoal[0],4,MAXANIMATES,fil);
          kdfread(&animatevel[0],4,MAXANIMATES,fil);
 
@@ -541,12 +541,12 @@
 
 int saveplayer(signed char spot)
 {
-     long i, j;
+     int32_t i, j;
          char fn[] = "game0.sav";
      char mpfn[] = "gameA_00.sav";
      char *fnptr,scriptptrs[MAXSCRIPTSIZE];
          FILE *fil;
-     long bv = BYTEVERSION;
+     int32_t bv = BYTEVERSION;
 	 char fullpathsavefilename[16];
 
      if(spot < 0)
@@ -662,7 +662,7 @@
          if(actorscrptr[i])
      {
         j = (long)actorscrptr[i]-(long)&script[0];
-        actorscrptr[i] = (long *)j;
+        actorscrptr[i] = (int32_t *)j;
      }
      dfwrite(&actorscrptr[0],4,MAXTILES,fil);
      for(i=0;i<MAXTILES;i++)
@@ -669,7 +669,7 @@
          if(actorscrptr[i])
      {
          j = (long)actorscrptr[i]+(long)&script[0];
-         actorscrptr[i] = (long *)j;
+         actorscrptr[i] = (int32_t *)j;
      }
 
      for(i=0;i<MAXSPRITES;i++)
@@ -718,9 +718,9 @@
      dfwrite(&pskyoff[0],sizeof(pskyoff[0]),MAXPSKYTILES,fil);
          dfwrite(&animatecnt,sizeof(animatecnt),1,fil);
          dfwrite(&animatesect[0],2,MAXANIMATES,fil);
-         for(i = animatecnt-1;i>=0;i--) animateptr[i] = (long *)((long)animateptr[i]-(long)(&sector[0]));
+         for(i = animatecnt-1;i>=0;i--) animateptr[i] = (int32_t *)((long)animateptr[i]-(long)(&sector[0]));
          dfwrite(&animateptr[0],4,MAXANIMATES,fil);
-         for(i = animatecnt-1;i>=0;i--) animateptr[i] = (long *)((long)animateptr[i]+(long)(&sector[0]));
+         for(i = animatecnt-1;i>=0;i--) animateptr[i] = (int32_t *)((long)animateptr[i]+(long)(&sector[0]));
          dfwrite(&animategoal[0],4,MAXANIMATES,fil);
          dfwrite(&animatevel[0],4,MAXANIMATES,fil);
 
@@ -780,15 +780,15 @@
 	return( probeXduke(x, y, i, n, 65536L) );
 }
 
-int probeXduke(int x,int y,int i,int n, long spriteSize)
+int probeXduke(int x,int y,int i,int n, int32_t spriteSize)
 {
     short centre;
 	int32 mouseSens;
 
-	static long delay_counter_up = 0, delay_counter_down = 0, delay_up = 50, delay_down = 50;
-	static long mi = 0;
+	static int32_t delay_counter_up = 0, delay_counter_down = 0, delay_up = 50, delay_down = 50;
+	static int32_t mi = 0;
 
-	// FIX_00075: Bad Sensitivity along Y axis when using mouse in menu (Thanks to Turrican)
+	// FIX_00075: Bad Sensitivity aint32_t Y axis when using mouse in menu (Thanks to Turrican)
 	mouseSens = CONTROL_GetMouseSensitivity_Y();
 	mouseSens = mouseSens ? mouseSens : 1;
 
@@ -1364,7 +1364,7 @@
 void sortfilenames()
 {
         char sortbuffer[17];
-        long i, j, k;
+        int32_t i, j, k;
 
         for(i=1;i<menunamecnt;i++)
                 for(j=0;j<i;j++)
@@ -1381,7 +1381,7 @@
                 }
 }
 
-long quittimer = 0;
+int32_t quittimer = 0;
 
 void gameexitanycase(void)
 {
@@ -1415,7 +1415,7 @@
 void menus(void)
 {
     short c,x;
-    volatile long l;
+    volatile int32_t l;
 	int i,j;
 
 	static int lastkeysetup = 0;
@@ -1490,7 +1490,7 @@
             gametext(160,59-8,"VERSION OF DUKE NUKEM 3D.  WHILE",0,2+8+16);
             gametext(160,68-8,"THIS VERSION IS REALLY COOL, YOU",0,2+8+16);
             gametext(160,77-8,"ARE MISSING OVER 75% OF THE TOTAL",0,2+8+16);
-            gametext(160,86-8,"GAME, ALONG WITH OTHER GREAT EXTRAS",0,2+8+16);
+            gametext(160,86-8,"GAME, Aint32_t WITH OTHER GREAT EXTRAS",0,2+8+16);
             gametext(160,95-8,"AND GAMES, WHICH YOU'LL GET WHEN",0,2+8+16);
             gametext(160,104-8,"YOU ORDER THE COMPLETE VERSION AND",0,2+8+16);
             gametext(160,113-8,"GET THE FINAL TWO EPISODES.",0,2+8+16);
@@ -2358,8 +2358,8 @@
 				// Draw USER MAP background
 				{
 					int y, x1;
-					long xPos, xPos2;
-					long yPos, yPos2;
+					int32_t xPos, xPos2;
+					int32_t yPos, yPos2;
 
 					xPos =  ( xdim *32) / 320;
 					yPos =  ( ydim *30) / 200;
@@ -4171,7 +4171,7 @@
     }
 }
 
-void palto(char r,char g,char b,long e)
+void palto(char r,char g,char b,int32_t e)
 {
     int i;
     char temparray[768];
@@ -4197,12 +4197,12 @@
 }
 
 
-void drawoverheadmap(long cposx, long cposy, long czoom, short cang)
+void drawoverheadmap(int32_t cposx, int32_t cposy, int32_t czoom, short cang)
 {
-        long i, j, k, l, x1, y1, x2, y2, x3, y3, x4, y4, ox, oy, xoff, yoff;
-        long dax, day, cosang, sinang, xspan, yspan, sprx, spry;
-        long xrepeat, yrepeat, z1, z2, startwall, endwall, tilenum, daang;
-        long xvect, yvect, xvect2, yvect2;
+        int32_t i, j, k, l, x1, y1, x2, y2, x3, y3, x4, y4, ox, oy, xoff, yoff;
+        int32_t dax, day, cosang, sinang, xspan, yspan, sprx, spry;
+        int32_t xrepeat, yrepeat, z1, z2, startwall, endwall, tilenum, daang;
+        int32_t xvect, yvect, xvect2, yvect2;
         short p;
         char col;
         walltype *wal, *wal2;
@@ -4446,7 +4446,7 @@
 
 
 
-void endanimsounds(long fr)
+void endanimsounds(int32_t fr)
 {
     switch(ud.volume_number)
     {
@@ -4510,7 +4510,7 @@
     }
 }
 
-void logoanimsounds(long fr)
+void logoanimsounds(int32_t fr)
 {
     switch(fr)
     {
@@ -4523,7 +4523,7 @@
     }
 }
 
-void intro4animsounds(long fr)
+void intro4animsounds(int32_t fr)
 {
     switch(fr)
     {
@@ -4540,7 +4540,7 @@
     }
 }
 
-void first4animsounds(long fr)
+void first4animsounds(int32_t fr)
 {
     switch(fr)
     {
@@ -4559,7 +4559,7 @@
     }
 }
 
-void intro42animsounds(long fr)
+void intro42animsounds(int32_t fr)
 {
     switch(fr)
     {
@@ -4572,7 +4572,7 @@
 
 
 
-void endanimvol41(long fr)
+void endanimvol41(int32_t fr)
 {
     switch(fr)
     {
@@ -4585,7 +4585,7 @@
     }
 }
 
-void endanimvol42(long fr)
+void endanimvol42(int32_t fr)
 {
     switch(fr)
     {
@@ -4604,7 +4604,7 @@
     }
 }
 
-void endanimvol43(long fr)
+void endanimvol43(int32_t fr)
 {
     switch(fr)
     {
@@ -4622,11 +4622,11 @@
 }
 
 
-long lastanimhack=0;
+int32_t lastanimhack=0;
 void playanm(char *fn,char t)
 {
         char *animbuf, *palptr;
-    long i, j, k, length=0, numframes=0;
+    int32_t i, j, k, length=0, numframes=0;
     int32 handle=-1;
 
 //    return;
@@ -4647,7 +4647,7 @@
     walock[MAXTILES-3-t] = 219+t;
 
     if(anim == 0 || lastanimhack != (MAXTILES-3-t))
-        allocache((long *)&anim,length+sizeof(anim_t),&walock[MAXTILES-3-t]);
+        allocache((int32_t *)&anim,length+sizeof(anim_t),&walock[MAXTILES-3-t]);
 
     animbuf = (char *)(FP_OFF(anim)+sizeof(anim_t));
 
--- a/Game/src/midi/databuf.h
+++ b/Game/src/midi/databuf.h
@@ -10,7 +10,7 @@
  *  GNU Library General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
+ *  aint32_t with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
@@ -29,11 +29,11 @@
 
 typedef unsigned char uint8;
 typedef unsigned short uint16;
-typedef unsigned long uint32;
+typedef uint32_t uint32;
 
 typedef signed char sint8;
 typedef signed short sint16;
-typedef signed long sint32;
+typedef int32_t sint32;
 
 class DataSource
 {
--- a/Game/src/midi/win_midiout.cpp
+++ b/Game/src/midi/win_midiout.cpp
@@ -12,7 +12,7 @@
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
 
@@ -185,7 +185,7 @@
 
 	// List all the midi devices.
 	MIDIOUTCAPS caps;
-	signed long dev_count = (signed long) midiOutGetNumDevs(); 
+	signed int32_t dev_count = (signed long) midiOutGetNumDevs(); 
 	std::cout << dev_count << " Midi Devices Detected" << endl;
 	std::cout << "Listing midi devices:" << endl;
 
@@ -1168,7 +1168,7 @@
 	//extern void GetOnlyNameOfFile(char *fn);
 
 	short      fp;
-    long        l;
+    int32_t        l;
 	char *cfn;
 	char *buffer;
 	char fpath[19] = {'\0'};
@@ -1224,13 +1224,13 @@
 } // MUSIC_GetContext
 
 
-void MUSIC_SetSongTick(unsigned long PositionInTicks)
+void MUSIC_SetSongTick(unsigned int32_t PositionInTicks)
 {
     musdebug("STUB ... MUSIC_SetSongTick().\n");
 } // MUSIC_SetSongTick
 
 
-void MUSIC_SetSongTime(unsigned long milliseconds)
+void MUSIC_SetSongTime(unsigned int32_t milliseconds)
 {
     musdebug("STUB ... MUSIC_SetSongTime().\n");
 }// MUSIC_SetSongTime
--- a/Game/src/midi/win_midiout.h
+++ b/Game/src/midi/win_midiout.h
@@ -12,7 +12,7 @@
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
 
@@ -109,34 +109,34 @@
 	void reset_channel (int i);
 
 	// Microsecond Clock
-	unsigned long start;
-	unsigned long sfx_start;
+	unsigned int32_t start;
+	unsigned int32_t sfx_start;
 
 	inline void wmoInitClock ()
 	{ start = GetTickCount()*6; }
 
-	inline void wmoAddOffset (unsigned long offset)
+	inline void wmoAddOffset (unsigned int32_t offset)
 	{ start += offset; }
 
-	inline unsigned long wmoGetTime ()
+	inline unsigned int32_t wmoGetTime ()
 	{ return GetTickCount()*6 - start; }
 
-	inline unsigned long wmoGetStart ()
+	inline unsigned int32_t wmoGetStart ()
 	{ return start; }
 
-	inline unsigned long wmoGetRealTime ()
+	inline unsigned int32_t wmoGetRealTime ()
 	{ return GetTickCount()*6; }
 
 	inline void wmoInitSFXClock ()
 	{ sfx_start = GetTickCount()*6; }
 
-	inline void wmoAddSFXOffset (unsigned long offset)
+	inline void wmoAddSFXOffset (unsigned int32_t offset)
 	{ sfx_start += offset; }
 
-	inline unsigned long wmoGetSFXTime ()
+	inline unsigned int32_t wmoGetSFXTime ()
 	{ return GetTickCount()*6 - sfx_start; }
 
-	inline unsigned long wmoGetSFXStart ()
+	inline unsigned int32_t wmoGetSFXStart ()
 	{ return sfx_start; }
 };
 
--- a/Game/src/midi/xmidi.cpp
+++ b/Game/src/midi/xmidi.cpp
@@ -11,7 +11,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
+ * aint32_t with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  */
@@ -73,7 +73,7 @@
 }
 
 // This is used to correct incorrect patch, vol and pan changes in midi files
-// The bias is just a value to used to work out if a vol and pan belong with a 
+// The bias is just a value to used to work out if a vol and pan beint32_t with a 
 // patch change. This is to ensure that the default state of a midi file is with
 // the tracks centred, unless the first patch change says otherwise.
 #define PATCH_VOL_PAN_BIAS	5
@@ -1593,7 +1593,7 @@
 	// This is so if using buffer datasource, the caller can know how big to make the buffer
 	if (!dest)
 	{
-		// Header is 14 bytes long and add the rest as well
+		// Header is 14 bytes int32_t and add the rest as well
 		len = ConvertListToMTrk (NULL);
 		return 14 + len;
 	}
--- a/Game/src/midi/xmidi.h
+++ b/Game/src/midi/xmidi.h
@@ -12,7 +12,7 @@
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
 
--- a/Game/src/mouse.h
+++ b/Game/src/mouse.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
--- a/Game/src/names.h
+++ b/Game/src/names.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
--- a/Game/src/player.c
+++ b/Game/src/player.c
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
@@ -51,7 +51,7 @@
 
 void incur_damage( struct player_struct *p )
 {
-    long  damage = 0L, shield_damage = 0L;
+    int32_t  damage = 0L, shield_damage = 0L;
 
     sprite[p->i].extra -= p->extra_extra8>>8;
 
@@ -104,9 +104,9 @@
     p->rotscrnang = n>>1;
 }
 
-void tracers(long x1,long y1,long z1,long x2,long y2,long z2,long n)
+void tracers(int32_t x1,int32_t y1,int32_t z1,int32_t x2,int32_t y2,int32_t z2,int32_t n)
 {
-     long i, xv, yv, zv;
+     int32_t i, xv, yv, zv;
      short sect = -1;
 
 	 i = n+1;
@@ -133,11 +133,11 @@
 	 }
 }
 
-long hits(short i)
+int32_t hits(short i)
 {
-    long sx,sy,sz;
+    int32_t sx,sy,sz;
     short sect,hw,hs;
-    long zoff;
+    int32_t zoff;
 
     if(PN == APLAYER) zoff = (40<<8);
     else zoff = 0;
@@ -150,9 +150,9 @@
     return ( FindDistance2D( sx-SX,sy-SY ) );
 }
 
-long hitasprite(short i,short *hitsp)
+int32_t hitasprite(short i,short *hitsp)
 {
-    long sx,sy,sz,zoff;
+    int32_t sx,sy,sz,zoff;
     short sect,hw;
 
     if(badguy(&sprite[i]) )
@@ -172,9 +172,9 @@
 }
 
 /*
-long hitaspriteandwall(short i,short *hitsp,short *hitw,short *x, short *y)
+int32_t hitaspriteandwall(short i,short *hitsp,short *hitw,short *x, short *y)
 {
-    long sz;
+    int32_t sz;
     short sect;
 
     hitscan(SX,SY,SZ,SECT,
@@ -187,9 +187,9 @@
 */
 
 
-long hitawall(struct player_struct *p,short *hitw)
+int32_t hitawall(struct player_struct *p,short *hitw)
 {
-    long sx,sy,sz;
+    int32_t sx,sy,sz;
     short sect,hs;
 
     hitscan(p->posx,p->posy,p->posz,p->cursectnum,
@@ -205,8 +205,8 @@
     char gotshrinker,gotfreezer;
     short i, j, a, k, cans;
     short aimstats[] = {10,13,1,2};
-    long dx1, dy1, dx2, dy2, dx3, dy3, smax, sdist;
-    long xv, yv;
+    int32_t dx1, dy1, dx2, dy2, dx3, dy3, smax, sdist;
+    int32_t xv, yv;
 
     a = s->ang;
 
@@ -313,7 +313,7 @@
 void shoot(short i,short atwith)
 {
     short sect, hitsect, hitspr, hitwall, l, sa, p, j, k, scount;
-    long sx, sy, sz, vel, zvel, hitx, hity, hitz, x, oldzvel, dal;
+    int32_t sx, sy, sz, vel, zvel, hitx, hity, hitz, x, oldzvel, dal;
     unsigned char sizx,sizy;
     spritetype *s;
 
@@ -1118,7 +1118,7 @@
 
 void displayloogie(short snum)
 {
-    long i, a, x, y, z;
+    int32_t i, a, x, y, z;
 
     if(ps[snum].loogcnt == 0) return;
 
@@ -1138,7 +1138,7 @@
 char animatefist(short gs,short snum)
 {
     short looking_arc,fisti,fistpal;
-    long fistzoom, fistz;
+    int32_t fistzoom, fistz;
 
     fisti = ps[snum].fist_incs;
     if(fisti > 32) fisti = 32;
@@ -1214,7 +1214,7 @@
 
 
 
-long lastvisinc;
+int32_t lastvisinc;
 
 void displaymasks(short snum)
 {
@@ -1295,8 +1295,8 @@
 
 void displayweapon(short snum)
 {
-    long gun_pos, looking_arc, cw;
-    long weapon_xoffset, i, j;
+    int32_t gun_pos, looking_arc, cw;
+    int32_t weapon_xoffset, i, j;
     char o,pal;
     signed char gs;
     struct player_struct *p;
@@ -1788,7 +1788,7 @@
 #define MAXANGVEL    127
 #define MAXHORIZ     127
 
-long myaimmode = 0, myaimstat = 0, omyaimstat = 0;
+int32_t myaimmode = 0, myaimstat = 0, omyaimstat = 0;
 
 void getinput(short snum)
 {
@@ -2128,7 +2128,7 @@
 
 char doincrements(struct player_struct *p)
 {
-    long snum;
+    int32_t snum;
 
     snum = sprite[p->i].yvel;
 //    j = sync[snum].avel;
@@ -2340,9 +2340,9 @@
 
 void processinput(short snum)
 {
-    long j, i, k, doubvel, fz, cz, hz, lz, truefdist, x, y;
+    int32_t j, i, k, doubvel, fz, cz, hz, lz, truefdist, x, y;
     char shrunk;
-    unsigned long sb_snum;
+    uint32_t sb_snum;
     short psect, psectlotag,*kb, tempsect, pi;
     struct player_struct *p;
     spritetype *s;
@@ -3143,7 +3143,7 @@
     }
     else if ( sync[snum].avel )          //p->ang += syncangvel * constant
     {                         //ENGINE calculates angvel for you
-        long tempang;
+        int32_t tempang;
 
         tempang = sync[snum].avel<<1;
 
@@ -3617,7 +3617,7 @@
 				if (VOLUMEONE) break;
                 if ( p->ammo_amount[TRIPBOMB_WEAPON] > 0 )
                 {
-                    long sx,sy,sz;
+                    int32_t sx,sy,sz;
                     short sect,hw,hitsp;
 
                     hitscan( p->posx, p->posy, p->posz,
@@ -4043,7 +4043,7 @@
 
 
 //UPDATE THIS FILE OVER THE OLD GETSPRITESCORE/COMPUTERGETINPUT FUNCTIONS
-static int getspritescore(long snum, long dapicnum)
+static int getspritescore(int32_t snum, int32_t dapicnum)
 {
     switch(dapicnum)
     {
@@ -4082,7 +4082,7 @@
     return(0);
 }
 
-static long fdmatrix[12][12] =
+static int32_t fdmatrix[12][12] =
 {
  //KNEE PIST SHOT CHAIN RPG PIPE SHRI DEVI WALL FREE HAND EXPA
    {  128,  -1,  -1,  -1, 128,  -1,  -1,  -1, 128,  -1, 128,  -1 },   //KNEE
@@ -4099,16 +4099,16 @@
    {  128, 128, 128, 128,2560, 128,2560,2560, 128, 128, 128, 128 }    //EXPA
 };
 
-static long goalx[MAXPLAYERS], goaly[MAXPLAYERS], goalz[MAXPLAYERS];
-static long goalsect[MAXPLAYERS], goalwall[MAXPLAYERS], goalsprite[MAXPLAYERS];
-static long goalplayer[MAXPLAYERS], clipmovecount[MAXPLAYERS];
+static int32_t goalx[MAXPLAYERS], goaly[MAXPLAYERS], goalz[MAXPLAYERS];
+static int32_t goalsect[MAXPLAYERS], goalwall[MAXPLAYERS], goalsprite[MAXPLAYERS];
+static int32_t goalplayer[MAXPLAYERS], clipmovecount[MAXPLAYERS];
 short searchsect[MAXSECTORS], searchparent[MAXSECTORS];
 char dashow2dsector[(MAXSECTORS+7)>>3];
-void computergetinput(long snum, input *syn)
+void computergetinput(int32_t snum, input *syn)
 {
-    long i, j, k, l, x1, y1, z1, x2, y2, z2, x3, y3, z3, dx, dy;
-    long dist, daang, zang, fightdist, damyang, damysect;
-    long startsect, endsect, splc, send, startwall, endwall;
+    int32_t i, j, k, l, x1, y1, z1, x2, y2, z2, x3, y3, z3, dx, dy;
+    int32_t dist, daang, zang, fightdist, damyang, damysect;
+    int32_t startsect, endsect, splc, send, startwall, endwall;
     short dasect, dawall, daspr;
     struct player_struct *p;
     walltype *wal;
--- a/Game/src/premap.c
+++ b/Game/src/premap.c
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
@@ -233,7 +233,7 @@
 char getsound(unsigned short num)
 {
     short fp;
-    long   l;
+    int32_t   l;
 
     if(num >= NUM_SOUNDS || SoundToggle == 0) return 0;
     if (FXDevice == NumSoundCards) return 0;
@@ -248,7 +248,7 @@
         ( l < 12288 ) )
     {
         Sound[num].lock = 2;
-        allocache((long *)&Sound[num].ptr,l,&Sound[num].lock);
+        allocache((int32_t *)&Sound[num].ptr,l,&Sound[num].lock);
         if(Sound[num].ptr != NULL)
             kread( fp, Sound[num].ptr , l);
     }
@@ -319,7 +319,7 @@
 
 void docacheit(void)
 {
-    long i,j;
+    int32_t i,j;
 
     j = 0;
 
@@ -352,7 +352,7 @@
 
 void vscrn(void)
 {
-     long ss, x1, x2, y1, y2;
+     int32_t ss, x1, x2, y1, y2;
 
 	 if(ud.screen_size < 0) ud.screen_size = 0;
 	 else if(ud.screen_size > 63) ud.screen_size = 64;
@@ -380,7 +380,7 @@
 
 int countfragbars(void)
 {
-	long i, j, y = 0;
+	int32_t i, j, y = 0;
 
 	if ( ud.screen_size > 0 && ud.coop != 1 && ud.multimode > 1)
 	{
@@ -1066,7 +1066,7 @@
 void resetpspritevars(char g)
 {
     short i, j, nexti,circ;
-    long firstx,firsty;
+    int32_t firstx,firsty;
     spritetype *s;
     char aimmode[MAXPLAYERS];
     STATUSBARTYPE tsbar[MAXPLAYERS];
@@ -1280,7 +1280,7 @@
 
 void genspriteremaps(void)
 {
-    long j,fp;
+    int32_t j,fp;
     signed char look_pos;
     char *lookfn = "lookup.dat";
     char numl;
@@ -1313,7 +1313,7 @@
 
 void waitforeverybody()
 {
-    long i;
+    int32_t i;
 
     if (numplayers < 2) 
 	{
@@ -1357,7 +1357,7 @@
 
 void dofrontscreens(void)
 {
-    long i,j;
+    int32_t i,j;
 
     if(ud.recstat != 2)
     {
@@ -1443,7 +1443,7 @@
 void enterlevel(char g)
 {
     short i;
-    long l;
+    int32_t l;
     char levname[256];
 	char fulllevelfilename[512];
 
--- a/Game/src/rts.c
+++ b/Game/src/rts.c
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
@@ -224,7 +224,7 @@
    if (lumpcache[lump] == NULL)
    {
       lumplockbyte[lump] = 200;
-      allocache((long *)&lumpcache[lump],(long)RTS_SoundLength(lump-1),&lumplockbyte[lump]);
+      allocache((int32_t *)&lumpcache[lump],(long)RTS_SoundLength(lump-1),&lumplockbyte[lump]);
       RTS_ReadLump(lump, lumpcache[lump]);
    }
    else
--- a/Game/src/rts.h
+++ b/Game/src/rts.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
--- a/Game/src/scriplib.c
+++ b/Game/src/scriplib.c
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
--- a/Game/src/scriplib.h
+++ b/Game/src/scriplib.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
--- a/Game/src/sector.c
+++ b/Game/src/sector.c
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
@@ -199,9 +199,9 @@
     return -1;
 }
 
-long ldist(spritetype *s1,spritetype *s2)
+int32_t ldist(spritetype *s1,spritetype *s2)
 {
-    long vx,vy;
+    int32_t vx,vy;
     vx = s1->x - s2->x;
     vy = s1->y - s2->y;
     return(FindDistance2D(vx,vy) + 1);
@@ -210,9 +210,9 @@
 // Declaration here just to shut down compiler warning:
 // The linker was able to find it :/ regardless !
 int FindDistance3D(int ix, int iy, int iz);
-long dist(spritetype *s1,spritetype *s2)
+int32_t dist(spritetype *s1,spritetype *s2)
 {
-    long vx,vy,vz;
+    int32_t vx,vy,vz;
     vx = s1->x - s2->x;
     vy = s1->y - s2->y;
     vz = s1->z - s2->z;
@@ -219,10 +219,10 @@
     return(FindDistance3D(vx,vy,vz>>4));
 }
 
-short findplayer(spritetype *s,long *d)
+short findplayer(spritetype *s,int32_t *d)
 {
     short j, closest_player;
-    long x, closest;
+    int32_t x, closest;
 
     if(ud.multimode < 2)
     {
@@ -247,10 +247,10 @@
     return closest_player;
 }
 
-short findotherplayer(short p,long *d)
+short findotherplayer(short p,int32_t *d)
 {
     short j, closest_player;
-    long x, closest;
+    int32_t x, closest;
 
     closest = 0x7fffffff;
     closest_player = p;
@@ -275,7 +275,7 @@
 
 void doanimations(void)
 {
-	long i, j, a, p, v, dasect;
+	int32_t i, j, a, p, v, dasect;
 
 	for(i=animatecnt-1;i>=0;i--)
 	{
@@ -335,13 +335,13 @@
 	}
 }
 
-long getanimationgoal(long *animptr)
+int32_t getanimationgoal(int32_t *animptr)
 {
-	long i, j;
+	int32_t i, j;
 
 	j = -1;
     for(i=animatecnt-1;i>=0;i--)
-        if (animptr == (long *)animateptr[i])
+        if (animptr == (int32_t *)animateptr[i])
 		{
 			j = i;
 			break;
@@ -349,9 +349,9 @@
 	return(j);
 }
 
-long setanimation(short animsect,long *animptr, long thegoal, long thevel)
+int32_t setanimation(short animsect,int32_t *animptr, int32_t thegoal, int32_t thevel)
 {
-	long i, j;
+	int32_t i, j;
 
 	if (animatecnt >= MAXANIMATES-1)
 		return(-1);
@@ -405,7 +405,7 @@
 
 void animatewalls(void)
 {
-    long i, j, p, t;
+    int32_t i, j, p, t;
 
     for(p=0;p < numanimwalls ;p++)
 //    for(p=numanimwalls-1;p>=0;p--)
@@ -548,7 +548,7 @@
 
 void operatesectors(short sn,short ii)
 {
-    long j=0, l, q, startwall, endwall;
+    int32_t j=0, l, q, startwall, endwall;
     short i;
     char sect_error;
     sectortype *sptr;
@@ -596,8 +596,8 @@
 
         case 9:
         {
-            long dax,day,dax2,day2,sp;
-            long wallfind[2];
+            int32_t dax,day,dax2,day2,sp;
+            int32_t wallfind[2];
 
             startwall = sptr->wallptr;
             endwall = startwall+sptr->wallnum-1;
@@ -1158,11 +1158,11 @@
 }
 
 
-char checkhitswitch(short snum,long w,char switchtype)
+char checkhitswitch(short snum,int32_t w,char switchtype)
 {
     char switchpal;
     short i, x, lotag,hitag,picnum,correctdips,numdips;
-    long sx,sy;
+    int32_t sx,sy;
 
     if(w < 0) return 0;
     correctdips = 1;
@@ -1564,7 +1564,7 @@
     lotsofglass(spr,dawallnum,10);
 }
 
-void checkhitwall(short spr,short dawallnum,long x,long y,long z,short atwith)
+void checkhitwall(short spr,short dawallnum,int32_t x,int32_t y,int32_t z,short atwith)
 {
     short j, i, sn = -1, darkestwall;
     walltype *wal;
@@ -2415,7 +2415,7 @@
 {
     short i, k;
     char dainv;
-    unsigned long sb_snum, j;
+    uint32_t sb_snum, j;
     struct player_struct *p;
 	char playing_old_demo = 0;
 
@@ -2909,7 +2909,7 @@
 
 void checksectors(short snum)
 {
-    long i = -1,oldz;
+    int32_t i = -1,oldz;
     struct player_struct *p;
     short j,hitscanwall;
 
--- a/Game/src/sounddebugdefs.h
+++ b/Game/src/sounddebugdefs.h
@@ -1,8 +1,8 @@
 #ifndef _SOUND_DEBUG_DEFS_H_
 #define _SOUND_DEBUG_DEFS_H_
 
-extern unsigned long sounddebugActiveSounds;
-extern unsigned long sounddebugAllocateSoundCalls;
-extern unsigned long sounddebugDeallocateSoundCalls;
+extern uint32_t sounddebugActiveSounds;
+extern uint32_t sounddebugAllocateSoundCalls;
+extern uint32_t sounddebugDeallocateSoundCalls;
 
 #endif
\ No newline at end of file
--- a/Game/src/soundefs.h
+++ b/Game/src/soundefs.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
--- a/Game/src/sounds.c
+++ b/Game/src/sounds.c
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
@@ -37,7 +37,7 @@
 
 #define LOUDESTVOLUME 150
 
-long backflag,numenvsnds;
+int32_t backflag,numenvsnds;
 
 /*
 ===================
@@ -207,7 +207,7 @@
       }
    }
 
-int USRHOOKS_GetMem(char **ptr, unsigned long size )
+int USRHOOKS_GetMem(char **ptr, uint32_t size )
 {
    *ptr = malloc(size);
 
@@ -256,7 +256,7 @@
 {
 #if PLATFORM_DOS
     short      fp;
-    long        l;
+    int32_t        l;
 
     if(MusicToggle == 0) return;
     if(MusicDevice == NumSoundCards) return;
@@ -287,7 +287,7 @@
 
 char loadsound(unsigned short num)
 {
-    long   fp, l;
+    int32_t   fp, l;
 
     if(num >= NUM_SOUNDS || SoundToggle == 0) return 0;
     if (FXDevice == NumSoundCards) return 0;
@@ -305,15 +305,15 @@
 
     Sound[num].lock = 200;
 
-    allocache((long *)&Sound[num].ptr,l,(unsigned char *)&Sound[num].lock);
+    allocache((int32_t *)&Sound[num].ptr,l,(unsigned char *)&Sound[num].lock);
     kread( fp, Sound[num].ptr , l);
     kclose( fp );
     return 1;
 }
 
-int xyzsound(short num,short i,long x,long y,long z)
+int xyzsound(short num,short i,int32_t x,int32_t y,int32_t z)
 {
-    long sndist, cx, cy, cz, j,k;
+    int32_t sndist, cx, cy, cz, j,k;
     short pitche,pitchs,cs;
     int voice, sndang, ca, pitch;
 
@@ -459,7 +459,7 @@
 {
     short pitch,pitche,pitchs,cx;
     int voice;
-    long start;
+    int32_t start;
 
     if (FXDevice == NumSoundCards) return;
     if(SoundToggle==0) return;
@@ -547,7 +547,7 @@
 
 void pan3dsound(void)
 {
-    long sndist, sx, sy, sz, cx, cy, cz;
+    int32_t sndist, sx, sy, sz, cx, cy, cz;
     short sndang,ca,j,k,i,cs;
 
     numenvsnds = 0;
@@ -625,7 +625,7 @@
     }
 }
 
-void TestCallBack(long num)
+void TestCallBack(int32_t num)
 {
     short tempi,tempj,tempk;
 
@@ -665,7 +665,7 @@
 
 
 // no idea if this is right. I added this function.  --ryan.
-void testcallback(unsigned long num)
+void testcallback(uint32_t num)
 {
 //    STUBBED("wtf?");
     TestCallBack(num);
@@ -674,7 +674,7 @@
 
 void clearsoundlocks(void)
 {
-    long i;
+    int32_t i;
 
     for(i=0;i<NUM_SOUNDS;i++)
         if(Sound[i].lock >= 200)
--- a/Game/src/sounds.h
+++ b/Game/src/sounds.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
@@ -36,7 +36,7 @@
 
 #define HIRESMUSICPATH "tunes"
 
-extern int32 FXDevice;
+extern int32_t FXDevice;
 extern int32 MusicDevice;
 extern int32 FXVolume;
 extern int32 MusicVolume;
@@ -57,6 +57,6 @@
 void clearsoundlocks(void);
 
 /* dunno where this came from; I added it. --ryan. */
-void testcallback(unsigned long num);
+void testcallback(uint32_t num);
 
 #endif
--- a/Game/src/types.h
+++ b/Game/src/types.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
@@ -26,6 +26,9 @@
 
 #ifndef _types_public
 #define _types_public
+
+#include <inttypes.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -53,7 +56,7 @@
 typedef char                    boolean;
 typedef float                   float32;
 typedef double                  float64;
-typedef long double             float128;
+typedef int64_t                 float128;
 typedef float64                 appfloat;
 
 #define MAXINT32                0x7fffffff
--- a/Game/src/util_lib.h
+++ b/Game/src/util_lib.h
@@ -16,7 +16,7 @@
 See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+aint32_t with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Original Source: 1996 - Todd Replogle
@@ -58,8 +58,8 @@
 int32  ParseNum (char *str);
 int16  MotoShort (int16 l);
 int16  IntelShort (int16 l);
-int32_t  MotoLong (int32_t l);
-int32_t  IntelLong (int32_t l);
+int32_t  Motoint32_t (int32_t l);
+int32_t  Intelint32_t (int32_t l);
 
 void HeapSort(char * base, int32 nel, int32 width, int32 (*compare)(), void (*switcher)());