summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/sunkbd/hlekbd.h
blob: a4f6d886f5c2866d7b4e481c076bd25af3f98810 (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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// license:BSD-3-Clause
// copyright-holders:Vas Crabb
#ifndef MAME_DEVICES_SUNKBD_HLEKBD_H
#define MAME_DEVICES_SUNKBD_HLEKBD_H

#pragma once

#include "sunkbd.h"
#include "machine/keyboard.h"
#include "sound/beep.h"
#include "diserial.h"


namespace bus { namespace sunkbd {

class hle_device_base
	: public device_t
	, public device_buffered_serial_interface<16U>
	, public device_sun_keyboard_port_interface
	, protected device_matrix_keyboard_interface<8U>
{
public:
	virtual ~hle_device_base() override;

	virtual DECLARE_WRITE_LINE_MEMBER( input_txd ) override;

protected:
	// constructor/destructor
	hle_device_base(
			machine_config const &mconfig,
			device_type type,
			char const *tag,
			device_t *owner,
			uint32_t clock);

	// device overrides
	virtual void device_add_mconfig(machine_config &config) override;
	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_buffered_serial_interface overrides
	virtual void tra_callback() override;
	virtual void tra_complete() override;

	// device_matrix_keyboard_interface overrides
	virtual void key_make(uint8_t row, uint8_t column) override;
	virtual void key_break(uint8_t row, uint8_t column) override;

	// customised transmit_byte method
	void transmit_byte(uint8_t byte);

	required_ioport m_dips;

private:
	enum {
		CLICK_TIMER_ID = 30'000
	};

	// TODO: ensure these don't clash with diagnostic LEDs on host computer
	enum : int {
		LED_NUM = 0,
		LED_COMPOSE,
		LED_SCROLL,
		LED_CAPS,
		LED_KANA
	};

	enum : uint8_t {
		BEEPER_BELL = 0x01U,
		BEEPER_CLICK = 0x02U
	};

	enum : uint8_t {
		RX_IDLE,
		RX_LED
	};

	enum : uint8_t {
		COMMAND_RESET = 0x01U,
		COMMAND_BELL_ON = 0x02U,
		COMMAND_BELL_OFF = 0x03U,
		COMMAND_CLICK_ON = 0x0aU,
		COMMAND_CLICK_OFF = 0x0bU,
		COMMAND_LED = 0x0eU,
		COMMAND_LAYOUT = 0x0fU
	};

	// device_buffered_serial_interface overrides
	virtual void received_byte(uint8_t byte) override;

	virtual uint8_t ident_byte() = 0;

	emu_timer                       *m_click_timer;
	required_device<beep_device>    m_beeper;
	output_finder<5>                m_leds;

	uint8_t   m_make_count;
	uint8_t   m_rx_state;

	uint8_t   m_keyclick;
	uint8_t   m_beeper_state;
};


class hle_type4_device_base : public hle_device_base
{
protected:
	using hle_device_base::hle_device_base;

private:
	virtual uint8_t ident_byte() override;
};


class hle_type3_device : public hle_device_base
{
public:
	hle_type3_device(
			machine_config const &mconfig,
			char const *tag,
			device_t *owner,
			uint32_t clock);

	virtual ioport_constructor device_input_ports() const override;

private:
	virtual uint8_t ident_byte() override;
};


class hle_type4_device : public hle_type4_device_base
{
public:
	hle_type4_device(
			machine_config const &mconfig,
			char const *tag,
			device_t *owner,
			uint32_t clock);

	virtual ioport_constructor device_input_ports() const override;
};


class hle_type5_device : public hle_type4_device_base
{
public:
	hle_type5_device(
			machine_config const &mconfig,
			char const *tag,
			device_t *owner,
			uint32_t clock);

	virtual ioport_constructor device_input_ports() const override;
};


class hle_type5_gb_device : public hle_type4_device_base
{
public:
	hle_type5_gb_device(
			machine_config const &mconfig,
			char const *tag,
			device_t *owner,
			uint32_t clock);

	virtual ioport_constructor device_input_ports() const override;
};


class hle_type5_se_device : public hle_type4_device_base
{
public:
	hle_type5_se_device(
			machine_config const &mconfig,
			char const *tag,
			device_t *owner,
			uint32_t clock);

	virtual ioport_constructor device_input_ports() const override;
};


class hle_type5_jp_device : public hle_type4_device_base
{
public:
	hle_type5_jp_device(
			machine_config const &mconfig,
			char const *tag,
			device_t *owner,
			uint32_t clock);

	virtual ioport_constructor device_input_ports() const override;
};

} } // namespace bus::sunkbd


DECLARE_DEVICE_TYPE_NS(SUN_TYPE3_HLE_KEYBOARD,    bus::sunkbd, hle_type3_device)
DECLARE_DEVICE_TYPE_NS(SUN_TYPE4_HLE_KEYBOARD,    bus::sunkbd, hle_type4_device)
DECLARE_DEVICE_TYPE_NS(SUN_TYPE5_HLE_KEYBOARD,    bus::sunkbd, hle_type5_device)
DECLARE_DEVICE_TYPE_NS(SUN_TYPE5_GB_HLE_KEYBOARD, bus::sunkbd, hle_type5_gb_device)
DECLARE_DEVICE_TYPE_NS(SUN_TYPE5_SE_HLE_KEYBOARD, bus::sunkbd, hle_type5_se_device)
DECLARE_DEVICE_TYPE_NS(SUN_TYPE5_JP_HLE_KEYBOARD, bus::sunkbd, hle_type5_jp_device)

#endif // MAME_DEVICES_SUNKBD_HLEKBD_H