Commit 15b65782 authored by Richard Gobeille's avatar Richard Gobeille
Browse files

engine: move crc16 functions into main engine definitions

parent 52d44555
......@@ -1048,6 +1048,8 @@ extern int32_t enginecompatibilitymode;
static CONSTEXPR int32_t const enginecompatibilitymode = ENGINE_EDUKE32;
#endif
EXTERN int32_t crctab16[256];
/*************************************************************************
POSITION VARIABLES:
......@@ -1239,6 +1241,11 @@ void printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol,
const char *name, char fontsize) ATTRIBUTE((nonnull(5)));
void Buninitart(void);
void initcrc16(void);
uint16_t getcrc16(char const *buffer, int bufleng);
#define updatecrc16(crc,dat) (crc = (((crc<<8)&65535)^crctab16[((((uint16_t)crc)>>8)&65535)^(dat)]))
////////// specialized rotatesprite wrappers for (very) often used cases //////////
static FORCE_INLINE void rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum,
int8_t dashade, char dapalnum, int32_t dastat,
......
......@@ -28,8 +28,6 @@
char levelname[BMAX_PATH] = {0};
#define updatecrc16(crc,dat) (crc = (((crc<<8)&65535)^crctable[((((uint16_t)crc)>>8)&65535)^dat]))
static int32_t crctable[256];
static char kensig[64];
static const char *CallExtGetVer(void);
......@@ -250,7 +248,6 @@ static int32_t movewalls(int32_t start, int32_t offs);
static void loadnames(const char *namesfile);
static void getclosestpointonwall(int32_t x, int32_t y, int32_t dawall, int32_t *nx, int32_t *ny,
int32_t maybe_screen_coord_p);
static void initcrc(void);
static int32_t menuselect(void);
static int32_t menuselect_auto(int, int); //PK
......@@ -739,8 +736,7 @@ int app_main(int argc, char const * const * argv)
artLoadFiles("tiles000.art", g_maxCacheSize);
Bstrcpy(kensig,"Uses BUILD technology by Ken Silverman");
initcrc();
Bstrcpy(kensig,"Uses BUILD technology by Ken Silverman");
InitCustomColors();
......@@ -10878,25 +10874,6 @@ static void getclosestpointonwall(int32_t x, int32_t y, int32_t dawall, int32_t
*ny = wy + ((dy*i)>>30);
}
static void initcrc(void)
{
int32_t i, j, k, a;
for (j=0; j<256; j++) //Calculate CRC table
{
k = (j<<8); a = 0;
for (i=7; i>=0; i--)
{
if (((k^a)&0x8000) > 0)
a = ((a<<1)&65535) ^ 0x1021; //0x1021 = genpoly
else
a = ((a<<1)&65535);
k = ((k<<1)&65535);
}
crctable[j] = (a&65535);
}
}
static int32_t GetWallBaseZ(int32_t wallnum)
{
int32_t z=0;
......
......@@ -189,6 +189,27 @@ static fix16_t global100horiz; // (-100..300)-scale horiz (the one passed to dr
int32_t enginecompatibilitymode = ENGINE_EDUKE32;
#endif
void initcrc16()
{
int i, j, k, a;
for (j=0;j<256;j++)
{
for (i=7,k=(j<<8),a=0;i>=0;i--,k=((k<<1)&65535))
{
if ((k^a)&0x8000) a = ((a<<1)&65535)^0x1021;
else a = ((a<<1)&65535);
}
crctab16[j] = (a&65535);
}
}
uint16_t getcrc16(char const *buffer, int bufleng)
{
int j = 0;
for (int i=bufleng-1;i>=0;i--) updatecrc16(j,buffer[i]);
return((uint16_t)(j&65535));
}
// adapted from build.c
static void getclosestpointonwall_internal(vec2_t const p, int32_t const dawall, vec2_t *const closest)
{
......@@ -8614,6 +8635,7 @@ int32_t enginePreInit(void)
validmodecnt = 0;
videoGetModes();
initcrc16();
initcrc32table();
#ifdef HAVE_CLIPSHAPE_FEATURE
......
......@@ -3,6 +3,7 @@
#include <string.h>
#include <ctype.h>
#include "build.h"
#include "compat.h"
#include "baselayer.h"
#include "renderlayer.h"
......@@ -346,30 +347,6 @@ void mmulti_sendlogon() {}
void mmulti_sendlogoff() {}
//--------------------------------------------------------------------------------------------------
static int crctab16[256];
static void initcrc16()
{
int i, j, k, a;
for (j=0;j<256;j++)
{
for (i=7,k=(j<<8),a=0;i>=0;i--,k=((k<<1)&65535))
{
if ((k^a)&0x8000) a = ((a<<1)&65535)^0x1021;
else a = ((a<<1)&65535);
}
crctab16[j] = (a&65535);
}
}
#define updatecrc16(crc,dat) crc = (((crc<<8)&65535)^crctab16[((((unsigned short)crc)>>8)&65535)^dat])
static unsigned short getcrc16(char *buffer, int bufleng)
{
int i, j;
j = 0;
for (i=bufleng-1;i>=0;i--) updatecrc16(j,buffer[i]);
return((unsigned short)(j&65535));
}
void mmulti_uninitmultiplayers() { netuninit(); }
static void initmultiplayers_reset(void)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment