From 7d0f136239c4dcee9f27adf9f7a8c262fcbfe95f Mon Sep 17 00:00:00 2001 From: "SND\\weimingzhi_cp" Date: Sun, 25 Oct 2009 14:21:02 +0000 Subject: git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@32889 e17a0e51-4ae3-4d35-97c3-1a29b211df97 --- plugins/dfinput/sdljoy.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 plugins/dfinput/sdljoy.c (limited to 'plugins/dfinput/sdljoy.c') diff --git a/plugins/dfinput/sdljoy.c b/plugins/dfinput/sdljoy.c new file mode 100644 index 00000000..2a80cfa8 --- /dev/null +++ b/plugins/dfinput/sdljoy.c @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2009, Wei Mingzhi . + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "pad.h" + +void InitSDLJoy() { + uint8_t i; + + g.PadState[0].JoyKeyStatus = 0xFFFF; + g.PadState[1].JoyKeyStatus = 0xFFFF; + + for (i = 0; i < 2; i++) { + if (g.cfg.PadDef[i].DevNum >= 0) { + g.PadState[i].JoyDev = SDL_JoystickOpen(g.cfg.PadDef[i].DevNum); + } else { + g.PadState[i].JoyDev = NULL; + } + } + + SDL_JoystickEventState(SDL_IGNORE); + + InitAnalog(); +} + +void DestroySDLJoy() { + uint8_t i; + + if (SDL_WasInit(SDL_INIT_JOYSTICK)) { + for (i = 0; i < 2; i++) { + if (g.PadState[i].JoyDev != NULL) { + SDL_JoystickClose(g.PadState[i].JoyDev); + } + } + } + + for (i = 0; i < 2; i++) { + g.PadState[i].JoyDev = NULL; + } +} + +void CheckJoy() { + uint8_t i, j, n; + int dx, dy; + + SDL_JoystickUpdate(); + + for (i = 0; i < 2; i++) { + if (g.PadState[i].JoyDev == NULL) { + continue; + } + + for (j = 0; j < DKEY_TOTAL; j++) { + switch (g.cfg.PadDef[i].KeyDef[j].JoyEvType) { + case AXIS: + n = abs(g.cfg.PadDef[i].KeyDef[j].J.Axis) - 1; + + if (g.cfg.PadDef[i].KeyDef[j].J.Axis > 0) { + if (SDL_JoystickGetAxis(g.PadState[i].JoyDev, n) > 16383) { + g.PadState[i].JoyKeyStatus &= ~(1 << j); + } else { + g.PadState[i].JoyKeyStatus |= (1 << j); + } + } else if (g.cfg.PadDef[i].KeyDef[j].J.Axis < 0) { + if (SDL_JoystickGetAxis(g.PadState[i].JoyDev, n) < -16383) { + g.PadState[i].JoyKeyStatus &= ~(1 << j); + } else { + g.PadState[i].JoyKeyStatus |= (1 << j); + } + } + break; + + case HAT: + n = (g.cfg.PadDef[i].KeyDef[j].J.Hat >> 8); + + if (SDL_JoystickGetHat(g.PadState[i].JoyDev, n) & (g.cfg.PadDef[i].KeyDef[j].J.Hat & 0xFF)) { + g.PadState[i].JoyKeyStatus &= ~(1 << j); + } else { + g.PadState[i].JoyKeyStatus |= (1 << j); + } + break; + + case BUTTON: + if (SDL_JoystickGetButton(g.PadState[i].JoyDev, g.cfg.PadDef[i].KeyDef[j].J.Button)) { + g.PadState[i].JoyKeyStatus &= ~(1 << j); + } else { + g.PadState[i].JoyKeyStatus |= (1 << j); + } + break; + + default: + break; + } + } + } + + CheckAnalog(); +} -- cgit v1.2.3