src/mess/includes/serial.h
| r3904 | r3905 | |
| 123 | 123 | |
| 124 | 124 | /* this callback is executed when this side has refreshed it's state, |
| 125 | 125 | to let the other end know */ |
| 126 | | void (*out_callback)(int id, unsigned long state); |
| 126 | void (*out_callback)(running_machine *machine, int id, unsigned long state); |
| 127 | 127 | /* this callback is executed when the other side has refreshed it's state, |
| 128 | 128 | to let the other end know */ |
| 129 | | void (*in_callback)(int id, unsigned long state); |
| 129 | void (*in_callback)(running_machine *machine, int id, unsigned long state); |
| 130 | 130 | }; |
| 131 | 131 | |
| 132 | 132 | /*----------- defined in machine/serial.c -----------*/ |
| 133 | 133 | |
| 134 | 134 | /* setup out and in callbacks */ |
| 135 | | void serial_connection_init(struct serial_connection *connection); |
| 135 | void serial_connection_init(running_machine *machine, struct serial_connection *connection); |
| 136 | 136 | |
| 137 | 137 | /* set callback which will be executed when out status has changed */ |
| 138 | | void serial_connection_set_out_callback(struct serial_connection *connection, void (*out_cb)(int id, unsigned long state)); |
| 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 | 139 | |
| 140 | 140 | /* set callback which will be executed when in status has changed */ |
| 141 | | void serial_connection_set_in_callback(struct serial_connection *connection, void (*in_cb)(int id, unsigned long state)); |
| 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 | 142 | |
| 143 | 143 | /* output status, if callback is setup it will be executed with the new status */ |
| 144 | | void serial_connection_out(struct serial_connection *connection); |
| 144 | void serial_connection_out(running_machine *machine, struct serial_connection *connection); |
| 145 | 145 | |
| 146 | 146 | /* join two serial connections */ |
| 147 | | void serial_connection_link(struct serial_connection *connection_a, struct serial_connection *connection_b); |
| 147 | void serial_connection_link(running_machine *machine, struct serial_connection *connection_a, struct serial_connection *connection_b); |
| 148 | 148 | |
| 149 | 149 | |
| 150 | 150 | /*******************************************************************************/ |
| r3904 | r3905 | |
| 225 | 225 | int transmit_register_get_data_bit(struct serial_transmit_register *transmit_reg); |
| 226 | 226 | /* setup transmit reg ready for transmit */ |
| 227 | 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(struct serial_transmit_register *transmit_reg, struct serial_connection *connection); |
| 228 | void transmit_register_send_bit(running_machine *machine, struct serial_transmit_register *transmit_reg, struct serial_connection *connection); |
| 229 | 229 | void transmit_register_reset(struct serial_transmit_register *transmit_reg); |
| 230 | 230 | |
| 231 | 231 | /*******************************************************************************/ |
src/mess/machine/serial.c
| r3904 | r3905 | |
| 81 | 81 | return serial_parity_table[data & 0x0ff]; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | | static void serial_device_in_callback(int id, unsigned long status) |
| 84 | static void serial_device_in_callback(running_machine *machine, int id, unsigned long status) |
| 85 | 85 | { |
| 86 | 86 | serial_devices[id].connection.input_state = status; |
| 87 | 87 | } |
| r3904 | r3905 | |
| 124 | 124 | serial_devices[id].data_form.parity = parity_code; |
| 125 | 125 | serial_devices[id].timer = timer_alloc(image->machine, serial_device_baud_rate_callback, NULL); |
| 126 | 126 | |
| 127 | | serial_connection_init(&serial_devices[id].connection); |
| 128 | | serial_connection_set_in_callback(&serial_devices[id].connection, serial_device_in_callback); |
| 127 | serial_connection_init(image->machine, &serial_devices[id].connection); |
| 128 | serial_connection_set_in_callback(image->machine, &serial_devices[id].connection, serial_device_in_callback); |
| 129 | 129 | |
| 130 | 130 | /* signal to other end it is clear to send! */ |
| 131 | 131 | /* data is initially high state */ |
| r3904 | r3905 | |
| 135 | 135 | /* set /dtr */ |
| 136 | 136 | serial_devices[id].connection.State |= SERIAL_STATE_DTR; |
| 137 | 137 | set_out_data_bit(serial_devices[id].connection.State, 1); |
| 138 | | serial_connection_out(&serial_devices[id].connection); |
| 138 | serial_connection_out(image->machine,&serial_devices[id].connection); |
| 139 | 139 | transmit_register_reset(&serial_devices[id].transmit_reg); |
| 140 | 140 | receive_register_reset(&serial_devices[id].receive_reg); |
| 141 | 141 | receive_register_setup(&serial_devices[id].receive_reg, &serial_devices[id].data_form); |
| r3904 | r3905 | |
| 495 | 495 | return bit; |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | | void transmit_register_send_bit(struct serial_transmit_register *transmit_reg, struct serial_connection *connection) |
| 498 | void transmit_register_send_bit(running_machine *machine, struct serial_transmit_register *transmit_reg, struct serial_connection *connection) |
| 499 | 499 | { |
| 500 | 500 | int data; |
| 501 | 501 | |
| r3904 | r3905 | |
| 505 | 505 | set_out_data_bit(connection->State, data); |
| 506 | 506 | |
| 507 | 507 | /* state out through connection */ |
| 508 | | serial_connection_out(connection); |
| 508 | serial_connection_out(machine, connection); |
| 509 | 509 | } |
| 510 | 510 | |
| 511 | 511 | void serial_protocol_none_sent_char(int id) |
| r3904 | r3905 | |
| 559 | 559 | if (serial_devices[id].connection.input_state & SERIAL_STATE_CTS) |
| 560 | 560 | { |
| 561 | 561 | /* send bit */ |
| 562 | | transmit_register_send_bit(&serial_devices[id].transmit_reg, &serial_devices[id].connection); |
| 562 | transmit_register_send_bit(machine, &serial_devices[id].transmit_reg, &serial_devices[id].connection); |
| 563 | 563 | } |
| 564 | 564 | } |
| 565 | 565 | |
| r3904 | r3905 | |
| 572 | 572 | if ((id<0) || (id>=MAX_SERIAL_DEVICES)) |
| 573 | 573 | return; |
| 574 | 574 | |
| 575 | | serial_connection_link(connection, &serial_devices[id].connection); |
| 575 | serial_connection_link(image->machine, connection, &serial_devices[id].connection); |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | |
| r3904 | r3905 | |
| 906 | 906 | |
| 907 | 907 | |
| 908 | 908 | /* setup callbacks for connection */ |
| 909 | | void serial_connection_init(struct serial_connection *connection) |
| 909 | void serial_connection_init(running_machine *machine, struct serial_connection *connection) |
| 910 | 910 | { |
| 911 | 911 | connection->out_callback = NULL; |
| 912 | 912 | connection->in_callback = NULL; |
| 913 | 913 | } |
| 914 | 914 | |
| 915 | 915 | /* set callback which will be executed when out status has changed */ |
| 916 | | void serial_connection_set_out_callback(struct serial_connection *connection, void (*out_cb)(int id, unsigned long state)) |
| 916 | void serial_connection_set_out_callback(running_machine *machine, struct serial_connection *connection, void (*out_cb)(running_machine *machine, int id, unsigned long state)) |
| 917 | 917 | { |
| 918 | 918 | connection->out_callback = out_cb; |
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | /* set callback which will be executed when in status has changed */ |
| 922 | | void serial_connection_set_in_callback(struct serial_connection *connection, void (*in_cb)(int id, unsigned long state)) |
| 922 | void serial_connection_set_in_callback(running_machine *machine, struct serial_connection *connection, void (*in_cb)(running_machine *machine, int id, unsigned long state)) |
| 923 | 923 | { |
| 924 | 924 | connection->in_callback = in_cb; |
| 925 | 925 | } |
| 926 | 926 | |
| 927 | 927 | /* output new state through connection */ |
| 928 | | void serial_connection_out(struct serial_connection *connection) |
| 928 | void serial_connection_out(running_machine *machine, struct serial_connection *connection) |
| 929 | 929 | { |
| 930 | 930 | if (connection->out_callback!=NULL) |
| 931 | 931 | { |
| r3904 | r3905 | |
| 933 | 933 | |
| 934 | 934 | state_at_other_end = serial_connection_spin_bits(connection->State); |
| 935 | 935 | |
| 936 | | connection->out_callback(connection->id, state_at_other_end); |
| 936 | connection->out_callback(machine, connection->id, state_at_other_end); |
| 937 | 937 | } |
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | /* join two serial connections together */ |
| 941 | | void serial_connection_link(struct serial_connection *connection_a, struct serial_connection *connection_b) |
| 941 | void serial_connection_link(running_machine *machine, struct serial_connection *connection_a, struct serial_connection *connection_b) |
| 942 | 942 | { |
| 943 | 943 | /* both connections should have their in connection setup! */ |
| 944 | 944 | /* the in connection is the callback they use to update their state based |
| r3904 | r3905 | |
| 947 | 947 | connection_b->out_callback = connection_a->in_callback; |
| 948 | 948 | |
| 949 | 949 | /* let b know the state of a */ |
| 950 | | serial_connection_out(connection_a); |
| 950 | serial_connection_out(machine,connection_a); |
| 951 | 951 | /* let a know the state of b */ |
| 952 | | serial_connection_out(connection_b); |
| 952 | serial_connection_out(machine,connection_b); |
| 953 | 953 | } |
src/mess/machine/thomson.c
| r3904 | r3905 | |
| 770 | 770 | to7_io_line.State &= ~SERIAL_STATE_DTR; |
| 771 | 771 | |
| 772 | 772 | set_out_data_bit( to7_io_line.State, tx ); |
| 773 | | serial_connection_out( &to7_io_line ); |
| 773 | serial_connection_out( space->machine, &to7_io_line ); |
| 774 | 774 | } |
| 775 | 775 | |
| 776 | 776 | |
| r3904 | r3905 | |
| 815 | 815 | |
| 816 | 816 | |
| 817 | 817 | |
| 818 | | static void to7_io_in_cb ( int id, unsigned long state ) |
| 818 | static void to7_io_in_cb ( running_machine *machine, int id, unsigned long state ) |
| 819 | 819 | { |
| 820 | 820 | /* our peer's state has changed */ |
| 821 | 821 | to7_io_line.input_state = state; |
| 822 | 822 | |
| 823 | | //LOG_IO(( "%f to7_io_in_callback: cts=%i dsr=%i rd=%i\n", attotime_to_double(timer_get_time(machine)), (state & SERIAL_STATE_CTS) ? 1 : 0, (state & SERIAL_STATE_DSR) ? 1 : 0, (int)get_in_data_bit( state ) )); |
| 823 | LOG_IO(( "%f to7_io_in_callback: cts=%i dsr=%i rd=%i\n", attotime_to_double(timer_get_time(machine)), (state & SERIAL_STATE_CTS) ? 1 : 0, (state & SERIAL_STATE_DSR) ? 1 : 0, (int)get_in_data_bit( state ) )); |
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | |
| r3904 | r3905 | |
| 861 | 861 | to7_io_line.State &= ~SERIAL_STATE_DTR; |
| 862 | 862 | to7_io_line.State |= SERIAL_STATE_RTS; /* always ready to send */ |
| 863 | 863 | set_out_data_bit( to7_io_line.State, 1 ); |
| 864 | | serial_connection_out( &to7_io_line ); |
| 864 | serial_connection_out( machine, &to7_io_line ); |
| 865 | 865 | } |
| 866 | 866 | |
| 867 | 867 | |
| r3904 | r3905 | |
| 871 | 871 | LOG (( "to7_io_init: CC 90-323 serial / parallel extension\n" )); |
| 872 | 872 | pia_config( machine, THOM_PIA_IO, &to7_io ); |
| 873 | 873 | centronics_config( machine, 0, &to7_centronics ); |
| 874 | | serial_connection_init( &to7_io_line ); |
| 875 | | serial_connection_set_in_callback( &to7_io_line, to7_io_in_cb ); |
| 874 | serial_connection_init( machine, &to7_io_line ); |
| 875 | serial_connection_set_in_callback( machine, &to7_io_line, to7_io_in_cb ); |
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | |
src/mess/machine/pmd85.c
| r3904 | r3905 | |
| 762 | 762 | |
| 763 | 763 | static struct serial_connection pmd85_cassette_serial_connection; |
| 764 | 764 | |
| 765 | | static void pmd85_cassette_write(int id, unsigned long state) |
| 765 | static void pmd85_cassette_write(running_machine *machine, int id, unsigned long state) |
| 766 | 766 | { |
| 767 | 767 | pmd85_cassette_serial_connection.input_state = state; |
| 768 | 768 | } |
| r3904 | r3905 | |
| 797 | 797 | data = (!previous_level && current_level) ? 1 : 0; |
| 798 | 798 | |
| 799 | 799 | set_out_data_bit(pmd85_cassette_serial_connection.State, data); |
| 800 | | serial_connection_out(&pmd85_cassette_serial_connection); |
| 800 | serial_connection_out(machine, &pmd85_cassette_serial_connection); |
| 801 | 801 | msm8251_receive_clock(device_list_find_by_tag( machine->config->devicelist, MSM8251, "uart" )); |
| 802 | 802 | |
| 803 | 803 | clk_level_tape = 1; |
| r3904 | r3905 | |
| 854 | 854 | pmd85_cassette_timer = timer_alloc(machine, pmd85_cassette_timer_callback, NULL); |
| 855 | 855 | timer_adjust_periodic(pmd85_cassette_timer, attotime_zero, 0, ATTOTIME_IN_HZ(2400)); |
| 856 | 856 | |
| 857 | | serial_connection_init(&pmd85_cassette_serial_connection); |
| 858 | | serial_connection_set_in_callback(&pmd85_cassette_serial_connection, pmd85_cassette_write); |
| 857 | serial_connection_init(machine, &pmd85_cassette_serial_connection); |
| 858 | serial_connection_set_in_callback(machine, &pmd85_cassette_serial_connection, pmd85_cassette_write); |
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | DRIVER_INIT ( pmd851 ) |
src/mess/machine/6551.c
| r3904 | r3905 | |
| 13 | 13 | *********************************************************************/ |
| 14 | 14 | |
| 15 | 15 | #include "driver.h" |
| 16 | | #include "deprecat.h" |
| 17 | 16 | #include "6551.h" |
| 18 | 17 | #include "includes/serial.h" |
| 19 | 18 | |
| r3904 | r3905 | |
| 79 | 78 | has updated state |
| 80 | 79 | -------------------------------------------------*/ |
| 81 | 80 | |
| 82 | | static void acia_6551_in_callback(int id, unsigned long state) |
| 81 | static void acia_6551_in_callback(running_machine *machine, int id, unsigned long state) |
| 83 | 82 | { |
| 84 | 83 | const device_config *device; |
| 85 | 84 | acia6551_t *acia; |
| 86 | 85 | |
| 87 | 86 | /* NPW 29-Nov-2008 - These two lines are a hack and indicate why our "serial" infrastructure needs to be updated */ |
| 88 | | device = device_list_find_by_tag(Machine->config->devicelist, ACIA6551, "acia"); |
| 87 | device = device_list_find_by_tag(machine->config->devicelist, ACIA6551, "acia"); |
| 89 | 88 | acia = get_token(device); |
| 90 | 89 | |
| 91 | 90 | acia->connection.input_state = state; |
| r3904 | r3905 | |
| 130 | 129 | if ((acia->transmit_reg.flags & TRANSMIT_REGISTER_EMPTY)==0) |
| 131 | 130 | { |
| 132 | 131 | // logerror("UART6551\n"); |
| 133 | | transmit_register_send_bit(&acia->transmit_reg, &acia->connection); |
| 132 | transmit_register_send_bit(machine, &acia->transmit_reg, &acia->connection); |
| 134 | 133 | } |
| 135 | 134 | } |
| 136 | 135 | |
| r3904 | r3905 | |
| 151 | 150 | acia->status_register |= (1<<4); |
| 152 | 151 | acia->timer = timer_alloc(device->machine, acia_6551_timer_callback, (void *) device); |
| 153 | 152 | |
| 154 | | serial_connection_init(&acia->connection); |
| 155 | | serial_connection_set_in_callback(&acia->connection, acia_6551_in_callback); |
| 153 | serial_connection_init(device->machine, &acia->connection); |
| 154 | serial_connection_set_in_callback(device->machine, &acia->connection, acia_6551_in_callback); |
| 156 | 155 | transmit_register_reset(&acia->transmit_reg); |
| 157 | 156 | receive_register_reset(&acia->receive_reg); |
| 158 | 157 | return DEVICE_START_OK; |
| r3904 | r3905 | |
| 398 | 397 | break; |
| 399 | 398 | } |
| 400 | 399 | |
| 401 | | serial_connection_out(&acia->connection); |
| 400 | serial_connection_out(device->machine, &acia->connection); |
| 402 | 401 | |
| 403 | 402 | acia_6551_update_data_form(device); |
| 404 | 403 | } |
src/mess/machine/msm8251.c
| r3904 | r3905 | |
| 7 | 7 | *********************************************************************/ |
| 8 | 8 | |
| 9 | 9 | #include "driver.h" |
| 10 | | #include "deprecat.h" |
| 11 | 10 | #include "msm8251.h" |
| 12 | 11 | #include "includes/serial.h" |
| 13 | 12 | |
| r3904 | r3905 | |
| 64 | 63 | ***************************************************************************/ |
| 65 | 64 | |
| 66 | 65 | static void msm8251_receive_character(const device_config *device, UINT8 ch); |
| 67 | | static void msm8251_in_callback(int id, unsigned long state); |
| 66 | static void msm8251_in_callback(running_machine *machine, int id, unsigned long state); |
| 68 | 67 | static void msm8251_update_tx_empty(const device_config *device); |
| 69 | 68 | static void msm8251_update_tx_ready(const device_config *device); |
| 70 | 69 | |
| r3904 | r3905 | |
| 100 | 99 | msm8251_in_callback |
| 101 | 100 | -------------------------------------------------*/ |
| 102 | 101 | |
| 103 | | static void msm8251_in_callback(int id, unsigned long state) |
| 102 | static void msm8251_in_callback(running_machine *machine, int id, unsigned long state) |
| 104 | 103 | { |
| 105 | 104 | const device_config *device; |
| 106 | 105 | msm8251_t *uart; |
| 107 | 106 | int changed; |
| 108 | 107 | |
| 109 | 108 | /* NPW 29-Nov-2008 - These two lines are a hack and indicate why our "serial" infrastructure needs to be updated */ |
| 110 | | device = device_list_find_by_tag(Machine->config->devicelist, MSM8251, "uart"); |
| 109 | device = device_list_find_by_tag(machine->config->devicelist, MSM8251, "uart"); |
| 111 | 110 | uart = get_token(device); |
| 112 | 111 | |
| 113 | 112 | changed = uart->connection.input_state^state; |
| r3904 | r3905 | |
| 136 | 135 | serial_helper_setup(); |
| 137 | 136 | |
| 138 | 137 | /* setup this side of the serial connection */ |
| 139 | | serial_connection_init(&uart->connection); |
| 140 | | serial_connection_set_in_callback(&uart->connection, msm8251_in_callback); |
| 138 | serial_connection_init(device->machine,&uart->connection); |
| 139 | serial_connection_set_in_callback(device->machine,&uart->connection, msm8251_in_callback); |
| 141 | 140 | uart->connection.input_state = 0; |
| 142 | 141 | return DEVICE_START_OK; |
| 143 | 142 | } |
| r3904 | r3905 | |
| 228 | 227 | if ((uart->transmit_reg.flags & TRANSMIT_REGISTER_EMPTY)==0) |
| 229 | 228 | { |
| 230 | 229 | // logerror("MSM8251\n"); |
| 231 | | transmit_register_send_bit(&uart->transmit_reg, &uart->connection); |
| 230 | transmit_register_send_bit(device->machine,&uart->transmit_reg, &uart->connection); |
| 232 | 231 | } |
| 233 | 232 | } |
| 234 | 233 | |
| r3904 | r3905 | |
| 315 | 314 | { |
| 316 | 315 | /* tx is in marking state (high) when tx empty! */ |
| 317 | 316 | set_out_data_bit(uart->connection.State, 1); |
| 318 | | serial_connection_out(&uart->connection); |
| 317 | serial_connection_out(device->machine,&uart->connection); |
| 319 | 318 | } |
| 320 | 319 | |
| 321 | 320 | if (uart_interface->tx_empty_callback != NULL) |
| r3904 | r3905 | |
| 342 | 341 | |
| 343 | 342 | /* assumption, rts is set to 1 */ |
| 344 | 343 | uart->connection.State &= ~SERIAL_STATE_RTS; |
| 345 | | serial_connection_out(&uart->connection); |
| 344 | serial_connection_out(device->machine, &uart->connection); |
| 346 | 345 | |
| 347 | 346 | transmit_register_reset(&uart->transmit_reg); |
| 348 | 347 | receive_register_reset(&uart->receive_reg); |
| r3904 | r3905 | |
| 659 | 658 | |
| 660 | 659 | |
| 661 | 660 | /* refresh outputs */ |
| 662 | | serial_connection_out(&uart->connection); |
| 661 | serial_connection_out(device->machine, &uart->connection); |
| 663 | 662 | |
| 664 | 663 | if (data & (1<<4)) |
| 665 | 664 | { |
| r3904 | r3905 | |
| 780 | 779 | void msm8251_connect(const device_config *device, struct serial_connection *other_connection) |
| 781 | 780 | { |
| 782 | 781 | msm8251_t *uart = get_token(device); |
| 783 | | serial_connection_link(&uart->connection, other_connection); |
| 782 | serial_connection_link(device->machine, &uart->connection, other_connection); |
| 784 | 783 | } |
| 785 | 784 | |
| 786 | 785 | |