summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/bus/snes_ctrl/multitap.c
blob: 8a18422c19f923e1f9e09edfa8d69c4a323ca94d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**********************************************************************

    Nintendo Super Famicom & SNES Multitap Adapter

    Copyright MESS Team.
    Visit http://mamedev.org for licensing and usage restrictions.

**********************************************************************/

#include "multitap.h"
#include "joypad.h"
#include "twintap.h"

//**************************************************************************
//  DEVICE DEFINITIONS
//**************************************************************************

const device_type SNES_MULTITAP = &device_creator<snes_multitap_device>;


static INPUT_PORTS_START( snes_multitap )
	PORT_START("CONFIG")
	PORT_CONFNAME( 0x01, 0x00, "Number of players")
	PORT_CONFSETTING(  0x00, "3-5P" )
	PORT_CONFSETTING(  0x01, "2P" )
INPUT_PORTS_END


//-------------------------------------------------
//  input_ports - device-specific input ports
//-------------------------------------------------

ioport_constructor snes_multitap_device::device_input_ports() const
{
	return INPUT_PORTS_NAME( snes_multitap );
}


static SLOT_INTERFACE_START( snes_multitap )
	SLOT_INTERFACE("joypad", SNES_JOYPAD)
	SLOT_INTERFACE("twintap", SNES_TWINTAP)
SLOT_INTERFACE_END

static MACHINE_CONFIG_FRAGMENT( multi5p )
	MCFG_SNES_CONTROL_PORT_ADD("port1", snes_multitap, "joypad")
	MCFG_SNES_CONTROL_PORT_ADD("port2", snes_multitap, "joypad")
	MCFG_SNES_CONTROL_PORT_ADD("port3", snes_multitap, "joypad")
	MCFG_SNES_CONTROL_PORT_ADD("port4", snes_multitap, "joypad")
MACHINE_CONFIG_END


//-------------------------------------------------
//  machine_config_additions - device-specific
//  machine configurations
//-------------------------------------------------

machine_config_constructor snes_multitap_device::device_mconfig_additions() const
{
	return MACHINE_CONFIG_NAME( multi5p );
}


//**************************************************************************
//  LIVE DEVICE
//**************************************************************************

//-------------------------------------------------
//  snes_multitap_device - constructor
//-------------------------------------------------

snes_multitap_device::snes_multitap_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
					device_t(mconfig, SNES_MULTITAP, "Nintendo SNES / SFC Multitap Adapter", tag, owner, clock, "snes_joypad", __FILE__),
					device_snes_control_port_interface(mconfig, *this),
					m_port1(*this, "port1"),
					m_port2(*this, "port2"),
					m_port3(*this, "port3"),
					m_port4(*this, "port4"),
					m_cfg(*this, "CONFIG")
{
}


//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void snes_multitap_device::device_start()
{
	save_item(NAME(m_select));
}

void snes_multitap_device::device_reset()
{
	m_select = 1;
}

//-------------------------------------------------
//  poll
//-------------------------------------------------

void snes_multitap_device::port_poll()
{
	m_port1->port_poll();
	if (m_cfg->read() == 0) // 4P
	{
		m_port2->port_poll();
		m_port3->port_poll();
		m_port4->port_poll();
	}
}

//-------------------------------------------------
//  read
//-------------------------------------------------

UINT8 snes_multitap_device::read_pin4()
{
	UINT8 ret = 0;

	if (m_cfg->read() == 0) // 4P
		ret |= m_select ? m_port1->read_pin4() : m_port3->read_pin4();
	else    // 1P
		ret |= m_select ? m_port1->read_pin4() : 0;

	return ret;
}

UINT8 snes_multitap_device::read_pin5()
{
	UINT8 ret = 0;

	if (m_cfg->read() == 0) // 4P
		ret |= m_select ? m_port2->read_pin4() : m_port4->read_pin4();
	return ret;
}

//-------------------------------------------------
//  write
//-------------------------------------------------

void snes_multitap_device::write_strobe(UINT8 data)
{
	m_port1->write_strobe(data);
	if (m_cfg->read() == 0) // 4P
	{
		m_port2->write_strobe(data);
		m_port3->write_strobe(data);
		m_port4->write_strobe(data);
	}
}

void snes_multitap_device::write_pin6(UINT8 data)
{
	m_select = data & 1;
}