summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/tube.cpp
blob: b1490283fd98e0ac61837909fc0f21e6b07f516f (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
// license:BSD-3-Clause
// copyright-holders:Nigel Barnes
/**********************************************************************

    Acorn Tube ULA emulation

    The Tube ULA acts as a parallel interface between two asynchronous
    processor systems. It consists of four byte-wide read-only registers
    and four byte-wide write-only registers. Eight bytes of memory mapped
    I/O space are used to address these registers, four for the data
    registers and four for the associated status registers.

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

#include "emu.h"
#include "machine/tube.h"



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

DEFINE_DEVICE_TYPE(TUBE, tube_device, "tube", "Acorn Tube ULA")



//-------------------------------------------------
//  bbc_tube_slot_device - constructor
//-------------------------------------------------

tube_device::tube_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, TUBE, tag, owner, clock),
	m_hirq_handler(*this),
	m_pnmi_handler(*this),
	m_pirq_handler(*this),
	m_drq_handler(*this)
{
}


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

void tube_device::device_start()
{
	// resolve callbacks
	m_hirq_handler.resolve_safe();
	m_pnmi_handler.resolve_safe();
	m_pirq_handler.resolve_safe();
	m_drq_handler.resolve_safe();
}


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

void tube_device::device_reset()
{
	m_ph1pos = m_hp3pos = 0;
	m_ph3pos = 1;
	m_r1stat = 0;
	m_hstat[0] = m_hstat[1] = m_hstat[3] = 0x40;
	m_hstat[2] = 0xc0;
	m_pstat[0] = m_pstat[1] = m_pstat[2] = m_pstat[3] = 0x40;
}


void tube_device::update_interrupts()
{
	m_hirq_handler(BIT(m_r1stat, 0) && BIT(m_hstat[3], 7) ? ASSERT_LINE : CLEAR_LINE);

	m_pirq_handler((BIT(m_r1stat, 1) && BIT(m_pstat[0], 7)) || (BIT(m_r1stat, 2) && BIT(m_pstat[3], 7)) ? ASSERT_LINE : CLEAR_LINE);

	m_pnmi_handler(BIT(m_r1stat, 3) && ((m_hp3pos > BIT(m_r1stat, 4)) || (m_ph3pos == 0)) ? ASSERT_LINE : CLEAR_LINE);

	m_drq_handler(!BIT(m_r1stat, 4) && ((m_hp3pos > BIT(m_r1stat, 4)) || (m_ph3pos == 0)) ? ASSERT_LINE : CLEAR_LINE);
}

uint8_t tube_device::host_r(offs_t offset)
{
	uint8_t data = 0xfe;

	switch (offset & 0x07)
	{
	case 0: /* Status and Register 1 flags */
		data = (m_hstat[0] & 0xc0) | m_r1stat;
		break;

	case 1: /* Register 1 */
		data = m_ph1[0];
		if (!machine().side_effects_disabled())
		{
			for (int i = 0; i < 23; i++) m_ph1[i] = m_ph1[i + 1];
			m_ph1pos--;
			m_pstat[0] |= 0x40;
			if (!m_ph1pos) m_hstat[0] &= ~0x80;
		}
		break;

	case 2: /* Register 2 flags */
		data = m_hstat[1];
		break;

	case 3: /* Register 2 */
		data = m_ph2;
		if (BIT(m_hstat[1], 7) && !machine().side_effects_disabled())
		{
			m_hstat[1] &= ~0x80;
			m_pstat[1] |= 0x40;
		}
		break;

	case 4: /* Register 3 flags */
		data = m_hstat[2];
		break;

	case 5: /* Register 3 */
		data = m_ph3[0];
		if ((m_ph3pos > 0) && !machine().side_effects_disabled())
		{
			m_ph3[0] = m_ph3[1];
			m_ph3pos--;
			m_pstat[2] |= 0xc0;
			if (!m_ph3pos) m_hstat[2] &= ~0x80;
		}
		break;

	case 6: /* Register 4 flags */
		data = m_hstat[3];
		break;

	case 7: /* Register 4 */
		data = m_ph4;
		if (BIT(m_hstat[3], 7) && !machine().side_effects_disabled())
		{
			m_hstat[3] &= ~0x80;
			m_pstat[3] |= 0x40;
		}
		break;
	}
	update_interrupts();

	return data;
}

void tube_device::host_w(offs_t offset, uint8_t data)
{
	switch (offset & 0x07)
	{
	case 0: /* Status flags */
		if (BIT(data, 7))
			m_r1stat |= (data & 0x3f);
		else
			m_r1stat &= ~(data & 0x3f);
		m_hstat[0] = (m_hstat[0] & 0xc0) | (data & 0x3f);
		break;

	case 1: /* Register 1 */
		m_hp1 = data;
		m_pstat[0] |= 0x80;
		m_hstat[0] &= ~0x40;
		break;

	case 3: /* Register 2 */
		m_hp2 = data;
		m_pstat[1] |= 0x80;
		m_hstat[1] &= ~0x40;
		break;

	case 5: /* Register 3 */
		if (BIT(m_r1stat, 4))
		{
			if (m_hp3pos < 2)
				m_hp3[m_hp3pos++] = data;
			if (m_hp3pos == 2)
			{
				m_pstat[2] |= 0x80;
				m_hstat[2] &= ~0x40;
			}
		}
		else
		{
			m_hp3[0] = data;
			m_hp3pos = 1;
			m_pstat[2] |= 0x80;
			m_hstat[2] &= ~0x40;
		}
		break;

	case 7: /* Register 4 */
		m_hp4 = data;
		m_pstat[3] |= 0x80;
		m_hstat[3] &= ~0x40;
		break;
	}

	update_interrupts();
}

uint8_t tube_device::parasite_r(offs_t offset)
{
	uint8_t data = 0x00;

	switch (offset & 0x07)
	{
	case 0: /*Register 1 flags */
		data = m_pstat[0] | m_r1stat;
		break;

	case 1: /* Register 1 */
		data = m_hp1;
		if (BIT(m_pstat[0], 7) && !machine().side_effects_disabled())
		{
			m_pstat[0] &= ~0x80;
			m_hstat[0] |= 0x40;
		}
		break;

	case 2: /* Register 2 flags */
		data = m_pstat[1];
		break;

	case 3: /* Register 2 */
		data = m_hp2;
		if (BIT(m_pstat[1], 7) && !machine().side_effects_disabled())
		{
			m_pstat[1] &= ~0x80;
			m_hstat[1] |= 0x40;
		}
		break;

	case 4: /* Register 3 flags */
		data = m_pstat[2];
		break;

	case 5: /* Register 3 */
		data = m_hp3[0];
		if ((m_hp3pos > 0) && !machine().side_effects_disabled())
		{
			m_hp3[0] = m_hp3[1];
			m_hp3pos--;
			if (!m_hp3pos)
			{
				m_hstat[2] |= 0x40;
				m_pstat[2] &= ~0x80;
			}
		}
		break;

	case 6: /* Register 4 flags */
		data = m_pstat[3];
		break;

	case 7: /* Register 4 */
		data = m_hp4;
		if (BIT(m_pstat[3], 7) && !machine().side_effects_disabled())
		{
			m_pstat[3] &= ~0x80;
			m_hstat[3] |= 0x40;
		}
		break;
	}
	update_interrupts();

	return data;
}

void tube_device::parasite_w(offs_t offset, uint8_t data)
{
	switch (offset & 0x07)
	{
	case 1: /* Register 1 */
		if (m_ph1pos < 24)
		{
			m_ph1[m_ph1pos++] = data;
			m_hstat[0] |= 0x80;
			if (m_ph1pos == 24)
				m_pstat[0] &= ~0x40;
		}
		break;

	case 3: /* Register 2 */
		m_ph2 = data;
		m_hstat[1] |= 0x80;
		m_pstat[1] &= ~0x40;
		break;

	case 5: /* Register 3 */
		if (BIT(m_r1stat, 4))
		{
			if (m_ph3pos < 2)
				m_ph3[m_ph3pos++] = data;
			if (m_ph3pos == 2)
			{
				m_hstat[2] |= 0x80;
				m_pstat[2] &= ~0x40;
			}
		}
		else
		{
			m_ph3[0] = data;
			m_ph3pos = 1;
			m_hstat[2] |= 0x80;
			m_pstat[2] &= ~0xc0;
		}
		break;

	case 7: /* Register 4 */
		m_ph4 = data;
		m_hstat[3] |= 0x80;
		m_pstat[3] &= ~0x40;
		break;
	}
	update_interrupts();
}