home *** CD-ROM | disk | FTP | other *** search
/ ring.yamanashi.ac.jp/pub/pc/freem/action/ / action.zip / a7xpg0_11.zip / a7xpg / import / SDL_endian.d < prev    next >
Text File  |  2003-09-20  |  4KB  |  98 lines

  1. /*
  2.     SDL - Simple DirectMedia Layer
  3.     Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
  4.  
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.  
  10.     This library 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.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public
  16.     License along with this library; if not, write to the Free
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  
  19.     Sam Lantinga
  20.     slouken@devolution.com
  21. */
  22.  
  23. /* Functions for reading and writing endian-specific values */
  24.  
  25. /* These functions read and write data of the specified endianness, 
  26.    dynamically translating to the host machine endianness.
  27.  
  28.    e.g.: If you want to read a 16 bit value on big-endian machine from
  29.          an open file containing little endian values, you would use:
  30.         value = SDL_ReadLE16(rp);
  31.          Note that the read/write functions use SDL_RWops pointers
  32.          instead of FILE pointers.  This allows you to read and write
  33.          endian values from large chunks of memory as well as files 
  34.          and other data sources.
  35. */
  36.  
  37. import SDL_types;
  38. import SDL_rwops;
  39. import SDL_byteorder;
  40.  
  41. extern(C):
  42.  
  43. /* Use inline functions for compilers that support them, and static
  44.    functions for those that do not.  Because these functions become
  45.    static for compilers that do not support inline functions, this
  46.    header should only be included in files that actually use them.
  47. */
  48.  
  49. Uint16 SDL_Swap16(Uint16 D) {
  50.     return((D<<8)|(D>>8));
  51. }
  52.  
  53. Uint32 SDL_Swap32(Uint32 D) {
  54.     return((D<<24)|((D<<8)&0x00FF0000)|((D>>8)&0x0000FF00)|(D>>24));
  55. }
  56.  
  57. Uint64 SDL_Swap64(Uint64 val) {
  58.     Uint32 hi, lo;
  59.     /* Separate into high and low 32-bit values and swap them */
  60.     lo = (Uint32)(val&0xFFFFFFFF);
  61.     val >>= 32;
  62.     hi = (Uint32)(val&0xFFFFFFFF);
  63.     val = SDL_Swap32(lo);
  64.     val <<= 32;
  65.     val |= SDL_Swap32(hi);
  66.     return(val);
  67. }
  68.  
  69. /* Byteswap item from the specified endianness to the native endianness */
  70. //#define SDL_SwapLE16(X)    (X)
  71. //#define SDL_SwapLE32(X)    (X)
  72. //#define SDL_SwapLE64(X)    (X)
  73. //#define SDL_SwapBE16(X)    SDL_Swap16(X)
  74. //#define SDL_SwapBE32(X)    SDL_Swap32(X)
  75. //#define SDL_SwapBE64(X)    SDL_Swap64(X)
  76. Uint16 SDL_SwapLE16(Uint16 X) { return SDL_Swap16(X); }
  77. Uint32 SDL_SwapLE32(Uint32 X) { return SDL_Swap32(X); }
  78. Uint64 SDL_SwapLE64(Uint64 X) { return SDL_Swap64(X); }
  79. Uint16 SDL_SwapBE16(Uint16 X) { return (X); }
  80. Uint32 SDL_SwapBE32(Uint32 X) { return (X); }
  81. Uint64 SDL_SwapBE64(Uint64 X) { return (X); }
  82.  
  83. /* Read an item of the specified endianness and return in native format */
  84. Uint16 SDL_ReadLE16(SDL_RWops *src);
  85. Uint16 SDL_ReadBE16(SDL_RWops *src);
  86. Uint32 SDL_ReadLE32(SDL_RWops *src);
  87. Uint32 SDL_ReadBE32(SDL_RWops *src);
  88. Uint64 SDL_ReadLE64(SDL_RWops *src);
  89. Uint64 SDL_ReadBE64(SDL_RWops *src);
  90.  
  91. /* Write an item of native format to the specified endianness */
  92. int SDL_WriteLE16(SDL_RWops *dst, Uint16 value);
  93. int SDL_WriteBE16(SDL_RWops *dst, Uint16 value);
  94. int SDL_WriteLE32(SDL_RWops *dst, Uint32 value);
  95. int SDL_WriteBE32(SDL_RWops *dst, Uint32 value);
  96. int SDL_WriteLE64(SDL_RWops *dst, Uint64 value);
  97. int SDL_WriteBE64(SDL_RWops *dst, Uint64 value);
  98.