src/joystick/nds/SDL_sysjoystick.c
branchgsoc2008_nds
changeset 2670 6e4669f4db49
child 2671 c3e7c0698cbb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/joystick/nds/SDL_sysjoystick.c	Tue Jun 10 06:57:57 2008 +0000
     1.3 @@ -0,0 +1,154 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@devolution.com
    1.24 +*/
    1.25 +
    1.26 +#ifdef SAVE_RCSID
    1.27 +static char rcsid =
    1.28 + "@(#) $Id: SDL_sysjoystick.c,v 1.2 2001/04/26 16:50:17 hercules Exp $";
    1.29 +#endif
    1.30 +
    1.31 +/* This is the system specific header for the SDL joystick API */
    1.32 +#include <nds.h>
    1.33 +//#include <nds/registers_alt.h>
    1.34 +#include <stdio.h>		/* For the definition of NULL */
    1.35 +
    1.36 +#include "SDL_error.h"
    1.37 +#include "SDL_joystick.h"
    1.38 +#include "SDL_sysjoystick.h"
    1.39 +#include "SDL_joystick_c.h"
    1.40 +
    1.41 +#include "../../video/nds/SDL_ndsevents_c.h"
    1.42 +
    1.43 +/* Function to scan the system for joysticks.
    1.44 + * This function should set SDL_numjoysticks to the number of available
    1.45 + * joysticks.  Joystick 0 should be the system default joystick.
    1.46 + * It should return 0, or -1 on an unrecoverable fatal error.
    1.47 + */
    1.48 +int SDL_SYS_JoystickInit(void)
    1.49 +{
    1.50 +	SDL_numjoysticks = 1;
    1.51 +    //keysInit();
    1.52 +
    1.53 +	return(1);
    1.54 +}
    1.55 +
    1.56 +/* Function to get the device-dependent name of a joystick */
    1.57 +const char *SDL_SYS_JoystickName(int index)
    1.58 +{
    1.59 +	if(!index)
    1.60 +		return "NDS builtin joypad";
    1.61 +	SDL_SetError("No joystick available with that index");
    1.62 +	return (NULL);
    1.63 +}
    1.64 +
    1.65 +/* Function to open a joystick for use.
    1.66 +   The joystick to open is specified by the index field of the joystick.
    1.67 +   This should fill the nbuttons and naxes fields of the joystick structure.
    1.68 +   It returns 0, or -1 if there is an error.
    1.69 + */
    1.70 +int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
    1.71 +{
    1.72 +	joystick->nbuttons=8;
    1.73 +	joystick->nhats=0;
    1.74 +	joystick->nballs=0;
    1.75 +	joystick->naxes=2;
    1.76 +	return 0;
    1.77 +}
    1.78 +
    1.79 +
    1.80 +/* Function to update the state of a joystick - called as a device poll.
    1.81 + * This function shouldn't update the joystick structure directly,
    1.82 + * but instead should call SDL_PrivateJoystick*() to deliver events
    1.83 + * and update joystick device state.
    1.84 + */
    1.85 +
    1.86 +int prevbutton=0;
    1.87 +int prevkey=0;
    1.88 +
    1.89 +int dc=NULL;int ldc=0;
    1.90 +u32 keysd,keysu=NULL;
    1.91 +void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
    1.92 +{
    1.93 +    //dc=keysd;
    1.94 +	//if (dc != NULL)
    1.95 +	//{
    1.96 +		//fprintf(stderr,"heartbeat= %d\n",REG_VCOUNT); 
    1.97 +		//swiWaitForVBlank();
    1.98 +		//scanKeys();
    1.99 +		//keysd = keysDown(); 
   1.100 +		//keysu = keysUp();
   1.101 +		//ldc=keysd;
   1.102 +		 
   1.103 +	//}
   1.104 +	/*if (prevkey !=NULL && prevbutton !=NULL)
   1.105 +	{
   1.106 +		scanKeys();
   1.107 +	}
   1.108 +	*/
   1.109 +	
   1.110 +	//scanKeys();
   1.111 +		keysd = keysDown(); 
   1.112 +		keysu = keysUp();
   1.113 +		
   1.114 +	
   1.115 +	short ax=0,v=0,h=0;
   1.116 +	if((keysd&KEY_UP)) {ax=1;v=-10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_UP;}//fprintf(stderr,"KEY_UP\n");}
   1.117 +	if((keysd&KEY_DOWN)) {ax=1;v=10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_DOWN;}//fprintf(stderr,"KEY_DOWN\n");}
   1.118 +	if((keysd&KEY_LEFT)) {ax=0;h=-10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_LEFT;}//fprintf(stderr,"KEY_LEFT\n");}
   1.119 +	if((keysd&KEY_RIGHT)) {ax=0;h=10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_RIGHT;}//fprintf(stderr,"KEY_RIGHT\n");}
   1.120 +
   1.121 +	if((keysu&KEY_UP)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=NULL;}//fprintf(stderr,"KEY_UP\n");}
   1.122 +	if((keysu&KEY_DOWN)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=NULL;}//fprintf(stderr,"KEY_DOWN\n");}
   1.123 +	if((keysu&KEY_LEFT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=NULL;}//fprintf(stderr,"KEY_LEFT\n");}
   1.124 +	if((keysu&KEY_RIGHT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=NULL;}//fprintf(stderr,"KEY_RIGHT\n");}
   1.125 +
   1.126 +	if((keysd&KEY_A))		{SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);prevbutton=KEY_A;}
   1.127 +	if((keysd&KEY_B))		{SDL_PrivateJoystickButton(joystick,1,SDL_PRESSED);prevbutton=KEY_B;}
   1.128 +	if((keysd&KEY_X))		{SDL_PrivateJoystickButton(joystick,2,SDL_PRESSED);prevbutton=KEY_X;}
   1.129 +	if((keysd&KEY_Y))		{SDL_PrivateJoystickButton(joystick,3,SDL_PRESSED);prevbutton=KEY_Y;}
   1.130 +	if((keysd&KEY_SELECT))	{SDL_PrivateJoystickButton(joystick,6,SDL_PRESSED);prevbutton=KEY_SELECT;}
   1.131 +	if((keysd&KEY_START))	{SDL_PrivateJoystickButton(joystick,7,SDL_PRESSED);prevbutton=KEY_START;}
   1.132 +	if((keysd&KEY_L))		{SDL_PrivateJoystickButton(joystick,4,SDL_PRESSED);prevbutton=KEY_L;}
   1.133 +	if((keysd&KEY_R))		{SDL_PrivateJoystickButton(joystick,5,SDL_PRESSED);prevbutton=KEY_R;}
   1.134 +
   1.135 +	if((keysu&KEY_A))		{SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);prevbutton=NULL;}
   1.136 +	if((keysu&KEY_B))		{SDL_PrivateJoystickButton(joystick,1,SDL_RELEASED);prevbutton=NULL;}
   1.137 +	if((keysu&KEY_X))		{SDL_PrivateJoystickButton(joystick,2,SDL_RELEASED);prevbutton=NULL;}
   1.138 +	if((keysu&KEY_Y))		{SDL_PrivateJoystickButton(joystick,3,SDL_RELEASED);prevbutton=NULL;}
   1.139 +	if((keysu&KEY_SELECT))  {SDL_PrivateJoystickButton(joystick,6,SDL_RELEASED);prevbutton=NULL;}
   1.140 +	if((keysu&KEY_START))	{SDL_PrivateJoystickButton(joystick,7,SDL_RELEASED);prevbutton=NULL;}
   1.141 +	if((keysu&KEY_L))		{SDL_PrivateJoystickButton(joystick,4,SDL_RELEASED);prevbutton=NULL;}
   1.142 +	if((keysu&KEY_R))		{SDL_PrivateJoystickButton(joystick,5,SDL_RELEASED);prevbutton=NULL;}
   1.143 +
   1.144 +
   1.145 +
   1.146 +}
   1.147 +
   1.148 +/* Function to close a joystick after use */
   1.149 +void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
   1.150 +{
   1.151 +}
   1.152 +
   1.153 +/* Function to perform any system-specific joystick related cleanup */
   1.154 +void SDL_SYS_JoystickQuit(void)
   1.155 +{
   1.156 +}
   1.157 +