trunk/src/emu/bus/rs232/keyboard.c
| r29629 | r29630 | |
| 1 | 1 | /*************************************************************************** |
| 2 | | Generic ASCII Keyboard |
| 2 | Generic ASCII Serial Keyboard |
| 3 | 3 | |
| 4 | 4 | Use MCFG_SERIAL_KEYBOARD_ADD to attach this as a serial device to a terminal |
| 5 | 5 | or computer. |
| 6 | 6 | |
| 7 | | Use MCFG_ASCII_KEYBOARD_ADD to attach as a generic ascii input device in |
| 8 | | cases where either the driver isn't developed enough yet; or for testing; |
| 9 | | or for the case of a computer with an inbuilt (not serial) ascii keyboard. |
| 10 | 7 | |
| 11 | 8 | Example of usage in a driver. |
| 12 | 9 | |
| 13 | 10 | In MACHINE_CONFIG |
| 14 | | MCFG_ASCII_KEYBOARD_ADD(KEYBOARD_TAG, keyboard_intf) |
| 11 | MCFG_SERIAL_KEYBOARD_ADD(KEYBOARD_TAG, keyboard_intf, 0) |
| 12 | or |
| 13 | MCFG_SERIAL_KEYBOARD_ADD(KEYBOARD_TAG, keyboard_intf, initial_baud_rate) |
| 15 | 14 | |
| 15 | |
| 16 | 16 | In the code: |
| 17 | 17 | |
| 18 | 18 | WRITE8_MEMBER( xxx_state::kbd_put ) |
| r29629 | r29630 | |
| 25 | 25 | DEVCB_DRIVER_MEMBER(xxx_state, kbd_put) |
| 26 | 26 | }; |
| 27 | 27 | |
| 28 | If a baud_rate is specified, it will be the initial baud rate, with |
| 29 | 8 bits, no parity, 1 stop bit. However you can override this with the |
| 30 | config switches. (Note that the config switch will specify 9600 initially, |
| 31 | even though it isn't). |
| 32 | |
| 33 | If a baud_rate is not specified, the rate will be solely determined |
| 34 | by the config switches. (Default 9600 baud) |
| 35 | |
| 36 | |
| 28 | 37 | ***************************************************************************/ |
| 29 | 38 | |
| 30 | 39 | #include "keyboard.h" |
| r29629 | r29630 | |
| 96 | 105 | |
| 97 | 106 | void serial_keyboard_device::device_start() |
| 98 | 107 | { |
| 99 | | int baud = clock(); |
| 100 | | if(!baud) baud = 9600; |
| 108 | m_baud = clock(); |
| 101 | 109 | m_out_tx_func.resolve(m_out_tx_cb, *this); |
| 102 | 110 | m_timer = timer_alloc(); |
| 103 | | set_data_frame(1, 8, PARITY_NONE, STOP_BITS_1); |
| 104 | | set_tra_rate(baud); |
| 111 | |
| 112 | if (m_baud) |
| 113 | { |
| 114 | set_data_frame(1, 8, PARITY_NONE, STOP_BITS_1); |
| 115 | set_tra_rate(m_baud); |
| 116 | } |
| 105 | 117 | } |
| 106 | 118 | |
| 107 | 119 | INPUT_CHANGED_MEMBER(serial_keyboard_device::update_frame) |
| 108 | 120 | { |
| 121 | m_baud = 0; |
| 109 | 122 | reset(); |
| 110 | 123 | } |
| 111 | 124 | |
| r29629 | r29630 | |
| 118 | 131 | else |
| 119 | 132 | m_out_tx_func(m_rbit); |
| 120 | 133 | |
| 121 | | UINT8 val = m_io_term_frame->read(); |
| 122 | | set_tra_rate(rates[val & 0x0f]); |
| 134 | if (m_baud == 0) |
| 135 | { |
| 136 | UINT8 val = m_io_term_frame->read(); |
| 137 | set_tra_rate(rates[val & 0x0f]); |
| 123 | 138 | |
| 124 | | switch(val & 0x30) |
| 125 | | { |
| 126 | | case 0x10: |
| 127 | | set_data_frame(1, 7, PARITY_EVEN, STOP_BITS_1); |
| 128 | | break; |
| 129 | | case 0x00: |
| 130 | | default: |
| 131 | | set_data_frame(1, 8, PARITY_NONE, STOP_BITS_1); |
| 132 | | break; |
| 133 | | case 0x20: |
| 134 | | set_data_frame(1, 8, PARITY_NONE, STOP_BITS_2); |
| 135 | | break; |
| 136 | | case 0x30: |
| 137 | | set_data_frame(1, 8, PARITY_EVEN, STOP_BITS_1); |
| 138 | | break; |
| 139 | switch(val & 0x30) |
| 140 | { |
| 141 | case 0x10: |
| 142 | set_data_frame(1, 7, PARITY_EVEN, STOP_BITS_1); |
| 143 | break; |
| 144 | case 0x00: |
| 145 | default: |
| 146 | set_data_frame(1, 8, PARITY_NONE, STOP_BITS_1); |
| 147 | break; |
| 148 | case 0x20: |
| 149 | set_data_frame(1, 8, PARITY_NONE, STOP_BITS_2); |
| 150 | break; |
| 151 | case 0x30: |
| 152 | set_data_frame(1, 8, PARITY_EVEN, STOP_BITS_1); |
| 153 | break; |
| 154 | } |
| 139 | 155 | } |
| 140 | 156 | } |
| 141 | 157 | |