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
375
|
// license:BSD-3-Clause
// copyright-holders:Curt Coder
/**********************************************************************
Motorola MC6852 Synchronous Serial Data Adapter emulation
Copyright MESS Team.
Visit http://mamedev.org for licensing and usage restrictions.
**********************************************************************/
/*
TODO:
- FIFO
- receive
- transmit
- parity
- 1-sync-character mode
- 2-sync-character mode
- external sync mode
- interrupts
*/
#include "emu.h"
#include "mc6852.h"
// device type definition
const device_type MC6852 = &device_creator<mc6852_device>;
//**************************************************************************
// MACROS / CONSTANTS
//**************************************************************************
#define LOG 0
#define S_RDA 0x01
#define S_TDRA 0x02
#define S_DCD 0x04
#define S_CTS 0x08
#define S_TUF 0x10
#define S_RX_OVRN 0x20
#define S_PE 0x40
#define S_IRQ 0x80
#define C1_RX_RS 0x01
#define C1_TX_RS 0x02
#define C1_STRIP_SYNC 0x04
#define C1_CLEAR_SYNC 0x08
#define C1_TIE 0x10
#define C1_RIE 0x20
#define C1_AC_MASK 0xc0
#define C1_AC_C2 0x00
#define C1_AC_C3 0x40
#define C1_AC_SYNC 0x80
#define C1_AC_TX_FIFO 0xc0
#define C2_PC1 0x01
#define C2_PC2 0x02
#define C2_1_2_BYTE 0x04
#define C2_WS_MASK 0x38
#define C2_WS_6_E 0x00
#define C2_WS_6_O 0x08
#define C2_WS_7 0x10
#define C2_WS_8 0x18
#define C2_WS_7_E 0x20
#define C2_WS_7_O 0x28
#define C2_WS_8_E 0x30
#define C2_WS_8_O 0x38
#define C2_TX_SYNC 0x40
#define C2_EIE 0x80
#define C3_E_I_SYNC 0x01
#define C3_1_2_SYNC 0x02
#define C3_CLEAR_CTS 0x04
#define C3_CTUF 0x08
//**************************************************************************
// INLINE HELPERS
//**************************************************************************
inline void mc6852_device::receive()
{
}
inline void mc6852_device::transmit()
{
}
//**************************************************************************
// LIVE DEVICE
//**************************************************************************
//-------------------------------------------------
// mc6852_device - constructor
//-------------------------------------------------
mc6852_device::mc6852_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, MC6852, "MC6852", tag, owner, clock, "mc6852", __FILE__)
{
}
//-------------------------------------------------
// device_config_complete - perform any
// operations now that the configuration is
// complete
//-------------------------------------------------
void mc6852_device::device_config_complete()
{
// inherit a copy of the static data
const mc6852_interface *intf = reinterpret_cast<const mc6852_interface *>(static_config());
if (intf != NULL)
*static_cast<mc6852_interface *>(this) = *intf;
// or initialize to defaults if none provided
else
{
memset(&m_out_tx_data_cb, 0, sizeof(m_out_tx_data_cb));
memset(&m_out_irq_cb, 0, sizeof(m_out_irq_cb));
memset(&m_out_sm_dtr_cb, 0, sizeof(m_out_sm_dtr_cb));
memset(&m_out_tuf_cb, 0, sizeof(m_out_tuf_cb));
}
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void mc6852_device::device_start()
{
// resolve callbacks
m_out_tx_data_func.resolve(m_out_tx_data_cb, *this);
m_out_irq_func.resolve(m_out_irq_cb, *this);
m_out_sm_dtr_func.resolve(m_out_sm_dtr_cb, *this);
m_out_tuf_func.resolve(m_out_tuf_cb, *this);
if (m_rx_clock > 0)
{
m_rx_timer = timer_alloc(TIMER_RX);
m_rx_timer->adjust(attotime::zero, 0, attotime::from_hz(m_rx_clock));
}
if (m_tx_clock > 0)
{
m_tx_timer = timer_alloc(TIMER_TX);
m_tx_timer->adjust(attotime::zero, 0, attotime::from_hz(m_tx_clock));
}
// register for state saving
save_item(NAME(m_status));
save_item(NAME(m_cr));
save_item(NAME(m_scr));
save_item(NAME(m_rx_fifo));
save_item(NAME(m_tx_fifo));
save_item(NAME(m_tdr));
save_item(NAME(m_tsr));
save_item(NAME(m_rdr));
save_item(NAME(m_rsr));
save_item(NAME(m_cts));
save_item(NAME(m_dcd));
save_item(NAME(m_sm_dtr));
save_item(NAME(m_tuf));
}
//-------------------------------------------------
// device_reset - device-specific reset
//-------------------------------------------------
void mc6852_device::device_reset()
{
/* set receiver shift register to all 1's */
m_rsr = 0xff;
/* reset and inhibit receiver/transmitter sections */
m_cr[0] |= (C1_TX_RS | C1_RX_RS);
}
//-------------------------------------------------
// device_timer - handler timer events
//-------------------------------------------------
void mc6852_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
switch (id)
{
case TIMER_RX:
receive();
break;
case TIMER_TX:
transmit();
break;
}
}
//-------------------------------------------------
// read -
//-------------------------------------------------
READ8_MEMBER( mc6852_device::read )
{
UINT8 data = 0;
if (BIT(offset, 0))
{
/* receive data FIFO */
}
else
{
/* status */
data = m_status;
}
return data;
}
//-------------------------------------------------
// write -
//-------------------------------------------------
WRITE8_MEMBER( mc6852_device::write )
{
if (BIT(offset, 0))
{
switch (m_cr[0] & C1_AC_MASK)
{
case C1_AC_C2:
/* control 2 */
m_cr[1] = data;
break;
case C1_AC_C3:
/* control 3 */
m_cr[2] = data;
break;
case C1_AC_SYNC:
/* sync code */
m_scr = data;
break;
case C1_AC_TX_FIFO:
/* transmit data FIFO */
break;
}
}
else
{
/* receiver reset */
if (data & C1_RX_RS)
{
/* When Rx Rs is set, it clears the receiver
control logic, sync logic, error logic, Rx Data FIFO Control,
Parity Error status bit, and DCD interrupt. The Receiver Shift
Register is set to ones.
*/
if (LOG) logerror("MC6852 '%s' Receiver Reset\n", tag());
m_status &= ~(S_RX_OVRN | S_PE | S_DCD | S_RDA);
m_rsr = 0xff;
}
/* transmitter reset */
if (data & C1_TX_RS)
{
/* When Tx Rs is set, it clears the transmitter
control section, Transmitter Shift Register, Tx Data FIFO
Control (the Tx Data FIFO can be reloaded after one E clock
pulse), the Transmitter Underflow status bit, and the CTS interrupt,
and inhibits the TDRA status bit (in the one-sync-character
and two-sync-character modes).*/
if (LOG) logerror("MC6852 '%s' Transmitter Reset\n", tag());
m_status &= ~(S_TUF | S_CTS | S_TDRA);
}
if (LOG)
{
if (data & C1_STRIP_SYNC) logerror("MC6852 '%s' Strip Synchronization Characters\n", tag());
if (data & C1_CLEAR_SYNC) logerror("MC6852 '%s' Clear Synchronization\n", tag());
}
m_cr[0] = data;
}
}
//-------------------------------------------------
// rx_clk_w -
//-------------------------------------------------
WRITE_LINE_MEMBER( mc6852_device::rx_clk_w )
{
if (state) receive();
}
//-------------------------------------------------
// tx_clk_w -
//-------------------------------------------------
WRITE_LINE_MEMBER( mc6852_device::tx_clk_w )
{
if (state) transmit();
}
//-------------------------------------------------
// cts_w -
//-------------------------------------------------
WRITE_LINE_MEMBER( mc6852_device::cts_w )
{
m_cts = state;
}
//-------------------------------------------------
// dcd_w -
//-------------------------------------------------
WRITE_LINE_MEMBER( mc6852_device::dcd_w )
{
m_dcd = state;
}
//-------------------------------------------------
// sm_dtr_r -
//-------------------------------------------------
READ_LINE_MEMBER( mc6852_device::sm_dtr_r )
{
return m_sm_dtr;
}
//-------------------------------------------------
// tuf_r -
//-------------------------------------------------
READ_LINE_MEMBER( mc6852_device::tuf_r )
{
return m_tuf;
}
//-------------------------------------------------
// write_rx -
//-------------------------------------------------
WRITE_LINE_MEMBER( mc6852_device::write_rx )
{
m_rxd = state;
}
|