summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/im6402.h
blob: 05f0b33861a894deab511c8add2bc0266d81ba59 (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
// license:BSD-3-Clause
// copyright-holders:Curt Coder
/***************************************************************************

    Intersil IM6402 Universal Asynchronous Receiver/Transmitter emulation

****************************************************************************
                            _____   _____
                   Vcc   1 |*    \_/     | 40  NOTE
                  NOTE   2 |             | 39  EPE
                   GND   3 |             | 38  CLS1
                   RRD   4 |             | 37  CLS2
                  RBR8   5 |             | 36  SBS
                  RBR7   6 |             | 35  PI
                  RBR6   7 |             | 34  CRL
                  RBR5   8 |             | 33  TBR8
                  RBR4   9 |             | 32  TBR7
                  RBR3  10 |    IM6402   | 31  TBR6
                  RBR2  11 |    IM6403   | 30  TBR5
                  RBR1  12 |             | 29  TBR4
                    PE  13 |             | 28  TBR3
                    FE  14 |             | 27  TBR2
                    OE  15 |             | 26  TBR1
                   SFD  16 |             | 25  TRO
                  NOTE  17 |             | 24  TRE
                   DRR  18 |             | 23  TRBL
                    DR  19 |             | 22  TBRE
                   RRI  20 |_____________| 21  MR


                NOTE:   PIN     IM6402      IM6403
                        ---------------------------
                        2       N/C         CONTROL
                        17      RRC         OSC IN
                        40      TRC         OSC OUT

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

#pragma once

#ifndef __IM6402__
#define __IM6402__

#include "emu.h"



/***************************************************************************
    INTERFACE CONFIGURATION MACROS
***************************************************************************/

#define MCFG_IM6402_ADD(_tag, _rrc, _trc) \
	MCFG_DEVICE_ADD(_tag, IM6402, 0) \
	im6402_device::set_rrc(*device, _rrc); \
	im6402_device::set_trc(*device, _trc);

#define MCFG_IM6402_TRO_CALLBACK(_write) \
	devcb = &im6402_device::set_tro_wr_callback(*device, DEVCB_##_write);

#define MCFG_IM6402_DR_CALLBACK(_write) \
	devcb = &im6402_device::set_dr_wr_callback(*device, DEVCB_##_write);

#define MCFG_IM6402_TBRE_CALLBACK(_write) \
	devcb = &im6402_device::set_tbre_wr_callback(*device, DEVCB_##_write);

#define MCFG_IM6402_TRE_CALLBACK(_write) \
	devcb = &im6402_device::set_tre_wr_callback(*device, DEVCB_##_write);



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

// ======================> im6402_device

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

	static void set_rrc(device_t &device, int rrc) { downcast<im6402_device &>(device).m_rrc = rrc; }
	static void set_trc(device_t &device, int trc) { downcast<im6402_device &>(device).m_trc = trc; }
	template<class _Object> static devcb_base &set_tro_wr_callback(device_t &device, _Object object) { return downcast<im6402_device &>(device).m_write_tro.set_callback(object); }
	template<class _Object> static devcb_base &set_dr_wr_callback(device_t &device, _Object object) { return downcast<im6402_device &>(device).m_write_dr.set_callback(object); }
	template<class _Object> static devcb_base &set_tbre_wr_callback(device_t &device, _Object object) { return downcast<im6402_device &>(device).m_write_tbre.set_callback(object); }
	template<class _Object> static devcb_base &set_tre_wr_callback(device_t &device, _Object object) { return downcast<im6402_device &>(device).m_write_tre.set_callback(object); }

	DECLARE_READ8_MEMBER( read ) { return m_rbr; }
	DECLARE_WRITE8_MEMBER( write );

	DECLARE_READ_LINE_MEMBER( dr_r ) { return m_dr; }
	DECLARE_READ_LINE_MEMBER( tbre_r ) { return m_tbre; }
	DECLARE_READ_LINE_MEMBER( tre_r ) { return m_tre; }
	DECLARE_READ_LINE_MEMBER( pe_r ) { return m_pe; }
	DECLARE_READ_LINE_MEMBER( fe_r ) { return m_fe; }
	DECLARE_READ_LINE_MEMBER( oe_r ) { return m_oe; }

	DECLARE_WRITE_LINE_MEMBER( write_rri ); // receiver register input
	DECLARE_WRITE_LINE_MEMBER( rrc_w );
	DECLARE_WRITE_LINE_MEMBER( trc_w );
	DECLARE_WRITE_LINE_MEMBER( rrd_w );
	DECLARE_WRITE_LINE_MEMBER( sfd_w );
	DECLARE_WRITE_LINE_MEMBER( drr_w );
	DECLARE_WRITE_LINE_MEMBER( mr_w );
	DECLARE_WRITE_LINE_MEMBER( crl_w );
	DECLARE_WRITE_LINE_MEMBER( pi_w );
	DECLARE_WRITE_LINE_MEMBER( sbs_w );
	DECLARE_WRITE_LINE_MEMBER( cls1_w );
	DECLARE_WRITE_LINE_MEMBER( cls2_w );
	DECLARE_WRITE_LINE_MEMBER( epe_w );

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

	// device_serial_interface overrides
	virtual void tra_callback() override;
	virtual void tra_complete() override;
	virtual void rcv_callback() override;
	virtual void rcv_complete() override;

private:
	inline void set_dr(int state);
	inline void set_tbre(int state);
	inline void set_tre(int state);

	devcb_write_line   m_write_tro;
	devcb_write_line   m_write_dr;
	devcb_write_line   m_write_tbre;
	devcb_write_line   m_write_tre;

	// status
	int m_dr;
	int m_tbre;
	int m_tre;
	int m_pe;
	int m_fe;
	int m_oe;

	// control
	int m_cls1;
	int m_cls2;
	int m_sbs;
	int m_sfd;
	int m_epe;
	int m_pi;

	// receiver
	UINT8 m_rbr;
	int m_rrc;
	int m_rrc_count;

	// transmitter
	UINT8 m_tbr;
	int m_trc;
	int m_trc_count;
};


// device type definition
extern const device_type IM6402;



#endif