2
2
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997-2004 Sam Lantinga
3
Copyright (C) 1997-2006 Sam Lantinga
5
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
6
modify it under the terms of the GNU Lesser General Public
7
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
8
version 2.1 of the License, or (at your option) any later version.
10
10
This library is distributed in the hope that it will be useful,
11
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
13
Lesser General Public License for more details.
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
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
You should have received a copy of the GNU Lesser General Public
16
License along with this library; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
"@(#) $Id: SDL_endian.h,v 1.15 2005/03/30 12:38:03 pmandin Exp $";
28
23
/* Functions for reading and writing endian-specific values */
30
25
#ifndef _SDL_endian_h
31
26
#define _SDL_endian_h
33
/* These functions read and write data of the specified endianness,
34
dynamically translating to the host machine endianness.
36
e.g.: If you want to read a 16 bit value on big-endian machine from
37
an open file containing little endian values, you would use:
38
value = SDL_ReadLE16(rp);
39
Note that the read/write functions use SDL_RWops pointers
40
instead of FILE pointers. This allows you to read and write
41
endian values from large chunks of memory as well as files
42
and other data sources.
47
#include "SDL_types.h"
48
#include "SDL_rwops.h"
49
#include "SDL_byteorder.h"
28
#include "SDL_stdinc.h"
30
/* The two types of endianness */
31
#define SDL_LIL_ENDIAN 1234
32
#define SDL_BIG_ENDIAN 4321
34
#ifndef SDL_BYTEORDER /* Not defined in SDL_config.h? */
35
#if defined(__hppa__) || \
36
defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
37
(defined(__MIPS__) && defined(__MISPEB__)) || \
38
defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \
40
#define SDL_BYTEORDER SDL_BIG_ENDIAN
42
#define SDL_BYTEORDER SDL_LIL_ENDIAN
44
#endif /* !SDL_BYTEORDER */
51
47
#include "begin_code.h"
52
48
/* Set up for C function definitions, even when using C++ */
59
55
static for compilers that do not support inline functions, this
60
56
header should only be included in files that actually use them.
62
#if defined(__GNUC__) && defined(__i386__)
58
#if defined(__GNUC__) && defined(__i386__) && \
59
!(__GNUC__ == 2 && __GNUC_MINOR__ == 95 /* broken gcc version */)
63
60
static __inline__ Uint16 SDL_Swap16(Uint16 x)
65
62
__asm__("xchgb %b0,%h0" : "=q" (x) : "0" (x));
186
183
#define SDL_SwapBE64(X) (X)
189
/* Read an item of the specified endianness and return in native format */
190
extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops *src);
191
extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops *src);
192
extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops *src);
193
extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops *src);
194
extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops *src);
195
extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops *src);
197
/* Write an item of native format to the specified endianness */
198
extern DECLSPEC int SDLCALL SDL_WriteLE16(SDL_RWops *dst, Uint16 value);
199
extern DECLSPEC int SDLCALL SDL_WriteBE16(SDL_RWops *dst, Uint16 value);
200
extern DECLSPEC int SDLCALL SDL_WriteLE32(SDL_RWops *dst, Uint32 value);
201
extern DECLSPEC int SDLCALL SDL_WriteBE32(SDL_RWops *dst, Uint32 value);
202
extern DECLSPEC int SDLCALL SDL_WriteLE64(SDL_RWops *dst, Uint64 value);
203
extern DECLSPEC int SDLCALL SDL_WriteBE64(SDL_RWops *dst, Uint64 value);
206
186
/* Ends C function definitions when using C++ */
207
187
#ifdef __cplusplus