1
/**********************************************************************
3
Motorola MC6852 Synchronous Serial Data Adapter emulation
6
Visit http://mamedev.org for licensing and usage restrictions.
8
**********************************************************************/
18
- 1-sync-character mode
19
- 2-sync-character mode
27
#include "machine/devhelpr.h"
30
// device type definition
31
const device_type MC6852 = &device_creator<mc6852_device>;
34
//**************************************************************************
36
//**************************************************************************
46
#define S_RX_OVRN 0x20
53
#define C1_STRIP_SYNC 0x04
54
#define C1_CLEAR_SYNC 0x08
57
#define C1_AC_MASK 0xc0
60
#define C1_AC_SYNC 0x80
61
#define C1_AC_TX_FIFO 0xc0
66
#define C2_1_2_BYTE 0x04
67
#define C2_WS_MASK 0x38
68
#define C2_WS_6_E 0x00
69
#define C2_WS_6_O 0x08
72
#define C2_WS_7_E 0x20
73
#define C2_WS_7_O 0x28
74
#define C2_WS_8_E 0x30
75
#define C2_WS_8_O 0x38
76
#define C2_TX_SYNC 0x40
80
#define C3_E_I_SYNC 0x01
81
#define C3_1_2_SYNC 0x02
82
#define C3_CLEAR_CTS 0x04
86
//**************************************************************************
88
//**************************************************************************
90
inline void mc6852_device::receive()
94
inline void mc6852_device::transmit()
100
//**************************************************************************
102
//**************************************************************************
104
//-------------------------------------------------
105
// mc6852_device - constructor
106
//-------------------------------------------------
108
mc6852_device::mc6852_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
109
: device_t(mconfig, MC6852, "MC6852", tag, owner, clock)
114
//-------------------------------------------------
115
// device_config_complete - perform any
116
// operations now that the configuration is
118
//-------------------------------------------------
120
void mc6852_device::device_config_complete()
122
// inherit a copy of the static data
123
const mc6852_interface *intf = reinterpret_cast<const mc6852_interface *>(static_config());
125
*static_cast<mc6852_interface *>(this) = *intf;
127
// or initialize to defaults if none provided
130
memset(&m_in_rx_data_cb, 0, sizeof(m_in_rx_data_cb));
131
memset(&m_out_tx_data_cb, 0, sizeof(m_out_tx_data_cb));
132
memset(&m_out_irq_cb, 0, sizeof(m_out_irq_cb));
133
memset(&m_in_cts_cb, 0, sizeof(m_in_cts_cb));
134
memset(&m_in_dcd_cb, 0, sizeof(m_in_dcd_cb));
135
memset(&m_out_sm_dtr_cb, 0, sizeof(m_out_sm_dtr_cb));
136
memset(&m_out_tuf_cb, 0, sizeof(m_out_tuf_cb));
141
//-------------------------------------------------
142
// device_start - device-specific startup
143
//-------------------------------------------------
145
void mc6852_device::device_start()
148
m_in_rx_data_func.resolve(m_in_rx_data_cb, *this);
149
m_out_tx_data_func.resolve(m_out_tx_data_cb, *this);
150
m_out_irq_func.resolve(m_out_irq_cb, *this);
151
m_in_cts_func.resolve(m_in_cts_cb, *this);
152
m_in_dcd_func.resolve(m_in_dcd_cb, *this);
153
m_out_sm_dtr_func.resolve(m_out_sm_dtr_cb, *this);
154
m_out_tuf_func.resolve(m_out_tuf_cb, *this);
158
m_rx_timer = timer_alloc(TIMER_RX);
159
m_rx_timer->adjust(attotime::zero, 0, attotime::from_hz(m_rx_clock));
164
m_tx_timer = timer_alloc(TIMER_TX);
165
m_tx_timer->adjust(attotime::zero, 0, attotime::from_hz(m_tx_clock));
168
// register for state saving
169
save_item(NAME(m_status));
170
save_item(NAME(m_cr));
171
save_item(NAME(m_scr));
172
save_item(NAME(m_rx_fifo));
173
save_item(NAME(m_tx_fifo));
174
save_item(NAME(m_tdr));
175
save_item(NAME(m_tsr));
176
save_item(NAME(m_rdr));
177
save_item(NAME(m_rsr));
178
save_item(NAME(m_cts));
179
save_item(NAME(m_dcd));
180
save_item(NAME(m_sm_dtr));
181
save_item(NAME(m_tuf));
185
//-------------------------------------------------
186
// device_reset - device-specific reset
187
//-------------------------------------------------
189
void mc6852_device::device_reset()
191
/* set receiver shift register to all 1's */
194
/* reset and inhibit receiver/transmitter sections */
195
m_cr[0] |= (C1_TX_RS | C1_RX_RS);
199
//-------------------------------------------------
200
// device_timer - handler timer events
201
//-------------------------------------------------
203
void mc6852_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
218
//-------------------------------------------------
220
//-------------------------------------------------
222
READ8_MEMBER( mc6852_device::read )
228
/* receive data FIFO */
240
//-------------------------------------------------
242
//-------------------------------------------------
244
WRITE8_MEMBER( mc6852_device::write )
248
switch (m_cr[0] & C1_AC_MASK)
266
/* transmit data FIFO */
275
/* When Rx Rs is set, it clears the receiver
276
control logic, sync logic, error logic, Rx Data FIFO Control,
277
Parity Error status bit, and DCD interrupt. The Receiver Shift
278
Register is set to ones.
281
if (LOG) logerror("MC6852 '%s' Receiver Reset\n", tag());
283
m_status &= ~(S_RX_OVRN | S_PE | S_DCD | S_RDA);
287
/* transmitter reset */
290
/* When Tx Rs is set, it clears the transmitter
291
control section, Transmitter Shift Register, Tx Data FIFO
292
Control (the Tx Data FIFO can be reloaded after one E clock
293
pulse), the Transmitter Underflow status bit, and the CTS interrupt,
294
and inhibits the TDRA status bit (in the one-sync-character
295
and two-sync-character modes).*/
297
if (LOG) logerror("MC6852 '%s' Transmitter Reset\n", tag());
299
m_status &= ~(S_TUF | S_CTS | S_TDRA);
304
if (data & C1_STRIP_SYNC) logerror("MC6852 '%s' Strip Synchronization Characters\n", tag());
305
if (data & C1_CLEAR_SYNC) logerror("MC6852 '%s' Clear Synchronization\n", tag());
313
//-------------------------------------------------
315
//-------------------------------------------------
317
WRITE_LINE_MEMBER( mc6852_device::rx_clk_w )
319
if (state) receive();
323
//-------------------------------------------------
325
//-------------------------------------------------
327
WRITE_LINE_MEMBER( mc6852_device::tx_clk_w )
329
if (state) transmit();
333
//-------------------------------------------------
335
//-------------------------------------------------
337
WRITE_LINE_MEMBER( mc6852_device::cts_w )
343
//-------------------------------------------------
345
//-------------------------------------------------
347
WRITE_LINE_MEMBER( mc6852_device::dcd_w )
353
//-------------------------------------------------
355
//-------------------------------------------------
357
READ_LINE_MEMBER( mc6852_device::sm_dtr_r )
363
//-------------------------------------------------
365
//-------------------------------------------------
367
READ_LINE_MEMBER( mc6852_device::tuf_r )