1 // license:BSD-3-Clause 2 // copyright-holders:Vas Crabb 3 #ifndef MAME_DEVICES_SUNKBD_HLEKBD_H 4 #define MAME_DEVICES_SUNKBD_HLEKBD_H 5 6 #pragma once 7 8 #include "sunkbd.h" 9 #include "machine/keyboard.h" 10 #include "sound/beep.h" 11 #include "diserial.h" 12 13 14 namespace bus { namespace sunkbd { 15 16 class hle_device_base 17 : public device_t 18 , public device_buffered_serial_interface<16U> 19 , public device_sun_keyboard_port_interface 20 , protected device_matrix_keyboard_interface<8U> 21 { 22 public: 23 virtual ~hle_device_base() override; 24 25 virtual DECLARE_WRITE_LINE_MEMBER( input_txd ) override; 26 27 protected: 28 // constructor/destructor 29 hle_device_base( 30 machine_config const &mconfig, 31 device_type type, 32 char const *tag, 33 device_t *owner, 34 uint32_t clock); 35 36 // device overrides 37 virtual void device_add_mconfig(machine_config &config) override; 38 virtual void device_start() override; 39 virtual void device_reset() override; 40 virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; 41 42 // device_buffered_serial_interface overrides 43 virtual void tra_callback() override; 44 virtual void tra_complete() override; 45 46 // device_matrix_keyboard_interface overrides 47 virtual void key_make(uint8_t row, uint8_t column) override; 48 virtual void key_break(uint8_t row, uint8_t column) override; 49 50 // customised transmit_byte method 51 void transmit_byte(uint8_t byte); 52 53 required_ioport m_dips; 54 55 private: 56 enum { 57 CLICK_TIMER_ID = 30'000 58 }; 59 60 // TODO: ensure these don't clash with diagnostic LEDs on host computer 61 enum : int { 62 LED_NUM = 0, 63 LED_COMPOSE, 64 LED_SCROLL, 65 LED_CAPS, 66 LED_KANA 67 }; 68 69 enum : uint8_t { 70 BEEPER_BELL = 0x01U, 71 BEEPER_CLICK = 0x02U 72 }; 73 74 enum : uint8_t { 75 RX_IDLE, 76 RX_LED 77 }; 78 79 enum : uint8_t { 80 COMMAND_RESET = 0x01U, 81 COMMAND_BELL_ON = 0x02U, 82 COMMAND_BELL_OFF = 0x03U, 83 COMMAND_CLICK_ON = 0x0aU, 84 COMMAND_CLICK_OFF = 0x0bU, 85 COMMAND_LED = 0x0eU, 86 COMMAND_LAYOUT = 0x0fU 87 }; 88 89 // device_buffered_serial_interface overrides 90 virtual void received_byte(uint8_t byte) override; 91 92 virtual uint8_t ident_byte() = 0; 93 94 emu_timer *m_click_timer; 95 required_device<beep_device> m_beeper; 96 output_finder<5> m_leds; 97 98 uint8_t m_make_count; 99 uint8_t m_rx_state; 100 101 uint8_t m_keyclick; 102 uint8_t m_beeper_state; 103 }; 104 105 106 class hle_type4_device_base : public hle_device_base 107 { 108 protected: 109 using hle_device_base::hle_device_base; 110 111 private: 112 virtual uint8_t ident_byte() override; 113 }; 114 115 116 class hle_type3_device : public hle_device_base 117 { 118 public: 119 hle_type3_device( 120 machine_config const &mconfig, 121 char const *tag, 122 device_t *owner, 123 uint32_t clock); 124 125 protected: 126 virtual ioport_constructor device_input_ports() const override; 127 128 private: 129 virtual uint8_t ident_byte() override; 130 }; 131 132 133 class hle_type4_device : public hle_type4_device_base 134 { 135 public: 136 hle_type4_device( 137 machine_config const &mconfig, 138 char const *tag, 139 device_t *owner, 140 uint32_t clock); 141 142 protected: 143 virtual ioport_constructor device_input_ports() const override; 144 }; 145 146 147 class hle_type5_device : public hle_type4_device_base 148 { 149 public: 150 hle_type5_device( 151 machine_config const &mconfig, 152 char const *tag, 153 device_t *owner, 154 uint32_t clock); 155 156 protected: 157 virtual ioport_constructor device_input_ports() const override; 158 }; 159 160 161 class hle_type5_gb_device : public hle_type4_device_base 162 { 163 public: 164 hle_type5_gb_device( 165 machine_config const &mconfig, 166 char const *tag, 167 device_t *owner, 168 uint32_t clock); 169 170 protected: 171 virtual ioport_constructor device_input_ports() const override; 172 }; 173 174 175 class hle_type5_se_device : public hle_type4_device_base 176 { 177 public: 178 hle_type5_se_device( 179 machine_config const &mconfig, 180 char const *tag, 181 device_t *owner, 182 uint32_t clock); 183 184 protected: 185 virtual ioport_constructor device_input_ports() const override; 186 }; 187 188 189 class hle_type5_jp_device : public hle_type4_device_base 190 { 191 public: 192 hle_type5_jp_device( 193 machine_config const &mconfig, 194 char const *tag, 195 device_t *owner, 196 uint32_t clock); 197 198 protected: 199 virtual ioport_constructor device_input_ports() const override; 200 }; 201 202 } } // namespace bus::sunkbd 203 204 205 DECLARE_DEVICE_TYPE_NS(SUN_TYPE3_HLE_KEYBOARD, bus::sunkbd, hle_type3_device) 206 DECLARE_DEVICE_TYPE_NS(SUN_TYPE4_HLE_KEYBOARD, bus::sunkbd, hle_type4_device) 207 DECLARE_DEVICE_TYPE_NS(SUN_TYPE5_HLE_KEYBOARD, bus::sunkbd, hle_type5_device) 208 DECLARE_DEVICE_TYPE_NS(SUN_TYPE5_GB_HLE_KEYBOARD, bus::sunkbd, hle_type5_gb_device) 209 DECLARE_DEVICE_TYPE_NS(SUN_TYPE5_SE_HLE_KEYBOARD, bus::sunkbd, hle_type5_se_device) 210 DECLARE_DEVICE_TYPE_NS(SUN_TYPE5_JP_HLE_KEYBOARD, bus::sunkbd, hle_type5_jp_device) 211 212 #endif // MAME_DEVICES_SUNKBD_HLEKBD_H 213