arch.hh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. //{{{ Interface 4
  9. //
  10. // System dependant #defines and macros
  11. // Endianess macros
  12. // short_swap,long_swap - exchange endianess
  13. // lstl, lltl - little short to local, little long to local (swaps to x86 endianess)
  14. //
  15. #ifndef __ARCH_HPP_
  16. #define __ARCH_HPP_
  17. #ifdef __MAC__
  18. #include <Types.h>
  19. #include <Files.h>
  20. #include <Errors.h>
  21. #endif
  22. // 32 bit architectures
  23. #if (__sgi || __linux || __WATCOMC__ || SUN4 || _WINDOWS || __MAC__)
  24. typedef unsigned long w32;
  25. typedef unsigned short w16;
  26. typedef unsigned char w8;
  27. typedef signed long sw32;
  28. typedef signed short sw16;
  29. typedef signed char sw8;
  30. #if (__linux || __sgi || SUN4) // gcc has long long
  31. typedef unsigned long long w64;
  32. typedef long long sw64;
  33. #elif (_WINDOWS) // visual c has __int64
  34. typedef unsigned __int64 w64;
  35. typedef __int64 sw64;
  36. #else
  37. #error please define w64
  38. #endif
  39. #else
  40. // 16 and 64 bit architectures are not defined yet
  41. // but can be added here as long as the compiler supports 32 bit words
  42. #error unknown architecture, please define basic types
  43. #endif
  44. #define w16_swap(x) (((((w16) (x)))<<8)|((((w16) (x)))>>8))
  45. #define w32_swap(x) \
  46. ((( ((w32)(x)) )>>24)|((( ((w32)(x)) )&0x00ff0000)>>8)| \
  47. ((( ((w32)(x)) )&0x0000ff00)<<8)|(( ((w32)(x)) )<<24))
  48. #if (__linux || __WATCOMC__ || _WINDOWS)
  49. enum { i4_bigend=0, i4_litend=1 };
  50. #define s_to_lsb(x) (x)
  51. #define l_to_lsb(x) (x)
  52. #define s_to_msb(x) w16_swap(x)
  53. #define l_to_msb(x) w32_swap(x)
  54. #else
  55. enum { i4_bigend=1, i4_litend=0 };
  56. #define s_to_lsb(x) w16_swap(x)
  57. #define l_to_lsb(x) w32_swap(x)
  58. #define s_to_msb(x) (x)
  59. #define l_to_msb(x) (x)
  60. #endif
  61. typedef sw16 i4_coord; // use this type for all x & y positions withing images
  62. typedef w32 i4_color; // reserved as 32bits in case we expand to 32 bit color
  63. #define i4_null 0
  64. #ifdef _WINDOWS
  65. #define I4_FAST_CALL __fastcall
  66. #else
  67. #define I4_FAST_CALL
  68. #endif
  69. typedef w8 i4_bool;
  70. enum { i4_F=0,
  71. i4_T=1 };
  72. // use this mainly for events, to cast to a known event type
  73. #define CAST_PTR(var_name, type, source_obj) type *var_name=(type *)(source_obj)
  74. inline void *ALIGN_FORWARD(void *addr)
  75. {
  76. return (void*)(((w32)addr+3)&~3);
  77. }
  78. inline void *ALIGN_BACKWARD(void *addr)
  79. {
  80. return (void*)(((w32)addr)&~3);
  81. }
  82. #endif