m_swap.h 1.45 KB
Newer Older
Alam Ed Arias committed
1 2 3 4
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 1998-2000 by DooM Legacy Team.
James R. committed
5
// Copyright (C) 1999-2020 by Sonic Team Junior.
Alam Ed Arias committed
6 7 8 9 10 11 12 13 14 15 16 17 18
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file  m_swap.h
/// \brief Endianess handling, swapping 16bit and 32bit

#ifndef __M_SWAP__
#define __M_SWAP__

// Endianess handling.
// WAD files are stored little endian.
Jaime Ita Passos committed
19 20 21
#include "endian.h"

// Little to big endian
22
#ifdef SRB2_BIG_ENDIAN
Alam Ed Arias committed
23

Jaime Ita Passos committed
24 25 26 27
	#define SHORT(x) ((INT16)(\
	(((UINT16)(x) & (UINT16)0x00ffU) << 8) \
	| \
	(((UINT16)(x) & (UINT16)0xff00U) >> 8))) \
Alam Ed Arias committed
28

Jaime Ita Passos committed
29 30 31 32 33 34 35 36 37 38 39 40 41
	#define LONG(x) ((INT32)(\
	(((UINT32)(x) & (UINT32)0x000000ffUL) << 24) \
	| \
	(((UINT32)(x) & (UINT32)0x0000ff00UL) <<  8) \
	| \
	(((UINT32)(x) & (UINT32)0x00ff0000UL) >>  8) \
	| \
	(((UINT32)(x) & (UINT32)0xff000000UL) >> 24)))

#else
	#define SHORT(x) ((INT16)(x))
	#define LONG(x)	((INT32)(x))
#endif
Alam Ed Arias committed
42

Jaime Ita Passos committed
43 44
// Big to little endian
#ifdef SRB2_LITTLE_ENDIAN
Jaime Ita Passos committed
45 46
	#define BIGENDIAN_LONG(x) ((INT32)(((x)>>24)&0xff)|(((x)<<8)&0xff0000)|(((x)>>8)&0xff00)|(((x)<<24)&0xff000000))
	#define BIGENDIAN_SHORT(x) ((INT16)(((x)>>8)|((x)<<8)))
Alam Ed Arias committed
47
#else
Jaime Ita Passos committed
48 49
	#define BIGENDIAN_LONG(x) ((INT32)(x))
	#define BIGENDIAN_SHORT(x) ((INT16)(x))
Alam Ed Arias committed
50 51 52
#endif

#endif