m_swap.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Emacs style mode select -*- C++ -*-
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. // $Log:$
  18. //
  19. // DESCRIPTION:
  20. // Endianess handling, swapping 16bit and 32bit.
  21. //
  22. //-----------------------------------------------------------------------------
  23. static const char
  24. rcsid[] = "$Id: m_bbox.c,v 1.1 1997/02/03 22:45:10 b1 Exp $";
  25. #ifdef __GNUG__
  26. #pragma implementation "m_swap.h"
  27. #endif
  28. #include "m_swap.h"
  29. // Not needed with big endian.
  30. #ifndef __BIG_ENDIAN__
  31. // Swap 16bit, that is, MSB and LSB byte.
  32. unsigned short SwapSHORT(unsigned short x)
  33. {
  34. // No masking with 0xFF should be necessary.
  35. return (x>>8) | (x<<8);
  36. }
  37. // Swapping 32bit.
  38. unsigned long SwapLONG( unsigned long x)
  39. {
  40. return
  41. (x>>24)
  42. | ((x>>8) & 0xff00)
  43. | ((x<<8) & 0xff0000)
  44. | (x<<24);
  45. }
  46. #endif