src/joystick/nds/SDL_sysjoystick.c
branchgsoc2008_nds
changeset 2671 c3e7c0698cbb
parent 2670 6e4669f4db49
child 2673 24a6b3588eac
     1.1 --- a/src/joystick/nds/SDL_sysjoystick.c	Tue Jun 10 06:57:57 2008 +0000
     1.2 +++ b/src/joystick/nds/SDL_sysjoystick.c	Thu Jun 12 02:38:49 2008 +0000
     1.3 @@ -22,13 +22,13 @@
     1.4  
     1.5  #ifdef SAVE_RCSID
     1.6  static char rcsid =
     1.7 - "@(#) $Id: SDL_sysjoystick.c,v 1.2 2001/04/26 16:50:17 hercules Exp $";
     1.8 +    "@(#) $Id: SDL_sysjoystick.c,v 1.2 2001/04/26 16:50:17 hercules Exp $";
     1.9  #endif
    1.10  
    1.11  /* This is the system specific header for the SDL joystick API */
    1.12  #include <nds.h>
    1.13  //#include <nds/registers_alt.h>
    1.14 -#include <stdio.h>		/* For the definition of NULL */
    1.15 +#include <stdio.h>              /* For the definition of NULL */
    1.16  
    1.17  #include "SDL_error.h"
    1.18  #include "SDL_joystick.h"
    1.19 @@ -42,21 +42,23 @@
    1.20   * joysticks.  Joystick 0 should be the system default joystick.
    1.21   * It should return 0, or -1 on an unrecoverable fatal error.
    1.22   */
    1.23 -int SDL_SYS_JoystickInit(void)
    1.24 +int
    1.25 +SDL_SYS_JoystickInit(void)
    1.26  {
    1.27 -	SDL_numjoysticks = 1;
    1.28 -    //keysInit();
    1.29 -
    1.30 -	return(1);
    1.31 +    SDL_numjoysticks = 1;
    1.32 +    
    1.33 +        //keysInit();
    1.34 +        return (1);
    1.35  }
    1.36  
    1.37  /* Function to get the device-dependent name of a joystick */
    1.38 -const char *SDL_SYS_JoystickName(int index)
    1.39 +const char *
    1.40 +SDL_SYS_JoystickName(int index)
    1.41  {
    1.42 -	if(!index)
    1.43 -		return "NDS builtin joypad";
    1.44 -	SDL_SetError("No joystick available with that index");
    1.45 -	return (NULL);
    1.46 +    if (!index)
    1.47 +        return "NDS builtin joypad";
    1.48 +    SDL_SetError("No joystick available with that index");
    1.49 +    return (NULL);
    1.50  }
    1.51  
    1.52  /* Function to open a joystick for use.
    1.53 @@ -64,91 +66,175 @@
    1.54     This should fill the nbuttons and naxes fields of the joystick structure.
    1.55     It returns 0, or -1 if there is an error.
    1.56   */
    1.57 -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
    1.58 +int
    1.59 +SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
    1.60  {
    1.61 -	joystick->nbuttons=8;
    1.62 -	joystick->nhats=0;
    1.63 -	joystick->nballs=0;
    1.64 -	joystick->naxes=2;
    1.65 -	return 0;
    1.66 +    joystick->nbuttons = 8;
    1.67 +    joystick->nhats = 0;
    1.68 +    joystick->nballs = 0;
    1.69 +    joystick->naxes = 2;
    1.70 +    return 0;
    1.71  }
    1.72 +
    1.73  
    1.74 -
    1.75  /* Function to update the state of a joystick - called as a device poll.
    1.76   * This function shouldn't update the joystick structure directly,
    1.77   * but instead should call SDL_PrivateJoystick*() to deliver events
    1.78   * and update joystick device state.
    1.79   */
    1.80 +int prevbutton = 0;
    1.81 +int prevkey = 0;
    1.82  
    1.83 -int prevbutton=0;
    1.84 -int prevkey=0;
    1.85 -
    1.86 -int dc=NULL;int ldc=0;
    1.87 -u32 keysd,keysu=NULL;
    1.88 -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
    1.89 -{
    1.90 -    //dc=keysd;
    1.91 -	//if (dc != NULL)
    1.92 -	//{
    1.93 -		//fprintf(stderr,"heartbeat= %d\n",REG_VCOUNT); 
    1.94 -		//swiWaitForVBlank();
    1.95 -		//scanKeys();
    1.96 -		//keysd = keysDown(); 
    1.97 -		//keysu = keysUp();
    1.98 -		//ldc=keysd;
    1.99 -		 
   1.100 -	//}
   1.101 -	/*if (prevkey !=NULL && prevbutton !=NULL)
   1.102 -	{
   1.103 -		scanKeys();
   1.104 -	}
   1.105 -	*/
   1.106 -	
   1.107 -	//scanKeys();
   1.108 -		keysd = keysDown(); 
   1.109 -		keysu = keysUp();
   1.110 -		
   1.111 -	
   1.112 -	short ax=0,v=0,h=0;
   1.113 -	if((keysd&KEY_UP)) {ax=1;v=-10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_UP;}//fprintf(stderr,"KEY_UP\n");}
   1.114 -	if((keysd&KEY_DOWN)) {ax=1;v=10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_DOWN;}//fprintf(stderr,"KEY_DOWN\n");}
   1.115 -	if((keysd&KEY_LEFT)) {ax=0;h=-10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_LEFT;}//fprintf(stderr,"KEY_LEFT\n");}
   1.116 -	if((keysd&KEY_RIGHT)) {ax=0;h=10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_RIGHT;}//fprintf(stderr,"KEY_RIGHT\n");}
   1.117 -
   1.118 -	if((keysu&KEY_UP)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=NULL;}//fprintf(stderr,"KEY_UP\n");}
   1.119 -	if((keysu&KEY_DOWN)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=NULL;}//fprintf(stderr,"KEY_DOWN\n");}
   1.120 -	if((keysu&KEY_LEFT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=NULL;}//fprintf(stderr,"KEY_LEFT\n");}
   1.121 -	if((keysu&KEY_RIGHT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=NULL;}//fprintf(stderr,"KEY_RIGHT\n");}
   1.122 -
   1.123 -	if((keysd&KEY_A))		{SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);prevbutton=KEY_A;}
   1.124 -	if((keysd&KEY_B))		{SDL_PrivateJoystickButton(joystick,1,SDL_PRESSED);prevbutton=KEY_B;}
   1.125 -	if((keysd&KEY_X))		{SDL_PrivateJoystickButton(joystick,2,SDL_PRESSED);prevbutton=KEY_X;}
   1.126 -	if((keysd&KEY_Y))		{SDL_PrivateJoystickButton(joystick,3,SDL_PRESSED);prevbutton=KEY_Y;}
   1.127 -	if((keysd&KEY_SELECT))	{SDL_PrivateJoystickButton(joystick,6,SDL_PRESSED);prevbutton=KEY_SELECT;}
   1.128 -	if((keysd&KEY_START))	{SDL_PrivateJoystickButton(joystick,7,SDL_PRESSED);prevbutton=KEY_START;}
   1.129 -	if((keysd&KEY_L))		{SDL_PrivateJoystickButton(joystick,4,SDL_PRESSED);prevbutton=KEY_L;}
   1.130 -	if((keysd&KEY_R))		{SDL_PrivateJoystickButton(joystick,5,SDL_PRESSED);prevbutton=KEY_R;}
   1.131 -
   1.132 -	if((keysu&KEY_A))		{SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);prevbutton=NULL;}
   1.133 -	if((keysu&KEY_B))		{SDL_PrivateJoystickButton(joystick,1,SDL_RELEASED);prevbutton=NULL;}
   1.134 -	if((keysu&KEY_X))		{SDL_PrivateJoystickButton(joystick,2,SDL_RELEASED);prevbutton=NULL;}
   1.135 -	if((keysu&KEY_Y))		{SDL_PrivateJoystickButton(joystick,3,SDL_RELEASED);prevbutton=NULL;}
   1.136 -	if((keysu&KEY_SELECT))  {SDL_PrivateJoystickButton(joystick,6,SDL_RELEASED);prevbutton=NULL;}
   1.137 -	if((keysu&KEY_START))	{SDL_PrivateJoystickButton(joystick,7,SDL_RELEASED);prevbutton=NULL;}
   1.138 -	if((keysu&KEY_L))		{SDL_PrivateJoystickButton(joystick,4,SDL_RELEASED);prevbutton=NULL;}
   1.139 -	if((keysu&KEY_R))		{SDL_PrivateJoystickButton(joystick,5,SDL_RELEASED);prevbutton=NULL;}
   1.140 -
   1.141 -
   1.142 -
   1.143 -}
   1.144 +int dc = NULL;
   1.145 +int ldc = 0;
   1.146 +u32 keysd, keysu = NULL;
   1.147 +void
   1.148 +SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
   1.149 +{
   1.150 +    
   1.151 +        //dc=keysd;
   1.152 +        //if (dc != NULL)
   1.153 +        //{
   1.154 +        //fprintf(stderr,"heartbeat= %d\n",REG_VCOUNT); 
   1.155 +        //swiWaitForVBlank();
   1.156 +        //scanKeys();
   1.157 +        //keysd = keysDown(); 
   1.158 +        //keysu = keysUp();
   1.159 +        //ldc=keysd;
   1.160 +        
   1.161 +        //}
   1.162 +        /*if (prevkey !=NULL && prevbutton !=NULL)
   1.163 +           {
   1.164 +           scanKeys();
   1.165 +           }
   1.166 +         */ 
   1.167 +        
   1.168 +        //scanKeys();
   1.169 +        keysd = keysDown();
   1.170 +    
   1.171 keysu = keysUp();
   1.172 +    
   1.173 
   1.174 short ax = 0, v = 0, h = 0;
   1.175 +    if ((keysd & KEY_UP)) {
   1.176 +        ax = 1;
   1.177 +        v = -10;
   1.178 +        SDL_PrivateJoystickAxis(joystick, ax, v);
   1.179 +        prevkey = KEY_UP;
   1.180 +    }                           //fprintf(stderr,"KEY_UP\n");}
   1.181 +    if ((keysd & KEY_DOWN)) {
   1.182 +        ax = 1;
   1.183 +        v = 10;
   1.184 +        SDL_PrivateJoystickAxis(joystick, ax, v);
   1.185 +        prevkey = KEY_DOWN;
   1.186 +    }                           //fprintf(stderr,"KEY_DOWN\n");}
   1.187 +    if ((keysd & KEY_LEFT)) {
   1.188 +        ax = 0;
   1.189 +        h = -10;
   1.190 +        SDL_PrivateJoystickAxis(joystick, ax, h);
   1.191 +        prevkey = KEY_LEFT;
   1.192 +    }                           //fprintf(stderr,"KEY_LEFT\n");}
   1.193 +    if ((keysd & KEY_RIGHT)) {
   1.194 +        ax = 0;
   1.195 +        h = 10;
   1.196 +        SDL_PrivateJoystickAxis(joystick, ax, h);
   1.197 +        prevkey = KEY_RIGHT;
   1.198 +    }                           //fprintf(stderr,"KEY_RIGHT\n");}
   1.199 +    
   1.200 if ((keysu & KEY_UP)) {
   1.201 +        ax = 1;
   1.202 +        v = 0;
   1.203 +        SDL_PrivateJoystickAxis(joystick, ax, v);
   1.204 +        prevkey = NULL;
   1.205 +    }                           //fprintf(stderr,"KEY_UP\n");}
   1.206 +    if ((keysu & KEY_DOWN)) {
   1.207 +        ax = 1;
   1.208 +        v = 0;
   1.209 +        SDL_PrivateJoystickAxis(joystick, ax, v);
   1.210 +        prevkey = NULL;
   1.211 +    }                           //fprintf(stderr,"KEY_DOWN\n");}
   1.212 +    if ((keysu & KEY_LEFT)) {
   1.213 +        ax = 0;
   1.214 +        h = 0;
   1.215 +        SDL_PrivateJoystickAxis(joystick, ax, h);
   1.216 +        prevkey = NULL;
   1.217 +    }                           //fprintf(stderr,"KEY_LEFT\n");}
   1.218 +    if ((keysu & KEY_RIGHT)) {
   1.219 +        ax = 0;
   1.220 +        h = 0;
   1.221 +        SDL_PrivateJoystickAxis(joystick, ax, h);
   1.222 +        prevkey = NULL;
   1.223 +    }                           //fprintf(stderr,"KEY_RIGHT\n");}
   1.224 +    
   1.225 if ((keysd & KEY_A)) {
   1.226 +        SDL_PrivateJoystickButton(joystick, 0, SDL_PRESSED);
   1.227 +        prevbutton = KEY_A;
   1.228 +    }
   1.229 +    
   1.230 if ((keysd & KEY_B)) {
   1.231 +        SDL_PrivateJoystickButton(joystick, 1, SDL_PRESSED);
   1.232 +        prevbutton = KEY_B;
   1.233 +    }
   1.234 +    
   1.235 if ((keysd & KEY_X)) {
   1.236 +        SDL_PrivateJoystickButton(joystick, 2, SDL_PRESSED);
   1.237 +        prevbutton = KEY_X;
   1.238 +    }
   1.239 +    
   1.240 if ((keysd & KEY_Y)) {
   1.241 +        SDL_PrivateJoystickButton(joystick, 3, SDL_PRESSED);
   1.242 +        prevbutton = KEY_Y;
   1.243 +    }
   1.244 +    
   1.245 if ((keysd & KEY_SELECT)) {
   1.246 +        SDL_PrivateJoystickButton(joystick, 6, SDL_PRESSED);
   1.247 +        prevbutton = KEY_SELECT;
   1.248 +    }
   1.249 +    
   1.250 if ((keysd & KEY_START)) {
   1.251 +        SDL_PrivateJoystickButton(joystick, 7, SDL_PRESSED);
   1.252 +        prevbutton = KEY_START;
   1.253 +    }
   1.254 +    
   1.255 if ((keysd & KEY_L)) {
   1.256 +        SDL_PrivateJoystickButton(joystick, 4, SDL_PRESSED);
   1.257 +        prevbutton = KEY_L;
   1.258 +    }
   1.259 +    
   1.260 if ((keysd & KEY_R)) {
   1.261 +        SDL_PrivateJoystickButton(joystick, 5, SDL_PRESSED);
   1.262 +        prevbutton = KEY_R;
   1.263 +    }
   1.264 +    
   1.265 
   1.266 if ((keysu & KEY_A)) {
   1.267 +        SDL_PrivateJoystickButton(joystick, 0, SDL_RELEASED);
   1.268 +        prevbutton = NULL;
   1.269 +    }
   1.270 +    
   1.271 if ((keysu & KEY_B)) {
   1.272 +        SDL_PrivateJoystickButton(joystick, 1, SDL_RELEASED);
   1.273 +        prevbutton = NULL;
   1.274 +    }
   1.275 +    
   1.276 if ((keysu & KEY_X)) {
   1.277 +        SDL_PrivateJoystickButton(joystick, 2, SDL_RELEASED);
   1.278 +        prevbutton = NULL;
   1.279 +    }
   1.280 +    
   1.281 if ((keysu & KEY_Y)) {
   1.282 +        SDL_PrivateJoystickButton(joystick, 3, SDL_RELEASED);
   1.283 +        prevbutton = NULL;
   1.284 +    }
   1.285 +    
   1.286 if ((keysu & KEY_SELECT)) {
   1.287 +        SDL_PrivateJoystickButton(joystick, 6, SDL_RELEASED);
   1.288 +        prevbutton = NULL;
   1.289 +    }
   1.290 +    
   1.291 if ((keysu & KEY_START)) {
   1.292 +        SDL_PrivateJoystickButton(joystick, 7, SDL_RELEASED);
   1.293 +        prevbutton = NULL;
   1.294 +    }
   1.295 +    
   1.296 if ((keysu & KEY_L)) {
   1.297 +        SDL_PrivateJoystickButton(joystick, 4, SDL_RELEASED);
   1.298 +        prevbutton = NULL;
   1.299 +    }
   1.300 +    
   1.301 if ((keysu & KEY_R)) {
   1.302 +        SDL_PrivateJoystickButton(joystick, 5, SDL_RELEASED);
   1.303 +        prevbutton = NULL;
   1.304 +    }
   1.305 +
   1.306 
   1.307 }
   1.308  
   1.309  /* Function to close a joystick after use */
   1.310 -void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
   1.311 +void
   1.312 +SDL_SYS_JoystickClose(SDL_Joystick * joystick)
   1.313  {
   1.314  }
   1.315  
   1.316  /* Function to perform any system-specific joystick related cleanup */
   1.317 -void SDL_SYS_JoystickQuit(void)
   1.318 +void
   1.319 +SDL_SYS_JoystickQuit(void)
   1.320  {
   1.321  }
   1.322 -