head 1.2; access; symbols pkgsrc-2013Q2:1.2.0.48 pkgsrc-2013Q2-base:1.2 pkgsrc-2012Q4:1.2.0.46 pkgsrc-2012Q4-base:1.2 pkgsrc-2011Q4:1.2.0.44 pkgsrc-2011Q4-base:1.2 pkgsrc-2011Q2:1.2.0.42 pkgsrc-2011Q2-base:1.2 pkgsrc-2009Q4:1.2.0.40 pkgsrc-2009Q4-base:1.2 pkgsrc-2008Q4:1.2.0.38 pkgsrc-2008Q4-base:1.2 pkgsrc-2008Q3:1.2.0.36 pkgsrc-2008Q3-base:1.2 cube-native-xorg:1.2.0.34 cube-native-xorg-base:1.2 pkgsrc-2008Q2:1.2.0.32 pkgsrc-2008Q2-base:1.2 pkgsrc-2008Q1:1.2.0.30 pkgsrc-2008Q1-base:1.2 pkgsrc-2007Q4:1.2.0.28 pkgsrc-2007Q4-base:1.2 pkgsrc-2007Q3:1.2.0.26 pkgsrc-2007Q3-base:1.2 pkgsrc-2007Q2:1.2.0.24 pkgsrc-2007Q2-base:1.2 pkgsrc-2007Q1:1.2.0.22 pkgsrc-2007Q1-base:1.2 pkgsrc-2006Q4:1.2.0.20 pkgsrc-2006Q4-base:1.2 pkgsrc-2006Q3:1.2.0.18 pkgsrc-2006Q3-base:1.2 pkgsrc-2006Q2:1.2.0.16 pkgsrc-2006Q2-base:1.2 pkgsrc-2006Q1:1.2.0.14 pkgsrc-2006Q1-base:1.2 pkgsrc-2005Q4:1.2.0.12 pkgsrc-2005Q4-base:1.2 pkgsrc-2005Q3:1.2.0.10 pkgsrc-2005Q3-base:1.2 pkgsrc-2005Q2:1.2.0.8 pkgsrc-2005Q2-base:1.2 pkgsrc-2005Q1:1.2.0.6 pkgsrc-2005Q1-base:1.2 pkgsrc-2004Q4:1.2.0.4 pkgsrc-2004Q4-base:1.2 pkgsrc-2004Q3:1.2.0.2 pkgsrc-2004Q3-base:1.2; locks; strict; comment @# @; 1.2 date 2004.08.31.15.53.09; author dillo; state dead; branches; next 1.1; 1.1 date 2004.07.26.17.22.40; author dillo; state Exp; branches; next ; desc @@ 1.2 log @update to 1.15: ** General - Improved event recording and playback. ** C64 changes - Fixed some CPU opcodes. - Added support for Magic Formel cart (preliminary). - Improved TFE cart emulation. - Fixed Final Cartridge III freeze bug. ** VIC20 changes - Four true drives are supported now. - The sound code has been rewritten. ** PLUS4 changes - Added cartridge support. ** VIC-II - Improved IRQ timing during DMA. ** Unix Changes - Improved ROM set support. - Added TFE and IDE64 cart support. - Fixed crash on 64bit archs. - Added BSD USB joystick support. - Complete rework of french translation. Credits to Paul (alias Kaddict)! ** Miscellaneous changes - Made fsdevice emulation to list non-PRG files again. - Improved REL file handling of the virtual drive emulation. - Fixed some bugs in the petcat tokenizer. @ text @$NetBSD: patch-bi,v 1.1 2004/07/26 17:22:40 dillo Exp $ --- src/arch/unix/joy_usb.c.orig 2004-07-26 14:35:45.000000000 +0200 +++ src/arch/unix/joy_usb.c @@@@ -0,0 +1,305 @@@@ +/* + * joy_usb.c - NetBSD/FreeBSD USB joystick support. + * + * Written by + * Dieter Baron + * + * This file is part of VICE, the Versatile Commodore Emulator. + * See README for copyright notice. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + * + */ + +#include "vice.h" + +#include +#include +#include + +#include "cmdline.h" +#include "joy.h" +#include "joystick.h" +#include "keyboard.h" +#include "log.h" +#include "resources.h" +#include "types.h" + +#if defined(HAS_JOYSTICK) && defined(HAS_USB_JOYSTICK) + +#define ITEM_AXIS 0 +#define ITEM_BUTTON 1 +#define ITEM_HAT 2 + +int hat_or[] = { + 1, 9, 8, 10, 2, 6, 4, 5, +}; + +extern log_t joystick_log; + +#include +#include +#include +#include +#ifdef HAVE_USBHID_H +#include +#else +#include +#endif + +#define MAX_DEV 4 /* number of uhid devices to try */ + +struct usb_joy_item { + struct hid_item item; + struct usb_joy_item *next; + + int is_hat; + int min_or; + int min_val; + int max_or; + int max_val; +}; + +static struct usb_joy_item *usb_joy_item[2]; + +static int usb_joy_fd[2] = { -1, -1 }; +static int usb_joy_size[2]; +static char *usb_joy_buf[2]; + +static int usb_joy_add_item(struct usb_joy_item **item, struct hid_item *hi, + int orval, int type) +{ + struct usb_joy_item *it; + int w; + + if ((it=malloc(sizeof(*it))) == NULL) { + /* XXX */ + return -1; + } + + it->next = *item; + *item = it; + + memcpy(&it->item, hi, sizeof(*hi)); + switch (type) { + case ITEM_AXIS: + w = (hi->logical_maximum-hi->logical_minimum)/3; + it->is_hat = 0; + it->min_or = orval; + it->min_val = hi->logical_minimum+w; + it->max_or = orval*2; + it->max_val = hi->logical_maximum-w; + break; + + case ITEM_BUTTON: + it->is_hat = 0; + it->min_or = 0; + it->min_val = -1; + it->max_or = orval; + it->max_val = hi->logical_maximum-1; + break; + + case ITEM_HAT: + it->is_hat = 1; + it->min_val = hi->logical_minimum; + break; + } + + return 0; +} + +static void usb_free_item(struct usb_joy_item **item) +{ + struct usb_joy_item *it, *it2; + + it=*item; + while (it) { + it2 = it; + it = it->next; + free(it2); + } + *item = NULL; +} + +int usb_joystick_init(void) +{ + int i, j, id, fd; + report_desc_t report; + struct hid_item h; + struct hid_data *d; + int is_joy, found; + char dev[32]; + + for (j=i=0; i<2 && jnext) { + val = hid_get_data(usb_joy_buf[jp], &it->item); + if (it->is_hat) { + val -= it->min_val; + if (val >= 0 && val <= 7) + joystick_set_value_or(i+1, hat_or[val]); + } + else { + if (val <= it->min_val) { + joystick_set_value_or(i+1, it->min_or); + } + else if (val > it->max_val) { + joystick_set_value_or(i+1, it->max_or); + } + } + } + } +} + +#endif /* HAS_JOYSTICK && HAS_USB_JOYSTICK */ + @ 1.1 log @various improvements: - enable fullscreen support - enable PNG screenshots - only use esound if USE_ESOUND is yes - add USB joystick support (okayed by kristerw) PKGREVISION++ @ text @d1 1 a1 1 $NetBSD$ @