summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/machine/mc2661.h
blob: 3ab5ab609ddf4c3d4da3dc0520284e2b4d6c8ab1 (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
/***************************************************************************

    Motorola MC2661/MC68661 Enhanced Programmable Communications Interface

    Copyright the MESS Team.
    Visit http://mamedev.org for licensing and usage restrictions.

****************************************************************************
                            _____   _____
                    D2   1 |*    \_/     | 28  D1
                    D3   2 |             | 27  D0
                   RxD   3 |             | 26  Vcc
                   GND   4 |             | 25  _RxC/BKDET
                    D4   5 |             | 24  _DTR
                    D5   6 |             | 23  _RTS
                    D6   7 |   MC2661    | 22  _DSR
                    D7   8 |   MC68661   | 21  RESET
            _TxC/XSYNC   9 |             | 20  BRCLK
                    A1  10 |             | 19  TxD
                   _CE  11 |             | 18  _TxEMT/DSCHG
                    A0  12 |             | 17  _CTS
                  _R/W  13 |             | 16  _DCD
                _RxRDY  14 |_____________| 15  _TxRDY

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

#pragma once

#ifndef __MC2661__
#define __MC2661__

#include "emu.h"



/***************************************************************************
    DEVICE CONFIGURATION MACROS
***************************************************************************/

#define MCFG_MC2661_ADD(_tag, _clock, _config) \
	MCFG_DEVICE_ADD(_tag, MC2661, _clock) \
	MCFG_DEVICE_CONFIG(_config)


#define MC2661_INTERFACE(_name) \
	const mc2661_interface (_name) =



/***************************************************************************
    TYPE DEFINITIONS
***************************************************************************/

// ======================> mc2661_interface

struct mc2661_interface
{
	int m_rxc;
	int m_txc;

	devcb_read_line		m_in_rxd_cb;
	devcb_write_line	m_out_txd_cb;

	devcb_write_line	m_out_rxrdy_cb;
	devcb_write_line	m_out_txrdy_cb;
	devcb_write_line	m_out_rts_cb;
	devcb_write_line	m_out_dtr_cb;
	devcb_write_line	m_out_txemt_dschg_cb;
	devcb_write_line	m_out_bkdet_cb;
	devcb_write_line	m_out_xsync_cb;
};


// ======================> mc2661_device

class mc2661_device :  public device_t,
					    public device_serial_interface,
					    public mc2661_interface
{
public:
	// construction/destruction
	mc2661_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);

	DECLARE_READ8_MEMBER( read );
	DECLARE_WRITE8_MEMBER( write );

	DECLARE_WRITE_LINE_MEMBER( rxc_w );
	DECLARE_WRITE_LINE_MEMBER( txc_w );

	DECLARE_WRITE_LINE_MEMBER( dsr_w );
	DECLARE_WRITE_LINE_MEMBER( dcd_w );
	DECLARE_WRITE_LINE_MEMBER( cts_w );

	DECLARE_READ_LINE_MEMBER( rxrdy_r );
	DECLARE_READ_LINE_MEMBER( txemt_r );

protected:
	// device-level overrides
	virtual void device_config_complete();
	virtual void device_start();
	virtual void device_reset();
	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);

	// device_serial_interface overrides
	virtual void input_callback(UINT8 state);

private:
	inline void receive();
	inline void transmit();

	enum 
	{
		TIMER_RX,
		TIMER_TX
	};

	devcb_resolved_read_line	m_in_rxd_func;
	devcb_resolved_write_line	m_out_txd_func;

	devcb_resolved_write_line	m_out_rxrdy_func;
	devcb_resolved_write_line	m_out_txrdy_func;
	devcb_resolved_write_line	m_out_rts_func;
	devcb_resolved_write_line	m_out_dtr_func;
	devcb_resolved_write_line	m_out_txemt_dschg_func;
	devcb_resolved_write_line	m_out_bkdet_func;
	devcb_resolved_write_line	m_out_xsync_func;

	UINT8 m_rhr;
	UINT8 m_thr;
	UINT8 m_cr;
	UINT8 m_sr;
	UINT8 m_mr[2];
	UINT8 m_sync[3];

	int m_mode_index;
	int m_sync_index;

	// timers
	emu_timer *m_rx_timer;
	emu_timer *m_tx_timer;
};


// device type definition
extern const device_type MC2661;



#endif