/* $Id: hps.swap.h,v 2.2 91/01/10 20:43:04 dave Exp $ */
/****************************************************************/
/* hps.swap.h: Some defines for accessing bytes					*/
/****************************************************************/
/*																*/
/*                 Confidential Information                     */
/*      Limited Distribution to Authorized Persons Only         */
/*     Created 1987 and Protected as an Unpublished Work        */
/*          Under the U.S. Copyright Act of 1976.               */
/*         Copyright (c) 1987, Systech Corporation          	*/
/*                  All Rights Reserved                         */
/*																*/
/*	THIS SOFTWARE IS LICENSED BY AND IS THE	CONFIDENTIAL AND 	*/
/*	PROPRIETARY PROPERTY OF SYSTECH COMPUTER CORPORATION AND 	*/
/*	MAY NOT, WITHOUT THE PRIOR WRITTEN CONSENT OF SYSTECH 		*/
/*	COMPUTER CORPORATION, BE REPRODUCED, USED OR DISCLOSED 		*/
/*	EXCEPT IN ACCORDANCE WITH A SYSTECH COMPUTER CORPORATION 	*/
/*	SOFTWARE LICENSE AGREEMENT.									*/
/****************************************************************/

/*
 *	Here are some defines for accessing individual bytes and words.
 *	All arguments are pointers.
 *		sp -- pointer to short.
 *		lp -- pointer to long.
 */

#ifdef INTEL	/***  INTEL PROCESSOR   ***/

#define L_BYTE(sp)		(*( unsigned char  *)(sp))
#define H_BYTE(sp)		(*((unsigned char  *)(sp) + 1))
#define L_WORD(lp)		(*( unsigned short *)(lp))
#define H_WORD(lp)		(*((unsigned short *)(lp) + 1))
#define LL_BYTE(lp)		(*( unsigned char  *)(lp))
#define LH_BYTE(lp)		(*((unsigned char  *)(lp) + 1))
#define HL_BYTE(lp)		(*((unsigned char  *)(lp) + 2))
#define HH_BYTE(lp)		(*((unsigned char  *)(lp) + 3))

#else			/*** MOTOROLA PROCESSOR	***/

#define L_BYTE(sp)		(*((unsigned char  *)(sp) + 1))
#define H_BYTE(sp)		(*( unsigned char  *)(sp))
#define L_WORD(lp)		(*((unsigned short *)(lp) + 1))
#define H_WORD(lp)		(*( unsigned short *)(lp))
#define LL_BYTE(lp)		(*((unsigned char  *)(lp) + 3))
#define LH_BYTE(lp)		(*((unsigned char  *)(lp) + 2))
#define HL_BYTE(lp)		(*((unsigned char  *)(lp) + 1))
#define HH_BYTE(lp)		(*( unsigned char  *)(lp))

#endif

/*
 *	Here are some defines for byte swapping.
 *	Copy from 's' to 'd' with bytes swapped.
 *	All arguments are pointers.
 *		SWAP_2BYTE -- pointers to short
 *		SWAP_4BYTE -- pointers to long
 */

#define SWAP_2BYTE(d,s)		{H_BYTE(d)  = L_BYTE(s);   \
							 L_BYTE(d)  = H_BYTE(s);}

#define SWAP_4BYTE(d,s)		{HH_BYTE(d) = LL_BYTE(s);  \
							 HL_BYTE(d) = LH_BYTE(s);  \
							 LH_BYTE(d) = HL_BYTE(s);  \
							 LL_BYTE(d) = HH_BYTE(s);}

/*
 *	Here are some defines for reading/writing intel defined values.
 *	Copy from 's' to 'd'
 *	All arguments are pointers.
 *		SET_2BYTE -- pointers to short
 *		GET_2BYTE -- pointers to short
 *		SET_3BYTE -- pointers to long
 *		GET_3BYTE -- pointers to long
 *		SET_4BYTE -- pointers to long
 *		GET_4BYTE -- pointers to long
 */

#ifdef INTEL	/***  INTEL PROCESSOR   ****/

#define SET_2BYTE(d,s)	{L_BYTE(d)  = L_BYTE(s);   \
						 H_BYTE(d)  = H_BYTE(s);}

#define SET_3BYTE(d,s)	{LL_BYTE(d) = LL_BYTE(s);  \
						 LH_BYTE(d) = LH_BYTE(s);  \
						 HL_BYTE(d) = HL_BYTE(s);}

#define GET_3BYTE(d,s)	{SET_3BYTE(d,s);           \
						 HH_BYTE(d) = 0;         }

#define SET_4BYTE(d,s)	{LL_BYTE(d) = LL_BYTE(s);  \
						 LH_BYTE(d) = LH_BYTE(s);  \
						 HL_BYTE(d) = HL_BYTE(s);  \
						 HH_BYTE(d) = HH_BYTE(s);}

#define GET_2BYTE(d,s)	SET_2BYTE(d,s)

#define GET_4BYTE(d,s)	SET_4BYTE(d,s)

#else			/*** MOTOROLA PROCESSOR ***/

/* #define SET_2BYTE(d,s)	SWAP_2BYTE(d,s) */
#define SET_2BYTE(d,s)		{H_BYTE(d)  = L_BYTE(s);   \
							 L_BYTE(d)  = H_BYTE(s);}

#define SET_3BYTE(d,s)	{HH_BYTE(d) = LL_BYTE(s);  \
						 HL_BYTE(d) = LH_BYTE(s);  \
						 LH_BYTE(d) = HL_BYTE(s);}

#define GET_3BYTE(d,s)	{LL_BYTE(d) = HH_BYTE(s);  \
						 LH_BYTE(d) = HL_BYTE(s);  \
						 HL_BYTE(d) = LH_BYTE(s);  \
						 HH_BYTE(d) = 0;         }

/* #define SET_4BYTE(d,s)	SWAP_4BYTE(d,s) */
#define SET_4BYTE(d,s)		{HH_BYTE(d) = LL_BYTE(s);  \
							 HL_BYTE(d) = LH_BYTE(s);  \
							 LH_BYTE(d) = HL_BYTE(s);  \
							 LL_BYTE(d) = HH_BYTE(s);}

/* #define GET_2BYTE(d,s)	SET_2BYTE(d,s) */
#define GET_2BYTE(d,s)		{H_BYTE(d)  = L_BYTE(s);   \
							 L_BYTE(d)  = H_BYTE(s);}

/* #define GET_4BYTE(d,s)	SET_4BYTE(d,s) */
#define GET_4BYTE(d,s)		{HH_BYTE(d) = LL_BYTE(s);  \
							 HL_BYTE(d) = LH_BYTE(s);  \
							 LH_BYTE(d) = HL_BYTE(s);  \
							 LL_BYTE(d) = HH_BYTE(s);}

#endif

/*
 * MODIFICATION HISTORY:
 *
 * $Log:	hps.swap.h,v $
 * Revision 1.1.2.1  92/06/24  13:53:28  marker
 * Branch RISCOS_5_01_2_FIXES off of trunk.
 * 
 * Revision 2.2  91/01/10  20:43:04  dave
 * Update header.
 * COSMETIC
 * 
 */
