revision 1010:a506a2f66180
summary |
tree |
shortlog |
changelog |
graph |
changeset |
raw | bz2 | zip | gz changeset | 1010:a506a2f66180 |
parent | 1009:c29795e15cef |
child | 1014:f5914b2fd0db |
author | nkeynes |
date | Sun Apr 12 02:04:27 2009 +0000 (14 years ago) |
Fix analogue joystick input
1.1 --- a/src/display.c Sun Apr 12 00:04:15 2009 +00001.2 +++ b/src/display.c Sun Apr 12 02:04:27 2009 +00001.3 @@ -354,18 +354,18 @@1.4 }1.5 }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.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.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 }
2.1 --- a/src/display.h Sun Apr 12 00:04:15 2009 +00002.2 +++ b/src/display.h Sun Apr 12 02:04:27 2009 +00002.3 @@ -227,6 +227,9 @@2.5 #define MAX_MOUSE_BUTTONS 322.7 +/* Pressure is 0..127 (allowing a joystick to be defined as two half-axes of 7- bits each) */2.8 +#define MAX_PRESSURE 0x7F2.9 +2.10 typedef void (*input_key_callback_t)( void *data, uint32_t value, uint32_t pressure, gboolean isKeyDown );2.12 /**2.13 @@ -337,9 +340,18 @@2.14 */2.15 void display_set_focused( gboolean has_focus );2.17 +/**2.18 + * Fire a keydown event on the specified device2.19 + * @param input The input device source generating the event, or NULL for the2.20 + * default GUI device2.21 + * @param keycode The device-specific keycode2.22 + * @param pressure The pressure of the key (0 to 127), where 0 is unpressed and2.23 + * 127 is maximum pressure. Devices without pressure sensitivity should2.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.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.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 +00003.2 +++ b/src/drivers/joy_linux.c Sun Apr 12 02:04:27 2009 +00003.3 @@ -52,6 +52,11 @@3.5 } *linux_joystick_t;3.7 +/* Linux joysticks return data in the range -32767 to 32767 - rescale this to3.8 + * -127 .. 1273.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 +00004.2 +++ b/src/drivers/video_osx.m Sun Apr 12 02:04:27 2009 +00004.3 @@ -131,12 +131,12 @@4.4 - (void)keyDown: (NSEvent *) event4.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 *) event4.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 *) event4.17 {4.18 @@ -146,10 +146,10 @@4.19 }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 +00005.2 +++ b/src/gtkui/gtk_win.c Sun Apr 12 02:04:27 2009 +00005.3 @@ -216,14 +216,14 @@5.4 }5.5 #endif5.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.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 }
6.1 --- a/src/maple/controller.c Sun Apr 12 00:04:15 2009 +00006.2 +++ b/src/maple/controller.c Sun Apr 12 02:04:27 2009 +00006.3 @@ -41,12 +41,15 @@6.4 #define BUTTON_RIGHT_TRIGGER 0x00FF0000 /* Bitmask */6.6 /* Second word of controller condition (bitmasks) */6.7 -#define JOY_X_AXIS 0x000000FF6.8 -#define JOY_Y_AXIS 0x0000FF006.9 +#define JOY_X_AXIS_MASK 0x000000FF6.10 +#define JOY_Y_AXIS_MASK 0x0000FF006.11 #define JOY_X_AXIS_CENTER 0x000000806.12 #define JOY_Y_AXIS_CENTER 0x000080006.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.21 /* The following bits are used by the emulator for flags but don't actually6.22 * appear in the hardware6.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:
.