summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/mm5740.h
blob: 8687f4d6cc9d0eda2a4727090034d456a8b2a7b4 (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
// license:BSD-3-Clause
// copyright-holders: R. Belmont
/**********************************************************************

    MM5740 Keyboard Encoder emulation

**********************************************************************
			    _____   _____
		    B3   1 |*    \_/     | 40  B4
		   Vll   2 |             | 39  B9
		 Clock   3 |             | 38  B2
		    X9   4 |             | 37  B1
		    X8   5 |             | 36  B8
		    X7   6 |             | 35  B7
		    X6   7 |             | 34  B6
		    X5   8 |             | 33  B5
		    X4   9 |             | 32  Vss
		    X3  10 |    MM5740   | 31  Y9
		    X2  11 |             | 30  Y8
		    X1  12 |             | 29  Y7
    Data Strobe Output  13 |             | 28  Y6
   Data Strobe Control  14 |             | 27  Y5
	 Output Enable  15 |             | 26  Y4
		Repeat  16 |             | 25  Y3
       Key Bounce Mask  17 |             | 24  Y2
		   Vgg  18 |             | 23  Y1
	       Control  19 |             | 22  Y0
	Shift Lock I/O  20 |_____________| 21  Shift

Name                 Pin No.     Function
----------------------------------------------------------------------

X1-X9                4-12        Output - Drives the key switch matrix.

Y1-Y10               22-31       Inputs - connect to the X drive lines with
				 the key switch matrix.

B1-B9                1,33-40     Tri-stated data outputs.

Data Strobe Output   13          Output to indicate key pressed.

Data Strobe Control  14          Input to control data strobe output pulse width.

Output Enable        15          Input to control the chip's TRI-STATE output

Repeat               16          Each cycle of this signal will issue
				 a new data strobe for the pressed key.

Key-Bounce Mask      17          Use capacitor on this chip to provide
				 key debouncing

Shift                21          Shift key pressed

Control              19          Control key pressed

Shift Lock I/O       20          Togglable input to signify shift (NOT caps) lock.

Clock                3           A TTL compatible clock signal 

Vss                  32          +5.0V 

Vll                  2           Ground

Vgg                  18          -12V


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

/* TODO:
	Support Key-bounce mask
	Support Repeat function
	Support shift lock
	Support additional internal ROMs
*/

#pragma once

#ifndef MAME_DEVICE_MACHINE_MM5740_H
#define MAME_DEVICE_MACHINE_MM5740_H


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

#define MCFG_MM5740_MATRIX_X1(_cb)       devcb = &mm5740_device::set_x_cb(*device, DEVCB_##_cb, 0);
#define MCFG_MM5740_MATRIX_X2(_cb)       devcb = &mm5740_device::set_x_cb(*device, DEVCB_##_cb, 1);
#define MCFG_MM5740_MATRIX_X3(_cb)       devcb = &mm5740_device::set_x_cb(*device, DEVCB_##_cb, 2);
#define MCFG_MM5740_MATRIX_X4(_cb)       devcb = &mm5740_device::set_x_cb(*device, DEVCB_##_cb, 3);
#define MCFG_MM5740_MATRIX_X5(_cb)       devcb = &mm5740_device::set_x_cb(*device, DEVCB_##_cb, 4);
#define MCFG_MM5740_MATRIX_X6(_cb)       devcb = &mm5740_device::set_x_cb(*device, DEVCB_##_cb, 5);
#define MCFG_MM5740_MATRIX_X7(_cb)       devcb = &mm5740_device::set_x_cb(*device, DEVCB_##_cb, 6);
#define MCFG_MM5740_MATRIX_X8(_cb)       devcb = &mm5740_device::set_x_cb(*device, DEVCB_##_cb, 7);
#define MCFG_MM5740_MATRIX_X9(_cb)       devcb = &mm5740_device::set_x_cb(*device, DEVCB_##_cb, 8);
#define MCFG_MM5740_SHIFT_CB(_cb)        devcb = &mm5740_device::set_shift_cb(*device, DEVCB_##_cb);
#define MCFG_MM5740_CONTROL_CB(_cb)      devcb = &mm5740_device::set_control_cb(*device, DEVCB_##_cb);
#define MCFG_MM5740_DATA_READY_CB(_cb)   devcb = &mm5740_device::set_data_ready_cb(*device, DEVCB_##_cb);

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

// ======================> mm5740_device

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

	// public interface
	uint16_t b_r();

	template<typename Object> static devcb_base &set_x_cb(device_t &device, Object &&object, uint8_t i) 
	{
		assert(i<9); return downcast<mm5740_device &>(device).m_read_x[i].set_callback(std::forward<Object>(object));
	}
	template<typename Object> static devcb_base &set_shift_cb(device_t &device, Object &&object)
	{
		return downcast<mm5740_device &>(device).m_read_shift.set_callback(std::forward<Object>(object));
	}
	template<typename Object> static devcb_base &set_control_cb(device_t &device, Object &&object)
	{
		return downcast<mm5740_device &>(device).m_read_control.set_callback(std::forward<Object>(object));
	}
	template<typename Object> static devcb_base &set_data_ready_cb(device_t &device, Object &&object)
	{
		return downcast<mm5740_device &>(device).m_write_data_ready.set_callback(std::forward<Object>(object));
	}
	static uint32_t calc_effective_clock_key_debounce(uint32_t capacitance);

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;

	virtual const tiny_rom_entry *device_rom_region() const override;

private:
	devcb_read16 m_read_x[9];
	devcb_read_line m_read_shift, m_read_control;
	devcb_write_line m_write_data_ready;

	required_memory_region m_rom;                   // Internal ROM

	int m_b;                    // output buffer

	int m_x_mask[9];            // mask of what keys are down

	// timers
	emu_timer *m_scan_timer;    // keyboard scan timer
};


// device type definition
extern const device_type MM5740;



#endif