1 // license:BSD-3-Clause
2 // copyright-holders:Nigel Barnes
3 /**********************************************************************
4 
5     Watford Electronics User Port Splitter
6 
7 **********************************************************************/
8 
9 
10 #include "emu.h"
11 #include "usersplit.h"
12 
13 //**************************************************************************
14 //  DEVICE DEFINITIONS
15 //**************************************************************************
16 
17 DEFINE_DEVICE_TYPE(BBC_USERSPLIT, bbc_usersplit_device, "bbc_usersplit", "BBC Micro User Port Splitter")
18 
19 
20 //-------------------------------------------------
21 //  INPUT_PORTS( usersplit )
22 //-------------------------------------------------
23 
INPUT_PORTS_START(usersplit)24 static INPUT_PORTS_START( usersplit )
25 	PORT_START("SELECT")
26 	PORT_CONFNAME(0x01, 0x00, "User Port") PORT_CHANGED_MEMBER(DEVICE_SELF, bbc_usersplit_device, userport_changed, 0)
27 	PORT_CONFSETTING(0x00, "A")
28 	PORT_CONFSETTING(0x01, "B")
29 INPUT_PORTS_END
30 
31 
32 //-------------------------------------------------
33 //  input_ports - device-specific input ports
34 //-------------------------------------------------
35 
36 ioport_constructor bbc_usersplit_device::device_input_ports() const
37 {
38 	return INPUT_PORTS_NAME( usersplit );
39 }
40 
41 //-------------------------------------------------
42 //  device_add_mconfig - add device configuration
43 //-------------------------------------------------
44 
device_add_mconfig(machine_config & config)45 void bbc_usersplit_device::device_add_mconfig(machine_config &config)
46 {
47 	/* user port A */
48 	BBC_USERPORT_SLOT(config, m_userport[0], bbc_userport_devices, nullptr);
49 	m_userport[0]->cb1_handler().set(FUNC(bbc_usersplit_device::cb1a_w));
50 	m_userport[0]->cb2_handler().set(FUNC(bbc_usersplit_device::cb2a_w));
51 
52 	/* user port B */
53 	BBC_USERPORT_SLOT(config, m_userport[1], bbc_userport_devices, nullptr);
54 	m_userport[1]->cb1_handler().set(FUNC(bbc_usersplit_device::cb1b_w));
55 	m_userport[1]->cb2_handler().set(FUNC(bbc_usersplit_device::cb2b_w));
56 }
57 
58 
59 //**************************************************************************
60 //  LIVE DEVICE
61 //**************************************************************************
62 
63 //-------------------------------------------------
64 //  bbc_usersplit_device - constructor
65 //-------------------------------------------------
66 
bbc_usersplit_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)67 bbc_usersplit_device::bbc_usersplit_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
68 	: device_t(mconfig, BBC_USERSPLIT, tag, owner, clock)
69 	, device_bbc_userport_interface(mconfig, *this)
70 	, m_userport(*this, "userport%u", 1)
71 {
72 }
73 
74 
75 //-------------------------------------------------
76 //  device_start - device-specific startup
77 //-------------------------------------------------
78 
device_start()79 void bbc_usersplit_device::device_start()
80 {
81 	m_selected = 0;
82 
83 	save_item(NAME(m_selected));
84 }
85 
86 
87 //**************************************************************************
88 //  IMPLEMENTATION
89 //**************************************************************************
90 
pb_r()91 uint8_t bbc_usersplit_device::pb_r()
92 {
93 	return m_userport[m_selected]->pb_r();
94 }
95 
pb_w(uint8_t data)96 void bbc_usersplit_device::pb_w(uint8_t data)
97 {
98 	m_userport[m_selected]->pb_w(data);
99 }
100 
write_cb1(int state)101 void bbc_usersplit_device::write_cb1(int state)
102 {
103 	m_userport[m_selected]->write_cb1(state);
104 }
105 
write_cb2(int state)106 void bbc_usersplit_device::write_cb2(int state)
107 {
108 	m_userport[m_selected]->write_cb2(state);
109 }
110 
111 
WRITE_LINE_MEMBER(bbc_usersplit_device::cb1a_w)112 WRITE_LINE_MEMBER(bbc_usersplit_device::cb1a_w)
113 {
114 	if (m_selected == 0x00)
115 		m_slot->cb1_w(state);
116 }
117 
WRITE_LINE_MEMBER(bbc_usersplit_device::cb2a_w)118 WRITE_LINE_MEMBER(bbc_usersplit_device::cb2a_w)
119 {
120 	if (m_selected == 0x00)
121 		m_slot->cb2_w(state);
122 }
123 
WRITE_LINE_MEMBER(bbc_usersplit_device::cb1b_w)124 WRITE_LINE_MEMBER(bbc_usersplit_device::cb1b_w)
125 {
126 	if (m_selected == 0x01)
127 		m_slot->cb1_w(state);
128 }
129 
WRITE_LINE_MEMBER(bbc_usersplit_device::cb2b_w)130 WRITE_LINE_MEMBER(bbc_usersplit_device::cb2b_w)
131 {
132 	if (m_selected == 0x01)
133 		m_slot->cb2_w(state);
134 }
135