comparison src/joystick/nds/SDL_sysjoystick.c @ 2670:6e4669f4db49 gsoc2008_nds

Fix for the previous commit: actually 'svn add'ed some files.
author Darren Alton <dalton@stevens.edu>
date Tue, 10 Jun 2008 06:57:57 +0000
parents
children c3e7c0698cbb
comparison
equal deleted inserted replaced
2669:e27bdcc80744 2670:6e4669f4db49
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Sam Lantinga
20 slouken@devolution.com
21 */
22
23 #ifdef SAVE_RCSID
24 static char rcsid =
25 "@(#) $Id: SDL_sysjoystick.c,v 1.2 2001/04/26 16:50:17 hercules Exp $";
26 #endif
27
28 /* This is the system specific header for the SDL joystick API */
29 #include <nds.h>
30 //#include <nds/registers_alt.h>
31 #include <stdio.h> /* For the definition of NULL */
32
33 #include "SDL_error.h"
34 #include "SDL_joystick.h"
35 #include "SDL_sysjoystick.h"
36 #include "SDL_joystick_c.h"
37
38 #include "../../video/nds/SDL_ndsevents_c.h"
39
40 /* Function to scan the system for joysticks.
41 * This function should set SDL_numjoysticks to the number of available
42 * joysticks. Joystick 0 should be the system default joystick.
43 * It should return 0, or -1 on an unrecoverable fatal error.
44 */
45 int SDL_SYS_JoystickInit(void)
46 {
47 SDL_numjoysticks = 1;
48 //keysInit();
49
50 return(1);
51 }
52
53 /* Function to get the device-dependent name of a joystick */
54 const char *SDL_SYS_JoystickName(int index)
55 {
56 if(!index)
57 return "NDS builtin joypad";
58 SDL_SetError("No joystick available with that index");
59 return (NULL);
60 }
61
62 /* Function to open a joystick for use.
63 The joystick to open is specified by the index field of the joystick.
64 This should fill the nbuttons and naxes fields of the joystick structure.
65 It returns 0, or -1 if there is an error.
66 */
67 int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
68 {
69 joystick->nbuttons=8;
70 joystick->nhats=0;
71 joystick->nballs=0;
72 joystick->naxes=2;
73 return 0;
74 }
75
76
77 /* Function to update the state of a joystick - called as a device poll.
78 * This function shouldn't update the joystick structure directly,
79 * but instead should call SDL_PrivateJoystick*() to deliver events
80 * and update joystick device state.
81 */
82
83 int prevbutton=0;
84 int prevkey=0;
85
86 int dc=NULL;int ldc=0;
87 u32 keysd,keysu=NULL;
88 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
89 {
90 //dc=keysd;
91 //if (dc != NULL)
92 //{
93 //fprintf(stderr,"heartbeat= %d\n",REG_VCOUNT);
94 //swiWaitForVBlank();
95 //scanKeys();
96 //keysd = keysDown();
97 //keysu = keysUp();
98 //ldc=keysd;
99
100 //}
101 /*if (prevkey !=NULL && prevbutton !=NULL)
102 {
103 scanKeys();
104 }
105 */
106
107 //scanKeys();
108 keysd = keysDown();
109 keysu = keysUp();
110
111
112 short ax=0,v=0,h=0;
113 if((keysd&KEY_UP)) {ax=1;v=-10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_UP;}//fprintf(stderr,"KEY_UP\n");}
114 if((keysd&KEY_DOWN)) {ax=1;v=10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_DOWN;}//fprintf(stderr,"KEY_DOWN\n");}
115 if((keysd&KEY_LEFT)) {ax=0;h=-10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_LEFT;}//fprintf(stderr,"KEY_LEFT\n");}
116 if((keysd&KEY_RIGHT)) {ax=0;h=10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_RIGHT;}//fprintf(stderr,"KEY_RIGHT\n");}
117
118 if((keysu&KEY_UP)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=NULL;}//fprintf(stderr,"KEY_UP\n");}
119 if((keysu&KEY_DOWN)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=NULL;}//fprintf(stderr,"KEY_DOWN\n");}
120 if((keysu&KEY_LEFT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=NULL;}//fprintf(stderr,"KEY_LEFT\n");}
121 if((keysu&KEY_RIGHT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=NULL;}//fprintf(stderr,"KEY_RIGHT\n");}
122
123 if((keysd&KEY_A)) {SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);prevbutton=KEY_A;}
124 if((keysd&KEY_B)) {SDL_PrivateJoystickButton(joystick,1,SDL_PRESSED);prevbutton=KEY_B;}
125 if((keysd&KEY_X)) {SDL_PrivateJoystickButton(joystick,2,SDL_PRESSED);prevbutton=KEY_X;}
126 if((keysd&KEY_Y)) {SDL_PrivateJoystickButton(joystick,3,SDL_PRESSED);prevbutton=KEY_Y;}
127 if((keysd&KEY_SELECT)) {SDL_PrivateJoystickButton(joystick,6,SDL_PRESSED);prevbutton=KEY_SELECT;}
128 if((keysd&KEY_START)) {SDL_PrivateJoystickButton(joystick,7,SDL_PRESSED);prevbutton=KEY_START;}
129 if((keysd&KEY_L)) {SDL_PrivateJoystickButton(joystick,4,SDL_PRESSED);prevbutton=KEY_L;}
130 if((keysd&KEY_R)) {SDL_PrivateJoystickButton(joystick,5,SDL_PRESSED);prevbutton=KEY_R;}
131
132 if((keysu&KEY_A)) {SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);prevbutton=NULL;}
133 if((keysu&KEY_B)) {SDL_PrivateJoystickButton(joystick,1,SDL_RELEASED);prevbutton=NULL;}
134 if((keysu&KEY_X)) {SDL_PrivateJoystickButton(joystick,2,SDL_RELEASED);prevbutton=NULL;}
135 if((keysu&KEY_Y)) {SDL_PrivateJoystickButton(joystick,3,SDL_RELEASED);prevbutton=NULL;}
136 if((keysu&KEY_SELECT)) {SDL_PrivateJoystickButton(joystick,6,SDL_RELEASED);prevbutton=NULL;}
137 if((keysu&KEY_START)) {SDL_PrivateJoystickButton(joystick,7,SDL_RELEASED);prevbutton=NULL;}
138 if((keysu&KEY_L)) {SDL_PrivateJoystickButton(joystick,4,SDL_RELEASED);prevbutton=NULL;}
139 if((keysu&KEY_R)) {SDL_PrivateJoystickButton(joystick,5,SDL_RELEASED);prevbutton=NULL;}
140
141
142
143 }
144
145 /* Function to close a joystick after use */
146 void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
147 {
148 }
149
150 /* Function to perform any system-specific joystick related cleanup */
151 void SDL_SYS_JoystickQuit(void)
152 {
153 }
154