Initial work for NDS haptic support.
authorDarren Alton <dalton@stevens.edu>
Sat, 06 Sep 2008 00:10:16 +0000
changeset 27491c5f440a60fe
parent 2748 5668c3dfe7bc
child 2750 e3affc66d963
Initial work for NDS haptic support.
Makefile.ds
src/haptic/nds/SDL_syshaptic.c
src/joystick/nds/SDL_sysjoystick.c
src/video/nds/SDL_ndsevents.c
     1.1 --- a/Makefile.ds	Thu Sep 04 13:43:39 2008 +0000
     1.2 +++ b/Makefile.ds	Sat Sep 06 00:10:16 2008 +0000
     1.3 @@ -55,6 +55,8 @@
     1.4  src/events/SDL_quit.c \
     1.5  src/events/SDL_windowevents.c \
     1.6  src/file/SDL_rwops.c \
     1.7 +src/haptic/SDL_haptic.c \
     1.8 +src/haptic/nds/SDL_syshaptic.c \
     1.9  src/joystick/nds/SDL_sysjoystick.c \
    1.10  src/joystick/SDL_joystick.c \
    1.11  src/stdlib/SDL_getenv.c \
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/haptic/nds/SDL_syshaptic.c	Sat Sep 06 00:10:16 2008 +0000
     2.3 @@ -0,0 +1,334 @@
     2.4 +/*
     2.5 +    SDL - Simple DirectMedia Layer
     2.6 +    Copyright (C) 2008 Edgar Simo
     2.7 +
     2.8 +    This library is free software; you can redistribute it and/or
     2.9 +    modify it under the terms of the GNU Lesser General Public
    2.10 +    License as published by the Free Software Foundation; either
    2.11 +    version 2.1 of the License, or (at your option) any later version.
    2.12 +
    2.13 +    This library is distributed in the hope that it will be useful,
    2.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    2.16 +    Lesser General Public License for more details.
    2.17 +
    2.18 +    You should have received a copy of the GNU Lesser General Public
    2.19 +    License along with this library; if not, write to the Free Software
    2.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2.21 +
    2.22 +    Sam Lantinga
    2.23 +    slouken@libsdl.org
    2.24 +*/
    2.25 +#include "SDL_config.h"
    2.26 +
    2.27 +#ifdef SDL_HAPTIC_NDS
    2.28 +
    2.29 +#include "SDL_haptic.h"
    2.30 +#include "../SDL_syshaptic.h"
    2.31 +#include "SDL_joystick.h"
    2.32 +#include <nds/arm9/rumble.h>
    2.33 +#include <nds/memory.h>
    2.34 +
    2.35 +#define MAX_HAPTICS  1
    2.36 +/* right now only the ezf3in1 (and maybe official rumble pak) are supported
    2.37 +   and there can only be one of those in at a time (in GBA slot.) */
    2.38 +
    2.39 +SDL_Haptic *nds_haptic = NULL;
    2.40 +
    2.41 +typedef struct
    2.42 +{
    2.43 +    enum
    2.44 +    { NONE, OFFICIAL, EZF3IN1 } type;
    2.45 +    int pos;
    2.46 +} NDS_HapticData;
    2.47 +
    2.48 +
    2.49 +
    2.50 +void NDS_EZF_OpenNorWrite()
    2.51 +{
    2.52 +    GBA_BUS[0x0FF0000] = 0xD200;
    2.53 +    GBA_BUS[0x0000000] = 0x1500;
    2.54 +    GBA_BUS[0x0010000] = 0xD200;
    2.55 +    GBA_BUS[0x0020000] = 0x1500;
    2.56 +    GBA_BUS[0x0E20000] = 0x1500;
    2.57 +    GBA_BUS[0x0FE0000] = 0x1500;
    2.58 +}
    2.59 +
    2.60 +
    2.61 +void NDS_EZF_CloseNorWrite()
    2.62 +{
    2.63 +    GBA_BUS[0x0FF0000] = 0xD200;
    2.64 +    GBA_BUS[0x0000000] = 0x1500;
    2.65 +    GBA_BUS[0x0010000] = 0xD200;
    2.66 +    GBA_BUS[0x0020000] = 0x1500;
    2.67 +    GBA_BUS[0x0E20000] = 0xD200;
    2.68 +    GBA_BUS[0x0FE0000] = 0x1500;
    2.69 +}
    2.70 +
    2.71 +void NDS_EZF_ChipReset()
    2.72 +{
    2.73 +    GBA_BUS[0x0000] = 0x00F0 ;
    2.74 +    GBA_BUS[0x1000] = 0x00F0 ;
    2.75 +}
    2.76 +uint32 NDS_EZF_IsPresent()
    2.77 +{
    2.78 +    vuint16 id1,id2;
    2.79 +
    2.80 +    NDS_EZF_OpenNorWrite();
    2.81 +
    2.82 +    GBA_BUS[0x0555] = 0x00AA;
    2.83 +    GBA_BUS[0x02AA] = 0x0055;
    2.84 +    GBA_BUS[0x0555] = 0x0090;
    2.85 +    GBA_BUS[0x1555] = 0x00AA;
    2.86 +    GBA_BUS[0x12AA] = 0x0055;
    2.87 +    GBA_BUS[0x1555] = 0x0090;
    2.88 +
    2.89 +    id1 = GBA_BUS[0x0001];
    2.90 +    id2 = GBA_BUS[0x1001];
    2.91 +
    2.92 +    if((id1!=0x227E)|| (id2!=0x227E)) {
    2.93 +        NDS_EZF_CloseNorWrite();
    2.94 +        return 0;
    2.95 +    }
    2.96 +
    2.97 +    id1 = GBA_BUS[0x000E];
    2.98 +    id2 = GBA_BUS[0x100E];
    2.99 +
   2.100 +    NDS_EZF_CloseNorWrite();
   2.101 +
   2.102 +    if(id1==0x2218 && id2==0x2218) {
   2.103 +        return 1;
   2.104 +    }
   2.105 +
   2.106 +    return 0;
   2.107 +}
   2.108 +
   2.109 +void NDS_EZF_SetShake(u8 pos)
   2.110 +{
   2.111 +    u16 data = ((pos%3)|0x00F0);
   2.112 +
   2.113 +    GBA_BUS[0x0FF0000] = 0xD200;
   2.114 +    GBA_BUS[0x0000000] = 0x1500;
   2.115 +    GBA_BUS[0x0010000] = 0xD200;
   2.116 +    GBA_BUS[0x0020000] = 0x1500;
   2.117 +    GBA_BUS[0x0F10000] = data;
   2.118 +    GBA_BUS[0x0FE0000] = 0x1500;
   2.119 +
   2.120 +    GBA_BUS[0] = 0x0000; /* write any value for vibration. */
   2.121 +    GBA_BUS[0] = 0x0002;
   2.122 +}
   2.123 +
   2.124 +static int
   2.125 +SDL_SYS_LogicError(void)
   2.126 +{
   2.127 +    SDL_SetError("Logic error: No haptic devices available.");
   2.128 +    return 0;
   2.129 +}
   2.130 +
   2.131 +
   2.132 +int
   2.133 +SDL_SYS_HapticInit(void)
   2.134 +{
   2.135 +    int ret = 0;
   2.136 +    if(isRumbleInserted()) {
   2.137 +        /* official rumble pak is present. */
   2.138 +        ret = 1;
   2.139 +        printf("debug: haptic present: nintendo\n");
   2.140 +    } else if(NDS_EZF_IsPresent()) {
   2.141 +        /* ezflash 3-in-1 pak is present. */
   2.142 +        ret = 1;
   2.143 +        printf("debug: haptic present: ezf3in1\n");
   2.144 +        NDS_EZF_ChipReset();
   2.145 +    } else {
   2.146 +        printf("debug: no haptic found\n");
   2.147 +    }
   2.148 +
   2.149 +    return ret;
   2.150 +}
   2.151 +
   2.152 +
   2.153 +const char *
   2.154 +SDL_SYS_HapticName(int index)
   2.155 +{
   2.156 +    if(nds_haptic) {
   2.157 +        switch(nds_haptic->hwdata->type) {
   2.158 +            case OFFICIAL: return "Nintendo DS Rumble Pak";
   2.159 +            case EZF3IN1: return "EZFlash 3-in-1 Rumble";
   2.160 +            default: return NULL;
   2.161 +        }
   2.162 +    }
   2.163 +    return NULL;
   2.164 +}
   2.165 +
   2.166 +
   2.167 +int
   2.168 +SDL_SYS_HapticOpen(SDL_Haptic * haptic)
   2.169 +{
   2.170 +    if(!haptic) {
   2.171 +        return -1;
   2.172 +    }
   2.173 +
   2.174 +    haptic->hwdata = SDL_malloc(sizeof(NDS_HapticData));
   2.175 +    if(!haptic->hwdata) {
   2.176 +        SDL_OutOfMemory();
   2.177 +        return -1;
   2.178 +    }
   2.179 +    nds_haptic = haptic;
   2.180 +
   2.181 +    haptic->supported = SDL_HAPTIC_CONSTANT;
   2.182 +
   2.183 +    /* determine what is here, if anything */
   2.184 +    haptic->hwdata->type = NONE;
   2.185 +    if(isRumbleInserted()) {
   2.186 +        /* official rumble pak is present. */
   2.187 +        haptic->hwdata->type = OFFICIAL;
   2.188 +    } else if(NDS_EZF_IsPresent()) {
   2.189 +        /* ezflash 3-in-1 pak is present. */
   2.190 +        haptic->hwdata->type = EZF3IN1;
   2.191 +        NDS_EZF_ChipReset();
   2.192 +    } else {
   2.193 +        /* no haptic present */
   2.194 +        SDL_SYS_LogicError();
   2.195 +        return -1;
   2.196 +    }
   2.197 +
   2.198 +    return 0;
   2.199 +}
   2.200 +
   2.201 +
   2.202 +int
   2.203 +SDL_SYS_HapticMouse(void)
   2.204 +{
   2.205 +    return -1;
   2.206 +}
   2.207 +
   2.208 +
   2.209 +int
   2.210 +SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
   2.211 +{
   2.212 +    return 0;
   2.213 +}
   2.214 +
   2.215 +
   2.216 +int
   2.217 +SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
   2.218 +{
   2.219 +    /*SDL_SYS_LogicError();*/
   2.220 +    return -1;
   2.221 +}
   2.222 +
   2.223 +
   2.224 +int
   2.225 +SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
   2.226 +{
   2.227 +    return 0;
   2.228 +}
   2.229 +
   2.230 +
   2.231 +void
   2.232 +SDL_SYS_HapticClose(SDL_Haptic * haptic)
   2.233 +{
   2.234 +    return;
   2.235 +}
   2.236 +
   2.237 +
   2.238 +void
   2.239 +SDL_SYS_HapticQuit(void)
   2.240 +{
   2.241 +    return;
   2.242 +}
   2.243 +
   2.244 +
   2.245 +int
   2.246 +SDL_SYS_HapticNewEffect(SDL_Haptic * haptic,
   2.247 +                        struct haptic_effect *effect, SDL_HapticEffect * base)
   2.248 +{
   2.249 +    SDL_SYS_LogicError();
   2.250 +    return -1;
   2.251 +}
   2.252 +
   2.253 +
   2.254 +int
   2.255 +SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
   2.256 +                           struct haptic_effect *effect,
   2.257 +                           SDL_HapticEffect * data)
   2.258 +{
   2.259 +    SDL_SYS_LogicError();
   2.260 +    return -1;
   2.261 +}
   2.262 +
   2.263 +
   2.264 +int
   2.265 +SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
   2.266 +                        Uint32 iterations)
   2.267 +{
   2.268 +    SDL_SYS_LogicError();
   2.269 +    return -1;
   2.270 +}
   2.271 +
   2.272 +
   2.273 +int
   2.274 +SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
   2.275 +{
   2.276 +    SDL_SYS_LogicError();
   2.277 +    return -1;
   2.278 +}
   2.279 +
   2.280 +
   2.281 +void
   2.282 +SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
   2.283 +{
   2.284 +    SDL_SYS_LogicError();
   2.285 +    return;
   2.286 +}
   2.287 +
   2.288 +
   2.289 +int
   2.290 +SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
   2.291 +                              struct haptic_effect *effect)
   2.292 +{
   2.293 +    SDL_SYS_LogicError();
   2.294 +    return -1;
   2.295 +}
   2.296 +
   2.297 +
   2.298 +int
   2.299 +SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
   2.300 +{
   2.301 +    SDL_SYS_LogicError();
   2.302 +    return -1;
   2.303 +}
   2.304 +
   2.305 +
   2.306 +int
   2.307 +SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
   2.308 +{
   2.309 +    SDL_SYS_LogicError();
   2.310 +    return -1;
   2.311 +}
   2.312 +
   2.313 +int
   2.314 +SDL_SYS_HapticPause(SDL_Haptic * haptic)
   2.315 +{
   2.316 +    SDL_SYS_LogicError();
   2.317 +    return -1;
   2.318 +}
   2.319 +
   2.320 +int
   2.321 +SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
   2.322 +{
   2.323 +    SDL_SYS_LogicError();
   2.324 +    return -1;
   2.325 +}
   2.326 +
   2.327 +int
   2.328 +SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
   2.329 +{
   2.330 +    SDL_SYS_LogicError();
   2.331 +    return -1;
   2.332 +}
   2.333 +
   2.334 +
   2.335 +
   2.336 +#endif /* SDL_HAPTIC_NDS */
   2.337 +/* vi: set ts=4 sw=4 expandtab: */
     3.1 --- a/src/joystick/nds/SDL_sysjoystick.c	Thu Sep 04 13:43:39 2008 +0000
     3.2 +++ b/src/joystick/nds/SDL_sysjoystick.c	Sat Sep 06 00:10:16 2008 +0000
     3.3 @@ -44,8 +44,7 @@
     3.4  int
     3.5  SDL_SYS_JoystickInit(void)
     3.6  {
     3.7 -    SDL_numjoysticks = 1;
     3.8 -    
     3.9 return (1);
    3.10 +    SDL_numjoysticks = 1;
    3.11     return (1);
    3.12  }
    3.13  
    3.14  /* Function to get the device-dependent name of a joystick */
    3.15 @@ -79,14 +78,14 @@
    3.16   * but instead should call SDL_PrivateJoystick*() to deliver events
    3.17   * and update joystick device state.
    3.18   */
    3.19 -    void
    3.20 +void
    3.21  SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
    3.22  {
    3.23      u32 keysd, keysu;
    3.24      int magnitude = 16384;
    3.25      
    3.26 -        /*scanKeys(); */ 
    3.27 -        keysd = keysDown();
    3.28 +    /*scanKeys(); - this is done in PumpEvents, because touch uses it too */
    3.29 +    keysd = keysDown();
    3.30      keysu = keysUp();
    3.31  
    3.32      if ((keysd & KEY_UP)) {
    3.33 @@ -101,58 +100,58 @@
    3.34      if ((keysd & KEY_RIGHT)) {
    3.35          SDL_PrivateJoystickAxis(joystick, 0, magnitude);
    3.36      }
    3.37 -    
    3.38 if ((keysu & (KEY_UP | KEY_DOWN))) {
    3.39 +
    3.40     if ((keysu & (KEY_UP | KEY_DOWN))) {
    3.41          SDL_PrivateJoystickAxis(joystick, 1, 0);
    3.42      }
    3.43 -    
    3.44 if ((keysu & (KEY_LEFT | KEY_RIGHT))) {
    3.45 +
    3.46     if ((keysu & (KEY_LEFT | KEY_RIGHT))) {
    3.47          SDL_PrivateJoystickAxis(joystick, 0, 0);
    3.48      }
    3.49 -    
    3.50 if ((keysd & KEY_A)) {
    3.51 +    
    3.52     if ((keysd & KEY_A)) {
    3.53          SDL_PrivateJoystickButton(joystick, 0, SDL_PRESSED);
    3.54      }
    3.55 -    
    3.56 if ((keysd & KEY_B)) {
    3.57 +    
    3.58     if ((keysd & KEY_B)) {
    3.59          SDL_PrivateJoystickButton(joystick, 1, SDL_PRESSED);
    3.60      }
    3.61 -    
    3.62 if ((keysd & KEY_X)) {
    3.63 +    
    3.64     if ((keysd & KEY_X)) {
    3.65          SDL_PrivateJoystickButton(joystick, 2, SDL_PRESSED);
    3.66      }
    3.67 -    
    3.68 if ((keysd & KEY_Y)) {
    3.69 +    
    3.70     if ((keysd & KEY_Y)) {
    3.71          SDL_PrivateJoystickButton(joystick, 3, SDL_PRESSED);
    3.72      }
    3.73 -    
    3.74 if ((keysd & KEY_L)) {
    3.75 +    
    3.76     if ((keysd & KEY_L)) {
    3.77          SDL_PrivateJoystickButton(joystick, 4, SDL_PRESSED);
    3.78      }
    3.79 -    
    3.80 if ((keysd & KEY_R)) {
    3.81 +    
    3.82     if ((keysd & KEY_R)) {
    3.83          SDL_PrivateJoystickButton(joystick, 5, SDL_PRESSED);
    3.84      }
    3.85 -    
    3.86 if ((keysd & KEY_SELECT)) {
    3.87 +    
    3.88     if ((keysd & KEY_SELECT)) {
    3.89          SDL_PrivateJoystickButton(joystick, 6, SDL_PRESSED);
    3.90      }
    3.91 -    
    3.92 if ((keysd & KEY_START)) {
    3.93 +    
    3.94     if ((keysd & KEY_START)) {
    3.95          SDL_PrivateJoystickButton(joystick, 7, SDL_PRESSED);
    3.96      }
    3.97 -    
    3.98 if ((keysu & KEY_A)) {
    3.99 +    
   3.100     if ((keysu & KEY_A)) {
   3.101          SDL_PrivateJoystickButton(joystick, 0, SDL_RELEASED);
   3.102      }
   3.103 -    
   3.104 if ((keysu & KEY_B)) {
   3.105 +    
   3.106     if ((keysu & KEY_B)) {
   3.107          SDL_PrivateJoystickButton(joystick, 1, SDL_RELEASED);
   3.108      }
   3.109 -    
   3.110 if ((keysu & KEY_X)) {
   3.111 +    
   3.112     if ((keysu & KEY_X)) {
   3.113          SDL_PrivateJoystickButton(joystick, 2, SDL_RELEASED);
   3.114      }
   3.115 -    
   3.116 if ((keysu & KEY_Y)) {
   3.117 +    
   3.118     if ((keysu & KEY_Y)) {
   3.119          SDL_PrivateJoystickButton(joystick, 3, SDL_RELEASED);
   3.120      }
   3.121 -    
   3.122 if ((keysu & KEY_L)) {
   3.123 +    
   3.124     if ((keysu & KEY_L)) {
   3.125          SDL_PrivateJoystickButton(joystick, 4, SDL_RELEASED);
   3.126      }
   3.127 -    
   3.128 if ((keysu & KEY_R)) {
   3.129 +    
   3.130     if ((keysu & KEY_R)) {
   3.131          SDL_PrivateJoystickButton(joystick, 5, SDL_RELEASED);
   3.132      }
   3.133 -    
   3.134 if ((keysu & KEY_SELECT)) {
   3.135 +    
   3.136     if ((keysu & KEY_SELECT)) {
   3.137          SDL_PrivateJoystickButton(joystick, 6, SDL_RELEASED);
   3.138      }
   3.139 -    
   3.140 if ((keysu & KEY_START)) {
   3.141 +    
   3.142     if ((keysu & KEY_START)) {
   3.143          SDL_PrivateJoystickButton(joystick, 7, SDL_RELEASED);
   3.144      }
   3.145  
   3.146 }
   3.147 @@ -170,3 +169,4 @@
   3.148  }
   3.149  
   3.150  #endif /* SDL_JOYSTICK_NDS */
   3.151 +
     4.1 --- a/src/video/nds/SDL_ndsevents.c	Thu Sep 04 13:43:39 2008 +0000
     4.2 +++ b/src/video/nds/SDL_ndsevents.c	Sat Sep 06 00:10:16 2008 +0000
     4.3 @@ -47,7 +47,8 @@
     4.4      }
     4.5      if (keysHeld() & KEY_TOUCH) {
     4.6          touchPosition t = touchReadXY();
     4.7 -        SDL_SendMouseMotion(0, 0, t.px, t.py);
     4.8 +        SDL_SendMouseMotion(0, 0, t.px, t.py, 1); /* last arg is pressure,
     4.9 +                                                     hardcoded 1 for now */
    4.10      }
    4.11  }
    4.12