view src/Port.h @ 251:40b5bff9576c

merge
author Robert McIntyre <rlm@mit.edu>
date Mon, 26 Mar 2012 03:50:17 -0500
parents 48369c6aeaa0
children
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 // RLM combatibility junk
21 typedef uint8_t u8;
22 typedef uint16_t u16;
23 typedef uint32_t u32;
24 typedef uint64_t u64;
26 typedef int8_t s8;
27 typedef int16_t s16;
28 typedef int32_t s32;
29 typedef int64_t s64;
32 typedef int8_t int8;
33 typedef uint8_t uint8;
34 typedef int16_t int16;
35 typedef uint16_t uint16;
36 typedef int32_t int32;
37 typedef uint32_t uint32;
38 typedef int64_t int64;
39 typedef uint64_t uint64;
40 typedef intptr_t pint;
42 #ifndef WIN32
44 #ifndef PATH_MAX
45 #define PATH_MAX 1024
46 #endif
48 #define _MAX_DIR PATH_MAX
49 #define _MAX_DRIVE 1
50 #define _MAX_FNAME PATH_MAX
51 #define _MAX_EXT PATH_MAX
52 #define _MAX_PATH PATH_MAX
54 #define ZeroMemory(a, b) memset((a), 0, (b))
56 void _makepath(char *path, const char *drive, const char *dir,
57 const char *fname, const char *ext);
58 void _splitpath(const char *path, char *drive, char *dir, char *fname,
59 char *ext);
60 #else /* WIN32 */
61 #define strcasecmp stricmp
62 #define strncasecmp strnicmp
63 #endif
66 // for consistency
67 static inline u8 swap8(u8 v)
68 {
69 return v;
70 }
72 // swaps a 16-bit value
73 static inline u16 swap16(u16 v)
74 {
75 return (v<<8)|(v>>8);
76 }
78 // swaps a 32-bit value
79 static inline u32 swap32(u32 v)
80 {
81 return (v<<24)|((v<<8)&0xff0000)|((v>>8)&0xff00)|(v>>24);
82 }
84 #define READ8LE(x) \
85 *((u8 *)x)
87 #define WRITE8LE(x, v) \
88 *((u8 *)x) = (v)
90 #ifdef WORDS_BIGENDIAN
91 #if defined(__GNUC__) && defined(__ppc__)
93 #define READ16LE(base) \
94 ({ unsigned short lhbrxResult; \
95 __asm__("lhbrx %0, 0, %1" : "=r" (lhbrxResult) : "r" (base) : "memory"); \
96 lhbrxResult; })
98 #define READ32LE(base) \
99 ({ unsigned long lwbrxResult; \
100 __asm__("lwbrx %0, 0, %1" : "=r" (lwbrxResult) : "r" (base) : "memory"); \
101 lwbrxResult; })
103 #define WRITE16LE(base, value) \
104 __asm__("sthbrx %0, 0, %1" : : "r" (value), "r" (base) : "memory")
106 #define WRITE32LE(base, value) \
107 __asm__("stwbrx %0, 0, %1" : : "r" (value), "r" (base) : "memory")
109 #else
110 #define READ16LE(x) \
111 swap16(*((u16 *)(x)))
112 #define READ32LE(x) \
113 swap32(*((u32 *)(x)))
114 #define WRITE16LE(x, v) \
115 *((u16 *)x) = swap16((v))
116 #define WRITE32LE(x, v) \
117 *((u32 *)x) = swap32((v))
118 #endif
119 #else
120 #define READ16LE(x) \
121 *((u16 *)x)
122 #define READ32LE(x) \
123 *((u32 *)x)
124 #define WRITE16LE(x, v) \
125 *((u16 *)x) = (v)
126 #define WRITE32LE(x, v) \
127 *((u32 *)x) = (v)
128 #endif
130 #ifndef CTASSERT
131 #define CTASSERT(x) typedef char __assert ## y[(x) ? 1 : -1];
132 #endif
134 #endif // VBA_PORT_H