view src/Port.h @ 7:c0a590a394c3

ignore generated files
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:50:33 -0600
parents f9f4f1b99eed
children 48369c6aeaa0
line wrap: on
line source
1 #ifndef VBA_PORT_H
2 #define VBA_PORT_H
4 #if _MSC_VER > 1000
5 #pragma once
6 #endif // _MSC_VER > 1000
8 #include <ctime>
10 #ifndef NULL
11 #define NULL 0
12 #endif
14 typedef unsigned char bool8;
16 #ifdef HAVE_STDINT_H
17 #include <stdint.h>
19 typedef int8_t int8;
20 typedef uint8_t uint8;
21 typedef int16_t int16;
22 typedef uint16_t uint16;
23 typedef int32_t int32;
24 typedef uint32_t uint32;
25 typedef int64_t int64;
26 typedef uint64_t uint64;
27 typedef intptr_t pint;
29 #else /* Don't have stdint.h */
31 #ifdef PTR_NOT_INT
32 typedef long pint;
33 #else /* pointer is int */
34 typedef int pint;
35 #endif /* PTR_NOT_INT */
37 /* FIXME: Refactor this by moving out the BORLAND part and unifying typedefs */
38 #ifndef WIN32
39 typedef unsigned char uint8;
40 typedef unsigned short uint16;
41 typedef signed char int8;
42 typedef short int16;
43 typedef int int32;
44 typedef unsigned int uint32;
45 # ifdef __GNUC__ /* long long is not part of ISO C++ */
46 __extension__ typedef long long int64;
47 __extension__ typedef unsigned long long uint64;
48 # else
49 typedef long long int64;
50 typedef unsigned long long uint64;
51 # endif
52 #else /* WIN32 */
54 # ifdef __BORLANDC__
55 # include <systypes.h>
56 # else
58 typedef unsigned char uint8;
59 typedef unsigned short uint16;
60 typedef signed char int8;
61 typedef short int16;
63 # ifndef WSAAPI
64 /* winsock2.h typedefs int32 as well. */
65 typedef long int32;
66 # endif
68 typedef unsigned int uint32;
70 # endif /* __BORLANDC__ */
72 typedef __int64 int64;
73 typedef unsigned __int64 uint64;
75 #endif /* WIN32 */
76 #endif /* HAVE_STDINT_H */
78 #ifndef WIN32
80 #ifndef PATH_MAX
81 #define PATH_MAX 1024
82 #endif
84 #define _MAX_DIR PATH_MAX
85 #define _MAX_DRIVE 1
86 #define _MAX_FNAME PATH_MAX
87 #define _MAX_EXT PATH_MAX
88 #define _MAX_PATH PATH_MAX
90 #define ZeroMemory(a, b) memset((a), 0, (b))
92 void _makepath(char *path, const char *drive, const char *dir,
93 const char *fname, const char *ext);
94 void _splitpath(const char *path, char *drive, char *dir, char *fname,
95 char *ext);
96 #else /* WIN32 */
97 #define strcasecmp stricmp
98 #define strncasecmp strnicmp
99 #endif
101 typedef uint8 u8;
102 typedef uint16 u16;
103 typedef uint32 u32;
104 typedef uint64 u64;
105 typedef int8 s8;
106 typedef int16 s16;
107 typedef int32 s32;
108 typedef int64 s64;
110 // for consistency
111 static inline u8 swap8(u8 v)
112 {
113 return v;
114 }
116 // swaps a 16-bit value
117 static inline u16 swap16(u16 v)
118 {
119 return (v<<8)|(v>>8);
120 }
122 // swaps a 32-bit value
123 static inline u32 swap32(u32 v)
124 {
125 return (v<<24)|((v<<8)&0xff0000)|((v>>8)&0xff00)|(v>>24);
126 }
128 #define READ8LE(x) \
129 *((u8 *)x)
131 #define WRITE8LE(x, v) \
132 *((u8 *)x) = (v)
134 #ifdef WORDS_BIGENDIAN
135 #if defined(__GNUC__) && defined(__ppc__)
137 #define READ16LE(base) \
138 ({ unsigned short lhbrxResult; \
139 __asm__("lhbrx %0, 0, %1" : "=r" (lhbrxResult) : "r" (base) : "memory"); \
140 lhbrxResult; })
142 #define READ32LE(base) \
143 ({ unsigned long lwbrxResult; \
144 __asm__("lwbrx %0, 0, %1" : "=r" (lwbrxResult) : "r" (base) : "memory"); \
145 lwbrxResult; })
147 #define WRITE16LE(base, value) \
148 __asm__("sthbrx %0, 0, %1" : : "r" (value), "r" (base) : "memory")
150 #define WRITE32LE(base, value) \
151 __asm__("stwbrx %0, 0, %1" : : "r" (value), "r" (base) : "memory")
153 #else
154 #define READ16LE(x) \
155 swap16(*((u16 *)(x)))
156 #define READ32LE(x) \
157 swap32(*((u32 *)(x)))
158 #define WRITE16LE(x, v) \
159 *((u16 *)x) = swap16((v))
160 #define WRITE32LE(x, v) \
161 *((u32 *)x) = swap32((v))
162 #endif
163 #else
164 #define READ16LE(x) \
165 *((u16 *)x)
166 #define READ32LE(x) \
167 *((u32 *)x)
168 #define WRITE16LE(x, v) \
169 *((u16 *)x) = (v)
170 #define WRITE32LE(x, v) \
171 *((u32 *)x) = (v)
172 #endif
174 #ifndef CTASSERT
175 #define CTASSERT(x) typedef char __assert ## y[(x) ? 1 : -1];
176 #endif
178 #endif // VBA_PORT_H