annotate src/Port.h @ 5:8fe0c57e53d2

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