revision 148:3f31c2d9b783
summary |
tree |
shortlog |
changelog |
graph |
changeset |
raw | bz2 | zip | gz changeset | 148:3f31c2d9b783 |
parent | 147:82478590bfa7 |
child | 149:d88dd2e9a190 |
author | nkeynes |
date | Sat May 20 02:40:51 2006 +0000 (17 years ago) |
Implement analog joystick (and make sure it defaults to centered)
src/maple/controller.c | view | annotate | diff | log | ||
src/maple/controller.h | view | annotate | diff | log |
1.1 --- a/src/maple/controller.c Sat May 20 02:40:16 2006 +00001.2 +++ b/src/maple/controller.c Sat May 20 02:40:51 2006 +00001.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 controller1.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.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.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 +00002.2 +++ b/src/maple/controller.h Sat May 20 02:40:51 2006 +00002.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 device2.9 *2.10 @@ -35,9 +35,19 @@2.11 /* Second word of controller condition (bitmasks) */2.12 #define JOY_X_AXIS 0x000000FF2.13 #define JOY_Y_AXIS 0x0000FF002.14 +#define JOY_X_AXIS_CENTER 0x000000802.15 +#define JOY_Y_AXIS_CENTER 0x000080002.16 #define JOY2_X_AXIS 0x00FF0000 /* not on standard controller */2.17 #define JOY2_Y_AXIS 0xFF000000 /* not on standard controller */2.19 +/* The following bits are used by the emulator for flags but don't actually2.20 + * appear in the hardware2.21 + */2.22 +#define JOY_LEFT 0x800000012.23 +#define JOY_RIGHT 0x800000022.24 +#define JOY_UP 0x800000042.25 +#define JOY_DOWN 0x800000082.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, \
.