Search
lxdream.org :: lxdream :: r148:3f31c2d9b783
lxdream 0.9.1
released Jun 29
Download Now
changeset148:3f31c2d9b783
parent147:82478590bfa7
child149:d88dd2e9a190
authornkeynes
dateSat May 20 02:40:51 2006 +0000 (14 years ago)
Implement analog joystick (and make sure it defaults to centered)
src/maple/controller.c
src/maple/controller.h
1.1 --- a/src/maple/controller.c Sat May 20 02:40:16 2006 +0000
1.2 +++ b/src/maple/controller.c Sat May 20 02:40:51 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: controller.c,v 1.3 2006-05-15 08:28:52 nkeynes Exp $
1.6 + * $Id: controller.c,v 1.4 2006-05-20 02:40:51 nkeynes Exp $
1.7 *
1.8 * Implements the standard dreamcast controller
1.9 *
1.10 @@ -44,7 +44,7 @@
1.11 { MAPLE_DEVICE_TAG, &controller_class, CONTROLLER_IDENT, CONTROLLER_VERSION,
1.12 controller_get_config, controller_attach, controller_detach, controller_destroy,
1.13 NULL, NULL, controller_get_cond, NULL, NULL, NULL },
1.14 - {0x0000FFFF, 0},
1.15 + {0x0000FFFF, 0x80808080},
1.16 {{ "dpad left", CONFIG_TYPE_KEY },
1.17 { "dpad right", CONFIG_TYPE_KEY },
1.18 { "dpad up", CONFIG_TYPE_KEY },
1.19 @@ -68,8 +68,6 @@
1.20 {
1.21 controller_device_t dev = malloc( sizeof(struct controller_device) );
1.22 memcpy( dev, &base_controller, sizeof(base_controller) );
1.23 - memset( dev->condition, 0, 8 );
1.24 - dev->condition[0] = 0x0000FFFF;
1.25 return MAPLE_DEVICE(dev);
1.26 }
1.27
1.28 @@ -80,11 +78,35 @@
1.29 {
1.30 controller_device_t dev = (controller_device_t)mdev;
1.31 if( isKeyDown ) {
1.32 - dev->condition[0] |= value;
1.33 - fprintf( stderr, "Key %08X DOWN\n", value );
1.34 + switch( value ) {
1.35 + case JOY_LEFT:
1.36 + dev->condition[1] &= ~JOY_X_AXIS;
1.37 + break;
1.38 + case JOY_RIGHT:
1.39 + dev->condition[1] |= JOY_X_AXIS;
1.40 + break;
1.41 + case JOY_UP:
1.42 + dev->condition[1] &= ~JOY_Y_AXIS;
1.43 + break;
1.44 + case JOY_DOWN:
1.45 + dev->condition[1] |= JOY_Y_AXIS;
1.46 + break;
1.47 + default:
1.48 + dev->condition[0] &= ~value;
1.49 + }
1.50 } else {
1.51 - dev->condition[0] &= ~value;
1.52 - fprintf( stderr, "Key %08X UP\n", value );
1.53 + switch(value ) {
1.54 + case JOY_LEFT:
1.55 + case JOY_RIGHT:
1.56 + dev->condition[1] = (dev->condition[1] & ~JOY_X_AXIS)| JOY_X_AXIS_CENTER;
1.57 + break;
1.58 + case JOY_UP:
1.59 + case JOY_DOWN:
1.60 + dev->condition[1] = (dev->condition[1] & ~JOY_Y_AXIS)| JOY_Y_AXIS_CENTER;
1.61 + break;
1.62 + default:
1.63 + dev->condition[0] |= value;
1.64 + }
1.65 }
1.66 }
1.67
1.68 @@ -110,10 +132,10 @@
1.69 input_register_key( dev->config[1].value, controller_key_callback, dev, BUTTON_DPAD_RIGHT );
1.70 input_register_key( dev->config[2].value, controller_key_callback, dev, BUTTON_DPAD_UP );
1.71 input_register_key( dev->config[3].value, controller_key_callback, dev, BUTTON_DPAD_DOWN );
1.72 - input_register_key( dev->config[4].value, controller_key_callback, dev, 0 );
1.73 - input_register_key( dev->config[5].value, controller_key_callback, dev, 0 );
1.74 - input_register_key( dev->config[6].value, controller_key_callback, dev, 0 );
1.75 - input_register_key( dev->config[7].value, controller_key_callback, dev, 0 );
1.76 + input_register_key( dev->config[4].value, controller_key_callback, dev, JOY_LEFT );
1.77 + input_register_key( dev->config[5].value, controller_key_callback, dev, JOY_RIGHT );
1.78 + input_register_key( dev->config[6].value, controller_key_callback, dev, JOY_UP );
1.79 + input_register_key( dev->config[7].value, controller_key_callback, dev, JOY_DOWN );
1.80 input_register_key( dev->config[8].value, controller_key_callback, dev, BUTTON_X );
1.81 input_register_key( dev->config[9].value, controller_key_callback, dev, BUTTON_Y );
1.82 input_register_key( dev->config[10].value, controller_key_callback, dev, BUTTON_A );
2.1 --- a/src/maple/controller.h Sat May 20 02:40:16 2006 +0000
2.2 +++ b/src/maple/controller.h Sat May 20 02:40:51 2006 +0000
2.3 @@ -1,5 +1,5 @@
2.4 /**
2.5 - * $Id: controller.h,v 1.2 2005-12-25 08:24:11 nkeynes Exp $
2.6 + * $Id: controller.h,v 1.3 2006-05-20 02:40:51 nkeynes Exp $
2.7 *
2.8 * Definitions for the standard controller device
2.9 *
2.10 @@ -35,9 +35,19 @@
2.11 /* Second word of controller condition (bitmasks) */
2.12 #define JOY_X_AXIS 0x000000FF
2.13 #define JOY_Y_AXIS 0x0000FF00
2.14 +#define JOY_X_AXIS_CENTER 0x00000080
2.15 +#define JOY_Y_AXIS_CENTER 0x00008000
2.16 #define JOY2_X_AXIS 0x00FF0000 /* not on standard controller */
2.17 #define JOY2_Y_AXIS 0xFF000000 /* not on standard controller */
2.18
2.19 +/* The following bits are used by the emulator for flags but don't actually
2.20 + * appear in the hardware
2.21 + */
2.22 +#define JOY_LEFT 0x80000001
2.23 +#define JOY_RIGHT 0x80000002
2.24 +#define JOY_UP 0x80000004
2.25 +#define JOY_DOWN 0x80000008
2.26 +
2.27 /* Standard controller ID */
2.28 #define CONTROLLER_IDENT {0x00, 0x00, 0x00, 0x01, 0x00, 0x0f, 0x06, 0xfe, 0x00, 0x00, 0x00, 0x00, \
2.29 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x44, 0x72, 0x65, 0x61, 0x6d, 0x63, 0x61, 0x73, 0x74, 0x20, \
.