annotate src/Port.h @ 445:ea5ed834be11

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