platform_endian.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* MegaZeux
  2. *
  3. * Copyright (C) 2008 Alistair John Strachan <alistair@devzero.co.uk
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #ifndef __ENDIAN_H
  20. #define __ENDIAN_H
  21. /* If SDL is available, include the header and use SDL's configured
  22. * endianness. If it's not available, use a list of architectures (actually
  23. * borrowed from SDL 1.2.13) to figure out our likely endianness.
  24. */
  25. #define PLATFORM_LIL_ENDIAN 0x1234
  26. #define PLATFORM_BIG_ENDIAN 0x4321
  27. #if defined(CONFIG_SDL) && !defined(SKIP_SDL)
  28. #include <SDL_endian.h>
  29. #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  30. #define PLATFORM_BYTE_ORDER PLATFORM_BIG_ENDIAN
  31. #else
  32. #define PLATFORM_BYTE_ORDER PLATFORM_LIL_ENDIAN
  33. #endif
  34. #else // !CONFIG_SDL
  35. #if defined(__BIG_ENDIAN__)
  36. #define PLATFORM_BYTE_ORDER PLATFORM_BIG_ENDIAN
  37. #elif defined(__LITTLE_ENDIAN__)
  38. #define PLATFORM_BYTE_ORDER PLATFORM_LIL_ENDIAN
  39. #elif defined(__hppa__) || \
  40. defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
  41. (defined(__MIPS__) && defined(__MISPEB__)) || \
  42. defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \
  43. defined(__sparc__)
  44. #define PLATFORM_BYTE_ORDER PLATFORM_BIG_ENDIAN
  45. #else
  46. #define PLATFORM_BYTE_ORDER PLATFORM_LIL_ENDIAN
  47. #endif
  48. #endif // CONFIG_SDL
  49. /* ModPlug and XMP both use this name to find out about endianness. It's not
  50. * too bad to pollute our namespace with it, so just do so here.
  51. */
  52. #if PLATFORM_BYTE_ORDER == PLATFORM_BIG_ENDIAN
  53. #define WORDS_BIGENDIAN
  54. #endif
  55. #endif // __ENDIAN_H