trunk/src/emu/bus/sms_ctrl/multitap.c
| r0 | r29593 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | Furrtek's homemade multitap emulation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | **********************************************************************/ |
| 9 | |
| 10 | #include "multitap.h" |
| 11 | |
| 12 | |
| 13 | // Scheme: http://www.smspower.org/uploads/Homebrew/BOoM-SMS-sms4p_2.png |
| 14 | |
| 15 | |
| 16 | //************************************************************************** |
| 17 | // DEVICE DEFINITIONS |
| 18 | //************************************************************************** |
| 19 | |
| 20 | const device_type SMS_MULTITAP = &device_creator<sms_multitap_device>; |
| 21 | |
| 22 | |
| 23 | //************************************************************************** |
| 24 | // LIVE DEVICE |
| 25 | //************************************************************************** |
| 26 | |
| 27 | //------------------------------------------------- |
| 28 | // sms_multitap_device - constructor |
| 29 | //------------------------------------------------- |
| 30 | |
| 31 | sms_multitap_device::sms_multitap_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : |
| 32 | device_t(mconfig, SMS_MULTITAP, "Furrtek's Multitap", tag, owner, clock, "sms_multitap", __FILE__), |
| 33 | device_sms_control_port_interface(mconfig, *this), |
| 34 | m_subctrl1_port(*this, "ctrl1"), |
| 35 | m_subctrl2_port(*this, "ctrl2"), |
| 36 | m_subctrl3_port(*this, "ctrl3"), |
| 37 | m_subctrl4_port(*this, "ctrl4"), |
| 38 | m_read_state(0), |
| 39 | m_last_data(0) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | |
| 44 | //------------------------------------------------- |
| 45 | // device_start - device-specific startup |
| 46 | //------------------------------------------------- |
| 47 | |
| 48 | void sms_multitap_device::device_start() |
| 49 | { |
| 50 | save_item(NAME(m_read_state)); |
| 51 | save_item(NAME(m_last_data)); |
| 52 | |
| 53 | m_subctrl1_port->device_start(); |
| 54 | m_subctrl2_port->device_start(); |
| 55 | m_subctrl3_port->device_start(); |
| 56 | m_subctrl4_port->device_start(); |
| 57 | } |
| 58 | |
| 59 | |
| 60 | //------------------------------------------------- |
| 61 | // sms_peripheral_r - multitap read |
| 62 | //------------------------------------------------- |
| 63 | |
| 64 | UINT8 sms_multitap_device::peripheral_r() |
| 65 | { |
| 66 | UINT8 data = 0xff; |
| 67 | |
| 68 | switch(m_read_state) |
| 69 | { |
| 70 | case 0: |
| 71 | data = m_subctrl1_port->port_r(); |
| 72 | break; |
| 73 | case 1: |
| 74 | data = m_subctrl2_port->port_r(); |
| 75 | break; |
| 76 | case 2: |
| 77 | data = m_subctrl3_port->port_r(); |
| 78 | break; |
| 79 | case 3: |
| 80 | data = m_subctrl4_port->port_r(); |
| 81 | break; |
| 82 | } |
| 83 | |
| 84 | // force TH level high (1), as the line is not connected to subports. |
| 85 | data |= 0x40; |
| 86 | |
| 87 | return data; |
| 88 | } |
| 89 | |
| 90 | |
| 91 | //------------------------------------------------- |
| 92 | // sms_peripheral_w - multitap write |
| 93 | //------------------------------------------------- |
| 94 | |
| 95 | void sms_multitap_device::peripheral_w(UINT8 data) |
| 96 | { |
| 97 | UINT8 output_data; |
| 98 | |
| 99 | // check if TH level is low (0) and was high (1) |
| 100 | if (!(data & 0x40) && (m_last_data & 0x40)) |
| 101 | { |
| 102 | m_read_state = (m_read_state + 1) & 3; |
| 103 | } |
| 104 | m_last_data = data; |
| 105 | |
| 106 | // output default TH level (1), as the line is not connected to subports. |
| 107 | output_data = data | 0x40; |
| 108 | |
| 109 | switch(m_read_state) |
| 110 | { |
| 111 | case 0: |
| 112 | m_subctrl1_port->port_w(output_data); |
| 113 | break; |
| 114 | case 1: |
| 115 | m_subctrl2_port->port_w(output_data); |
| 116 | break; |
| 117 | case 2: |
| 118 | m_subctrl3_port->port_w(output_data); |
| 119 | break; |
| 120 | case 3: |
| 121 | m_subctrl4_port->port_w(output_data); |
| 122 | break; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | |
| 127 | //------------------------------------------------- |
| 128 | // machine_config_additions - device-specific |
| 129 | // machine configurations |
| 130 | //------------------------------------------------- |
| 131 | |
| 132 | READ32_MEMBER( sms_multitap_device::pixel_r ) |
| 133 | { |
| 134 | return m_port->pixel_r(); |
| 135 | } |
| 136 | |
| 137 | |
| 138 | static MACHINE_CONFIG_FRAGMENT( multitap_slot ) |
| 139 | // Controller subports setup, without the TH callback declaration, |
| 140 | // because the circuit scheme shows TH of subports without connection. |
| 141 | MCFG_SMS_CONTROL_PORT_ADD("ctrl1", sms_control_port_devices, "joypad") |
| 142 | MCFG_SMS_CONTROL_PORT_PIXEL_HANDLER(READ32(sms_multitap_device, pixel_r)) |
| 143 | MCFG_SMS_CONTROL_PORT_ADD("ctrl2", sms_control_port_devices, "joypad") |
| 144 | MCFG_SMS_CONTROL_PORT_PIXEL_HANDLER(READ32(sms_multitap_device, pixel_r)) |
| 145 | MCFG_SMS_CONTROL_PORT_ADD("ctrl3", sms_control_port_devices, "joypad") |
| 146 | MCFG_SMS_CONTROL_PORT_PIXEL_HANDLER(READ32(sms_multitap_device, pixel_r)) |
| 147 | MCFG_SMS_CONTROL_PORT_ADD("ctrl4", sms_control_port_devices, "joypad") |
| 148 | MCFG_SMS_CONTROL_PORT_PIXEL_HANDLER(READ32(sms_multitap_device, pixel_r)) |
| 149 | MACHINE_CONFIG_END |
| 150 | |
| 151 | |
| 152 | machine_config_constructor sms_multitap_device::device_mconfig_additions() const |
| 153 | { |
| 154 | return MACHINE_CONFIG_NAME( multitap_slot ); |
| 155 | } |
trunk/src/emu/bus/sms_ctrl/multitap.h
| r0 | r29593 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | Furrtek's homemade multitap emulation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | **********************************************************************/ |
| 9 | |
| 10 | #pragma once |
| 11 | |
| 12 | #ifndef __SMS_MULTITAP__ |
| 13 | #define __SMS_MULTITAP__ |
| 14 | |
| 15 | |
| 16 | #include "emu.h" |
| 17 | #include "smsctrl.h" |
| 18 | |
| 19 | |
| 20 | |
| 21 | //************************************************************************** |
| 22 | // TYPE DEFINITIONS |
| 23 | //************************************************************************** |
| 24 | |
| 25 | // ======================> sms_multitap_device |
| 26 | |
| 27 | class sms_multitap_device : public device_t, |
| 28 | public device_sms_control_port_interface |
| 29 | { |
| 30 | public: |
| 31 | // construction/destruction |
| 32 | sms_multitap_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 33 | |
| 34 | DECLARE_READ32_MEMBER(pixel_r); |
| 35 | |
| 36 | protected: |
| 37 | // device-level overrides |
| 38 | virtual void device_start(); |
| 39 | virtual machine_config_constructor device_mconfig_additions() const; |
| 40 | |
| 41 | // device_sms_control_port_interface overrides |
| 42 | virtual UINT8 peripheral_r(); |
| 43 | virtual void peripheral_w(UINT8 data); |
| 44 | |
| 45 | private: |
| 46 | required_device<sms_control_port_device> m_subctrl1_port; |
| 47 | required_device<sms_control_port_device> m_subctrl2_port; |
| 48 | required_device<sms_control_port_device> m_subctrl3_port; |
| 49 | required_device<sms_control_port_device> m_subctrl4_port; |
| 50 | |
| 51 | UINT8 m_read_state; |
| 52 | UINT8 m_last_data; |
| 53 | }; |
| 54 | |
| 55 | |
| 56 | // device type definition |
| 57 | extern const device_type SMS_MULTITAP; |
| 58 | |
| 59 | |
| 60 | #endif |