Search
lxdream.org :: lxdream :: r1010:a506a2f66180
lxdream 0.9.1
released Jun 29
Download Now
changeset1010:a506a2f66180
parent1009:c29795e15cef
child1014:f5914b2fd0db
authornkeynes
dateSun Apr 12 02:04:27 2009 +0000 (15 years ago)
Fix analogue joystick input
src/display.c
src/display.h
src/drivers/joy_linux.c
src/drivers/video_osx.m
src/gtkui/gtk_win.c
src/maple/controller.c
1.1 --- a/src/display.c Sun Apr 12 00:04:15 2009 +0000
1.2 +++ b/src/display.c Sun Apr 12 02:04:27 2009 +0000
1.3 @@ -354,18 +354,18 @@
1.4 }
1.5 }
1.6
1.7 -void input_event_keyup( input_driver_t driver, uint16_t keycode, uint32_t pressure )
1.8 +void input_event_keyup( input_driver_t driver, uint16_t keycode )
1.9 {
1.10 if( display_focused ) {
1.11 keymap_entry_t *entryp = input_entry_from_keycode(driver,keycode);
1.12 if( entryp != NULL && *entryp != NULL ) {
1.13 - (*entryp)->callback( (*entryp)->data, (*entryp)->value, pressure, FALSE );
1.14 + (*entryp)->callback( (*entryp)->data, (*entryp)->value, 0, FALSE );
1.15 }
1.16
1.17 if( driver == NULL ) {
1.18 keymap_entry_t key = keyhooks;
1.19 while( key != NULL ) {
1.20 - key->callback( key->data, keycode, pressure, FALSE );
1.21 + key->callback( key->data, keycode, 0, FALSE );
1.22 key = key->next;
1.23 }
1.24 }
1.25 @@ -458,7 +458,7 @@
1.26 mouse_y = y;
1.27 }
1.28 mouse_buttons |= (1<<button);
1.29 - input_event_keydown( &system_mouse_driver, button+1, 1 );
1.30 + input_event_keydown( &system_mouse_driver, button+1, MAX_PRESSURE );
1.31 input_event_run_mouse_hooks( mouse_buttons, x, y, absolute );
1.32 }
1.33
1.34 @@ -469,7 +469,7 @@
1.35 mouse_y = y;
1.36 }
1.37 mouse_buttons &= ~(1<<button);
1.38 - input_event_keyup( &system_mouse_driver, button+1, 1 );
1.39 + input_event_keyup( &system_mouse_driver, button+1 );
1.40 input_event_run_mouse_hooks( mouse_buttons, x, y, absolute );
1.41 }
1.42
2.1 --- a/src/display.h Sun Apr 12 00:04:15 2009 +0000
2.2 +++ b/src/display.h Sun Apr 12 02:04:27 2009 +0000
2.3 @@ -227,6 +227,9 @@
2.4
2.5 #define MAX_MOUSE_BUTTONS 32
2.6
2.7 +/* Pressure is 0..127 (allowing a joystick to be defined as two half-axes of 7- bits each) */
2.8 +#define MAX_PRESSURE 0x7F
2.9 +
2.10 typedef void (*input_key_callback_t)( void *data, uint32_t value, uint32_t pressure, gboolean isKeyDown );
2.11
2.12 /**
2.13 @@ -337,9 +340,18 @@
2.14 */
2.15 void display_set_focused( gboolean has_focus );
2.16
2.17 +/**
2.18 + * Fire a keydown event on the specified device
2.19 + * @param input The input device source generating the event, or NULL for the
2.20 + * default GUI device
2.21 + * @param keycode The device-specific keycode
2.22 + * @param pressure The pressure of the key (0 to 127), where 0 is unpressed and
2.23 + * 127 is maximum pressure. Devices without pressure sensitivity should
2.24 + * always use MAX_PRESSURE (127)
2.25 + */
2.26 void input_event_keydown( input_driver_t input, uint16_t keycode, uint32_t pressure );
2.27
2.28 -void input_event_keyup( input_driver_t input, uint16_t keycode, uint32_t pressure );
2.29 +void input_event_keyup( input_driver_t input, uint16_t keycode );
2.30
2.31 /**
2.32 * Receive an input mouse down event. Normally these should be absolute events when
3.1 --- a/src/drivers/joy_linux.c Sun Apr 12 00:04:15 2009 +0000
3.2 +++ b/src/drivers/joy_linux.c Sun Apr 12 02:04:27 2009 +0000
3.3 @@ -52,6 +52,11 @@
3.4
3.5 } *linux_joystick_t;
3.6
3.7 +/* Linux joysticks return data in the range -32767 to 32767 - rescale this to
3.8 + * -127 .. 127
3.9 + */
3.10 +#define SCALE_PRESSURE(x) ((x)>>8)
3.11 +
3.12 static gboolean linux_joystick_callback( GIOChannel *source, GIOCondition condition,
3.13 gpointer data );
3.14 static int linux_joystick_scan();
3.15 @@ -146,21 +151,21 @@
3.16 if( event.type == JS_EVENT_BUTTON ) {
3.17 int keycode = event.number+1;
3.18 if( event.value == 0 ) {
3.19 - input_event_keyup( (input_driver_t)joy, keycode, 0 );
3.20 + input_event_keyup( (input_driver_t)joy, keycode );
3.21 } else {
3.22 - input_event_keydown( (input_driver_t)joy, keycode, event.value );
3.23 + input_event_keydown( (input_driver_t)joy, keycode, MAX_PRESSURE );
3.24 }
3.25 } else if( event.type == JS_EVENT_AXIS ) {
3.26 int keycode = (event.number*2) + joy->button_count + 1;
3.27 if( event.value == 0 ) {
3.28 - input_event_keyup( (input_driver_t)joy, keycode, 0 );
3.29 - input_event_keyup( (input_driver_t)joy, keycode+1, 0 );
3.30 + input_event_keyup( (input_driver_t)joy, keycode );
3.31 + input_event_keyup( (input_driver_t)joy, keycode+1 );
3.32 } else if( event.value < 0 ) {
3.33 - input_event_keydown( (input_driver_t)joy, keycode+1, -event.value );
3.34 - input_event_keyup( (input_driver_t)joy, keycode, 0 );
3.35 + input_event_keyup( (input_driver_t)joy, keycode );
3.36 + input_event_keydown( (input_driver_t)joy, keycode+1, SCALE_PRESSURE(-event.value) );
3.37 } else {
3.38 - input_event_keydown( (input_driver_t)joy, keycode, event.value );
3.39 - input_event_keyup( (input_driver_t)joy, keycode+1, 0 );
3.40 + input_event_keyup( (input_driver_t)joy, keycode+1 );
3.41 + input_event_keydown( (input_driver_t)joy, keycode, SCALE_PRESSURE(event.value) );
3.42 }
3.43 }
3.44 }
4.1 --- a/src/drivers/video_osx.m Sun Apr 12 00:04:15 2009 +0000
4.2 +++ b/src/drivers/video_osx.m Sun Apr 12 02:04:27 2009 +0000
4.3 @@ -131,12 +131,12 @@
4.4 - (void)keyDown: (NSEvent *) event
4.5 {
4.6 if( ![event isARepeat] ) {
4.7 - input_event_keydown( NULL, [event keyCode]+1, 1 );
4.8 + input_event_keydown( NULL, [event keyCode]+1, MAX_PRESSURE );
4.9 }
4.10 }
4.11 - (void)keyUp: (NSEvent *) event
4.12 {
4.13 - input_event_keyup( NULL, [event keyCode]+1, 1 );
4.14 + input_event_keyup( NULL, [event keyCode]+1 );
4.15 }
4.16 - (void)flagsChanged: (NSEvent *) event
4.17 {
4.18 @@ -146,10 +146,10 @@
4.19 }
4.20
4.21 if( flagsMask[keycode] == 0 ) {
4.22 - input_event_keydown( NULL, keycode+1, 1 );
4.23 + input_event_keydown( NULL, keycode+1, MAX_PRESSURE );
4.24 flagsMask[keycode] = 1;
4.25 } else {
4.26 - input_event_keyup( NULL, keycode+1, 1 );
4.27 + input_event_keyup( NULL, keycode+1 );
4.28 flagsMask[keycode] = 0;
4.29 }
4.30 }
5.1 --- a/src/gtkui/gtk_win.c Sun Apr 12 00:04:15 2009 +0000
5.2 +++ b/src/gtkui/gtk_win.c Sun Apr 12 02:04:27 2009 +0000
5.3 @@ -216,14 +216,14 @@
5.4 }
5.5 #endif
5.6 }
5.7 - input_event_keydown( NULL, gtk_get_unmodified_keyval(event), 1 );
5.8 + input_event_keydown( NULL, gtk_get_unmodified_keyval(event), MAX_PRESSURE );
5.9 return TRUE;
5.10 }
5.11
5.12 static gboolean on_video_window_key_released( GtkWidget *widget, GdkEventKey *event,
5.13 gpointer user_data )
5.14 {
5.15 - input_event_keyup( NULL, gtk_get_unmodified_keyval(event), 0 );
5.16 + input_event_keyup( NULL, gtk_get_unmodified_keyval(event) );
5.17 return TRUE;
5.18 }
5.19
6.1 --- a/src/maple/controller.c Sun Apr 12 00:04:15 2009 +0000
6.2 +++ b/src/maple/controller.c Sun Apr 12 02:04:27 2009 +0000
6.3 @@ -41,12 +41,15 @@
6.4 #define BUTTON_RIGHT_TRIGGER 0x00FF0000 /* Bitmask */
6.5
6.6 /* Second word of controller condition (bitmasks) */
6.7 -#define JOY_X_AXIS 0x000000FF
6.8 -#define JOY_Y_AXIS 0x0000FF00
6.9 +#define JOY_X_AXIS_MASK 0x000000FF
6.10 +#define JOY_Y_AXIS_MASK 0x0000FF00
6.11 #define JOY_X_AXIS_CENTER 0x00000080
6.12 #define JOY_Y_AXIS_CENTER 0x00008000
6.13 -#define JOY2_X_AXIS 0x00FF0000 /* not on standard controller */
6.14 -#define JOY2_Y_AXIS 0xFF000000 /* not on standard controller */
6.15 +#define JOY2_X_AXIS_MASK 0x00FF0000 /* not on standard controller */
6.16 +#define JOY2_Y_AXIS_MASK 0xFF000000 /* not on standard controller */
6.17 +
6.18 +#define JOY_X_AXIS(x) ((x)&0xFF)
6.19 +#define JOY_Y_AXIS(y) (((y)&0xFF)<<8)
6.20
6.21 /* The following bits are used by the emulator for flags but don't actually
6.22 * appear in the hardware
6.23 @@ -148,16 +151,20 @@
6.24 if( isKeyDown ) {
6.25 switch( value ) {
6.26 case JOY_LEFT:
6.27 - dev->condition[1] &= ~JOY_X_AXIS;
6.28 + dev->condition[1] &= ~JOY_X_AXIS_MASK;
6.29 + dev->condition[1] |= JOY_X_AXIS(0x7F - pressure);
6.30 break;
6.31 case JOY_RIGHT:
6.32 - dev->condition[1] |= JOY_X_AXIS;
6.33 + dev->condition[1] &= ~JOY_X_AXIS_MASK;
6.34 + dev->condition[1] |= JOY_X_AXIS(0x80 + pressure);
6.35 break;
6.36 case JOY_UP:
6.37 - dev->condition[1] &= ~JOY_Y_AXIS;
6.38 + dev->condition[1] &= ~JOY_Y_AXIS_MASK;
6.39 + dev->condition[1] |= JOY_Y_AXIS(0x7F - pressure);
6.40 break;
6.41 case JOY_DOWN:
6.42 - dev->condition[1] |= JOY_Y_AXIS;
6.43 + dev->condition[1] &= ~JOY_Y_AXIS_MASK;
6.44 + dev->condition[1] |= JOY_Y_AXIS(0x80 + pressure);
6.45 break;
6.46 case BUTTON_LEFT_TRIGGER:
6.47 case BUTTON_RIGHT_TRIGGER:
6.48 @@ -170,11 +177,11 @@
6.49 switch(value ) {
6.50 case JOY_LEFT:
6.51 case JOY_RIGHT:
6.52 - dev->condition[1] = (dev->condition[1] & ~JOY_X_AXIS)| JOY_X_AXIS_CENTER;
6.53 + dev->condition[1] = (dev->condition[1] & ~JOY_X_AXIS_MASK)| JOY_X_AXIS_CENTER;
6.54 break;
6.55 case JOY_UP:
6.56 case JOY_DOWN:
6.57 - dev->condition[1] = (dev->condition[1] & ~JOY_Y_AXIS)| JOY_Y_AXIS_CENTER;
6.58 + dev->condition[1] = (dev->condition[1] & ~JOY_Y_AXIS_MASK)| JOY_Y_AXIS_CENTER;
6.59 break;
6.60 case BUTTON_LEFT_TRIGGER:
6.61 case BUTTON_RIGHT_TRIGGER:
.