arch.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. Copyright (C) 2004 Michael Liebscher <johnnycanuck@users.sourceforge.net>
  3. Copyright (C) 1997-2001 Id Software, Inc.
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. /*
  17. * arch.h: System dependant #defines and macros.
  18. *
  19. * Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
  20. *
  21. * Acknowledgement:
  22. * Portion of this code was derived from Quake II, and was originally
  23. * written by Id Software, Inc.
  24. *
  25. */
  26. #ifndef __ARCH_H__
  27. #define __ARCH_H__
  28. // Define BUILDSTRING and CPUSTRING based on platform
  29. #ifdef _WIN32
  30. #ifdef _DEBUG
  31. #define BUILDSTRING "Win32 DEBUG"
  32. #else
  33. #define BUILDSTRING "Win32 RELEASE"
  34. #endif
  35. #ifdef _M_IX86
  36. #define CPUSTRING "x86"
  37. #elif defined _M_ALPHA
  38. #define CPUSTRING "AXP"
  39. #else
  40. #define CPUSTRING "Unknown CPU"
  41. #endif
  42. #elif defined __linux__
  43. #define BUILDSTRING "Linux"
  44. #ifdef __i386__
  45. #define CPUSTRING "i386"
  46. #elif defined __alpha__
  47. #define CPUSTRING "AXP"
  48. #else
  49. #define CPUSTRING "Unknown CPU"
  50. #endif
  51. #elif defined __FreeBSD__
  52. #define BUILDSTRING "FreeBSD"
  53. #ifdef __i386__
  54. #define CPUSTRING "i386"
  55. #else
  56. #define CPUSTRING "Unknown CPU"
  57. #endif
  58. #elif defined __sun__
  59. #define BUILDSTRING "Solaris"
  60. #ifdef __i386__
  61. #define CPUSTRING "i386"
  62. #else
  63. #define CPUSTRING "sparc"
  64. #endif
  65. #elif defined MACOS
  66. #define BUILDSTRING "MAC"
  67. #ifdef __powerpc__
  68. #define CPUSTRING "PowerPC"
  69. #else
  70. #define CPUSTRING "Unknown CPU"
  71. #endif
  72. #else
  73. #define BUILDSTRING "Unknown OS"
  74. #define CPUSTRING "Unknown CPU"
  75. #endif /* if WIN32 else __linux__ else __FreeBSD__ else __sun__ else MACOS */
  76. /*
  77. correct numeric types: W8, SW8, W16, SW16, W32, SW32, W64, SW64
  78. correct misc types: void, float, _boolean
  79. s -signed
  80. XX -Number of bits
  81. */
  82. #if( __GNUC__ || __WATCOMC__ || _MSC_VER )
  83. typedef unsigned char W8, *PW8;
  84. typedef signed char SW8, *PSW8;
  85. typedef unsigned short W16, *PW16;
  86. typedef signed short SW16, *PSW16;
  87. typedef unsigned long W32, *PW32;
  88. typedef signed long SW32, *PSW32;
  89. #if( __GNUC__ )
  90. typedef unsigned long long W64, *PW64;
  91. typedef long long SW64, *PSW64;
  92. #elif( _MSC_VER || __WATCOMC__ )
  93. typedef unsigned __int64 W64, *PW64;
  94. typedef __int64 SW64, *PSW64;
  95. #else
  96. #error "please define W64"
  97. #endif
  98. #else
  99. #error "Unknown compiler, please define basic types"
  100. #endif
  101. /* Define NULL pointer value */
  102. #ifndef NULL
  103. #ifdef __cplusplus
  104. #define NULL 0
  105. #else
  106. #define NULL ((void *)0)
  107. #endif
  108. #endif /* NULL */
  109. /* Define INLINECALL keyword */
  110. #ifndef INLINECALL
  111. #if defined(__cplusplus) || defined(__GNUC__)
  112. #define INLINECALL inline
  113. #elif defined(_WIN32) && !defined(__WATCOMC__)
  114. #define INLINECALL __inline
  115. #else
  116. #define INLINECALL /* Not supported */
  117. #endif
  118. #endif /* INLINECALL */
  119. typedef W8 colour3_t[ 3 ]; // RGB
  120. typedef W8 colour4_t[ 4 ]; // RGBA
  121. typedef W32 COLOURVAL, *PCOLOURVAL; // Represents a 32-bit colour value.
  122. #ifdef _WIN32
  123. #define vsnprintf _vsnprintf
  124. #endif
  125. typedef W8 _boolean;
  126. #define false 0
  127. #define true 1
  128. //enum { false = 0,
  129. // true = 1 };
  130. #define ShortSwap( x ) ( ( (((W16) (x)) & 0x00FF) << 8 ) | ( (((W16) (x))& 0xFF00) >> 8) )
  131. #define LongSwap( x ) ( ( ((W32) (x)) & 0xFF000000) >> 24 ) | ( ((( (W32) (x) ) & 0xFF0000) >> 8) ) | ( ((( (W32) (x) ) & 0xFF00) << 8 ) ) | ( (( (W32) (x) ) & 0xFF) << 24 )
  132. #if defined( IPHONE) || defined(__i386__) || defined(_M_IX86) // Little endian
  133. #define BigShort( x ) ShortSwap( x )
  134. #define LittleShort( x ) ( x )
  135. #define BigLong( x ) LongSwap( x )
  136. #define LittleLong( x ) ( x )
  137. #define BigFloat( x ) FloatSwap( x )
  138. #define LittleFloat( x ) ( x )
  139. #else // Big endian
  140. #define BigShort( x ) ( x )
  141. #define LittleShort( x ) ShortSwap( x )
  142. #define BigLong( x ) ( x )
  143. #define LittleLong( x ) LongSwap( x )
  144. #define BigFloat( x ) ( x )
  145. #define LittleFloat( x ) FloatSwap( x )
  146. #endif
  147. #endif /* __ARCH_H__ */