trunk/src/mess/machine/pc_joy_sw.c
r0 | r22825 | |
| 1 | //TODO: determine when to switch modes and add single bit mode |
| 2 | |
| 3 | #include "machine/pc_joy_sw.h" |
| 4 | |
| 5 | const device_type PC_MSSW_PAD = &device_creator<pc_mssw_pad_device>; |
| 6 | |
| 7 | pc_mssw_pad_device::pc_mssw_pad_device(const machine_config& mconfig, const char* tag, device_t* owner, UINT32 clock) : |
| 8 | device_t(mconfig, PC_MSSW_PAD, "Microsoft Sidewinder Pad", tag, owner, clock, "mssw_pad", __FILE__), |
| 9 | device_pc_joy_interface(mconfig, *this), |
| 10 | m_btn1(*this, "btn1"), |
| 11 | m_btn2(*this, "btn2"), |
| 12 | m_btn3(*this, "btn3"), |
| 13 | m_btn4(*this, "btn4"), |
| 14 | m_conf(*this, "CONFIG") |
| 15 | { |
| 16 | } |
| 17 | |
| 18 | void pc_mssw_pad_device::device_start() |
| 19 | { |
| 20 | m_timer = timer_alloc(); |
| 21 | } |
| 22 | |
| 23 | void pc_mssw_pad_device::device_reset() |
| 24 | { |
| 25 | m_count = 0; |
| 26 | m_state = 0xf; |
| 27 | m_active = false; |
| 28 | m_timer->adjust(attotime::never, 0); |
| 29 | } |
| 30 | |
| 31 | void pc_mssw_pad_device::device_timer(emu_timer &timer, device_timer_id tid, int param, void *ptr) |
| 32 | { |
| 33 | UINT16 pad_state = 0; |
| 34 | // only multibit mode for now |
| 35 | if(m_count == -1) |
| 36 | { |
| 37 | reset(); |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | if((m_count / 5) > m_conf->read()) |
| 42 | { |
| 43 | m_timer->adjust(attotime::from_usec(50), 0); |
| 44 | m_state &= ~1; |
| 45 | m_count = -1; |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | if(m_state & 1) |
| 50 | { |
| 51 | m_state &= ~1; |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | switch(m_count / 5) |
| 56 | { |
| 57 | case 0: |
| 58 | pad_state = m_btn1->read(); |
| 59 | break; |
| 60 | case 1: |
| 61 | pad_state = m_btn2->read(); |
| 62 | break; |
| 63 | case 2: |
| 64 | pad_state = m_btn3->read(); |
| 65 | break; |
| 66 | case 3: |
| 67 | pad_state = m_btn4->read(); |
| 68 | break; |
| 69 | } |
| 70 | |
| 71 | switch(m_count % 5) |
| 72 | { |
| 73 | case 0: |
| 74 | m_state = ((pad_state & 7) << 1) | 1; |
| 75 | break; |
| 76 | case 1: |
| 77 | m_state = ((pad_state & 0x38) >> 2) | 1; |
| 78 | break; |
| 79 | case 2: |
| 80 | m_state = ((pad_state & 0x1c0) >> 5) | 1; |
| 81 | break; |
| 82 | case 3: |
| 83 | m_state = ((pad_state & 0xe00) >> 8) | 1; |
| 84 | break; |
| 85 | case 4: |
| 86 | { |
| 87 | UINT8 parity = (pad_state >> 8) ^ pad_state; |
| 88 | parity = (parity >> 4) ^ parity; |
| 89 | parity = (parity >> 2) ^ parity; |
| 90 | parity = (((parity >> 1) ^ parity) & 1); |
| 91 | |
| 92 | m_state = ((pad_state & 0x3000) >> 11) | (parity << 3) | 1; |
| 93 | break; |
| 94 | } |
| 95 | } |
| 96 | m_count++; |
| 97 | } |
| 98 | |
| 99 | static INPUT_PORTS_START( sidewinder_pad ) |
| 100 | PORT_START("btn1") |
| 101 | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) |
| 102 | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) |
| 103 | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) |
| 104 | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) |
| 105 | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("A") |
| 106 | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("B") |
| 107 | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("C") |
| 108 | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("X") |
| 109 | PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("Y") |
| 110 | PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("Z") |
| 111 | PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_NAME("L") |
| 112 | PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("R") |
| 113 | PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON9 ) PORT_NAME("Start") |
| 114 | PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON10 ) PORT_NAME("M") |
| 115 | PORT_BIT( 0xc000, IP_ACTIVE_LOW, IPT_UNUSED ) |
| 116 | PORT_START("btn2") |
| 117 | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2) |
| 118 | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2) |
| 119 | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) |
| 120 | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2) |
| 121 | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("A") PORT_PLAYER(2) |
| 122 | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("B") PORT_PLAYER(2) |
| 123 | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("C") PORT_PLAYER(2) |
| 124 | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("X") PORT_PLAYER(2) |
| 125 | PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("Y") PORT_PLAYER(2) |
| 126 | PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("Z") PORT_PLAYER(2) |
| 127 | PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_NAME("L") PORT_PLAYER(2) |
| 128 | PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("R") PORT_PLAYER(2) |
| 129 | PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON9 ) PORT_NAME("Start") PORT_PLAYER(2) |
| 130 | PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON10 ) PORT_NAME("M") PORT_PLAYER(2) |
| 131 | PORT_BIT( 0xc000, IP_ACTIVE_LOW, IPT_UNUSED ) |
| 132 | PORT_START("btn3") |
| 133 | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(3) |
| 134 | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(3) |
| 135 | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(3) |
| 136 | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(3) |
| 137 | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("A") PORT_PLAYER(3) |
| 138 | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("B") PORT_PLAYER(3) |
| 139 | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("C") PORT_PLAYER(3) |
| 140 | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("X") PORT_PLAYER(3) |
| 141 | PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("Y") PORT_PLAYER(3) |
| 142 | PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("Z") PORT_PLAYER(3) |
| 143 | PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_NAME("L") PORT_PLAYER(3) |
| 144 | PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("R") PORT_PLAYER(3) |
| 145 | PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON9 ) PORT_NAME("Start") PORT_PLAYER(3) |
| 146 | PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON10 ) PORT_NAME("M") PORT_PLAYER(3) |
| 147 | PORT_BIT( 0xc000, IP_ACTIVE_LOW, IPT_UNUSED ) |
| 148 | PORT_START("btn4") |
| 149 | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(4) |
| 150 | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(4) |
| 151 | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(4) |
| 152 | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(4) |
| 153 | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("A") PORT_PLAYER(4) |
| 154 | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("B") PORT_PLAYER(4) |
| 155 | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("C") PORT_PLAYER(4) |
| 156 | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("X") PORT_PLAYER(4) |
| 157 | PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("Y") PORT_PLAYER(4) |
| 158 | PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("Z") PORT_PLAYER(4) |
| 159 | PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_NAME("L") PORT_PLAYER(4) |
| 160 | PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("R") PORT_PLAYER(4) |
| 161 | PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON9 ) PORT_NAME("Start") PORT_PLAYER(4) |
| 162 | PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON10 ) PORT_NAME("M") PORT_PLAYER(4) |
| 163 | PORT_BIT( 0xc000, IP_ACTIVE_LOW, IPT_UNUSED ) |
| 164 | PORT_START("CONFIG") |
| 165 | PORT_CONFNAME(0x03, 0x00, "Number of Sidewinder Pads") |
| 166 | PORT_CONFSETTING( 0x00, "1") |
| 167 | PORT_CONFSETTING( 0x01, "2") |
| 168 | PORT_CONFSETTING( 0x02, "3") |
| 169 | PORT_CONFSETTING( 0x03, "4") |
| 170 | INPUT_PORTS_END |
| 171 | |
| 172 | ioport_constructor pc_mssw_pad_device::device_input_ports() const |
| 173 | { |
| 174 | return INPUT_PORTS_NAME( sidewinder_pad ); |
| 175 | } |
| 176 | |
| 177 | |