From 6039eb05ba6d82ef56f2868c96654c552d117bf9 Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Wed, 7 Feb 2018 20:04:46 -0500 Subject: sdl: remove non-rockbox drivers We never use any of these other drivers, so having them around just takes up space. Change-Id: Iced812162df1fef3fd55522b7e700acb6c3bcd41 --- .../sdl/src/joystick/beos/SDL_bejoystick.cc | 237 ---- .../plugins/sdl/src/joystick/bsd/SDL_sysjoystick.c | 608 ---------- .../sdl/src/joystick/darwin/SDL_sysjoystick.c | 842 -------------- apps/plugins/sdl/src/joystick/dc/SDL_sysjoystick.c | 193 ---- .../sdl/src/joystick/linux/SDL_sysjoystick.c | 1218 -------------------- .../sdl/src/joystick/macos/SDL_sysjoystick.c | 320 ----- .../sdl/src/joystick/mint/SDL_sysjoystick.c | 826 ------------- .../plugins/sdl/src/joystick/nds/SDL_sysjoystick.c | 150 --- .../sdl/src/joystick/riscos/SDL_sysjoystick.c | 176 --- .../sdl/src/joystick/win32/SDL_mmjoystick.c | 407 ------- 10 files changed, 4977 deletions(-) delete mode 100644 apps/plugins/sdl/src/joystick/beos/SDL_bejoystick.cc delete mode 100644 apps/plugins/sdl/src/joystick/bsd/SDL_sysjoystick.c delete mode 100644 apps/plugins/sdl/src/joystick/darwin/SDL_sysjoystick.c delete mode 100644 apps/plugins/sdl/src/joystick/dc/SDL_sysjoystick.c delete mode 100644 apps/plugins/sdl/src/joystick/linux/SDL_sysjoystick.c delete mode 100644 apps/plugins/sdl/src/joystick/macos/SDL_sysjoystick.c delete mode 100644 apps/plugins/sdl/src/joystick/mint/SDL_sysjoystick.c delete mode 100644 apps/plugins/sdl/src/joystick/nds/SDL_sysjoystick.c delete mode 100644 apps/plugins/sdl/src/joystick/riscos/SDL_sysjoystick.c delete mode 100644 apps/plugins/sdl/src/joystick/win32/SDL_mmjoystick.c (limited to 'apps/plugins/sdl/src/joystick') diff --git a/apps/plugins/sdl/src/joystick/beos/SDL_bejoystick.cc b/apps/plugins/sdl/src/joystick/beos/SDL_bejoystick.cc deleted file mode 100644 index af8a34164b..0000000000 --- a/apps/plugins/sdl/src/joystick/beos/SDL_bejoystick.cc +++ /dev/null @@ -1,237 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#ifdef SDL_JOYSTICK_BEOS - -/* This is the system specific header for the SDL joystick API */ - -#include -#include - -extern "C" { - -#include "SDL_joystick.h" -#include "../SDL_sysjoystick.h" -#include "../SDL_joystick_c.h" - - -/* The maximum number of joysticks we'll detect */ -#define MAX_JOYSTICKS 16 - -/* A list of available joysticks */ -static char *SDL_joyport[MAX_JOYSTICKS]; -static char *SDL_joyname[MAX_JOYSTICKS]; - -/* The private structure used to keep track of a joystick */ -struct joystick_hwdata { - BJoystick *stick; - uint8 *new_hats; - int16 *new_axes; -}; - -/* Function to scan the system for joysticks. - * This function should set SDL_numjoysticks to the number of available - * joysticks. Joystick 0 should be the system default joystick. - * It should return 0, or -1 on an unrecoverable fatal error. - */ -int SDL_SYS_JoystickInit(void) -{ - BJoystick joystick; - int numjoysticks; - int i; - int32 nports; - char name[B_OS_NAME_LENGTH]; - - /* Search for attached joysticks */ - nports = joystick.CountDevices(); - numjoysticks = 0; - SDL_memset(SDL_joyport, 0, (sizeof SDL_joyport)); - SDL_memset(SDL_joyname, 0, (sizeof SDL_joyname)); - for ( i=0; (SDL_numjoysticks < MAX_JOYSTICKS) && (i < nports); ++i ) { - if ( joystick.GetDeviceName(i, name) == B_OK ) { - if ( joystick.Open(name) != B_ERROR ) { - BString stick_name; - joystick.GetControllerName(&stick_name); - SDL_joyport[numjoysticks] = strdup(name); - SDL_joyname[numjoysticks] = - strdup(stick_name.String()); - numjoysticks++; - joystick.Close(); - } - } - } - return(numjoysticks); -} - -/* Function to get the device-dependent name of a joystick */ -const char *SDL_SYS_JoystickName(int index) -{ - return SDL_joyname[index]; -} - -/* Function to open a joystick for use. - The joystick to open is specified by the index field of the joystick. - This should fill the nbuttons and naxes fields of the joystick structure. - It returns 0, or -1 if there is an error. - */ -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) -{ - BJoystick *stick; - - /* Create the joystick data structure */ - joystick->hwdata = (struct joystick_hwdata *) - SDL_malloc(sizeof(*joystick->hwdata)); - if ( joystick->hwdata == NULL ) { - SDL_OutOfMemory(); - return(-1); - } - SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); - stick = new BJoystick; - joystick->hwdata->stick = stick; - - /* Open the requested joystick for use */ - if ( stick->Open(SDL_joyport[joystick->index]) == B_ERROR ) { - SDL_SetError("Unable to open joystick"); - SDL_SYS_JoystickClose(joystick); - return(-1); - } - - /* Set the joystick to calibrated mode */ - stick->EnableCalibration(); - - /* Get the number of buttons, hats, and axes on the joystick */ - joystick->nbuttons = stick->CountButtons(); - joystick->naxes = stick->CountAxes(); - joystick->nhats = stick->CountHats(); - - joystick->hwdata->new_axes = (int16 *) - SDL_malloc(joystick->naxes*sizeof(int16)); - joystick->hwdata->new_hats = (uint8 *) - SDL_malloc(joystick->nhats*sizeof(uint8)); - if ( ! joystick->hwdata->new_hats || ! joystick->hwdata->new_axes ) { - SDL_OutOfMemory(); - SDL_SYS_JoystickClose(joystick); - return(-1); - } - - /* We're done! */ - return(0); -} - -/* Function to update the state of a joystick - called as a device poll. - * This function shouldn't update the joystick structure directly, - * but instead should call SDL_PrivateJoystick*() to deliver events - * and update joystick device state. - */ -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) -{ - static const Uint8 hat_map[9] = { - SDL_HAT_CENTERED, - SDL_HAT_UP, - SDL_HAT_RIGHTUP, - SDL_HAT_RIGHT, - SDL_HAT_RIGHTDOWN, - SDL_HAT_DOWN, - SDL_HAT_LEFTDOWN, - SDL_HAT_LEFT, - SDL_HAT_LEFTUP - }; - const int JITTER = (32768/10); /* 10% jitter threshold (ok?) */ - - BJoystick *stick; - int i, change; - int16 *axes; - uint8 *hats; - uint32 buttons; - - /* Set up data pointers */ - stick = joystick->hwdata->stick; - axes = joystick->hwdata->new_axes; - hats = joystick->hwdata->new_hats; - - /* Get the new joystick state */ - stick->Update(); - stick->GetAxisValues(axes); - stick->GetHatValues(hats); - buttons = stick->ButtonValues(); - - /* Generate axis motion events */ - for ( i=0; inaxes; ++i ) { - change = ((int32)axes[i] - joystick->axes[i]); - if ( (change > JITTER) || (change < -JITTER) ) { - SDL_PrivateJoystickAxis(joystick, i, axes[i]); - } - } - - /* Generate hat change events */ - for ( i=0; inhats; ++i ) { - if ( hats[i] != joystick->hats[i] ) { - SDL_PrivateJoystickHat(joystick, i, hat_map[hats[i]]); - } - } - - /* Generate button events */ - for ( i=0; inbuttons; ++i ) { - if ( (buttons&0x01) != joystick->buttons[i] ) { - SDL_PrivateJoystickButton(joystick, i, (buttons&0x01)); - } - buttons >>= 1; - } -} - -/* Function to close a joystick after use */ -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) -{ - if ( joystick->hwdata ) { - joystick->hwdata->stick->Close(); - delete joystick->hwdata->stick; - if ( joystick->hwdata->new_hats ) { - SDL_free(joystick->hwdata->new_hats); - } - if ( joystick->hwdata->new_axes ) { - SDL_free(joystick->hwdata->new_axes); - } - SDL_free(joystick->hwdata); - joystick->hwdata = NULL; - } -} - -/* Function to perform any system-specific joystick related cleanup */ -void SDL_SYS_JoystickQuit(void) -{ - int i; - - for ( i=0; SDL_joyport[i]; ++i ) { - SDL_free(SDL_joyport[i]); - } - SDL_joyport[0] = NULL; - - for ( i=0; SDL_joyname[i]; ++i ) { - SDL_free(SDL_joyname[i]); - } - SDL_joyname[0] = NULL; -} - -}; // extern "C" - -#endif /* SDL_JOYSTICK_BEOS */ diff --git a/apps/plugins/sdl/src/joystick/bsd/SDL_sysjoystick.c b/apps/plugins/sdl/src/joystick/bsd/SDL_sysjoystick.c deleted file mode 100644 index 500fc62951..0000000000 --- a/apps/plugins/sdl/src/joystick/bsd/SDL_sysjoystick.c +++ /dev/null @@ -1,608 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#ifdef SDL_JOYSTICK_USBHID - -/* - * Joystick driver for the uhid(4) interface found in OpenBSD, - * NetBSD and FreeBSD. - * - * Maintainer: - */ - -#include - -#include -#include -#include - -#ifndef __FreeBSD_kernel_version -#define __FreeBSD_kernel_version __FreeBSD_version -#endif - -#if defined(HAVE_USB_H) -#include -#endif -#ifdef __DragonFly__ -#include -#include -#else -#include -#include -#endif - -#if defined(HAVE_USBHID_H) -#include -#elif defined(HAVE_LIBUSB_H) -#include -#elif defined(HAVE_LIBUSBHID_H) -#include -#endif - -#if defined(__FREEBSD__) || defined(__FreeBSD_kernel__) -#ifndef __DragonFly__ -#include -#endif -#if __FreeBSD_kernel_version > 800063 -#include -#endif -#include -#endif - -#if SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H -#include -#endif - -#include "SDL_joystick.h" -#include "../SDL_sysjoystick.h" -#include "../SDL_joystick_c.h" - -#define MAX_UHID_JOYS 4 -#define MAX_JOY_JOYS 2 -#define MAX_JOYS (MAX_UHID_JOYS + MAX_JOY_JOYS) - -struct report { -#if defined(__FREEBSD__) && (__FreeBSD_kernel_version > 800063) - struct usb_gen_descriptor *buf; /* Buffer */ -#else - struct usb_ctl_report *buf; /* Buffer */ -#endif - size_t size; /* Buffer size */ - int rid; /* Report ID */ - enum { - SREPORT_UNINIT, - SREPORT_CLEAN, - SREPORT_DIRTY - } status; -}; - -static struct { - int uhid_report; - hid_kind_t kind; - const char *name; -} const repinfo[] = { - { UHID_INPUT_REPORT, hid_input, "input" }, - { UHID_OUTPUT_REPORT, hid_output, "output" }, - { UHID_FEATURE_REPORT, hid_feature, "feature" } -}; - -enum { - REPORT_INPUT = 0, - REPORT_OUTPUT = 1, - REPORT_FEATURE = 2 -}; - -enum { - JOYAXE_X, - JOYAXE_Y, - JOYAXE_Z, - JOYAXE_SLIDER, - JOYAXE_WHEEL, - JOYAXE_RX, - JOYAXE_RY, - JOYAXE_RZ, - JOYAXE_count -}; - -struct joystick_hwdata { - int fd; - char *path; - enum { - BSDJOY_UHID, /* uhid(4) */ - BSDJOY_JOY /* joy(4) */ - } type; - struct report_desc *repdesc; - struct report inreport; - int axis_map[JOYAXE_count]; /* map present JOYAXE_* to 0,1,..*/ - int x; - int y; - int xmin; - int ymin; - int xmax; - int ymax; -}; - -static char *joynames[MAX_JOYS]; -static char *joydevnames[MAX_JOYS]; - -static int report_alloc(struct report *, struct report_desc *, int); -static void report_free(struct report *); - -#if defined(USBHID_UCR_DATA) || defined(__FreeBSD_kernel__) -#define REP_BUF_DATA(rep) ((rep)->buf->ucr_data) -#elif (defined(__FREEBSD__) && (__FreeBSD_kernel_version > 800063)) -#define REP_BUF_DATA(rep) ((rep)->buf->ugd_data) -#else -#define REP_BUF_DATA(rep) ((rep)->buf->data) -#endif - -int -SDL_SYS_JoystickInit(void) -{ - char s[16]; - int i, fd; - - SDL_numjoysticks = 0; - - SDL_memset(joynames, 0, sizeof(joynames)); - SDL_memset(joydevnames, 0, sizeof(joydevnames)); - - for (i = 0; i < MAX_UHID_JOYS; i++) { - SDL_Joystick nj; - - SDL_snprintf(s, SDL_arraysize(s), "/dev/uhid%d", i); - - nj.index = SDL_numjoysticks; - joynames[nj.index] = strdup(s); - - if (SDL_SYS_JoystickOpen(&nj) == 0) { - SDL_SYS_JoystickClose(&nj); - SDL_numjoysticks++; - } else { - SDL_free(joynames[nj.index]); - joynames[nj.index] = NULL; - } - } - for (i = 0; i < MAX_JOY_JOYS; i++) { - SDL_snprintf(s, SDL_arraysize(s), "/dev/joy%d", i); - fd = open(s, O_RDONLY); - if (fd != -1) { - joynames[SDL_numjoysticks++] = strdup(s); - close(fd); - } - } - - /* Read the default USB HID usage table. */ - hid_init(NULL); - - return (SDL_numjoysticks); -} - -const char * -SDL_SYS_JoystickName(int index) -{ - if (joydevnames[index] != NULL) { - return (joydevnames[index]); - } - return (joynames[index]); -} - -static int -usage_to_joyaxe(unsigned usage) -{ - int joyaxe; - switch (usage) { - case HUG_X: - joyaxe = JOYAXE_X; break; - case HUG_Y: - joyaxe = JOYAXE_Y; break; - case HUG_Z: - joyaxe = JOYAXE_Z; break; - case HUG_SLIDER: - joyaxe = JOYAXE_SLIDER; break; - case HUG_WHEEL: - joyaxe = JOYAXE_WHEEL; break; - case HUG_RX: - joyaxe = JOYAXE_RX; break; - case HUG_RY: - joyaxe = JOYAXE_RY; break; - case HUG_RZ: - joyaxe = JOYAXE_RZ; break; - default: - joyaxe = -1; - } - return joyaxe; -} - -static unsigned -hatval_to_sdl(Sint32 hatval) -{ - static const unsigned hat_dir_map[8] = { - SDL_HAT_UP, SDL_HAT_RIGHTUP, SDL_HAT_RIGHT, SDL_HAT_RIGHTDOWN, - SDL_HAT_DOWN, SDL_HAT_LEFTDOWN, SDL_HAT_LEFT, SDL_HAT_LEFTUP - }; - unsigned result; - if ((hatval & 7) == hatval) - result = hat_dir_map[hatval]; - else - result = SDL_HAT_CENTERED; - return result; -} - - -int -SDL_SYS_JoystickOpen(SDL_Joystick *joy) -{ - char *path = joynames[joy->index]; - struct joystick_hwdata *hw; - struct hid_item hitem; - struct hid_data *hdata; - struct report *rep; - int fd; - int i; - - fd = open(path, O_RDONLY); - if (fd == -1) { - SDL_SetError("%s: %s", path, strerror(errno)); - return (-1); - } - - hw = (struct joystick_hwdata *)SDL_malloc(sizeof(struct joystick_hwdata)); - if (hw == NULL) { - SDL_OutOfMemory(); - close(fd); - return (-1); - } - joy->hwdata = hw; - hw->fd = fd; - hw->path = strdup(path); - hw->x = 0; - hw->y = 0; - hw->xmin = 0xffff; - hw->ymin = 0xffff; - hw->xmax = 0; - hw->ymax = 0; - if (! SDL_strncmp(path, "/dev/joy", 8)) { - hw->type = BSDJOY_JOY; - joy->naxes = 2; - joy->nbuttons = 2; - joy->nhats = 0; - joy->nballs = 0; - joydevnames[joy->index] = strdup("Gameport joystick"); - goto usbend; - } else { - hw->type = BSDJOY_UHID; - } - - { - int ax; - for (ax = 0; ax < JOYAXE_count; ax++) - hw->axis_map[ax] = -1; - } - hw->repdesc = hid_get_report_desc(fd); - if (hw->repdesc == NULL) { - SDL_SetError("%s: USB_GET_REPORT_DESC: %s", hw->path, - strerror(errno)); - goto usberr; - } - rep = &hw->inreport; -#if defined(__FREEBSD__) && (__FreeBSD_kernel_version > 800063) || defined(__FreeBSD_kernel__) - rep->rid = hid_get_report_id(fd); - if (rep->rid < 0) { -#else - if (ioctl(fd, USB_GET_REPORT_ID, &rep->rid) < 0) { -#endif - rep->rid = -1; /* XXX */ - } - if (report_alloc(rep, hw->repdesc, REPORT_INPUT) < 0) { - goto usberr; - } - if (rep->size <= 0) { - SDL_SetError("%s: Input report descriptor has invalid length", - hw->path); - goto usberr; - } - -#if defined(USBHID_NEW) || (defined(__FREEBSD__) && __FreeBSD_kernel_version >= 500111) || defined(__FreeBSD_kernel__) - hdata = hid_start_parse(hw->repdesc, 1 << hid_input, rep->rid); -#else - hdata = hid_start_parse(hw->repdesc, 1 << hid_input); -#endif - if (hdata == NULL) { - SDL_SetError("%s: Cannot start HID parser", hw->path); - goto usberr; - } - joy->naxes = 0; - joy->nbuttons = 0; - joy->nhats = 0; - joy->nballs = 0; - for (i=0; iaxis_map[i] = -1; - - while (hid_get_item(hdata, &hitem) > 0) { - char *sp; - const char *s; - - switch (hitem.kind) { - case hid_collection: - switch (HID_PAGE(hitem.usage)) { - case HUP_GENERIC_DESKTOP: - switch (HID_USAGE(hitem.usage)) { - case HUG_JOYSTICK: - case HUG_GAME_PAD: - s = hid_usage_in_page(hitem.usage); - sp = SDL_malloc(SDL_strlen(s) + 5); - SDL_snprintf(sp, SDL_strlen(s) + 5, "%s (%d)", s, - joy->index); - joydevnames[joy->index] = sp; - } - } - break; - case hid_input: - switch (HID_PAGE(hitem.usage)) { - case HUP_GENERIC_DESKTOP: { - unsigned usage = HID_USAGE(hitem.usage); - int joyaxe = usage_to_joyaxe(usage); - if (joyaxe >= 0) { - hw->axis_map[joyaxe] = 1; - } else if (usage == HUG_HAT_SWITCH) { - joy->nhats++; - } - break; - } - case HUP_BUTTON: - joy->nbuttons++; - break; - default: - break; - } - break; - default: - break; - } - } - hid_end_parse(hdata); - for (i=0; iaxis_map[i] > 0) - hw->axis_map[i] = joy->naxes++; - -usbend: - /* The poll blocks the event thread. */ - fcntl(fd, F_SETFL, O_NONBLOCK); - - return (0); -usberr: - close(hw->fd); - SDL_free(hw->path); - SDL_free(hw); - return (-1); -} - -void -SDL_SYS_JoystickUpdate(SDL_Joystick *joy) -{ - struct hid_item hitem; - struct hid_data *hdata; - struct report *rep; - int nbutton, naxe = -1; - Sint32 v; - -#if defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H || defined(__FreeBSD_kernel__) - struct joystick gameport; - - if (joy->hwdata->type == BSDJOY_JOY) { - if (read(joy->hwdata->fd, &gameport, sizeof gameport) != sizeof gameport) - return; - if (abs(joy->hwdata->x - gameport.x) > 8) { - joy->hwdata->x = gameport.x; - if (joy->hwdata->x < joy->hwdata->xmin) { - joy->hwdata->xmin = joy->hwdata->x; - } - if (joy->hwdata->x > joy->hwdata->xmax) { - joy->hwdata->xmax = joy->hwdata->x; - } - if (joy->hwdata->xmin == joy->hwdata->xmax) { - joy->hwdata->xmin--; - joy->hwdata->xmax++; - } - v = (Sint32)joy->hwdata->x; - v -= (joy->hwdata->xmax + joy->hwdata->xmin + 1)/2; - v *= 32768/((joy->hwdata->xmax - joy->hwdata->xmin + 1)/2); - SDL_PrivateJoystickAxis(joy, 0, v); - } - if (abs(joy->hwdata->y - gameport.y) > 8) { - joy->hwdata->y = gameport.y; - if (joy->hwdata->y < joy->hwdata->ymin) { - joy->hwdata->ymin = joy->hwdata->y; - } - if (joy->hwdata->y > joy->hwdata->ymax) { - joy->hwdata->ymax = joy->hwdata->y; - } - if (joy->hwdata->ymin == joy->hwdata->ymax) { - joy->hwdata->ymin--; - joy->hwdata->ymax++; - } - v = (Sint32)joy->hwdata->y; - v -= (joy->hwdata->ymax + joy->hwdata->ymin + 1)/2; - v *= 32768/((joy->hwdata->ymax - joy->hwdata->ymin + 1)/2); - SDL_PrivateJoystickAxis(joy, 1, v); - } - if (gameport.b1 != joy->buttons[0]) { - SDL_PrivateJoystickButton(joy, 0, gameport.b1); - } - if (gameport.b2 != joy->buttons[1]) { - SDL_PrivateJoystickButton(joy, 1, gameport.b2); - } - return; - } -#endif /* defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H */ - - rep = &joy->hwdata->inreport; - - if (read(joy->hwdata->fd, REP_BUF_DATA(rep), rep->size) != rep->size) { - return; - } -#if defined(USBHID_NEW) || (defined(__FREEBSD__) && __FreeBSD_kernel_version >= 500111) || defined(__FreeBSD_kernel__) - hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input, rep->rid); -#else - hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input); -#endif - if (hdata == NULL) { - fprintf(stderr, "%s: Cannot start HID parser\n", - joy->hwdata->path); - return; - } - - for (nbutton = 0; hid_get_item(hdata, &hitem) > 0;) { - switch (hitem.kind) { - case hid_input: - switch (HID_PAGE(hitem.usage)) { - case HUP_GENERIC_DESKTOP: { - unsigned usage = HID_USAGE(hitem.usage); - int joyaxe = usage_to_joyaxe(usage); - if (joyaxe >= 0) { - naxe = joy->hwdata->axis_map[joyaxe]; - /* scaleaxe */ - v = (Sint32)hid_get_data(REP_BUF_DATA(rep), - &hitem); - v -= (hitem.logical_maximum + hitem.logical_minimum + 1)/2; - v *= 32768/((hitem.logical_maximum - hitem.logical_minimum + 1)/2); - if (v != joy->axes[naxe]) { - SDL_PrivateJoystickAxis(joy, naxe, v); - } - } else if (usage == HUG_HAT_SWITCH) { - v = (Sint32)hid_get_data(REP_BUF_DATA(rep), - &hitem); - SDL_PrivateJoystickHat(joy, 0, - hatval_to_sdl(v)-hitem.logical_minimum); - } - break; - } - case HUP_BUTTON: - v = (Sint32)hid_get_data(REP_BUF_DATA(rep), - &hitem); - if (joy->buttons[nbutton] != v) { - SDL_PrivateJoystickButton(joy, - nbutton, v); - } - nbutton++; - break; - default: - continue; - } - break; - default: - break; - } - } - hid_end_parse(hdata); - - return; -} - -/* Function to close a joystick after use */ -void -SDL_SYS_JoystickClose(SDL_Joystick *joy) -{ - if (SDL_strncmp(joy->hwdata->path, "/dev/joy", 8)) { - report_free(&joy->hwdata->inreport); - hid_dispose_report_desc(joy->hwdata->repdesc); - } - close(joy->hwdata->fd); - SDL_free(joy->hwdata->path); - SDL_free(joy->hwdata); - - return; -} - -void -SDL_SYS_JoystickQuit(void) -{ - int i; - - for (i = 0; i < MAX_JOYS; i++) { - if (joynames[i] != NULL) - SDL_free(joynames[i]); - if (joydevnames[i] != NULL) - SDL_free(joydevnames[i]); - } - - return; -} - -static int -report_alloc(struct report *r, struct report_desc *rd, int repind) -{ - int len; - -#ifdef __DragonFly__ - len = hid_report_size(rd, r->rid, repinfo[repind].kind); -#elif __FREEBSD__ -# if (__FreeBSD_kernel_version >= 460000) || defined(__FreeBSD_kernel__) -# if (__FreeBSD_kernel_version <= 500111) - len = hid_report_size(rd, r->rid, repinfo[repind].kind); -# else - len = hid_report_size(rd, repinfo[repind].kind, r->rid); -# endif -# else - len = hid_report_size(rd, repinfo[repind].kind, &r->rid); -# endif -#else -# ifdef USBHID_NEW - len = hid_report_size(rd, repinfo[repind].kind, r->rid); -# else - len = hid_report_size(rd, repinfo[repind].kind, &r->rid); -# endif -#endif - - if (len < 0) { - SDL_SetError("Negative HID report size"); - return (-1); - } - r->size = len; - - if (r->size > 0) { - r->buf = SDL_malloc(sizeof(*r->buf) - sizeof(REP_BUF_DATA(r)) + - r->size); - if (r->buf == NULL) { - SDL_OutOfMemory(); - return (-1); - } - } else { - r->buf = NULL; - } - - r->status = SREPORT_CLEAN; - return (0); -} - -static void -report_free(struct report *r) -{ - if (r->buf != NULL) { - SDL_free(r->buf); - } - r->status = SREPORT_UNINIT; -} - -#endif /* SDL_JOYSTICK_USBHID */ diff --git a/apps/plugins/sdl/src/joystick/darwin/SDL_sysjoystick.c b/apps/plugins/sdl/src/joystick/darwin/SDL_sysjoystick.c deleted file mode 100644 index a9ccb35fad..0000000000 --- a/apps/plugins/sdl/src/joystick/darwin/SDL_sysjoystick.c +++ /dev/null @@ -1,842 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#ifdef SDL_JOYSTICK_IOKIT - -/* SDL joystick driver for Darwin / Mac OS X, based on the IOKit HID API */ -/* Written 2001 by Max Horn */ - -#include -#include -#include -#include -#include -#include -#include -#ifdef MACOS_10_0_4 -#include -#else -/* The header was moved here in Mac OS X 10.1 */ -#include -#endif -#include -#include -#include -#include /* for NewPtrClear, DisposePtr */ - -#include "SDL_joystick.h" -#include "../SDL_sysjoystick.h" -#include "../SDL_joystick_c.h" - -struct recElement -{ - IOHIDElementCookie cookie; /* unique value which identifies element, will NOT change */ - long min; /* reported min value possible */ - long max; /* reported max value possible */ -#if 0 - /* TODO: maybe should handle the following stuff somehow? */ - - long scaledMin; /* reported scaled min value possible */ - long scaledMax; /* reported scaled max value possible */ - long size; /* size in bits of data return from element */ - Boolean relative; /* are reports relative to last report (deltas) */ - Boolean wrapping; /* does element wrap around (one value higher than max is min) */ - Boolean nonLinear; /* are the values reported non-linear relative to element movement */ - Boolean preferredState; /* does element have a preferred state (such as a button) */ - Boolean nullState; /* does element have null state */ -#endif /* 0 */ - - /* runtime variables used for auto-calibration */ - long minReport; /* min returned value */ - long maxReport; /* max returned value */ - - struct recElement * pNext; /* next element in list */ -}; -typedef struct recElement recElement; - -struct joystick_hwdata -{ - IOHIDDeviceInterface ** interface; /* interface to device, NULL = no interface */ - - char product[256]; /* name of product */ - long usage; /* usage page from IOUSBHID Parser.h which defines general usage */ - long usagePage; /* usage within above page from IOUSBHID Parser.h which defines specific usage */ - - long axes; /* number of axis (calculated, not reported by device) */ - long buttons; /* number of buttons (calculated, not reported by device) */ - long hats; /* number of hat switches (calculated, not reported by device) */ - long elements; /* number of total elements (shouldbe total of above) (calculated, not reported by device) */ - - recElement* firstAxis; - recElement* firstButton; - recElement* firstHat; - - int removed; - int uncentered; - - struct joystick_hwdata* pNext; /* next device */ -}; -typedef struct joystick_hwdata recDevice; - - -/* Linked list of all available devices */ -static recDevice *gpDeviceList = NULL; - - -static void HIDReportErrorNum (char * strError, long numError) -{ - SDL_SetError(strError); -} - -static void HIDGetCollectionElements (CFMutableDictionaryRef deviceProperties, recDevice *pDevice); - -/* returns current value for element, polling element - * will return 0 on error conditions which should be accounted for by application - */ - -static SInt32 HIDGetElementValue (recDevice *pDevice, recElement *pElement) -{ - IOReturn result = kIOReturnSuccess; - IOHIDEventStruct hidEvent; - hidEvent.value = 0; - - if (NULL != pDevice && NULL != pElement && NULL != pDevice->interface) - { - result = (*(pDevice->interface))->getElementValue(pDevice->interface, pElement->cookie, &hidEvent); - if (kIOReturnSuccess == result) - { - /* record min and max for auto calibration */ - if (hidEvent.value < pElement->minReport) - pElement->minReport = hidEvent.value; - if (hidEvent.value > pElement->maxReport) - pElement->maxReport = hidEvent.value; - } - } - - /* auto user scale */ - return hidEvent.value; -} - -static SInt32 HIDScaledCalibratedValue (recDevice *pDevice, recElement *pElement, long min, long max) -{ - float deviceScale = max - min; - float readScale = pElement->maxReport - pElement->minReport; - SInt32 value = HIDGetElementValue(pDevice, pElement); - if (readScale == 0) - return value; /* no scaling at all */ - else - return ((value - pElement->minReport) * deviceScale / readScale) + min; -} - - -static void HIDRemovalCallback(void * target, - IOReturn result, - void * refcon, - void * sender) -{ - recDevice *device = (recDevice *) refcon; - device->removed = 1; - device->uncentered = 1; -} - - - -/* Create and open an interface to device, required prior to extracting values or building queues. - * Note: appliction now owns the device and must close and release it prior to exiting - */ - -static IOReturn HIDCreateOpenDeviceInterface (io_object_t hidDevice, recDevice *pDevice) -{ - IOReturn result = kIOReturnSuccess; - HRESULT plugInResult = S_OK; - SInt32 score = 0; - IOCFPlugInInterface ** ppPlugInInterface = NULL; - - if (NULL == pDevice->interface) - { - result = IOCreatePlugInInterfaceForService (hidDevice, kIOHIDDeviceUserClientTypeID, - kIOCFPlugInInterfaceID, &ppPlugInInterface, &score); - if (kIOReturnSuccess == result) - { - /* Call a method of the intermediate plug-in to create the device interface */ - plugInResult = (*ppPlugInInterface)->QueryInterface (ppPlugInInterface, - CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID), (void *) &(pDevice->interface)); - if (S_OK != plugInResult) - HIDReportErrorNum ("CouldnŐt query HID class device interface from plugInInterface", plugInResult); - (*ppPlugInInterface)->Release (ppPlugInInterface); - } - else - HIDReportErrorNum ("Failed to create **plugInInterface via IOCreatePlugInInterfaceForService.", result); - } - if (NULL != pDevice->interface) - { - result = (*(pDevice->interface))->open (pDevice->interface, 0); - if (kIOReturnSuccess != result) - HIDReportErrorNum ("Failed to open pDevice->interface via open.", result); - else - (*(pDevice->interface))->setRemovalCallback (pDevice->interface, HIDRemovalCallback, pDevice, pDevice); - - } - return result; -} - -/* Closes and releases interface to device, should be done prior to exting application - * Note: will have no affect if device or interface do not exist - * application will "own" the device if interface is not closed - * (device may have to be plug and re-plugged in different location to get it working again without a restart) - */ - -static IOReturn HIDCloseReleaseInterface (recDevice *pDevice) -{ - IOReturn result = kIOReturnSuccess; - - if ((NULL != pDevice) && (NULL != pDevice->interface)) - { - /* close the interface */ - result = (*(pDevice->interface))->close (pDevice->interface); - if (kIOReturnNotOpen == result) - { - /* do nothing as device was not opened, thus can't be closed */ - } - else if (kIOReturnSuccess != result) - HIDReportErrorNum ("Failed to close IOHIDDeviceInterface.", result); - /* release the interface */ - result = (*(pDevice->interface))->Release (pDevice->interface); - if (kIOReturnSuccess != result) - HIDReportErrorNum ("Failed to release IOHIDDeviceInterface.", result); - pDevice->interface = NULL; - } - return result; -} - -/* extracts actual specific element information from each element CF dictionary entry */ - -static void HIDGetElementInfo (CFTypeRef refElement, recElement *pElement) -{ - long number; - CFTypeRef refType; - - refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementCookieKey)); - if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) - pElement->cookie = (IOHIDElementCookie) number; - refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementMinKey)); - if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) - pElement->minReport = pElement->min = number; - refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementMaxKey)); - if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) - pElement->maxReport = pElement->max = number; -/* - TODO: maybe should handle the following stuff somehow? - - refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMinKey)); - if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) - pElement->scaledMin = number; - refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMaxKey)); - if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) - pElement->scaledMax = number; - refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementSizeKey)); - if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) - pElement->size = number; - refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsRelativeKey)); - if (refType) - pElement->relative = CFBooleanGetValue (refType); - refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsWrappingKey)); - if (refType) - pElement->wrapping = CFBooleanGetValue (refType); - refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsNonLinearKey)); - if (refType) - pElement->nonLinear = CFBooleanGetValue (refType); - refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasPreferedStateKey)); - if (refType) - pElement->preferredState = CFBooleanGetValue (refType); - refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasNullStateKey)); - if (refType) - pElement->nullState = CFBooleanGetValue (refType); -*/ -} - -/* examines CF dictionary vlaue in device element hierarchy to determine if it is element of interest or a collection of more elements - * if element of interest allocate storage, add to list and retrieve element specific info - * if collection then pass on to deconstruction collection into additional individual elements - */ - -static void HIDAddElement (CFTypeRef refElement, recDevice* pDevice) -{ - recElement* element = NULL; - recElement** headElement = NULL; - long elementType, usagePage, usage; - CFTypeRef refElementType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementTypeKey)); - CFTypeRef refUsagePage = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementUsagePageKey)); - CFTypeRef refUsage = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementUsageKey)); - - - if ((refElementType) && (CFNumberGetValue (refElementType, kCFNumberLongType, &elementType))) - { - /* look at types of interest */ - if ((elementType == kIOHIDElementTypeInput_Misc) || (elementType == kIOHIDElementTypeInput_Button) || - (elementType == kIOHIDElementTypeInput_Axis)) - { - if (refUsagePage && CFNumberGetValue (refUsagePage, kCFNumberLongType, &usagePage) && - refUsage && CFNumberGetValue (refUsage, kCFNumberLongType, &usage)) - { - switch (usagePage) /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */ - { - case kHIDPage_GenericDesktop: - { - switch (usage) /* look at usage to determine function */ - { - case kHIDUsage_GD_X: - case kHIDUsage_GD_Y: - case kHIDUsage_GD_Z: - case kHIDUsage_GD_Rx: - case kHIDUsage_GD_Ry: - case kHIDUsage_GD_Rz: - case kHIDUsage_GD_Slider: - case kHIDUsage_GD_Dial: - case kHIDUsage_GD_Wheel: - element = (recElement *) NewPtrClear (sizeof (recElement)); - if (element) - { - pDevice->axes++; - headElement = &(pDevice->firstAxis); - } - break; - case kHIDUsage_GD_Hatswitch: - element = (recElement *) NewPtrClear (sizeof (recElement)); - if (element) - { - pDevice->hats++; - headElement = &(pDevice->firstHat); - } - break; - } - } - break; - case kHIDPage_Button: - element = (recElement *) NewPtrClear (sizeof (recElement)); - if (element) - { - pDevice->buttons++; - headElement = &(pDevice->firstButton); - } - break; - default: - break; - } - } - } - else if (kIOHIDElementTypeCollection == elementType) - HIDGetCollectionElements ((CFMutableDictionaryRef) refElement, pDevice); - } - - if (element && headElement) /* add to list */ - { - pDevice->elements++; - if (NULL == *headElement) - *headElement = element; - else - { - recElement *elementPrevious, *elementCurrent; - elementCurrent = *headElement; - while (elementCurrent) - { - elementPrevious = elementCurrent; - elementCurrent = elementPrevious->pNext; - } - elementPrevious->pNext = element; - } - element->pNext = NULL; - HIDGetElementInfo (refElement, element); - } -} - -/* collects information from each array member in device element list (each array memeber = element) */ - -static void HIDGetElementsCFArrayHandler (const void * value, void * parameter) -{ - if (CFGetTypeID (value) == CFDictionaryGetTypeID ()) - HIDAddElement ((CFTypeRef) value, (recDevice *) parameter); -} - -/* handles retrieval of element information from arrays of elements in device IO registry information */ - -static void HIDGetElements (CFTypeRef refElementCurrent, recDevice *pDevice) -{ - CFTypeID type = CFGetTypeID (refElementCurrent); - if (type == CFArrayGetTypeID()) /* if element is an array */ - { - CFRange range = {0, CFArrayGetCount (refElementCurrent)}; - /* CountElementsCFArrayHandler called for each array member */ - CFArrayApplyFunction (refElementCurrent, range, HIDGetElementsCFArrayHandler, pDevice); - } -} - -/* handles extracting element information from element collection CF types - * used from top level element decoding and hierarchy deconstruction to flatten device element list - */ - -static void HIDGetCollectionElements (CFMutableDictionaryRef deviceProperties, recDevice *pDevice) -{ - CFTypeRef refElementTop = CFDictionaryGetValue (deviceProperties, CFSTR(kIOHIDElementKey)); - if (refElementTop) - HIDGetElements (refElementTop, pDevice); -} - -/* use top level element usage page and usage to discern device usage page and usage setting appropriate vlaues in device record */ - -static void HIDTopLevelElementHandler (const void * value, void * parameter) -{ - CFTypeRef refCF = 0; - if (CFGetTypeID (value) != CFDictionaryGetTypeID ()) - return; - refCF = CFDictionaryGetValue (value, CFSTR(kIOHIDElementUsagePageKey)); - if (!CFNumberGetValue (refCF, kCFNumberLongType, &((recDevice *) parameter)->usagePage)) - SDL_SetError ("CFNumberGetValue error retrieving pDevice->usagePage."); - refCF = CFDictionaryGetValue (value, CFSTR(kIOHIDElementUsageKey)); - if (!CFNumberGetValue (refCF, kCFNumberLongType, &((recDevice *) parameter)->usage)) - SDL_SetError ("CFNumberGetValue error retrieving pDevice->usage."); -} - -/* extracts device info from CF dictionary records in IO registry */ - -static void HIDGetDeviceInfo (io_object_t hidDevice, CFMutableDictionaryRef hidProperties, recDevice *pDevice) -{ - CFMutableDictionaryRef usbProperties = 0; - io_registry_entry_t parent1, parent2; - - /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also - * get dictionary for usb properties: step up two levels and get CF dictionary for USB properties - */ - if ((KERN_SUCCESS == IORegistryEntryGetParentEntry (hidDevice, kIOServicePlane, &parent1)) && - (KERN_SUCCESS == IORegistryEntryGetParentEntry (parent1, kIOServicePlane, &parent2)) && - (KERN_SUCCESS == IORegistryEntryCreateCFProperties (parent2, &usbProperties, kCFAllocatorDefault, kNilOptions))) - { - if (usbProperties) - { - CFTypeRef refCF = 0; - /* get device info - * try hid dictionary first, if fail then go to usb dictionary - */ - - - /* get product name */ - refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDProductKey)); - if (!refCF) - refCF = CFDictionaryGetValue (usbProperties, CFSTR("USB Product Name")); - if (refCF) - { - if (!CFStringGetCString (refCF, pDevice->product, 256, CFStringGetSystemEncoding ())) - SDL_SetError ("CFStringGetCString error retrieving pDevice->product."); - } - - /* get usage page and usage */ - refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey)); - if (refCF) - { - if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->usagePage)) - SDL_SetError ("CFNumberGetValue error retrieving pDevice->usagePage."); - refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDPrimaryUsageKey)); - if (refCF) - if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->usage)) - SDL_SetError ("CFNumberGetValue error retrieving pDevice->usage."); - } - - if (NULL == refCF) /* get top level element HID usage page or usage */ - { - /* use top level element instead */ - CFTypeRef refCFTopElement = 0; - refCFTopElement = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDElementKey)); - { - /* refCFTopElement points to an array of element dictionaries */ - CFRange range = {0, CFArrayGetCount (refCFTopElement)}; - CFArrayApplyFunction (refCFTopElement, range, HIDTopLevelElementHandler, pDevice); - } - } - - CFRelease (usbProperties); - } - else - SDL_SetError ("IORegistryEntryCreateCFProperties failed to create usbProperties."); - - if (kIOReturnSuccess != IOObjectRelease (parent2)) - SDL_SetError ("IOObjectRelease error with parent2."); - if (kIOReturnSuccess != IOObjectRelease (parent1)) - SDL_SetError ("IOObjectRelease error with parent1."); - } -} - - -static recDevice *HIDBuildDevice (io_object_t hidDevice) -{ - recDevice *pDevice = (recDevice *) NewPtrClear (sizeof (recDevice)); - if (pDevice) - { - /* get dictionary for HID properties */ - CFMutableDictionaryRef hidProperties = 0; - kern_return_t result = IORegistryEntryCreateCFProperties (hidDevice, &hidProperties, kCFAllocatorDefault, kNilOptions); - if ((result == KERN_SUCCESS) && hidProperties) - { - /* create device interface */ - result = HIDCreateOpenDeviceInterface (hidDevice, pDevice); - if (kIOReturnSuccess == result) - { - HIDGetDeviceInfo (hidDevice, hidProperties, pDevice); /* hidDevice used to find parents in registry tree */ - HIDGetCollectionElements (hidProperties, pDevice); - } - else - { - DisposePtr((Ptr)pDevice); - pDevice = NULL; - } - CFRelease (hidProperties); - } - else - { - DisposePtr((Ptr)pDevice); - pDevice = NULL; - } - } - return pDevice; -} - -/* disposes of the element list associated with a device and the memory associated with the list - */ - -static void HIDDisposeElementList (recElement **elementList) -{ - recElement *pElement = *elementList; - while (pElement) - { - recElement *pElementNext = pElement->pNext; - DisposePtr ((Ptr) pElement); - pElement = pElementNext; - } - *elementList = NULL; -} - -/* disposes of a single device, closing and releaseing interface, freeing memory fro device and elements, setting device pointer to NULL - * all your device no longer belong to us... (i.e., you do not 'own' the device anymore) - */ - -static recDevice *HIDDisposeDevice (recDevice **ppDevice) -{ - kern_return_t result = KERN_SUCCESS; - recDevice *pDeviceNext = NULL; - if (*ppDevice) - { - /* save next device prior to disposing of this device */ - pDeviceNext = (*ppDevice)->pNext; - - /* free element lists */ - HIDDisposeElementList (&(*ppDevice)->firstAxis); - HIDDisposeElementList (&(*ppDevice)->firstButton); - HIDDisposeElementList (&(*ppDevice)->firstHat); - - result = HIDCloseReleaseInterface (*ppDevice); /* function sanity checks interface value (now application does not own device) */ - if (kIOReturnSuccess != result) - HIDReportErrorNum ("HIDCloseReleaseInterface failed when trying to dipose device.", result); - DisposePtr ((Ptr)*ppDevice); - *ppDevice = NULL; - } - return pDeviceNext; -} - - -/* Function to scan the system for joysticks. - * Joystick 0 should be the system default joystick. - * This function should return the number of available joysticks, or -1 - * on an unrecoverable fatal error. - */ -int SDL_SYS_JoystickInit(void) -{ - IOReturn result = kIOReturnSuccess; - mach_port_t masterPort = 0; - io_iterator_t hidObjectIterator = 0; - CFMutableDictionaryRef hidMatchDictionary = NULL; - recDevice *device, *lastDevice; - io_object_t ioHIDDeviceObject = 0; - - SDL_numjoysticks = 0; - - if (gpDeviceList) - { - SDL_SetError("Joystick: Device list already inited."); - return -1; - } - - result = IOMasterPort (bootstrap_port, &masterPort); - if (kIOReturnSuccess != result) - { - SDL_SetError("Joystick: IOMasterPort error with bootstrap_port."); - return -1; - } - - /* Set up a matching dictionary to search I/O Registry by class name for all HID class devices. */ - hidMatchDictionary = IOServiceMatching (kIOHIDDeviceKey); - if (hidMatchDictionary) - { - /* Add key for device type (joystick, in this case) to refine the matching dictionary. */ - - /* NOTE: we now perform this filtering later - UInt32 usagePage = kHIDPage_GenericDesktop; - UInt32 usage = kHIDUsage_GD_Joystick; - CFNumberRef refUsage = NULL, refUsagePage = NULL; - - refUsage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usage); - CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsageKey), refUsage); - refUsagePage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usagePage); - CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsagePageKey), refUsagePage); - */ - } - else - { - SDL_SetError("Joystick: Failed to get HID CFMutableDictionaryRef via IOServiceMatching."); - return -1; - } - - /*/ Now search I/O Registry for matching devices. */ - result = IOServiceGetMatchingServices (masterPort, hidMatchDictionary, &hidObjectIterator); - /* Check for errors */ - if (kIOReturnSuccess != result) - { - SDL_SetError("Joystick: Couldn't create a HID object iterator."); - return -1; - } - if (!hidObjectIterator) /* there are no joysticks */ - { - gpDeviceList = NULL; - SDL_numjoysticks = 0; - return 0; - } - /* IOServiceGetMatchingServices consumes a reference to the dictionary, so we don't need to release the dictionary ref. */ - - /* build flat linked list of devices from device iterator */ - - gpDeviceList = lastDevice = NULL; - - while ((ioHIDDeviceObject = IOIteratorNext (hidObjectIterator))) - { - /* build a device record */ - device = HIDBuildDevice (ioHIDDeviceObject); - if (!device) - continue; - - /* dump device object, it is no longer needed */ - result = IOObjectRelease (ioHIDDeviceObject); -/* if (KERN_SUCCESS != result) - HIDReportErrorNum ("IOObjectRelease error with ioHIDDeviceObject.", result); -*/ - - /* Filter device list to non-keyboard/mouse stuff */ - if ( (device->usagePage != kHIDPage_GenericDesktop) || - ((device->usage != kHIDUsage_GD_Joystick && - device->usage != kHIDUsage_GD_GamePad && - device->usage != kHIDUsage_GD_MultiAxisController)) ) { - - /* release memory for the device */ - HIDDisposeDevice (&device); - DisposePtr((Ptr)device); - continue; - } - - /* Add device to the end of the list */ - if (lastDevice) - lastDevice->pNext = device; - else - gpDeviceList = device; - lastDevice = device; - } - result = IOObjectRelease (hidObjectIterator); /* release the iterator */ - - /* Count the total number of devices we found */ - device = gpDeviceList; - while (device) - { - SDL_numjoysticks++; - device = device->pNext; - } - - return SDL_numjoysticks; -} - -/* Function to get the device-dependent name of a joystick */ -const char *SDL_SYS_JoystickName(int index) -{ - recDevice *device = gpDeviceList; - - for (; index > 0; index--) - device = device->pNext; - - return device->product; -} - -/* Function to open a joystick for use. - * The joystick to open is specified by the index field of the joystick. - * This should fill the nbuttons and naxes fields of the joystick structure. - * It returns 0, or -1 if there is an error. - */ -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) -{ - recDevice *device = gpDeviceList; - int index; - - for (index = joystick->index; index > 0; index--) - device = device->pNext; - - joystick->hwdata = device; - joystick->name = device->product; - - joystick->naxes = device->axes; - joystick->nhats = device->hats; - joystick->nballs = 0; - joystick->nbuttons = device->buttons; - - return 0; -} - -/* Function to update the state of a joystick - called as a device poll. - * This function shouldn't update the joystick structure directly, - * but instead should call SDL_PrivateJoystick*() to deliver events - * and update joystick device state. - */ -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) -{ - recDevice *device = joystick->hwdata; - recElement *element; - SInt32 value, range; - int i; - - if (device->removed) /* device was unplugged; ignore it. */ - { - if (device->uncentered) - { - device->uncentered = 0; - - /* Tell the app that everything is centered/unpressed... */ - for (i = 0; i < device->axes; i++) - SDL_PrivateJoystickAxis(joystick, i, 0); - - for (i = 0; i < device->buttons; i++) - SDL_PrivateJoystickButton(joystick, i, 0); - - for (i = 0; i < device->hats; i++) - SDL_PrivateJoystickHat(joystick, i, SDL_HAT_CENTERED); - } - - return; - } - - element = device->firstAxis; - i = 0; - while (element) - { - value = HIDScaledCalibratedValue(device, element, -32768, 32767); - if ( value != joystick->axes[i] ) - SDL_PrivateJoystickAxis(joystick, i, value); - element = element->pNext; - ++i; - } - - element = device->firstButton; - i = 0; - while (element) - { - value = HIDGetElementValue(device, element); - if (value > 1) /* handle pressure-sensitive buttons */ - value = 1; - if ( value != joystick->buttons[i] ) - SDL_PrivateJoystickButton(joystick, i, value); - element = element->pNext; - ++i; - } - - element = device->firstHat; - i = 0; - while (element) - { - Uint8 pos = 0; - - range = (element->max - element->min + 1); - value = HIDGetElementValue(device, element) - element->min; - if (range == 4) /* 4 position hatswitch - scale up value */ - value *= 2; - else if (range != 8) /* Neither a 4 nor 8 positions - fall back to default position (centered) */ - value = -1; - switch(value) - { - case 0: - pos = SDL_HAT_UP; - break; - case 1: - pos = SDL_HAT_RIGHTUP; - break; - case 2: - pos = SDL_HAT_RIGHT; - break; - case 3: - pos = SDL_HAT_RIGHTDOWN; - break; - case 4: - pos = SDL_HAT_DOWN; - break; - case 5: - pos = SDL_HAT_LEFTDOWN; - break; - case 6: - pos = SDL_HAT_LEFT; - break; - case 7: - pos = SDL_HAT_LEFTUP; - break; - default: - /* Every other value is mapped to center. We do that because some - * joysticks use 8 and some 15 for this value, and apparently - * there are even more variants out there - so we try to be generous. - */ - pos = SDL_HAT_CENTERED; - break; - } - if ( pos != joystick->hats[i] ) - SDL_PrivateJoystickHat(joystick, i, pos); - element = element->pNext; - ++i; - } - - return; -} - -/* Function to close a joystick after use */ -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) -{ - /* Should we do anything here? */ - return; -} - -/* Function to perform any system-specific joystick related cleanup */ -void SDL_SYS_JoystickQuit(void) -{ - while (NULL != gpDeviceList) - gpDeviceList = HIDDisposeDevice (&gpDeviceList); -} - -#endif /* SDL_JOYSTICK_IOKIT */ diff --git a/apps/plugins/sdl/src/joystick/dc/SDL_sysjoystick.c b/apps/plugins/sdl/src/joystick/dc/SDL_sysjoystick.c deleted file mode 100644 index dc089e7bf0..0000000000 --- a/apps/plugins/sdl/src/joystick/dc/SDL_sysjoystick.c +++ /dev/null @@ -1,193 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#ifdef SDL_JOYSTICK_DC - -#include "SDL_events.h" -#include "SDL_joystick.h" -#include "../SDL_sysjoystick.h" -#include "../SDL_joystick_c.h" - -#include -#include - -#define MAX_JOYSTICKS 8 /* only 2 are supported in the multimedia API */ -#define MAX_AXES 6 /* each joystick can have up to 6 axes */ -#define MAX_BUTTONS 8 /* and 8 buttons */ -#define MAX_HATS 2 - -#define JOYNAMELEN 8 - -/* array to hold joystick ID values */ -static uint8 SYS_Joystick_addr[MAX_JOYSTICKS]; - -/* The private structure used to keep track of a joystick */ -struct joystick_hwdata -{ - cont_cond_t prev_cond; - int prev_buttons; -}; - -/* Function to scan the system for joysticks. - * This function should set SDL_numjoysticks to the number of available - * joysticks. Joystick 0 should be the system default joystick. - * It should return 0, or -1 on an unrecoverable fatal error. - */ -int SDL_SYS_JoystickInit(void) -{ - int numdevs; - - int p,u; - - numdevs = 0; - for(p=0;pinfo.product_name; -} - -/* Function to open a joystick for use. - The joystick to open is specified by the index field of the joystick. - This should fill the nbuttons and naxes fields of the joystick structure. - It returns 0, or -1 if there is an error. - */ -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) -{ - /* allocate memory for system specific hardware data */ - joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata)); - if (joystick->hwdata == NULL) - { - SDL_OutOfMemory(); - return(-1); - } - SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); - - /* fill nbuttons, naxes, and nhats fields */ - joystick->nbuttons = MAX_BUTTONS; - joystick->naxes = MAX_AXES; - joystick->nhats = MAX_HATS; - return(0); -} - - -/* Function to update the state of a joystick - called as a device poll. - * This function shouldn't update the joystick structure directly, - * but instead should call SDL_PrivateJoystick*() to deliver events - * and update joystick device state. - */ - -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) -{ -const int sdl_buttons[] = { - CONT_C, - CONT_B, - CONT_A, - CONT_START, - CONT_Z, - CONT_Y, - CONT_X, - CONT_D -}; - - uint8 addr; - cont_cond_t cond,*prev_cond; - int buttons,prev_buttons,i,changed; - - addr = SYS_Joystick_addr[joystick->index]; - if (cont_get_cond(addr,&cond)<0) return; - - buttons = cond.buttons; - prev_buttons = joystick->hwdata->prev_buttons; - changed = buttons^prev_buttons; - - if ((changed)&(CONT_DPAD_UP|CONT_DPAD_DOWN|CONT_DPAD_LEFT|CONT_DPAD_RIGHT)) { - int hat = SDL_HAT_CENTERED; - if (buttons&CONT_DPAD_UP) hat|=SDL_HAT_UP; - if (buttons&CONT_DPAD_DOWN) hat|=SDL_HAT_DOWN; - if (buttons&CONT_DPAD_LEFT) hat|=SDL_HAT_LEFT; - if (buttons&CONT_DPAD_RIGHT) hat|=SDL_HAT_RIGHT; - SDL_PrivateJoystickHat(joystick, 0, hat); - } - if ((changed)&(CONT_DPAD2_UP|CONT_DPAD2_DOWN|CONT_DPAD2_LEFT|CONT_DPAD2_RIGHT)) { - int hat = SDL_HAT_CENTERED; - if (buttons&CONT_DPAD2_UP) hat|=SDL_HAT_UP; - if (buttons&CONT_DPAD2_DOWN) hat|=SDL_HAT_DOWN; - if (buttons&CONT_DPAD2_LEFT) hat|=SDL_HAT_LEFT; - if (buttons&CONT_DPAD2_RIGHT) hat|=SDL_HAT_RIGHT; - SDL_PrivateJoystickHat(joystick, 1, hat); - } - - for(i=0;ihwdata->prev_cond; - if (cond.joyx!=prev_cond->joyx) - SDL_PrivateJoystickAxis(joystick, 0, cond.joyx-128); - if (cond.joyy!=prev_cond->joyy) - SDL_PrivateJoystickAxis(joystick, 1, cond.joyy-128); - if (cond.rtrig!=prev_cond->rtrig) - SDL_PrivateJoystickAxis(joystick, 2, cond.rtrig); - if (cond.ltrig!=prev_cond->ltrig) - SDL_PrivateJoystickAxis(joystick, 3, cond.ltrig); - if (cond.joy2x!=prev_cond->joy2x) - SDL_PrivateJoystickAxis(joystick, 4, cond.joy2x-128); - if (cond.joy2y!=prev_cond->joy2y) - SDL_PrivateJoystickAxis(joystick, 5, cond.joy2y-128); - - joystick->hwdata->prev_buttons = buttons; - joystick->hwdata->prev_cond = cond; -} - -/* Function to close a joystick after use */ -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) -{ - if (joystick->hwdata != NULL) { - /* free system specific hardware data */ - SDL_free(joystick->hwdata); - } -} - -/* Function to perform any system-specific joystick related cleanup */ -void SDL_SYS_JoystickQuit(void) -{ - return; -} - -#endif /* SDL_JOYSTICK_DC */ diff --git a/apps/plugins/sdl/src/joystick/linux/SDL_sysjoystick.c b/apps/plugins/sdl/src/joystick/linux/SDL_sysjoystick.c deleted file mode 100644 index ee43974789..0000000000 --- a/apps/plugins/sdl/src/joystick/linux/SDL_sysjoystick.c +++ /dev/null @@ -1,1218 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#ifdef SDL_JOYSTICK_LINUX - -/* This is the system specific header for the SDL joystick API */ - -#include -#include -#include -#include -#include /* For the definition of PATH_MAX */ -#include -#if SDL_INPUT_LINUXEV -#include -#endif - -#include "SDL_joystick.h" -#include "../SDL_sysjoystick.h" -#include "../SDL_joystick_c.h" - -/* Special joystick configurations */ -static struct { - const char *name; - int naxes; - int nhats; - int nballs; -} special_joysticks[] = { - { "MadCatz Panther XL", 3, 2, 1 }, /* We don't handle rudder (axis 8) */ - { "SideWinder Precision Pro", 4, 1, 0 }, - { "SideWinder 3D Pro", 4, 1, 0 }, - { "Microsoft SideWinder 3D Pro", 4, 1, 0 }, - { "Microsoft SideWinder Precision Pro", 4, 1, 0 }, - { "Microsoft SideWinder Dual Strike USB version 1.0", 2, 1, 0 }, - { "WingMan Interceptor", 3, 3, 0 }, - { "WingMan Extreme Digital 3D", 4, 1, 0 }, - { "Microsoft SideWinder Precision 2 Joystick", 4, 1, 0 }, - { "Logitech Inc. WingMan Extreme Digital 3D", 4, 1, 0 }, - { "Saitek Saitek X45", 6, 1, 0 } -}; - -/* It looks like newer kernels have the logical mapping at the driver level */ -#define NO_LOGICAL_JOYSTICKS - -#ifndef NO_LOGICAL_JOYSTICKS - -/* - Some USB HIDs show up as a single joystick even though they actually - control 2 or more joysticks. -*/ -/* - This code handles the MP-8800 (Quad) and MP-8866 (Dual), which can - be identified by their transparent blue design. It's quite trivial - to add other joysticks with similar quirky behavior. - -id -*/ - -struct joystick_logical_mapping { - int njoy; - int nthing; -}; - -/* - {logical joy, logical axis}, - {logical joy, logical hat}, - {logical joy, logical ball}, - {logical joy, logical button} -*/ - -static struct joystick_logical_mapping mp88xx_1_logical_axismap[] = { - {0,0},{0,1},{0,2},{0,3},{0,4},{0,5} -}; -static struct joystick_logical_mapping mp88xx_1_logical_buttonmap[] = { - {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11} -}; - -static struct joystick_logical_mapping mp88xx_2_logical_axismap[] = { - {0,0},{0,1},{0,2},{1,0},{1,1},{0,3}, - {1,2},{1,3},{0,4},{0,5},{1,4},{1,5} -}; -static struct joystick_logical_mapping mp88xx_2_logical_buttonmap[] = { - {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11}, - {1,0},{1,1},{1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{1,8},{1,9},{1,10},{1,11} -}; - -static struct joystick_logical_mapping mp88xx_3_logical_axismap[] = { - {0,0},{0,1},{0,2},{1,0},{1,1},{0,3}, - {1,2},{1,3},{2,0},{2,1},{2,2},{2,3}, - {0,4},{0,5},{1,4},{1,5},{2,4},{2,5} -}; -static struct joystick_logical_mapping mp88xx_3_logical_buttonmap[] = { - {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11}, - {1,0},{1,1},{1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{1,8},{1,9},{1,10},{1,11}, - {2,0},{2,1},{2,2},{2,3},{2,4},{2,5},{2,6},{2,7},{2,8},{2,9},{2,10},{2,11} -}; - -static struct joystick_logical_mapping mp88xx_4_logical_axismap[] = { - {0,0},{0,1},{0,2},{1,0},{1,1},{0,3}, - {1,2},{1,3},{2,0},{2,1},{2,2},{2,3}, - {3,0},{3,1},{3,2},{3,3},{0,4},{0,5}, - {1,4},{1,5},{2,4},{2,5},{3,4},{3,5} -}; -static struct joystick_logical_mapping mp88xx_4_logical_buttonmap[] = { - {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11}, - {1,0},{1,1},{1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{1,8},{1,9},{1,10},{1,11}, - {2,0},{2,1},{2,2},{2,3},{2,4},{2,5},{2,6},{2,7},{2,8},{2,9},{2,10},{2,11}, - {3,0},{3,1},{3,2},{3,3},{3,4},{3,5},{3,6},{3,7},{3,8},{3,9},{3,10},{3,11} -}; - -struct joystick_logical_layout { - int naxes; - int nhats; - int nballs; - int nbuttons; -}; - -static struct joystick_logical_layout mp88xx_1_logical_layout[] = { - {6, 0, 0, 12} -}; -static struct joystick_logical_layout mp88xx_2_logical_layout[] = { - {6, 0, 0, 12}, - {6, 0, 0, 12} -}; -static struct joystick_logical_layout mp88xx_3_logical_layout[] = { - {6, 0, 0, 12}, - {6, 0, 0, 12}, - {6, 0, 0, 12} -}; -static struct joystick_logical_layout mp88xx_4_logical_layout[] = { - {6, 0, 0, 12}, - {6, 0, 0, 12}, - {6, 0, 0, 12}, - {6, 0, 0, 12} -}; - -/* - This array sets up a means of mapping a single physical joystick to - multiple logical joysticks. (djm) - - njoys - the number of logical joysticks - - layouts - an array of layout structures, one to describe each logical joystick - - axes, hats, balls, buttons - arrays that map a physical thingy to a logical thingy - */ -struct joystick_logicalmap { - const char *name; - int nbuttons; - int njoys; - struct joystick_logical_layout *layout; - struct joystick_logical_mapping *axismap; - struct joystick_logical_mapping *hatmap; - struct joystick_logical_mapping *ballmap; - struct joystick_logical_mapping *buttonmap; -}; - -static struct joystick_logicalmap joystick_logicalmap[] = { - { - "WiseGroup.,Ltd MP-8866 Dual USB Joypad", - 12, - 1, - mp88xx_1_logical_layout, - mp88xx_1_logical_axismap, - NULL, - NULL, - mp88xx_1_logical_buttonmap - }, - { - "WiseGroup.,Ltd MP-8866 Dual USB Joypad", - 24, - 2, - mp88xx_2_logical_layout, - mp88xx_2_logical_axismap, - NULL, - NULL, - mp88xx_2_logical_buttonmap - }, - { - "WiseGroup.,Ltd MP-8800 Quad USB Joypad", - 12, - 1, - mp88xx_1_logical_layout, - mp88xx_1_logical_axismap, - NULL, - NULL, - mp88xx_1_logical_buttonmap - }, - { - "WiseGroup.,Ltd MP-8800 Quad USB Joypad", - 24, - 2, - mp88xx_2_logical_layout, - mp88xx_2_logical_axismap, - NULL, - NULL, - mp88xx_2_logical_buttonmap - }, - { - "WiseGroup.,Ltd MP-8800 Quad USB Joypad", - 36, - 3, - mp88xx_3_logical_layout, - mp88xx_3_logical_axismap, - NULL, - NULL, - mp88xx_3_logical_buttonmap - }, - { - "WiseGroup.,Ltd MP-8800 Quad USB Joypad", - 48, - 4, - mp88xx_4_logical_layout, - mp88xx_4_logical_axismap, - NULL, - NULL, - mp88xx_4_logical_buttonmap - } -}; - -/* find the head of a linked list, given a point in it - */ -#define SDL_joylist_head(i, start)\ - for(i = start; SDL_joylist[i].fname == NULL;) i = SDL_joylist[i].prev; - -#define SDL_logical_joydecl(d) d - - -#else - -#define SDL_logical_joydecl(d) - -#endif /* USE_LOGICAL_JOYSTICKS */ - -/* The maximum number of joysticks we'll detect */ -#define MAX_JOYSTICKS 32 - -/* A list of available joysticks */ -static struct -{ - char* fname; -#ifndef NO_LOGICAL_JOYSTICKS - SDL_Joystick* joy; - struct joystick_logicalmap* map; - int prev; - int next; - int logicalno; -#endif /* USE_LOGICAL_JOYSTICKS */ -} SDL_joylist[MAX_JOYSTICKS]; - - -/* The private structure used to keep track of a joystick */ -struct joystick_hwdata { - int fd; - /* The current linux joystick driver maps hats to two axes */ - struct hwdata_hat { - int axis[2]; - } *hats; - /* The current linux joystick driver maps balls to two axes */ - struct hwdata_ball { - int axis[2]; - } *balls; - - /* Support for the Linux 2.4 unified input interface */ -#if SDL_INPUT_LINUXEV - SDL_bool is_hid; - Uint8 key_map[KEY_MAX-BTN_MISC]; - Uint8 abs_map[ABS_MAX]; - struct axis_correct { - int used; - int coef[3]; - } abs_correct[ABS_MAX]; -#endif -}; - - -#ifndef NO_LOGICAL_JOYSTICKS - -static int CountLogicalJoysticks(int max) -{ - register int i, j, k, ret, prev; - const char* name; - int nbuttons, fd; - unsigned char n; - - ret = 0; - - for(i = 0; i < max; i++) { - name = SDL_SYS_JoystickName(i); - - fd = open(SDL_joylist[i].fname, O_RDONLY, 0); - if ( fd >= 0 ) { - if ( ioctl(fd, JSIOCGBUTTONS, &n) < 0 ) { - nbuttons = -1; - } else { - nbuttons = n; - } - close(fd); - } - else { - nbuttons=-1; - } - - if (name) { - for(j = 0; j < SDL_arraysize(joystick_logicalmap); j++) { - if (!SDL_strcmp(name, joystick_logicalmap[j].name) && (nbuttons==-1 || nbuttons==joystick_logicalmap[j].nbuttons)) { - prev = i; - SDL_joylist[prev].map = &(joystick_logicalmap[j]); - - for(k = 1; k < joystick_logicalmap[j].njoys; k++) { - SDL_joylist[prev].next = max + ret; - SDL_joylist[max+ret].prev = prev; - - prev = max + ret; - SDL_joylist[prev].logicalno = k; - SDL_joylist[prev].map = &(joystick_logicalmap[j]); - ret++; - } - - break; - } - } - } - } - - return ret; -} - -static void LogicalSuffix(int logicalno, char* namebuf, int len) -{ - register int slen; - const static char suffixs[] = - "01020304050607080910111213141516171819" - "20212223242526272829303132"; - const char* suffix; - slen = SDL_strlen(namebuf); - suffix = NULL; - - if (logicalno*2= 0 ) { - /* Assume the user knows what they're doing. */ - SDL_joylist[numjoysticks].fname = SDL_strdup(envpath); - if ( SDL_joylist[numjoysticks].fname ) { - dev_nums[numjoysticks] = sb.st_rdev; - ++numjoysticks; - } - close(fd); - } - } - envpath = delim; - } - SDL_free(envcopy); - } - - for ( i=0; i 0) ) - break; -#endif - } -#ifndef NO_LOGICAL_JOYSTICKS - numjoysticks += CountLogicalJoysticks(numjoysticks); -#endif - - return(numjoysticks); -} - -/* Function to get the device-dependent name of a joystick */ -const char *SDL_SYS_JoystickName(int index) -{ - int fd; - static char namebuf[128]; - char *name; - SDL_logical_joydecl(int oindex = index); - -#ifndef NO_LOGICAL_JOYSTICKS - SDL_joylist_head(index, index); -#endif - name = NULL; - fd = open(SDL_joylist[index].fname, O_RDONLY, 0); - if ( fd >= 0 ) { - if ( -#if SDL_INPUT_LINUXEV - (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) && -#endif - (ioctl(fd, JSIOCGNAME(sizeof(namebuf)), namebuf) <= 0) ) { - name = SDL_joylist[index].fname; - } else { - name = namebuf; - } - close(fd); - - -#ifndef NO_LOGICAL_JOYSTICKS - if (SDL_joylist[oindex].prev || SDL_joylist[oindex].next || index!=oindex) - { - LogicalSuffix(SDL_joylist[oindex].logicalno, namebuf, 128); - } -#endif - } - return name; -} - -static int allocate_hatdata(SDL_Joystick *joystick) -{ - int i; - - joystick->hwdata->hats = (struct hwdata_hat *)SDL_malloc( - joystick->nhats * sizeof(struct hwdata_hat)); - if ( joystick->hwdata->hats == NULL ) { - return(-1); - } - for ( i=0; inhats; ++i ) { - joystick->hwdata->hats[i].axis[0] = 1; - joystick->hwdata->hats[i].axis[1] = 1; - } - return(0); -} - -static int allocate_balldata(SDL_Joystick *joystick) -{ - int i; - - joystick->hwdata->balls = (struct hwdata_ball *)SDL_malloc( - joystick->nballs * sizeof(struct hwdata_ball)); - if ( joystick->hwdata->balls == NULL ) { - return(-1); - } - for ( i=0; inballs; ++i ) { - joystick->hwdata->balls[i].axis[0] = 0; - joystick->hwdata->balls[i].axis[1] = 0; - } - return(0); -} - -static SDL_bool JS_ConfigJoystick(SDL_Joystick *joystick, int fd) -{ - SDL_bool handled; - unsigned char n; - int tmp_naxes, tmp_nhats, tmp_nballs; - const char *name; - char *env, env_name[128]; - int i; - - handled = SDL_FALSE; - - /* Default joystick device settings */ - if ( ioctl(fd, JSIOCGAXES, &n) < 0 ) { - joystick->naxes = 2; - } else { - joystick->naxes = n; - } - if ( ioctl(fd, JSIOCGBUTTONS, &n) < 0 ) { - joystick->nbuttons = 2; - } else { - joystick->nbuttons = n; - } - - name = SDL_SYS_JoystickName(joystick->index); - - /* Generic analog joystick support */ - if ( SDL_strstr(name, "Analog") == name && SDL_strstr(name, "-hat") ) { - if ( SDL_sscanf(name,"Analog %d-axis %*d-button %d-hat", - &tmp_naxes, &tmp_nhats) == 2 ) { - - joystick->naxes = tmp_naxes; - joystick->nhats = tmp_nhats; - - handled = SDL_TRUE; - } - } - - /* Special joystick support */ - for ( i=0; i < SDL_arraysize(special_joysticks); ++i ) { - if ( SDL_strcmp(name, special_joysticks[i].name) == 0 ) { - - joystick->naxes = special_joysticks[i].naxes; - joystick->nhats = special_joysticks[i].nhats; - joystick->nballs = special_joysticks[i].nballs; - - handled = SDL_TRUE; - break; - } - } - - /* User environment joystick support */ - if ( (env = SDL_getenv("SDL_LINUX_JOYSTICK")) ) { - *env_name = '\0'; - if ( *env == '\'' && SDL_sscanf(env, "'%[^']s'", env_name) == 1 ) - env += SDL_strlen(env_name)+2; - else if ( SDL_sscanf(env, "%s", env_name) == 1 ) - env += SDL_strlen(env_name); - - if ( SDL_strcmp(name, env_name) == 0 ) { - - if ( SDL_sscanf(env, "%d %d %d", &tmp_naxes, &tmp_nhats, - &tmp_nballs) == 3 ) { - - joystick->naxes = tmp_naxes; - joystick->nhats = tmp_nhats; - joystick->nballs = tmp_nballs; - - handled = SDL_TRUE; - } - } - } - - /* Remap hats and balls */ - if (handled) { - if ( joystick->nhats > 0 ) { - if ( allocate_hatdata(joystick) < 0 ) { - joystick->nhats = 0; - } - } - if ( joystick->nballs > 0 ) { - if ( allocate_balldata(joystick) < 0 ) { - joystick->nballs = 0; - } - } - } - - return(handled); -} - -#if SDL_INPUT_LINUXEV - -static SDL_bool EV_ConfigJoystick(SDL_Joystick *joystick, int fd) -{ - int i, t; - unsigned long keybit[NBITS(KEY_MAX)] = { 0 }; - unsigned long absbit[NBITS(ABS_MAX)] = { 0 }; - unsigned long relbit[NBITS(REL_MAX)] = { 0 }; - - /* See if this device uses the new unified event API */ - if ( (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) >= 0) && - (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) >= 0) && - (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relbit)), relbit) >= 0) ) { - joystick->hwdata->is_hid = SDL_TRUE; - - /* Get the number of buttons, axes, and other thingamajigs */ - for ( i=BTN_JOYSTICK; i < KEY_MAX; ++i ) { - if ( test_bit(i, keybit) ) { -#ifdef DEBUG_INPUT_EVENTS - printf("Joystick has button: 0x%x\n", i); -#endif - joystick->hwdata->key_map[i-BTN_MISC] = - joystick->nbuttons; - ++joystick->nbuttons; - } - } - for ( i=BTN_MISC; i < BTN_JOYSTICK; ++i ) { - if ( test_bit(i, keybit) ) { -#ifdef DEBUG_INPUT_EVENTS - printf("Joystick has button: 0x%x\n", i); -#endif - joystick->hwdata->key_map[i-BTN_MISC] = - joystick->nbuttons; - ++joystick->nbuttons; - } - } - for ( i=0; ihwdata->abs_map[i] = joystick->naxes; - if ( absinfo.minimum == absinfo.maximum ) { - joystick->hwdata->abs_correct[i].used = 0; - } else { - joystick->hwdata->abs_correct[i].used = 1; - joystick->hwdata->abs_correct[i].coef[0] = - (absinfo.maximum + absinfo.minimum) / 2 - absinfo.flat; - joystick->hwdata->abs_correct[i].coef[1] = - (absinfo.maximum + absinfo.minimum) / 2 + absinfo.flat; - t = ((absinfo.maximum - absinfo.minimum) / 2 - 2 * absinfo.flat); - if ( t != 0 ) { - joystick->hwdata->abs_correct[i].coef[2] = (1 << 29) / t; - } else { - joystick->hwdata->abs_correct[i].coef[2] = 0; - } - } - ++joystick->naxes; - } - } - for ( i=ABS_HAT0X; i <= ABS_HAT3Y; i += 2 ) { - if ( test_bit(i, absbit) || test_bit(i+1, absbit) ) { -#ifdef DEBUG_INPUT_EVENTS - printf("Joystick has hat %d\n",(i-ABS_HAT0X)/2); -#endif - ++joystick->nhats; - } - } - if ( test_bit(REL_X, relbit) || test_bit(REL_Y, relbit) ) { - ++joystick->nballs; - } - - /* Allocate data to keep track of these thingamajigs */ - if ( joystick->nhats > 0 ) { - if ( allocate_hatdata(joystick) < 0 ) { - joystick->nhats = 0; - } - } - if ( joystick->nballs > 0 ) { - if ( allocate_balldata(joystick) < 0 ) { - joystick->nballs = 0; - } - } - } - return(joystick->hwdata->is_hid); -} - -#endif /* SDL_INPUT_LINUXEV */ - -#ifndef NO_LOGICAL_JOYSTICKS -static void ConfigLogicalJoystick(SDL_Joystick *joystick) -{ - struct joystick_logical_layout* layout; - - layout = SDL_joylist[joystick->index].map->layout + - SDL_joylist[joystick->index].logicalno; - - joystick->nbuttons = layout->nbuttons; - joystick->nhats = layout->nhats; - joystick->naxes = layout->naxes; - joystick->nballs = layout->nballs; -} -#endif - - -/* Function to open a joystick for use. - The joystick to open is specified by the index field of the joystick. - This should fill the nbuttons and naxes fields of the joystick structure. - It returns 0, or -1 if there is an error. - */ -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) -{ - int fd; - SDL_logical_joydecl(int realindex); - SDL_logical_joydecl(SDL_Joystick *realjoy = NULL); - - /* Open the joystick and set the joystick file descriptor */ -#ifndef NO_LOGICAL_JOYSTICKS - if (SDL_joylist[joystick->index].fname == NULL) { - SDL_joylist_head(realindex, joystick->index); - realjoy = SDL_JoystickOpen(realindex); - - if (realjoy == NULL) - return(-1); - - fd = realjoy->hwdata->fd; - - } else { - fd = open(SDL_joylist[joystick->index].fname, O_RDONLY, 0); - } - SDL_joylist[joystick->index].joy = joystick; -#else - fd = open(SDL_joylist[joystick->index].fname, O_RDONLY, 0); -#endif - - if ( fd < 0 ) { - SDL_SetError("Unable to open %s\n", - SDL_joylist[joystick->index]); - return(-1); - } - joystick->hwdata = (struct joystick_hwdata *) - SDL_malloc(sizeof(*joystick->hwdata)); - if ( joystick->hwdata == NULL ) { - SDL_OutOfMemory(); - close(fd); - return(-1); - } - SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); - joystick->hwdata->fd = fd; - - /* Set the joystick to non-blocking read mode */ - fcntl(fd, F_SETFL, O_NONBLOCK); - - /* Get the number of buttons and axes on the joystick */ -#ifndef NO_LOGICAL_JOYSTICKS - if (realjoy) - ConfigLogicalJoystick(joystick); - else -#endif -#if SDL_INPUT_LINUXEV - if ( ! EV_ConfigJoystick(joystick, fd) ) -#endif - JS_ConfigJoystick(joystick, fd); - - return(0); -} - -#ifndef NO_LOGICAL_JOYSTICKS - -static SDL_Joystick* FindLogicalJoystick( - SDL_Joystick *joystick, struct joystick_logical_mapping* v) -{ - SDL_Joystick *logicaljoy; - register int i; - - i = joystick->index; - logicaljoy = NULL; - - /* get the fake joystick that will receive the event - */ - for(;;) { - - if (SDL_joylist[i].logicalno == v->njoy) { - logicaljoy = SDL_joylist[i].joy; - break; - } - - if (SDL_joylist[i].next == 0) - break; - - i = SDL_joylist[i].next; - - } - - return logicaljoy; -} - -static int LogicalJoystickButton( - SDL_Joystick *joystick, Uint8 button, Uint8 state){ - struct joystick_logical_mapping* buttons; - SDL_Joystick *logicaljoy = NULL; - - /* if there's no map then this is just a regular joystick - */ - if (SDL_joylist[joystick->index].map == NULL) - return 0; - - /* get the logical joystick that will receive the event - */ - buttons = SDL_joylist[joystick->index].map->buttonmap+button; - logicaljoy = FindLogicalJoystick(joystick, buttons); - - if (logicaljoy == NULL) - return 1; - - SDL_PrivateJoystickButton(logicaljoy, buttons->nthing, state); - - return 1; -} - -static int LogicalJoystickAxis( - SDL_Joystick *joystick, Uint8 axis, Sint16 value) -{ - struct joystick_logical_mapping* axes; - SDL_Joystick *logicaljoy = NULL; - - /* if there's no map then this is just a regular joystick - */ - if (SDL_joylist[joystick->index].map == NULL) - return 0; - - /* get the logical joystick that will receive the event - */ - axes = SDL_joylist[joystick->index].map->axismap+axis; - logicaljoy = FindLogicalJoystick(joystick, axes); - - if (logicaljoy == NULL) - return 1; - - SDL_PrivateJoystickAxis(logicaljoy, axes->nthing, value); - - return 1; -} -#endif /* USE_LOGICAL_JOYSTICKS */ - -static __inline__ -void HandleHat(SDL_Joystick *stick, Uint8 hat, int axis, int value) -{ - struct hwdata_hat *the_hat; - const Uint8 position_map[3][3] = { - { SDL_HAT_LEFTUP, SDL_HAT_UP, SDL_HAT_RIGHTUP }, - { SDL_HAT_LEFT, SDL_HAT_CENTERED, SDL_HAT_RIGHT }, - { SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN } - }; - SDL_logical_joydecl(SDL_Joystick *logicaljoy = NULL); - SDL_logical_joydecl(struct joystick_logical_mapping* hats = NULL); - - if (stick->nhats <= hat) { - return; /* whoops, that shouldn't happen! */ - } - - the_hat = &stick->hwdata->hats[hat]; - if ( value < 0 ) { - value = 0; - } else - if ( value == 0 ) { - value = 1; - } else - if ( value > 0 ) { - value = 2; - } - if ( value != the_hat->axis[axis] ) { - the_hat->axis[axis] = value; - -#ifndef NO_LOGICAL_JOYSTICKS - /* if there's no map then this is just a regular joystick - */ - if (SDL_joylist[stick->index].map != NULL) { - - /* get the fake joystick that will receive the event - */ - hats = SDL_joylist[stick->index].map->hatmap+hat; - logicaljoy = FindLogicalJoystick(stick, hats); - } - - if (logicaljoy) { - stick = logicaljoy; - hat = hats->nthing; - } -#endif /* USE_LOGICAL_JOYSTICKS */ - - SDL_PrivateJoystickHat(stick, hat, - position_map[the_hat->axis[1]][the_hat->axis[0]]); - } -} - -static __inline__ -void HandleBall(SDL_Joystick *stick, Uint8 ball, int axis, int value) -{ - if ((stick->nballs <= ball) || (axis >= 2)) { - return; /* whoops, that shouldn't happen! */ - } - stick->hwdata->balls[ball].axis[axis] += value; -} - -/* Function to update the state of a joystick - called as a device poll. - * This function shouldn't update the joystick structure directly, - * but instead should call SDL_PrivateJoystick*() to deliver events - * and update joystick device state. - */ -static __inline__ void JS_HandleEvents(SDL_Joystick *joystick) -{ - struct js_event events[32]; - int i, len; - Uint8 other_axis; - -#ifndef NO_LOGICAL_JOYSTICKS - if (SDL_joylist[joystick->index].fname == NULL) { - SDL_joylist_head(i, joystick->index); - JS_HandleEvents(SDL_joylist[i].joy); - return; - } -#endif - - while ((len=read(joystick->hwdata->fd, events, (sizeof events))) > 0) { - len /= sizeof(events[0]); - for ( i=0; inaxes ) { -#ifndef NO_LOGICAL_JOYSTICKS - if (!LogicalJoystickAxis(joystick, - events[i].number, events[i].value)) -#endif - SDL_PrivateJoystickAxis(joystick, - events[i].number, events[i].value); - break; - } - events[i].number -= joystick->naxes; - other_axis = (events[i].number / 2); - if ( other_axis < joystick->nhats ) { - HandleHat(joystick, other_axis, - events[i].number%2, - events[i].value); - break; - } - events[i].number -= joystick->nhats*2; - other_axis = (events[i].number / 2); - if ( other_axis < joystick->nballs ) { - HandleBall(joystick, other_axis, - events[i].number%2, - events[i].value); - break; - } - break; - case JS_EVENT_BUTTON: -#ifndef NO_LOGICAL_JOYSTICKS - if (!LogicalJoystickButton(joystick, - events[i].number, events[i].value)) -#endif - SDL_PrivateJoystickButton(joystick, - events[i].number, events[i].value); - break; - default: - /* ?? */ - break; - } - } - } -} -#if SDL_INPUT_LINUXEV -static __inline__ int EV_AxisCorrect(SDL_Joystick *joystick, int which, int value) -{ - struct axis_correct *correct; - - correct = &joystick->hwdata->abs_correct[which]; - if ( correct->used ) { - if ( value > correct->coef[0] ) { - if ( value < correct->coef[1] ) { - return 0; - } - value -= correct->coef[1]; - } else { - value -= correct->coef[0]; - } - value *= correct->coef[2]; - value >>= 14; - } - - /* Clamp and return */ - if ( value < -32768 ) return -32768; - if ( value > 32767 ) return 32767; - - return value; -} - -static __inline__ void EV_HandleEvents(SDL_Joystick *joystick) -{ - struct input_event events[32]; - int i, len; - int code; - -#ifndef NO_LOGICAL_JOYSTICKS - if (SDL_joylist[joystick->index].fname == NULL) { - SDL_joylist_head(i, joystick->index); - return EV_HandleEvents(SDL_joylist[i].joy); - } -#endif - - while ((len=read(joystick->hwdata->fd, events, (sizeof events))) > 0) { - len /= sizeof(events[0]); - for ( i=0; i= BTN_MISC ) { - code -= BTN_MISC; -#ifndef NO_LOGICAL_JOYSTICKS - if (!LogicalJoystickButton(joystick, - joystick->hwdata->key_map[code], - events[i].value)) -#endif - SDL_PrivateJoystickButton(joystick, - joystick->hwdata->key_map[code], - events[i].value); - } - break; - case EV_ABS: - switch (code) { - case ABS_HAT0X: - case ABS_HAT0Y: - case ABS_HAT1X: - case ABS_HAT1Y: - case ABS_HAT2X: - case ABS_HAT2Y: - case ABS_HAT3X: - case ABS_HAT3Y: - code -= ABS_HAT0X; - HandleHat(joystick, code/2, code%2, - events[i].value); - break; - default: - events[i].value = EV_AxisCorrect(joystick, code, events[i].value); -#ifndef NO_LOGICAL_JOYSTICKS - if (!LogicalJoystickAxis(joystick, - joystick->hwdata->abs_map[code], - events[i].value)) -#endif - SDL_PrivateJoystickAxis(joystick, - joystick->hwdata->abs_map[code], - events[i].value); - break; - } - break; - case EV_REL: - switch (code) { - case REL_X: - case REL_Y: - code -= REL_X; - HandleBall(joystick, code/2, code%2, - events[i].value); - break; - default: - break; - } - break; - default: - break; - } - } - } -} -#endif /* SDL_INPUT_LINUXEV */ - -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) -{ - int i; - -#if SDL_INPUT_LINUXEV - if ( joystick->hwdata->is_hid ) - EV_HandleEvents(joystick); - else -#endif - JS_HandleEvents(joystick); - - /* Deliver ball motion updates */ - for ( i=0; inballs; ++i ) { - int xrel, yrel; - - xrel = joystick->hwdata->balls[i].axis[0]; - yrel = joystick->hwdata->balls[i].axis[1]; - if ( xrel || yrel ) { - joystick->hwdata->balls[i].axis[0] = 0; - joystick->hwdata->balls[i].axis[1] = 0; - SDL_PrivateJoystickBall(joystick, (Uint8)i, xrel, yrel); - } - } -} - -/* Function to close a joystick after use */ -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) -{ -#ifndef NO_LOGICAL_JOYSTICKS - register int i; - if (SDL_joylist[joystick->index].fname == NULL) { - SDL_joylist_head(i, joystick->index); - SDL_JoystickClose(SDL_joylist[i].joy); - } -#endif - - if ( joystick->hwdata ) { -#ifndef NO_LOGICAL_JOYSTICKS - if (SDL_joylist[joystick->index].fname != NULL) -#endif - close(joystick->hwdata->fd); - if ( joystick->hwdata->hats ) { - SDL_free(joystick->hwdata->hats); - } - if ( joystick->hwdata->balls ) { - SDL_free(joystick->hwdata->balls); - } - SDL_free(joystick->hwdata); - joystick->hwdata = NULL; - } -} - -/* Function to perform any system-specific joystick related cleanup */ -void SDL_SYS_JoystickQuit(void) -{ - int i; - - for ( i=0; SDL_joylist[i].fname; ++i ) { - SDL_free(SDL_joylist[i].fname); - SDL_joylist[i].fname = NULL; - } -} - -#endif /* SDL_JOYSTICK_LINUX */ diff --git a/apps/plugins/sdl/src/joystick/macos/SDL_sysjoystick.c b/apps/plugins/sdl/src/joystick/macos/SDL_sysjoystick.c deleted file mode 100644 index 3645dbd014..0000000000 --- a/apps/plugins/sdl/src/joystick/macos/SDL_sysjoystick.c +++ /dev/null @@ -1,320 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#ifdef SDL_JOYSTICK_MACOS - -/* SDL stuff -- "SDL_sysjoystick.c" - MacOS joystick functions by Frederick Reitberger - - The code that follows is meant for SDL. Use at your own risk. -*/ - -#include - -#include "SDL_joystick.h" -#include "../SDL_sysjoystick.h" -#include "../SDL_joystick_c.h" - - -/* The max number of joysticks we will detect */ -#define MAX_JOYSTICKS 16 -/* Limit ourselves to 32 elements per device */ -#define kMaxReferences 32 - -#define ISpSymmetricAxisToFloat(axis) ((((float) axis) - kISpAxisMiddle) / (kISpAxisMaximum-kISpAxisMiddle)) -#define ISpAsymmetricAxisToFloat(axis) (((float) axis) / (kISpAxisMaximum)) - - -static ISpDeviceReference SYS_Joysticks[MAX_JOYSTICKS]; -static ISpElementListReference SYS_Elements[MAX_JOYSTICKS]; -static ISpDeviceDefinition SYS_DevDef[MAX_JOYSTICKS]; - -struct joystick_hwdata -{ - char name[64]; -/* Uint8 id;*/ - ISpElementReference refs[kMaxReferences]; - /* gonna need some sort of mapping info */ -}; - - -/* Function to scan the system for joysticks. - * Joystick 0 should be the system default joystick. - * This function should return the number of available joysticks, or -1 - * on an unrecoverable fatal error. - */ -int SDL_SYS_JoystickInit(void) -{ - static ISpDeviceClass classes[4] = { - kISpDeviceClass_Joystick, - #if kISpDeviceClass_Gamepad - kISpDeviceClass_Gamepad, - #endif - kISpDeviceClass_Wheel, - 0 - }; - OSErr err; - int i; - UInt32 count, numJoysticks; - - if ( (Ptr)0 == (Ptr)ISpStartup ) { - SDL_SetError("InputSprocket not installed"); - return -1; // InputSprocket not installed - } - - if( (Ptr)0 == (Ptr)ISpGetVersion ) { - SDL_SetError("InputSprocket not version 1.1 or newer"); - return -1; // old version of ISp (not at least 1.1) - } - - ISpStartup(); - - /* Get all the joysticks */ - numJoysticks = 0; - for ( i=0; classes[i]; ++i ) { - count = 0; - err = ISpDevices_ExtractByClass( - classes[i], - MAX_JOYSTICKS-numJoysticks, - &count, - &SYS_Joysticks[numJoysticks]); - numJoysticks += count; - } - - for(i = 0; i < numJoysticks; i++) - { - ISpDevice_GetDefinition( - SYS_Joysticks[i], sizeof(ISpDeviceDefinition), - &SYS_DevDef[i]); - - err = ISpElementList_New( - 0, NULL, - &SYS_Elements[i], 0); - - if (err) { - SDL_OutOfMemory(); - return -1; - } - - ISpDevice_GetElementList( - SYS_Joysticks[i], - &SYS_Elements[i]); - } - - ISpDevices_Deactivate(numJoysticks, SYS_Joysticks); - - return numJoysticks; -} - -/* Function to get the device-dependent name of a joystick */ -const char *SDL_SYS_JoystickName(int index) -{ - static char name[64]; - int len; - - /* convert pascal string to c-string */ - len = SYS_DevDef[index].deviceName[0]; - if ( len >= sizeof(name) ) { - len = (sizeof(name) - 1); - } - SDL_memcpy(name, &SYS_DevDef[index].deviceName[1], len); - name[len] = '\0'; - - return name; -} - -/* Function to open a joystick for use. - The joystick to open is specified by the index field of the joystick. - This should fill the nbuttons and naxes fields of the joystick structure. - It returns 0, or -1 if there is an error. - */ -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) -{ - int index; - UInt32 count, gotCount, count2; - long numAxis, numButtons, numHats, numBalls; - - count = kMaxReferences; - count2 = 0; - numAxis = numButtons = numHats = numBalls = 0; - - index = joystick->index; - - /* allocate memory for system specific hardware data */ - joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata)); - if (joystick->hwdata == NULL) - { - SDL_OutOfMemory(); - return(-1); - } - SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); - SDL_strlcpy(joystick->hwdata->name, SDL_SYS_JoystickName(index), SDL_arraysize(joystick->hwdata->name)); - joystick->name = joystick->hwdata->name; - - ISpElementList_ExtractByKind( - SYS_Elements[index], - kISpElementKind_Axis, - count, - &gotCount, - joystick->hwdata->refs); - - numAxis = gotCount; - count -= gotCount; - count2 += gotCount; - - ISpElementList_ExtractByKind( - SYS_Elements[index], - kISpElementKind_DPad, - count, - &gotCount, - &(joystick->hwdata->refs[count2])); - - numHats = gotCount; - count -= gotCount; - count2 += gotCount; - - ISpElementList_ExtractByKind( - SYS_Elements[index], - kISpElementKind_Button, - count, - &gotCount, - &(joystick->hwdata->refs[count2])); - - numButtons = gotCount; - count -= gotCount; - count2 += gotCount; - - joystick->naxes = numAxis; - joystick->nhats = numHats; - joystick->nballs = numBalls; - joystick->nbuttons = numButtons; - - ISpDevices_Activate( - 1, - &SYS_Joysticks[index]); - - return 0; -} - -/* Function to update the state of a joystick - called as a device poll. - * This function shouldn't update the joystick structure directly, - * but instead should call SDL_PrivateJoystick*() to deliver events - * and update joystick device state. - */ -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) -{ - int i, j; - ISpAxisData a; - ISpDPadData b; - //ISpDeltaData c; - ISpButtonData d; - - for(i = 0, j = 0; i < joystick->naxes; i++, j++) - { - Sint16 value; - - ISpElement_GetSimpleState( - joystick->hwdata->refs[j], - &a); - value = (ISpSymmetricAxisToFloat(a)* 32767.0); - if ( value != joystick->axes[i] ) { - SDL_PrivateJoystickAxis(joystick, i, value); - } - } - - for(i = 0; i < joystick->nhats; i++, j++) - { - Uint8 pos; - - ISpElement_GetSimpleState( - joystick->hwdata->refs[j], - &b); - switch(b) { - case kISpPadIdle: - pos = SDL_HAT_CENTERED; - break; - case kISpPadLeft: - pos = SDL_HAT_LEFT; - break; - case kISpPadUpLeft: - pos = SDL_HAT_LEFTUP; - break; - case kISpPadUp: - pos = SDL_HAT_UP; - break; - case kISpPadUpRight: - pos = SDL_HAT_RIGHTUP; - break; - case kISpPadRight: - pos = SDL_HAT_RIGHT; - break; - case kISpPadDownRight: - pos = SDL_HAT_RIGHTDOWN; - break; - case kISpPadDown: - pos = SDL_HAT_DOWN; - break; - case kISpPadDownLeft: - pos = SDL_HAT_LEFTDOWN; - break; - } - if ( pos != joystick->hats[i] ) { - SDL_PrivateJoystickHat(joystick, i, pos); - } - } - - for(i = 0; i < joystick->nballs; i++, j++) - { - /* ignore balls right now */ - } - - for(i = 0; i < joystick->nbuttons; i++, j++) - { - ISpElement_GetSimpleState( - joystick->hwdata->refs[j], - &d); - if ( d != joystick->buttons[i] ) { - SDL_PrivateJoystickButton(joystick, i, d); - } - } -} - -/* Function to close a joystick after use */ -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) -{ - int index; - - index = joystick->index; - - ISpDevices_Deactivate( - 1, - &SYS_Joysticks[index]); -} - -/* Function to perform any system-specific joystick related cleanup */ -void SDL_SYS_JoystickQuit(void) -{ - ISpShutdown(); -} - -#endif /* SDL_JOYSTICK_MACOS */ diff --git a/apps/plugins/sdl/src/joystick/mint/SDL_sysjoystick.c b/apps/plugins/sdl/src/joystick/mint/SDL_sysjoystick.c deleted file mode 100644 index 9a36152927..0000000000 --- a/apps/plugins/sdl/src/joystick/mint/SDL_sysjoystick.c +++ /dev/null @@ -1,826 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#ifdef SDL_JOYSTICK_MINT - -/* - * Atari Joystick/Joypad drivers - * - * Patrice Mandin - */ - -#include -#include - -#include "SDL_events.h" -#include "../SDL_sysjoystick.h" -#include "../SDL_joystick_c.h" - -#include "../../video/ataricommon/SDL_ikbdinterrupt_s.h" -#include "../../video/ataricommon/SDL_xbiosevents_c.h" -#include "../../video/ataricommon/SDL_xbiosinterrupt_s.h" - -/*--- Const ---*/ - -/* We can have: - 1 joystick on IKBD port 1, read via hardware I/O - or same joystick on IKBD port 1, read via xbios - 1 joypad on port A (up to 4 with teamtap) - or 2 joysticks on joypad port A - or 1 analog paddle on joypad port A - or 1 lightpen on joypad port A - 1 joypad on port B (up to 4 with teamtap) - or 2 joysticks on joypad port B - or 1 analog paddle on joypad port B - 2 joysticks on parallel port -*/ - -enum { - IKBD_JOY1=0, - XBIOS_JOY1, - PORTA_PAD0, - PORTA_PAD1, - PORTA_PAD2, - PORTA_PAD3, - PORTB_PAD0, - PORTB_PAD1, - PORTB_PAD2, - PORTB_PAD3, - PORTA_JOY0, - PORTA_JOY1, - PORTB_JOY0, - PORTB_JOY1, - PORTA_LP, - PORTA_ANPAD, - PORTB_ANPAD, -#if 0 - PARA_JOY0, - PARA_JOY1, -#endif - MAX_JOYSTICKS -}; - -enum { - MCH_ST=0, - MCH_STE, - MCH_TT, - MCH_F30, - MCH_CLONE, - MCH_ARANYM -}; - -/* Joypad buttons - * Procontroller note: - * L,R are connected to 4,6 - * X,Y,Z are connected to 7,8,9 - */ - -enum { - JP_UP=0, JP_DOWN, JP_LEFT, JP_RIGHT, - JP_KPMULT, JP_KP7, JP_KP4, JP_KP1, - JP_KP0, JP_KP8, JP_KP5, JP_KP2, - JP_KPNUM, JP_KP9, JP_KP6, JP_KP3, - JP_PAUSE, JP_FIRE0, JP_UNDEF0, JP_FIRE1, - JP_UNDEF1, JP_FIRE2, JP_UNDEF2, JP_OPTION -}; - -#define JP_NUM_BUTTONS 17 - -#define PORT_JS_RIGHT (1<<0) -#define PORT_JS_LEFT (1<<1) -#define PORT_JS_DOWN (1<<2) -#define PORT_JS_UP (1<<3) -#define PORT_JS_FIRE (1<<4) - -enum { - TEAMTAP_MAYBE=0, - TEAMTAP_YES, - TEAMTAP_NO -}; - -/* Teamtap detection values */ -static const Uint32 teamtap_ghosts[20][4]={ - {1<>16) == MCH_STE) || - (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16) || - (cookie_mch == MCH_ARANYM<<16)) - { - atarijoysticks[IKBD_JOY1].enabled=(SDL_AtariIkbd_enabled!=0); - } - if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16) || - (cookie_mch == MCH_ARANYM<<16)) - { - atarijoysticks[PORTA_PAD0].enabled = - atarijoysticks[PORTA_PAD1].enabled = - atarijoysticks[PORTA_PAD2].enabled = - atarijoysticks[PORTA_PAD3].enabled = - atarijoysticks[PORTB_PAD0].enabled = - atarijoysticks[PORTB_PAD1].enabled = - atarijoysticks[PORTB_PAD2].enabled = - atarijoysticks[PORTB_PAD3].enabled = SDL_TRUE; - } - if (!atarijoysticks[IKBD_JOY1].enabled) { - atarijoysticks[XBIOS_JOY1].enabled=(SDL_AtariXbios_enabled!=0); - } - - /* Read environment for joysticks to enable */ - if (envr) { - /* IKBD on any Atari, maybe clones */ - if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) || - (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16) || - (cookie_mch == MCH_ARANYM<<16)) { - if (SDL_AtariIkbd_enabled!=0) { - TEST_JOY_ENABLED(envr, "ikbd-joy1", IKBD_JOY1); - } - } - /* Joypads ports on STE, Falcon and maybe others */ - if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16) || - (cookie_mch == MCH_ARANYM<<16)) { - TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD0); - if (!atarijoysticks[PORTA_PAD0].enabled) { - TEST_JOY_ENABLED(envr, "porta-joy0", PORTA_JOY0); - TEST_JOY_ENABLED(envr, "porta-joy1", PORTA_JOY1); - if (!(atarijoysticks[PORTA_JOY0].enabled) && !(atarijoysticks[PORTA_JOY1].enabled)) { - TEST_JOY_ENABLED(envr, "porta-lp", PORTA_LP); - if (!atarijoysticks[PORTA_LP].enabled) { - TEST_JOY_ENABLED(envr, "porta-anpad", PORTA_ANPAD); - } - } - } - - TEST_JOY_ENABLED(envr, "portb-pad", PORTB_PAD0); - if (!atarijoysticks[PORTB_PAD0].enabled) { - TEST_JOY_ENABLED(envr, "portb-joy0", PORTB_JOY0); - TEST_JOY_ENABLED(envr, "portb-joy1", PORTB_JOY1); - if (!(atarijoysticks[PORTB_JOY0].enabled) && !(atarijoysticks[PORTB_JOY1].enabled)) { - TEST_JOY_ENABLED(envr, "portb-anpad", PORTB_ANPAD); - } - } - } - - if (!atarijoysticks[IKBD_JOY1].enabled) { - if (SDL_AtariXbios_enabled!=0) { - TEST_JOY_ENABLED(envr, "xbios-joy1", XBIOS_JOY1); - } - } -#if 0 - /* Parallel port on any Atari, maybe clones */ - if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) || - (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) { - TEST_JOY_ENABLED(envr, "para-joy0", PARA_JOY0); - TEST_JOY_ENABLED(envr, "para-joy1", PARA_JOY1); - } -#endif - } - - /* Need to update joypad ports ? */ - joypad_ports_enabled=SDL_FALSE; - for (i=PORTA_PAD0;i<=PORTB_ANPAD;i++) { - if (atarijoysticks[i].enabled) { - joypad_ports_enabled=SDL_TRUE; - break; - } - } - - SDL_numjoysticks = 0; - for (i=0;iindex); - if (numjoystick==-1) - return -1; - - joystick->naxes=0; - joystick->nhats=0; - joystick->nballs=0; - - switch(numjoystick) { - case PORTA_PAD0: - case PORTA_PAD1: - case PORTA_PAD2: - case PORTA_PAD3: - case PORTB_PAD0: - case PORTB_PAD1: - case PORTB_PAD2: - case PORTB_PAD3: - joystick->nhats=1; - joystick->nbuttons=JP_NUM_BUTTONS; - break; - case PORTA_LP: - case PORTA_ANPAD: - case PORTB_ANPAD: - joystick->naxes=2; - joystick->nbuttons=2; - break; - default: - joystick->nhats=1; - joystick->nbuttons=1; - break; - } - - return(0); -} - -/* Detect Teamtap using ghost events */ -static void detect_teamtap(int num_port) -{ - int i,j; - - /* Check if joypad 1,2,3 triggered but not 0 */ - for (i=1; i<4; i++) { - if (jp_joypads[num_port*4+i] && (jp_joypads[num_port*4]==0)) { - has_teamtap[num_port] = TEAMTAP_YES; - return; - } - } - - /* Check if joypad 0 on a given port triggered ghost events for - * other joypads - */ - for (i=0; i<20; i++) { - int with_teamtap=1; - - if (jp_joypads[num_port*4]!=teamtap_ghosts[i][0]) - continue; - - /* If any button on first joypad pressed, check other pads */ - for (j=1; j<4; j++) { - if ((jp_joypads[num_port*4+j] & teamtap_ghosts[i][j]) - ==teamtap_ghosts[i][j]) - { - with_teamtap = 0; - } - } - - has_teamtap[num_port] = (with_teamtap ? TEAMTAP_YES : TEAMTAP_NO); - break; - } -} - -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) -{ - int numjoystick; - Uint8 hatstate; - Uint32 curstate,prevstate; - - numjoystick=GetEnabledAtariJoystick(joystick->index); - if (numjoystick==-1) - return; - - prevstate = atarijoysticks[numjoystick].prevstate; - - if (joypad_ports_enabled) { - Supexec(UpdateJoypads); - } - - switch (numjoystick) { - case IKBD_JOY1: - case XBIOS_JOY1: - { - curstate = 0; - - if (numjoystick==IKBD_JOY1) { - curstate = SDL_AtariIkbd_joystick & 0xff; - } - if (numjoystick==XBIOS_JOY1) { - curstate = SDL_AtariXbios_joystick & 0xff; - } - - if (curstate != prevstate) { - hatstate = SDL_HAT_CENTERED; - if (curstate & IKBD_JOY_LEFT) { - hatstate |= SDL_HAT_LEFT; - } - if (curstate & IKBD_JOY_RIGHT) { - hatstate |= SDL_HAT_RIGHT; - } - if (curstate & IKBD_JOY_UP) { - hatstate |= SDL_HAT_UP; - } - if (curstate & IKBD_JOY_DOWN) { - hatstate |= SDL_HAT_DOWN; - } - SDL_PrivateJoystickHat(joystick, 0, hatstate); - - /* Button */ - if ((curstate & IKBD_JOY_FIRE) && !(prevstate & IKBD_JOY_FIRE)) { - SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED); - } - if (!(curstate & IKBD_JOY_FIRE) && (prevstate & IKBD_JOY_FIRE)) { - SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED); - } - } - atarijoysticks[numjoystick].prevstate = curstate; - } - break; - case PORTA_PAD0: - case PORTA_PAD1: - case PORTA_PAD2: - case PORTA_PAD3: - case PORTB_PAD0: - case PORTB_PAD1: - case PORTB_PAD2: - case PORTB_PAD3: - { - int numjoypad,i,numport; - - numjoypad = numport = 0; - switch(numjoystick) { - case PORTA_PAD0: - numjoypad = 0; break; - case PORTA_PAD1: - numjoypad = 1; break; - case PORTA_PAD2: - numjoypad = 2; break; - case PORTA_PAD3: - numjoypad = 3; break; - case PORTB_PAD0: - numjoypad = 4; numport = 1; break; - case PORTB_PAD1: - numjoypad = 5; numport = 1; break; - case PORTB_PAD2: - numjoypad = 6; numport = 1; break; - case PORTB_PAD3: - numjoypad = 7; numport = 1; break; - } - - jp_joypads[numjoypad] &= 0xabffff; - - if (has_teamtap[numport]==TEAMTAP_MAYBE) { - detect_teamtap(numport); - } - /* No events for PORTX_PAD[1,2,3] if no teamtap detected */ - if (has_teamtap[numport] == TEAMTAP_NO) { - if ((numjoypad & 3)!=0) { - return; - } - } - - curstate=jp_joypads[numjoypad]; - if (curstate!=prevstate) { - hatstate = SDL_HAT_CENTERED; - if (curstate & (1<>dir_shift) & 15; - curstate |= ((jp_fires>>fire_shift) & 1)<<4; - - if (curstate != prevstate) { - hatstate = SDL_HAT_CENTERED; - if (curstate & PORT_JS_LEFT) { - hatstate |= SDL_HAT_LEFT; - } - if (curstate & PORT_JS_RIGHT) { - hatstate |= SDL_HAT_RIGHT; - } - if (curstate & PORT_JS_UP) { - hatstate |= SDL_HAT_UP; - } - if (curstate & PORT_JS_DOWN) { - hatstate |= SDL_HAT_DOWN; - } - SDL_PrivateJoystickHat(joystick, 0, hatstate); - - /* Button */ - if ((curstate & PORT_JS_FIRE) && !(prevstate & PORT_JS_FIRE)) { - SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED); - } - if (!(curstate & PORT_JS_FIRE) && (prevstate & PORT_JS_FIRE)) { - SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED); - } - } - atarijoysticks[numjoystick].prevstate = curstate; - } - break; - case PORTA_LP: - { - int i; - - curstate = jp_lightpens[0]>>1; - curstate |= (jp_lightpens[1]>>1)<<15; - curstate |= (jp_fires & 3)<<30; - - if (curstate != prevstate) { - /* X axis */ - SDL_PrivateJoystickAxis(joystick,0,jp_lightpens[0] ^ 0x8000); - /* Y axis */ - SDL_PrivateJoystickAxis(joystick,1,jp_lightpens[1] ^ 0x8000); - /* Buttons */ - for (i=0;i<2;i++) { - int button; - - button=1<<(30+i); - - if ((curstate & button) && !(prevstate & button)) { - SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED); - } - if (!(curstate & button) && (prevstate & button)) { - SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED); - } - } - } - atarijoysticks[numjoystick].prevstate = curstate; - } - break; - case PORTA_ANPAD: - case PORTB_ANPAD: - { - int numpaddle, i; - - numpaddle=0<<1; - if (numjoystick==PORTB_ANPAD) numpaddle=1<<1; - - curstate = jp_paddles[numpaddle]>>1; - curstate |= (jp_paddles[numpaddle+1]>>1)<<15; - curstate |= ((jp_fires>>numpaddle) & 3)<<30; - - if (curstate != prevstate) { - /* X axis */ - SDL_PrivateJoystickAxis(joystick,0,jp_paddles[numpaddle] ^ 0x8000); - /* Y axis */ - SDL_PrivateJoystickAxis(joystick,1,jp_paddles[numpaddle+1] ^ 0x8000); - /* Buttons */ - for (i=0;i<2;i++) { - int button; - - button=1<<(30+i); - - if ((curstate & button) && !(prevstate & button)) { - SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED); - } - if (!(curstate & button) && (prevstate & button)) { - SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED); - } - } - } - atarijoysticks[numjoystick].prevstate = curstate; - } - break; -#if 0 - case PARA_JOY0: - case PARA_JOY1: - break; -#endif - }; - - return; -} - -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) -{ - return; -} - -void SDL_SYS_JoystickQuit(void) -{ - SDL_numjoysticks=0; - return; -} - -/*--- Joypad I/O read/write interface ---*/ - -#define JOYPAD_IO_BASE (0xffff9200) -struct JOYPAD_IO_S { - Uint16 fires; - Uint16 directions; - Uint16 dummy1[6]; - Uint16 paddles[4]; - Uint16 dummy2[4]; - Uint16 lightpens[2]; -}; -#define JOYPAD_IO ((*(volatile struct JOYPAD_IO_S *)JOYPAD_IO_BASE)) - -static const Uint16 joypad_masks[8*4]={ - 0xfffe, 0xfffd, 0xfffb, 0xfff7, - 0xfff0, 0xfff1, 0xfff2, 0xfff3, - 0xfff4, 0xfff5, 0xfff6, 0xfff8, - 0xfff9, 0xfffa, 0xfffc, 0xffff, - 0xffef, 0xffdf, 0xffbf, 0xff7f, - 0xff0f, 0xff1f, 0xff2f, 0xff3f, - 0xff4f, 0xff5f, 0xff6f, 0xff8f, - 0xff9f, 0xffaf, 0xffcf, 0xffff -}; - -static void UpdateJoypads(void) -{ - Uint16 tmp, i, j; - Uint32 cur_fire, cur_dir; - - /*--- This function is called in supervisor mode ---*/ - - /* Update joysticks */ - jp_fires = (~(JOYPAD_IO.fires)) & 15; - jp_directions = (~(JOYPAD_IO.directions)); - - /* Update lightpen */ - tmp = JOYPAD_IO.lightpens[0] & 1023; - jp_lightpens[0] = (tmp<<6) | (tmp>>4); - tmp = JOYPAD_IO.lightpens[1] & 1023; - jp_lightpens[1] = (tmp<<6) | (tmp>>4); - - /* Update paddles */ - tmp = (JOYPAD_IO.paddles[0] & 255); - jp_paddles[0] = (tmp<<8) | tmp; - tmp = (JOYPAD_IO.paddles[1] & 255); - jp_paddles[1] = (tmp<<8) | tmp; - tmp = (JOYPAD_IO.paddles[2] & 255); - jp_paddles[2] = (tmp<<8) | tmp; - tmp = (JOYPAD_IO.paddles[3] & 255); - jp_paddles[3] = (tmp<<8) | tmp; - - /* Update joypads on teamtap port A */ - for (i=0; i<4; i++) { - jp_joypads[i] = 0; - for (j=0; j<4; j++) { - JOYPAD_IO.directions = joypad_masks[(i*4)+j]; - - cur_fire = (~(JOYPAD_IO.fires) & 3)<<16; - cur_dir = (~(JOYPAD_IO.directions)>>8) & 15; - - jp_joypads[i] |= cur_fire<<(j*2); - jp_joypads[i] |= cur_dir<<(j*4); - } - } - - /* Update joypads on teamtap port B */ - for (i=4; i<8; i++) { - jp_joypads[i] = 0; - for (j=0; j<4; j++) { - JOYPAD_IO.directions = joypad_masks[(i*4)+j]; - - cur_fire = (~(JOYPAD_IO.fires) & 0xc)<<14; - cur_dir = (~(JOYPAD_IO.directions)>>12) & 15; - - jp_joypads[i] |= cur_fire<<(j*2); - jp_joypads[i] |= cur_dir<<(j*4); - } - } - - JOYPAD_IO.directions=0xffff; -} - -#endif /* SDL_JOYSTICK_MINT */ diff --git a/apps/plugins/sdl/src/joystick/nds/SDL_sysjoystick.c b/apps/plugins/sdl/src/joystick/nds/SDL_sysjoystick.c deleted file mode 100644 index 122f48d863..0000000000 --- a/apps/plugins/sdl/src/joystick/nds/SDL_sysjoystick.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -/* This is the system specific header for the SDL joystick API */ -#include -//#include - -#include "SDL_error.h" -#include "SDL_events.h" -#include "SDL_joystick.h" -#include "../SDL_sysjoystick.h" -#include "../SDL_joystick_c.h" - -#include "../../video/nds/SDL_ndsevents_c.h" - -/* Function to scan the system for joysticks. - * This function should set SDL_numjoysticks to the number of available - * joysticks. Joystick 0 should be the system default joystick. - * It should return 0, or -1 on an unrecoverable fatal error. - */ -int SDL_SYS_JoystickInit(void) -{ - SDL_numjoysticks = 1; - //keysInit(); - - return(1); -} - -/* Function to get the device-dependent name of a joystick */ -const char *SDL_SYS_JoystickName(int index) -{ - if(!index) - return "NDS builtin joypad"; - SDL_SetError("No joystick available with that index"); - return (NULL); -} - -/* Function to open a joystick for use. - The joystick to open is specified by the index field of the joystick. - This should fill the nbuttons and naxes fields of the joystick structure. - It returns 0, or -1 if there is an error. - */ -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) -{ - joystick->nbuttons=8; - joystick->nhats=0; - joystick->nballs=0; - joystick->naxes=2; - return 0; -} - - -/* Function to update the state of a joystick - called as a device poll. - * This function shouldn't update the joystick structure directly, - * but instead should call SDL_PrivateJoystick*() to deliver events - * and update joystick device state. - */ - -int prevbutton=0; -int prevkey=0; - -int dc=0;int ldc=0; -u32 keysd,keysu=0; -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) -{ - //dc=keysd; - //if (dc) - //{ - //fprintf(stderr,"heartbeat= %d\n",REG_VCOUNT); - //swiWaitForVBlank(); - //scanKeys(); - //keysd = keysDown(); - //keysu = keysUp(); - //ldc=keysd; - - //} - /*if (prevkey && prevbutton) - { - scanKeys(); - } - */ - - //scanKeys(); - keysd = keysDown(); - keysu = keysUp(); - - - short ax=0,v=0,h=0; - if((keysd&KEY_UP)) {ax=1;v=-10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_UP;}//fprintf(stderr,"KEY_UP\n");} - if((keysd&KEY_DOWN)) {ax=1;v=10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_DOWN;}//fprintf(stderr,"KEY_DOWN\n");} - if((keysd&KEY_LEFT)) {ax=0;h=-10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_LEFT;}//fprintf(stderr,"KEY_LEFT\n");} - if((keysd&KEY_RIGHT)) {ax=0;h=10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_RIGHT;}//fprintf(stderr,"KEY_RIGHT\n");} - - if((keysu&KEY_UP)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=0;}//fprintf(stderr,"KEY_UP\n");} - if((keysu&KEY_DOWN)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=0;}//fprintf(stderr,"KEY_DOWN\n");} - if((keysu&KEY_LEFT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=0;}//fprintf(stderr,"KEY_LEFT\n");} - if((keysu&KEY_RIGHT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=0;}//fprintf(stderr,"KEY_RIGHT\n");} - - if((keysd&KEY_A)) {SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);prevbutton=KEY_A;} - if((keysd&KEY_B)) {SDL_PrivateJoystickButton(joystick,1,SDL_PRESSED);prevbutton=KEY_B;} - if((keysd&KEY_X)) {SDL_PrivateJoystickButton(joystick,2,SDL_PRESSED);prevbutton=KEY_X;} - if((keysd&KEY_Y)) {SDL_PrivateJoystickButton(joystick,3,SDL_PRESSED);prevbutton=KEY_Y;} - if((keysd&KEY_SELECT)) {SDL_PrivateJoystickButton(joystick,6,SDL_PRESSED);prevbutton=KEY_SELECT;} - if((keysd&KEY_START)) {SDL_PrivateJoystickButton(joystick,7,SDL_PRESSED);prevbutton=KEY_START;} - if((keysd&KEY_L)) {SDL_PrivateJoystickButton(joystick,4,SDL_PRESSED);prevbutton=KEY_L;} - if((keysd&KEY_R)) {SDL_PrivateJoystickButton(joystick,5,SDL_PRESSED);prevbutton=KEY_R;} - - if((keysu&KEY_A)) {SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);prevbutton=0;} - if((keysu&KEY_B)) {SDL_PrivateJoystickButton(joystick,1,SDL_RELEASED);prevbutton=0;} - if((keysu&KEY_X)) {SDL_PrivateJoystickButton(joystick,2,SDL_RELEASED);prevbutton=0;} - if((keysu&KEY_Y)) {SDL_PrivateJoystickButton(joystick,3,SDL_RELEASED);prevbutton=0;} - if((keysu&KEY_SELECT)) {SDL_PrivateJoystickButton(joystick,6,SDL_RELEASED);prevbutton=0;} - if((keysu&KEY_START)) {SDL_PrivateJoystickButton(joystick,7,SDL_RELEASED);prevbutton=0;} - if((keysu&KEY_L)) {SDL_PrivateJoystickButton(joystick,4,SDL_RELEASED);prevbutton=0;} - if((keysu&KEY_R)) {SDL_PrivateJoystickButton(joystick,5,SDL_RELEASED);prevbutton=0;} - - - -} - -/* Function to close a joystick after use */ -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) -{ -} - -/* Function to perform any system-specific joystick related cleanup */ -void SDL_SYS_JoystickQuit(void) -{ -} - diff --git a/apps/plugins/sdl/src/joystick/riscos/SDL_sysjoystick.c b/apps/plugins/sdl/src/joystick/riscos/SDL_sysjoystick.c deleted file mode 100644 index 214d4c7474..0000000000 --- a/apps/plugins/sdl/src/joystick/riscos/SDL_sysjoystick.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#ifdef SDL_JOYSTICK_RISCOS - -/* - RISC OS - Joystick support by Alan Buckley (alan_baa@hotmail.com) - 10 April 2003 - - Note: Currently assumes joystick is present if joystick module is loaded - and that there is one joystick with four buttons. -*/ - -/* This is the system specific header for the SDL joystick API */ - -#include "SDL_events.h" -#include "SDL_joystick.h" -#include "../SDL_sysjoystick.h" -#include "../SDL_joystick_c.h" - -#include "kernel.h" - -#define JOYSTICK_READ 0x43F40 - -struct joystick_hwdata -{ - int joystate; -}; - - -/* Function to scan the system for joysticks. - * This function should set SDL_numjoysticks to the number of available - * joysticks. Joystick 0 should be the system default joystick. - * It should return number of joysticks, or -1 on an unrecoverable fatal error. - */ -int SDL_SYS_JoystickInit(void) -{ - _kernel_swi_regs regs; - - /* Try to read joystick 0 */ - regs.r[0] = 0; - if (_kernel_swi(JOYSTICK_READ, ®s, ®s) == NULL) - { - /* Switch works so assume we've got a joystick */ - return 1; - } - /* Switch fails so it looks like there's no joystick here */ - - return(0); -} - -/* Function to get the device-dependent name of a joystick */ -const char *SDL_SYS_JoystickName(int index) -{ - if (index == 0) - { - return "RISC OS Joystick 0"; - } - - SDL_SetError("No joystick available with that index"); - return(NULL); -} - -/* Function to open a joystick for use. - The joystick to open is specified by the index field of the joystick. - This should fill the nbuttons and naxes fields of the joystick structure. - It returns 0, or -1 if there is an error. - */ -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) -{ - _kernel_swi_regs regs; - - if(!(joystick->hwdata=SDL_malloc(sizeof(struct joystick_hwdata)))) - return -1; - - regs.r[0] = joystick->index; - - /* Don't know how to get exact count of buttons so assume max of 4 for now */ - joystick->nbuttons=4; - - joystick->nhats=0; - joystick->nballs=0; - joystick->naxes=2; - joystick->hwdata->joystate=0; - - return 0; - -} - -/* Function to update the state of a joystick - called as a device poll. - * This function shouldn't update the joystick structure directly, - * but instead should call SDL_PrivateJoystick*() to deliver events - * and update joystick device state. - */ -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) -{ - _kernel_swi_regs regs; - regs.r[0] = joystick->index; - - if (_kernel_swi(JOYSTICK_READ, ®s, ®s) == NULL) - { - int newstate = regs.r[0]; - int oldstate = joystick->hwdata->joystate; - if (newstate != oldstate) - { - if ((newstate & 0xFF) != (oldstate & 0xFF)) - { - int y = regs.r[0] & 0xFF; - /* Convert to signed values */ - if (y >= 128) y -= 256; - SDL_PrivateJoystickAxis(joystick,1,-y * 256); /* Up and down opposite to result in SDL */ - } - if ((newstate & 0xFF00) != (oldstate & 0xFF00)) - { - int x = (regs.r[0] & 0xFF00) >> 8; - if (x >= 128) x -= 256; - SDL_PrivateJoystickAxis(joystick,0,x * 256); - } - - if ((newstate & 0xFF0000) != (oldstate & 0xFF0000)) - { - int buttons = (regs.r[0] & 0xFF0000) >> 16; - int oldbuttons = (oldstate & 0xFF0000) >> 16; - int i; - for (i = 0; i < joystick->nbuttons; i++) - { - if ((buttons & (1<hwdata->joystate = newstate; - } - } - - return; -} - -/* Function to close a joystick after use */ -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) -{ - if(joystick->hwdata) - SDL_free(joystick->hwdata); - return; -} - -/* Function to perform any system-specific joystick related cleanup */ -void SDL_SYS_JoystickQuit(void) -{ - SDL_numjoysticks=0; - - return; -} - -#endif /* SDL_JOYSTICK_RISCOS */ diff --git a/apps/plugins/sdl/src/joystick/win32/SDL_mmjoystick.c b/apps/plugins/sdl/src/joystick/win32/SDL_mmjoystick.c deleted file mode 100644 index 8c53f9e3dd..0000000000 --- a/apps/plugins/sdl/src/joystick/win32/SDL_mmjoystick.c +++ /dev/null @@ -1,407 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#ifdef SDL_JOYSTICK_WINMM - -/* Win32 MultiMedia Joystick driver, contributed by Andrei de A. Formiga */ - -#define WIN32_LEAN_AND_MEAN -#include -#include -#include - -#include "SDL_events.h" -#include "SDL_joystick.h" -#include "../SDL_sysjoystick.h" -#include "../SDL_joystick_c.h" - -#define MAX_JOYSTICKS 16 -#define MAX_AXES 6 /* each joystick can have up to 6 axes */ -#define MAX_BUTTONS 32 /* and 32 buttons */ -#define AXIS_MIN -32768 /* minimum value for axis coordinate */ -#define AXIS_MAX 32767 /* maximum value for axis coordinate */ -/* limit axis to 256 possible positions to filter out noise */ -#define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/256) -#define JOY_BUTTON_FLAG(n) (1<index; - axis_min[0] = SYS_Joystick[index].wXmin; - axis_max[0] = SYS_Joystick[index].wXmax; - axis_min[1] = SYS_Joystick[index].wYmin; - axis_max[1] = SYS_Joystick[index].wYmax; - axis_min[2] = SYS_Joystick[index].wZmin; - axis_max[2] = SYS_Joystick[index].wZmax; - axis_min[3] = SYS_Joystick[index].wRmin; - axis_max[3] = SYS_Joystick[index].wRmax; - axis_min[4] = SYS_Joystick[index].wUmin; - axis_max[4] = SYS_Joystick[index].wUmax; - axis_min[5] = SYS_Joystick[index].wVmin; - axis_max[5] = SYS_Joystick[index].wVmax; - - /* allocate memory for system specific hardware data */ - joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata)); - if (joystick->hwdata == NULL) - { - SDL_OutOfMemory(); - return(-1); - } - SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); - - /* set hardware data */ - joystick->hwdata->id = SYS_JoystickID[index]; - for ( i = 0; i < MAX_AXES; ++i ) { - if ( (i<2) || (SYS_Joystick[index].wCaps & caps_flags[i-2]) ) { - joystick->hwdata->transaxis[i].offset = - AXIS_MIN - axis_min[i]; - joystick->hwdata->transaxis[i].scale = - (float)(AXIS_MAX - AXIS_MIN) / (axis_max[i] - axis_min[i]); - } else { - joystick->hwdata->transaxis[i].offset = 0; - joystick->hwdata->transaxis[i].scale = 1.0; /* Just in case */ - } - } - - /* fill nbuttons, naxes, and nhats fields */ - joystick->nbuttons = SYS_Joystick[index].wNumButtons; - joystick->naxes = SYS_Joystick[index].wNumAxes; - if ( SYS_Joystick[index].wCaps & JOYCAPS_HASPOV ) { - joystick->nhats = 1; - } else { - joystick->nhats = 0; - } - return(0); -} - -static Uint8 TranslatePOV(DWORD value) -{ - Uint8 pos; - - pos = SDL_HAT_CENTERED; - if ( value != JOY_POVCENTERED ) { - if ( (value > JOY_POVLEFT) || (value < JOY_POVRIGHT) ) { - pos |= SDL_HAT_UP; - } - if ( (value > JOY_POVFORWARD) && (value < JOY_POVBACKWARD) ) { - pos |= SDL_HAT_RIGHT; - } - if ( (value > JOY_POVRIGHT) && (value < JOY_POVLEFT) ) { - pos |= SDL_HAT_DOWN; - } - if ( value > JOY_POVBACKWARD ) { - pos |= SDL_HAT_LEFT; - } - } - return(pos); -} - -/* Function to update the state of a joystick - called as a device poll. - * This function shouldn't update the joystick structure directly, - * but instead should call SDL_PrivateJoystick*() to deliver events - * and update joystick device state. - */ -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) -{ - MMRESULT result; - int i; - DWORD flags[MAX_AXES] = { JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ, - JOY_RETURNR, JOY_RETURNU, JOY_RETURNV }; - DWORD pos[MAX_AXES]; - struct _transaxis *transaxis; - int value, change; - JOYINFOEX joyinfo; - - joyinfo.dwSize = sizeof(joyinfo); - joyinfo.dwFlags = JOY_RETURNALL|JOY_RETURNPOVCTS; - if ( ! joystick->hats ) { - joyinfo.dwFlags &= ~(JOY_RETURNPOV|JOY_RETURNPOVCTS); - } - result = joyGetPosEx(joystick->hwdata->id, &joyinfo); - if ( result != JOYERR_NOERROR ) { - SetMMerror("joyGetPosEx", result); - return; - } - - /* joystick motion events */ - pos[0] = joyinfo.dwXpos; - pos[1] = joyinfo.dwYpos; - pos[2] = joyinfo.dwZpos; - pos[3] = joyinfo.dwRpos; - pos[4] = joyinfo.dwUpos; - pos[5] = joyinfo.dwVpos; - - transaxis = joystick->hwdata->transaxis; - for (i = 0; i < joystick->naxes; i++) { - if (joyinfo.dwFlags & flags[i]) { - value = (int)(((float)pos[i] + transaxis[i].offset) * transaxis[i].scale); - change = (value - joystick->axes[i]); - if ( (change < -JOY_AXIS_THRESHOLD) || (change > JOY_AXIS_THRESHOLD) ) { - SDL_PrivateJoystickAxis(joystick, (Uint8)i, (Sint16)value); - } - } - } - - /* joystick button events */ - if ( joyinfo.dwFlags & JOY_RETURNBUTTONS ) { - for ( i = 0; i < joystick->nbuttons; ++i ) { - if ( joyinfo.dwButtons & JOY_BUTTON_FLAG(i) ) { - if ( ! joystick->buttons[i] ) { - SDL_PrivateJoystickButton(joystick, (Uint8)i, SDL_PRESSED); - } - } else { - if ( joystick->buttons[i] ) { - SDL_PrivateJoystickButton(joystick, (Uint8)i, SDL_RELEASED); - } - } - } - } - - /* joystick hat events */ - if ( joyinfo.dwFlags & JOY_RETURNPOV ) { - Uint8 pos; - - pos = TranslatePOV(joyinfo.dwPOV); - if ( pos != joystick->hats[0] ) { - SDL_PrivateJoystickHat(joystick, 0, pos); - } - } -} - -/* Function to close a joystick after use */ -void SDL_SYS_JoystickClose(SDL_Joystick *joystick) -{ - if (joystick->hwdata != NULL) { - /* free system specific hardware data */ - SDL_free(joystick->hwdata); - joystick->hwdata = NULL; - } -} - -/* Function to perform any system-specific joystick related cleanup */ -void SDL_SYS_JoystickQuit(void) -{ - int i; - for (i = 0; i < MAX_JOYSTICKS; i++) { - if ( SYS_JoystickName[i] != NULL ) { - SDL_free(SYS_JoystickName[i]); - SYS_JoystickName[i] = NULL; - } - } -} - - -/* implementation functions */ -void SetMMerror(char *function, int code) -{ - static char *error; - static char errbuf[1024]; - - errbuf[0] = 0; - switch (code) - { - case MMSYSERR_NODRIVER: - error = "Joystick driver not present"; - break; - - case MMSYSERR_INVALPARAM: - case JOYERR_PARMS: - error = "Invalid parameter(s)"; - break; - - case MMSYSERR_BADDEVICEID: - error = "Bad device ID"; - break; - - case JOYERR_UNPLUGGED: - error = "Joystick not attached"; - break; - - case JOYERR_NOCANDO: - error = "Can't capture joystick input"; - break; - - default: - SDL_snprintf(errbuf, SDL_arraysize(errbuf), - "%s: Unknown Multimedia system error: 0x%x", - function, code); - break; - } - - if ( ! errbuf[0] ) { - SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error); - } - SDL_SetError("%s", errbuf); -} - -#endif /* SDL_JOYSTICK_WINMM */ -- cgit v1.2.3