From 9eea2335f91cadeb21fd8afbf3b9af05fabecf7f Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 16 Mar 2011 12:57:26 +0000 Subject: [PATCH] Added possibility of altering default input port setting for devices. [Miodrag Milanovic] --- src/emu/devintrf.c | 1 + src/emu/devintrf.h | 6 ++++++ src/emu/inptport.c | 26 ++++++++++++++++++++++++++ src/emu/inptport.h | 23 ++++++++++++++++++++++- 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/emu/devintrf.c b/src/emu/devintrf.c index d80ade49c3e..5d6026fcd82 100644 --- a/src/emu/devintrf.c +++ b/src/emu/devintrf.c @@ -293,6 +293,7 @@ device_config::device_config(const machine_config &mconfig, device_type type, co m_clock(clock), m_machine_config(mconfig), m_static_config(NULL), + m_input_defaults(NULL), m_name(name), m_tag(tag), m_config_complete(false) diff --git a/src/emu/devintrf.h b/src/emu/devintrf.h index 1fdcea5b21a..3b82989aa7c 100644 --- a/src/emu/devintrf.h +++ b/src/emu/devintrf.h @@ -108,6 +108,8 @@ device_t *_ConfigClass::alloc_device(running_machine &machine) const \ #define MCFG_DEVICE_CLOCK(_clock) \ device_config::static_set_clock(device, _clock); \ +#define MCFG_DEVICE_INPUT_DEFAULTS(_config) \ + device_config::static_set_input_default(device, DEVICE_INPUT_DEFAULTS_NAME(_config)); \ //************************************************************************** @@ -128,6 +130,7 @@ struct rom_entry; class machine_config; class emu_timer; typedef union _input_port_token input_port_token; +typedef struct _input_device_default input_device_default; // exception classes @@ -289,6 +292,7 @@ public: const char *tag() const { return m_tag; } const void *static_config() const { return m_static_config; } const machine_config &mconfig() const { return m_machine_config; } + const input_device_default *input_ports_defaults() const { return m_input_defaults; } // methods that wrap both interface-level and device-level behavior void config_complete(); @@ -297,6 +301,7 @@ public: // configuration helpers static void static_set_clock(device_config *device, UINT32 clock) { device->m_clock = clock; } static void static_set_static_config(device_config *device, const void *config) { device->m_static_config = config; } + static void static_set_input_default(device_config *device, const input_device_default *config) { device->m_input_defaults = config; } //------------------- begin derived class overrides @@ -327,6 +332,7 @@ protected: const machine_config & m_machine_config; // reference to the machine's configuration const void * m_static_config; // static device configuration + const input_device_default *m_input_defaults; // devices input ports default overrides astring m_name; // name of the device astring m_shortname; // short name of the device, used for potential romload diff --git a/src/emu/inptport.c b/src/emu/inptport.c index 5328325235c..abaea68723c 100644 --- a/src/emu/inptport.c +++ b/src/emu/inptport.c @@ -2931,6 +2931,29 @@ static int frame_get_digital_field_state(const input_field_config *field, int mo PORT CONFIGURATION HELPERS ***************************************************************************/ +/*------------------------------------------------- + port_default_value - updates default value + of port settings according to device settings +-------------------------------------------------*/ + +static UINT32 port_default_value(const char *fulltag, UINT32 mask, UINT32 defval, device_config *owner) +{ + astring tempstring; + const input_device_default *def = NULL; + if (owner!=NULL) { + def = owner->input_ports_defaults(); + if (def!=NULL) { + while (def->tag!=NULL) { + if ((strcmp(fulltag,owner->subtag(tempstring,def->tag))==0) && (def->mask == mask)) { + return def->defvalue; + } + def++; + } + } + } + return defval; +} + /*------------------------------------------------- port_config_detokenize - recursively detokenize a series of input port tokens @@ -3410,6 +3433,7 @@ static void port_config_detokenize(ioport_list &portlist, const input_port_token TOKEN_GET_UINT64_UNPACK2(ipt, mask, 32, defval, 32); if (curfield != NULL) field_config_insert(curfield, &maskbits, errorbuf, errorbuflen); + defval = port_default_value(fulltag,mask,defval,owner); curfield = field_config_alloc(curport, IPT_DIPSWITCH, defval, mask); cursetting = NULL; curfield->name = input_port_string_from_token(*ipt++); @@ -3488,6 +3512,7 @@ static void port_config_detokenize(ioport_list &portlist, const input_port_token TOKEN_GET_UINT64_UNPACK2(ipt, mask, 32, defval, 32); if (curfield != NULL) field_config_insert(curfield, &maskbits, errorbuf, errorbuflen); + defval = port_default_value(fulltag,mask,defval,owner); curfield = field_config_alloc(curport, IPT_CONFIG, defval, mask); cursetting = NULL; curfield->name = input_port_string_from_token(*ipt++); @@ -3519,6 +3544,7 @@ static void port_config_detokenize(ioport_list &portlist, const input_port_token TOKEN_GET_UINT64_UNPACK2(ipt, mask, 32, defval, 32); if (curfield != NULL) field_config_insert(curfield, &maskbits, errorbuf, errorbuflen); + defval = port_default_value(fulltag,mask,defval,owner); curfield = field_config_alloc(curport, IPT_CATEGORY, defval, mask); cursetting = NULL; curfield->name = input_port_string_from_token(*ipt++); diff --git a/src/emu/inptport.h b/src/emu/inptport.h index 4ceb0fa467e..31d566323fa 100644 --- a/src/emu/inptport.h +++ b/src/emu/inptport.h @@ -723,7 +723,14 @@ struct _input_field_user_settings UINT8 reverse; /* for analog controls */ }; - +/* device defined default input settings */ +typedef struct _input_device_default input_device_default; +struct _input_device_default +{ + const char * tag; /* tag of port to update */ + input_port_value mask; /* mask to apply to the port */ + input_port_value defvalue; /* new default value */ +}; /* a single input port configuration */ class input_port_config { @@ -1024,6 +1031,20 @@ struct _inp_header TOKEN_STRING(_name), +/* name of table */ +#define DEVICE_INPUT_DEFAULTS_NAME(_name) device_iptdef_##_name + +/* start of table */ +#define DEVICE_INPUT_DEFAULTS_START(_name) \ + const input_device_default DEVICE_INPUT_DEFAULTS_NAME(_name)[] = { + +/* end of table */ +#define DEVICE_INPUT_DEFAULTS(_tag,_mask,_defval) \ + { _tag ,_mask, _defval }, \ + +/* end of table */ +#define DEVICE_INPUT_DEFAULTS_END \ + {NULL,0,0} }; /*************************************************************************** HELPER MACROS