Search
lxdream.org :: lxdream/src/maple/controller.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/maple/controller.c
changeset 770:429ff505c450
prev736:a02d1475ccfd
next838:9abb2fa58934
author nkeynes
date Mon Jul 28 03:41:25 2008 +0000 (11 years ago)
permissions -rw-r--r--
last change Implement key-binding configuration pane for Cocoa UI
Minor tweaks for consistency and static-correctness
file annotate diff log raw
1.1 --- a/src/maple/controller.c Mon Jul 14 07:44:42 2008 +0000
1.2 +++ b/src/maple/controller.c Mon Jul 28 03:41:25 2008 +0000
1.3 @@ -17,34 +17,37 @@
1.4 */
1.5
1.6 #include <stdlib.h>
1.7 +#include <assert.h>
1.8 #include "dream.h"
1.9 #include "dreamcast.h"
1.10 #include "display.h"
1.11 #include "maple.h"
1.12 #include "maple/controller.h"
1.13
1.14 -#define CONTROLLER_CONFIG_ENTRIES 16
1.15 +#define CONTROLLER_CONFIG_ENTRIES 15
1.16
1.17 -void controller_attach( maple_device_t dev );
1.18 -void controller_detach( maple_device_t dev );
1.19 -void controller_destroy( maple_device_t dev );
1.20 -maple_device_t controller_clone( maple_device_t dev );
1.21 -maple_device_t controller_new();
1.22 -lxdream_config_entry_t controller_get_config( maple_device_t dev );
1.23 -int controller_get_cond( maple_device_t dev, int function, unsigned char *outbuf,
1.24 +static void controller_attach( maple_device_t dev );
1.25 +static void controller_detach( maple_device_t dev );
1.26 +static void controller_destroy( maple_device_t dev );
1.27 +static maple_device_t controller_clone( maple_device_t dev );
1.28 +static maple_device_t controller_new();
1.29 +static lxdream_config_entry_t controller_get_config( maple_device_t dev );
1.30 +static void controller_set_config_value( maple_device_t dev, unsigned int key, const gchar *value );
1.31 +static int controller_get_cond( maple_device_t dev, int function, unsigned char *outbuf,
1.32 unsigned int *outlen );
1.33
1.34 typedef struct controller_device {
1.35 struct maple_device dev;
1.36 uint32_t condition[2];
1.37 - struct lxdream_config_entry config[CONTROLLER_CONFIG_ENTRIES];
1.38 + struct lxdream_config_entry config[CONTROLLER_CONFIG_ENTRIES+1];
1.39 } *controller_device_t;
1.40
1.41 struct maple_device_class controller_class = { "Sega Controller", controller_new };
1.42
1.43 static struct controller_device base_controller = {
1.44 { MAPLE_DEVICE_TAG, &controller_class, CONTROLLER_IDENT, CONTROLLER_VERSION,
1.45 - controller_get_config, controller_attach, controller_detach, controller_destroy,
1.46 + controller_get_config, controller_set_config_value,
1.47 + controller_attach, controller_detach, controller_destroy,
1.48 controller_clone, NULL, NULL, controller_get_cond, NULL, NULL, NULL },
1.49 {0x0000FFFF, 0x80808080},
1.50 {{ "dpad left", N_("Dpad left"), CONFIG_TYPE_KEY },
1.51 @@ -64,16 +67,21 @@
1.52 { "start", N_("Start button"), CONFIG_TYPE_KEY },
1.53 { NULL, CONFIG_TYPE_NONE }} };
1.54
1.55 +static int config_button_map[] = {
1.56 + BUTTON_DPAD_LEFT, BUTTON_DPAD_RIGHT, BUTTON_DPAD_UP, BUTTON_DPAD_DOWN,
1.57 + JOY_LEFT, JOY_RIGHT, JOY_UP, JOY_DOWN, BUTTON_X, BUTTON_Y, BUTTON_A,
1.58 + BUTTON_B, BUTTON_LEFT_TRIGGER, BUTTON_RIGHT_TRIGGER, BUTTON_START };
1.59 +
1.60 #define CONTROLLER(x) ((controller_device_t)(x))
1.61
1.62 -maple_device_t controller_new( )
1.63 +static maple_device_t controller_new( )
1.64 {
1.65 controller_device_t dev = malloc( sizeof(struct controller_device) );
1.66 memcpy( dev, &base_controller, sizeof(base_controller) );
1.67 return MAPLE_DEVICE(dev);
1.68 }
1.69
1.70 -maple_device_t controller_clone( maple_device_t srcdevice )
1.71 +static maple_device_t controller_clone( maple_device_t srcdevice )
1.72 {
1.73 controller_device_t src = (controller_device_t)srcdevice;
1.74 controller_device_t dev = (controller_device_t)controller_new();
1.75 @@ -85,7 +93,7 @@
1.76 /**
1.77 * Input callback
1.78 */
1.79 -void controller_key_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
1.80 +static void controller_key_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
1.81 {
1.82 controller_device_t dev = (controller_device_t)mdev;
1.83 if( isKeyDown ) {
1.84 @@ -129,13 +137,23 @@
1.85 }
1.86 }
1.87
1.88 -lxdream_config_entry_t controller_get_config( maple_device_t mdev )
1.89 +static lxdream_config_entry_t controller_get_config( maple_device_t mdev )
1.90 {
1.91 controller_device_t dev = (controller_device_t)mdev;
1.92 return dev->config;
1.93 }
1.94
1.95 -void controller_destroy( maple_device_t mdev )
1.96 +static void controller_set_config_value( maple_device_t mdev, unsigned int key, const gchar *value )
1.97 +{
1.98 + controller_device_t dev = (controller_device_t)mdev;
1.99 + assert( key < CONTROLLER_CONFIG_ENTRIES );
1.100 +
1.101 + input_unregister_key( dev->config[key].value, controller_key_callback, dev, config_button_map[key] );
1.102 + lxdream_set_config_value( &dev->config[key], value );
1.103 + input_register_key( dev->config[key].value, controller_key_callback, dev, config_button_map[key] );
1.104 +}
1.105 +
1.106 +static void controller_destroy( maple_device_t mdev )
1.107 {
1.108 free( mdev );
1.109 }
1.110 @@ -144,49 +162,27 @@
1.111 * Device is being attached to the bus. Go through the config and reserve the
1.112 * keys we need.
1.113 */
1.114 -void controller_attach( maple_device_t mdev )
1.115 +static void controller_attach( maple_device_t mdev )
1.116 {
1.117 controller_device_t dev = (controller_device_t)mdev;
1.118 - input_register_key( dev->config[0].value, controller_key_callback, dev, BUTTON_DPAD_LEFT );
1.119 - input_register_key( dev->config[1].value, controller_key_callback, dev, BUTTON_DPAD_RIGHT );
1.120 - input_register_key( dev->config[2].value, controller_key_callback, dev, BUTTON_DPAD_UP );
1.121 - input_register_key( dev->config[3].value, controller_key_callback, dev, BUTTON_DPAD_DOWN );
1.122 - input_register_key( dev->config[4].value, controller_key_callback, dev, JOY_LEFT );
1.123 - input_register_key( dev->config[5].value, controller_key_callback, dev, JOY_RIGHT );
1.124 - input_register_key( dev->config[6].value, controller_key_callback, dev, JOY_UP );
1.125 - input_register_key( dev->config[7].value, controller_key_callback, dev, JOY_DOWN );
1.126 - input_register_key( dev->config[8].value, controller_key_callback, dev, BUTTON_X );
1.127 - input_register_key( dev->config[9].value, controller_key_callback, dev, BUTTON_Y );
1.128 - input_register_key( dev->config[10].value, controller_key_callback, dev, BUTTON_A );
1.129 - input_register_key( dev->config[11].value, controller_key_callback, dev, BUTTON_B );
1.130 - input_register_key( dev->config[12].value, controller_key_callback, dev, BUTTON_LEFT_TRIGGER );
1.131 - input_register_key( dev->config[13].value, controller_key_callback, dev, BUTTON_RIGHT_TRIGGER );
1.132 - input_register_key( dev->config[14].value, controller_key_callback, dev, BUTTON_START );
1.133 + int i;
1.134 + for( i=0; i<CONTROLLER_CONFIG_ENTRIES; i++ ) {
1.135 + input_register_key( dev->config[i].value, controller_key_callback, dev, config_button_map[i] );
1.136 + }
1.137 }
1.138
1.139 -void controller_detach( maple_device_t mdev )
1.140 +static void controller_detach( maple_device_t mdev )
1.141 {
1.142 controller_device_t dev = (controller_device_t)mdev;
1.143 - input_unregister_key( dev->config[0].value, controller_key_callback, dev, BUTTON_DPAD_LEFT );
1.144 - input_unregister_key( dev->config[1].value, controller_key_callback, dev, BUTTON_DPAD_RIGHT );
1.145 - input_unregister_key( dev->config[2].value, controller_key_callback, dev, BUTTON_DPAD_UP );
1.146 - input_unregister_key( dev->config[3].value, controller_key_callback, dev, BUTTON_DPAD_DOWN );
1.147 - input_unregister_key( dev->config[4].value, controller_key_callback, dev, JOY_LEFT );
1.148 - input_unregister_key( dev->config[5].value, controller_key_callback, dev, JOY_RIGHT );
1.149 - input_unregister_key( dev->config[6].value, controller_key_callback, dev, JOY_UP );
1.150 - input_unregister_key( dev->config[7].value, controller_key_callback, dev, JOY_DOWN );
1.151 - input_unregister_key( dev->config[8].value, controller_key_callback, dev, BUTTON_X );
1.152 - input_unregister_key( dev->config[9].value, controller_key_callback, dev, BUTTON_Y );
1.153 - input_unregister_key( dev->config[10].value, controller_key_callback, dev, BUTTON_A );
1.154 - input_unregister_key( dev->config[11].value, controller_key_callback, dev, BUTTON_B );
1.155 - input_unregister_key( dev->config[12].value, controller_key_callback, dev, BUTTON_LEFT_TRIGGER );
1.156 - input_unregister_key( dev->config[13].value, controller_key_callback, dev, BUTTON_RIGHT_TRIGGER );
1.157 - input_unregister_key( dev->config[14].value, controller_key_callback, dev, BUTTON_START );
1.158 + int i;
1.159 + for( i=0; i<CONTROLLER_CONFIG_ENTRIES; i++ ) {
1.160 + input_unregister_key( dev->config[i].value, controller_key_callback, dev, config_button_map[i] );
1.161 + }
1.162
1.163 }
1.164
1.165
1.166 -int controller_get_cond( maple_device_t mdev, int function, unsigned char *outbuf,
1.167 +static int controller_get_cond( maple_device_t mdev, int function, unsigned char *outbuf,
1.168 unsigned int *outlen )
1.169 {
1.170 controller_device_t dev = (controller_device_t)mdev;
.