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

    MOS Technology 6551 Asynchronous Communication Interface Adapter

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

**********************************************************************
                            _____   _____
                   GND   1 |*    \_/     | 28  R/_W
                   CS0   2 |             | 27  phi2
                  _CS1   3 |             | 26  _IRQ
                  _RES   4 |             | 25  DB7
                   RxC   5 |             | 24  DB6
                 XTAL1   6 |             | 23  DB5
                 XTAL2   7 |   MOS6551   | 22  DB4
                  _RTS   8 |             | 21  DB3
                  _CTS   9 |             | 20  DB2
                   TxD  10 |             | 19  DB1
                  _DTR  11 |             | 18  DB0
                   RxD  12 |             | 17  _DBR
                   RS0  13 |             | 16  _DCD
                   RS1  14 |_____________| 15  Vcc

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

#pragma once

#ifndef __MOS6551__
#define __MOS6551__

#include "emu.h"



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

#define MCFG_MOS6551_ADD(_tag, _clock, _irq) \
	MCFG_DEVICE_ADD(_tag, MOS6551, _clock) \
	devcb = &mos6551_device::set_irq_handler(*device, DEVCB2_##_irq);



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

// ======================> mos6551_device

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

	// static configuration helpers
	template<class _Object> static devcb2_base &set_irq_handler(device_t &device, _Object object) { return downcast<mos6551_device &>(device).m_irq_handler.set_callback(object); }

	DECLARE_READ8_MEMBER( read );
	DECLARE_WRITE8_MEMBER( write );

	void set_rxc(int clock);

protected:
	// device-level overrides
	virtual void device_start();
	virtual void device_reset();

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

	enum
	{
		CTRL_BRG_16X_EXTCLK = 0,
		CTRL_BRG_50,
		CTRL_BRG_75,
		CTRL_BRG_109_92,
		CTRL_BRG_134_58,
		CTRL_BRG_150,
		CTRL_BRG_300,
		CTRL_BRG_600,
		CTRL_BRG_1200,
		CTRL_BRG_1800,
		CTRL_BRG_2400,
		CTRL_BRG_3600,
		CTRL_BRG_4800,
		CTRL_BRG_7200,
		CTRL_BRG_9600,
		CTRL_BRG_19200,
		CTRL_BRG_MASK = 0x0f,
		
		CTRL_RXC_EXT = 0x00,
		CTRL_RXC_BRG = 0x10,
		CTRL_RXC_MASK = 0x10,
		
		CTRL_WL_8 = 0x00,
		CTRL_WL_7 = 0x20,
		CTRL_WL_6 = 0x40,
		CTRL_WL_5 = 0x60,
		CTRL_WL_MASK = 0x60,
		
		CTRL_SB_1 = 0x00,
		CTRL_SB_2 = 0x80,
		CTRL_SB_MASK = 0x80
	};

	enum
	{
		CMD_DTR = 0x01,
		
		CMD_RIE = 0x02,
		
		CMD_TC_RTS_HI = 0x00,
		CMD_TC_TIE_RTS_LO = 0x04,
		CMD_TC_RTS_LO = 0x08,
		CMD_TC_BRK = 0x0c,
		CMD_TC_MASK = 0x0c,

		CMD_ECHO = 0x10,

		CMD_PARITY = 0x20,
		CMD_PARITY_ODD = 0x00,
		CMD_PARITY_EVEN = 0x40,
		CMD_PARITY_MARK = 0x80,
		CMD_PARITY_SPACE = 0xc0,
		CMD_PARITY_MASK = 0xc0
	};

	enum
	{
		ST_PE = 0x01,
		ST_FE = 0x02,
		ST_OR = 0x04,
		ST_RDRF = 0x08,
		ST_TDRE = 0x10,
		ST_DCD = 0x20,
		ST_DSR = 0x40,
		ST_IRQ = 0x80
	};

	void update_serial();

	devcb2_write_line m_irq_handler;

	UINT8 m_ctrl;
	UINT8 m_cmd;
	UINT8 m_st;
	UINT8 m_tdr;

	int m_ext_rxc;

	static const int brg_divider[16];
};


// device type definition
extern const device_type MOS6551;



#endif