summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/hp_dio/hp_dio.cpp
blob: 647b28f83c9d5dd41a6705c535840e7ac9d31417 (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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
// license:BSD-3-Clause
// copyright-holders:Miodrag Milanovic, R. Belmont
/***************************************************************************

        HP DIO and DIO-II bus devices

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

#include "emu.h"
#include "hp_dio.h"
#include "hp98265a.h"
#include "hp98543.h"
#include "hp98544.h"
#include "hp98550.h"
#include "hp98603a.h"
#include "hp98603b.h"
#include "hp98620.h"
#include "hp98643.h"
#include "hp98644.h"
#include "human_interface.h"

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

DEFINE_DEVICE_TYPE(DIO16_SLOT, bus::hp_dio::dio16_slot_device, "dio16_slot", "16-bit DIO slot")
DEFINE_DEVICE_TYPE(DIO32_SLOT, bus::hp_dio::dio32_slot_device, "dio32_slot", "32-bit DIO-II slot")
DEFINE_DEVICE_TYPE(DIO16,      bus::hp_dio::dio16_device,      "dio16",      "16-bit DIO bus")
DEFINE_DEVICE_TYPE(DIO32,      bus::hp_dio::dio32_device,      "dio32",      "32-bit DIO-II bus")

namespace bus::hp_dio {

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

dio16_slot_device::dio16_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	dio16_slot_device(mconfig, DIO16_SLOT, tag, owner, clock)
{
}

dio16_slot_device::dio16_slot_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, type, tag, owner, clock),
	device_slot_interface(mconfig, *this),
	m_dio(*this, finder_base::DUMMY_TAG)
{
}

void dio16_slot_device::device_resolve_objects()
{
	device_dio16_card_interface *const card(dynamic_cast<device_dio16_card_interface *>(get_card_device()));
	if (card && m_dio)
		card->set_diobus(*m_dio);
}

void dio16_slot_device::device_validity_check(validity_checker &valid) const
{
	device_t *const card(get_card_device());
	if (card && !dynamic_cast<device_dio16_card_interface *>(card))
		osd_printf_error("Card device %s (%s) does not implement device_dio16_card_interface\n", card->tag(), card->name());
}

void dio16_slot_device::device_start()
{
	device_t *const card(get_card_device());
	if (card && !dynamic_cast<device_dio16_card_interface *>(card))
		throw emu_fatalerror("dio16_slot_device: card device %s (%s) does not implement device_dio16_card_interface\n", card->tag(), card->name());
}

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

//-------------------------------------------------
//  dio32_slot_device - constructor
//-------------------------------------------------
dio32_slot_device::dio32_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	dio16_slot_device(mconfig, DIO32_SLOT, tag, owner, clock)
{
}

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

void dio32_slot_device::device_start()
{
	dio16_slot_device::device_start();
}

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

//-------------------------------------------------
//  dio16_device - constructor
//-------------------------------------------------

dio16_device::dio16_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	dio16_device(mconfig, DIO16, tag, owner, clock)
{
}

dio16_device::dio16_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, type, tag, owner, clock),
	m_prgspace(*this, finder_base::DUMMY_TAG, -1),
	m_bus_index{0},
	m_irq{0},
	m_dmar{0},
	m_irq1_out_cb(*this),
	m_irq2_out_cb(*this),
	m_irq3_out_cb(*this),
	m_irq4_out_cb(*this),
	m_irq5_out_cb(*this),
	m_irq6_out_cb(*this),
	m_irq7_out_cb(*this),
	m_dmar0_out_cb(*this),
	m_dmar1_out_cb(*this)
{
	std::fill(std::begin(m_cards), std::end(m_cards), nullptr);
	m_prgwidth = 0;
}

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

void dio16_device::device_start()
{
	m_irq1_out_cb.resolve_safe();
	m_irq2_out_cb.resolve_safe();
	m_irq3_out_cb.resolve_safe();
	m_irq4_out_cb.resolve_safe();
	m_irq5_out_cb.resolve_safe();
	m_irq6_out_cb.resolve_safe();
	m_irq7_out_cb.resolve_safe();
	m_dmar0_out_cb.resolve_safe();
	m_dmar1_out_cb.resolve_safe();

	m_prgwidth = m_prgspace->data_width();

	save_item(NAME(m_irq));
	save_item(NAME(m_dmar));
}

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

void dio16_device::device_reset()
{
}

unsigned dio16_device::add_card(device_dio16_card_interface &card)
{
	m_cards.push_back(&card);
	return m_bus_index++;
}

void dio16_device::set_irq(unsigned index, unsigned int level, int state)
{
	bool const changed(bool(state) != BIT(m_irq[level], index));
	if (!changed)
		return;

	if (state)
		m_irq[level] |= (1 << index);
	else
		m_irq[level] &= ~(1 << index);

	if (m_bus_index != index) {
		switch (level) {
		case 0:
			m_irq1_out_cb(state);
			break;
		case 1:
			m_irq2_out_cb(state);
			break;
		case 2:
			m_irq3_out_cb(state);
			break;
		case 3:
			m_irq4_out_cb(state);
			break;
		case 4:
			m_irq5_out_cb(state);
			break;
		case 5:
			m_irq6_out_cb(state);
			break;
		case 6:
			m_irq7_out_cb(state);
			break;
		}
	}
}

void dio16_device::set_dmar(unsigned int index, unsigned int num, int state)
{
	assert(num <= 1);

	bool const changed(bool(state) != BIT(m_dmar[num], index));
	if (!changed)
		return;
	if (state)
		m_dmar[num] |= (1 << index);
	else
		m_dmar[num] &= ~(1 << index);


	for (auto &card : m_cards) {

		if (card->get_index() == index)
			continue;

		switch (num) {
		case 0:
			card->dmar0_in(state);
			break;
		case 1:
			card->dmar1_in(state);
			break;
		}
	}
}

void dio16_device::dmack_w_out(int index, int channel, uint8_t val)
{
	for (auto &card : m_cards) {
		if (card->get_index() == index)
			continue;
		card->dmack_w_in(channel, val);
	}
}

uint8_t dio16_device::dmack_r_out(int index, int channel)
{
	uint8_t ret = 0xff;

	for (auto &card : m_cards) {
		if (card->get_index() == index)
			continue;
		ret &= card->dmack_r_in(channel);
	}
	return ret;
}

WRITE_LINE_MEMBER(dio16_device::reset_in)
{
	for (auto &card : m_cards) {
		if (card->get_index() != m_bus_index)
			card->reset_in(state);
	}
}

template<typename R, typename W> void dio16_device::install_memory(offs_t start, offs_t end, R rhandler, W whandler) {
	switch (m_prgwidth) {
	case 16:
		m_prgspace->install_readwrite_handler(start, end, rhandler,
							  whandler);
		break;
	case 32:
		m_prgspace->install_readwrite_handler(start, end, rhandler,
							  whandler, 0xffffffff);
		break;
	default:
		fatalerror("DIO: Bus width %d not supported\n", m_prgwidth);
	}
}

template void dio16_device::install_memory<read16_delegate,    write16_delegate   >(offs_t start, offs_t end, read16_delegate rhandler,    write16_delegate whandler);
template void dio16_device::install_memory<read16s_delegate,   write16s_delegate  >(offs_t start, offs_t end, read16s_delegate rhandler,   write16s_delegate whandler);
template void dio16_device::install_memory<read16sm_delegate,  write16sm_delegate >(offs_t start, offs_t end, read16sm_delegate rhandler,  write16sm_delegate whandler);

void dio16_device::install_bank(offs_t start, offs_t end, uint8_t *data)
{
	m_prgspace->install_ram(start, end, data);
}

void dio16_device::unmap_bank(offs_t start, offs_t end)
{
	m_prgspace->unmap_readwrite(start, end);
}

void dio16_device::install_rom(offs_t start, offs_t end, uint8_t *data)
{
	m_prgspace->install_rom(start, end, data);
}

void dio16_device::unmap_rom(offs_t start, offs_t end)
{
	m_prgspace->unmap_read(start, end);
}

void device_dio16_card_interface::set_bus(dio16_device &bus)
{
	m_index = (m_dio_dev = &bus)->add_card(*this);
}

//**************************************************************************
//  DEVICE DIO16 CARD INTERFACE
//**************************************************************************

device_dio16_card_interface::device_dio16_card_interface(const machine_config &mconfig, device_t &device) :
	device_interface(device, "hpdio"),
	m_dio_dev(nullptr), m_next(nullptr)
{
}

device_dio16_card_interface::~device_dio16_card_interface()
{
}

void device_dio16_card_interface::interface_pre_start()
{
	if (!m_dio_dev)
		throw emu_fatalerror("device_dio16_card_interface: DIO bus not configured\n");
}

//**************************************************************************
//  DIO32 DEVICE
//**************************************************************************

dio32_device::dio32_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	dio16_device(mconfig, DIO32, tag, owner, clock)
{
}

void dio32_device::device_start()
{
	dio16_device::device_start();
}

//**************************************************************************
//  DEVICE DIO32 CARD INTERFACE
//**************************************************************************

device_dio32_card_interface::device_dio32_card_interface(const machine_config &mconfig, device_t &device) :
	device_dio16_card_interface(mconfig, device)
{
}

device_dio32_card_interface::~device_dio32_card_interface()
{
}

void device_dio32_card_interface::interface_pre_start()
{
	device_dio16_card_interface::interface_pre_start();

	if (m_dio_dev && !dynamic_cast<dio32_device *>(m_dio_dev))
		throw emu_fatalerror("device_dio32_card_interface: DIO32 device %s (%s) in DIO16 slot %s\n", device().tag(), device().name(), m_dio_dev->name());
}

} // namespace bus::hp_dio

void dio16_cards(device_slot_interface & device)
{
	device.option_add("98543", HPDIO_98543);
	device.option_add("98544", HPDIO_98544);
	device.option_add("98603a", HPDIO_98603A);
	device.option_add("98603b", HPDIO_98603B);
	device.option_add("98643", HPDIO_98643);
	device.option_add("98644", HPDIO_98644);
	device.option_add("human_interface", HPDIO_HUMAN_INTERFACE);
}

void dio32_cards(device_slot_interface & device)
{
	dio16_cards(device);
	device.option_add("98265a", HPDIO_98265A);
	device.option_add("98550", HPDIO_98550);
	device.option_add("98620", HPDIO_98620);
}