diff -urN release/ports/devel/libsdl/Portfile release/ports/devel/libsdl/Portfile
--- release/ports/devel/libsdl/Portfile	2009-09-10 03:16:41.000000000 -0500
+++ release/ports/devel/libsdl/Portfile	2009-09-19 10:40:22.000000000 -0500
@@ -33,9 +33,12 @@
     port:xorg-libXrandr \
     port:xrender
 
-patchfiles      patch-SDL_x11gl_c.h.diff
+patchfiles      patch-SDL_x11gl_c.h.diff \
+                patch-SDL_snow_leopard.diff \
+                patch-SDL_1.2.13_14_backport.diff
 
 configure.args  --enable-shared \
+                --disable-nasm \
                 --mandir=${prefix}/share/man \
                 --x-include=${prefix}/include \
                 --x-lib=${prefix}/lib
@@ -100,13 +103,6 @@
     }
 }
 
-platform darwin 10 {
-	# This doesn't build correctly against the 10.6 SDK due to using deprecated (10.5) and removed (10.6) API
-	macosx_deployment_target 10.5
-	configure.cppflags-append -isysroot /Developer/SDKs/MacOSX10.5.sdk
-	configure.cflags-append -isysroot /Developer/SDKs/MacOSX10.5.sdk
-}
-
 livecheck.type  regex
 livecheck.url   ${homepage}download.php
 livecheck.regex ${my_name}-(\\d+(?:\\.\\d+)*)
diff -urN release/ports/devel/libsdl/files/patch-SDL_snow_leopard.diff release/ports/devel/libsdl/files/patch-SDL_snow_leopard.diff
--- release/ports/devel/libsdl/files/patch-SDL_snow_leopard.diff	1969-12-31 18:00:00.000000000 -0600
+++ release/ports/devel/libsdl/files/patch-SDL_snow_leopard.diff	2009-09-18 23:13:40.000000000 -0500
@@ -0,0 +1,998 @@
+Index: src/cdrom/macosx/CDPlayer.h
+===================================================================
+--- src/cdrom/macosx/CDPlayer.h	(revision 4718)
++++ src/cdrom/macosx/CDPlayer.h	(working copy)
+@@ -34,6 +34,10 @@
+ #include "SDL_thread.h"
+ #include "SDL_mutex.h"
+ 
++#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1050
++typedef SInt16 FSIORefNum;
++#endif
++
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+Index: src/video/quartz/SDL_QuartzVideo.h
+===================================================================
+--- src/video/quartz/SDL_QuartzVideo.h	(revision 4718)
++++ src/video/quartz/SDL_QuartzVideo.h	(working copy)
+@@ -93,7 +93,8 @@
+     Uint32             warp_flag;          /* boolean; notify to event loop that a warp just occured */
+     Uint32             warp_ticks;         /* timestamp when the warp occured */
+     NSWindow           *window;            /* Cocoa window to implement the SDL window */
+-    NSQuickDrawView    *view;              /* the window's view; draw 2D and OpenGL into this view */
++    NSView             *view;              /* the window's view; draw 2D and OpenGL into this view */
++    CGContextRef       cg_context;         /* CoreGraphics rendering context */
+     SDL_Surface        *resize_icon;       /* icon for the resize badge, we have to draw it by hand */
+     SDL_GrabMode       current_grab_mode;  /* default value is SDL_GRAB_OFF */
+     SDL_Rect           **client_mode_list; /* resolution list to pass back to client */
+@@ -113,7 +114,8 @@
+     Uint8              *current_buffer;    /* the buffer being copied to the screen */
+     BOOL               quit_thread;        /* used to quit the async blitting thread */
+     SInt32             system_version;     /* used to dis-/enable workarounds depending on the system version */
+-    
++
++#if SDL_LEGACY_QUICKDRAW
+     ImageDescriptionHandle yuv_idh;
+     MatrixRecordPtr        yuv_matrix;
+     DecompressorComponent  yuv_codec;
+@@ -121,6 +123,7 @@
+     PlanarPixmapInfoYUV420 *yuv_pixmap;
+     Sint16                  yuv_width, yuv_height;
+     CGrafPtr                yuv_port;
++#endif
+ 
+     void *opengl_library;    /* dynamically loaded OpenGL library. */
+ } SDL_PrivateVideoData;
+@@ -139,6 +142,7 @@
+ #define mode_flags (this->hidden->flags)
+ #define qz_window (this->hidden->window)
+ #define window_view (this->hidden->view)
++#define cg_context (this->hidden->cg_context)
+ #define video_set (this->hidden->video_set)
+ #define warp_ticks (this->hidden->warp_ticks)
+ #define warp_flag (this->hidden->warp_flag)
+@@ -156,6 +160,7 @@
+ #define cursor_should_be_visible (this->hidden->cursor_should_be_visible)
+ #define cursor_visible (this->hidden->cursor_visible)
+ #define sw_buffers (this->hidden->sw_buffers)
++#define sw_contexts (this->hidden->sw_contexts)
+ #define thread (this->hidden->thread)
+ #define sem1 (this->hidden->sem1)
+ #define sem2 (this->hidden->sem2)
+Index: src/video/quartz/SDL_QuartzGL.m
+===================================================================
+--- src/video/quartz/SDL_QuartzGL.m	(revision 4718)
++++ src/video/quartz/SDL_QuartzGL.m	(working copy)
+@@ -45,7 +45,8 @@
+ @implementation NSOpenGLContext (CGLContextAccess)
+ - (CGLContextObj) cglContext;
+ {
+-    return _contextAuxiliary;
++return NULL;  // !!! FIXME
++    //return _contextAuxiliary;
+ }
+ @end
+ 
+Index: src/video/quartz/SDL_QuartzWindow.h
+===================================================================
+--- src/video/quartz/SDL_QuartzWindow.h	(revision 4718)
++++ src/video/quartz/SDL_QuartzWindow.h	(working copy)
+@@ -21,6 +21,10 @@
+ */
+ #include "SDL_config.h"
+ 
++#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1050
++typedef unsigned int NSUInteger;
++#endif
++
+ /* Subclass of NSWindow to fix genie effect and support resize events  */
+ @interface SDL_QuartzWindow : NSWindow
+ - (void)miniaturize:(id)sender;
+@@ -29,7 +33,7 @@
+ - (void)appDidHide:(NSNotification*)note;
+ - (void)appWillUnhide:(NSNotification*)note;
+ - (void)appDidUnhide:(NSNotification*)note;
+-- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag;
++- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag;
+ @end
+ 
+ /* Delegate for our NSWindow to send SDLQuit() on close */
+Index: src/video/quartz/SDL_QuartzWM.m
+===================================================================
+--- src/video/quartz/SDL_QuartzWM.m	(revision 4718)
++++ src/video/quartz/SDL_QuartzWM.m	(working copy)
+@@ -171,11 +171,7 @@
+     else {
+        
+         *p = [ window_view convertPoint:*p toView: nil ];
+-        
+-        /* We need a workaround in OpenGL mode */
+-        if ( SDL_VideoSurface->flags & SDL_OPENGL ) {
+-            p->y = [window_view frame].size.height - p->y;
+-        }
++        p->y = [window_view frame].size.height - p->y;
+     }
+ }
+ 
+@@ -189,11 +185,7 @@
+     else {
+ 
+         *p = [ window_view convertPoint:*p fromView: nil ];
+-        
+-        /* We need a workaround in OpenGL mode */
+-        if ( SDL_VideoSurface != NULL && (SDL_VideoSurface->flags & SDL_OPENGL) ) {
+-            p->y = [window_view frame].size.height - p->y;
+-        }
++        p->y = [window_view frame].size.height - p->y;
+     }
+ }
+ 
+Index: src/video/quartz/SDL_QuartzYUV.m
+===================================================================
+--- src/video/quartz/SDL_QuartzYUV.m	(revision 4718)
++++ src/video/quartz/SDL_QuartzYUV.m	(working copy)
+@@ -48,10 +48,15 @@
+ }
+ 
+ static int QZ_DisplayYUV (_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst) {
+-
++#if SDL_LEGACY_QUICKDRAW
+     OSErr err;
+     CodecFlags flags;
++    int h;
++    char *p_dst, *p_src;
++    PixMapHandle           hPixMap;
++    long                   theRowBytes;
+ 
++
+     if (dst->x != 0 || dst->y != 0) {
+ 
+         SDL_SetError ("Need a dst at (0,0)");
+@@ -81,27 +86,40 @@
+                                          codecFlagUseImageBuffer, &flags, nil ) != noErr ) )
+     {
+         SDL_SetError ("DecompressSequenceFrameS failed");
++        return TRUE;
+     }
+ 
+-    return err != noErr;
++    /* TODO: use CGContextDrawImage here too!  Create two CGContextRefs the same way we
++       create two buffers, replace current_buffer with current_context and set it
++       appropriately in QZ_FlipDoubleBuffer.  Use CTM instead of the above
++       SetIdentityMatrix thing.  */
++    hPixMap     = GetGWorldPixMap(yuv_port);
++    p_src       = GetPixBaseAddr(hPixMap);
++    theRowBytes = QTGetPixMapHandleRowBytes(hPixMap);
++    p_dst       = SDL_VideoSurface->pixels + SDL_VideoSurface->offset;
++    for (h = dst->h; h--; ) {
++        SDL_memcpy (p_dst, p_src, dst->w * 4);
++        p_src += theRowBytes;
++        p_dst += SDL_VideoSurface->pitch;
++    }
++    SDL_Flip (SDL_VideoSurface);
++#endif
++    return FALSE;
+ }
+ 
+ static void QZ_FreeHWYUV (_THIS, SDL_Overlay *overlay) {
+-
++#if SDL_LEGACY_QUICKDRAW
+     CDSequenceEnd (yuv_seq);
+     ExitMovies();
++    DisposeGWorld(yuv_port);
+ 
+     SDL_free (overlay->hwfuncs);
+     SDL_free (overlay->pitches);
+     SDL_free (overlay->pixels);
+ 
+-    if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
+-        [ qz_window close ];
+-        qz_window = nil;
+-    }
+-
+     SDL_free (yuv_matrix);
+     DisposeHandle ((Handle)yuv_idh);
++#endif
+ }
+ 
+ /* check for 16 byte alignment, bail otherwise */
+@@ -112,11 +130,12 @@
+ 
+ SDL_Overlay* QZ_CreateYUVOverlay (_THIS, int width, int height,
+                                          Uint32 format, SDL_Surface *display) {
+-
++    SDL_Overlay *overlay = NULL;
++#if SDL_LEGACY_QUICKDRAW
+     Uint32 codec;
+     OSStatus err;
+     CGrafPtr port;
+-    SDL_Overlay *overlay;
++    Rect  theBounds = {0, 0};
+ 
+     if (format == SDL_YV12_OVERLAY ||
+         format == SDL_IYUV_OVERLAY) {
+@@ -150,50 +169,21 @@
+         SDL_SetError ("Could not find QuickTime codec for format");
+         return NULL;
+     }
+-
+-    if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
+-
+-        /*
+-          Acceleration requires a window to be present.
+-          A CGrafPtr that points to the screen isn't good enough
+-        */
+-        NSRect content = NSMakeRect (0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
+-
+-        qz_window = [ [ SDL_QuartzWindow alloc ]
+-                            initWithContentRect:content
+-                            styleMask:NSBorderlessWindowMask
+-                            backing:NSBackingStoreBuffered defer:NO ];
+-
+-        if (qz_window == nil) {
+-            SDL_SetError ("Could not create the Cocoa window");
+-            return NULL;
+-        }
+-
+-        [ qz_window setContentView:[ [ NSQuickDrawView alloc ] init ] ];
+-        [ qz_window setReleasedWhenClosed:YES ];
+-        [ qz_window center ];
+-        [ qz_window setAcceptsMouseMovedEvents:YES ];
+-        [ qz_window setLevel:CGShieldingWindowLevel() ];
+-        [ qz_window makeKeyAndOrderFront:nil ];
+-
+-        port = [ [ qz_window contentView ] qdPort ];
+-        SetPort (port);
+-        
+-        /*
+-            BUG: would like to remove white flash when window kicks in
+-            {
+-                Rect r;
+-                SetRect (&r, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
+-                PaintRect (&r);
+-                QDFlushPortBuffer (port, nil);
+-            }
+-        */
++    
++    theBounds.right  = width;
++    theBounds.bottom = height;
++    yuv_port = NULL;
++    
++    err = QTNewGWorld(&yuv_port, k32ARGBPixelFormat, &theBounds,
++                      NULL, NULL, 0);
++    
++    if (err != noErr) {
++        SDL_SetError ("Could not init QuickTime world");
++        return NULL;
+     }
+-    else {
+-        port = [ window_view qdPort ];
+-        SetPort (port);
+-    }
+     
++    LockPixels(GetGWorldPixMap(yuv_port));
++    
+     SetIdentityMatrix (yuv_matrix);
+     
+     HLock ((Handle)yuv_idh);
+@@ -219,7 +209,7 @@
+                                     yuv_idh,
+                                     NULL,
+                                     0,
+-                                    port,
++                                    yuv_port,
+                                     NULL,
+                                     NULL,
+                                     yuv_matrix,
+@@ -231,11 +221,13 @@
+     
+     if (err != noErr) {
+         SDL_SetError ("Error trying to start YUV codec.");
++        DisposeGWorld(yuv_port);
+         return NULL;
+     }
+     
+     overlay = (SDL_Overlay*) SDL_malloc (sizeof(*overlay));
+     if (overlay == NULL) {
++        DisposeGWorld(yuv_port);
+         SDL_OutOfMemory();
+         return NULL;
+     }
+@@ -263,6 +255,7 @@
+             plane3 = 1; /* V plane maps to plane 2 */
+         }
+         else {
++            DisposeGWorld(yuv_port);
+             SDL_SetError("Unsupported YUV format");
+             return NULL;
+         }
+@@ -270,6 +263,7 @@
+         pixels = (Uint8**) SDL_malloc (sizeof(*pixels) * 3);
+         pitches = (Uint16*) SDL_malloc (sizeof(*pitches) * 3);
+         if (pixels == NULL || pitches == NULL) {
++            DisposeGWorld(yuv_port);
+             SDL_OutOfMemory();
+             return NULL;
+         }
+@@ -280,6 +274,7 @@
+             SDL_malloc (sizeof(PlanarPixmapInfoYUV420) +
+                     (width * height * 2));
+         if (yuv_pixmap == NULL) {
++            DisposeGWorld(yuv_port);
+             SDL_OutOfMemory ();
+             return NULL;
+         }
+@@ -314,6 +309,7 @@
+ 
+     overlay->hwfuncs = SDL_malloc (sizeof(*overlay->hwfuncs));
+     if (overlay->hwfuncs == NULL) {
++		DisposeGWorld(yuv_port);
+         SDL_OutOfMemory();
+         return NULL;
+     }
+@@ -325,6 +321,7 @@
+ 
+     yuv_width = overlay->w;
+     yuv_height = overlay->h;
++#endif
+     
+     return overlay;
+ }
+Index: src/video/quartz/SDL_QuartzVideo.m
+===================================================================
+--- src/video/quartz/SDL_QuartzVideo.m	(revision 4718)
++++ src/video/quartz/SDL_QuartzVideo.m	(working copy)
+@@ -38,7 +38,8 @@
+ @implementation NSScreen (NSScreenAccess)
+ - (void) setFrame:(NSRect)frame;
+ {
+-    _frame = frame;
++// !!! FIXME
++//    _frame = frame;
+ }
+ @end
+ 
+@@ -52,6 +53,8 @@
+ - (void) doCommandBySelector:(SEL) myselector {}
+ @end
+ 
++/* absent in 10.3.9.  */
++CG_EXTERN CGImageRef CGBitmapContextCreateImage (CGContextRef);
+ 
+ /* Bootstrap functions */
+ static int              QZ_Available ();
+@@ -79,8 +82,6 @@
+ static void         QZ_DoubleBufferUpdate (_THIS, int num_rects, SDL_Rect *rects);
+ 
+ static void         QZ_DirectUpdate     (_THIS, int num_rects, SDL_Rect *rects);
+-static int          QZ_LockWindow       (_THIS, SDL_Surface *surface);
+-static void         QZ_UnlockWindow     (_THIS, SDL_Surface *surface);
+ static void         QZ_UpdateRects      (_THIS, int num_rects, SDL_Rect *rects);
+ static void         QZ_VideoQuit        (_THIS);
+ 
+@@ -371,6 +372,12 @@
+     this->LockHWSurface   = NULL;
+     this->UnlockHWSurface = NULL;
+     
++    if (cg_context) {
++        CGContextFlush (cg_context);
++        CGContextRelease (cg_context);
++        cg_context = nil;
++    }
++    
+     /* Release fullscreen resources */
+     if ( mode_flags & SDL_FULLSCREEN ) {
+ 
+@@ -487,7 +494,8 @@
+     current->flags |= SDL_FULLSCREEN;
+     current->flags |= SDL_HWSURFACE;
+     current->flags |= SDL_PREALLOC;
+-    
++    /* current->hwdata = (void *) CGDisplayGetDrawingContext (display_id); */
++
+     this->UpdateRects     = QZ_DirectUpdate;
+     this->LockHWSurface   = QZ_LockHWSurface;
+     this->UnlockHWSurface = QZ_UnlockHWSurface;
+@@ -538,6 +546,7 @@
+        and with no valid window/view in FULLSCREEN, SDL wouldn't update its cursor. )
+     */
+ 	/* Check for user-specified window and view */
++#if SDL_LEGACY_QUICKDRAW
+     {
+         char *windowPtrString = getenv ("SDL_NSWindowPointer");
+         char *viewPtrString = getenv ("SDL_NSQuickDrawViewPointer");
+@@ -561,12 +570,13 @@
+             [ qz_window retain ];
+         }
+     }
++#endif
+     /* Check if we should recreate the window */
+     if (qz_window == nil) {
+         /* Manually create a window, avoids having a nib file resource */
+         qz_window = [ [ SDL_QuartzWindow alloc ] 
+             initWithContentRect:contentRect
+-                styleMask:nil 
++                styleMask:0
+                     backing:NSBackingStoreBuffered
+                         defer:NO ];
+ 
+@@ -695,6 +705,7 @@
+     }
+     
+     /* Check for user-specified window and view */
++#if SDL_LEGACY_QUICKDRAW
+     {
+         char *windowPtrString = getenv ("SDL_NSWindowPointer");
+         char *viewPtrString = getenv ("SDL_NSQuickDrawViewPointer");
+@@ -727,7 +738,8 @@
+                 current->flags |= SDL_NOFRAME;
+         }
+     }
+-    
++#endif
++
+     /* Check if we should recreate the window */
+     if (qz_window == nil) {
+     
+@@ -809,46 +821,34 @@
+     }
+     /* For 2D, we set the subview to an NSQuickDrawView */
+     else {
+-        short qdbpp = 0;
++        CGColorSpaceRef cgColorspace;
+ 
+         /* Only recreate the view if it doesn't already exist */
+         if (window_view == nil) {
+         
+-            window_view = [ [ NSQuickDrawView alloc ] initWithFrame:contentRect ];
++            window_view = [ [ NSView alloc ] initWithFrame:contentRect ];
+             [ window_view setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable ];
+             [ [ qz_window contentView ] addSubview:window_view ];
+             [ window_view release ];
+             [ qz_window makeKeyAndOrderFront:nil ];
+         }
+         
+-        LockPortBits ( [ window_view qdPort ] );
+-        current->pixels = GetPixBaseAddr ( GetPortPixMap ( [ window_view qdPort ] ) );
+-        current->pitch  = GetPixRowBytes ( GetPortPixMap ( [ window_view qdPort ] ) );
+-        qdbpp           = GetPixDepth ( GetPortPixMap ( [ window_view qdPort ] ) );
+-        UnlockPortBits ( [ window_view qdPort ] );
+-
+-        /* QuickDraw may give a 16-bit shadow surface on 8-bit displays! */
+-        *bpp = qdbpp;
+-
++        cgColorspace = CGColorSpaceCreateDeviceRGB();
++        current->pitch = 4 * current->w;
++        current->pixels = SDL_malloc (current->h * current->pitch);
++        
++        cg_context = CGBitmapContextCreate (current->pixels, current->w, current->h,
++                        8, current->pitch, cgColorspace,
++                        kCGImageAlphaNoneSkipFirst);
++        CGColorSpaceRelease (cgColorspace);
++        
+         current->flags |= SDL_SWSURFACE;
+-        current->flags |= SDL_PREALLOC;
+         current->flags |= SDL_ASYNCBLIT;
++        current->hwdata = (void *) cg_context;
+         
+-        /* 
+-            current->pixels now points to the window's pixels
+-            We want it to point to the *view's* pixels 
+-        */
+-        { 
+-            int vOffset = [ qz_window frame ].size.height - 
+-                [ window_view frame ].size.height - [ window_view frame ].origin.y;
+-            
+-            int hOffset = [ window_view frame ].origin.x;
+-                    
+-            current->pixels = (Uint8 *)current->pixels + (vOffset * current->pitch) + hOffset * (qdbpp/8);
+-        }
+         this->UpdateRects     = QZ_UpdateRects;
+-        this->LockHWSurface   = QZ_LockWindow;
+-        this->UnlockHWSurface = QZ_UnlockWindow;
++        this->LockHWSurface   = QZ_LockHWSurface;
++        this->UnlockHWSurface = QZ_UnlockHWSurface;
+     }
+ 
+     /* Save flags to ensure correct teardown */
+@@ -877,8 +877,8 @@
+     }
+     /* Setup windowed video */
+     else {
+-        /* Force bpp to the device's bpp */
+-        bpp = device_bpp;
++        /* Force bpp to 32 */
++        bpp = 32;
+         current = QZ_SetVideoWindowed (this, current, width, height, &bpp, flags);
+         if (current == NULL)
+             return NULL;
+@@ -903,9 +903,15 @@
+                 return NULL;
+             case 32:   /* (8)-8-8-8 ARGB */
+                 amask = 0x00000000;
++#ifdef __LITTLE_ENDIAN__
++                rmask = 0x0000FF00;
++                gmask = 0x00FF0000;
++                bmask = 0xFF000000;
++#else
+                 rmask = 0x00FF0000;
+                 gmask = 0x0000FF00;
+                 bmask = 0x000000FF;
++#endif
+                 break;
+         }
+ 
+@@ -1062,6 +1068,9 @@
+         /* On error, skip VBL delay */
+         ERROR:
+         
++        /* TODO: use CGContextDrawImage here too!  Create two CGContextRefs the same way we
++           create two buffers, replace current_buffer with current_context and set it
++           appropriately in QZ_FlipDoubleBuffer.  */
+         while ( h-- ) {
+         
+             SDL_memcpy (dst, src, len);
+@@ -1105,254 +1114,7 @@
+ #pragma unused(this,num_rects,rects)
+ }
+ 
+-/*
+-    The obscured code is based on work by Matt Slot fprefect@ambrosiasw.com,
+-    who supplied sample code for Carbon.
+-*/
+ 
+-/*#define TEST_OBSCURED 1*/
+-
+-#if TEST_OBSCURED
+-#include "CGS.h"
+-#endif
+-
+-static int QZ_IsWindowObscured (NSWindow *window) {
+-
+-
+-#if TEST_OBSCURED
+-
+-    /*  
+-        In order to determine if a direct copy to the screen is possible,
+-        we must figure out if there are any windows covering ours (including shadows).
+-        This can be done by querying the window server about the on screen
+-        windows for their screen rectangle and window level.
+-        The procedure used below is puts accuracy before speed; however, it aims to call
+-        the window server the fewest number of times possible to keep things reasonable.
+-        In my testing on a 300mhz G3, this routine typically takes < 2 ms. -DW
+-    
+-    Notes:
+-        -Calls into the Window Server involve IPC which is slow.
+-        -Getting a rectangle seems slower than getting the window level
+-        -The window list we get back is in sorted order, top to bottom
+-        -On average, I suspect, most windows above ours are dock icon windows (hence optimization)
+-        -Some windows above ours are always there, and cannot move or obscure us (menu bar)
+-    
+-    Bugs:
+-        -no way (yet) to deactivate direct drawing when a window is dragged,
+-        or suddenly obscured, so drawing continues and can produce garbage
+-        We need some kind of locking mechanism on window movement to prevent this
+-    
+-        -deactivated normal windows use activated normal
+-        window shadows (slight inaccuraccy)
+-    */
+-
+-    /* Cache the connection to the window server */
+-    static CGSConnectionID    cgsConnection = (CGSConnectionID) -1;
+-
+-    /* Cache the dock icon windows */
+-    static CGSWindowID          dockIcons[kMaxWindows];
+-    static int                  numCachedDockIcons = 0;
+-
+-    CGSWindowID                windows[kMaxWindows];
+-    CGSWindowCount             i, count;
+-    CGSWindowLevel             winLevel;
+-    CGSRect                    winRect;
+-
+-    CGSRect contentRect;
+-    int     windowNumber;
+-    int     firstDockIcon;
+-    int     dockIconCacheMiss;
+-    int     windowContentOffset;
+-
+-    int     obscured = SDL_TRUE;
+-
+-    if ( [ window isVisible ] ) {
+-
+-        /*  
+-            walk the window list looking for windows over top of
+-            (or casting a shadow on) ours 
+-        */
+-
+-        /* 
+-           Get a connection to the window server
+-           Should probably be moved out into SetVideoMode() or InitVideo()
+-        */
+-        if (cgsConnection == (CGSConnectionID) -1) {
+-            cgsConnection = (CGSConnectionID) 0;
+-            cgsConnection = _CGSDefaultConnection ();
+-        }
+-
+-        if (cgsConnection) {
+-
+-            if ( ! [ window styleMask ] & NSBorderlessWindowMask )
+-                windowContentOffset = 22;
+-            else
+-                windowContentOffset = 0;
+-
+-            windowNumber = [ window windowNumber ];
+-
+-            /* The window list is sorted according to order on the screen */
+-            count = 0;
+-            CGSGetOnScreenWindowList (cgsConnection, 0, kMaxWindows, windows, &count);
+-            CGSGetScreenRectForWindow (cgsConnection, windowNumber, &contentRect);
+-
+-            /* adjust rect for window title bar (if present) */
+-            contentRect.origin.y    += windowContentOffset;
+-            contentRect.size.height -= windowContentOffset;
+-
+-            firstDockIcon = -1;
+-            dockIconCacheMiss = SDL_FALSE;
+-
+-            /* 
+-                The first window is always an empty window with level kCGSWindowLevelTop
+-                so start at index 1
+-            */
+-            for (i = 1; i < count; i++) {
+-
+-                /* If we reach our window in the list, it cannot be obscured */
+-                if (windows[i] == windowNumber) {
+-
+-                    obscured = SDL_FALSE;
+-                    break;
+-                }
+-                else {
+-
+-                    float shadowSide;
+-                    float shadowTop;
+-                    float shadowBottom;
+-
+-                    CGSGetWindowLevel (cgsConnection, windows[i], &winLevel);
+-
+-                    if (winLevel == kCGSWindowLevelDockIcon) {
+-
+-                        int j;
+-
+-                        if (firstDockIcon < 0) {
+-
+-                            firstDockIcon = i;
+-
+-                            if (numCachedDockIcons > 0) {
+-
+-                                for (j = 0; j < numCachedDockIcons; j++) {
+-
+-                                    if (windows[i] == dockIcons[j])
+-                                        i++;
+-                                    else
+-                                        break;
+-                                }
+-
+-                                if (j != 0) {
+-
+-                                    i--;
+-
+-                                    if (j < numCachedDockIcons) {
+-
+-                                        dockIconCacheMiss = SDL_TRUE;
+-                                    }
+-                                }
+-
+-                            }
+-                        }
+-
+-                        continue;
+-                    }
+-                    else if (winLevel == kCGSWindowLevelMenuIgnore
+-                             /* winLevel == kCGSWindowLevelTop */) {
+-
+-                        continue; /* cannot obscure window */
+-                    }
+-                    else if (winLevel == kCGSWindowLevelDockMenu ||
+-                             winLevel == kCGSWindowLevelMenu) {
+-
+-                        shadowSide = 18;
+-                        shadowTop = 4;
+-                        shadowBottom = 22;
+-                    }
+-                    else if (winLevel == kCGSWindowLevelUtility) {
+-
+-                        shadowSide = 8;
+-                        shadowTop = 4;
+-                        shadowBottom = 12;
+-                    }
+-                    else if (winLevel == kCGSWindowLevelNormal) {
+-
+-                        /* 
+-                            These numbers are for foreground windows,
+-                            they are too big (but will work) for background windows 
+-                        */
+-                        shadowSide = 20;
+-                        shadowTop = 10;
+-                        shadowBottom = 24;
+-                    }
+-                    else if (winLevel == kCGSWindowLevelDock) {
+-
+-                        /* Create dock icon cache */
+-                        if (numCachedDockIcons != (i-firstDockIcon) ||
+-                            dockIconCacheMiss) {
+-
+-                            numCachedDockIcons = i - firstDockIcon;
+-                            SDL_memcpy (dockIcons, &(windows[firstDockIcon]),
+-                                    numCachedDockIcons * sizeof(*windows));
+-                        }
+-
+-                        /* no shadow */
+-                        shadowSide = 0;
+-                        shadowTop = 0;
+-                        shadowBottom = 0;
+-                    }
+-                    else {
+-
+-                        /*
+-                            kCGSWindowLevelDockLabel,
+-                            kCGSWindowLevelDock,
+-                            kOther???
+-                        */
+-
+-                        /* no shadow */
+-                        shadowSide = 0;
+-                        shadowTop = 0;
+-                        shadowBottom = 0;
+-                    }
+-
+-                    CGSGetScreenRectForWindow (cgsConnection, windows[i], &winRect);
+-
+-                    winRect.origin.x -= shadowSide;
+-                    winRect.origin.y -= shadowTop;
+-                    winRect.size.width += shadowSide;
+-                    winRect.size.height += shadowBottom;
+-
+-                    if (NSIntersectsRect (contentRect, winRect)) {
+-
+-                        obscured = SDL_TRUE;
+-                        break;
+-                    }
+-
+-                } /* window was not our window */
+-
+-            } /* iterate over windows */
+-
+-        } /* get cgsConnection */
+-
+-    } /* window is visible */
+-    
+-    return obscured;
+-#else
+-    return SDL_TRUE;
+-#endif
+-}
+-
+-
+-/* Locking functions for the software window buffer */
+-static int QZ_LockWindow (_THIS, SDL_Surface *surface) {
+-    
+-    return LockPortBits ( [ window_view qdPort ] );
+-}
+-
+-static void QZ_UnlockWindow (_THIS, SDL_Surface *surface) {
+-
+-    UnlockPortBits ( [ window_view qdPort ] );
+-}
+-
+ /* Resize icon, BMP format */
+ static const unsigned char QZ_ResizeIcon[] = {
+     0x42,0x4d,0x31,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00,
+@@ -1393,41 +1155,34 @@
+     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0b
+ };
+ 
+-static void QZ_DrawResizeIcon (_THIS, RgnHandle dirtyRegion) {
++static void QZ_DrawResizeIcon (_THIS) {
+ 
+     /* Check if we should draw the resize icon */
+     if (SDL_VideoSurface->flags & SDL_RESIZABLE) {
+     
+-        Rect    icon;
+-        SetRect (&icon, SDL_VideoSurface->w - 13, SDL_VideoSurface->h - 13, 
+-                    SDL_VideoSurface->w, SDL_VideoSurface->h);
+-                    
+-        if (RectInRgn (&icon, dirtyRegion)) {
++        SDL_Rect icon_rect;
+         
+-            SDL_Rect icon_rect;
++        /* Create the icon image */
++        if (resize_icon == NULL) {
++        
++            SDL_RWops *rw;
++            SDL_Surface *tmp;
+             
+-            /* Create the icon image */
+-            if (resize_icon == NULL) {
++            rw = SDL_RWFromConstMem (QZ_ResizeIcon, sizeof(QZ_ResizeIcon));
++            tmp = SDL_LoadBMP_RW (rw, SDL_TRUE);
++                                                            
++            resize_icon = SDL_ConvertSurface (tmp, SDL_VideoSurface->format, SDL_SRCCOLORKEY);
++            SDL_SetColorKey (resize_icon, SDL_SRCCOLORKEY, 0xFFFFFF);
+             
+-                SDL_RWops *rw;
+-                SDL_Surface *tmp;
+-                
+-                rw = SDL_RWFromConstMem (QZ_ResizeIcon, sizeof(QZ_ResizeIcon));
+-                tmp = SDL_LoadBMP_RW (rw, SDL_TRUE);
+-                                                                
+-                resize_icon = SDL_ConvertSurface (tmp, SDL_VideoSurface->format, SDL_SRCCOLORKEY);
+-                SDL_SetColorKey (resize_icon, SDL_SRCCOLORKEY, 0xFFFFFF);
+-                
+-                SDL_FreeSurface (tmp);
+-            }
++            SDL_FreeSurface (tmp);
++        }
+             
+-            icon_rect.x = SDL_VideoSurface->w - 13;
+-            icon_rect.y = SDL_VideoSurface->h - 13;
+-            icon_rect.w = 13;
+-            icon_rect.h = 13;
++        icon_rect.x = SDL_VideoSurface->w - 13;
++        icon_rect.y = SDL_VideoSurface->h - 13;
++        icon_rect.w = 13;
++        icon_rect.h = 13;
+             
+-            SDL_BlitSurface (resize_icon, NULL, SDL_VideoSurface, &icon_rect);
+-        }
++        SDL_BlitSurface (resize_icon, NULL, SDL_VideoSurface, &icon_rect);
+     }
+ }
+ 
+@@ -1441,75 +1196,19 @@
+         /* Do nothing if miniaturized */
+     }
+     
+-    else if ( ! QZ_IsWindowObscured (qz_window) ) {
+-
+-        /* Use direct copy to flush contents to the display */
+-        CGrafPtr savePort;
+-        CGrafPtr dstPort, srcPort;
+-        const BitMap  *dstBits, *srcBits;
+-        Rect     dstRect, srcRect;
+-        Point    offset;
+-        int i;
+-
+-        GetPort (&savePort);
+-
+-        dstPort = CreateNewPortForCGDisplayID ((UInt32)display_id);
+-        srcPort = [ window_view qdPort ];
+-
+-        offset.h = 0;
+-        offset.v = 0;
+-        SetPort (srcPort);
+-        LocalToGlobal (&offset);
+-
+-        SetPort (dstPort);
+-
+-        LockPortBits (dstPort);
+-        LockPortBits (srcPort);
+-
+-        dstBits = GetPortBitMapForCopyBits (dstPort);
+-        srcBits = GetPortBitMapForCopyBits (srcPort);
+-
+-        for (i = 0; i < numRects; i++) {
+-
+-            SetRect (&srcRect, rects[i].x, rects[i].y,
+-                     rects[i].x + rects[i].w,
+-                     rects[i].y + rects[i].h);
+-
+-            SetRect (&dstRect,
+-                     rects[i].x + offset.h,
+-                     rects[i].y + offset.v,
+-                     rects[i].x + rects[i].w + offset.h,
+-                     rects[i].y + rects[i].h + offset.v);
+-
+-            CopyBits (srcBits, dstBits,
+-                      &srcRect, &dstRect, srcCopy, NULL);
+-
+-        }
+-
+-        SetPort (savePort);
+-    }
+     else {
+-        /* Use QDFlushPortBuffer() to flush content to display */
+-        int i;
+-        RgnHandle dirty = NewRgn ();
+-        RgnHandle temp  = NewRgn ();
+-
+-        SetEmptyRgn (dirty);
+-
+-        /* Build the region of dirty rectangles */
+-        for (i = 0; i < numRects; i++) {
+-
+-            MacSetRectRgn (temp, rects[i].x, rects[i].y,
+-                        rects[i].x + rects[i].w, rects[i].y + rects[i].h);
+-            MacUnionRgn (dirty, temp, dirty);
+-        }
+-
+-        QZ_DrawResizeIcon (this, dirty);
++        CGContextRef cgc = (CGContextRef)
++            [[NSGraphicsContext graphicsContextWithWindow: qz_window]
++                graphicsPort];
++        QZ_DrawResizeIcon (this);
++        CGContextFlush (cg_context);
++        CGImageRef image = CGBitmapContextCreateImage (cg_context);
++        CGRect rectangle = CGRectMake (0,0,[window_view frame].size.width,[window_view frame].size.height);
+         
+-        /* Flush the dirty region */
+-        QDFlushPortBuffer ( [ window_view qdPort ], dirty );
+-        DisposeRgn (dirty);
+-        DisposeRgn (temp);
++        CGContextDrawImage (cgc, rectangle, image);
++        CGImageRelease(image);
++        CGContextFlush (cgc);
++        CGContextRelease (cgc);
+     }
+ }
+ 
+Index: src/video/quartz/SDL_QuartzWindow.m
+===================================================================
+--- src/video/quartz/SDL_QuartzWindow.m	(revision 4718)
++++ src/video/quartz/SDL_QuartzWindow.m	(working copy)
+@@ -125,31 +125,6 @@
+         newViewFrame = [ window_view frame ];
+         
+         SDL_PrivateResize (newViewFrame.size.width, newViewFrame.size.height);
+-
+-        /* If not OpenGL, we have to update the pixels and pitch */
+-        if ( ! ( SDL_VideoSurface->flags & SDL_OPENGL ) ) {
+-            
+-            CGrafPtr thePort = [ window_view qdPort ];
+-            LockPortBits ( thePort );
+-            
+-            SDL_VideoSurface->pixels = GetPixBaseAddr ( GetPortPixMap ( thePort ) );
+-            SDL_VideoSurface->pitch  = GetPixRowBytes ( GetPortPixMap ( thePort ) );
+-                        
+-            /* 
+-                SDL_VideoSurface->pixels now points to the window's pixels
+-                We want it to point to the *view's* pixels 
+-            */
+-            { 
+-                int vOffset = [ qz_window frame ].size.height - 
+-                    newViewFrame.size.height - newViewFrame.origin.y;
+-                
+-                int hOffset = newViewFrame.origin.x;
+-                        
+-                SDL_VideoSurface->pixels = (Uint8 *)SDL_VideoSurface->pixels + (vOffset * SDL_VideoSurface->pitch) + hOffset * (device_bpp/8);
+-            }
+-            
+-            UnlockPortBits ( thePort );
+-        }
+     }
+ }
+ 
+@@ -183,7 +158,7 @@
+     SDL_PrivateAppActive (1, SDL_APPACTIVE);
+ }
+ 
+-- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag
++- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag
+ {
+     /* Make our window subclass receive these application notifications */
+     [ [ NSNotificationCenter defaultCenter ] addObserver:self
+Index: configure.in
+===================================================================
+--- configure.in	(revision 4718)
++++ configure.in	(working copy)
+@@ -2697,7 +2697,8 @@
+         fi
+         if test x$enable_video_carbon = xyes -o x$enable_video_cocoa = xyes; then
+             # The Cocoa backend still needs Carbon, and the YUV code QuickTime
+-            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,QuickTime -Wl,-framework,ApplicationServices"
++            dnl EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,QuickTime -Wl,-framework,ApplicationServices"
++            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,ApplicationServices"
+             EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,Carbon"
+         fi
+         # If either the audio or CD driver is used, add the AudioUnit framework
diff -urN release/ports/devel/libsdl/files/patch-SDL_1.2.13_14_backport.diff release/ports/devel/libsdl/files/patch-SDL_1.2.13_14_backport.diff
--- release/ports/devel/libsdl/files/patch-SDL_1.2.13_14_backport.diff	1969-12-31 18:00:00.000000000 -0600
+++ release/ports/devel/libsdl/files/patch-SDL_1.2.13_14_backport.diff	2009-09-19 09:20:31.000000000 -0500
@@ -0,0 +1,584 @@
+--- configure.in	2009-09-18 23:15:04.000000000 -0500
++++ configure.in	2009-09-18 23:33:14.000000000 -0500
+@@ -2553,8 +2553,6 @@
+         if test x$enable_audio = xyes; then
+             AC_DEFINE(SDL_AUDIO_DRIVER_COREAUDIO)
+             SOURCES="$SOURCES $srcdir/src/audio/macosx/*.c"
+-            AC_DEFINE(SDL_AUDIO_DRIVER_SNDMGR)
+-            SOURCES="$SOURCES $srcdir/src/audio/macrom/*.c"
+             have_audio=yes
+         fi
+         # Set up files for the joystick library
+--- configure	2007-12-30 23:09:39.000000000 -0600
++++ configure	2009-09-19 09:15:17.000000000 -0500
+@@ -33970,11 +33970,6 @@
+ _ACEOF
+ 
+             SOURCES="$SOURCES $srcdir/src/audio/macosx/*.c"
+-            cat >>confdefs.h <<\_ACEOF
+-#define SDL_AUDIO_DRIVER_SNDMGR 1
+-_ACEOF
+-
+-            SOURCES="$SOURCES $srcdir/src/audio/macrom/*.c"
+             have_audio=yes
+         fi
+         # Set up files for the joystick library
+--- src/audio/macosx/SDL_coreaudio.c    (.../tags/SDL/release-1.2.13)   (revisio 4719)
++++ src/audio/macosx/SDL_coreaudio.c    (.../branches/SDL-1.2)  (revision 4719)
+@@ -21,8 +21,10 @@
+ */
+ #include "SDL_config.h"
+ 
++#include <CoreAudio/CoreAudio.h>
++#include <CoreServices/CoreServices.h>
+ #include <AudioUnit/AudioUnit.h>
+-#ifdef AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER
++#if MAC_OS_X_VERSION_MAX_ALLOWED <= 1050
+ #include <AudioUnit/AUNTComponent.h>
+ #endif
+ 
+@@ -91,19 +93,25 @@
+ };
+ 
+ /* The CoreAudio callback */
+-static OSStatus     audioCallback (void                             *inRefCon, 
+-                                    AudioUnitRenderActionFlags      inActionFlags,
+-                                    const AudioTimeStamp            *inTimeStamp, 
+-                                    UInt32                          inBusNumber, 
+-                                    AudioBuffer                     *ioData)
++static OSStatus     audioCallback (void                            *inRefCon,
++                                   AudioUnitRenderActionFlags      *ioActionFlags,
++                                   const AudioTimeStamp            *inTimeStamp,
++                                   UInt32                          inBusNumber,
++                                   UInt32                          inNumberFrames,
++                                   AudioBufferList                 *ioData)
+ {
+     SDL_AudioDevice *this = (SDL_AudioDevice *)inRefCon;
+     UInt32 remaining, len;
++    AudioBuffer *abuf;
+     void *ptr;
++    UInt32 i;
+ 
+     /* Only do anything if audio is enabled and not paused */
+     if ( ! this->enabled || this->paused ) {
+-        SDL_memset(ioData->mData, this->spec.silence, ioData->mDataByteSize);
++        for (i = 0; i < ioData->mNumberBuffers; i++) {
++            abuf = &ioData->mBuffers[i];
++            SDL_memset(abuf->mData, this->spec.silence, abuf->mDataByteSize);
++        }
+         return 0;
+     }
+     
+@@ -114,29 +122,32 @@
+     assert(!this->convert.needed);
+     assert(this->spec.channels == ioData->mNumberChannels);
+      */
+-    
+-    remaining = ioData->mDataByteSize;
+-    ptr = ioData->mData;
+-    while (remaining > 0) {
+-        if (bufferOffset >= bufferSize) {
+-            /* Generate the data */
+-            SDL_memset(buffer, this->spec.silence, bufferSize);
+-            SDL_mutexP(this->mixer_lock);
+-            (*this->spec.callback)(this->spec.userdata,
+-                        buffer, bufferSize);
+-            SDL_mutexV(this->mixer_lock);
+-            bufferOffset = 0;
+-        }
++
++    for (i = 0; i < ioData->mNumberBuffers; i++) {
++        abuf = &ioData->mBuffers[i];
++        remaining = abuf->mDataByteSize;
++        ptr = abuf->mData;
++        while (remaining > 0) {
++            if (bufferOffset >= bufferSize) {
++                /* Generate the data */
++                SDL_memset(buffer, this->spec.silence, bufferSize);
++                SDL_mutexP(this->mixer_lock);
++                (*this->spec.callback)(this->spec.userdata,
++                            buffer, bufferSize);
++                SDL_mutexV(this->mixer_lock);
++                bufferOffset = 0;
++            }
+         
+-        len = bufferSize - bufferOffset;
+-        if (len > remaining)
+-            len = remaining;
+-        SDL_memcpy(ptr, (char *)buffer + bufferOffset, len);
+-        ptr = (char *)ptr + len;
+-        remaining -= len;
+-        bufferOffset += len;
++            len = bufferSize - bufferOffset;
++            if (len > remaining)
++                len = remaining;
++            SDL_memcpy(ptr, (char *)buffer + bufferOffset, len);
++            ptr = (char *)ptr + len;
++            remaining -= len;
++            bufferOffset += len;
++        }
+     }
+-    
++
+     return 0;
+ }
+ 
+@@ -159,7 +170,7 @@
+ void Core_CloseAudio(_THIS)
+ {
+     OSStatus result;
+-    struct AudioUnitInputCallback callback;
++    struct AURenderCallbackStruct callback;
+ 
+     /* stop processing the audio unit */
+     result = AudioOutputUnitStop (outputAudioUnit);
+@@ -172,7 +183,7 @@
+     callback.inputProc = 0;
+     callback.inputProcRefCon = 0;
+     result = AudioUnitSetProperty (outputAudioUnit, 
+-                        kAudioUnitProperty_SetInputCallback, 
++                        kAudioUnitProperty_SetRenderCallback,
+                         kAudioUnitScope_Input, 
+                         0,
+                         &callback, 
+@@ -203,7 +214,7 @@
+     OSStatus result = noErr;
+     Component comp;
+     ComponentDescription desc;
+-    struct AudioUnitInputCallback callback;
++    struct AURenderCallbackStruct callback;
+     AudioStreamBasicDescription requestedDesc;
+ 
+     /* Setup a AudioStreamBasicDescription with the requested format */
+@@ -224,9 +235,9 @@
+ 
+ 
+     /* Locate the default output audio unit */
+-    desc.componentType = kAudioUnitComponentType;
+-    desc.componentSubType = kAudioUnitSubType_Output;
+-    desc.componentManufacturer = kAudioUnitID_DefaultOutput;
++    desc.componentType = kAudioUnitType_Output;
++    desc.componentSubType = kAudioUnitSubType_DefaultOutput;
++    desc.componentManufacturer = kAudioUnitManufacturer_Apple;
+     desc.componentFlags = 0;
+     desc.componentFlagsMask = 0;
+     
+@@ -256,7 +267,7 @@
+     callback.inputProc = audioCallback;
+     callback.inputProcRefCon = this;
+     result = AudioUnitSetProperty (outputAudioUnit, 
+-                        kAudioUnitProperty_SetInputCallback, 
++                        kAudioUnitProperty_SetRenderCallback,
+                         kAudioUnitScope_Input, 
+                         0,
+                         &callback, 
+diff -ur src/cdrom/macosx/AudioFilePlayer.c src/cdrom/macosx/AudioFilePlayer.c
+--- src/cdrom/macosx/AudioFilePlayer.c	2007-12-30 22:48:00.000000000 -0600
++++ src/cdrom/macosx/AudioFilePlayer.c	2009-09-15 16:45:29.000000000 -0500
+@@ -1,6 +1,6 @@
+ /*
+     SDL - Simple DirectMedia Layer
+-    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
++    Copyright (C) 1997-2009 Sam Lantinga
+ 
+     This library is free software; you can redistribute it and/or
+     modify it under the terms of the GNU Library General Public
+@@ -23,6 +23,7 @@
+     so if you want to see the original search for it on apple.com/developer
+ */
+ #include "SDL_config.h"
++#include "SDL_endian.h"
+ 
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+     AudioFilePlayer.cpp
+@@ -78,7 +79,7 @@
+         /* we're going to use this to know which convert routine to call
+            a v1 audio unit will have a type of 'aunt'
+            a v2 audio unit will have one of several different types. */
+-    if (desc.componentType != kAudioUnitComponentType) {
++    if (desc.componentType != kAudioUnitType_Output) {
+         result = badComponentInstance;
+         /*THROW_RESULT("BAD COMPONENT")*/
+         if (result) return 0;
+@@ -175,7 +176,7 @@
+         afp->mInputCallback.inputProcRefCon = afp->mAudioFileManager;
+ 
+         OSStatus result = AudioUnitSetProperty (afp->mPlayUnit, 
+-                            kAudioUnitProperty_SetInputCallback, 
++                            kAudioUnitProperty_SetRenderCallback,
+                             kAudioUnitScope_Input, 
+                             0,
+                             &afp->mInputCallback, 
+@@ -215,7 +216,7 @@
+         afp->mInputCallback.inputProc = 0;
+         afp->mInputCallback.inputProcRefCon = 0;
+         OSStatus result = AudioUnitSetProperty (afp->mPlayUnit, 
+-                                        kAudioUnitProperty_SetInputCallback, 
++                                        kAudioUnitProperty_SetRenderCallback,
+                                         kAudioUnitScope_Input, 
+                                         0,
+                                         &afp->mInputCallback, 
+@@ -254,12 +255,12 @@
+     result = FSReadFork(afp->mForkRefNum, fsAtMark, 0, sizeof(chunkHeader), &chunkHeader, &actual);
+        if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork")*/
+ 
+-    if (chunkHeader.ckID != 'FORM') {
++    if (SDL_SwapBE32(chunkHeader.ckID) != 'FORM') {
+         result = -1;
+         if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): chunk id is not 'FORM'");*/
+     }
+ 
+-    if (chunkHeader.formType != 'AIFC') {
++    if (SDL_SwapBE32(chunkHeader.formType) != 'AIFC') {
+         result = -1;
+         if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): file format is not 'AIFC'");*/
+     }
+@@ -272,8 +273,11 @@
+     offset = 0;
+     do {
+         result = FSReadFork(afp->mForkRefNum, fsFromMark, offset, sizeof(chunk), &chunk, &actual);
+-           if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork")*/
+-            
++        if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork")*/
++
++        chunk.ckID = SDL_SwapBE32(chunk.ckID);
++        chunk.ckSize = SDL_SwapBE32(chunk.ckSize);
++
+         /* Skip the chunk data */
+         offset = chunk.ckSize;
+     } while (chunk.ckID != 'SSND');
+@@ -281,10 +285,12 @@
+     /* Read the header of the SSND chunk. After this, we are positioned right
+        at the start of the audio data. */
+     result = FSReadFork(afp->mForkRefNum, fsAtMark, 0, sizeof(ssndData), &ssndData, &actual);
+-       if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork")*/
++    if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork")*/
++
++    ssndData.offset = SDL_SwapBE32(ssndData.offset);
+ 
+     result = FSSetForkPosition(afp->mForkRefNum, fsFromMark, ssndData.offset);
+-       if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSSetForkPosition")*/
++    if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSSetForkPosition")*/
+ 
+     /* Data size */
+     *outFileDataSize = chunk.ckSize - ssndData.offset - 8;
+diff -ur src/cdrom/macosx/AudioFilePlayer.h src/cdrom/macosx/AudioFilePlayer.h
+--- src/cdrom/macosx/AudioFilePlayer.h	2007-12-30 22:48:00.000000000 -0600
++++ src/cdrom/macosx/AudioFilePlayer.h	2009-09-15 16:45:29.000000000 -0500
+@@ -1,6 +1,6 @@
+ /*
+     SDL - Simple DirectMedia Layer
+-    Copyright (C) 1997-2004 Sam Lantinga
++    Copyright (C) 1997-2009 Sam Lantinga
+ 
+     This library is free software; you can redistribute it and/or
+     modify it under the terms of the GNU Library General Public
+@@ -33,7 +33,7 @@
+ #include <CoreServices/CoreServices.h>
+ 
+ #include <AudioUnit/AudioUnit.h>
+-#ifdef AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER
++#if MAC_OS_X_VERSION_MAX_ALLOWED <= 1050
+ #include <AudioUnit/AUNTComponent.h>
+ #endif
+ 
+@@ -82,7 +82,7 @@
+     AudioUnit                       mPlayUnit;
+     SInt16                          mForkRefNum;
+     
+-    AudioUnitInputCallback          mInputCallback;
++    AURenderCallbackStruct          mInputCallback;
+ 
+     AudioStreamBasicDescription     mFileDescription;
+     
+@@ -114,7 +114,7 @@
+            as it is called by the parent's Disconnect() method */
+     void                (*Disconnect)(struct S_AudioFileManager *afm);
+     int                 (*DoConnect)(struct S_AudioFileManager *afm);
+-    OSStatus            (*Read)(struct S_AudioFileManager *afm, char *buffer, UInt32 *len);
++    OSStatus            (*Read)(struct S_AudioFileManager *afm, char *buffer, ByteCount *len);
+     const char*         (*GetFileBuffer)(struct S_AudioFileManager *afm);
+     const AudioFilePlayer *(*GetParent)(struct S_AudioFileManager *afm);
+     void                (*SetPosition)(struct S_AudioFileManager *afm, SInt64 pos);  /* seek/rewind in the file */
+@@ -148,17 +148,18 @@
+     int                 mFinishedReadingData;
+ 
+ /*protected:*/
+-    OSStatus            (*Render)(struct S_AudioFileManager *afm, AudioBuffer *ioData);
++    OSStatus            (*Render)(struct S_AudioFileManager *afm, AudioBufferList *ioData);
+     OSStatus            (*GetFileData)(struct S_AudioFileManager *afm, void** inOutData, UInt32 *inOutDataSize);
+     void                (*AfterRender)(struct S_AudioFileManager *afm);
+ 
+ /*public:*/
+     /*static*/
+-    OSStatus            (*FileInputProc)(void                             *inRefCon,
+-                                         AudioUnitRenderActionFlags      inActionFlags,
++    OSStatus            (*FileInputProc)(void                            *inRefCon,
++                                         AudioUnitRenderActionFlags      *ioActionFlags,
+                                          const AudioTimeStamp            *inTimeStamp,
+                                          UInt32                          inBusNumber,
+-                                         AudioBuffer                     *ioData);
++                                         UInt32                          inNumberFrames,
++                                         AudioBufferList                 *ioData);
+ } AudioFileManager;
+ 
+ 
+diff -ur src/cdrom/macosx/AudioFileReaderThread.c src/cdrom/macosx/AudioFileReaderThread.c
+--- src/cdrom/macosx/AudioFileReaderThread.c	2007-12-30 22:48:00.000000000 -0600
++++ src/cdrom/macosx/AudioFileReaderThread.c	2009-09-15 16:45:29.000000000 -0500
+@@ -1,6 +1,6 @@
+ /*
+     SDL - Simple DirectMedia Layer
+-    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
++    Copyright (C) 1997-2009 Sam Lantinga
+ 
+     This library is free software; you can redistribute it and/or
+     modify it under the terms of the GNU Library General Public
+@@ -245,7 +245,7 @@
+ static void    FileReaderThread_ReadNextChunk (FileReaderThread *frt)
+ {
+     OSStatus result;
+-    UInt32  dataChunkSize;
++    ByteCount dataChunkSize;
+     AudioFileManager* theItem = 0;
+ 
+     for (;;) 
+@@ -380,7 +380,7 @@
+         afm->mNumTimesAskedSinceFinished = 0;
+         afm->mLockUnsuccessful = 0;
+         
+-        UInt32 dataChunkSize;
++        ByteCount dataChunkSize;
+         
+         if ((afm->mFileLength - afm->mReadFilePosition) < afm->mChunkSize)
+             dataChunkSize = afm->mFileLength - afm->mReadFilePosition;
+@@ -415,7 +415,7 @@
+     }
+ }
+ 
+-static OSStatus AudioFileManager_Read(AudioFileManager *afm, char *buffer, UInt32 *len)
++static OSStatus AudioFileManager_Read(AudioFileManager *afm, char *buffer, ByteCount *len)
+ {
+     return FSReadFork (afm->mForkRefNum,
+                        fsFromStart,
+@@ -508,39 +508,44 @@
+     return afm->mByteCounter;
+ }
+ 
+-
+-static OSStatus    AudioFileManager_FileInputProc (void                       *inRefCon,
+-                                             AudioUnitRenderActionFlags inActionFlags,
+-                                             const AudioTimeStamp       *inTimeStamp, 
+-                                             UInt32                     inBusNumber, 
+-                                             AudioBuffer                *ioData)
++static OSStatus    AudioFileManager_FileInputProc (void                  *inRefCon,
++                                         AudioUnitRenderActionFlags      *ioActionFlags,
++                                         const AudioTimeStamp            *inTimeStamp,
++                                         UInt32                          inBusNumber,
++                                         UInt32                          inNumberFrames,
++                                         AudioBufferList                 *ioData)
+ {
+     AudioFileManager* afm = (AudioFileManager*)inRefCon;
+     return afm->Render(afm, ioData);
+ }
+ 
+-static OSStatus    AudioFileManager_Render (AudioFileManager *afm, AudioBuffer *ioData)
++static OSStatus    AudioFileManager_Render (AudioFileManager *afm, AudioBufferList *ioData)
+ {
+     OSStatus result = noErr;
++    AudioBuffer *abuf;
++    UInt32 i;
++
++    for (i = 0; i < ioData->mNumberBuffers; i++) {
++        abuf = &ioData->mBuffers[i];
++        if (afm->mBufferOffset >= afm->mBufferSize) {
++            result = afm->GetFileData(afm, &afm->mTmpBuffer, &afm->mBufferSize);
++            if (result) {
++                SDL_SetError ("AudioConverterFillBuffer:%ld\n", result);
++                afm->mParent->DoNotification(afm->mParent, result);
++                return result;
++            }
++
++            afm->mBufferOffset = 0;
++        }
++
++        if (abuf->mDataByteSize > afm->mBufferSize - afm->mBufferOffset)
++            abuf->mDataByteSize = afm->mBufferSize - afm->mBufferOffset;
++        abuf->mData = (char *)afm->mTmpBuffer + afm->mBufferOffset;
++        afm->mBufferOffset += abuf->mDataByteSize;
+     
+-	if (afm->mBufferOffset >= afm->mBufferSize) {
+-		result = afm->GetFileData(afm, &afm->mTmpBuffer, &afm->mBufferSize);
+-		if (result) {
+-			SDL_SetError ("AudioConverterFillBuffer:%ld\n", result);
+-			afm->mParent->DoNotification(afm->mParent, result);
+-			return result;
+-		}
+-
+-		afm->mBufferOffset = 0;
+-	}
+-    	
+-    if (ioData->mDataByteSize > afm->mBufferSize - afm->mBufferOffset)
+-    	ioData->mDataByteSize = afm->mBufferSize - afm->mBufferOffset;
+-    ioData->mData = (char *)afm->mTmpBuffer + afm->mBufferOffset;
+-    afm->mBufferOffset += ioData->mDataByteSize;
+-    
+-	afm->mByteCounter += ioData->mDataByteSize;
+-	afm->AfterRender(afm);
++        afm->mByteCounter += abuf->mDataByteSize;
++        afm->AfterRender(afm);
++    }
+     return result;
+ }
+ 
+diff -ur src/cdrom/macosx/CDPlayer.c src/cdrom/macosx/CDPlayer.c
+--- src/cdrom/macosx/CDPlayer.c	2007-12-30 22:48:00.000000000 -0600
++++ src/cdrom/macosx/CDPlayer.c	2009-09-18 07:04:01.000000000 -0500
+@@ -1,6 +1,6 @@
+ /*
+     SDL - Simple DirectMedia Layer
+-    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
++    Copyright (C) 1997-2009 Sam Lantinga
+ 
+     This library is free software; you can redistribute it and/or
+     modify it under the terms of the GNU Library General Public
+@@ -134,28 +134,37 @@
+ {
+     HFSUniStr255      dataForkName;
+     OSStatus          theErr;
+-    SInt16            forkRefNum;
++    FSIORefNum        forkRefNum;
+     SInt64            forkSize;
+     Ptr               forkData = 0;
+     ByteCount         actualRead;
+     CFDataRef         dataRef = 0;
+     CFPropertyListRef propertyListRef = 0;
+-
++    int               i;
+     FSRefParam      fsRefPB;
+     FSRef           tocPlistFSRef;
+-    
++    FSRef           rootRef;
+     const char* error = "Unspecified Error";
+-    
++    const UniChar uniName[] = { '.','T','O','C','.','p','l','i','s','t' };
++
++    theErr = FSGetVolumeInfo(theVolume, 0, 0, kFSVolInfoNone, 0, 0, &rootRef);
++    if(theErr != noErr) {
++        error = "FSGetVolumeInfo";
++        goto bail;
++    }
++
++    SDL_memset(&fsRefPB, '\0', sizeof (fsRefPB));
++
+     /* get stuff from .TOC.plist */
+-    fsRefPB.ioCompletion = NULL;
+-    fsRefPB.ioNamePtr = "\p.TOC.plist";
+-    fsRefPB.ioVRefNum = theVolume;
+-    fsRefPB.ioDirID = 0;
++    fsRefPB.ref = &rootRef;
+     fsRefPB.newRef = &tocPlistFSRef;
+-    
+-    theErr = PBMakeFSRefSync (&fsRefPB);
++    fsRefPB.nameLength = sizeof (uniName) / sizeof (uniName[0]);
++    fsRefPB.name = uniName;
++    fsRefPB.textEncodingHint = kTextEncodingUnknown;
++
++    theErr = PBMakeFSRefUnicodeSync (&fsRefPB);
+     if(theErr != noErr) {
+-        error = "PBMakeFSRefSync";
++        error = "PBMakeFSRefUnicodeSync";
+         goto bail;
+     }
+     
+@@ -551,9 +560,9 @@
+     { /*try {*/
+         ComponentDescription desc;
+     
+-        desc.componentType = kAudioUnitComponentType;
+-        desc.componentSubType = kAudioUnitSubType_Output;
+-        desc.componentManufacturer = kAudioUnitID_DefaultOutput;
++        desc.componentType = kAudioUnitType_Output;
++        desc.componentSubType = kAudioUnitSubType_DefaultOutput;
++        desc.componentManufacturer = kAudioUnitManufacturer_Apple;
+         desc.componentFlags = 0;
+         desc.componentFlagsMask = 0;
+         
+diff -ur src/cdrom/macosx/CDPlayer.h src/cdrom/macosx/CDPlayer.h
+--- src/cdrom/macosx/CDPlayer.h	2009-09-19 09:17:23.000000000 -0500
++++ src/cdrom/macosx/CDPlayer.h	2009-09-18 07:01:02.000000000 -0500
+@@ -1,6 +1,6 @@
+ /*
+     SDL - Simple DirectMedia Layer
+-    Copyright (C) 1997-2004 Sam Lantinga
++    Copyright (C) 1997-2009 Sam Lantinga
+ 
+     This library is free software; you can redistribute it and/or
+     modify it under the terms of the GNU Library General Public
+diff -ur src/cdrom/macosx/SDLOSXCAGuard.c src/cdrom/macosx/SDLOSXCAGuard.c
+--- src/cdrom/macosx/SDLOSXCAGuard.c	2007-12-30 22:48:00.000000000 -0600
++++ src/cdrom/macosx/SDLOSXCAGuard.c	2009-09-15 16:45:29.000000000 -0500
+@@ -1,6 +1,6 @@
+ /*
+     SDL - Simple DirectMedia Layer
+-    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
++    Copyright (C) 1997-2009 Sam Lantinga
+ 
+     This library is free software; you can redistribute it and/or
+     modify it under the terms of the GNU Library General Public
+diff -ur src/cdrom/macosx/SDLOSXCAGuard.h src/cdrom/macosx/SDLOSXCAGuard.h
+--- src/cdrom/macosx/SDLOSXCAGuard.h	2007-12-30 22:48:00.000000000 -0600
++++ src/cdrom/macosx/SDLOSXCAGuard.h	2009-09-15 16:45:29.000000000 -0500
+@@ -1,6 +1,6 @@
+ /*
+     SDL - Simple DirectMedia Layer
+-    Copyright (C) 1997-2004 Sam Lantinga
++    Copyright (C) 1997-2009 Sam Lantinga
+ 
+     This library is free software; you can redistribute it and/or
+     modify it under the terms of the GNU Library General Public
+diff -ur src/cdrom/macosx/SDL_syscdrom.c src/cdrom/macosx/SDL_syscdrom.c
+--- src/cdrom/macosx/SDL_syscdrom.c	2007-12-30 22:48:00.000000000 -0600
++++ src/cdrom/macosx/SDL_syscdrom.c	2009-09-18 07:04:20.000000000 -0500
+@@ -1,6 +1,6 @@
+ /*
+     SDL - Simple DirectMedia Layer
+-    Copyright (C) 1997-2006 Sam Lantinga
++    Copyright (C) 1997-2009 Sam Lantinga
+ 
+     This library is free software; you can redistribute it and/or
+     modify it under the terms of the GNU Lesser General Public
+@@ -263,6 +263,14 @@
+ /* Get the Unix disk name of the volume */
+ static const char *SDL_SYS_CDName (int drive)
+ {
++    /*
++     * !!! FIXME: PBHGetVolParmsSync() is gone in 10.6,
++     * !!! FIXME:  replaced with FSGetVolumeParms(), which
++     * !!! FIXME:  isn't available before 10.5.  :/
++     */
++    return "Mac OS X CD-ROM Device";
++
++#if 0
+     OSStatus     err = noErr;
+     HParamBlockRec  pb;
+     GetVolParmsInfoBuffer   volParmsInfo;
+@@ -282,6 +290,7 @@
+     }
+ 
+     return volParmsInfo.vMDeviceID;
++#endif
+ }
+ 
+ /* Open the "device" */
+diff -ur src/cdrom/macosx/SDL_syscdrom_c.h src/cdrom/macosx/SDL_syscdrom_c.h
+--- src/cdrom/macosx/SDL_syscdrom_c.h	2007-12-30 22:48:00.000000000 -0600
++++ src/cdrom/macosx/SDL_syscdrom_c.h	2009-09-15 16:45:29.000000000 -0500
+@@ -1,6 +1,6 @@
+ /*
+     SDL - Simple DirectMedia Layer
+-    Copyright (C) 1997-2004 Sam Lantinga
++    Copyright (C) 1997-2009 Sam Lantinga
+ 
+     This library is free software; you can redistribute it and/or
+     modify it under the terms of the GNU Library General Public

