Anonymous avatar Anonymous committed d28c2e8

Added SDL.endian functions

Comments (0)

Files changed (3)

 from SDL.audio import *
 from SDL.cdrom import *
 from SDL.constants import *
+from SDL.endian import *
 from SDL.error import *
 from SDL.events import *
 from SDL.joystick import *
 TIMER_RESOLUTION = 0x0000000a
 #END GENERATED CONSTANTS
 
-
 # From SDL_ttf.h (inserted manually)
 TTF_STYLE_NORMAL    = 0x00
 TTF_STYLE_BOLD      = 0x01
+#!/usr/bin/env python
+
+'''Functions for converting to native byte order
+'''
+
+__docformat__ = 'restructuredtext'
+__version__ = '$Id: $'
+
+import sys
+
+import SDL.constants
+
+def SDL_Swap16(x):
+    return (x << 8 & 0xff00) | \
+           (x >> 8 & 0x00ff)
+
+def SDL_Swap32(x):
+    return (x << 24 & 0xff000000) | \
+           (x << 8  & 0x00ff0000) | \
+           (x >> 8  & 0x0000ff00) | \
+           (x >> 24 & 0x000000ff) 
+
+def SDL_Swap64(x):
+    return (SDL_Swap32(x & 0xffffffff) << 32) | \
+           (SDL_Swap32(x >> 32 & 0xffffffff))
+
+def _noop(x):
+    return x
+
+if sys.byteorder == 'big':
+    SDL_BYTEORDER = SDL.constants.SDL_BIG_ENDIAN
+    SDL_SwapLE16 = SDL_Swap16
+    SDL_SwapLE32 = SDL_Swap32
+    SDL_SwapLE64 = SDL_Swap64
+    SDL_SwapBE16 = _noop
+    SDL_SwapBE32 = _noop
+    SDL_SwapBE64 = _noop
+else:
+    SDL_BYTEORDER = SDL.constants.SDL_LIL_ENDIAN
+    SDL_SwapLE16 = _noop
+    SDL_SwapLE32 = _noop
+    SDL_SwapLE64 = _noop
+    SDL_SwapBE16 = SDL_Swap16
+    SDL_SwapBE32 = SDL_Swap32
+    SDL_SwapBE64 = SDL_Swap64
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.