src/haptic/nds/SDL_syshaptic.c
author Darren Alton <dalton@stevens.edu>
Sat, 06 Sep 2008 04:31:34 +0000
changeset 2750 e3affc66d963
parent 2749 1c5f440a60fe
child 3011 8f4ed5ec2b06
permissions -rw-r--r--
Fixes to the NDS sprite2 test. Illustrates partially working texture-as-sprite functionality.
dalton@2749
     1
/*
dalton@2749
     2
    SDL - Simple DirectMedia Layer
dalton@2749
     3
    Copyright (C) 2008 Edgar Simo
dalton@2749
     4
dalton@2749
     5
    This library is free software; you can redistribute it and/or
dalton@2749
     6
    modify it under the terms of the GNU Lesser General Public
dalton@2749
     7
    License as published by the Free Software Foundation; either
dalton@2749
     8
    version 2.1 of the License, or (at your option) any later version.
dalton@2749
     9
dalton@2749
    10
    This library is distributed in the hope that it will be useful,
dalton@2749
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
dalton@2749
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dalton@2749
    13
    Lesser General Public License for more details.
dalton@2749
    14
dalton@2749
    15
    You should have received a copy of the GNU Lesser General Public
dalton@2749
    16
    License along with this library; if not, write to the Free Software
dalton@2749
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
dalton@2749
    18
dalton@2749
    19
    Sam Lantinga
dalton@2749
    20
    slouken@libsdl.org
dalton@2749
    21
*/
dalton@2749
    22
#include "SDL_config.h"
dalton@2749
    23
dalton@2749
    24
#ifdef SDL_HAPTIC_NDS
dalton@2749
    25
dalton@2749
    26
#include "SDL_haptic.h"
dalton@2749
    27
#include "../SDL_syshaptic.h"
dalton@2749
    28
#include "SDL_joystick.h"
dalton@2749
    29
#include <nds/arm9/rumble.h>
dalton@2749
    30
#include <nds/memory.h>
dalton@2749
    31
dalton@2749
    32
#define MAX_HAPTICS  1
dalton@2749
    33
/* right now only the ezf3in1 (and maybe official rumble pak) are supported
dalton@2749
    34
   and there can only be one of those in at a time (in GBA slot.) */
dalton@2749
    35
dalton@2749
    36
SDL_Haptic *nds_haptic = NULL;
dalton@2749
    37
dalton@2749
    38
typedef struct
dalton@2749
    39
{
dalton@2749
    40
    enum
dalton@2749
    41
    { NONE, OFFICIAL, EZF3IN1 } type;
dalton@2749
    42
    int pos;
dalton@2749
    43
} NDS_HapticData;
dalton@2749
    44
dalton@2749
    45
dalton@2750
    46
dalton@2750
    47
void
dalton@2750
    48
NDS_EZF_OpenNorWrite() 
dalton@2750
    49
{
dalton@2750
    50
    
dalton@2750
    51
GBA_BUS[0x0FF0000] = 0xD200;
dalton@2750
    52
    
dalton@2750
    53
GBA_BUS[0x0000000] = 0x1500;
dalton@2750
    54
    
dalton@2750
    55
GBA_BUS[0x0010000] = 0xD200;
dalton@2749
    56
    
dalton@2750
    57
GBA_BUS[0x0020000] = 0x1500;
dalton@2750
    58
    
dalton@2750
    59
GBA_BUS[0x0E20000] = 0x1500;
dalton@2750
    60
    
dalton@2750
    61
GBA_BUS[0x0FE0000] = 0x1500;
dalton@2750
    62
dalton@2750
    63
} 
dalton@2750
    64
dalton@2750
    65
dalton@2750
    66
void
dalton@2750
    67
dalton@2750
    68
NDS_EZF_CloseNorWrite() 
dalton@2750
    69
{
dalton@2750
    70
    
dalton@2750
    71
GBA_BUS[0x0FF0000] = 0xD200;
dalton@2750
    72
    
dalton@2750
    73
GBA_BUS[0x0000000] = 0x1500;
dalton@2750
    74
    
dalton@2749
    75
GBA_BUS[0x0010000] = 0xD200;
dalton@2749
    76
    
dalton@2749
    77
GBA_BUS[0x0020000] = 0x1500;
dalton@2749
    78
    
dalton@2749
    79
GBA_BUS[0x0E20000] = 0xD200;
dalton@2749
    80
    
dalton@2749
    81
GBA_BUS[0x0FE0000] = 0x1500;
dalton@2749
    82
dalton@2749
    83
}
dalton@2750
    84
dalton@2750
    85
void
dalton@2750
    86
NDS_EZF_ChipReset()
dalton@2750
    87
{
dalton@2750
    88
    
dalton@2750
    89
GBA_BUS[0x0000] = 0x00F0;
dalton@2750
    90
    
dalton@2750
    91
GBA_BUS[0x1000] = 0x00F0;
dalton@2749
    92
} 
dalton@2749
    93
uint32 NDS_EZF_IsPresent() 
dalton@2750
    94
{
dalton@2750
    95
    
dalton@2749
    96
vuint16 id1, id2;
dalton@2750
    97
dalton@2750
    98
    NDS_EZF_OpenNorWrite();
dalton@2750
    99
dalton@2750
   100
    GBA_BUS[0x0555] = 0x00AA;
dalton@2749
   101
    GBA_BUS[0x02AA] = 0x0055;
dalton@2750
   102
    GBA_BUS[0x0555] = 0x0090;
dalton@2750
   103
    GBA_BUS[0x1555] = 0x00AA;
dalton@2750
   104
    GBA_BUS[0x12AA] = 0x0055;
dalton@2750
   105
    GBA_BUS[0x1555] = 0x0090;
dalton@2750
   106
    
dalton@2750
   107
id1 = GBA_BUS[0x0001];
dalton@2750
   108
    
dalton@2749
   109
id2 = GBA_BUS[0x1001];
dalton@2750
   110
    
dalton@2750
   111
if ((id1 != 0x227E) || (id2 != 0x227E)) {
dalton@2750
   112
        NDS_EZF_CloseNorWrite();
dalton@2749
   113
        
dalton@2749
   114
return 0;
dalton@2749
   115
    }
dalton@2749
   116
    
dalton@2749
   117
dalton@2749
   118
id1 = GBA_BUS[0x000E];
dalton@2749
   119
    
dalton@2749
   120
id2 = GBA_BUS[0x100E];
dalton@2749
   121
dalton@2749
   122
    NDS_EZF_CloseNorWrite();
dalton@2749
   123
    
dalton@2749
   124
if (id1 == 0x2218 && id2 == 0x2218) {
dalton@2749
   125
        
dalton@2750
   126
return 1;
dalton@2749
   127
    }
dalton@2749
   128
    
dalton@2749
   129
return 0;
dalton@2750
   130
dalton@2749
   131
}
dalton@2749
   132
dalton@2749
   133
void
dalton@2749
   134
NDS_EZF_SetShake(u8 pos) 
dalton@2749
   135
{
dalton@2749
   136
    u16 data = ((pos % 3) | 0x00F0);
dalton@2749
   137
    
dalton@2749
   138
GBA_BUS[0x0FF0000] = 0xD200;
dalton@2749
   139
    
dalton@2749
   140
GBA_BUS[0x0000000] = 0x1500;
dalton@2749
   141
    
dalton@2749
   142
GBA_BUS[0x0010000] = 0xD200;
dalton@2749
   143
    
dalton@2749
   144
GBA_BUS[0x0020000] = 0x1500;
dalton@2749
   145
    
dalton@2750
   146
GBA_BUS[0x0F10000] = data;
dalton@2750
   147
    
dalton@2750
   148
GBA_BUS[0x0FE0000] = 0x1500;
dalton@2750
   149
dalton@2750
   150
    GBA_BUS[0] = 0x0000;        /* write any value for vibration. */
dalton@2750
   151
    GBA_BUS[0] = 0x0002;
dalton@2750
   152
dalton@2750
   153
}
dalton@2749
   154
dalton@2749
   155
static int
dalton@2749
   156
SDL_SYS_LogicError(void)
dalton@2749
   157
{
dalton@2749
   158
    SDL_SetError("Logic error: No haptic devices available.");
dalton@2749
   159
    return 0;
dalton@2749
   160
}
dalton@2749
   161
dalton@2749
   162
dalton@2750
   163
int
dalton@2749
   164
SDL_SYS_HapticInit(void)
dalton@2749
   165
{
dalton@2749
   166
    int ret = 0;
dalton@2749
   167
    if (isRumbleInserted()) {
dalton@2750
   168
        /* official rumble pak is present. */
dalton@2749
   169
        ret = 1;
dalton@2749
   170
        printf("debug: haptic present: nintendo\n");
dalton@2749
   171
    } else if (NDS_EZF_IsPresent()) {
dalton@2749
   172
        /* ezflash 3-in-1 pak is present. */
dalton@2749
   173
        ret = 1;
dalton@2749
   174
        printf("debug: haptic present: ezf3in1\n");
dalton@2749
   175
        NDS_EZF_ChipReset();
dalton@2749
   176
    } else {
dalton@2749
   177
        printf("debug: no haptic found\n");
dalton@2750
   178
    }
dalton@2749
   179
dalton@2749
   180
    return ret;
dalton@2750
   181
}
dalton@2749
   182
dalton@2749
   183
dalton@2749
   184
const char *
dalton@2749
   185
SDL_SYS_HapticName(int index)
dalton@2749
   186
{
dalton@2749
   187
    if (nds_haptic) {
dalton@2749
   188
        switch (nds_haptic->hwdata->type) {
dalton@2749
   189
        case OFFICIAL:
dalton@2749
   190
            return "Nintendo DS Rumble Pak";
dalton@2749
   191
        case EZF3IN1:
dalton@2749
   192
            return "EZFlash 3-in-1 Rumble";
dalton@2749
   193
        default:
dalton@2749
   194
            return NULL;
dalton@2749
   195
        }
dalton@2749
   196
    }
dalton@2749
   197
    return NULL;
dalton@2749
   198
}
dalton@2749
   199
dalton@2749
   200
dalton@2749
   201
int
dalton@2749
   202
SDL_SYS_HapticOpen(SDL_Haptic * haptic)
dalton@2749
   203
{
dalton@2749
   204
    if (!haptic) {
dalton@2749
   205
        return -1;
dalton@2749
   206
    }
dalton@2749
   207
dalton@2749
   208
    haptic->hwdata = SDL_malloc(sizeof(NDS_HapticData));
dalton@2749
   209
    if (!haptic->hwdata) {
dalton@2749
   210
        SDL_OutOfMemory();
dalton@2749
   211
        return -1;
dalton@2750
   212
    }
dalton@2749
   213
    nds_haptic = haptic;
dalton@2749
   214
dalton@2749
   215
    haptic->supported = SDL_HAPTIC_CONSTANT;
dalton@2749
   216
dalton@2749
   217
    /* determine what is here, if anything */
dalton@2749
   218
    haptic->hwdata->type = NONE;
dalton@2749
   219
    if (isRumbleInserted()) {
dalton@2749
   220
        /* official rumble pak is present. */
dalton@2749
   221
        haptic->hwdata->type = OFFICIAL;
dalton@2749
   222
    } else if (NDS_EZF_IsPresent()) {
dalton@2749
   223
        /* ezflash 3-in-1 pak is present. */
dalton@2749
   224
        haptic->hwdata->type = EZF3IN1;
dalton@2749
   225
        NDS_EZF_ChipReset();
dalton@2749
   226
    } else {
dalton@2749
   227
        /* no haptic present */
dalton@2749
   228
        SDL_SYS_LogicError();
dalton@2749
   229
        return -1;
dalton@2749
   230
    }
dalton@2749
   231
dalton@2749
   232
    return 0;
dalton@2749
   233
}
dalton@2749
   234
dalton@2749
   235
dalton@2749
   236
int
dalton@2749
   237
SDL_SYS_HapticMouse(void)
dalton@2749
   238
{
dalton@2749
   239
    return -1;
dalton@2749
   240
}
dalton@2749
   241
dalton@2749
   242
dalton@2749
   243
int
dalton@2749
   244
SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
dalton@2749
   245
{
dalton@2749
   246
    return 0;
dalton@2749
   247
}
dalton@2749
   248
dalton@2749
   249
dalton@2749
   250
int
dalton@2749
   251
SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
dalton@2749
   252
{
dalton@2749
   253
    /*SDL_SYS_LogicError(); */
dalton@2749
   254
    return -1;
dalton@2749
   255
}
dalton@2749
   256
dalton@2749
   257
dalton@2749
   258
int
dalton@2749
   259
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
dalton@2749
   260
{
dalton@2749
   261
    return 0;
dalton@2749
   262
}
dalton@2749
   263
dalton@2749
   264
dalton@2749
   265
void
dalton@2749
   266
SDL_SYS_HapticClose(SDL_Haptic * haptic)
dalton@2749
   267
{
dalton@2749
   268
    return;
dalton@2749
   269
}
dalton@2749
   270
dalton@2749
   271
dalton@2749
   272
void
dalton@2749
   273
SDL_SYS_HapticQuit(void)
dalton@2749
   274
{
dalton@2749
   275
    return;
dalton@2749
   276
}
dalton@2749
   277
dalton@2749
   278
dalton@2749
   279
int
dalton@2749
   280
SDL_SYS_HapticNewEffect(SDL_Haptic * haptic,
dalton@2749
   281
                        struct haptic_effect *effect, SDL_HapticEffect * base)
dalton@2749
   282
{
dalton@2749
   283
    SDL_SYS_LogicError();
dalton@2749
   284
    return -1;
dalton@2749
   285
}
dalton@2749
   286
dalton@2749
   287
dalton@2749
   288
int
dalton@2749
   289
SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
dalton@2749
   290
                           struct haptic_effect *effect,
dalton@2749
   291
                           SDL_HapticEffect * data)
dalton@2749
   292
{
dalton@2749
   293
    SDL_SYS_LogicError();
dalton@2749
   294
    return -1;
dalton@2749
   295
}
dalton@2749
   296
dalton@2749
   297
dalton@2749
   298
int
dalton@2749
   299
SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
dalton@2749
   300
                        Uint32 iterations)
dalton@2749
   301
{
dalton@2749
   302
    SDL_SYS_LogicError();
dalton@2749
   303
    return -1;
dalton@2749
   304
}
dalton@2749
   305
dalton@2749
   306
dalton@2749
   307
int
dalton@2749
   308
SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
dalton@2749
   309
{
dalton@2749
   310
    SDL_SYS_LogicError();
dalton@2749
   311
    return -1;
dalton@2749
   312
}
dalton@2749
   313
dalton@2749
   314
dalton@2749
   315
void
dalton@2749
   316
SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
dalton@2749
   317
{
dalton@2749
   318
    SDL_SYS_LogicError();
dalton@2749
   319
    return;
dalton@2749
   320
}
dalton@2749
   321
dalton@2749
   322
dalton@2749
   323
int
dalton@2749
   324
SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
dalton@2749
   325
                              struct haptic_effect *effect)
dalton@2749
   326
{
dalton@2749
   327
    SDL_SYS_LogicError();
dalton@2749
   328
    return -1;
dalton@2749
   329
}
dalton@2749
   330
dalton@2750
   331
dalton@2750
   332
int
dalton@2750
   333
SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
dalton@2750
   334
{
dalton@2750
   335
    SDL_SYS_LogicError();
dalton@2750
   336
    return -1;
dalton@2750
   337
}
dalton@2750
   338
dalton@2750
   339
dalton@2750
   340
int
dalton@2750
   341
SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
dalton@2750
   342
{
dalton@2750
   343
    SDL_SYS_LogicError();
dalton@2750
   344
    return -1;
dalton@2750
   345
}
dalton@2750
   346
dalton@2750
   347
int
dalton@2750
   348
SDL_SYS_HapticPause(SDL_Haptic * haptic)
dalton@2750
   349
{
dalton@2750
   350
    SDL_SYS_LogicError();
dalton@2750
   351
    return -1;
dalton@2750
   352
}
dalton@2750
   353
dalton@2750
   354
int
dalton@2750
   355
SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
dalton@2750
   356
{
dalton@2750
   357
    SDL_SYS_LogicError();
dalton@2750
   358
    return -1;
dalton@2750
   359
}
dalton@2750
   360
dalton@2750
   361
int
dalton@2750
   362
SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
dalton@2750
   363
{
dalton@2750
   364
    SDL_SYS_LogicError();
dalton@2750
   365
    return -1;
dalton@2750
   366
}
dalton@2750
   367
dalton@2750
   368
dalton@2750
   369
dalton@2750
   370
#endif /* SDL_HAPTIC_NDS */
dalton@2750
   371
/* vi: set ts=4 sw=4 expandtab: */