src/joystick/nds/SDL_sysjoystick.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 15 Feb 2011 16:41:04 -0800
changeset 5301 248c5c7d6e29
parent 5262 b530ef003506
child 5535 96594ac5fd1a
permissions -rw-r--r--
Patch to fix includes from Frank Zago
slouken@2735
     1
/*
slouken@2735
     2
    SDL - Simple DirectMedia Layer
slouken@5262
     3
    Copyright (C) 1997-2011 Sam Lantinga
slouken@2735
     4
slouken@2735
     5
    This library is free software; you can redistribute it and/or
slouken@3697
     6
    modify it under the terms of the GNU Lesser General Public
slouken@2735
     7
    License as published by the Free Software Foundation; either
slouken@3697
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@2735
     9
slouken@2735
    10
    This library is distributed in the hope that it will be useful,
slouken@2735
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@2735
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@3697
    13
    Lesser General Public License for more details.
slouken@2735
    14
slouken@3697
    15
    You should have received a copy of the GNU Lesser General Public
slouken@3697
    16
    License along with this library; if not, write to the Free Software
slouken@3697
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@2735
    18
slouken@2735
    19
    Sam Lantinga
slouken@3697
    20
    slouken@libsdl.org
slouken@2735
    21
*/
slouken@2735
    22
slouken@2735
    23
#include "SDL_config.h"
slouken@2735
    24
slouken@2735
    25
#ifdef SDL_JOYSTICK_NDS
slouken@2735
    26
slouken@2735
    27
/* This is the system specific header for the SDL joystick API */
slouken@2735
    28
#include <nds.h>
slouken@2735
    29
#include <stdio.h>              /* For the definition of NULL */
slouken@2735
    30
slouken@2735
    31
#include "SDL_error.h"
slouken@2735
    32
#include "SDL_events.h"
slouken@2735
    33
#include "SDL_joystick.h"
slouken@5301
    34
#include "../SDL_sysjoystick.h"
slouken@5301
    35
#include "../SDL_joystick_c.h"
slouken@2735
    36
slouken@2735
    37
#include "../../video/nds/SDL_ndsevents_c.h"
slouken@2735
    38
slouken@2735
    39
/* Function to scan the system for joysticks.
slouken@2735
    40
 * This function should set SDL_numjoysticks to the number of available
slouken@2735
    41
 * joysticks.  Joystick 0 should be the system default joystick.
slouken@2735
    42
 * It should return 0, or -1 on an unrecoverable fatal error.
slouken@2735
    43
 */
slouken@2735
    44
int
slouken@2735
    45
SDL_SYS_JoystickInit(void)
slouken@2735
    46
{
dalton@2750
    47
    SDL_numjoysticks = 1;
slouken@4761
    48
    return (1);
slouken@2735
    49
}
slouken@2735
    50
slouken@2735
    51
/* Function to get the device-dependent name of a joystick */
slouken@2735
    52
const char *
slouken@2735
    53
SDL_SYS_JoystickName(int index)
slouken@2735
    54
{
slouken@2735
    55
    if (!index)
slouken@2735
    56
        return "NDS builtin joypad";
slouken@2735
    57
    SDL_SetError("No joystick available with that index");
slouken@2735
    58
    return (NULL);
slouken@2735
    59
}
slouken@2735
    60
slouken@2735
    61
/* Function to open a joystick for use.
slouken@2735
    62
   The joystick to open is specified by the index field of the joystick.
slouken@2735
    63
   This should fill the nbuttons and naxes fields of the joystick structure.
slouken@2735
    64
   It returns 0, or -1 if there is an error.
slouken@2735
    65
 */
slouken@2735
    66
int
slouken@2735
    67
SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
slouken@2735
    68
{
slouken@2735
    69
    joystick->nbuttons = 8;
slouken@2735
    70
    joystick->nhats = 0;
slouken@2735
    71
    joystick->nballs = 0;
slouken@2735
    72
    joystick->naxes = 2;
slouken@2735
    73
    return 0;
slouken@2735
    74
}
slouken@2735
    75
slouken@4761
    76
slouken@2735
    77
/* Function to update the state of a joystick - called as a device poll.
slouken@2735
    78
 * This function shouldn't update the joystick structure directly,
slouken@2735
    79
 * but instead should call SDL_PrivateJoystick*() to deliver events
slouken@2735
    80
 * and update joystick device state.
slouken@2735
    81
 */
dalton@2750
    82
    void
slouken@2735
    83
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
slouken@2735
    84
{
slouken@2735
    85
    u32 keysd, keysu;
slouken@2735
    86
    int magnitude = 16384;
slouken@4761
    87
    
slouken@4761
    88
        /*scanKeys(); - this is done in PumpEvents, because touch uses it too */ 
dalton@2750
    89
        keysd = keysDown();
slouken@2735
    90
    keysu = keysUp();
slouken@2735
    91
slouken@2735
    92
    if ((keysd & KEY_UP)) {
slouken@2735
    93
        SDL_PrivateJoystickAxis(joystick, 1, -magnitude);
slouken@2735
    94
    }
slouken@2735
    95
    if ((keysd & KEY_DOWN)) {
slouken@2735
    96
        SDL_PrivateJoystickAxis(joystick, 1, magnitude);
slouken@2735
    97
    }
slouken@2735
    98
    if ((keysd & KEY_LEFT)) {
slouken@2735
    99
        SDL_PrivateJoystickAxis(joystick, 0, -magnitude);
slouken@2735
   100
    }
slouken@2735
   101
    if ((keysd & KEY_RIGHT)) {
slouken@2735
   102
        SDL_PrivateJoystickAxis(joystick, 0, magnitude);
slouken@2735
   103
    }
slouken@4761
   104
    if ((keysu & (KEY_UP | KEY_DOWN))) {
slouken@2735
   105
        SDL_PrivateJoystickAxis(joystick, 1, 0);
slouken@2735
   106
    }
slouken@4761
   107
    if ((keysu & (KEY_LEFT | KEY_RIGHT))) {
slouken@2735
   108
        SDL_PrivateJoystickAxis(joystick, 0, 0);
slouken@2735
   109
    }
slouken@4761
   110
    if ((keysd & KEY_A)) {
slouken@2735
   111
        SDL_PrivateJoystickButton(joystick, 0, SDL_PRESSED);
slouken@2735
   112
    }
slouken@4761
   113
    if ((keysd & KEY_B)) {
slouken@2735
   114
        SDL_PrivateJoystickButton(joystick, 1, SDL_PRESSED);
slouken@2735
   115
    }
slouken@4761
   116
    if ((keysd & KEY_X)) {
slouken@2735
   117
        SDL_PrivateJoystickButton(joystick, 2, SDL_PRESSED);
slouken@2735
   118
    }
slouken@4761
   119
    if ((keysd & KEY_Y)) {
slouken@2735
   120
        SDL_PrivateJoystickButton(joystick, 3, SDL_PRESSED);
slouken@2735
   121
    }
slouken@4761
   122
    if ((keysd & KEY_L)) {
slouken@2735
   123
        SDL_PrivateJoystickButton(joystick, 4, SDL_PRESSED);
slouken@2735
   124
    }
slouken@4761
   125
    if ((keysd & KEY_R)) {
slouken@2735
   126
        SDL_PrivateJoystickButton(joystick, 5, SDL_PRESSED);
slouken@2735
   127
    }
slouken@4761
   128
    if ((keysd & KEY_SELECT)) {
slouken@2735
   129
        SDL_PrivateJoystickButton(joystick, 6, SDL_PRESSED);
slouken@2735
   130
    }
slouken@4761
   131
    if ((keysd & KEY_START)) {
slouken@2735
   132
        SDL_PrivateJoystickButton(joystick, 7, SDL_PRESSED);
slouken@2735
   133
    }
slouken@4761
   134
    if ((keysu & KEY_A)) {
slouken@2735
   135
        SDL_PrivateJoystickButton(joystick, 0, SDL_RELEASED);
slouken@2735
   136
    }
slouken@4761
   137
    if ((keysu & KEY_B)) {
slouken@2735
   138
        SDL_PrivateJoystickButton(joystick, 1, SDL_RELEASED);
slouken@2735
   139
    }
slouken@4761
   140
    if ((keysu & KEY_X)) {
slouken@2735
   141
        SDL_PrivateJoystickButton(joystick, 2, SDL_RELEASED);
slouken@2735
   142
    }
slouken@4761
   143
    if ((keysu & KEY_Y)) {
slouken@2735
   144
        SDL_PrivateJoystickButton(joystick, 3, SDL_RELEASED);
slouken@2735
   145
    }
slouken@4761
   146
    if ((keysu & KEY_L)) {
slouken@2735
   147
        SDL_PrivateJoystickButton(joystick, 4, SDL_RELEASED);
slouken@2735
   148
    }
slouken@4761
   149
    if ((keysu & KEY_R)) {
slouken@2735
   150
        SDL_PrivateJoystickButton(joystick, 5, SDL_RELEASED);
slouken@2735
   151
    }
slouken@4761
   152
    if ((keysu & KEY_SELECT)) {
slouken@2735
   153
        SDL_PrivateJoystickButton(joystick, 6, SDL_RELEASED);
slouken@2735
   154
    }
slouken@4761
   155
    if ((keysu & KEY_START)) {
slouken@2735
   156
        SDL_PrivateJoystickButton(joystick, 7, SDL_RELEASED);
slouken@2735
   157
    }
slouken@4761
   158
}
slouken@2735
   159
slouken@2735
   160
/* Function to close a joystick after use */
slouken@2735
   161
void
slouken@2735
   162
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
slouken@2735
   163
{
slouken@2735
   164
}
slouken@2735
   165
slouken@2735
   166
/* Function to perform any system-specific joystick related cleanup */
slouken@2735
   167
void
slouken@2735
   168
SDL_SYS_JoystickQuit(void)
slouken@2735
   169
{
slouken@2735
   170
}
slouken@2735
   171
slouken@2735
   172
#endif /* SDL_JOYSTICK_NDS */