use platform specific endian swap functions (in our case SDL's)
parent
a8422bd857
commit
8fd7e7ba10
|
@ -175,6 +175,7 @@ set(srcs_windows
|
|||
|
||||
set(srcs_sdl
|
||||
source/sdl/cd_sdl.c
|
||||
source/sdl/endian_sdl.h
|
||||
source/sdl/gl_vidsdl.c
|
||||
source/sdl/in_sdl.c
|
||||
source/sdl/main_sdl.c
|
||||
|
|
|
@ -508,67 +508,6 @@ float Q_atof(const char *str)
|
|||
return val * sign;
|
||||
}
|
||||
|
||||
/*
|
||||
============================================================================
|
||||
|
||||
BYTE ORDER FUNCTIONS
|
||||
|
||||
============================================================================
|
||||
*/
|
||||
|
||||
bool host_bigendian;
|
||||
|
||||
int16_t (*BigShort)(int16_t l);
|
||||
int32_t (*BigLong)(int32_t l);
|
||||
float (*BigFloat)(float l);
|
||||
|
||||
int16_t (*LittleShort)(int16_t l);
|
||||
int32_t (*LittleLong)(int32_t l);
|
||||
float (*LittleFloat)(float l);
|
||||
|
||||
static int16_t ShortSwap(int16_t l)
|
||||
{
|
||||
int32_t copy;
|
||||
((byte *)©)[0] = ((byte *)&l)[1];
|
||||
((byte *)©)[1] = ((byte *)&l)[0];
|
||||
return copy;
|
||||
}
|
||||
|
||||
static int16_t ShortNoSwap(int16_t l)
|
||||
{
|
||||
return l;
|
||||
}
|
||||
|
||||
static int32_t LongSwap(int32_t l)
|
||||
{
|
||||
int32_t copy;
|
||||
((byte *)©)[0] = ((byte *)&l)[3];
|
||||
((byte *)©)[1] = ((byte *)&l)[2];
|
||||
((byte *)©)[2] = ((byte *)&l)[1];
|
||||
((byte *)©)[3] = ((byte *)&l)[0];
|
||||
return copy;
|
||||
}
|
||||
|
||||
static int32_t LongNoSwap(int32_t l)
|
||||
{
|
||||
return l;
|
||||
}
|
||||
|
||||
static float FloatSwap(float f)
|
||||
{
|
||||
float copy;
|
||||
((byte *)©)[0] = ((byte *)&f)[3];
|
||||
((byte *)©)[1] = ((byte *)&f)[2];
|
||||
((byte *)©)[2] = ((byte *)&f)[1];
|
||||
((byte *)©)[3] = ((byte *)&f)[0];
|
||||
return copy;
|
||||
}
|
||||
|
||||
static float FloatNoSwap(float f)
|
||||
{
|
||||
return f;
|
||||
}
|
||||
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
|
@ -1250,43 +1189,6 @@ void COM_InitArgv(int32_t argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
COM_Init
|
||||
================
|
||||
*/
|
||||
void COM_Init(void)
|
||||
{
|
||||
int32_t i = 0x12345678;
|
||||
|
||||
if(*(byte *)&i == 0x12)
|
||||
host_bigendian = true;
|
||||
else if(*(byte *)&i == 0x78)
|
||||
host_bigendian = false;
|
||||
else
|
||||
Sys_Error("Unsupported endianness");
|
||||
|
||||
if(host_bigendian)
|
||||
{
|
||||
BigShort = ShortNoSwap;
|
||||
BigLong = LongNoSwap;
|
||||
BigFloat = FloatNoSwap;
|
||||
LittleShort = ShortSwap;
|
||||
LittleLong = LongSwap;
|
||||
LittleFloat = FloatSwap;
|
||||
}
|
||||
else
|
||||
{
|
||||
BigShort = ShortSwap;
|
||||
BigLong = LongSwap;
|
||||
BigFloat = FloatSwap;
|
||||
LittleShort = ShortNoSwap;
|
||||
LittleLong = LongNoSwap;
|
||||
LittleFloat = FloatNoSwap;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
============
|
||||
va
|
||||
|
|
|
@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#ifndef spingle__common_h
|
||||
#define spingle__common_h
|
||||
|
||||
#include "sdl/endian_sdl.h"
|
||||
|
||||
#define q_minfunc(typ, name) \
|
||||
static inline typ name(typ a, typ b) {return a < b ? a : b;}
|
||||
|
@ -66,11 +67,11 @@ GenericTypes(CLAMPfunc, CLAMP)
|
|||
|
||||
typedef struct sizebuf_s
|
||||
{
|
||||
bool allowoverflow; // if false, do a Sys_Error
|
||||
bool overflowed; // set to true if the buffer size failed
|
||||
byte *data;
|
||||
int32_t maxsize;
|
||||
int32_t cursize;
|
||||
bool allowoverflow; // if false, do a Sys_Error
|
||||
bool overflowed; // set to true if the buffer size failed
|
||||
byte *data;
|
||||
int32_t maxsize;
|
||||
int32_t cursize;
|
||||
} sizebuf_t;
|
||||
|
||||
void SZ_Alloc(sizebuf_t *buf, int32_t startsize);
|
||||
|
@ -95,16 +96,6 @@ void InsertLinkAfter(link_t *l, link_t *after);
|
|||
|
||||
//============================================================================
|
||||
|
||||
extern bool host_bigendian;
|
||||
|
||||
extern int16_t (*BigShort)(int16_t l);
|
||||
extern int32_t (*BigLong)(int32_t l);
|
||||
extern float (*BigFloat)(float l);
|
||||
|
||||
extern int16_t (*LittleShort)(int16_t l);
|
||||
extern int32_t (*LittleLong)(int32_t l);
|
||||
extern float (*LittleFloat)(float l);
|
||||
|
||||
static inline int16_t ReadBigShort(byte const *bytes)
|
||||
{
|
||||
int16_t v;
|
||||
|
@ -243,7 +234,6 @@ extern int32_t safemode;
|
|||
|
||||
int32_t COM_CheckParm(const char *parm);
|
||||
|
||||
void COM_Init(void);
|
||||
void COM_InitArgv(int32_t argc, char **argv);
|
||||
void COM_InitFilesystem(void);
|
||||
|
||||
|
|
|
@ -826,7 +826,6 @@ void Host_Init(void)
|
|||
Cmd_Init();
|
||||
LOG_Init(host_parms);
|
||||
Cvar_Init(); //johnfitz
|
||||
COM_Init();
|
||||
COM_InitFilesystem();
|
||||
Host_InitLocal();
|
||||
W_LoadWadFile(); //johnfitz -- filename is now hard-coded for honesty
|
||||
|
|
|
@ -317,16 +317,13 @@ static int32_t mp3_decode(snd_stream_t *stream, byte *buf, int32_t len)
|
|||
sample = 0x7FFF;
|
||||
else
|
||||
sample >>= (MAD_F_FRACBITS + 1 - 16);
|
||||
if(host_bigendian)
|
||||
{
|
||||
*buf++ = (sample >> 8) & 0xFF;
|
||||
*buf++ = sample & 0xFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
*buf++ = sample & 0xFF;
|
||||
*buf++ = (sample >> 8) & 0xFF;
|
||||
}
|
||||
#if HOST_BIGENDIAN
|
||||
*buf++ = (sample >> 8) & 0xFF;
|
||||
*buf++ = sample & 0xFF;
|
||||
#else
|
||||
*buf++ = sample & 0xFF;
|
||||
*buf++ = (sample >> 8) & 0xFF;
|
||||
#endif
|
||||
i++;
|
||||
}
|
||||
p->cursamp++;
|
||||
|
|
|
@ -155,7 +155,7 @@ static int32_t S_VORBIS_CodecReadStream(snd_stream_t *stream, int32_t bytes, voi
|
|||
* the channels are interleaved in the output buffer.
|
||||
*/
|
||||
res = ov_read((OggVorbis_File *)stream->priv, ptr, rem,
|
||||
host_bigendian,
|
||||
HOST_BIGENDIAN,
|
||||
VORBIS_SAMPLEWIDTH,
|
||||
VORBIS_SIGNED_DATA,
|
||||
& section);
|
||||
|
|
Loading…
Reference in New Issue