1 /*
2 qendian.c
3
4 (description)
5
6 Copyright (C) 1996-1997 Id Software, Inc.
7 Copyright (C) 1999,2000 contributors of the QuakeForge project
8 Please see the file "AUTHORS" for a list of contributors
9
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
19 See the GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to:
23
24 Free Software Foundation, Inc.
25 59 Temple Place - Suite 330
26 Boston, MA 02111-1307, USA
27
28 */
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <ctype.h>
34
35 #include "QF/qendian.h"
36 #include "QF/qtypes.h"
37 #include "QF/quakeio.h"
38
39 /*
40 BYTE ORDER FUNCTIONS
41 */
42
43 #ifndef WORDS_BIGENDIAN
44 VISIBLE qboolean bigendien = false;;
45 #else
46 VISIBLE qboolean bigendien = true;;
47 #endif
48
49
50 VISIBLE uint16_t
_ShortSwap(uint16_t l)51 _ShortSwap (uint16_t l)
52 {
53 byte b1, b2;
54
55 b1 = l & 255;
56 b2 = (l >> 8) & 255;
57
58 return (b1 << 8) + b2;
59 }
60
61 VISIBLE uint16_t
_ShortNoSwap(uint16_t l)62 _ShortNoSwap (uint16_t l)
63 {
64 return l;
65 }
66
67 VISIBLE uint32_t
_LongSwap(uint32_t l)68 _LongSwap (uint32_t l)
69 {
70 byte b1, b2, b3, b4;
71
72 b1 = l & 255;
73 b2 = (l >> 8) & 255;
74 b3 = (l >> 16) & 255;
75 b4 = (l >> 24) & 255;
76
77 return ((int) b1 << 24) + ((int) b2 << 16) + ((int) b3 << 8) + b4;
78 }
79
80 VISIBLE uint32_t
_LongNoSwap(uint32_t l)81 _LongNoSwap (uint32_t l)
82 {
83 return l;
84 }
85
86 VISIBLE float
_FloatSwap(float f)87 _FloatSwap (float f)
88 {
89 union {
90 float f;
91 byte b[4];
92 } dat1 , dat2;
93
94 dat1.f = f;
95 dat2.b[0] = dat1.b[3];
96 dat2.b[1] = dat1.b[2];
97 dat2.b[2] = dat1.b[1];
98 dat2.b[3] = dat1.b[0];
99 return dat2.f;
100 }
101
102 VISIBLE float
_FloatNoSwap(float f)103 _FloatNoSwap (float f)
104 {
105 return f;
106 }
107