initial commit
[iso2ps2.git] / ps2classic / types.h
1 // Copyright 2013 RobertoB*
2 // Licensed under the terms of the GNU GPL, version 2
3 // http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
4 #ifndef TYPES_H__
5 #define TYPES_H__
6
7 #include <stdint.h>
8
9 typedef uint64_t u64;
10 typedef int64_t s64;
11 typedef uint32_t u32;
12 typedef int32_t s32;
13 typedef uint16_t u16;
14 typedef int16_t s16;
15 typedef uint8_t u8;
16 typedef int8_t s8;
17
18
19 #ifdef WIN32
20 #define ftello ftello64
21 #define fseeko fseeko64
22 #endif
23
24
25
26 static inline u8 be8(u8 *p)
27 {
28 return *p;
29 }
30
31 static inline u16 be16(u8 *p)
32 {
33 u16 a;
34
35 a = p[0] << 8;
36 a |= p[1];
37
38 return a;
39 }
40
41 static inline u16 le16(u8 *p)
42 {
43 u16 a;
44
45 a = p[1] << 8;
46 a |= p[0];
47
48 return a;
49 }
50
51 static inline u32 be32(u8 *p)
52 {
53 u32 a;
54
55 a = p[0] << 24;
56 a |= p[1] << 16;
57 a |= p[2] << 8;
58 a |= p[3] << 0;
59
60 return a;
61 }
62
63 static inline u32 le32(u8 *p)
64 {
65 u32 a;
66
67 a = p[3] << 24;
68 a |= p[2] << 16;
69 a |= p[1] << 8;
70 a |= p[0] << 0;
71
72 return a;
73 }
74
75 static inline u64 be64(u8 *p)
76 {
77 u32 a, b;
78
79 a = be32(p);
80 b = be32(p + 4);
81
82 return ((u64)a<<32) | b;
83 }
84
85 static inline void wbe16(u8 *p, u16 v)
86 {
87 p[0] = v >> 8;
88 p[1] = v;
89 }
90
91 static inline void wbe32(u8 *p, u32 v)
92 {
93 p[0] = v >> 24;
94 p[1] = v >> 16;
95 p[2] = v >> 8;
96 p[3] = v;
97 }
98
99 static inline void wbe64(u8 *p, u64 v)
100 {
101 wbe32(p + 4, v);
102 v >>= 32;
103 wbe32(p, v);
104 }
105
106
107 #endif