summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/adamnet/adamnet.cpp
blob: c153a826f67c19e9203f569698a76871d83bc2f2 (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
// license:BSD-3-Clause
// copyright-holders:Curt Coder
/**********************************************************************

    Coleco ADAMnet bus emulation

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

#include "emu.h"
#include "adamnet.h"



//**************************************************************************
//  GLOBAL VARIABLES
//**************************************************************************

const device_type ADAMNET = &device_creator<adamnet_device>;
const device_type ADAMNET_SLOT = &device_creator<adamnet_slot_device>;



//**************************************************************************
//  DEVICE ADAMNET CARD INTERFACE
//**************************************************************************

//-------------------------------------------------
//  device_adamnet_card_interface - constructor
//-------------------------------------------------

device_adamnet_card_interface::device_adamnet_card_interface(const machine_config &mconfig, device_t &device)
	: device_slot_card_interface(mconfig, device),
	m_bus(nullptr)
{
}


//-------------------------------------------------
//  ~device_adamnet_card_interface - destructor
//-------------------------------------------------

device_adamnet_card_interface::~device_adamnet_card_interface()
{
}



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

//-------------------------------------------------
//  adamnet_slot_device - constructor
//-------------------------------------------------
adamnet_slot_device::adamnet_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, ADAMNET_SLOT, "ADAMnet slot", tag, owner, clock, "adamnet_slot", __FILE__),
	device_slot_interface(mconfig, *this), m_bus(nullptr)
{
}


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

void adamnet_slot_device::device_start()
{
	m_bus = machine().device<adamnet_device>(ADAMNET_TAG);
	device_adamnet_card_interface *dev = dynamic_cast<device_adamnet_card_interface *>(get_card_device());
	if (dev) m_bus->add_device(get_card_device());
}



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

//-------------------------------------------------
//  adamnet_device - constructor
//-------------------------------------------------

adamnet_device::adamnet_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, ADAMNET, "ADAMnet bus", tag, owner, clock, "adamnet", __FILE__),
	m_txd(1),
	m_reset(CLEAR_LINE)
{
}


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

void adamnet_device::device_start()
{
}


//-------------------------------------------------
//  device_stop - device-specific stop
//-------------------------------------------------

void adamnet_device::device_stop()
{
	m_device_list.reset();
}


//-------------------------------------------------
//  add_adamnet_card - add ADAMNET card
//-------------------------------------------------

void adamnet_device::add_device(device_t *target)
{
	auto entry = global_alloc(daisy_entry(target));

	entry->m_interface->m_bus = this;

	m_device_list.append(*entry);
}


//-------------------------------------------------
//  daisy_entry - constructor
//-------------------------------------------------

adamnet_device::daisy_entry::daisy_entry(device_t *device)
	: m_next(nullptr),
		m_device(device),
		m_interface(nullptr),
		m_txd(1)
{
	device->interface(m_interface);
}


//-------------------------------------------------
//  rxd_r - receive data
//-------------------------------------------------

READ_LINE_MEMBER( adamnet_device::rxd_r )
{
	int state = m_txd;//1;

	daisy_entry *entry = m_device_list.first();

	while (entry)
	{
		state &= entry->m_txd;

		entry = entry->next();
	}

	return state;
}


//-------------------------------------------------
//  rxd_r - receive data
//-------------------------------------------------

int adamnet_device::rxd_r(device_t *device)
{
	int state = m_txd;

	daisy_entry *entry = m_device_list.first();

	while (entry)
	{
		//if (strcmp(entry->m_device->tag(), device->tag()))
		{
			state &= entry->m_txd;
		}

		entry = entry->next();
	}

	return state;
}


//-------------------------------------------------
//  txd_w - transmit data
//-------------------------------------------------

WRITE_LINE_MEMBER( adamnet_device::txd_w )
{
	if (m_txd != state)
	{
		m_txd = state;
	}
}


//-------------------------------------------------
//  txd_w - transmit data
//-------------------------------------------------

void adamnet_device::txd_w(device_t *device, int state)
{
	daisy_entry *entry = m_device_list.first();

	while (entry)
	{
		if (!strcmp(entry->m_device->tag(), device->tag()))
		{
			if (entry->m_txd != state)
			{
				entry->m_txd = state;
			}
			break;
		}

		entry = entry->next();
	}
}


//-------------------------------------------------
//  reset_r - bus reset
//-------------------------------------------------

READ_LINE_MEMBER( adamnet_device::reset_r )
{
	return m_reset;
}


//-------------------------------------------------
//  reset_w - bus reset
//-------------------------------------------------

WRITE_LINE_MEMBER( adamnet_device::reset_w )
{
	m_reset = state;

	daisy_entry *entry = m_device_list.first();

	while (entry)
	{
		entry->m_interface->adamnet_reset_w(state);

		entry = entry->next();
	}
}


//-------------------------------------------------
//  SLOT_INTERFACE( adamnet_devices )
//-------------------------------------------------

// slot devices
#include "ddp.h"
#include "fdc.h"
#include "kb.h"
#include "printer.h"
#include "spi.h"

SLOT_INTERFACE_START( adamnet_devices )
	SLOT_INTERFACE("ddp", ADAM_DDP)
	SLOT_INTERFACE("fdc", ADAM_FDC)
	SLOT_INTERFACE("kb", ADAM_KB)
	SLOT_INTERFACE("prn", ADAM_PRN)
	SLOT_INTERFACE("spi", ADAM_SPI)
SLOT_INTERFACE_END