1 // license:BSD-3-Clause
2 // copyright-holders:Vas Crabb
3 /*
4     Sun keyboard port
5 
6     Pre-USB Sun keyboards use an asynchronous serial protocol.  Data is
7     transmitted at TTL levels using an asynchronous serial protocol at
8     1,200 Baud.  The protocol remained compatible from at least the
9     Type 2 keyboard to the Type 6 keyboard, although key layout and key
10     cap labels varied, some scancodes were repurposed, and a variety of
11     connectors were used.
12 
13     From the Sun 2/50 onwards, the keyboard and mouse share a single
14     connector, either using a splitter adapter, or by plugging the mouse
15     into a pass-through connector on the keyboard.
16 
17     Type 3 female DA-15 connector on host (introduced on Sun 2/50):
18      1: keyboard RxD         9: GND
19      2: GND                 10: +5V
20      3: keyboard TxD        11: +5V
21      4: GND                 12: +5V
22      5: mouse RxD           13: +5V
23      6: GND                 14: +5V
24      7: mouse TxD           15: +5V
25      8: GND
26 
27     Type 4 female Mini-DIN-8 connector on host (introduced on Sun 3/80):
28     1: GND          3: +5V              6: keyboard RxD
29     2: GND          4: mouse RxD        7: mouse TxD
30                     5: keyboard TxD     8: +5V
31 
32     Type 5 female Mini-DIN-8 connector on host:
33     1: GND          3: +5V              6: keyboard RxD
34     2: GND          4: mouse RxD        7: power key
35                     5: keyboard TxD     8: +5V
36 
37     Scancodes (U.S. caps except as noted):
38     00:                 20: 3               40: [ {             60: Page Up
39     01: L1/Stop         21: 5               41: ] }             61: L10/Cut
40     02: Volume Down     22: 5               42: Delete          62: Num Lock
41     03: L2/Again        23: 6               43: Compose         63: Left Shift
42     04: Volume Up       24: 7               44: R7/KP 7         64: Z
43     05: F1              25: 8               45: R8/KP 8         65: X
44     06: F2              26: 9               46: R9/KP 9         66: C
45     07: F10             27: 0               47: KP -            67: V
46     08: F3              28: - _             48: L7/Open         68: B
47     09: F11             29: = +             49: L8/Paste        69: N
48     0a: F4              2a: ` ~             4a: End             6a: M
49     0b: F12             2b: Backspace       4b:                 6b: , <
50     0c: F5              2c: Insert          4c: Control         6c: . >
51     0d: Alt Graph       2d: R4/KP =/Mute    4d: A               6d: / ?
52     0e: F6              2e: R5/KP /         4e: S               6e: Right Shift
53     0f: Blank           2f: R6/KP *         4f: D               6f: Line Feed/\ _
54     10: F7              30: Power           50: F               70: R13/KP 1
55     11: F8              31: L5/Front        51: G               71: R14/KP 2
56     12: F9              32: KP .            52: H               72: R15/KP 3
57     13: Alt             33: L6/Copy         53: J               73: Kakutei
58     14: Cursor Up       34: Home            54: K               74: Henkan
59     15: R1/Pause        35: Tab             55: L               75: Nihongo On-Off
60     16: R2/Print Screen 36: Q               56: ; :             76: Help
61     17: R3/Scroll Lock  37: W               57: ' "             77: Caps Lock
62     18: Cursor Left     38: E               58: \ |             78: Left Meta
63     19: L3/Props        39: R               59: Return          79: Space
64     1a: L4/Undo         3a: T               5a: Enter           7a: Right Meta
65     1b: Cursor Down     3b: Y               5b: R10/KP 4        7b: Page Down
66     1c: Cursor Right    3c: U               5c: R11/KP 5        7c: < >
67     1d: Escape          3d: I               5d: R12/KP 6        7d: KP +
68     1e: 1               3e: O               5e: KP 0            7e:
69     1f: 2               3f: P               5f: L9/Find         7f:
70 
71     7e and 7f are reserved for special messages.
72     L function group and R function group repurposed on Type 4 keyboard.
73     F10, F11, F12, Alt Graph, Compose, and Help added on Type 4 keyboard.
74     Num Lock, KP -, KP +, KP 0, KP ., and Enter added on Type 4 keyboard.
75     Line Feed removed from Type 5 keyboard.
76     Cursor Up, Cursor Down, Cursor Left, and Cursor Right added on Type 5 keyboard.
77     Insert, Home, End, Page Up, and Page Down added on Type 5 keyboard.
78     Volume Down, Volume Up, and Power added on Type 5 keyboard.
79     KP = repurposed for Mute on Type 5 keyboard.
80     Blank key only present on Type 5 UNIX keyboard.
81     < > only present on Type 5 International (ISO) keyboard.
82     Line Feed repurposed for backslash/underscore on Type 5 Japanese (JIS) keyboard.
83     Kakutei, Henkan, and Nihongo On-Off only present on Type 5 Japanese (JIS) keyboard.
84 
85     TODO:
86     * Add power key line for soft power sun4c and later systems.
87     * Confirm actual logic levels.
88     * Dump keyboard microcontrollers.
89 */
90 
91 #include "emu.h"
92 #include "sunkbd.h"
93 
94 
95 DEFINE_DEVICE_TYPE(SUNKBD_PORT, sun_keyboard_port_device, "sunkbd", "Sun Keyboard Port")
96 
97 
98 int const device_sun_keyboard_port_interface::START_BIT_COUNT;
99 int const device_sun_keyboard_port_interface::DATA_BIT_COUNT;
100 device_serial_interface::parity_t const device_sun_keyboard_port_interface::PARITY;
101 device_serial_interface::stop_bits_t const device_sun_keyboard_port_interface::STOP_BITS;
102 int const device_sun_keyboard_port_interface::BAUD;
103 
104 
105 
sun_keyboard_port_device(machine_config const & mconfig,char const * tag,device_t * owner,uint32_t clock)106 sun_keyboard_port_device::sun_keyboard_port_device(
107 		machine_config const &mconfig,
108 		char const *tag,
109 		device_t *owner,
110 		uint32_t clock)
111 	: sun_keyboard_port_device(mconfig, SUNKBD_PORT, tag, owner, clock)
112 {
113 }
114 
115 
sun_keyboard_port_device(machine_config const & mconfig,device_type type,char const * tag,device_t * owner,uint32_t clock)116 sun_keyboard_port_device::sun_keyboard_port_device(
117 		machine_config const &mconfig,
118 		device_type type,
119 		char const *tag,
120 		device_t *owner,
121 		uint32_t clock)
122 	: device_t(mconfig, type, tag, owner, clock)
123 	, device_single_card_slot_interface<device_sun_keyboard_port_interface>(mconfig, *this)
124 	, m_rxd(0)
125 	, m_rxd_handler(*this)
126 	, m_dev(nullptr)
127 {
128 }
129 
130 
~sun_keyboard_port_device()131 sun_keyboard_port_device::~sun_keyboard_port_device()
132 {
133 }
134 
135 
device_config_complete()136 void sun_keyboard_port_device::device_config_complete()
137 {
138 	m_dev = get_card_device();
139 }
140 
141 
device_resolve_objects()142 void sun_keyboard_port_device::device_resolve_objects()
143 {
144 	m_rxd_handler.resolve_safe();
145 }
146 
147 
device_start()148 void sun_keyboard_port_device::device_start()
149 {
150 	save_item(NAME(m_rxd));
151 
152 	m_rxd = 1;
153 
154 	m_rxd_handler(m_rxd);
155 }
156 
157 
WRITE_LINE_MEMBER(sun_keyboard_port_device::write_txd)158 WRITE_LINE_MEMBER( sun_keyboard_port_device::write_txd )
159 {
160 	if (m_dev)
161 		m_dev->input_txd(state);
162 }
163 
164 
165 
device_sun_keyboard_port_interface(machine_config const & mconfig,device_t & device)166 device_sun_keyboard_port_interface::device_sun_keyboard_port_interface(machine_config const &mconfig, device_t &device)
167 	: device_interface(device, "sunkbd")
168 	, m_port(dynamic_cast<sun_keyboard_port_device *>(device.owner()))
169 {
170 }
171 
172 
~device_sun_keyboard_port_interface()173 device_sun_keyboard_port_interface::~device_sun_keyboard_port_interface()
174 {
175 }
176 
177 
178 
179 #include "hlekbd.h"
180 
default_sun_keyboard_devices(device_slot_interface & device)181 void default_sun_keyboard_devices(device_slot_interface &device)
182 {
183 	device.option_add("type3hle",   SUN_TYPE3_HLE_KEYBOARD);
184 	device.option_add("type4hle",   SUN_TYPE4_HLE_KEYBOARD);
185 	device.option_add("type5hle",   SUN_TYPE5_HLE_KEYBOARD);
186 	device.option_add("type5gbhle", SUN_TYPE5_GB_HLE_KEYBOARD);
187 	device.option_add("type5sehle", SUN_TYPE5_SE_HLE_KEYBOARD);
188 	device.option_add("type5jphle", SUN_TYPE5_JP_HLE_KEYBOARD);
189 }
190