Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4973 right-hear 1
/*
2
byteswap.h - C preprocessor macros for byte swapping.
3
Copyright (C) 1995, 1996 Michael Riepe 
4
 
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
9
 
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
Library General Public License for more details.
14
 
15
You should have received a copy of the GNU Library General Public
16
License along with this library; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
*/
19
 
20
/* @(#) $Id: byteswap.h,v 1.2 1996/10/22 16:45:54 michael Exp $ */
21
 
22
#ifndef _BYTESWAP_H
23
#define _BYTESWAP_H
24
 
25
#define lu(from,i,s)		(((long)((unsigned char*)(from))[i])<<(s))
26
#define li(from,i,s)		(((long)((signed char*)(from))[i])<<(s))
27
 
28
#define __load_u16L(from)	((unsigned long)(lu(from,1,8)|lu(from,0,0)))
29
#define __load_u16M(from)	((unsigned long)(lu(from,0,8)|lu(from,1,0)))
30
#define __load_i16L(from)	((long)(li(from,1,8)|lu(from,0,0)))
31
#define __load_i16M(from)	((long)(li(from,0,8)|lu(from,1,0)))
32
 
33
#define __load_u32L(from)	((unsigned long)(lu(from,3,24)|	\
34
						 lu(from,2,16)|	\
35
						 lu(from,1,8)|	\
36
						 lu(from,0,0)))
37
#define __load_u32M(from)	((unsigned long)(lu(from,0,24)|	\
38
						 lu(from,1,16)|	\
39
						 lu(from,2,8)|	\
40
						 lu(from,3,0)))
41
#define __load_i32L(from)	((long)(li(from,3,24)|	\
42
					lu(from,2,16)|	\
43
					lu(from,1,8)|	\
44
					lu(from,0,0)))
45
#define __load_i32M(from)	((long)(li(from,0,24)|	\
46
					lu(from,1,16)|	\
47
					lu(from,2,8)|	\
48
					lu(from,3,0)))
49
 
50
#define su(to,i,v,s)		(((char*)(to))[i]=((unsigned long)(v)>>(s)))
51
#define si(to,i,v,s)		(((char*)(to))[i]=((long)(v)>>(s)))
52
 
53
#define __store_u16L(to,v)	(su(to,1,v,8),su(to,0,v,0))
54
#define __store_u16M(to,v)	(su(to,0,v,8),su(to,1,v,0))
55
#define __store_i16L(to,v)	(si(to,1,v,8),si(to,0,v,0))
56
#define __store_i16M(to,v)	(si(to,0,v,8),si(to,1,v,0))
57
 
58
#define __store_u32L(to,v)	(su(to,3,v,24),	\
59
				 su(to,2,v,16),	\
60
				 su(to,1,v,8),	\
61
				 su(to,0,v,0))
62
#define __store_u32M(to,v)	(su(to,0,v,24),	\
63
				 su(to,1,v,16),	\
64
				 su(to,2,v,8),	\
65
				 su(to,3,v,0))
66
#define __store_i32L(to,v)	(si(to,3,v,24),	\
67
				 si(to,2,v,16),	\
68
				 si(to,1,v,8),	\
69
				 si(to,0,v,0))
70
#define __store_i32M(to,v)	(si(to,0,v,24),	\
71
				 si(to,1,v,16),	\
72
				 si(to,2,v,8),	\
73
				 si(to,3,v,0))
74
 
75
#endif /* _BYTESWAP_H */