src/mess/includes/serial.h
| r6086 | r6087 | |
| 1 | | /***************************************************************************** |
| 2 | | * |
| 3 | | * includes/serial.h |
| 4 | | * |
| 5 | | * internal serial transmission |
| 6 | | * |
| 7 | | * This code is used to transmit a file stored on the host filesystem |
| 8 | | * (e.g. PC harddrive) to an emulated system. |
| 9 | | * |
| 10 | | * The file is converted into a serial bit-stream which can be received |
| 11 | | * by the emulated serial chip in the emulated system. |
| 12 | | * |
| 13 | | * The file can be transmitted using different protocols. |
| 14 | | * |
| 15 | | * A and B are two computers linked with a serial connection |
| 16 | | * A and B can transmit and receive data, through the same connection |
| 17 | | * |
| 18 | | * These flags apply to A and B, and give the state of the input & output |
| 19 | | * signals at each side. |
| 20 | | * |
| 21 | | ****************************************************************************/ |
| 22 | | |
| 23 | | #ifndef SERIAL_H_ |
| 24 | | #define SERIAL_H_ |
| 25 | | |
| 26 | | |
| 27 | | /* |
| 28 | | CTS = Clear to Send. (INPUT) |
| 29 | | Other end of connection is ready to accept data |
| 30 | | |
| 31 | | |
| 32 | | NOTE: |
| 33 | | |
| 34 | | This output is active low on serial chips (e.g. 0 is CTS is set), |
| 35 | | but here it is active high! |
| 36 | | */ |
| 37 | | #define SERIAL_STATE_CTS 0x0001 |
| 38 | | |
| 39 | | /* |
| 40 | | RTS = Request to Send. (OUTPUT) |
| 41 | | This end is ready to send data, and requests if the other |
| 42 | | end is ready to accept it |
| 43 | | |
| 44 | | NOTE: |
| 45 | | |
| 46 | | This output is active low on serial chips (e.g. 0 is RTS is set), |
| 47 | | but here it is active high! |
| 48 | | */ |
| 49 | | #define SERIAL_STATE_RTS 0x0002 |
| 50 | | |
| 51 | | /* |
| 52 | | DSR = Data Set ready. (INPUT) |
| 53 | | Other end of connection has data |
| 54 | | |
| 55 | | |
| 56 | | NOTE: |
| 57 | | |
| 58 | | This output is active low on serial chips (e.g. 0 is DSR is set), |
| 59 | | but here it is active high! |
| 60 | | */ |
| 61 | | #define SERIAL_STATE_DSR 0x0004 |
| 62 | | |
| 63 | | /* |
| 64 | | DTR = Data terminal Ready. (OUTPUT) |
| 65 | | TX contains new data. |
| 66 | | |
| 67 | | NOTE: |
| 68 | | |
| 69 | | This output is active low on serial chips (e.g. 0 is DTR is set), |
| 70 | | but here it is active high! |
| 71 | | */ |
| 72 | | #define SERIAL_STATE_DTR 0x0008 |
| 73 | | /* RX = Recieve data. (INPUT) */ |
| 74 | | #define SERIAL_STATE_RX_DATA 0x00010 |
| 75 | | /* TX = Transmit data. (OUTPUT) */ |
| 76 | | #define SERIAL_STATE_TX_DATA 0x00020 |
| 77 | | |
| 78 | | /* protocol selections */ |
| 79 | | |
| 80 | | /* all data is transmitted with a start bit, data bits, optional parity bit, |
| 81 | | and stop bits. These are programmable. */ |
| 82 | | enum |
| 83 | | { |
| 84 | | SERIAL_PROTOCOL_NONE, /* no protocol applied */ |
| 85 | | SERIAL_PROTOCOL_XMODEM /* transfer data using xmodem protocol */ |
| 86 | | }; |
| 87 | | |
| 88 | | /* parity selections */ |
| 89 | | /* if all the bits are added in a byte, if the result is: |
| 90 | | even -> parity is even |
| 91 | | odd -> parity is odd |
| 92 | | */ |
| 93 | | enum |
| 94 | | { |
| 95 | | SERIAL_PARITY_NONE, /* no parity. a parity bit will not be in the transmitted/received data */ |
| 96 | | SERIAL_PARITY_ODD, /* odd parity */ |
| 97 | | SERIAL_PARITY_EVEN /* even parity */ |
| 98 | | }; |
| 99 | | |
| 100 | | /* this macro is used to extract the received data from the status */ |
| 101 | | #define get_in_data_bit(x) ((x & SERIAL_STATE_RX_DATA)>>4) |
| 102 | | |
| 103 | | /* this macro is used to set the transmitted data in the status */ |
| 104 | | #define set_out_data_bit(x, data) \ |
| 105 | | x&=~SERIAL_STATE_TX_DATA; \ |
| 106 | | x|=(data<<5) |
| 107 | | |
| 108 | | |
| 109 | | /*******************************************************************************/ |
| 110 | | /**** SERIAL CONNECTION ***/ |
| 111 | | |
| 112 | | |
| 113 | | /* this structure represents a serial connection */ |
| 114 | | struct serial_connection |
| 115 | | { |
| 116 | | int id; |
| 117 | | |
| 118 | | /* state of this side */ |
| 119 | | unsigned long State; |
| 120 | | |
| 121 | | /* state of other side - store here */ |
| 122 | | unsigned long input_state; |
| 123 | | |
| 124 | | /* this callback is executed when this side has refreshed it's state, |
| 125 | | to let the other end know */ |
| 126 | | void (*out_callback)(running_machine *machine, int id, unsigned long state); |
| 127 | | /* this callback is executed when the other side has refreshed it's state, |
| 128 | | to let the other end know */ |
| 129 | | void (*in_callback)(running_machine *machine, int id, unsigned long state); |
| 130 | | }; |
| 131 | | |
| 132 | | /*----------- defined in machine/serial.c -----------*/ |
| 133 | | |
| 134 | | /* setup out and in callbacks */ |
| 135 | | void serial_connection_init(running_machine *machine, struct serial_connection *connection); |
| 136 | | |
| 137 | | /* set callback which will be executed when out status has changed */ |
| 138 | | void serial_connection_set_out_callback(running_machine *machine, struct serial_connection *connection, void (*out_cb)(running_machine *machine, int id, unsigned long state)); |
| 139 | | |
| 140 | | /* set callback which will be executed when in status has changed */ |
| 141 | | void serial_connection_set_in_callback(running_machine *machine, struct serial_connection *connection, void (*in_cb)(running_machine *machine, int id, unsigned long state)); |
| 142 | | |
| 143 | | /* output status, if callback is setup it will be executed with the new status */ |
| 144 | | void serial_connection_out(running_machine *machine, struct serial_connection *connection); |
| 145 | | |
| 146 | | /* join two serial connections */ |
| 147 | | void serial_connection_link(running_machine *machine, struct serial_connection *connection_a, struct serial_connection *connection_b); |
| 148 | | |
| 149 | | |
| 150 | | /*******************************************************************************/ |
| 151 | | |
| 152 | | /* form of data being transmitted and received */ |
| 153 | | struct data_form |
| 154 | | { |
| 155 | | /* length of word in bits */ |
| 156 | | unsigned long word_length; |
| 157 | | /* parity state */ |
| 158 | | unsigned long parity; |
| 159 | | /* number of stop bits */ |
| 160 | | unsigned long stop_bit_count; |
| 161 | | }; |
| 162 | | |
| 163 | | /*******************************************************************************/ |
| 164 | | |
| 165 | | /*******************************************************************************/ |
| 166 | | /**** RECEIVE AND TRANSMIT GENERIC CODE ****/ |
| 167 | | |
| 168 | | /* this can be used by most of the serial chip implementations, |
| 169 | | because they all work in roughly the same way. |
| 170 | | There is generic code to send and receive data in the specified form */ |
| 171 | | |
| 172 | | /* receive is waiting for start bit. The transition from high-low indicates |
| 173 | | start of start bit. This is used to synchronise with the data being transfered */ |
| 174 | | #define RECEIVE_REGISTER_WAITING_FOR_START_BIT 0x01 |
| 175 | | /* receive is synchronised with data, data bits will be clocked in */ |
| 176 | | #define RECEIVE_REGISTER_SYNCHRONISED 0x02 |
| 177 | | /* set if receive register has been filled */ |
| 178 | | #define RECEIVE_REGISTER_FULL 0x04 |
| 179 | | |
| 180 | | |
| 181 | | /* the receive register holds data in receive form! */ |
| 182 | | /* this must be extracted to get the data byte received */ |
| 183 | | struct serial_receive_register |
| 184 | | { |
| 185 | | /* data */ |
| 186 | | unsigned long register_data; |
| 187 | | /* flags */ |
| 188 | | unsigned long flags; |
| 189 | | /* bit count received */ |
| 190 | | unsigned long bit_count_received; |
| 191 | | /* length of data to receive - includes data bits, parity bit and stop bit */ |
| 192 | | unsigned long bit_count; |
| 193 | | |
| 194 | | /* the byte of data received */ |
| 195 | | unsigned char byte_received; |
| 196 | | }; |
| 197 | | |
| 198 | | void receive_register_setup(struct serial_receive_register *receive, struct data_form *data_form); |
| 199 | | void receive_register_update_bit(struct serial_receive_register *receive, int bit_state); |
| 200 | | void receive_register_extract(struct serial_receive_register *receive_reg, struct data_form *data_form); |
| 201 | | void receive_register_reset(struct serial_receive_register *receive_reg); |
| 202 | | |
| 203 | | /* the transmit register is the final stage |
| 204 | | in the serial transmit procedure */ |
| 205 | | /* normally, data is written to the transmit reg, |
| 206 | | then it is assembled into transmit form and transmitted */ |
| 207 | | /* the transmit register holds data in transmit form */ |
| 208 | | |
| 209 | | /* register is empty and ready to be filled with data */ |
| 210 | | #define TRANSMIT_REGISTER_EMPTY 0x0001 |
| 211 | | |
| 212 | | struct serial_transmit_register |
| 213 | | { |
| 214 | | /* data */ |
| 215 | | unsigned long register_data; |
| 216 | | /* flags */ |
| 217 | | unsigned long flags; |
| 218 | | /* number of bits transmitted */ |
| 219 | | unsigned long bit_count_transmitted; |
| 220 | | /* length of data to send */ |
| 221 | | unsigned long bit_count; |
| 222 | | }; |
| 223 | | |
| 224 | | /* get a bit from the transmit register */ |
| 225 | | int transmit_register_get_data_bit(struct serial_transmit_register *transmit_reg); |
| 226 | | /* setup transmit reg ready for transmit */ |
| 227 | | void transmit_register_setup(struct serial_transmit_register *transmit_reg, struct data_form *data_form,unsigned char data_byte); |
| 228 | | void transmit_register_send_bit(running_machine *machine, struct serial_transmit_register *transmit_reg, struct serial_connection *connection); |
| 229 | | void transmit_register_reset(struct serial_transmit_register *transmit_reg); |
| 230 | | |
| 231 | | /*******************************************************************************/ |
| 232 | | /**** SERIAL HELPER ****/ |
| 233 | | |
| 234 | | void serial_helper_setup(void); |
| 235 | | unsigned char serial_helper_get_parity(unsigned char data); |
| 236 | | |
| 237 | | /*******************************************************************************/ |
| 238 | | /**** SERIAL DEVICE ****/ |
| 239 | | |
| 240 | | /* a read/write bit stream. used to transmit data and to receive data */ |
| 241 | | struct data_stream |
| 242 | | { |
| 243 | | /* pointer to buffer */ |
| 244 | | unsigned char *pData; |
| 245 | | /* length of buffer */ |
| 246 | | unsigned long DataLength; |
| 247 | | |
| 248 | | /* bit offset within current byte */ |
| 249 | | unsigned long BitCount; |
| 250 | | /* byte offset within data */ |
| 251 | | unsigned long ByteCount; |
| 252 | | }; |
| 253 | | |
| 254 | | /* an internal interface used by serial device */ |
| 255 | | struct serial_protocol_interface |
| 256 | | { |
| 257 | | /* callback executed when character has been received */ |
| 258 | | void (*character_received_callback)(int id,unsigned char ch); |
| 259 | | /* callback executed when character has been transmitted, ready to transmit a new char */ |
| 260 | | void (*character_sent_callback)(int id); |
| 261 | | }; |
| 262 | | |
| 263 | | /* a serial device */ |
| 264 | | struct serial_device |
| 265 | | { |
| 266 | | /* transmit data bit-stream */ |
| 267 | | struct data_stream transmit; |
| 268 | | /* receive data bit-stream */ |
| 269 | | struct data_stream receive; |
| 270 | | |
| 271 | | /* register to receive data */ |
| 272 | | struct serial_receive_register receive_reg; |
| 273 | | /* register to transmit data */ |
| 274 | | struct serial_transmit_register transmit_reg; |
| 275 | | |
| 276 | | /* connection to transmit/receive data over */ |
| 277 | | struct serial_connection connection; |
| 278 | | |
| 279 | | /* data form to transmit/receive */ |
| 280 | | struct data_form data_form; |
| 281 | | |
| 282 | | int transmit_state; |
| 283 | | int protocol; |
| 284 | | |
| 285 | | /* baud rate */ |
| 286 | | unsigned long BaudRate; |
| 287 | | |
| 288 | | /* baud rate timer */ |
| 289 | | void *timer; |
| 290 | | |
| 291 | | struct serial_protocol_interface protocol_interface; |
| 292 | | }; |
| 293 | | |
| 294 | | unsigned long serial_device_get_state(int id); |
| 295 | | |
| 296 | | /* connect this device to the emulated serial chip */ |
| 297 | | /* id is the serial device to connect to */ |
| 298 | | /* connection is the serial connection to connect to the serial device */ |
| 299 | | void serial_device_connect(const device_config *image, struct serial_connection *connection); |
| 300 | | |
| 301 | | /* init this device */ |
| 302 | | DEVICE_START(serial_device); |
| 303 | | DEVICE_IMAGE_LOAD(serial_device); |
| 304 | | DEVICE_IMAGE_UNLOAD(serial_device); |
| 305 | | |
| 306 | | void serial_device_setup(const device_config *image, int baud_rate, int num_data_bits, int stop_bit_count, int parity_code); |
| 307 | | |
| 308 | | /* get name of protocol identified by specified id */ |
| 309 | | const char *serial_device_get_protocol_name(int protocol_id); |
| 310 | | |
| 311 | | /* set the protocol to be used by the serial device */ |
| 312 | | void serial_device_set_protocol(const device_config *image, int protocol_id); |
| 313 | | /* set the transmit state of the serial device */ |
| 314 | | void serial_device_set_transmit_state(const device_config *image, int state); |
| 315 | | |
| 316 | | /***********************************************************************************************/ |
| 317 | | /* XModem protocol */ |
| 318 | | |
| 319 | | #define XMODEM_CRC_NAK 67 /* begins a xmodem-crc transfer */ |
| 320 | | #define XMODEM_SOH 1 /* id of a 256 byte block */ |
| 321 | | #define XMODEM_EOT 4 |
| 322 | | #define XMODEM_ACK 6 |
| 323 | | #define XMODEM_NAK 21 /* begins a xmodem transfer */ |
| 324 | | #define XMODEM_CAN 24 |
| 325 | | #define XMODEM_STX 2 /* id start of a 1k block */ |
| 326 | | |
| 327 | | |
| 328 | | #endif /* SERIAL_H_ */ |
src/mess/machine/serial.h
| r0 | r6087 | |
| 1 | /***************************************************************************** |
| 2 | * |
| 3 | * machine/serial.h |
| 4 | * |
| 5 | * internal serial transmission |
| 6 | * |
| 7 | * This code is used to transmit a file stored on the host filesystem |
| 8 | * (e.g. PC harddrive) to an emulated system. |
| 9 | * |
| 10 | * The file is converted into a serial bit-stream which can be received |
| 11 | * by the emulated serial chip in the emulated system. |
| 12 | * |
| 13 | * The file can be transmitted using different protocols. |
| 14 | * |
| 15 | * A and B are two computers linked with a serial connection |
| 16 | * A and B can transmit and receive data, through the same connection |
| 17 | * |
| 18 | * These flags apply to A and B, and give the state of the input & output |
| 19 | * signals at each side. |
| 20 | * |
| 21 | ****************************************************************************/ |
| 22 | |
| 23 | #ifndef SERIAL_H_ |
| 24 | #define SERIAL_H_ |
| 25 | |
| 26 | |
| 27 | /* |
| 28 | CTS = Clear to Send. (INPUT) |
| 29 | Other end of connection is ready to accept data |
| 30 | |
| 31 | |
| 32 | NOTE: |
| 33 | |
| 34 | This output is active low on serial chips (e.g. 0 is CTS is set), |
| 35 | but here it is active high! |
| 36 | */ |
| 37 | #define SERIAL_STATE_CTS 0x0001 |
| 38 | |
| 39 | /* |
| 40 | RTS = Request to Send. (OUTPUT) |
| 41 | This end is ready to send data, and requests if the other |
| 42 | end is ready to accept it |
| 43 | |
| 44 | NOTE: |
| 45 | |
| 46 | This output is active low on serial chips (e.g. 0 is RTS is set), |
| 47 | but here it is active high! |
| 48 | */ |
| 49 | #define SERIAL_STATE_RTS 0x0002 |
| 50 | |
| 51 | /* |
| 52 | DSR = Data Set ready. (INPUT) |
| 53 | Other end of connection has data |
| 54 | |
| 55 | |
| 56 | NOTE: |
| 57 | |
| 58 | This output is active low on serial chips (e.g. 0 is DSR is set), |
| 59 | but here it is active high! |
| 60 | */ |
| 61 | #define SERIAL_STATE_DSR 0x0004 |
| 62 | |
| 63 | /* |
| 64 | DTR = Data terminal Ready. (OUTPUT) |
| 65 | TX contains new data. |
| 66 | |
| 67 | NOTE: |
| 68 | |
| 69 | This output is active low on serial chips (e.g. 0 is DTR is set), |
| 70 | but here it is active high! |
| 71 | */ |
| 72 | #define SERIAL_STATE_DTR 0x0008 |
| 73 | /* RX = Recieve data. (INPUT) */ |
| 74 | #define SERIAL_STATE_RX_DATA 0x00010 |
| 75 | /* TX = Transmit data. (OUTPUT) */ |
| 76 | #define SERIAL_STATE_TX_DATA 0x00020 |
| 77 | |
| 78 | /* protocol selections */ |
| 79 | |
| 80 | /* all data is transmitted with a start bit, data bits, optional parity bit, |
| 81 | and stop bits. These are programmable. */ |
| 82 | enum |
| 83 | { |
| 84 | SERIAL_PROTOCOL_NONE, /* no protocol applied */ |
| 85 | SERIAL_PROTOCOL_XMODEM /* transfer data using xmodem protocol */ |
| 86 | }; |
| 87 | |
| 88 | /* parity selections */ |
| 89 | /* if all the bits are added in a byte, if the result is: |
| 90 | even -> parity is even |
| 91 | odd -> parity is odd |
| 92 | */ |
| 93 | enum |
| 94 | { |
| 95 | SERIAL_PARITY_NONE, /* no parity. a parity bit will not be in the transmitted/received data */ |
| 96 | SERIAL_PARITY_ODD, /* odd parity */ |
| 97 | SERIAL_PARITY_EVEN /* even parity */ |
| 98 | }; |
| 99 | |
| 100 | /* this macro is used to extract the received data from the status */ |
| 101 | #define get_in_data_bit(x) ((x & SERIAL_STATE_RX_DATA)>>4) |
| 102 | |
| 103 | /* this macro is used to set the transmitted data in the status */ |
| 104 | #define set_out_data_bit(x, data) \ |
| 105 | x&=~SERIAL_STATE_TX_DATA; \ |
| 106 | x|=(data<<5) |
| 107 | |
| 108 | |
| 109 | /*******************************************************************************/ |
| 110 | /**** SERIAL CONNECTION ***/ |
| 111 | |
| 112 | |
| 113 | /* this structure represents a serial connection */ |
| 114 | struct serial_connection |
| 115 | { |
| 116 | int id; |
| 117 | |
| 118 | /* state of this side */ |
| 119 | unsigned long State; |
| 120 | |
| 121 | /* state of other side - store here */ |
| 122 | unsigned long input_state; |
| 123 | |
| 124 | /* this callback is executed when this side has refreshed it's state, |
| 125 | to let the other end know */ |
| 126 | void (*out_callback)(running_machine *machine, int id, unsigned long state); |
| 127 | /* this callback is executed when the other side has refreshed it's state, |
| 128 | to let the other end know */ |
| 129 | void (*in_callback)(running_machine *machine, int id, unsigned long state); |
| 130 | }; |
| 131 | |
| 132 | /*----------- defined in machine/serial.c -----------*/ |
| 133 | |
| 134 | /* setup out and in callbacks */ |
| 135 | void serial_connection_init(running_machine *machine, struct serial_connection *connection); |
| 136 | |
| 137 | /* set callback which will be executed when out status has changed */ |
| 138 | void serial_connection_set_out_callback(running_machine *machine, struct serial_connection *connection, void (*out_cb)(running_machine *machine, int id, unsigned long state)); |
| 139 | |
| 140 | /* set callback which will be executed when in status has changed */ |
| 141 | void serial_connection_set_in_callback(running_machine *machine, struct serial_connection *connection, void (*in_cb)(running_machine *machine, int id, unsigned long state)); |
| 142 | |
| 143 | /* output status, if callback is setup it will be executed with the new status */ |
| 144 | void serial_connection_out(running_machine *machine, struct serial_connection *connection); |
| 145 | |
| 146 | /* join two serial connections */ |
| 147 | void serial_connection_link(running_machine *machine, struct serial_connection *connection_a, struct serial_connection *connection_b); |
| 148 | |
| 149 | |
| 150 | /*******************************************************************************/ |
| 151 | |
| 152 | /* form of data being transmitted and received */ |
| 153 | struct data_form |
| 154 | { |
| 155 | /* length of word in bits */ |
| 156 | unsigned long word_length; |
| 157 | /* parity state */ |
| 158 | unsigned long parity; |
| 159 | /* number of stop bits */ |
| 160 | unsigned long stop_bit_count; |
| 161 | }; |
| 162 | |
| 163 | /*******************************************************************************/ |
| 164 | |
| 165 | /*******************************************************************************/ |
| 166 | /**** RECEIVE AND TRANSMIT GENERIC CODE ****/ |
| 167 | |
| 168 | /* this can be used by most of the serial chip implementations, |
| 169 | because they all work in roughly the same way. |
| 170 | There is generic code to send and receive data in the specified form */ |
| 171 | |
| 172 | /* receive is waiting for start bit. The transition from high-low indicates |
| 173 | start of start bit. This is used to synchronise with the data being transfered */ |
| 174 | #define RECEIVE_REGISTER_WAITING_FOR_START_BIT 0x01 |
| 175 | /* receive is synchronised with data, data bits will be clocked in */ |
| 176 | #define RECEIVE_REGISTER_SYNCHRONISED 0x02 |
| 177 | /* set if receive register has been filled */ |
| 178 | #define RECEIVE_REGISTER_FULL 0x04 |
| 179 | |
| 180 | |
| 181 | /* the receive register holds data in receive form! */ |
| 182 | /* this must be extracted to get the data byte received */ |
| 183 | struct serial_receive_register |
| 184 | { |
| 185 | /* data */ |
| 186 | unsigned long register_data; |
| 187 | /* flags */ |
| 188 | unsigned long flags; |
| 189 | /* bit count received */ |
| 190 | unsigned long bit_count_received; |
| 191 | /* length of data to receive - includes data bits, parity bit and stop bit */ |
| 192 | unsigned long bit_count; |
| 193 | |
| 194 | /* the byte of data received */ |
| 195 | unsigned char byte_received; |
| 196 | }; |
| 197 | |
| 198 | void receive_register_setup(struct serial_receive_register *receive, struct data_form *data_form); |
| 199 | void receive_register_update_bit(struct serial_receive_register *receive, int bit_state); |
| 200 | void receive_register_extract(struct serial_receive_register *receive_reg, struct data_form *data_form); |
| 201 | void receive_register_reset(struct serial_receive_register *receive_reg); |
| 202 | |
| 203 | /* the transmit register is the final stage |
| 204 | in the serial transmit procedure */ |
| 205 | /* normally, data is written to the transmit reg, |
| 206 | then it is assembled into transmit form and transmitted */ |
| 207 | /* the transmit register holds data in transmit form */ |
| 208 | |
| 209 | /* register is empty and ready to be filled with data */ |
| 210 | #define TRANSMIT_REGISTER_EMPTY 0x0001 |
| 211 | |
| 212 | struct serial_transmit_register |
| 213 | { |
| 214 | /* data */ |
| 215 | unsigned long register_data; |
| 216 | /* flags */ |
| 217 | unsigned long flags; |
| 218 | /* number of bits transmitted */ |
| 219 | unsigned long bit_count_transmitted; |
| 220 | /* length of data to send */ |
| 221 | unsigned long bit_count; |
| 222 | }; |
| 223 | |
| 224 | /* get a bit from the transmit register */ |
| 225 | int transmit_register_get_data_bit(struct serial_transmit_register *transmit_reg); |
| 226 | /* setup transmit reg ready for transmit */ |
| 227 | void transmit_register_setup(struct serial_transmit_register *transmit_reg, struct data_form *data_form,unsigned char data_byte); |
| 228 | void transmit_register_send_bit(running_machine *machine, struct serial_transmit_register *transmit_reg, struct serial_connection *connection); |
| 229 | void transmit_register_reset(struct serial_transmit_register *transmit_reg); |
| 230 | |
| 231 | /*******************************************************************************/ |
| 232 | /**** SERIAL HELPER ****/ |
| 233 | |
| 234 | void serial_helper_setup(void); |
| 235 | unsigned char serial_helper_get_parity(unsigned char data); |
| 236 | |
| 237 | /*******************************************************************************/ |
| 238 | /**** SERIAL DEVICE ****/ |
| 239 | |
| 240 | /* a read/write bit stream. used to transmit data and to receive data */ |
| 241 | struct data_stream |
| 242 | { |
| 243 | /* pointer to buffer */ |
| 244 | unsigned char *pData; |
| 245 | /* length of buffer */ |
| 246 | unsigned long DataLength; |
| 247 | |
| 248 | /* bit offset within current byte */ |
| 249 | unsigned long BitCount; |
| 250 | /* byte offset within data */ |
| 251 | unsigned long ByteCount; |
| 252 | }; |
| 253 | |
| 254 | /* an internal interface used by serial device */ |
| 255 | struct serial_protocol_interface |
| 256 | { |
| 257 | /* callback executed when character has been received */ |
| 258 | void (*character_received_callback)(int id,unsigned char ch); |
| 259 | /* callback executed when character has been transmitted, ready to transmit a new char */ |
| 260 | void (*character_sent_callback)(int id); |
| 261 | }; |
| 262 | |
| 263 | /* a serial device */ |
| 264 | struct serial_device |
| 265 | { |
| 266 | /* transmit data bit-stream */ |
| 267 | struct data_stream transmit; |
| 268 | /* receive data bit-stream */ |
| 269 | struct data_stream receive; |
| 270 | |
| 271 | /* register to receive data */ |
| 272 | struct serial_receive_register receive_reg; |
| 273 | /* register to transmit data */ |
| 274 | struct serial_transmit_register transmit_reg; |
| 275 | |
| 276 | /* connection to transmit/receive data over */ |
| 277 | struct serial_connection connection; |
| 278 | |
| 279 | /* data form to transmit/receive */ |
| 280 | struct data_form data_form; |
| 281 | |
| 282 | int transmit_state; |
| 283 | int protocol; |
| 284 | |
| 285 | /* baud rate */ |
| 286 | unsigned long BaudRate; |
| 287 | |
| 288 | /* baud rate timer */ |
| 289 | void *timer; |
| 290 | |
| 291 | struct serial_protocol_interface protocol_interface; |
| 292 | }; |
| 293 | |
| 294 | unsigned long serial_device_get_state(int id); |
| 295 | |
| 296 | /* connect this device to the emulated serial chip */ |
| 297 | /* id is the serial device to connect to */ |
| 298 | /* connection is the serial connection to connect to the serial device */ |
| 299 | void serial_device_connect(const device_config *image, struct serial_connection *connection); |
| 300 | |
| 301 | /* init this device */ |
| 302 | DEVICE_START(serial_device); |
| 303 | DEVICE_IMAGE_LOAD(serial_device); |
| 304 | DEVICE_IMAGE_UNLOAD(serial_device); |
| 305 | |
| 306 | void serial_device_setup(const device_config *image, int baud_rate, int num_data_bits, int stop_bit_count, int parity_code); |
| 307 | |
| 308 | /* get name of protocol identified by specified id */ |
| 309 | const char *serial_device_get_protocol_name(int protocol_id); |
| 310 | |
| 311 | /* set the protocol to be used by the serial device */ |
| 312 | void serial_device_set_protocol(const device_config *image, int protocol_id); |
| 313 | /* set the transmit state of the serial device */ |
| 314 | void serial_device_set_transmit_state(const device_config *image, int state); |
| 315 | |
| 316 | /***********************************************************************************************/ |
| 317 | /* XModem protocol */ |
| 318 | |
| 319 | #define XMODEM_CRC_NAK 67 /* begins a xmodem-crc transfer */ |
| 320 | #define XMODEM_SOH 1 /* id of a 256 byte block */ |
| 321 | #define XMODEM_EOT 4 |
| 322 | #define XMODEM_ACK 6 |
| 323 | #define XMODEM_NAK 21 /* begins a xmodem transfer */ |
| 324 | #define XMODEM_CAN 24 |
| 325 | #define XMODEM_STX 2 /* id start of a 1k block */ |
| 326 | |
| 327 | |
| 328 | #endif /* SERIAL_H_ */ |