2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
qendian.c
|
|
|
|
|
|
|
|
(description)
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 1999,2000 contributors of the QuakeForge project
|
|
|
|
Please see the file "AUTHORS" for a list of contributors
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2001-03-28 17:17:56 +00:00
|
|
|
#include "QF/qendian.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/qtypes.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakeio.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
BYTE ORDER FUNCTIONS
|
|
|
|
*/
|
|
|
|
|
2001-03-28 17:17:56 +00:00
|
|
|
#ifndef WORDS_BIGENDIAN
|
2021-01-09 11:42:23 +00:00
|
|
|
VISIBLE qboolean bigendien = false;
|
2001-03-28 17:17:56 +00:00
|
|
|
#else
|
2021-01-09 11:42:23 +00:00
|
|
|
VISIBLE qboolean bigendien = true;
|
2001-03-28 17:17:56 +00:00
|
|
|
#endif
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-22 22:03:16 +00:00
|
|
|
|
2012-08-19 04:37:06 +00:00
|
|
|
VISIBLE uint16_t
|
|
|
|
_ShortSwap (uint16_t l)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
byte b1, b2;
|
|
|
|
|
|
|
|
b1 = l & 255;
|
|
|
|
b2 = (l >> 8) & 255;
|
|
|
|
|
|
|
|
return (b1 << 8) + b2;
|
|
|
|
}
|
|
|
|
|
2012-08-19 04:37:06 +00:00
|
|
|
VISIBLE uint16_t
|
|
|
|
_ShortNoSwap (uint16_t l)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2012-08-19 04:37:06 +00:00
|
|
|
VISIBLE uint32_t
|
|
|
|
_LongSwap (uint32_t l)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
byte b1, b2, b3, b4;
|
|
|
|
|
|
|
|
b1 = l & 255;
|
|
|
|
b2 = (l >> 8) & 255;
|
|
|
|
b3 = (l >> 16) & 255;
|
|
|
|
b4 = (l >> 24) & 255;
|
|
|
|
|
|
|
|
return ((int) b1 << 24) + ((int) b2 << 16) + ((int) b3 << 8) + b4;
|
|
|
|
}
|
|
|
|
|
2012-08-19 04:37:06 +00:00
|
|
|
VISIBLE uint32_t
|
|
|
|
_LongNoSwap (uint32_t l)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE float
|
2007-05-26 23:18:46 +00:00
|
|
|
_FloatSwap (float f)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
union {
|
|
|
|
float f;
|
|
|
|
byte b[4];
|
|
|
|
} dat1 , dat2;
|
|
|
|
|
|
|
|
dat1.f = f;
|
|
|
|
dat2.b[0] = dat1.b[3];
|
|
|
|
dat2.b[1] = dat1.b[2];
|
|
|
|
dat2.b[2] = dat1.b[1];
|
|
|
|
dat2.b[3] = dat1.b[0];
|
|
|
|
return dat2.f;
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE float
|
2007-05-26 23:18:46 +00:00
|
|
|
_FloatNoSwap (float f)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
return f;
|
|
|
|
}
|