/******************************************************************************
** cmacros.h                                                                 **
**---------------------------------------------------------------------------**
** Collection of useful C-macros                                             **
**---------------------------------------------------------------------------**
** Version : V 1.0                                                           **
** Date    : 03.07.1995                                                      **
** Author  : Stefan Kost                                                     **
******************************************************************************/

/* Bitmanipulation Macros */
/* n ist the variable to work with */
/* m ist the bitposition to change */
/* BitClr(11,0) => 10 ; this clear the lowest bit in the number 11 */

#define BitSet(n,m)			( n|(1L<<m) )
#define BitClr(n,m)			( n&~(1L<<m) )
#define BitTest(n,m)		( n&(1L<<m)>>m )
#define BitToggle(n,m)		( (n&(1L<<m)>>m) ? (n&~(1L<<m)) : (n|(1L<<m)) )

/* Variable Swapping */
/* swaps the contents of variable a with b and uses c as buffer */
/* all variables should have the same typ */

#define Swap(a,b,c)			c=a;a=b;b=c;

/* Rangechecking */
/* check if a is larger than lo and smaller than hi */
/* RangeX : bounds are excluded, RangeI : bounds are included */

#define RangeX(a,lo,hi)		( (a>hi ? hi : a)<lo ? lo : (a>hi ? hi : a) )
#define RangeI(a,lo,hi)		( (a>=hi ? hi : a)<=lo ? lo : (a>=hi ? hi : a) )

/* Odd/Even-Check */
/* simply check if a given number is odd or even */

#define Odd(a)				( a&1L )
#define Even(a)				( !(a&1L) )

/* Endianconversion */
/* converts between motorola`s and intel`s (buuuh) number format */

#define LitEnd2BigEnd_16(w)	( (w&0xFF)<<8 | (w&0xFF00)>>8 )
#define LitEnd2BigEnd_32(l)	( (l&0xFF)<<24 | (l&0xFF00)<<8 | (l&0xFF0000)>>8 | (l&0xFF000000)>>24 )

/* IFF-Handling */
/* generates chunk-ID`s for iff-files */

#define MakeID(a,b,c,d)		( (LONG)(a)<<24L | (LONG)(b)<<16L | (c)<<8 | (d) )
