2 * Copyright (c) 2009, Wei Mingzhi <whistler@openoffice.org>.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program 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
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses>.
24 g.PadState[0].JoyKeyStatus = 0xFFFF;
25 g.PadState[1].JoyKeyStatus = 0xFFFF;
27 for (i = 0; i < 2; i++) {
28 if (g.cfg.PadDef[i].DevNum >= 0) {
29 g.PadState[i].JoyDev = SDL_JoystickOpen(g.cfg.PadDef[i].DevNum);
31 g.PadState[i].JoyDev = NULL;
35 SDL_JoystickEventState(SDL_IGNORE);
40 void DestroySDLJoy() {
43 if (SDL_WasInit(SDL_INIT_JOYSTICK)) {
44 for (i = 0; i < 2; i++) {
45 if (g.PadState[i].JoyDev != NULL) {
46 SDL_JoystickClose(g.PadState[i].JoyDev);
51 for (i = 0; i < 2; i++) {
52 g.PadState[i].JoyDev = NULL;
61 for (i = 0; i < 2; i++) {
62 if (g.PadState[i].JoyDev == NULL) {
66 for (j = 0; j < DKEY_TOTAL; j++) {
67 switch (g.cfg.PadDef[i].KeyDef[j].JoyEvType) {
69 n = abs(g.cfg.PadDef[i].KeyDef[j].J.Axis) - 1;
71 if (g.cfg.PadDef[i].KeyDef[j].J.Axis > 0) {
72 if (SDL_JoystickGetAxis(g.PadState[i].JoyDev, n) > 16383) {
73 g.PadState[i].JoyKeyStatus &= ~(1 << j);
75 g.PadState[i].JoyKeyStatus |= (1 << j);
77 } else if (g.cfg.PadDef[i].KeyDef[j].J.Axis < 0) {
78 if (SDL_JoystickGetAxis(g.PadState[i].JoyDev, n) < -16383) {
79 g.PadState[i].JoyKeyStatus &= ~(1 << j);
81 g.PadState[i].JoyKeyStatus |= (1 << j);
87 n = (g.cfg.PadDef[i].KeyDef[j].J.Hat >> 8);
89 if (SDL_JoystickGetHat(g.PadState[i].JoyDev, n) & (g.cfg.PadDef[i].KeyDef[j].J.Hat & 0xFF)) {
90 g.PadState[i].JoyKeyStatus &= ~(1 << j);
92 g.PadState[i].JoyKeyStatus |= (1 << j);
97 if (SDL_JoystickGetButton(g.PadState[i].JoyDev, g.cfg.PadDef[i].KeyDef[j].J.Button)) {
98 g.PadState[i].JoyKeyStatus &= ~(1 << j);
100 g.PadState[i].JoyKeyStatus |= (1 << j);