some changes to the dummy driver for debug purposes that should be reverted. gsoc2008_nds
authorDarren Alton <dalton@stevens.edu>
Thu, 12 Jun 2008 02:38:49 +0000
branchgsoc2008_nds
changeset 2671c3e7c0698cbb
parent 2670 6e4669f4db49
child 2672 74ac057679d5
some changes to the dummy driver for debug purposes that should be reverted.
most importantly, commenting out a check for an env. var.
include/SDL_config_nintendods.h
include/SDL_stdinc.h
src/joystick/nds/SDL_sysjoystick.c
src/thread/nds/SDL_syscond.c
src/thread/nds/SDL_syscond_c.h
src/thread/nds/SDL_sysmutex.c
src/thread/nds/SDL_sysmutex_c.h
src/thread/nds/SDL_syssem.c
src/thread/nds/SDL_syssem_c.h
src/thread/nds/SDL_systhread.c
src/video/dummy/SDL_nullrender.c
src/video/dummy/SDL_nullvideo.c
src/video/nds/SDL_ndsrender.c
src/video/nds/SDL_ndsvideo.c
     1.1 --- a/include/SDL_config_nintendods.h	Tue Jun 10 06:57:57 2008 +0000
     1.2 +++ b/include/SDL_config_nintendods.h	Thu Jun 12 02:38:49 2008 +0000
     1.3 @@ -111,7 +111,6 @@
     1.4  #define SDL_TIMERS_DISABLED	1
     1.5  
     1.6  /* Enable various video drivers */
     1.7 -#define SDL_VIDEO_DRIVER_NDS	1
     1.8 +#define SDL_VIDEO_DRIVER_DUMMY	1
     1.9  
    1.10  #endif /* _SDL_config_nintendods_h */
    1.11 -
     2.1 --- a/include/SDL_stdinc.h	Tue Jun 10 06:57:57 2008 +0000
     2.2 +++ b/include/SDL_stdinc.h	Thu Jun 12 02:38:49 2008 +0000
     2.3 @@ -147,9 +147,9 @@
     2.4  SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
     2.5  SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
     2.6  SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
     2.7 -#ifndef __NINTENDODS__ /* TODO: figure out why the following happens:
     2.8 -include/SDL_stdinc.h:150: error: size of array 'SDL_dummy_uint64' is negative
     2.9 -include/SDL_stdinc.h:151: error: size of array 'SDL_dummy_sint64' is negative */
    2.10 +#ifndef __NINTENDODS__          /* TODO: figure out why the following happens:
    2.11 +                                   include/SDL_stdinc.h:150: error: size of array 'SDL_dummy_uint64' is negative
    2.12 +                                   include/SDL_stdinc.h:151: error: size of array 'SDL_dummy_sint64' is negative */
    2.13  SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
    2.14  SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
    2.15  #endif
    2.16 @@ -166,7 +166,7 @@
    2.17  #endif
    2.18  
    2.19  #ifndef DOXYGEN_SHOULD_IGNORE_THIS
    2.20 -#ifndef __NINTENDODS__  /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */
    2.21 +#ifndef __NINTENDODS__          /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */
    2.22  typedef enum
    2.23  {
    2.24      DUMMY_ENUM_VALUE
    2.25 @@ -432,7 +432,7 @@
    2.26  #define SDL_wcslen      wcslen
    2.27  #else
    2.28  #if !defined(wchar_t) && defined(__NINTENDODS__)
    2.29 -#define wchar_t short /* TODO: figure out why libnds doesn't have this */
    2.30 +#define wchar_t short           /* TODO: figure out why libnds doesn't have this */
    2.31  #endif
    2.32  extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t * string);
    2.33  #endif
     3.1 --- a/src/joystick/nds/SDL_sysjoystick.c	Tue Jun 10 06:57:57 2008 +0000
     3.2 +++ b/src/joystick/nds/SDL_sysjoystick.c	Thu Jun 12 02:38:49 2008 +0000
     3.3 @@ -22,13 +22,13 @@
     3.4  
     3.5  #ifdef SAVE_RCSID
     3.6  static char rcsid =
     3.7 - "@(#) $Id: SDL_sysjoystick.c,v 1.2 2001/04/26 16:50:17 hercules Exp $";
     3.8 +    "@(#) $Id: SDL_sysjoystick.c,v 1.2 2001/04/26 16:50:17 hercules Exp $";
     3.9  #endif
    3.10  
    3.11  /* This is the system specific header for the SDL joystick API */
    3.12  #include <nds.h>
    3.13  //#include <nds/registers_alt.h>
    3.14 -#include <stdio.h>		/* For the definition of NULL */
    3.15 +#include <stdio.h>              /* For the definition of NULL */
    3.16  
    3.17  #include "SDL_error.h"
    3.18  #include "SDL_joystick.h"
    3.19 @@ -42,21 +42,23 @@
    3.20   * joysticks.  Joystick 0 should be the system default joystick.
    3.21   * It should return 0, or -1 on an unrecoverable fatal error.
    3.22   */
    3.23 -int SDL_SYS_JoystickInit(void)
    3.24 +int
    3.25 +SDL_SYS_JoystickInit(void)
    3.26  {
    3.27 -	SDL_numjoysticks = 1;
    3.28 -    //keysInit();
    3.29 -
    3.30 -	return(1);
    3.31 +    SDL_numjoysticks = 1;
    3.32 +    
    3.33 +        //keysInit();
    3.34 +        return (1);
    3.35  }
    3.36  
    3.37  /* Function to get the device-dependent name of a joystick */
    3.38 -const char *SDL_SYS_JoystickName(int index)
    3.39 +const char *
    3.40 +SDL_SYS_JoystickName(int index)
    3.41  {
    3.42 -	if(!index)
    3.43 -		return "NDS builtin joypad";
    3.44 -	SDL_SetError("No joystick available with that index");
    3.45 -	return (NULL);
    3.46 +    if (!index)
    3.47 +        return "NDS builtin joypad";
    3.48 +    SDL_SetError("No joystick available with that index");
    3.49 +    return (NULL);
    3.50  }
    3.51  
    3.52  /* Function to open a joystick for use.
    3.53 @@ -64,91 +66,175 @@
    3.54     This should fill the nbuttons and naxes fields of the joystick structure.
    3.55     It returns 0, or -1 if there is an error.
    3.56   */
    3.57 -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
    3.58 +int
    3.59 +SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
    3.60  {
    3.61 -	joystick->nbuttons=8;
    3.62 -	joystick->nhats=0;
    3.63 -	joystick->nballs=0;
    3.64 -	joystick->naxes=2;
    3.65 -	return 0;
    3.66 +    joystick->nbuttons = 8;
    3.67 +    joystick->nhats = 0;
    3.68 +    joystick->nballs = 0;
    3.69 +    joystick->naxes = 2;
    3.70 +    return 0;
    3.71  }
    3.72 +
    3.73  
    3.74 -
    3.75  /* Function to update the state of a joystick - called as a device poll.
    3.76   * This function shouldn't update the joystick structure directly,
    3.77   * but instead should call SDL_PrivateJoystick*() to deliver events
    3.78   * and update joystick device state.
    3.79   */
    3.80 +int prevbutton = 0;
    3.81 +int prevkey = 0;
    3.82  
    3.83 -int prevbutton=0;
    3.84 -int prevkey=0;
    3.85 -
    3.86 -int dc=NULL;int ldc=0;
    3.87 -u32 keysd,keysu=NULL;
    3.88 -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
    3.89 -{
    3.90 -    //dc=keysd;
    3.91 -	//if (dc != NULL)
    3.92 -	//{
    3.93 -		//fprintf(stderr,"heartbeat= %d\n",REG_VCOUNT); 
    3.94 -		//swiWaitForVBlank();
    3.95 -		//scanKeys();
    3.96 -		//keysd = keysDown(); 
    3.97 -		//keysu = keysUp();
    3.98 -		//ldc=keysd;
    3.99 -		 
   3.100 -	//}
   3.101 -	/*if (prevkey !=NULL && prevbutton !=NULL)
   3.102 -	{
   3.103 -		scanKeys();
   3.104 -	}
   3.105 -	*/
   3.106 -	
   3.107 -	//scanKeys();
   3.108 -		keysd = keysDown(); 
   3.109 -		keysu = keysUp();
   3.110 -		
   3.111 -	
   3.112 -	short ax=0,v=0,h=0;
   3.113 -	if((keysd&KEY_UP)) {ax=1;v=-10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_UP;}//fprintf(stderr,"KEY_UP\n");}
   3.114 -	if((keysd&KEY_DOWN)) {ax=1;v=10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_DOWN;}//fprintf(stderr,"KEY_DOWN\n");}
   3.115 -	if((keysd&KEY_LEFT)) {ax=0;h=-10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_LEFT;}//fprintf(stderr,"KEY_LEFT\n");}
   3.116 -	if((keysd&KEY_RIGHT)) {ax=0;h=10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_RIGHT;}//fprintf(stderr,"KEY_RIGHT\n");}
   3.117 -
   3.118 -	if((keysu&KEY_UP)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=NULL;}//fprintf(stderr,"KEY_UP\n");}
   3.119 -	if((keysu&KEY_DOWN)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=NULL;}//fprintf(stderr,"KEY_DOWN\n");}
   3.120 -	if((keysu&KEY_LEFT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=NULL;}//fprintf(stderr,"KEY_LEFT\n");}
   3.121 -	if((keysu&KEY_RIGHT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=NULL;}//fprintf(stderr,"KEY_RIGHT\n");}
   3.122 -
   3.123 -	if((keysd&KEY_A))		{SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);prevbutton=KEY_A;}
   3.124 -	if((keysd&KEY_B))		{SDL_PrivateJoystickButton(joystick,1,SDL_PRESSED);prevbutton=KEY_B;}
   3.125 -	if((keysd&KEY_X))		{SDL_PrivateJoystickButton(joystick,2,SDL_PRESSED);prevbutton=KEY_X;}
   3.126 -	if((keysd&KEY_Y))		{SDL_PrivateJoystickButton(joystick,3,SDL_PRESSED);prevbutton=KEY_Y;}
   3.127 -	if((keysd&KEY_SELECT))	{SDL_PrivateJoystickButton(joystick,6,SDL_PRESSED);prevbutton=KEY_SELECT;}
   3.128 -	if((keysd&KEY_START))	{SDL_PrivateJoystickButton(joystick,7,SDL_PRESSED);prevbutton=KEY_START;}
   3.129 -	if((keysd&KEY_L))		{SDL_PrivateJoystickButton(joystick,4,SDL_PRESSED);prevbutton=KEY_L;}
   3.130 -	if((keysd&KEY_R))		{SDL_PrivateJoystickButton(joystick,5,SDL_PRESSED);prevbutton=KEY_R;}
   3.131 -
   3.132 -	if((keysu&KEY_A))		{SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);prevbutton=NULL;}
   3.133 -	if((keysu&KEY_B))		{SDL_PrivateJoystickButton(joystick,1,SDL_RELEASED);prevbutton=NULL;}
   3.134 -	if((keysu&KEY_X))		{SDL_PrivateJoystickButton(joystick,2,SDL_RELEASED);prevbutton=NULL;}
   3.135 -	if((keysu&KEY_Y))		{SDL_PrivateJoystickButton(joystick,3,SDL_RELEASED);prevbutton=NULL;}
   3.136 -	if((keysu&KEY_SELECT))  {SDL_PrivateJoystickButton(joystick,6,SDL_RELEASED);prevbutton=NULL;}
   3.137 -	if((keysu&KEY_START))	{SDL_PrivateJoystickButton(joystick,7,SDL_RELEASED);prevbutton=NULL;}
   3.138 -	if((keysu&KEY_L))		{SDL_PrivateJoystickButton(joystick,4,SDL_RELEASED);prevbutton=NULL;}
   3.139 -	if((keysu&KEY_R))		{SDL_PrivateJoystickButton(joystick,5,SDL_RELEASED);prevbutton=NULL;}
   3.140 -
   3.141 -
   3.142 -
   3.143 -}
   3.144 +int dc = NULL;
   3.145 +int ldc = 0;
   3.146 +u32 keysd, keysu = NULL;
   3.147 +void
   3.148 +SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
   3.149 +{
   3.150 +    
   3.151 +        //dc=keysd;
   3.152 +        //if (dc != NULL)
   3.153 +        //{
   3.154 +        //fprintf(stderr,"heartbeat= %d\n",REG_VCOUNT); 
   3.155 +        //swiWaitForVBlank();
   3.156 +        //scanKeys();
   3.157 +        //keysd = keysDown(); 
   3.158 +        //keysu = keysUp();
   3.159 +        //ldc=keysd;
   3.160 +        
   3.161 +        //}
   3.162 +        /*if (prevkey !=NULL && prevbutton !=NULL)
   3.163 +           {
   3.164 +           scanKeys();
   3.165 +           }
   3.166 +         */ 
   3.167 +        
   3.168 +        //scanKeys();
   3.169 +        keysd = keysDown();
   3.170 +    
   3.171 keysu = keysUp();
   3.172 +    
   3.173 
   3.174 short ax = 0, v = 0, h = 0;
   3.175 +    if ((keysd & KEY_UP)) {
   3.176 +        ax = 1;
   3.177 +        v = -10;
   3.178 +        SDL_PrivateJoystickAxis(joystick, ax, v);
   3.179 +        prevkey = KEY_UP;
   3.180 +    }                           //fprintf(stderr,"KEY_UP\n");}
   3.181 +    if ((keysd & KEY_DOWN)) {
   3.182 +        ax = 1;
   3.183 +        v = 10;
   3.184 +        SDL_PrivateJoystickAxis(joystick, ax, v);
   3.185 +        prevkey = KEY_DOWN;
   3.186 +    }                           //fprintf(stderr,"KEY_DOWN\n");}
   3.187 +    if ((keysd & KEY_LEFT)) {
   3.188 +        ax = 0;
   3.189 +        h = -10;
   3.190 +        SDL_PrivateJoystickAxis(joystick, ax, h);
   3.191 +        prevkey = KEY_LEFT;
   3.192 +    }                           //fprintf(stderr,"KEY_LEFT\n");}
   3.193 +    if ((keysd & KEY_RIGHT)) {
   3.194 +        ax = 0;
   3.195 +        h = 10;
   3.196 +        SDL_PrivateJoystickAxis(joystick, ax, h);
   3.197 +        prevkey = KEY_RIGHT;
   3.198 +    }                           //fprintf(stderr,"KEY_RIGHT\n");}
   3.199 +    
   3.200 if ((keysu & KEY_UP)) {
   3.201 +        ax = 1;
   3.202 +        v = 0;
   3.203 +        SDL_PrivateJoystickAxis(joystick, ax, v);
   3.204 +        prevkey = NULL;
   3.205 +    }                           //fprintf(stderr,"KEY_UP\n");}
   3.206 +    if ((keysu & KEY_DOWN)) {
   3.207 +        ax = 1;
   3.208 +        v = 0;
   3.209 +        SDL_PrivateJoystickAxis(joystick, ax, v);
   3.210 +        prevkey = NULL;
   3.211 +    }                           //fprintf(stderr,"KEY_DOWN\n");}
   3.212 +    if ((keysu & KEY_LEFT)) {
   3.213 +        ax = 0;
   3.214 +        h = 0;
   3.215 +        SDL_PrivateJoystickAxis(joystick, ax, h);
   3.216 +        prevkey = NULL;
   3.217 +    }                           //fprintf(stderr,"KEY_LEFT\n");}
   3.218 +    if ((keysu & KEY_RIGHT)) {
   3.219 +        ax = 0;
   3.220 +        h = 0;
   3.221 +        SDL_PrivateJoystickAxis(joystick, ax, h);
   3.222 +        prevkey = NULL;
   3.223 +    }                           //fprintf(stderr,"KEY_RIGHT\n");}
   3.224 +    
   3.225 if ((keysd & KEY_A)) {
   3.226 +        SDL_PrivateJoystickButton(joystick, 0, SDL_PRESSED);
   3.227 +        prevbutton = KEY_A;
   3.228 +    }
   3.229 +    
   3.230 if ((keysd & KEY_B)) {
   3.231 +        SDL_PrivateJoystickButton(joystick, 1, SDL_PRESSED);
   3.232 +        prevbutton = KEY_B;
   3.233 +    }
   3.234 +    
   3.235 if ((keysd & KEY_X)) {
   3.236 +        SDL_PrivateJoystickButton(joystick, 2, SDL_PRESSED);
   3.237 +        prevbutton = KEY_X;
   3.238 +    }
   3.239 +    
   3.240 if ((keysd & KEY_Y)) {
   3.241 +        SDL_PrivateJoystickButton(joystick, 3, SDL_PRESSED);
   3.242 +        prevbutton = KEY_Y;
   3.243 +    }
   3.244 +    
   3.245 if ((keysd & KEY_SELECT)) {
   3.246 +        SDL_PrivateJoystickButton(joystick, 6, SDL_PRESSED);
   3.247 +        prevbutton = KEY_SELECT;
   3.248 +    }
   3.249 +    
   3.250 if ((keysd & KEY_START)) {
   3.251 +        SDL_PrivateJoystickButton(joystick, 7, SDL_PRESSED);
   3.252 +        prevbutton = KEY_START;
   3.253 +    }
   3.254 +    
   3.255 if ((keysd & KEY_L)) {
   3.256 +        SDL_PrivateJoystickButton(joystick, 4, SDL_PRESSED);
   3.257 +        prevbutton = KEY_L;
   3.258 +    }
   3.259 +    
   3.260 if ((keysd & KEY_R)) {
   3.261 +        SDL_PrivateJoystickButton(joystick, 5, SDL_PRESSED);
   3.262 +        prevbutton = KEY_R;
   3.263 +    }
   3.264 +    
   3.265 
   3.266 if ((keysu & KEY_A)) {
   3.267 +        SDL_PrivateJoystickButton(joystick, 0, SDL_RELEASED);
   3.268 +        prevbutton = NULL;
   3.269 +    }
   3.270 +    
   3.271 if ((keysu & KEY_B)) {
   3.272 +        SDL_PrivateJoystickButton(joystick, 1, SDL_RELEASED);
   3.273 +        prevbutton = NULL;
   3.274 +    }
   3.275 +    
   3.276 if ((keysu & KEY_X)) {
   3.277 +        SDL_PrivateJoystickButton(joystick, 2, SDL_RELEASED);
   3.278 +        prevbutton = NULL;
   3.279 +    }
   3.280 +    
   3.281 if ((keysu & KEY_Y)) {
   3.282 +        SDL_PrivateJoystickButton(joystick, 3, SDL_RELEASED);
   3.283 +        prevbutton = NULL;
   3.284 +    }
   3.285 +    
   3.286 if ((keysu & KEY_SELECT)) {
   3.287 +        SDL_PrivateJoystickButton(joystick, 6, SDL_RELEASED);
   3.288 +        prevbutton = NULL;
   3.289 +    }
   3.290 +    
   3.291 if ((keysu & KEY_START)) {
   3.292 +        SDL_PrivateJoystickButton(joystick, 7, SDL_RELEASED);
   3.293 +        prevbutton = NULL;
   3.294 +    }
   3.295 +    
   3.296 if ((keysu & KEY_L)) {
   3.297 +        SDL_PrivateJoystickButton(joystick, 4, SDL_RELEASED);
   3.298 +        prevbutton = NULL;
   3.299 +    }
   3.300 +    
   3.301 if ((keysu & KEY_R)) {
   3.302 +        SDL_PrivateJoystickButton(joystick, 5, SDL_RELEASED);
   3.303 +        prevbutton = NULL;
   3.304 +    }
   3.305 +
   3.306 
   3.307 }
   3.308  
   3.309  /* Function to close a joystick after use */
   3.310 -void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
   3.311 +void
   3.312 +SDL_SYS_JoystickClose(SDL_Joystick * joystick)
   3.313  {
   3.314  }
   3.315  
   3.316  /* Function to perform any system-specific joystick related cleanup */
   3.317 -void SDL_SYS_JoystickQuit(void)
   3.318 +void
   3.319 +SDL_SYS_JoystickQuit(void)
   3.320  {
   3.321  }
   3.322 -
     4.1 --- a/src/thread/nds/SDL_syscond.c	Tue Jun 10 06:57:57 2008 +0000
     4.2 +++ b/src/thread/nds/SDL_syscond.c	Thu Jun 12 02:38:49 2008 +0000
     4.3 @@ -22,7 +22,7 @@
     4.4  
     4.5  #ifdef SAVE_RCSID
     4.6  static char rcsid =
     4.7 - "@(#) $Id: SDL_syscond.c,v 1.2 2001/04/26 16:50:18 hercules Exp $";
     4.8 +    "@(#) $Id: SDL_syscond.c,v 1.2 2001/04/26 16:50:18 hercules Exp $";
     4.9  #endif
    4.10  
    4.11  /* An implementation of condition variables using semaphores and mutexes */
    4.12 @@ -39,107 +39,111 @@
    4.13  
    4.14  struct SDL_cond
    4.15  {
    4.16 -	SDL_mutex *lock;
    4.17 -	int waiting;
    4.18 -	int signals;
    4.19 -	SDL_sem *wait_sem;
    4.20 -	SDL_sem *wait_done;
    4.21 +    SDL_mutex *lock;
    4.22 +    int waiting;
    4.23 +    int signals;
    4.24 +    SDL_sem *wait_sem;
    4.25 +    SDL_sem *wait_done;
    4.26  };
    4.27  
    4.28  /* Create a condition variable */
    4.29 -SDL_cond * SDL_CreateCond(void)
    4.30 +SDL_cond *
    4.31 +SDL_CreateCond(void)
    4.32  {
    4.33 -	SDL_cond *cond;
    4.34 +    SDL_cond *cond;
    4.35  
    4.36 -	cond = (SDL_cond *) malloc(sizeof(SDL_cond));
    4.37 -	if ( cond ) {
    4.38 -		cond->lock = SDL_CreateMutex();
    4.39 -		cond->wait_sem = SDL_CreateSemaphore(0);
    4.40 -		cond->wait_done = SDL_CreateSemaphore(0);
    4.41 -		cond->waiting = cond->signals = 0;
    4.42 -		if ( ! cond->lock || ! cond->wait_sem || ! cond->wait_done ) {
    4.43 -			SDL_DestroyCond(cond);
    4.44 -			cond = NULL;
    4.45 -		}
    4.46 -	} else {
    4.47 -		SDL_OutOfMemory();
    4.48 -	}
    4.49 -	return(cond);
    4.50 +    cond = (SDL_cond *) malloc(sizeof(SDL_cond));
    4.51 +    if (cond) {
    4.52 +        cond->lock = SDL_CreateMutex();
    4.53 +        cond->wait_sem = SDL_CreateSemaphore(0);
    4.54 +        cond->wait_done = SDL_CreateSemaphore(0);
    4.55 +        cond->waiting = cond->signals = 0;
    4.56 +        if (!cond->lock || !cond->wait_sem || !cond->wait_done) {
    4.57 +            SDL_DestroyCond(cond);
    4.58 +            cond = NULL;
    4.59 +        }
    4.60 +    } else {
    4.61 +        SDL_OutOfMemory();
    4.62 +    }
    4.63 +    return (cond);
    4.64  }
    4.65  
    4.66  /* Destroy a condition variable */
    4.67 -void SDL_DestroyCond(SDL_cond *cond)
    4.68 +void
    4.69 +SDL_DestroyCond(SDL_cond * cond)
    4.70  {
    4.71 -	if ( cond ) {
    4.72 -		if ( cond->wait_sem ) {
    4.73 -			SDL_DestroySemaphore(cond->wait_sem);
    4.74 -		}
    4.75 -		if ( cond->wait_done ) {
    4.76 -			SDL_DestroySemaphore(cond->wait_done);
    4.77 -		}
    4.78 -		if ( cond->lock ) {
    4.79 -			SDL_DestroyMutex(cond->lock);
    4.80 -		}
    4.81 -		free(cond);
    4.82 -	}
    4.83 +    if (cond) {
    4.84 +        if (cond->wait_sem) {
    4.85 +            SDL_DestroySemaphore(cond->wait_sem);
    4.86 +        }
    4.87 +        if (cond->wait_done) {
    4.88 +            SDL_DestroySemaphore(cond->wait_done);
    4.89 +        }
    4.90 +        if (cond->lock) {
    4.91 +            SDL_DestroyMutex(cond->lock);
    4.92 +        }
    4.93 +        free(cond);
    4.94 +    }
    4.95  }
    4.96  
    4.97  /* Restart one of the threads that are waiting on the condition variable */
    4.98 -int SDL_CondSignal(SDL_cond *cond)
    4.99 +int
   4.100 +SDL_CondSignal(SDL_cond * cond)
   4.101  {
   4.102 -	if ( ! cond ) {
   4.103 -		SDL_SetError("Passed a NULL condition variable");
   4.104 -		return -1;
   4.105 -	}
   4.106 +    if (!cond) {
   4.107 +        SDL_SetError("Passed a NULL condition variable");
   4.108 +        return -1;
   4.109 +    }
   4.110  
   4.111 -	/* If there are waiting threads not already signalled, then
   4.112 -	   signal the condition and wait for the thread to respond.
   4.113 -	*/
   4.114 -	SDL_LockMutex(cond->lock);
   4.115 -	if ( cond->waiting > cond->signals ) {
   4.116 -		++cond->signals;
   4.117 -		SDL_SemPost(cond->wait_sem);
   4.118 -		SDL_UnlockMutex(cond->lock);
   4.119 -		SDL_SemWait(cond->wait_done);
   4.120 -	} else {
   4.121 -		SDL_UnlockMutex(cond->lock);
   4.122 -	}
   4.123 +    /* If there are waiting threads not already signalled, then
   4.124 +       signal the condition and wait for the thread to respond.
   4.125 +     */
   4.126 +    SDL_LockMutex(cond->lock);
   4.127 +    if (cond->waiting > cond->signals) {
   4.128 +        ++cond->signals;
   4.129 +        SDL_SemPost(cond->wait_sem);
   4.130 +        SDL_UnlockMutex(cond->lock);
   4.131 +        SDL_SemWait(cond->wait_done);
   4.132 +    } else {
   4.133 +        SDL_UnlockMutex(cond->lock);
   4.134 +    }
   4.135  
   4.136 -	return 0;
   4.137 +    return 0;
   4.138  }
   4.139  
   4.140  /* Restart all threads that are waiting on the condition variable */
   4.141 -int SDL_CondBroadcast(SDL_cond *cond)
   4.142 +int
   4.143 +SDL_CondBroadcast(SDL_cond * cond)
   4.144  {
   4.145 -	if ( ! cond ) {
   4.146 -		SDL_SetError("Passed a NULL condition variable");
   4.147 -		return -1;
   4.148 -	}
   4.149 +    if (!cond) {
   4.150 +        SDL_SetError("Passed a NULL condition variable");
   4.151 +        return -1;
   4.152 +    }
   4.153  
   4.154 -	/* If there are waiting threads not already signalled, then
   4.155 -	   signal the condition and wait for the thread to respond.
   4.156 -	*/
   4.157 -	SDL_LockMutex(cond->lock);
   4.158 -	if ( cond->waiting > cond->signals ) {
   4.159 -		int i, num_waiting;
   4.160 +    /* If there are waiting threads not already signalled, then
   4.161 +       signal the condition and wait for the thread to respond.
   4.162 +     */
   4.163 +    SDL_LockMutex(cond->lock);
   4.164 +    if (cond->waiting > cond->signals) {
   4.165 +        int i, num_waiting;
   4.166  
   4.167 -		num_waiting = (cond->waiting - cond->signals);
   4.168 -		cond->signals = cond->waiting;
   4.169 -		for ( i=0; i<num_waiting; ++i ) {
   4.170 -			SDL_SemPost(cond->wait_sem);
   4.171 -		}
   4.172 -		/* Now all released threads are blocked here, waiting for us.
   4.173 -		   Collect them all (and win fabulous prizes!) :-)
   4.174 -		 */
   4.175 -		SDL_UnlockMutex(cond->lock);
   4.176 -		for ( i=0; i<num_waiting; ++i ) {
   4.177 -			SDL_SemWait(cond->wait_done);
   4.178 -		}
   4.179 -	} else {
   4.180 -		SDL_UnlockMutex(cond->lock);
   4.181 -	}
   4.182 +        num_waiting = (cond->waiting - cond->signals);
   4.183 +        cond->signals = cond->waiting;
   4.184 +        for (i = 0; i < num_waiting; ++i) {
   4.185 +            SDL_SemPost(cond->wait_sem);
   4.186 +        }
   4.187 +        /* Now all released threads are blocked here, waiting for us.
   4.188 +           Collect them all (and win fabulous prizes!) :-)
   4.189 +         */
   4.190 +        SDL_UnlockMutex(cond->lock);
   4.191 +        for (i = 0; i < num_waiting; ++i) {
   4.192 +            SDL_SemWait(cond->wait_done);
   4.193 +        }
   4.194 +    } else {
   4.195 +        SDL_UnlockMutex(cond->lock);
   4.196 +    }
   4.197  
   4.198 -	return 0;
   4.199 +    return 0;
   4.200  }
   4.201  
   4.202  /* Wait on the condition variable for at most 'ms' milliseconds.
   4.203 @@ -162,62 +166,64 @@
   4.204  	...
   4.205  	SDL_UnlockMutex(lock);
   4.206   */
   4.207 -int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms)
   4.208 +int
   4.209 +SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
   4.210  {
   4.211 -	int retval;
   4.212 +    int retval;
   4.213  
   4.214 -	if ( ! cond ) {
   4.215 -		SDL_SetError("Passed a NULL condition variable");
   4.216 -		return -1;
   4.217 -	}
   4.218 +    if (!cond) {
   4.219 +        SDL_SetError("Passed a NULL condition variable");
   4.220 +        return -1;
   4.221 +    }
   4.222  
   4.223 -	/* Obtain the protection mutex, and increment the number of waiters.
   4.224 -	   This allows the signal mechanism to only perform a signal if there
   4.225 -	   are waiting threads.
   4.226 -	 */
   4.227 -	SDL_LockMutex(cond->lock);
   4.228 -	++cond->waiting;
   4.229 -	SDL_UnlockMutex(cond->lock);
   4.230 +    /* Obtain the protection mutex, and increment the number of waiters.
   4.231 +       This allows the signal mechanism to only perform a signal if there
   4.232 +       are waiting threads.
   4.233 +     */
   4.234 +    SDL_LockMutex(cond->lock);
   4.235 +    ++cond->waiting;
   4.236 +    SDL_UnlockMutex(cond->lock);
   4.237  
   4.238 -	/* Unlock the mutex, as is required by condition variable semantics */
   4.239 -	SDL_UnlockMutex(mutex);
   4.240 +    /* Unlock the mutex, as is required by condition variable semantics */
   4.241 +    SDL_UnlockMutex(mutex);
   4.242  
   4.243 -	/* Wait for a signal */
   4.244 -	if ( ms == SDL_MUTEX_MAXWAIT ) {
   4.245 -		retval = SDL_SemWait(cond->wait_sem);
   4.246 -	} else {
   4.247 -		retval = SDL_SemWaitTimeout(cond->wait_sem, ms);
   4.248 -	}
   4.249 +    /* Wait for a signal */
   4.250 +    if (ms == SDL_MUTEX_MAXWAIT) {
   4.251 +        retval = SDL_SemWait(cond->wait_sem);
   4.252 +    } else {
   4.253 +        retval = SDL_SemWaitTimeout(cond->wait_sem, ms);
   4.254 +    }
   4.255  
   4.256 -	/* Let the signaler know we have completed the wait, otherwise
   4.257 -           the signaler can race ahead and get the condition semaphore
   4.258 -           if we are stopped between the mutex unlock and semaphore wait,
   4.259 -           giving a deadlock.  See the following URL for details:
   4.260 -        http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html
   4.261 -	*/
   4.262 -	SDL_LockMutex(cond->lock);
   4.263 -	if ( cond->signals > 0 ) {
   4.264 -		/* If we timed out, we need to eat a condition signal */
   4.265 -		if ( retval > 0 ) {
   4.266 -			SDL_SemWait(cond->wait_sem);
   4.267 -		}
   4.268 -		/* We always notify the signal thread that we are done */
   4.269 -		SDL_SemPost(cond->wait_done);
   4.270 +    /* Let the signaler know we have completed the wait, otherwise
   4.271 +       the signaler can race ahead and get the condition semaphore
   4.272 +       if we are stopped between the mutex unlock and semaphore wait,
   4.273 +       giving a deadlock.  See the following URL for details:
   4.274 +       http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html
   4.275 +     */
   4.276 +    SDL_LockMutex(cond->lock);
   4.277 +    if (cond->signals > 0) {
   4.278 +        /* If we timed out, we need to eat a condition signal */
   4.279 +        if (retval > 0) {
   4.280 +            SDL_SemWait(cond->wait_sem);
   4.281 +        }
   4.282 +        /* We always notify the signal thread that we are done */
   4.283 +        SDL_SemPost(cond->wait_done);
   4.284  
   4.285 -		/* Signal handshake complete */
   4.286 -		--cond->signals;
   4.287 -	}
   4.288 -	--cond->waiting;
   4.289 -	SDL_UnlockMutex(cond->lock);
   4.290 +        /* Signal handshake complete */
   4.291 +        --cond->signals;
   4.292 +    }
   4.293 +    --cond->waiting;
   4.294 +    SDL_UnlockMutex(cond->lock);
   4.295  
   4.296 -	/* Lock the mutex, as is required by condition variable semantics */
   4.297 -	SDL_LockMutex(mutex);
   4.298 +    /* Lock the mutex, as is required by condition variable semantics */
   4.299 +    SDL_LockMutex(mutex);
   4.300  
   4.301 -	return retval;
   4.302 +    return retval;
   4.303  }
   4.304  
   4.305  /* Wait on the condition variable forever */
   4.306 -int SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex)
   4.307 +int
   4.308 +SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
   4.309  {
   4.310 -	return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT);
   4.311 +    return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT);
   4.312  }
     5.1 --- a/src/thread/nds/SDL_syscond_c.h	Tue Jun 10 06:57:57 2008 +0000
     5.2 +++ b/src/thread/nds/SDL_syscond_c.h	Thu Jun 12 02:38:49 2008 +0000
     5.3 @@ -22,6 +22,5 @@
     5.4  
     5.5  #ifdef SAVE_RCSID
     5.6  static char rcsid =
     5.7 - "@(#) $Id: SDL_syscond_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $";
     5.8 +    "@(#) $Id: SDL_syscond_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $";
     5.9  #endif
    5.10 -
     6.1 --- a/src/thread/nds/SDL_sysmutex.c	Tue Jun 10 06:57:57 2008 +0000
     6.2 +++ b/src/thread/nds/SDL_sysmutex.c	Thu Jun 12 02:38:49 2008 +0000
     6.3 @@ -22,7 +22,7 @@
     6.4  
     6.5  #ifdef SAVE_RCSID
     6.6  static char rcsid =
     6.7 - "@(#) $Id: SDL_sysmutex.c,v 1.2 2001/04/26 16:50:18 hercules Exp $";
     6.8 +    "@(#) $Id: SDL_sysmutex.c,v 1.2 2001/04/26 16:50:18 hercules Exp $";
     6.9  #endif
    6.10  
    6.11  /* An implementation of mutexes using semaphores */
    6.12 @@ -35,103 +35,108 @@
    6.13  #include "SDL_systhread_c.h"
    6.14  
    6.15  
    6.16 -struct SDL_mutex {
    6.17 -	int recursive;
    6.18 -	Uint32 owner;
    6.19 -	SDL_sem *sem;
    6.20 +struct SDL_mutex
    6.21 +{
    6.22 +    int recursive;
    6.23 +    Uint32 owner;
    6.24 +    SDL_sem *sem;
    6.25  };
    6.26  
    6.27  /* Create a mutex */
    6.28 -SDL_mutex *SDL_CreateMutex(void)
    6.29 +SDL_mutex *
    6.30 +SDL_CreateMutex(void)
    6.31  {
    6.32 -	SDL_mutex *mutex;
    6.33 +    SDL_mutex *mutex;
    6.34  
    6.35 -	/* Allocate mutex memory */
    6.36 -	mutex = (SDL_mutex *)malloc(sizeof(*mutex));
    6.37 -	if ( mutex ) {
    6.38 -		/* Create the mutex semaphore, with initial value 1 */
    6.39 -		mutex->sem = SDL_CreateSemaphore(1);
    6.40 -		mutex->recursive = 0;
    6.41 -		mutex->owner = 0;
    6.42 -		if ( ! mutex->sem ) {
    6.43 -			free(mutex);
    6.44 -			mutex = NULL;
    6.45 -		}
    6.46 -	} else {
    6.47 -		SDL_OutOfMemory();
    6.48 -	}
    6.49 -	return mutex;
    6.50 +    /* Allocate mutex memory */
    6.51 +    mutex = (SDL_mutex *) malloc(sizeof(*mutex));
    6.52 +    if (mutex) {
    6.53 +        /* Create the mutex semaphore, with initial value 1 */
    6.54 +        mutex->sem = SDL_CreateSemaphore(1);
    6.55 +        mutex->recursive = 0;
    6.56 +        mutex->owner = 0;
    6.57 +        if (!mutex->sem) {
    6.58 +            free(mutex);
    6.59 +            mutex = NULL;
    6.60 +        }
    6.61 +    } else {
    6.62 +        SDL_OutOfMemory();
    6.63 +    }
    6.64 +    return mutex;
    6.65  }
    6.66  
    6.67  /* Free the mutex */
    6.68 -void SDL_DestroyMutex(SDL_mutex *mutex)
    6.69 +void
    6.70 +SDL_DestroyMutex(SDL_mutex * mutex)
    6.71  {
    6.72 -	if ( mutex ) {
    6.73 -		if ( mutex->sem ) {
    6.74 -			SDL_DestroySemaphore(mutex->sem);
    6.75 -		}
    6.76 -		free(mutex);
    6.77 -	}
    6.78 +    if (mutex) {
    6.79 +        if (mutex->sem) {
    6.80 +            SDL_DestroySemaphore(mutex->sem);
    6.81 +        }
    6.82 +        free(mutex);
    6.83 +    }
    6.84  }
    6.85  
    6.86  /* Lock the semaphore */
    6.87 -int SDL_mutexP(SDL_mutex *mutex)
    6.88 +int
    6.89 +SDL_mutexP(SDL_mutex * mutex)
    6.90  {
    6.91  #ifdef DISABLE_THREADS
    6.92 -	return 0;
    6.93 +    return 0;
    6.94  #else
    6.95 -	Uint32 this_thread;
    6.96 +    Uint32 this_thread;
    6.97  
    6.98 -	if ( mutex == NULL ) {
    6.99 -		SDL_SetError("Passed a NULL mutex");
   6.100 -		return -1;
   6.101 -	}
   6.102 +    if (mutex == NULL) {
   6.103 +        SDL_SetError("Passed a NULL mutex");
   6.104 +        return -1;
   6.105 +    }
   6.106  
   6.107 -	this_thread = SDL_ThreadID();
   6.108 -	if ( mutex->owner == this_thread ) {
   6.109 -		++mutex->recursive;
   6.110 -	} else {
   6.111 -		/* The order of operations is important.
   6.112 -		   We set the locking thread id after we obtain the lock
   6.113 -		   so unlocks from other threads will fail.
   6.114 -		*/
   6.115 -		SDL_SemWait(mutex->sem);
   6.116 -		mutex->owner = this_thread;
   6.117 -		mutex->recursive = 0;
   6.118 -	}
   6.119 +    this_thread = SDL_ThreadID();
   6.120 +    if (mutex->owner == this_thread) {
   6.121 +        ++mutex->recursive;
   6.122 +    } else {
   6.123 +        /* The order of operations is important.
   6.124 +           We set the locking thread id after we obtain the lock
   6.125 +           so unlocks from other threads will fail.
   6.126 +         */
   6.127 +        SDL_SemWait(mutex->sem);
   6.128 +        mutex->owner = this_thread;
   6.129 +        mutex->recursive = 0;
   6.130 +    }
   6.131  
   6.132 -	return 0;
   6.133 +    return 0;
   6.134  #endif /* DISABLE_THREADS */
   6.135  }
   6.136  
   6.137  /* Unlock the mutex */
   6.138 -int SDL_mutexV(SDL_mutex *mutex)
   6.139 +int
   6.140 +SDL_mutexV(SDL_mutex * mutex)
   6.141  {
   6.142  #ifdef DISABLE_THREADS
   6.143 -	return 0;
   6.144 +    return 0;
   6.145  #else
   6.146 -	if ( mutex == NULL ) {
   6.147 -		SDL_SetError("Passed a NULL mutex");
   6.148 -		return -1;
   6.149 -	}
   6.150 +    if (mutex == NULL) {
   6.151 +        SDL_SetError("Passed a NULL mutex");
   6.152 +        return -1;
   6.153 +    }
   6.154  
   6.155 -	/* If we don't own the mutex, we can't unlock it */
   6.156 -	if ( SDL_ThreadID() != mutex->owner ) {
   6.157 -		SDL_SetError("mutex not owned by this thread");
   6.158 -		return -1;
   6.159 -	}
   6.160 +    /* If we don't own the mutex, we can't unlock it */
   6.161 +    if (SDL_ThreadID() != mutex->owner) {
   6.162 +        SDL_SetError("mutex not owned by this thread");
   6.163 +        return -1;
   6.164 +    }
   6.165  
   6.166 -	if ( mutex->recursive ) {
   6.167 -		--mutex->recursive;
   6.168 -	} else {
   6.169 -		/* The order of operations is important.
   6.170 -		   First reset the owner so another thread doesn't lock
   6.171 -		   the mutex and set the ownership before we reset it,
   6.172 -		   then release the lock semaphore.
   6.173 -		 */
   6.174 -		mutex->owner = 0;
   6.175 -		SDL_SemPost(mutex->sem);
   6.176 -	}
   6.177 -	return 0;
   6.178 +    if (mutex->recursive) {
   6.179 +        --mutex->recursive;
   6.180 +    } else {
   6.181 +        /* The order of operations is important.
   6.182 +           First reset the owner so another thread doesn't lock
   6.183 +           the mutex and set the ownership before we reset it,
   6.184 +           then release the lock semaphore.
   6.185 +         */
   6.186 +        mutex->owner = 0;
   6.187 +        SDL_SemPost(mutex->sem);
   6.188 +    }
   6.189 +    return 0;
   6.190  #endif /* DISABLE_THREADS */
   6.191  }
     7.1 --- a/src/thread/nds/SDL_sysmutex_c.h	Tue Jun 10 06:57:57 2008 +0000
     7.2 +++ b/src/thread/nds/SDL_sysmutex_c.h	Thu Jun 12 02:38:49 2008 +0000
     7.3 @@ -22,6 +22,5 @@
     7.4  
     7.5  #ifdef SAVE_RCSID
     7.6  static char rcsid =
     7.7 - "@(#) $Id: SDL_sysmutex_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $";
     7.8 +    "@(#) $Id: SDL_sysmutex_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $";
     7.9  #endif
    7.10 -
     8.1 --- a/src/thread/nds/SDL_syssem.c	Tue Jun 10 06:57:57 2008 +0000
     8.2 +++ b/src/thread/nds/SDL_syssem.c	Thu Jun 12 02:38:49 2008 +0000
     8.3 @@ -22,7 +22,7 @@
     8.4  
     8.5  #ifdef SAVE_RCSID
     8.6  static char rcsid =
     8.7 - "@(#) $Id: SDL_syssem.c,v 1.2 2001/04/26 16:50:18 hercules Exp $";
     8.8 +    "@(#) $Id: SDL_syssem.c,v 1.2 2001/04/26 16:50:18 hercules Exp $";
     8.9  #endif
    8.10  
    8.11  /* An implementation of semaphores using mutexes and condition variables */
    8.12 @@ -37,178 +37,192 @@
    8.13  
    8.14  #ifdef DISABLE_THREADS
    8.15  
    8.16 -SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
    8.17 +SDL_sem *
    8.18 +SDL_CreateSemaphore(Uint32 initial_value)
    8.19  {
    8.20 -	SDL_SetError("SDL not configured with thread support");
    8.21 -	return (SDL_sem *)0;
    8.22 +    SDL_SetError("SDL not configured with thread support");
    8.23 +    return (SDL_sem *) 0;
    8.24  }
    8.25  
    8.26 -void SDL_DestroySemaphore(SDL_sem *sem)
    8.27 +void
    8.28 +SDL_DestroySemaphore(SDL_sem * sem)
    8.29  {
    8.30 -	return;
    8.31 +    return;
    8.32  }
    8.33  
    8.34 -int SDL_SemTryWait(SDL_sem *sem)
    8.35 +int
    8.36 +SDL_SemTryWait(SDL_sem * sem)
    8.37  {
    8.38 -	SDL_SetError("SDL not configured with thread support");
    8.39 -	return -1;
    8.40 +    SDL_SetError("SDL not configured with thread support");
    8.41 +    return -1;
    8.42  }
    8.43  
    8.44 -int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
    8.45 +int
    8.46 +SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
    8.47  {
    8.48 -	SDL_SetError("SDL not configured with thread support");
    8.49 -	return -1;
    8.50 +    SDL_SetError("SDL not configured with thread support");
    8.51 +    return -1;
    8.52  }
    8.53  
    8.54 -int SDL_SemWait(SDL_sem *sem)
    8.55 +int
    8.56 +SDL_SemWait(SDL_sem * sem)
    8.57  {
    8.58 -	SDL_SetError("SDL not configured with thread support");
    8.59 -	return -1;
    8.60 +    SDL_SetError("SDL not configured with thread support");
    8.61 +    return -1;
    8.62  }
    8.63  
    8.64 -Uint32 SDL_SemValue(SDL_sem *sem)
    8.65 +Uint32
    8.66 +SDL_SemValue(SDL_sem * sem)
    8.67  {
    8.68 -	return 0;
    8.69 +    return 0;
    8.70  }
    8.71  
    8.72 -int SDL_SemPost(SDL_sem *sem)
    8.73 +int
    8.74 +SDL_SemPost(SDL_sem * sem)
    8.75  {
    8.76 -	SDL_SetError("SDL not configured with thread support");
    8.77 -	return -1;
    8.78 +    SDL_SetError("SDL not configured with thread support");
    8.79 +    return -1;
    8.80  }
    8.81  
    8.82  #else
    8.83  
    8.84  struct SDL_semaphore
    8.85  {
    8.86 -	Uint32 count;
    8.87 -	Uint32 waiters_count;
    8.88 -	SDL_mutex *count_lock;
    8.89 -	SDL_cond *count_nonzero;
    8.90 +    Uint32 count;
    8.91 +    Uint32 waiters_count;
    8.92 +    SDL_mutex *count_lock;
    8.93 +    SDL_cond *count_nonzero;
    8.94  };
    8.95  
    8.96 -SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
    8.97 +SDL_sem *
    8.98 +SDL_CreateSemaphore(Uint32 initial_value)
    8.99  {
   8.100 -	SDL_sem *sem;
   8.101 +    SDL_sem *sem;
   8.102  
   8.103 -	sem = (SDL_sem *)malloc(sizeof(*sem));
   8.104 -	if ( ! sem ) {
   8.105 -		SDL_OutOfMemory();
   8.106 -		return(0);
   8.107 -	}
   8.108 -	sem->count = initial_value;
   8.109 -	sem->waiters_count = 0;
   8.110 +    sem = (SDL_sem *) malloc(sizeof(*sem));
   8.111 +    if (!sem) {
   8.112 +        SDL_OutOfMemory();
   8.113 +        return (0);
   8.114 +    }
   8.115 +    sem->count = initial_value;
   8.116 +    sem->waiters_count = 0;
   8.117  
   8.118 -	sem->count_lock = SDL_CreateMutex();
   8.119 -	sem->count_nonzero = SDL_CreateCond();
   8.120 -	if ( ! sem->count_lock || ! sem->count_nonzero ) {
   8.121 -		SDL_DestroySemaphore(sem);
   8.122 -		return(0);
   8.123 -	}
   8.124 +    sem->count_lock = SDL_CreateMutex();
   8.125 +    sem->count_nonzero = SDL_CreateCond();
   8.126 +    if (!sem->count_lock || !sem->count_nonzero) {
   8.127 +        SDL_DestroySemaphore(sem);
   8.128 +        return (0);
   8.129 +    }
   8.130  
   8.131 -	return(sem);
   8.132 +    return (sem);
   8.133  }
   8.134  
   8.135  /* WARNING:
   8.136     You cannot call this function when another thread is using the semaphore.
   8.137  */
   8.138 -void SDL_DestroySemaphore(SDL_sem *sem)
   8.139 +void
   8.140 +SDL_DestroySemaphore(SDL_sem * sem)
   8.141  {
   8.142 -	if ( sem ) {
   8.143 -		sem->count = 0xFFFFFFFF;
   8.144 -		while ( sem->waiters_count > 0) {
   8.145 -			SDL_CondSignal(sem->count_nonzero);
   8.146 -			SDL_Delay(10);
   8.147 -		}
   8.148 -		SDL_DestroyCond(sem->count_nonzero);
   8.149 -		SDL_mutexP(sem->count_lock);
   8.150 -		SDL_mutexV(sem->count_lock);
   8.151 -		SDL_DestroyMutex(sem->count_lock);
   8.152 -		free(sem);
   8.153 -	}
   8.154 +    if (sem) {
   8.155 +        sem->count = 0xFFFFFFFF;
   8.156 +        while (sem->waiters_count > 0) {
   8.157 +            SDL_CondSignal(sem->count_nonzero);
   8.158 +            SDL_Delay(10);
   8.159 +        }
   8.160 +        SDL_DestroyCond(sem->count_nonzero);
   8.161 +        SDL_mutexP(sem->count_lock);
   8.162 +        SDL_mutexV(sem->count_lock);
   8.163 +        SDL_DestroyMutex(sem->count_lock);
   8.164 +        free(sem);
   8.165 +    }
   8.166  }
   8.167  
   8.168 -int SDL_SemTryWait(SDL_sem *sem)
   8.169 +int
   8.170 +SDL_SemTryWait(SDL_sem * sem)
   8.171  {
   8.172 -	int retval;
   8.173 +    int retval;
   8.174  
   8.175 -	if ( ! sem ) {
   8.176 -		SDL_SetError("Passed a NULL semaphore");
   8.177 -		return -1;
   8.178 -	}
   8.179 +    if (!sem) {
   8.180 +        SDL_SetError("Passed a NULL semaphore");
   8.181 +        return -1;
   8.182 +    }
   8.183  
   8.184 -	retval = SDL_MUTEX_TIMEDOUT;
   8.185 -	SDL_LockMutex(sem->count_lock);
   8.186 -	if ( sem->count > 0 ) {
   8.187 -		--sem->count;
   8.188 -		retval = 0;
   8.189 -	}
   8.190 -	SDL_UnlockMutex(sem->count_lock);
   8.191 +    retval = SDL_MUTEX_TIMEDOUT;
   8.192 +    SDL_LockMutex(sem->count_lock);
   8.193 +    if (sem->count > 0) {
   8.194 +        --sem->count;
   8.195 +        retval = 0;
   8.196 +    }
   8.197 +    SDL_UnlockMutex(sem->count_lock);
   8.198  
   8.199 -	return retval;
   8.200 +    return retval;
   8.201  }
   8.202  
   8.203 -int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
   8.204 +int
   8.205 +SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
   8.206  {
   8.207 -	int retval;
   8.208 +    int retval;
   8.209  
   8.210 -	if ( ! sem ) {
   8.211 -		SDL_SetError("Passed a NULL semaphore");
   8.212 -		return -1;
   8.213 -	}
   8.214 +    if (!sem) {
   8.215 +        SDL_SetError("Passed a NULL semaphore");
   8.216 +        return -1;
   8.217 +    }
   8.218  
   8.219 -	/* A timeout of 0 is an easy case */
   8.220 -	if ( timeout == 0 ) {
   8.221 -		return SDL_SemTryWait(sem);
   8.222 -	}
   8.223 +    /* A timeout of 0 is an easy case */
   8.224 +    if (timeout == 0) {
   8.225 +        return SDL_SemTryWait(sem);
   8.226 +    }
   8.227  
   8.228 -	SDL_LockMutex(sem->count_lock);
   8.229 -	++sem->waiters_count;
   8.230 -	retval = 0;
   8.231 -	while ( (sem->count == 0) && (retval != SDL_MUTEX_TIMEDOUT) ) {
   8.232 -		retval = SDL_CondWaitTimeout(sem->count_nonzero,
   8.233 -		                             sem->count_lock, timeout);
   8.234 -	}
   8.235 -	--sem->waiters_count;
   8.236 -	--sem->count;
   8.237 -	SDL_UnlockMutex(sem->count_lock);
   8.238 +    SDL_LockMutex(sem->count_lock);
   8.239 +    ++sem->waiters_count;
   8.240 +    retval = 0;
   8.241 +    while ((sem->count == 0) && (retval != SDL_MUTEX_TIMEDOUT)) {
   8.242 +        retval = SDL_CondWaitTimeout(sem->count_nonzero,
   8.243 +                                     sem->count_lock, timeout);
   8.244 +    }
   8.245 +    --sem->waiters_count;
   8.246 +    --sem->count;
   8.247 +    SDL_UnlockMutex(sem->count_lock);
   8.248  
   8.249 -	return retval;
   8.250 +    return retval;
   8.251  }
   8.252  
   8.253 -int SDL_SemWait(SDL_sem *sem)
   8.254 +int
   8.255 +SDL_SemWait(SDL_sem * sem)
   8.256  {
   8.257 -	return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
   8.258 +    return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
   8.259  }
   8.260  
   8.261 -Uint32 SDL_SemValue(SDL_sem *sem)
   8.262 +Uint32
   8.263 +SDL_SemValue(SDL_sem * sem)
   8.264  {
   8.265 -	Uint32 value;
   8.266 -	
   8.267 -	value = 0;
   8.268 -	if ( sem ) {
   8.269 -		SDL_LockMutex(sem->count_lock);
   8.270 -		value = sem->count;
   8.271 -		SDL_UnlockMutex(sem->count_lock);
   8.272 -	}
   8.273 -	return value;
   8.274 +    Uint32 value;
   8.275 +
   8.276 +    value = 0;
   8.277 +    if (sem) {
   8.278 +        SDL_LockMutex(sem->count_lock);
   8.279 +        value = sem->count;
   8.280 +        SDL_UnlockMutex(sem->count_lock);
   8.281 +    }
   8.282 +    return value;
   8.283  }
   8.284  
   8.285 -int SDL_SemPost(SDL_sem *sem)
   8.286 +int
   8.287 +SDL_SemPost(SDL_sem * sem)
   8.288  {
   8.289 -	if ( ! sem ) {
   8.290 -		SDL_SetError("Passed a NULL semaphore");
   8.291 -		return -1;
   8.292 -	}
   8.293 +    if (!sem) {
   8.294 +        SDL_SetError("Passed a NULL semaphore");
   8.295 +        return -1;
   8.296 +    }
   8.297  
   8.298 -	SDL_LockMutex(sem->count_lock);
   8.299 -	if ( sem->waiters_count > 0 ) {
   8.300 -		SDL_CondSignal(sem->count_nonzero);
   8.301 -	}
   8.302 -	++sem->count;
   8.303 -	SDL_UnlockMutex(sem->count_lock);
   8.304 +    SDL_LockMutex(sem->count_lock);
   8.305 +    if (sem->waiters_count > 0) {
   8.306 +        SDL_CondSignal(sem->count_nonzero);
   8.307 +    }
   8.308 +    ++sem->count;
   8.309 +    SDL_UnlockMutex(sem->count_lock);
   8.310  
   8.311 -	return 0;
   8.312 +    return 0;
   8.313  }
   8.314  
   8.315  #endif /* DISABLE_THREADS */
     9.1 --- a/src/thread/nds/SDL_syssem_c.h	Tue Jun 10 06:57:57 2008 +0000
     9.2 +++ b/src/thread/nds/SDL_syssem_c.h	Thu Jun 12 02:38:49 2008 +0000
     9.3 @@ -22,6 +22,5 @@
     9.4  
     9.5  #ifdef SAVE_RCSID
     9.6  static char rcsid =
     9.7 - "@(#) $Id: SDL_syssem_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $";
     9.8 +    "@(#) $Id: SDL_syssem_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $";
     9.9  #endif
    9.10 -
    10.1 --- a/src/thread/nds/SDL_systhread.c	Tue Jun 10 06:57:57 2008 +0000
    10.2 +++ b/src/thread/nds/SDL_systhread.c	Thu Jun 12 02:38:49 2008 +0000
    10.3 @@ -22,7 +22,7 @@
    10.4  
    10.5  #ifdef SAVE_RCSID
    10.6  static char rcsid =
    10.7 - "@(#) $Id: SDL_systhread.c,v 1.2 2001/04/26 16:50:18 hercules Exp $";
    10.8 +    "@(#) $Id: SDL_systhread.c,v 1.2 2001/04/26 16:50:18 hercules Exp $";
    10.9  #endif
   10.10  
   10.11  /* Thread management routines for SDL */
   10.12 @@ -31,29 +31,33 @@
   10.13  #include "SDL_thread.h"
   10.14  #include "SDL_systhread.h"
   10.15  
   10.16 -int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
   10.17 +int
   10.18 +SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
   10.19  {
   10.20 -	SDL_SetError("Threads are not supported on this platform");
   10.21 -	return(-1);
   10.22 +    SDL_SetError("Threads are not supported on this platform");
   10.23 +    return (-1);
   10.24  }
   10.25  
   10.26 -void SDL_SYS_SetupThread(void)
   10.27 +void
   10.28 +SDL_SYS_SetupThread(void)
   10.29  {
   10.30 -	return;
   10.31 +    return;
   10.32  }
   10.33  
   10.34 -Uint32 SDL_ThreadID(void)
   10.35 +Uint32
   10.36 +SDL_ThreadID(void)
   10.37  {
   10.38 -	return(0);
   10.39 +    return (0);
   10.40  }
   10.41  
   10.42 -void SDL_SYS_WaitThread(SDL_Thread *thread)
   10.43 +void
   10.44 +SDL_SYS_WaitThread(SDL_Thread * thread)
   10.45  {
   10.46 -	return;
   10.47 +    return;
   10.48  }
   10.49  
   10.50 -void SDL_SYS_KillThread(SDL_Thread *thread)
   10.51 +void
   10.52 +SDL_SYS_KillThread(SDL_Thread * thread)
   10.53  {
   10.54 -	return;
   10.55 +    return;
   10.56  }
   10.57 -
    11.1 --- a/src/video/dummy/SDL_nullrender.c	Tue Jun 10 06:57:57 2008 +0000
    11.2 +++ b/src/video/dummy/SDL_nullrender.c	Thu Jun 12 02:38:49 2008 +0000
    11.3 @@ -174,12 +174,18 @@
    11.4          (SDL_DUMMY_RenderData *) renderer->driverdata;
    11.5  
    11.6      /* Send the data to the display */
    11.7 -    if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
    11.8 +    /*if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) */  {
    11.9          char file[128];
   11.10          SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp",
   11.11                       renderer->window, ++frame_number);
   11.12          SDL_SaveBMP(data->screens[data->current_screen], file);
   11.13      }
   11.14 +    /*{
   11.15 +        int i;
   11.16 +        for (i = 0; i < 256 * 192; ++i)
   11.17 +            ((Uint16 *)0x6800000)[i]
   11.18 +                = ((Uint16 *)(data->screens[data->current_screen]->pixels))[i];
   11.19 +    }*/
   11.20  
   11.21      /* Update the flipping chain, if any */
   11.22      if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
    12.1 --- a/src/video/dummy/SDL_nullvideo.c	Tue Jun 10 06:57:57 2008 +0000
    12.2 +++ b/src/video/dummy/SDL_nullvideo.c	Thu Jun 12 02:38:49 2008 +0000
    12.3 @@ -63,7 +63,7 @@
    12.4          return (1);
    12.5      }
    12.6  
    12.7 -    return (0);
    12.8 +    return (1);
    12.9  }
   12.10  
   12.11  static void
    13.1 --- a/src/video/nds/SDL_ndsrender.c	Tue Jun 10 06:57:57 2008 +0000
    13.2 +++ b/src/video/nds/SDL_ndsrender.c	Thu Jun 12 02:38:49 2008 +0000
    13.3 @@ -35,20 +35,20 @@
    13.4  /* SDL surface based renderer implementation */
    13.5  
    13.6  static SDL_Renderer *SDL_NDS_CreateRenderer(SDL_Window * window,
    13.7 -                                              Uint32 flags);
    13.8 +                                            Uint32 flags);
    13.9  static int SDL_NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g,
   13.10 -                                Uint8 b, Uint8 a, const SDL_Rect * rect);
   13.11 +                              Uint8 b, Uint8 a, const SDL_Rect * rect);
   13.12  static int SDL_NDS_RenderCopy(SDL_Renderer * renderer,
   13.13 -                                SDL_Texture * texture,
   13.14 -                                const SDL_Rect * srcrect,
   13.15 -                                const SDL_Rect * dstrect);
   13.16 +                              SDL_Texture * texture,
   13.17 +                              const SDL_Rect * srcrect,
   13.18 +                              const SDL_Rect * dstrect);
   13.19  static void SDL_NDS_RenderPresent(SDL_Renderer * renderer);
   13.20  static void SDL_NDS_DestroyRenderer(SDL_Renderer * renderer);
   13.21  
   13.22  
   13.23  SDL_RenderDriver SDL_NDS_RenderDriver = {
   13.24      SDL_NDS_CreateRenderer,
   13.25 -    { "nds",  SDL_RENDERER_PRESENTCOPY }
   13.26 +    {"nds", SDL_RENDERER_PRESENTCOPY}
   13.27  /*   (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
   13.28        SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
   13.29        SDL_RENDERER_PRESENTDISCARD),*/
   13.30 @@ -73,14 +73,15 @@
   13.31      Uint32 Rmask = 0x7C00, Gmask = 0x03E0, Bmask = 0x001F, Amask = 0x8000;
   13.32  
   13.33      printf("SDL_NDS_CreateRenderer(window, 0x%x)\n", flags);
   13.34 -    printf(" window: (%d,%d), %dx%d\n", window->x, window->y, window->w, window->h);
   13.35 +    printf(" window: (%d,%d), %dx%d\n", window->x, window->y, window->w,
   13.36 +           window->h);
   13.37  
   13.38      /* hard coded this to ARGB1555 for now
   13.39 -    if (!SDL_PixelFormatEnumToMasks
   13.40 -        (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
   13.41 -        SDL_SetError("Unknown display format");
   13.42 -        return NULL;
   13.43 -    }*/
   13.44 +       if (!SDL_PixelFormatEnumToMasks
   13.45 +       (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
   13.46 +       SDL_SetError("Unknown display format");
   13.47 +       return NULL;
   13.48 +       } */
   13.49  
   13.50      renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
   13.51      if (!renderer) {
   13.52 @@ -118,7 +119,8 @@
   13.53      }
   13.54      for (i = 0; i < n; ++i) {
   13.55          data->screens[i] =
   13.56 -            SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask, Amask);
   13.57 +            SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask,
   13.58 +                                 Amask);
   13.59          if (!data->screens[i]) {
   13.60              SDL_NDS_DestroyRenderer(renderer);
   13.61              return NULL;
   13.62 @@ -131,17 +133,11 @@
   13.63  #if 0
   13.64  #define blarg (data->screens[0])
   13.65      printf("hello?\n");
   13.66 -    if(!data || !(data->screens) || !blarg) {
   13.67 +    if (!data || !(data->screens) || !blarg) {
   13.68          printf("they're null.\n");
   13.69      } else {
   13.70          printf("not null.\n");
   13.71 -        printf("%d\n%d\n%d\n%d\n%x\n%x\n%x\n%x\n",
   13.72 -        blarg->w, blarg->h, blarg->pitch,
   13.73 -        blarg->format->BitsPerPixel,
   13.74 -        blarg->format->Rmask,
   13.75 -        blarg->format->Gmask,
   13.76 -        blarg->format->Bmask,
   13.77 -        (u32)(blarg->pixels)); /* ARGH WHY DOESN'T THIS PRINT AT ALL? */
   13.78 +        printf("%d\n%d\n%d\n%d\n%x\n%x\n%x\n%x\n", blarg->w, blarg->h, blarg->pitch, blarg->format->BitsPerPixel, blarg->format->Rmask, blarg->format->Gmask, blarg->format->Bmask, (u32) (blarg->pixels));     /* ARGH WHY DOESN'T THIS PRINT AT ALL? */
   13.79          printf("hurr\n");
   13.80      }
   13.81  #undef blarg
   13.82 @@ -151,7 +147,7 @@
   13.83  
   13.84  static int
   13.85  SDL_NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
   13.86 -                     Uint8 a, const SDL_Rect * rect)
   13.87 +                   Uint8 a, const SDL_Rect * rect)
   13.88  {
   13.89      SDL_NDS_RenderData *data = (SDL_NDS_RenderData *) renderer->driverdata;
   13.90      SDL_Surface *target = data->screens[data->current_screen];
   13.91 @@ -164,26 +160,29 @@
   13.92  }
   13.93  
   13.94  /* this is mainly for testing stuff to put a surface where I can see it */
   13.95 -void sdlds_surf2vram(SDL_Surface *s) {
   13.96 +void
   13.97 +sdlds_surf2vram(SDL_Surface * s)
   13.98 +{
   13.99      int i;
  13.100 -    for(i = 0; i < 256*192; ++i) {
  13.101 -        ((u16*)VRAM_A)[i] = ((u16*)(s->pixels))[i];
  13.102 +    for (i = 0; i < 256 * 192; ++i) {
  13.103 +        ((u16 *) VRAM_A)[i] = ((u16 *) (s->pixels))[i];
  13.104      }
  13.105  }
  13.106  
  13.107  static int
  13.108  SDL_NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
  13.109 -                     const SDL_Rect * srcrect, const SDL_Rect * dstrect)
  13.110 +                   const SDL_Rect * srcrect, const SDL_Rect * dstrect)
  13.111  {
  13.112 -    SDL_NDS_RenderData *data =
  13.113 -        (SDL_NDS_RenderData *) renderer->driverdata;
  13.114 +    SDL_NDS_RenderData *data = (SDL_NDS_RenderData *) renderer->driverdata;
  13.115      SDL_Window *window = SDL_GetWindowFromID(renderer->window);
  13.116      SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
  13.117      printf("SDL_NDS_RenderCopy(renderer, texture, srcrect, dstrect)\n");
  13.118      printf(" renderer: %s\n", renderer->info.name);
  13.119      printf(" texture: %dx%d\n", texture->w, texture->h);
  13.120 -    printf(" srcrect: (%d,%d), %dx%d\n", srcrect->x, srcrect->y, srcrect->w, srcrect->h);
  13.121 -    printf(" dstrect: (%d,%d), %dx%d\n", dstrect->x, dstrect->y, dstrect->w, dstrect->h);
  13.122 +    printf(" srcrect: (%d,%d), %dx%d\n", srcrect->x, srcrect->y, srcrect->w,
  13.123 +           srcrect->h);
  13.124 +    printf(" dstrect: (%d,%d), %dx%d\n", dstrect->x, dstrect->y, dstrect->w,
  13.125 +           dstrect->h);
  13.126  
  13.127      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
  13.128          SDL_Surface *target = data->screens[data->current_screen];
  13.129 @@ -201,37 +200,38 @@
  13.130          SDL_Rect real_dstrect = *dstrect;
  13.131          printf("Rmask %x Gmask %x Bmask %x Amask %x\n"
  13.132                 "width %d, height %d, pitch %d\nbpp %d, pixels %x\n",
  13.133 -            surface->format->Rmask, surface->format->Gmask,
  13.134 -            surface->format->Bmask, surface->format->Amask,
  13.135 -            surface->w, surface->h, surface->pitch,
  13.136 -            surface->format->BitsPerPixel, (u32)(surface->pixels));
  13.137 +               surface->format->Rmask, surface->format->Gmask,
  13.138 +               surface->format->Bmask, surface->format->Amask,
  13.139 +               surface->w, surface->h, surface->pitch,
  13.140 +               surface->format->BitsPerPixel, (u32) (surface->pixels));
  13.141          sdlds_surf2vram(surface);
  13.142          return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect);
  13.143      }
  13.144  #if 0
  13.145  /* previous attempt to copy it directly to vram */
  13.146 -        SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
  13.147 -        int sx = srcrect->x, sy = srcrect->y, sw = srcrect->w, sh = srcrect->h;
  13.148 -        int dx = dstrect->x, dy = dstrect->y, dw = dstrect->w, dh = dstrect->h;
  13.149 -        int si,sj, di,dj;
  13.150 -        /*printf("DEBUG: still alive!\n");*/
  13.151 -        for(sj=0, dj=0; sj<sh && dj<dh; ++sj, ++dj) {
  13.152 -            for(si=0, di=0; si<sw && di<dw; ++si, ++di) {
  13.153 -                ((uint16*)VRAM_A)[(dj+dy)*256 + di+dx]
  13.154 -                 = ((Uint16*)surface->pixels)[(sj+sy)*(surface->w) + si+sx];
  13.155 -            }
  13.156 +    SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
  13.157 +    int sx = srcrect->x, sy = srcrect->y, sw = srcrect->w, sh = srcrect->h;
  13.158 +    int dx = dstrect->x, dy = dstrect->y, dw = dstrect->w, dh = dstrect->h;
  13.159 +    int si, sj, di, dj;
  13.160 +    /*printf("DEBUG: still alive!\n"); */
  13.161 +    for (sj = 0, dj = 0; sj < sh && dj < dh; ++sj, ++dj) {
  13.162 +        for (si = 0, di = 0; si < sw && di < dw; ++si, ++di) {
  13.163 +            ((uint16 *) VRAM_A)[(dj + dy) * 256 + di + dx]
  13.164 +                = ((Uint16 *) surface->pixels)[(sj + sy) * (surface->w) + si +
  13.165 +                                               sx];
  13.166          }
  13.167 -        /*printf("DEBUG: still alive!\n");*/
  13.168      }
  13.169 -    return 0;
  13.170 +    /*printf("DEBUG: still alive!\n"); */
  13.171 +}
  13.172 +
  13.173 +return 0;
  13.174  #endif
  13.175  }
  13.176  
  13.177  static void
  13.178  SDL_NDS_RenderPresent(SDL_Renderer * renderer)
  13.179  {
  13.180 -    SDL_NDS_RenderData *data =
  13.181 -        (SDL_NDS_RenderData *) renderer->driverdata;
  13.182 +    SDL_NDS_RenderData *data = (SDL_NDS_RenderData *) renderer->driverdata;
  13.183  
  13.184      printf("SDL_NDS_RenderPresent(renderer)\n");
  13.185      printf(" renderer: %s\n", renderer->info.name);
  13.186 @@ -240,18 +240,25 @@
  13.187  #if 0
  13.188  /*testing to see if rectangles drawn get copied right*/
  13.189      {
  13.190 -    SDL_Rect ra;
  13.191 -  	ra.x=0; ra.y=0; ra.w=256; ra.h=192;
  13.192 -	SDL_FillRect(data->screens[data->current_screen], &ra, 0x250);
  13.193 -	ra.x=32; ra.y=32; ra.w=192; ra.h=128;
  13.194 -	SDL_FillRect(data->screens[data->current_screen], &ra,
  13.195 -	    SDL_MapRGBA(data->screens[data->current_screen]->format,
  13.196 -	    255,255,255,255));
  13.197 -	}
  13.198 +        SDL_Rect ra;
  13.199 +        ra.x = 0;
  13.200 +        ra.y = 0;
  13.201 +        ra.w = 256;
  13.202 +        ra.h = 192;
  13.203 +        
  13.204 SDL_FillRect(data->screens[data->current_screen], &ra, 0x250);
  13.205 +        ra.x = 32;
  13.206 +        ra.y = 32;
  13.207 +        ra.w = 192;
  13.208 +        ra.h = 128;
  13.209 +        
  13.210 SDL_FillRect(data->screens[data->current_screen], &ra,
  13.211 +                      SDL_MapRGBA(data->screens[data->current_screen]->format,
  13.212 +                                  255, 255, 255, 255));
  13.213 +    }
  13.214  /*okay so this works but why not when I do it in the main()?
  13.215    for some reason the screen I get from screen=SDL_SetVideoMode(...)
  13.216    doesn't get copied to renderer->driverdata? */
  13.217 -    for(i = 0; i < 30; ++i) swiWaitForVBlank(); /* delay for debug purpose */
  13.218 +    for (i = 0; i < 30; ++i)
  13.219 +        swiWaitForVBlank();     /* delay for debug purpose */
  13.220  #endif
  13.221      sdlds_surf2vram(data->screens[data->current_screen]);
  13.222  
    14.1 --- a/src/video/nds/SDL_ndsvideo.c	Tue Jun 10 06:57:57 2008 +0000
    14.2 +++ b/src/video/nds/SDL_ndsvideo.c	Thu Jun 12 02:38:49 2008 +0000
    14.3 @@ -63,7 +63,7 @@
    14.4  NDS_Available(void)
    14.5  {
    14.6      const char *envr = SDL_getenv("SDL_VIDEODRIVER");
    14.7 -	printf("NDS_Available()\n");
    14.8 +    printf("NDS_Available()\n");
    14.9      return (1);
   14.10  }
   14.11  
   14.12 @@ -77,7 +77,7 @@
   14.13  NDS_CreateDevice(int devindex)
   14.14  {
   14.15      SDL_VideoDevice *device;
   14.16 -	printf("NDS_CreateDevice(%d)\n", devindex);
   14.17 +    printf("NDS_CreateDevice(%d)\n", devindex);
   14.18  
   14.19      /* Initialize all variables that we clean on shutdown */
   14.20      device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
   14.21 @@ -95,7 +95,7 @@
   14.22      device->SetDisplayMode = NDS_SetDisplayMode;
   14.23      device->PumpEvents = NDS_PumpEvents;
   14.24  
   14.25 -    device->num_displays = 2; /* DS = dual screens */
   14.26 +    device->num_displays = 2;   /* DS = dual screens */
   14.27  
   14.28      device->free = NDS_DeleteDevice;
   14.29  
   14.30 @@ -114,7 +114,8 @@
   14.31      int i;
   14.32  
   14.33      /* simple 256x192x16x60 for now */
   14.34 -    mode.w = 256;  mode.h = 192;
   14.35 +    mode.w = 256;
   14.36 +    mode.h = 192;
   14.37      mode.format = SDL_PIXELFORMAT_ARGB1555;
   14.38      mode.refresh_rate = 60;
   14.39      mode.driverdata = NULL;
   14.40 @@ -125,43 +126,49 @@
   14.41      SDL_zero(mode);
   14.42      SDL_AddDisplayMode(0, &mode);
   14.43  
   14.44 -	/* hackish stuff to get things up and running for now, and for a console */
   14.45 -	powerON(POWER_ALL);
   14.46 -	videoSetMode(MODE_FB0);
   14.47 -	videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); /* debug text on sub */
   14.48 -	vramSetBankA(VRAM_A_LCD);
   14.49 -	vramSetBankC(VRAM_C_SUB_BG);
   14.50 -	irqInit();
   14.51 -	irqEnable(IRQ_VBLANK);
   14.52 +    /* hackish stuff to get things up and running for now, and for a console */
   14.53 +    powerON(POWER_ALL);
   14.54 +    videoSetMode(MODE_FB0);
   14.55 +    videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);    /* debug text on sub */
   14.56 +    
   14.57     vramSetBankA(VRAM_A_LCD);
   14.58 +    vramSetBankC(VRAM_C_SUB_BG);
   14.59 +    
   14.60     irqInit();
   14.61 +    irqEnable(IRQ_VBLANK);
   14.62      /* set up console for debug text 'n stuff */
   14.63 -    SUB_BG0_CR = BG_MAP_BASE(31); BG_PALETTE_SUB[255] = RGB15(31,31,31);
   14.64 -	consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31),
   14.65 -	                   (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
   14.66 -    for(i = 0; i < 256*192; ++i) {
   14.67 -		((u16*)VRAM_A)[i] = i;
   14.68 -	}
   14.69 -	for(i = 0; i < 60; ++i) swiWaitForVBlank();
   14.70 -    /*NDS_SetDisplayMode(_this, &mode);*/
   14.71 +    SUB_BG0_CR = BG_MAP_BASE(31);
   14.72 +    BG_PALETTE_SUB[255] = RGB15(31, 31, 31);
   14.73 +    consoleInitDefault((u16 *) SCREEN_BASE_BLOCK_SUB(31),
   14.74 +                       (u16 *) CHAR_BASE_BLOCK_SUB(0), 16);
   14.75 +    for (i = 0; i < 256 * 192; ++i) {
   14.76 +        ((u16 *) VRAM_A)[i] = i;
   14.77 +    }
   14.78 +    for (i = 0; i < 60; ++i)
   14.79 +        swiWaitForVBlank();
   14.80 +    
   14.81 +    /*NDS_SetDisplayMode(_this, &mode); */
   14.82      return 0;
   14.83  }
   14.84  
   14.85  static int
   14.86  NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
   14.87  {
   14.88 -	/* right now this function is just hard-coded for 256x192 ARGB1555 */
   14.89 +    /* right now this function is just hard-coded for 256x192 ARGB1555 */
   14.90  #if 0
   14.91 -	videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE); /* display on main core */
   14.92 -    videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); /* debug text on sub */
   14.93 +    videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);       /* display on main core */
   14.94 +    videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);    /* debug text on sub */
   14.95      vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_LCD,
   14.96                       VRAM_C_SUB_BG, VRAM_D_LCD);
   14.97  
   14.98      /* maps well to the 256x192 screen anyway.  note: need VRAM_B for bigger */
   14.99      BG3_CR = BG_BMP16_256x256;
  14.100      /* affine transformation matrix.  nothing too fancy here */
  14.101 -	BG3_XDX = 0x100;    BG3_XDY = 0;
  14.102 -	BG3_YDX = 0;        BG3_YDY = 0x100;
  14.103 -	/* x/y position */
  14.104 -	BG3_CX = 0;         BG3_CY = 0;
  14.105 +    BG3_XDX = 0x100;
  14.106 +    BG3_XDY = 0;
  14.107 +    BG3_YDX = 0;
  14.108 +    BG3_YDY = 0x100;
  14.109 +    /* x/y position */
  14.110 +    BG3_CX = 0;
  14.111 +    BG3_CY = 0;
  14.112  #endif
  14.113      return 0;
  14.114  }