home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / slfinsta.zip / include / portable.h < prev    next >
C/C++ Source or Header  |  2000-03-26  |  3KB  |  104 lines

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