Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5131 clevermous 1
/*
2
    SDL - Simple DirectMedia Layer
3
    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
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
17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
19
    Sam Lantinga
20
    slouken@devolution.com
21
*/
22
 
23
#ifdef SAVE_RCSID
24
static char rcsid =
25
 "@(#) $Id: SDL_endian.h,v 1.2 2001/04/26 16:50:17 hercules Exp $";
26
#endif
27
 
28
/* Functions for reading and writing endian-specific values */
29
 
30
#ifndef _SDL_endian_h
31
#define _SDL_endian_h
32
 
33
/* These functions read and write data of the specified endianness,
34
   dynamically translating to the host machine endianness.
35
 
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.
43
*/
44
 
45
#include 
46
 
47
#include "SDL_types.h"
48
#include "SDL_rwops.h"
49
#include "SDL_byteorder.h"
50
 
51
#include "begin_code.h"
52
/* Set up for C function definitions, even when using C++ */
53
#ifdef __cplusplus
54
extern "C" {
55
#endif
56
 
57
/* Use inline functions for compilers that support them, and static
58
   functions for those that do not.  Because these functions become
59
   static for compilers that do not support inline functions, this
60
   header should only be included in files that actually use them.
61
*/
62
#ifndef SDL_Swap16
63
static __inline__ Uint16 SDL_Swap16(Uint16 D) {
64
	return((D<<8)|(D>>8));
65
}
66
#endif
67
#ifndef SDL_Swap32
68
static __inline__ Uint32 SDL_Swap32(Uint32 D) {
69
	return((D<<24)|((D<<8)&0x00FF0000)|((D>>8)&0x0000FF00)|(D>>24));
70
}
71
#endif
72
#ifdef SDL_HAS_64BIT_TYPE
73
#ifndef SDL_Swap64
74
static __inline__ Uint64 SDL_Swap64(Uint64 val) {
75
	Uint32 hi, lo;
76
 
77
	/* Separate into high and low 32-bit values and swap them */
78
	lo = (Uint32)(val&0xFFFFFFFF);
79
	val >>= 32;
80
	hi = (Uint32)(val&0xFFFFFFFF);
81
	val = SDL_Swap32(lo);
82
	val <<= 32;
83
	val |= SDL_Swap32(hi);
84
	return(val);
85
}
86
#endif
87
#else
88
#ifndef SDL_Swap64
89
/* This is mainly to keep compilers from complaining in SDL code.
90
   If there is no real 64-bit datatype, then compilers will complain about
91
   the fake 64-bit datatype that SDL provides when it compiles user code.
92
*/
93
#define SDL_Swap64(X)	(X)
94
#endif
95
#endif /* SDL_HAS_64BIT_TYPE */
96
 
97
 
98
/* Byteswap item from the specified endianness to the native endianness */
99
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
100
#define SDL_SwapLE16(X)	(X)
101
#define SDL_SwapLE32(X)	(X)
102
#define SDL_SwapLE64(X)	(X)
103
#define SDL_SwapBE16(X)	SDL_Swap16(X)
104
#define SDL_SwapBE32(X)	SDL_Swap32(X)
105
#define SDL_SwapBE64(X)	SDL_Swap64(X)
106
#else
107
#define SDL_SwapLE16(X)	SDL_Swap16(X)
108
#define SDL_SwapLE32(X)	SDL_Swap32(X)
109
#define SDL_SwapLE64(X)	SDL_Swap64(X)
110
#define SDL_SwapBE16(X)	(X)
111
#define SDL_SwapBE32(X)	(X)
112
#define SDL_SwapBE64(X)	(X)
113
#endif
114
 
115
/* Read an item of the specified endianness and return in native format */
116
extern DECLSPEC Uint16 SDL_ReadLE16(SDL_RWops *src);
117
extern DECLSPEC Uint16 SDL_ReadBE16(SDL_RWops *src);
118
extern DECLSPEC Uint32 SDL_ReadLE32(SDL_RWops *src);
119
extern DECLSPEC Uint32 SDL_ReadBE32(SDL_RWops *src);
120
extern DECLSPEC Uint64 SDL_ReadLE64(SDL_RWops *src);
121
extern DECLSPEC Uint64 SDL_ReadBE64(SDL_RWops *src);
122
 
123
/* Write an item of native format to the specified endianness */
124
extern DECLSPEC int SDL_WriteLE16(SDL_RWops *dst, Uint16 value);
125
extern DECLSPEC int SDL_WriteBE16(SDL_RWops *dst, Uint16 value);
126
extern DECLSPEC int SDL_WriteLE32(SDL_RWops *dst, Uint32 value);
127
extern DECLSPEC int SDL_WriteBE32(SDL_RWops *dst, Uint32 value);
128
extern DECLSPEC int SDL_WriteLE64(SDL_RWops *dst, Uint64 value);
129
extern DECLSPEC int SDL_WriteBE64(SDL_RWops *dst, Uint64 value);
130
 
131
 
132
/* Ends C function definitions when using C++ */
133
#ifdef __cplusplus
134
}
135
#endif
136
#include "close_code.h"
137
 
138
#endif /* _SDL_endian_h */