Search
lxdream.org :: lxdream/src/maple/controller.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/maple/controller.c
changeset 144:7f0714e89aaa
prev31:495e480360d7
next148:3f31c2d9b783
author nkeynes
date Mon May 15 08:28:52 2006 +0000 (15 years ago)
permissions -rw-r--r--
last change Rename video_driver to display_driver
Add input source to display
Implement configuration file support
Hook controllers up to configuration
file annotate diff log raw
1.1 --- a/src/maple/controller.c Sun Dec 25 08:24:11 2005 +0000
1.2 +++ b/src/maple/controller.c Mon May 15 08:28:52 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: controller.c,v 1.2 2005-12-25 08:24:11 nkeynes Exp $
1.6 + * $Id: controller.c,v 1.3 2006-05-15 08:28:52 nkeynes Exp $
1.7 *
1.8 * Implements the standard dreamcast controller
1.9 *
1.10 @@ -18,25 +18,51 @@
1.11
1.12 #include <stdlib.h>
1.13 #include "dream.h"
1.14 +#include "dreamcast.h"
1.15 #include "maple.h"
1.16 #include "maple/controller.h"
1.17
1.18 +#define CONTROLLER_CONFIG_ENTRIES 16
1.19 +
1.20 void controller_attach( maple_device_t dev );
1.21 void controller_detach( maple_device_t dev );
1.22 +void controller_destroy( maple_device_t dev );
1.23 +maple_device_t controller_new();
1.24 +dreamcast_config_entry_t controller_get_config( maple_device_t dev );
1.25 int controller_get_cond( maple_device_t dev, int function, char *outbuf,
1.26 int *outlen );
1.27
1.28 -static struct maple_device base_controller = {
1.29 - MAPLE_DEVICE_TAG, CONTROLLER_IDENT, CONTROLLER_VERSION, NULL, NULL,
1.30 - controller_get_cond, NULL, NULL, NULL,
1.31 - controller_attach, controller_detach };
1.32 -
1.33 typedef struct controller_device {
1.34 struct maple_device dev;
1.35 uint32_t condition[2];
1.36 + struct dreamcast_config_entry config[CONTROLLER_CONFIG_ENTRIES];
1.37 } *controller_device_t;
1.38
1.39 +struct maple_device_class controller_class = { "Sega Controller", controller_new };
1.40
1.41 +static struct controller_device base_controller = {
1.42 + { MAPLE_DEVICE_TAG, &controller_class, CONTROLLER_IDENT, CONTROLLER_VERSION,
1.43 + controller_get_config, controller_attach, controller_detach, controller_destroy,
1.44 + NULL, NULL, controller_get_cond, NULL, NULL, NULL },
1.45 + {0x0000FFFF, 0},
1.46 + {{ "dpad left", CONFIG_TYPE_KEY },
1.47 + { "dpad right", CONFIG_TYPE_KEY },
1.48 + { "dpad up", CONFIG_TYPE_KEY },
1.49 + { "dpad down", CONFIG_TYPE_KEY },
1.50 + { "analog left", CONFIG_TYPE_KEY },
1.51 + { "analog right", CONFIG_TYPE_KEY },
1.52 + { "analog up", CONFIG_TYPE_KEY },
1.53 + { "analog down", CONFIG_TYPE_KEY },
1.54 + { "button X", CONFIG_TYPE_KEY },
1.55 + { "button Y", CONFIG_TYPE_KEY },
1.56 + { "button A", CONFIG_TYPE_KEY },
1.57 + { "button B", CONFIG_TYPE_KEY },
1.58 + { "trigger left", CONFIG_TYPE_KEY },
1.59 + { "trigger right", CONFIG_TYPE_KEY },
1.60 + { "start", CONFIG_TYPE_KEY },
1.61 + { NULL, CONFIG_TYPE_NONE }} };
1.62 +
1.63 +#define CONTROLLER(x) ((controller_device_t)(x))
1.64
1.65 maple_device_t controller_new( )
1.66 {
1.67 @@ -47,10 +73,54 @@
1.68 return MAPLE_DEVICE(dev);
1.69 }
1.70
1.71 +/**
1.72 + * Input callback
1.73 + */
1.74 +void controller_key_callback( void *mdev, uint32_t value, gboolean isKeyDown )
1.75 +{
1.76 + controller_device_t dev = (controller_device_t)mdev;
1.77 + if( isKeyDown ) {
1.78 + dev->condition[0] |= value;
1.79 + fprintf( stderr, "Key %08X DOWN\n", value );
1.80 + } else {
1.81 + dev->condition[0] &= ~value;
1.82 + fprintf( stderr, "Key %08X UP\n", value );
1.83 + }
1.84 +}
1.85
1.86 -void controller_attach( maple_device_t dev )
1.87 +dreamcast_config_entry_t controller_get_config( maple_device_t mdev )
1.88 {
1.89 + controller_device_t dev = (controller_device_t)mdev;
1.90 + return dev->config;
1.91 +}
1.92
1.93 +void controller_destroy( maple_device_t mdev )
1.94 +{
1.95 + free( mdev );
1.96 +}
1.97 +
1.98 +/**
1.99 + * Device is being attached to the bus. Go through the config and reserve the
1.100 + * keys we need.
1.101 + */
1.102 +void controller_attach( maple_device_t mdev )
1.103 +{
1.104 + controller_device_t dev = (controller_device_t)mdev;
1.105 + input_register_key( dev->config[0].value, controller_key_callback, dev, BUTTON_DPAD_LEFT );
1.106 + input_register_key( dev->config[1].value, controller_key_callback, dev, BUTTON_DPAD_RIGHT );
1.107 + input_register_key( dev->config[2].value, controller_key_callback, dev, BUTTON_DPAD_UP );
1.108 + input_register_key( dev->config[3].value, controller_key_callback, dev, BUTTON_DPAD_DOWN );
1.109 + input_register_key( dev->config[4].value, controller_key_callback, dev, 0 );
1.110 + input_register_key( dev->config[5].value, controller_key_callback, dev, 0 );
1.111 + input_register_key( dev->config[6].value, controller_key_callback, dev, 0 );
1.112 + input_register_key( dev->config[7].value, controller_key_callback, dev, 0 );
1.113 + input_register_key( dev->config[8].value, controller_key_callback, dev, BUTTON_X );
1.114 + input_register_key( dev->config[9].value, controller_key_callback, dev, BUTTON_Y );
1.115 + input_register_key( dev->config[10].value, controller_key_callback, dev, BUTTON_A );
1.116 + input_register_key( dev->config[11].value, controller_key_callback, dev, BUTTON_B );
1.117 + input_register_key( dev->config[12].value, controller_key_callback, dev, BUTTON_LEFT_TRIGGER );
1.118 + input_register_key( dev->config[13].value, controller_key_callback, dev, BUTTON_RIGHT_TRIGGER );
1.119 + input_register_key( dev->config[14].value, controller_key_callback, dev, BUTTON_START );
1.120 }
1.121
1.122 void controller_detach( maple_device_t dev )
.