summaryrefslogtreecommitdiffstats
path: root/src/mame/machine/vt100_kbd.h
blob: 9b1499fd918ced75340b2d9d4ff6343a06843bf9 (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
// license:BSD-3-Clause
// copyright-holders:Miodrag Milanovic, Jonathan Gevaryahu, AJR
/***************************************************************************

        DEC VT100 keyboard emulation

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

#ifndef MAME_MACHINE_VT100_KBD_H
#define MAME_MACHINE_VT100_KBD_H

#pragma once

#include "machine/ay31015.h"
#include "machine/ripple_counter.h"
#include "sound/beep.h"
#include "speaker.h"


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

#define MCFG_VT100_KEYBOARD_SIGNAL_OUT_CALLBACK(_devcb) \
	devcb = &downcast<vt100_keyboard_device &>(*device).set_signal_out_callback(DEVCB_##_devcb);


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

// ======================> vt100_keyboard_device

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

	// configuration
	template <class Object> devcb_base &set_signal_out_callback(Object &&cb) { return m_signal_out_cb.set_callback(std::forward<Object>(cb)); }

	DECLARE_WRITE_LINE_MEMBER(signal_line_w);

protected:
	vt100_keyboard_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock);

	virtual void device_resolve_objects() override;
	virtual void device_start() override;
	virtual void device_add_mconfig(machine_config &config) override;
	virtual ioport_constructor device_input_ports() const override;

	virtual bool scan_enabled() const { return m_uart->tbmt_r(); }
	virtual void scan_start() { }

private:
	// internal helpers
	DECLARE_WRITE_LINE_MEMBER(signal_out_w);
	DECLARE_WRITE_LINE_MEMBER(scan_disable_w);
	DECLARE_WRITE8_MEMBER(key_scan_w);

	devcb_write_line m_signal_out_cb;

	required_device<ay31015_device> m_uart;
	required_device<beep_device> m_speaker;
	required_device<ripple_counter_device> m_scan_counter;
	required_ioport_array<16> m_key_row;

	output_finder<> m_online_led;
	output_finder<> m_local_led;
	output_finder<> m_locked_led;
	output_finder<4> m_ln_led;

	bool m_signal_line;
	attotime m_last_signal_change;
	u8 m_last_scan;
};

// ======================> ms7002_device

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

protected:
	virtual void device_start() override;
	virtual void device_add_mconfig(machine_config &config) override;
	virtual ioport_constructor device_input_ports() const override;

	virtual bool scan_enabled() const override { return m_scan_enable; }
	virtual void scan_start() override { m_scan_enable = true; }

private:
	DECLARE_WRITE_LINE_MEMBER(scan_disable_w);

	bool m_scan_enable;
};

// device type definitions
DECLARE_DEVICE_TYPE(VT100_KEYBOARD, vt100_keyboard_device)
DECLARE_DEVICE_TYPE(MS7002, ms7002_device)

#endif // MAME_MACHINE_VT100_KBD_H