summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/pce_ctrl/multitap.cpp
blob: 22d08658b777409f18733b12d901ad175b0232e0 (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
// license:BSD-3-Clause
// copyright-holders:cam900
/**********************************************************************

    NEC PC Engine/TurboGrafx-16 Multi Tap emulation

    Based on SMS controller port emulation (devices\bus\sms_ctrl\*.*)
    by Fabio Priuli,
    PC engine emulation (mame\*\pce.*)
    by Charles MacDonald, Wilbert Pol, Angelo Salese

    First party model (PI-PD003, and US released TurboTap and DuoTap)
    has allowed up to 5 controllers, Third-party Multi Taps are has
    allowed up to 2-4 controllers, and also compatible?

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

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


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

DEFINE_DEVICE_TYPE(PCE_MULTITAP, pce_multitap_device, "pce_multitap", "NEC PC Engine/TurboGrafx-16 Multi Tap")


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

//-------------------------------------------------
//  pce_multitap_device - constructor
//-------------------------------------------------

pce_multitap_device::pce_multitap_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) :
	device_t(mconfig, PCE_MULTITAP, tag, owner, clock),
	device_pce_control_port_interface(mconfig, *this),
	m_subctrl_port(*this, "ctrl%u", 1U),
	m_port_sel(0),
	m_prev_sel(0)
{
}


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

void pce_multitap_device::device_add_mconfig(machine_config &config)
{
	for (auto & elem : m_subctrl_port)
		PCE_CONTROL_PORT(config, elem, pce_control_port_devices, "joypad2");
}


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

void pce_multitap_device::device_start()
{
	save_item(NAME(m_port_sel));
	save_item(NAME(m_prev_sel));
}


//-------------------------------------------------
//  device_reset - device-specific reset
//-------------------------------------------------

void pce_multitap_device::device_reset()
{
	m_port_sel = 0;
	m_prev_sel = false;
}


//-------------------------------------------------
//  peripheral_r - multitap read
//-------------------------------------------------

u8 pce_multitap_device::peripheral_r()
{
	u8 data = 0xf;
	if (m_port_sel < 5) // up to 5 controller ports
		data = m_subctrl_port[m_port_sel]->port_r();

	return data;
}


//-------------------------------------------------
//  sel_w - SEL pin write, with port select
//-------------------------------------------------

void pce_multitap_device::sel_w(int state)
{
	for (auto & elem : m_subctrl_port)
		elem->sel_w(state);

	// bump counter on a low-to-high transition of SEL bit
	if ((!m_prev_sel) && state)
		m_port_sel = (m_port_sel + 1) & 7;

	m_prev_sel = state;
}


//-------------------------------------------------
//  clr_w - CLR pin write, with reset multitap
//-------------------------------------------------

void pce_multitap_device::clr_w(int state)
{
	for (auto & elem : m_subctrl_port)
		elem->clr_w(state);

	// clear counter if Reset bit is set
	if (state)
		m_port_sel = 0;
}