]> git.saurik.com Git - wxWidgets.git/blob - utils/Install/incace/portable.h
wxHtmlHistoryItem needs not be wxObject
[wxWidgets.git] / utils / Install / incace / portable.h
1 /****************************************************************/
2 /* */
3 /* A collection of routines used in making ACE portable for */
4 /* different computers */
5 /* */
6 /****************************************************************/
7
8 #ifndef __portable_h
9 #define __portable_h
10
11 #include "os.h"
12
13 #ifdef HI_LO_BYTE_ORDER
14
15 /* All kinds of inplace swap routines, to reverse from LOHI to HILO byte order */
16
17 #ifdef AMIGA
18
19 #if __SASC && __VERSION__>=6 && __REVISION__>=58
20
21 #define WORDswap(n) (*(n) = __builtin_rol(*(n), 8, 1))
22 #define LONGswap(n) ( WORDswap(&((WORD *)(n))[0]),\
23 WORDswap(&((WORD *)(n))[1]),\
24 *(n) = __builtin_rol(*(n), 16, 2) )
25 #else /* __SASC */
26
27 #define EORSWAP
28
29 #endif /* !__SASC */
30
31 #endif /* AMIGA */
32
33
34 #ifdef EORSWAP
35
36 /* With some compilers and processors these work faster then the
37 * regular swap below, for example on a Amiga 68040 using SAS C 6.58.
38 * But using builtin rotates works even faster, see above.
39 */
40
41 #define WORDswap(n) (((BYTE*)(n))[0] ^= ((BYTE*)(n))[1],\
42 ((BYTE*)(n))[1] ^= ((BYTE*)(n))[0],\
43 ((BYTE*)(n))[0] ^= ((BYTE*)(n))[1])
44 #define LONGswap(n) (((BYTE*)(n))[0] ^= ((BYTE*)(n))[3],\
45 ((BYTE*)(n))[3] ^= ((BYTE*)(n))[0],\
46 ((BYTE*)(n))[0] ^= ((BYTE*)(n))[3],\
47 ((BYTE*)(n))[1] ^= ((BYTE*)(n))[2],\
48 ((BYTE*)(n))[2] ^= ((BYTE*)(n))[1],\
49 ((BYTE*)(n))[1] ^= ((BYTE*)(n))[2])
50 #endif /* EORSWAP */
51
52 #ifndef WORDswap
53
54 /* If not yet defined use the standard swaps */
55
56 #define WORDswap(n) (*(n) = (*(n) << 8) | (*(n) >> 8))
57 #define LONGswap(n) ( WORDswap(&((WORD *)(n))[0]),\
58 WORDswap(&((WORD *)(n))[1]),\
59 *(n) = (*(n) >> 16) | (*(n) << 16) )
60 #endif /* WORDSWAP */
61
62 #endif /* HI_LO_BYTE_ORDER */
63
64
65 /* GENERIC: Convert to LONG or WORD from BYTE-Pointer-to-LOHI-byte-order data,
66 * without worrying if the bytes are word alined in memory.
67 * p is a pointer to char.
68 */
69
70 #ifdef HI_LO_BYTE_ORDER
71
72 #define BUFP2WORD(p) ((UWORD)*(p)++ | ((*(p)++)<<8))
73 #define BUFP2LONG(p) ((ULONG)*(p)++ | ((*(p)++)<<8) | ((*(p)++)<<16) | ((*(p)++)<<24))
74
75 #define BUF2WORD(p) ((UWORD)*(p) | (*((p)+1)<<8))
76 #define BUF2LONG(p) ((ULONG)*(p) | (*((p)+1)<<8) | (*((p)+2)<<16) | (*((p)+3)<<24))
77
78 #else /* HI_LO_BYTE_ORDER */
79
80 #define BUFP2WORD(p) *(UWORD*)((p+=2)-2)
81 #define BUFP2LONG(p) *(ULONG*)((p+=4)-4)
82
83 #define BUF2WORD(p) (*(UWORD*)p)
84 #define BUF2LONG(p) (*(ULONG*)p)
85
86 #endif /* !HI_LO_BYTE_ORDER */
87
88 /* Timestamp macros */
89
90 #define get_tx(m,d,h,n) (((ULONG)m<<21)+((ULONG)d<<16)+((ULONG)h<<11)+(n<<5))
91 #define get_tstamp(y,m,d,h,n,s) ((((ULONG)(y-1980))<<25)+get_tx(m,d,h,n)+(s/2))
92
93 #define ts_year(ts) ((UINT)((ts >> 25) & 0x7f) + 1980)
94 #define ts_month(ts) ((UINT)(ts >> 21) & 0x0f) // 1..12 means Jan..Dec
95 #define ts_day(ts) ((UINT)(ts >> 16) & 0x1f) // 1..31 means 1st..31st
96 #define ts_hour(ts) ((UINT)(ts >> 11) & 0x1f)
97 #define ts_min(ts) ((UINT)(ts >> 5) & 0x3f)
98 #define ts_sec(ts) ((UINT)((ts & 0x1f) * 2))
99
100
101 #endif /* __portable_h */