1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
/* svgajoystick.c: Joystick emulation (using svgalib)
Copyright (c) 2003-4 Darren Salt
$Id: svgajoystick.c 4015 2009-05-04 13:07:43Z fredm $
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.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Author contact information:
E-mail: philip-fuse@shadowmagic.org.uk
Darren: linux@youmustbejoking.demon.co.uk
*/
#include <config.h>
#if !defined USE_JOYSTICK || defined HAVE_JSW_H
/* Fake joystick, or override UI-specific handling */
#include "../uijoystick.c"
#else /* #if !defined USE_JOYSTICK || defined HAVE_JSW_H */
/* Use the svgalib joystick support */
#include <string.h>
#include <errno.h>
#include <libspectrum.h>
#include <vgajoystick.h>
#include "fuse.h"
#include "joystick.h"
#include "keyboard.h"
#include "settings.h"
#include "spectrum.h"
#include "machine.h"
#include "ui/ui.h"
static int sticks = 0;
static int buttons[2];
static void joy_handler( int ev, int number, char value, int which );
static int
init_stick( int which )
{
if( !joystick_init( which, JOY_CALIB_STDOUT ) ) {
ui_error( UI_ERROR_ERROR, "failed to initialise joystick %i: %s",
which + 1, errno ? strerror (errno) : "not configured?" );
return 1;
}
if( joystick_getnumaxes( which ) < 2 ||
joystick_getnumbuttons( which ) < 1 ) {
joystick_close( which );
ui_error( UI_ERROR_ERROR, "sorry, joystick %i is inadequate!", which + 1 );
return 1;
}
buttons[which] = joystick_getnumbuttons( which );
if( buttons[which] > 10 ) buttons[which] = 10;
return 0;
}
int
ui_joystick_init( void )
{
int i;
/* If we can't init the first, don't try the second */
if( init_stick( 0 ) ) {
sticks = 0;
} else if( init_stick( 1 ) ) {
sticks = 1;
} else {
sticks = 2;
}
for( i = 0; i < sticks; i++ ) {
joystick_sethandler( i, joy_handler );
}
return sticks;
}
void
ui_joystick_end( void )
{
joystick_close( -1 );
}
static void
do_axis( int which, int position, input_key negative, input_key positive )
{
input_event_t event1, event2;
event1.types.joystick.which = event2.types.joystick.which = which;
event1.types.joystick.button = positive;
event2.types.joystick.button = negative;
event1.type = position > 0 ? INPUT_EVENT_JOYSTICK_PRESS :
INPUT_EVENT_JOYSTICK_RELEASE;
event2.type = position < 0 ? INPUT_EVENT_JOYSTICK_PRESS :
INPUT_EVENT_JOYSTICK_RELEASE;
input_event( &event1 );
input_event( &event2 );
}
static void
joy_handler( int ev, int number, char value, int which )
{
input_event_t event;
switch ( ev ) {
case JOY_EVENTAXIS:
if( number == 0 )
do_axis( which, value, INPUT_JOYSTICK_LEFT, INPUT_JOYSTICK_RIGHT );
else if( number == 1 )
do_axis( which, value, INPUT_JOYSTICK_UP, INPUT_JOYSTICK_DOWN );
break;
case JOY_EVENTBUTTONDOWN:
case JOY_EVENTBUTTONUP:
if( number >= buttons[which] ) return;
event.types.joystick.which = which;
event.types.joystick.button = INPUT_JOYSTICK_FIRE_1 + number;
event.type = ( ev == JOY_EVENTBUTTONDOWN )
? INPUT_EVENT_JOYSTICK_PRESS
: INPUT_EVENT_JOYSTICK_RELEASE;
input_event( &event );
break;
default:
break;
}
}
void
ui_joystick_poll( void )
{
}
#endif /* #if !defined USE_JOYSTICK || defined HAVE_JSW_H */
|