trunk/src/emu/ioport.c
| r20934 | r20935 | |
| 1522 | 1522 | // eval - evaluate condition |
| 1523 | 1523 | //------------------------------------------------- |
| 1524 | 1524 | |
| 1525 | | bool ioport_condition::eval(device_t &device) const |
| 1525 | bool ioport_condition::eval() const |
| 1526 | 1526 | { |
| 1527 | 1527 | // always condition is always true |
| 1528 | 1528 | if (m_condition == ALWAYS) |
| 1529 | 1529 | return true; |
| 1530 | 1530 | |
| 1531 | 1531 | // otherwise, read the referenced port and switch off the condition type |
| 1532 | | ioport_value condvalue = device.ioport(m_tag)->read(); |
| 1532 | ioport_value condvalue = m_port->read(); |
| 1533 | 1533 | switch (m_condition) |
| 1534 | 1534 | { |
| 1535 | 1535 | case ALWAYS: return true; |
| r20934 | r20935 | |
| 1544 | 1544 | } |
| 1545 | 1545 | |
| 1546 | 1546 | |
| 1547 | //------------------------------------------------- |
| 1548 | // initialize - create the live state |
| 1549 | //------------------------------------------------- |
| 1547 | 1550 | |
| 1551 | void ioport_condition::initialize(device_t &device) |
| 1552 | { |
| 1553 | if (m_tag != NULL) |
| 1554 | m_port = device.ioport(m_tag); |
| 1555 | } |
| 1556 | |
| 1557 | |
| 1558 | |
| 1548 | 1559 | //************************************************************************** |
| 1549 | 1560 | // I/O PORT SETTING |
| 1550 | 1561 | //************************************************************************** |
| r20934 | r20935 | |
| 2257 | 2268 | |
| 2258 | 2269 | // allocate live state |
| 2259 | 2270 | m_live = global_alloc(ioport_field_live(*this, analog)); |
| 2271 | |
| 2272 | m_condition.initialize(device()); |
| 2273 | |
| 2274 | for (ioport_setting *setting = first_setting(); setting != NULL; setting = setting->next()) |
| 2275 | setting->condition().initialize(setting->device()); |
| 2260 | 2276 | } |
| 2261 | 2277 | |
| 2262 | 2278 | |
trunk/src/emu/ioport.h
| r20934 | r20935 | |
| 917 | 917 | |
| 918 | 918 | // operators |
| 919 | 919 | bool operator==(const ioport_condition &rhs) const { return (m_mask == rhs.m_mask && m_value == rhs.m_value && m_condition == rhs.m_condition && strcmp(m_tag, rhs.m_tag) == 0); } |
| 920 | | bool eval(device_t &device) const; |
| 920 | bool eval() const; |
| 921 | 921 | bool none() const { return (m_condition == ALWAYS); } |
| 922 | 922 | |
| 923 | 923 | // configuration |
| r20934 | r20935 | |
| 930 | 930 | m_value = value; |
| 931 | 931 | } |
| 932 | 932 | |
| 933 | void initialize(device_t &device); |
| 934 | |
| 933 | 935 | private: |
| 934 | 936 | // internal state |
| 935 | 937 | condition_t m_condition; // condition to use |
| 936 | 938 | const char * m_tag; // tag of port whose condition is to be tested |
| 939 | ioport_port * m_port; // reference to the port to be tested |
| 937 | 940 | ioport_value m_mask; // mask to apply to the port |
| 938 | 941 | ioport_value m_value; // value to compare against |
| 939 | 942 | }; |
| r20934 | r20935 | |
| 961 | 964 | const char *name() const { return m_name; } |
| 962 | 965 | |
| 963 | 966 | // helpers |
| 964 | | bool enabled() { return m_condition.eval(device()); } |
| 967 | bool enabled() { return m_condition.eval(); } |
| 965 | 968 | |
| 966 | 969 | private: |
| 967 | 970 | // internal state |
| r20934 | r20935 | |
| 1084 | 1087 | bool is_digital_joystick() const { return (m_type > IPT_DIGITAL_JOYSTICK_FIRST && m_type < IPT_DIGITAL_JOYSTICK_LAST); } |
| 1085 | 1088 | |
| 1086 | 1089 | // additional operations |
| 1087 | | bool enabled() const { return m_condition.eval(device()); } |
| 1090 | bool enabled() const { return m_condition.eval(); } |
| 1088 | 1091 | const char *setting_name() const; |
| 1089 | 1092 | bool has_previous_setting() const; |
| 1090 | 1093 | void select_previous_setting(); |