summaryrefslogtreecommitdiffstats
path: root/src/devices/bus/sms_ctrl/multitap.cpp
blob: 56e7144cbd54221b711e7dd2b7663951b1170db3 (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
// license:BSD-3-Clause
// copyright-holders:Fabio Priuli
/**********************************************************************

    Furrtek's homemade multitap emulation

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

#include "emu.h"
#include "multitap.h"


// Scheme: http://www.smspower.org/uploads/Homebrew/BOoM-SMS-sms4p_2.png


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

DEFINE_DEVICE_TYPE(SMS_MULTITAP, sms_multitap_device, "sms_multitap", "Furrtek SMS Multitap")


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

//-------------------------------------------------
//  sms_multitap_device - constructor
//-------------------------------------------------

sms_multitap_device::sms_multitap_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, SMS_MULTITAP, tag, owner, clock),
	device_sms_control_port_interface(mconfig, *this),
	m_subctrl1_port(*this, "ctrl1"),
	m_subctrl2_port(*this, "ctrl2"),
	m_subctrl3_port(*this, "ctrl3"),
	m_subctrl4_port(*this, "ctrl4"),
	m_read_state(0),
	m_last_data(0)
{
}


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

void sms_multitap_device::device_start()
{
	save_item(NAME(m_read_state));
	save_item(NAME(m_last_data));
}


//-------------------------------------------------
//  sms_peripheral_r - multitap read
//-------------------------------------------------

uint8_t sms_multitap_device::peripheral_r()
{
	uint8_t data = 0xff;

	switch(m_read_state)
	{
	case 0:
		data = m_subctrl1_port->port_r();
		break;
	case 1:
		data = m_subctrl2_port->port_r();
		break;
	case 2:
		data = m_subctrl3_port->port_r();
		break;
	case 3:
		data = m_subctrl4_port->port_r();
		break;
	}

	// force TH level high (1), as the line is not connected to subports.
	data |= 0x40;

	return data;
}


//-------------------------------------------------
//  sms_peripheral_w - multitap write
//-------------------------------------------------

void sms_multitap_device::peripheral_w(uint8_t data)
{
	uint8_t output_data;

	// check if TH level is low (0) and was high (1)
	if (!(data & 0x40) && (m_last_data & 0x40))
	{
		m_read_state = (m_read_state + 1) & 3;
	}
	m_last_data = data;

	// output default TH level (1), as the line is not connected to subports.
	output_data = data | 0x40;

	switch(m_read_state)
	{
	case 0:
		m_subctrl1_port->port_w(output_data);
		break;
	case 1:
		m_subctrl2_port->port_w(output_data);
		break;
	case 2:
		m_subctrl3_port->port_w(output_data);
		break;
	case 3:
		m_subctrl4_port->port_w(output_data);
		break;
	}
}


//-------------------------------------------------
//  device_add_mconfig - add device configuration
//-------------------------------------------------

READ32_MEMBER( sms_multitap_device::pixel_r )
{
	return m_port->pixel_r();
}


MACHINE_CONFIG_START(sms_multitap_device::device_add_mconfig)
	// Controller subports setup, without the TH callback declaration,
	// because the circuit scheme shows TH of subports without connection.
	MCFG_SMS_CONTROL_PORT_ADD("ctrl1", sms_control_port_devices, "joypad")
	MCFG_SMS_CONTROL_PORT_PIXEL_HANDLER(READ32(*this, sms_multitap_device, pixel_r))
	MCFG_SMS_CONTROL_PORT_ADD("ctrl2", sms_control_port_devices, "joypad")
	MCFG_SMS_CONTROL_PORT_PIXEL_HANDLER(READ32(*this, sms_multitap_device, pixel_r))
	MCFG_SMS_CONTROL_PORT_ADD("ctrl3", sms_control_port_devices, "joypad")
	MCFG_SMS_CONTROL_PORT_PIXEL_HANDLER(READ32(*this, sms_multitap_device, pixel_r))
	MCFG_SMS_CONTROL_PORT_ADD("ctrl4", sms_control_port_devices, "joypad")
	MCFG_SMS_CONTROL_PORT_PIXEL_HANDLER(READ32(*this, sms_multitap_device, pixel_r))
MACHINE_CONFIG_END