src/emu/machine/z80dart.c
| r8854 | r8855 | |
| 17 | 17 | |
| 18 | 18 | TODO: |
| 19 | 19 | |
| 20 | | - synchronous mode (Z80-SIO/1,2) |
| 21 | 20 | - break detection |
| 22 | 21 | - wr0 reset tx interrupt pending |
| 23 | 22 | - wait/ready |
| 24 | 23 | - 1.5 stop bits |
| 24 | - synchronous mode (Z80-SIO/1,2) |
| 25 | - SDLC mode (Z80-SIO/1,2) |
| 25 | 26 | |
| 26 | 27 | */ |
| 27 | 28 | |
| r8854 | r8855 | |
| 48 | 49 | |
| 49 | 50 | enum |
| 50 | 51 | { |
| 52 | CHANNEL_A = 0, |
| 53 | CHANNEL_B |
| 54 | }; |
| 55 | |
| 56 | enum |
| 57 | { |
| 51 | 58 | STATE_START = 0, |
| 52 | 59 | STATE_DATA, |
| 53 | 60 | STATE_PARITY, |
| r8854 | r8855 | |
| 63 | 70 | INT_SPECIAL |
| 64 | 71 | }; |
| 65 | 72 | |
| 66 | | const int Z80DART_RR0_RX_CHAR_AVAILABLE = 0x01; |
| 67 | | const int Z80DART_RR0_INTERRUPT_PENDING = 0x02; |
| 68 | | const int Z80DART_RR0_TX_BUFFER_EMPTY = 0x04; |
| 69 | | const int Z80DART_RR0_DCD = 0x08; |
| 70 | | const int Z80DART_RR0_RI = 0x10; |
| 71 | | const int Z80DART_RR0_CTS = 0x20; |
| 72 | | const int Z80DART_RR0_BREAK = 0x80; // not supported |
| 73 | const int RR0_RX_CHAR_AVAILABLE = 0x01; |
| 74 | const int RR0_INTERRUPT_PENDING = 0x02; |
| 75 | const int RR0_TX_BUFFER_EMPTY = 0x04; |
| 76 | const int RR0_DCD = 0x08; |
| 77 | const int RR0_RI = 0x10; |
| 78 | const int RR0_SYNC_HUNT = 0x10; // not supported |
| 79 | const int RR0_CTS = 0x20; |
| 80 | const int RR0_TX_UNDERRUN = 0x40; // not supported |
| 81 | const int RR0_BREAK_ABORT = 0x80; // not supported |
| 73 | 82 | |
| 74 | | const int Z80DART_RR1_ALL_SENT = 0x01; |
| 75 | | const int Z80DART_RR1_PARITY_ERROR = 0x10; |
| 76 | | const int Z80DART_RR1_RX_OVERRUN_ERROR = 0x20; |
| 77 | | const int Z80DART_RR1_FRAMING_ERROR = 0x40; |
| 83 | const int RR1_ALL_SENT = 0x01; |
| 84 | const int RR1_RESIDUE_CODE_MASK = 0x0e; // not supported |
| 85 | const int RR1_PARITY_ERROR = 0x10; |
| 86 | const int RR1_RX_OVERRUN_ERROR = 0x20; |
| 87 | const int RR1_CRC_FRAMING_ERROR = 0x40; |
| 88 | const int RR1_END_OF_FRAME = 0x80; // not supported |
| 78 | 89 | |
| 79 | | const int Z80DART_WR0_REGISTER_MASK = 0x07; |
| 80 | | const int Z80DART_WR0_COMMAND_MASK = 0x38; |
| 81 | | const int Z80DART_WR0_NULL_CODE = 0x00; |
| 82 | | const int Z80DART_WR0_RESET_EXT_STATUS = 0x10; |
| 83 | | const int Z80DART_WR0_CHANNEL_RESET = 0x18; |
| 84 | | const int Z80DART_WR0_ENABLE_INT_NEXT_RX = 0x20; |
| 85 | | const int Z80DART_WR0_RESET_TX_INT = 0x28; // not supported |
| 86 | | const int Z80DART_WR0_ERROR_RESET = 0x30; |
| 87 | | const int Z80DART_WR0_RETURN_FROM_INT = 0x38; // not supported |
| 90 | const int WR0_REGISTER_MASK = 0x07; |
| 91 | const int WR0_COMMAND_MASK = 0x38; |
| 92 | const int WR0_NULL = 0x00; |
| 93 | const int WR0_SEND_ABORT = 0x08; // not supported |
| 94 | const int WR0_RESET_EXT_STATUS = 0x10; |
| 95 | const int WR0_CHANNEL_RESET = 0x18; |
| 96 | const int WR0_ENABLE_INT_NEXT_RX = 0x20; |
| 97 | const int WR0_RESET_TX_INT = 0x28; // not supported |
| 98 | const int WR0_ERROR_RESET = 0x30; |
| 99 | const int WR0_RETURN_FROM_INT = 0x38; // not supported |
| 100 | const int WR0_CRC_RESET_CODE_MASK = 0xc0; // not supported |
| 101 | const int WR0_CRC_RESET_NULL = 0x00; // not supported |
| 102 | const int WR0_CRC_RESET_RX = 0x40; // not supported |
| 103 | const int WR0_CRC_RESET_TX = 0x80; // not supported |
| 104 | const int WR0_CRC_RESET_TX_UNDERRUN = 0xc0; // not supported |
| 88 | 105 | |
| 89 | | const int Z80DART_WR1_EXT_INT_ENABLE = 0x01; |
| 90 | | const int Z80DART_WR1_TX_INT_ENABLE = 0x02; |
| 91 | | const int Z80DART_WR1_STATUS_VECTOR = 0x04; |
| 92 | | const int Z80DART_WR1_RX_INT_ENABLE_MASK = 0x18; |
| 93 | | const int Z80DART_WR1_RX_INT_DISABLE = 0x00; |
| 94 | | const int Z80DART_WR1_RX_INT_FIRST = 0x08; |
| 95 | | const int Z80DART_WR1_RX_INT_ALL_PARITY = 0x10; // not supported |
| 96 | | const int Z80DART_WR1_RX_INT_ALL = 0x18; |
| 97 | | const int Z80DART_WR1_WRDY_ON_RX_TX = 0x20; // not supported |
| 98 | | const int Z80DART_WR1_WRDY_FUNCTION = 0x40; // not supported |
| 99 | | const int Z80DART_WR1_WRDY_ENABLE = 0x80; // not supported |
| 106 | const int WR1_EXT_INT_ENABLE = 0x01; |
| 107 | const int WR1_TX_INT_ENABLE = 0x02; |
| 108 | const int WR1_STATUS_VECTOR = 0x04; |
| 109 | const int WR1_RX_INT_MODE_MASK = 0x18; |
| 110 | const int WR1_RX_INT_DISABLE = 0x00; |
| 111 | const int WR1_RX_INT_FIRST = 0x08; |
| 112 | const int WR1_RX_INT_ALL_PARITY = 0x10; // not supported |
| 113 | const int WR1_RX_INT_ALL = 0x18; |
| 114 | const int WR1_WRDY_ON_RX_TX = 0x20; // not supported |
| 115 | const int WR1_WRDY_FUNCTION = 0x40; // not supported |
| 116 | const int WR1_WRDY_ENABLE = 0x80; // not supported |
| 100 | 117 | |
| 101 | | const int Z80DART_WR3_RX_ENABLE = 0x01; |
| 102 | | const int Z80DART_WR3_AUTO_ENABLES = 0x20; |
| 103 | | const int Z80DART_WR3_RX_WORD_LENGTH_MASK = 0xc0; |
| 104 | | const int Z80DART_WR3_RX_WORD_LENGTH_5 = 0x00; |
| 105 | | const int Z80DART_WR3_RX_WORD_LENGTH_7 = 0x40; |
| 106 | | const int Z80DART_WR3_RX_WORD_LENGTH_6 = 0x80; |
| 107 | | const int Z80DART_WR3_RX_WORD_LENGTH_8 = 0xc0; |
| 118 | const int WR3_RX_ENABLE = 0x01; |
| 119 | const int WR3_SYNC_CHAR_LOAD_INHIBIT= 0x02; // not supported |
| 120 | const int WR3_ADDRESS_SEARCH_MODE = 0x04; // not supported |
| 121 | const int WR3_RX_CRC_ENABLE = 0x08; // not supported |
| 122 | const int WR3_ENTER_HUNT_PHASE = 0x10; // not supported |
| 123 | const int WR3_AUTO_ENABLES = 0x20; |
| 124 | const int WR3_RX_WORD_LENGTH_MASK = 0xc0; |
| 125 | const int WR3_RX_WORD_LENGTH_5 = 0x00; |
| 126 | const int WR3_RX_WORD_LENGTH_7 = 0x40; |
| 127 | const int WR3_RX_WORD_LENGTH_6 = 0x80; |
| 128 | const int WR3_RX_WORD_LENGTH_8 = 0xc0; |
| 108 | 129 | |
| 109 | | const int Z80DART_WR4_PARITY_ENABLE = 0x01; // not supported |
| 110 | | const int Z80DART_WR4_PARITY_EVEN = 0x02; // not supported |
| 111 | | const int Z80DART_WR4_STOP_BITS_MASK = 0x0c; |
| 112 | | const int Z80DART_WR4_STOP_BITS_1 = 0x04; |
| 113 | | const int Z80DART_WR4_STOP_BITS_1_5 = 0x08; // not supported |
| 114 | | const int Z80DART_WR4_STOP_BITS_2 = 0x0c; |
| 115 | | const int Z80DART_WR4_CLOCK_MODE_MASK = 0xc0; |
| 116 | | const int Z80DART_WR4_CLOCK_MODE_X1 = 0x00; |
| 117 | | const int Z80DART_WR4_CLOCK_MODE_X16 = 0x40; |
| 118 | | const int Z80DART_WR4_CLOCK_MODE_X32 = 0x80; |
| 119 | | const int Z80DART_WR4_CLOCK_MODE_X64 = 0xc0; |
| 130 | const int WR4_PARITY_ENABLE = 0x01; // not supported |
| 131 | const int WR4_PARITY_EVEN = 0x02; // not supported |
| 132 | const int WR4_STOP_BITS_MASK = 0x0c; |
| 133 | const int WR4_STOP_BITS_1 = 0x04; |
| 134 | const int WR4_STOP_BITS_1_5 = 0x08; // not supported |
| 135 | const int WR4_STOP_BITS_2 = 0x0c; |
| 136 | const int WR4_SYNC_MODE_MASK = 0x30; // not supported |
| 137 | const int WR4_SYNC_MODE_8_BIT = 0x00; // not supported |
| 138 | const int WR4_SYNC_MODE_16_BIT = 0x10; // not supported |
| 139 | const int WR4_SYNC_MODE_SDLC = 0x20; // not supported |
| 140 | const int WR4_SYNC_MODE_EXT = 0x30; // not supported |
| 141 | const int WR4_CLOCK_RATE_MASK = 0xc0; |
| 142 | const int WR4_CLOCK_RATE_X1 = 0x00; |
| 143 | const int WR4_CLOCK_RATE_X16 = 0x40; |
| 144 | const int WR4_CLOCK_RATE_X32 = 0x80; |
| 145 | const int WR4_CLOCK_RATE_X64 = 0xc0; |
| 120 | 146 | |
| 121 | | const int Z80DART_WR5_RTS = 0x02; |
| 122 | | const int Z80DART_WR5_TX_ENABLE = 0x08; |
| 123 | | const int Z80DART_WR5_SEND_BREAK = 0x10; |
| 124 | | const int Z80DART_WR5_TX_WORD_LENGTH_MASK = 0xc0; |
| 125 | | const int Z80DART_WR5_TX_WORD_LENGTH_5 = 0x00; |
| 126 | | const int Z80DART_WR5_TX_WORD_LENGTH_7 = 0x40; |
| 127 | | const int Z80DART_WR5_TX_WORD_LENGTH_6 = 0x80; |
| 128 | | const int Z80DART_WR5_TX_WORD_LENGTH_8 = 0xc0; |
| 129 | | const int Z80DART_WR5_DTR = 0x80; |
| 147 | const int WR5_TX_CRC_ENABLE = 0x01; // not supported |
| 148 | const int WR5_RTS = 0x02; |
| 149 | const int WR5_CRC16 = 0x04; // not supported |
| 150 | const int WR5_TX_ENABLE = 0x08; |
| 151 | const int WR5_SEND_BREAK = 0x10; |
| 152 | const int WR5_TX_WORD_LENGTH_MASK = 0xc0; |
| 153 | const int WR5_TX_WORD_LENGTH_5 = 0x00; |
| 154 | const int WR5_TX_WORD_LENGTH_7 = 0x40; |
| 155 | const int WR5_TX_WORD_LENGTH_6 = 0x80; |
| 156 | const int WR5_TX_WORD_LENGTH_8 = 0xc0; |
| 157 | const int WR5_DTR = 0x80; |
| 130 | 158 | |
| 131 | 159 | |
| 132 | 160 | |
| r8854 | r8855 | |
| 246 | 274 | // resolve callbacks |
| 247 | 275 | devcb_resolve_write_line(&m_out_int_func, &m_config.m_out_int_func, this); |
| 248 | 276 | |
| 249 | | m_channel[Z80DART_CH_A].start(this, Z80DART_CH_A, m_config.m_in_rxda_func, m_config.m_out_txda_func, m_config.m_out_dtra_func, m_config.m_out_rtsa_func, m_config.m_out_wrdya_func, m_config.m_out_synca_func); |
| 250 | | m_channel[Z80DART_CH_B].start(this, Z80DART_CH_B, m_config.m_in_rxdb_func, m_config.m_out_txdb_func, m_config.m_out_dtrb_func, m_config.m_out_rtsb_func, m_config.m_out_wrdyb_func, m_config.m_out_syncb_func); |
| 277 | m_channel[CHANNEL_A].start(this, CHANNEL_A, m_config.m_in_rxda_func, m_config.m_out_txda_func, m_config.m_out_dtra_func, m_config.m_out_rtsa_func, m_config.m_out_wrdya_func, m_config.m_out_synca_func); |
| 278 | m_channel[CHANNEL_B].start(this, CHANNEL_B, m_config.m_in_rxdb_func, m_config.m_out_txdb_func, m_config.m_out_dtrb_func, m_config.m_out_rtsb_func, m_config.m_out_wrdyb_func, m_config.m_out_syncb_func); |
| 251 | 279 | |
| 252 | 280 | if (m_config.m_rx_clock_a != 0) |
| 253 | 281 | { |
| 254 | 282 | // allocate channel A receive timer |
| 255 | | m_rxca_timer = timer_alloc(&m_machine, dart_channel::static_rxc_tick, (void *)&m_channel[Z80DART_CH_A]); |
| 283 | m_rxca_timer = timer_alloc(&m_machine, dart_channel::static_rxc_tick, (void *)&m_channel[CHANNEL_A]); |
| 256 | 284 | timer_adjust_periodic(m_rxca_timer, attotime_zero, 0, ATTOTIME_IN_HZ(m_config.m_rx_clock_a)); |
| 257 | 285 | } |
| 258 | 286 | |
| 259 | 287 | if (m_config.m_tx_clock_a != 0) |
| 260 | 288 | { |
| 261 | 289 | // allocate channel A transmit timer |
| 262 | | m_txca_timer = timer_alloc(&m_machine, dart_channel::static_txc_tick, (void *)&m_channel[Z80DART_CH_A]); |
| 290 | m_txca_timer = timer_alloc(&m_machine, dart_channel::static_txc_tick, (void *)&m_channel[CHANNEL_A]); |
| 263 | 291 | timer_adjust_periodic(m_txca_timer, attotime_zero, 0, ATTOTIME_IN_HZ(m_config.m_tx_clock_a)); |
| 264 | 292 | } |
| 265 | 293 | |
| 266 | 294 | if (m_config.m_rx_clock_b != 0) |
| 267 | 295 | { |
| 268 | 296 | // allocate channel B receive timer |
| 269 | | m_rxcb_timer = timer_alloc(&m_machine, dart_channel::static_rxc_tick, (void *)&m_channel[Z80DART_CH_B]); |
| 297 | m_rxcb_timer = timer_alloc(&m_machine, dart_channel::static_rxc_tick, (void *)&m_channel[CHANNEL_B]); |
| 270 | 298 | timer_adjust_periodic(m_rxcb_timer, attotime_zero, 0, ATTOTIME_IN_HZ(m_config.m_rx_clock_b)); |
| 271 | 299 | } |
| 272 | 300 | |
| 273 | 301 | if (m_config.m_tx_clock_b != 0) |
| 274 | 302 | { |
| 275 | 303 | // allocate channel B transmit timer |
| 276 | | m_txcb_timer = timer_alloc(&m_machine, dart_channel::static_txc_tick, (void *)&m_channel[Z80DART_CH_B]); |
| 304 | m_txcb_timer = timer_alloc(&m_machine, dart_channel::static_txc_tick, (void *)&m_channel[CHANNEL_B]); |
| 277 | 305 | timer_adjust_periodic(m_txcb_timer, attotime_zero, 0, ATTOTIME_IN_HZ(m_config.m_tx_clock_b)); |
| 278 | 306 | } |
| 279 | 307 | |
| r8854 | r8855 | |
| 289 | 317 | { |
| 290 | 318 | LOG(("Z80DART \"%s\" Reset\n", tag())); |
| 291 | 319 | |
| 292 | | for (int channel = Z80DART_CH_A; channel <= Z80DART_CH_B; channel++) |
| 320 | for (int channel = CHANNEL_A; channel <= CHANNEL_B; channel++) |
| 293 | 321 | { |
| 294 | 322 | m_channel[channel].reset(); |
| 295 | 323 | } |
| r8854 | r8855 | |
| 352 | 380 | { |
| 353 | 381 | // clear interrupt, switch to the IEO state, and update the IRQs |
| 354 | 382 | m_int_state[i] = Z80_DAISY_IEO; |
| 355 | | m_channel[Z80DART_CH_A].m_rr[0] &= ~Z80DART_RR0_INTERRUPT_PENDING; |
| 383 | m_channel[CHANNEL_A].m_rr[0] &= ~RR0_INTERRUPT_PENDING; |
| 356 | 384 | check_interrupts(); |
| 357 | 385 | |
| 358 | | LOG(("Z80DART \"%s\" : Interrupt Acknowledge Vector %02x\n", tag(), m_channel[Z80DART_CH_B].m_rr[2])); |
| 386 | LOG(("Z80DART \"%s\" : Interrupt Acknowledge Vector %02x\n", tag(), m_channel[CHANNEL_B].m_rr[2])); |
| 359 | 387 | |
| 360 | | return m_channel[Z80DART_CH_B].m_rr[2]; |
| 388 | return m_channel[CHANNEL_B].m_rr[2]; |
| 361 | 389 | } |
| 362 | 390 | } |
| 363 | 391 | |
| 364 | 392 | logerror("z80dart_irq_ack: failed to find an interrupt to ack!\n"); |
| 365 | 393 | |
| 366 | | return m_channel[Z80DART_CH_B].m_rr[2]; |
| 394 | return m_channel[CHANNEL_B].m_rr[2]; |
| 367 | 395 | } |
| 368 | 396 | |
| 369 | 397 | |
| r8854 | r8855 | |
| 417 | 445 | void z80dart_device::take_interrupt(int priority) |
| 418 | 446 | { |
| 419 | 447 | m_int_state[priority] |= Z80_DAISY_INT; |
| 420 | | m_channel[Z80DART_CH_A].m_rr[0] |= Z80DART_RR0_INTERRUPT_PENDING; |
| 448 | m_channel[CHANNEL_A].m_rr[0] |= RR0_INTERRUPT_PENDING; |
| 421 | 449 | |
| 422 | 450 | // check for interrupt |
| 423 | 451 | check_interrupts(); |
| r8854 | r8855 | |
| 454 | 482 | m_tx_bits(0), |
| 455 | 483 | m_tx_parity(0), |
| 456 | 484 | m_dtr(0), |
| 457 | | m_rts(0) |
| 485 | m_rts(0), |
| 486 | m_sync(0) |
| 458 | 487 | { |
| 459 | 488 | memset(&m_in_rxd_func, 0, sizeof(m_in_rxd_func)); |
| 460 | 489 | memset(&m_out_txd_func, 0, sizeof(m_out_txd_func)); |
| r8854 | r8855 | |
| 509 | 538 | state_save_register_device_item(m_device, m_index, m_tx_parity); |
| 510 | 539 | state_save_register_device_item(m_device, m_index, m_dtr); |
| 511 | 540 | state_save_register_device_item(m_device, m_index, m_rts); |
| 541 | state_save_register_device_item(m_device, m_index, m_sync); |
| 512 | 542 | } |
| 513 | 543 | |
| 514 | 544 | |
| r8854 | r8855 | |
| 523 | 553 | |
| 524 | 554 | LOG(("Z80DART \"%s\" Channel %c : Interrupt Request %u\n", m_device->tag(), 'A' + m_index, level)); |
| 525 | 555 | |
| 526 | | if ((m_index == Z80DART_CH_B) && (m_wr[1] & Z80DART_WR1_STATUS_VECTOR)) |
| 556 | if ((m_index == CHANNEL_B) && (m_wr[1] & WR1_STATUS_VECTOR)) |
| 527 | 557 | { |
| 528 | 558 | // status affects vector |
| 529 | 559 | vector = (m_wr[2] & 0xf1) | (!m_index << 3) | (level << 1); |
| r8854 | r8855 | |
| 545 | 575 | { |
| 546 | 576 | int clocks = 1; |
| 547 | 577 | |
| 548 | | switch (m_wr[4] & Z80DART_WR4_CLOCK_MODE_MASK) |
| 578 | switch (m_wr[4] & WR4_CLOCK_RATE_MASK) |
| 549 | 579 | { |
| 550 | | case Z80DART_WR4_CLOCK_MODE_X1: clocks = 1; break; |
| 551 | | case Z80DART_WR4_CLOCK_MODE_X16: clocks = 16; break; |
| 552 | | case Z80DART_WR4_CLOCK_MODE_X32: clocks = 32; break; |
| 553 | | case Z80DART_WR4_CLOCK_MODE_X64: clocks = 64; break; |
| 580 | case WR4_CLOCK_RATE_X1: clocks = 1; break; |
| 581 | case WR4_CLOCK_RATE_X16: clocks = 16; break; |
| 582 | case WR4_CLOCK_RATE_X32: clocks = 32; break; |
| 583 | case WR4_CLOCK_RATE_X64: clocks = 64; break; |
| 554 | 584 | } |
| 555 | 585 | |
| 556 | 586 | return clocks; |
| r8854 | r8855 | |
| 565 | 595 | { |
| 566 | 596 | float bits = 1; |
| 567 | 597 | |
| 568 | | switch (m_wr[4] & Z80DART_WR4_STOP_BITS_MASK) |
| 598 | switch (m_wr[4] & WR4_STOP_BITS_MASK) |
| 569 | 599 | { |
| 570 | | case Z80DART_WR4_STOP_BITS_1: bits = 1; break; |
| 571 | | case Z80DART_WR4_STOP_BITS_1_5: bits = 1.5; break; |
| 572 | | case Z80DART_WR4_STOP_BITS_2: bits = 2; break; |
| 600 | case WR4_STOP_BITS_1: bits = 1; break; |
| 601 | case WR4_STOP_BITS_1_5: bits = 1.5; break; |
| 602 | case WR4_STOP_BITS_2: bits = 2; break; |
| 573 | 603 | } |
| 574 | 604 | |
| 575 | 605 | return bits; |
| r8854 | r8855 | |
| 584 | 614 | { |
| 585 | 615 | int bits = 5; |
| 586 | 616 | |
| 587 | | switch (m_wr[3] & Z80DART_WR3_RX_WORD_LENGTH_MASK) |
| 617 | switch (m_wr[3] & WR3_RX_WORD_LENGTH_MASK) |
| 588 | 618 | { |
| 589 | | case Z80DART_WR3_RX_WORD_LENGTH_5: bits = 5; break; |
| 590 | | case Z80DART_WR3_RX_WORD_LENGTH_6: bits = 6; break; |
| 591 | | case Z80DART_WR3_RX_WORD_LENGTH_7: bits = 7; break; |
| 592 | | case Z80DART_WR3_RX_WORD_LENGTH_8: bits = 8; break; |
| 619 | case WR3_RX_WORD_LENGTH_5: bits = 5; break; |
| 620 | case WR3_RX_WORD_LENGTH_6: bits = 6; break; |
| 621 | case WR3_RX_WORD_LENGTH_7: bits = 7; break; |
| 622 | case WR3_RX_WORD_LENGTH_8: bits = 8; break; |
| 593 | 623 | } |
| 594 | 624 | |
| 595 | 625 | return bits; |
| r8854 | r8855 | |
| 604 | 634 | { |
| 605 | 635 | int bits = 5; |
| 606 | 636 | |
| 607 | | switch (m_wr[5] & Z80DART_WR5_TX_WORD_LENGTH_MASK) |
| 637 | switch (m_wr[5] & WR5_TX_WORD_LENGTH_MASK) |
| 608 | 638 | { |
| 609 | | case Z80DART_WR5_TX_WORD_LENGTH_5: bits = 5; break; |
| 610 | | case Z80DART_WR5_TX_WORD_LENGTH_6: bits = 6; break; |
| 611 | | case Z80DART_WR5_TX_WORD_LENGTH_7: bits = 7; break; |
| 612 | | case Z80DART_WR5_TX_WORD_LENGTH_8: bits = 8; break; |
| 639 | case WR5_TX_WORD_LENGTH_5: bits = 5; break; |
| 640 | case WR5_TX_WORD_LENGTH_6: bits = 6; break; |
| 641 | case WR5_TX_WORD_LENGTH_7: bits = 7; break; |
| 642 | case WR5_TX_WORD_LENGTH_8: bits = 8; break; |
| 613 | 643 | } |
| 614 | 644 | |
| 615 | 645 | return bits; |
| r8854 | r8855 | |
| 623 | 653 | void z80dart_device::dart_channel::reset() |
| 624 | 654 | { |
| 625 | 655 | // disable receiver |
| 626 | | m_wr[3] &= ~Z80DART_WR3_RX_ENABLE; |
| 656 | m_wr[3] &= ~WR3_RX_ENABLE; |
| 627 | 657 | m_rx_state = STATE_START; |
| 628 | 658 | |
| 629 | 659 | // disable transmitter |
| 630 | | m_wr[5] &= ~Z80DART_WR5_TX_ENABLE; |
| 660 | m_wr[5] &= ~WR5_TX_ENABLE; |
| 631 | 661 | m_tx_state = STATE_START; |
| 632 | 662 | |
| 633 | 663 | // reset external lines |
| 634 | 664 | RTS(1); |
| 635 | 665 | DTR(1); |
| 636 | 666 | |
| 637 | | if (m_index == Z80DART_CH_A) |
| 667 | if (m_index == CHANNEL_A) |
| 638 | 668 | { |
| 639 | 669 | // reset interrupt logic |
| 640 | 670 | int i; |
| r8854 | r8855 | |
| 655 | 685 | |
| 656 | 686 | int z80dart_device::dart_channel::detect_start_bit() |
| 657 | 687 | { |
| 658 | | if (!(m_wr[3] & Z80DART_WR3_RX_ENABLE)) return 0; |
| 688 | if (!(m_wr[3] & WR3_RX_ENABLE)) return 0; |
| 659 | 689 | |
| 660 | 690 | return !RXD; |
| 661 | 691 | } |
| r8854 | r8855 | |
| 696 | 726 | |
| 697 | 727 | void z80dart_device::dart_channel::detect_parity_error() |
| 698 | 728 | { |
| 699 | | int parity = (m_wr[1] & Z80DART_WR4_PARITY_EVEN) ? 1 : 0; |
| 729 | int parity = (m_wr[1] & WR4_PARITY_EVEN) ? 1 : 0; |
| 700 | 730 | |
| 701 | 731 | if (RXD != (m_rx_parity ^ parity)) |
| 702 | 732 | { |
| 703 | 733 | // parity error detected |
| 704 | | m_rx_error |= Z80DART_RR1_PARITY_ERROR; |
| 734 | m_rx_error |= RR1_PARITY_ERROR; |
| 705 | 735 | |
| 706 | | switch (m_wr[1] & Z80DART_WR1_RX_INT_ENABLE_MASK) |
| 736 | switch (m_wr[1] & WR1_RX_INT_MODE_MASK) |
| 707 | 737 | { |
| 708 | | case Z80DART_WR1_RX_INT_FIRST: |
| 738 | case WR1_RX_INT_FIRST: |
| 709 | 739 | if (!m_rx_first) |
| 710 | 740 | { |
| 711 | 741 | take_interrupt(INT_SPECIAL); |
| 712 | 742 | } |
| 713 | 743 | break; |
| 714 | 744 | |
| 715 | | case Z80DART_WR1_RX_INT_ALL_PARITY: |
| 745 | case WR1_RX_INT_ALL_PARITY: |
| 716 | 746 | take_interrupt(INT_SPECIAL); |
| 717 | 747 | break; |
| 718 | 748 | |
| 719 | | case Z80DART_WR1_RX_INT_ALL: |
| 749 | case WR1_RX_INT_ALL: |
| 720 | 750 | take_interrupt(INT_RECEIVE); |
| 721 | 751 | break; |
| 722 | 752 | } |
| r8854 | r8855 | |
| 733 | 763 | if (!RXD) |
| 734 | 764 | { |
| 735 | 765 | // framing error detected |
| 736 | | m_rx_error |= Z80DART_RR1_FRAMING_ERROR; |
| 766 | m_rx_error |= RR1_CRC_FRAMING_ERROR; |
| 737 | 767 | |
| 738 | | switch (m_wr[1] & Z80DART_WR1_RX_INT_ENABLE_MASK) |
| 768 | switch (m_wr[1] & WR1_RX_INT_MODE_MASK) |
| 739 | 769 | { |
| 740 | | case Z80DART_WR1_RX_INT_FIRST: |
| 770 | case WR1_RX_INT_FIRST: |
| 741 | 771 | if (!m_rx_first) |
| 742 | 772 | { |
| 743 | 773 | take_interrupt(INT_SPECIAL); |
| 744 | 774 | } |
| 745 | 775 | break; |
| 746 | 776 | |
| 747 | | case Z80DART_WR1_RX_INT_ALL_PARITY: |
| 748 | | case Z80DART_WR1_RX_INT_ALL: |
| 777 | case WR1_RX_INT_ALL_PARITY: |
| 778 | case WR1_RX_INT_ALL: |
| 749 | 779 | take_interrupt(INT_SPECIAL); |
| 750 | 780 | break; |
| 751 | 781 | } |
| r8854 | r8855 | |
| 785 | 815 | if (character_completed()) |
| 786 | 816 | { |
| 787 | 817 | // all data bits received |
| 788 | | if (m_wr[4] & Z80DART_WR4_PARITY_ENABLE) |
| 818 | if (m_wr[4] & WR4_PARITY_ENABLE) |
| 789 | 819 | { |
| 790 | 820 | // next bit is the parity bit |
| 791 | 821 | m_rx_state = STATE_PARITY; |
| r8854 | r8855 | |
| 855 | 885 | switch (m_tx_state) |
| 856 | 886 | { |
| 857 | 887 | case STATE_START: |
| 858 | | if ((m_wr[5] & Z80DART_WR5_TX_ENABLE) && !(m_rr[0] & Z80DART_RR0_TX_BUFFER_EMPTY)) |
| 888 | if ((m_wr[5] & WR5_TX_ENABLE) && !(m_rr[0] & RR0_TX_BUFFER_EMPTY)) |
| 859 | 889 | { |
| 860 | 890 | // transmit start bit |
| 861 | 891 | TXD(0); |
| r8854 | r8855 | |
| 864 | 894 | m_tx_shift = m_tx_data; |
| 865 | 895 | |
| 866 | 896 | // empty transmit buffer |
| 867 | | m_rr[0] |= Z80DART_RR0_TX_BUFFER_EMPTY; |
| 897 | m_rr[0] |= RR0_TX_BUFFER_EMPTY; |
| 868 | 898 | |
| 869 | | if (m_wr[1] & Z80DART_WR1_TX_INT_ENABLE) |
| 899 | if (m_wr[1] & WR1_TX_INT_ENABLE) |
| 870 | 900 | take_interrupt(INT_TRANSMIT); |
| 871 | 901 | |
| 872 | 902 | m_tx_state = STATE_DATA; |
| 873 | 903 | } |
| 874 | | else if (m_wr[5] & Z80DART_WR5_SEND_BREAK) |
| 904 | else if (m_wr[5] & WR5_SEND_BREAK) |
| 875 | 905 | { |
| 876 | 906 | // transmit break |
| 877 | 907 | TXD(0); |
| r8854 | r8855 | |
| 894 | 924 | |
| 895 | 925 | if (m_rx_bits == word_length) |
| 896 | 926 | { |
| 897 | | if (m_wr[4] & Z80DART_WR4_PARITY_ENABLE) |
| 927 | if (m_wr[4] & WR4_PARITY_ENABLE) |
| 898 | 928 | m_tx_state = STATE_PARITY; |
| 899 | 929 | else |
| 900 | 930 | { |
| r8854 | r8855 | |
| 926 | 956 | TXD(1); |
| 927 | 957 | |
| 928 | 958 | // if transmit buffer is empty |
| 929 | | if (m_rr[0] & Z80DART_RR0_TX_BUFFER_EMPTY) |
| 959 | if (m_rr[0] & RR0_TX_BUFFER_EMPTY) |
| 930 | 960 | { |
| 931 | 961 | // then all characters have been sent |
| 932 | | m_rr[1] |= Z80DART_RR1_ALL_SENT; |
| 962 | m_rr[1] |= RR1_ALL_SENT; |
| 933 | 963 | |
| 934 | 964 | // when the RTS bit is reset, the _RTS output goes high after the transmitter empties |
| 935 | 965 | if (!m_rts) |
| r8854 | r8855 | |
| 950 | 980 | { |
| 951 | 981 | UINT8 data = 0; |
| 952 | 982 | |
| 953 | | int reg = m_wr[0] & Z80DART_WR0_REGISTER_MASK; |
| 983 | int reg = m_wr[0] & WR0_REGISTER_MASK; |
| 954 | 984 | |
| 955 | 985 | switch (reg) |
| 956 | 986 | { |
| r8854 | r8855 | |
| 961 | 991 | |
| 962 | 992 | case 2: |
| 963 | 993 | // channel B only |
| 964 | | if (m_index == Z80DART_CH_B) |
| 994 | if (m_index == CHANNEL_B) |
| 965 | 995 | data = m_rr[reg]; |
| 966 | 996 | break; |
| 967 | 997 | } |
| r8854 | r8855 | |
| 978 | 1008 | |
| 979 | 1009 | void z80dart_device::dart_channel::control_write(UINT8 data) |
| 980 | 1010 | { |
| 981 | | int reg = m_wr[0] & Z80DART_WR0_REGISTER_MASK; |
| 1011 | int reg = m_wr[0] & WR0_REGISTER_MASK; |
| 982 | 1012 | |
| 983 | 1013 | LOG(("Z80DART \"%s\" Channel %c : Control Register Write '%02x'\n", m_device->tag(), 'A' + m_index, data)); |
| 984 | 1014 | |
| r8854 | r8855 | |
| 988 | 1018 | if (reg != 0) |
| 989 | 1019 | { |
| 990 | 1020 | // mask out register index |
| 991 | | m_wr[0] &= ~Z80DART_WR0_REGISTER_MASK; |
| 1021 | m_wr[0] &= ~WR0_REGISTER_MASK; |
| 992 | 1022 | } |
| 993 | 1023 | |
| 994 | 1024 | switch (reg) |
| 995 | 1025 | { |
| 996 | 1026 | case 0: |
| 997 | | switch (data & Z80DART_WR0_COMMAND_MASK) |
| 1027 | switch (data & WR0_COMMAND_MASK) |
| 998 | 1028 | { |
| 999 | | case Z80DART_WR0_RESET_EXT_STATUS: |
| 1029 | case WR0_NULL: |
| 1030 | LOG(("Z80DART \"%s\" Channel %c : Null\n", m_device->tag(), 'A' + m_index)); |
| 1031 | break; |
| 1032 | |
| 1033 | case WR0_SEND_ABORT: |
| 1034 | LOG(("Z80DART \"%s\" Channel %c : Send Abort\n", m_device->tag(), 'A' + m_index)); |
| 1035 | logerror("Z80DART \"%s\" Channel %c : unsupported command: Send Abort\n", m_device->tag(), 'A' + m_index); |
| 1036 | break; |
| 1037 | |
| 1038 | case WR0_RESET_EXT_STATUS: |
| 1000 | 1039 | // reset external/status interrupt |
| 1001 | | m_rr[0] &= ~(Z80DART_RR0_DCD | Z80DART_RR0_RI | Z80DART_RR0_CTS | Z80DART_RR0_BREAK); |
| 1040 | m_rr[0] &= ~(RR0_DCD | RR0_RI | RR0_CTS | RR0_BREAK_ABORT); |
| 1002 | 1041 | |
| 1003 | | if (!m_dcd) m_rr[0] |= Z80DART_RR0_DCD; |
| 1004 | | if (m_ri) m_rr[0] |= Z80DART_RR0_RI; |
| 1005 | | if (m_cts) m_rr[0] |= Z80DART_RR0_CTS; |
| 1042 | if (!m_dcd) m_rr[0] |= RR0_DCD; |
| 1043 | if (m_ri) m_rr[0] |= RR0_RI; |
| 1044 | if (m_cts) m_rr[0] |= RR0_CTS; |
| 1006 | 1045 | |
| 1007 | 1046 | m_rx_rr0_latch = 0; |
| 1008 | 1047 | |
| 1009 | 1048 | LOG(("Z80DART \"%s\" Channel %c : Reset External/Status Interrupt\n", m_device->tag(), 'A' + m_index)); |
| 1010 | 1049 | break; |
| 1011 | 1050 | |
| 1012 | | case Z80DART_WR0_CHANNEL_RESET: |
| 1051 | case WR0_CHANNEL_RESET: |
| 1013 | 1052 | // channel reset |
| 1014 | 1053 | LOG(("Z80DART \"%s\" Channel %c : Channel Reset\n", m_device->tag(), 'A' + m_index)); |
| 1015 | 1054 | reset(); |
| 1016 | 1055 | break; |
| 1017 | 1056 | |
| 1018 | | case Z80DART_WR0_ENABLE_INT_NEXT_RX: |
| 1057 | case WR0_ENABLE_INT_NEXT_RX: |
| 1019 | 1058 | // enable interrupt on next receive character |
| 1020 | 1059 | LOG(("Z80DART \"%s\" Channel %c : Enable Interrupt on Next Received Character\n", m_device->tag(), 'A' + m_index)); |
| 1021 | 1060 | m_rx_first = 1; |
| 1022 | 1061 | break; |
| 1023 | 1062 | |
| 1024 | | case Z80DART_WR0_RESET_TX_INT: |
| 1063 | case WR0_RESET_TX_INT: |
| 1025 | 1064 | // reset transmitter interrupt pending |
| 1026 | 1065 | LOG(("Z80DART \"%s\" Channel %c : Reset Transmitter Interrupt Pending\n", m_device->tag(), 'A' + m_index)); |
| 1066 | logerror("Z80DART \"%s\" Channel %c : unsupported command: Reset Transmitter Interrupt Pending\n", m_device->tag(), 'A' + m_index); |
| 1027 | 1067 | break; |
| 1028 | 1068 | |
| 1029 | | case Z80DART_WR0_ERROR_RESET: |
| 1069 | case WR0_ERROR_RESET: |
| 1030 | 1070 | // error reset |
| 1031 | 1071 | LOG(("Z80DART \"%s\" Channel %c : Error Reset\n", m_device->tag(), 'A' + m_index)); |
| 1032 | | m_rr[1] &= ~(Z80DART_RR1_FRAMING_ERROR | Z80DART_RR1_RX_OVERRUN_ERROR | Z80DART_RR1_PARITY_ERROR); |
| 1072 | m_rr[1] &= ~(RR1_CRC_FRAMING_ERROR | RR1_RX_OVERRUN_ERROR | RR1_PARITY_ERROR); |
| 1033 | 1073 | break; |
| 1034 | 1074 | |
| 1035 | | case Z80DART_WR0_RETURN_FROM_INT: |
| 1075 | case WR0_RETURN_FROM_INT: |
| 1036 | 1076 | // return from interrupt |
| 1037 | 1077 | LOG(("Z80DART \"%s\" Channel %c : Return from Interrupt\n", m_device->tag(), 'A' + m_index)); |
| 1038 | 1078 | m_device->z80daisy_irq_reti(); |
| r8854 | r8855 | |
| 1041 | 1081 | break; |
| 1042 | 1082 | |
| 1043 | 1083 | case 1: |
| 1044 | | LOG(("Z80DART \"%s\" Channel %c : External Interrupt Enable %u\n", m_device->tag(), 'A' + m_index, (data & Z80DART_WR1_EXT_INT_ENABLE) ? 1 : 0)); |
| 1045 | | LOG(("Z80DART \"%s\" Channel %c : Transmit Interrupt Enable %u\n", m_device->tag(), 'A' + m_index, (data & Z80DART_WR1_TX_INT_ENABLE) ? 1 : 0)); |
| 1046 | | LOG(("Z80DART \"%s\" Channel %c : Status Affects Vector %u\n", m_device->tag(), 'A' + m_index, (data & Z80DART_WR1_STATUS_VECTOR) ? 1 : 0)); |
| 1047 | | LOG(("Z80DART \"%s\" Channel %c : Wait/Ready Enable %u\n", m_device->tag(), 'A' + m_index, (data & Z80DART_WR1_WRDY_ENABLE) ? 1 : 0)); |
| 1084 | LOG(("Z80DART \"%s\" Channel %c : External Interrupt Enable %u\n", m_device->tag(), 'A' + m_index, (data & WR1_EXT_INT_ENABLE) ? 1 : 0)); |
| 1085 | LOG(("Z80DART \"%s\" Channel %c : Transmit Interrupt Enable %u\n", m_device->tag(), 'A' + m_index, (data & WR1_TX_INT_ENABLE) ? 1 : 0)); |
| 1086 | LOG(("Z80DART \"%s\" Channel %c : Status Affects Vector %u\n", m_device->tag(), 'A' + m_index, (data & WR1_STATUS_VECTOR) ? 1 : 0)); |
| 1087 | LOG(("Z80DART \"%s\" Channel %c : Wait/Ready Enable %u\n", m_device->tag(), 'A' + m_index, (data & WR1_WRDY_ENABLE) ? 1 : 0)); |
| 1048 | 1088 | |
| 1049 | | switch (data & Z80DART_WR1_RX_INT_ENABLE_MASK) |
| 1089 | switch (data & WR1_RX_INT_MODE_MASK) |
| 1050 | 1090 | { |
| 1051 | | case Z80DART_WR1_RX_INT_DISABLE: |
| 1091 | case WR1_RX_INT_DISABLE: |
| 1052 | 1092 | LOG(("Z80DART \"%s\" Channel %c : Receiver Interrupt Disabled\n", m_device->tag(), 'A' + m_index)); |
| 1053 | 1093 | break; |
| 1054 | 1094 | |
| 1055 | | case Z80DART_WR1_RX_INT_FIRST: |
| 1095 | case WR1_RX_INT_FIRST: |
| 1056 | 1096 | LOG(("Z80DART \"%s\" Channel %c : Receiver Interrupt on First Character\n", m_device->tag(), 'A' + m_index)); |
| 1057 | 1097 | break; |
| 1058 | 1098 | |
| 1059 | | case Z80DART_WR1_RX_INT_ALL_PARITY: |
| 1099 | case WR1_RX_INT_ALL_PARITY: |
| 1060 | 1100 | LOG(("Z80DART \"%s\" Channel %c : Receiver Interrupt on All Characters, Parity Affects Vector\n", m_device->tag(), 'A' + m_index)); |
| 1061 | 1101 | break; |
| 1062 | 1102 | |
| 1063 | | case Z80DART_WR1_RX_INT_ALL: |
| 1103 | case WR1_RX_INT_ALL: |
| 1064 | 1104 | LOG(("Z80DART \"%s\" Channel %c : Receiver Interrupt on All Characters\n", m_device->tag(), 'A' + m_index)); |
| 1065 | 1105 | break; |
| 1066 | 1106 | } |
| r8854 | r8855 | |
| 1075 | 1115 | break; |
| 1076 | 1116 | |
| 1077 | 1117 | case 3: |
| 1078 | | LOG(("Z80DART \"%s\" Channel %c : Receiver Enable %u\n", m_device->tag(), 'A' + m_index, (data & Z80DART_WR3_RX_ENABLE) ? 1 : 0)); |
| 1079 | | LOG(("Z80DART \"%s\" Channel %c : Auto Enables %u\n", m_device->tag(), 'A' + m_index, (data & Z80DART_WR3_AUTO_ENABLES) ? 1 : 0)); |
| 1118 | LOG(("Z80DART \"%s\" Channel %c : Receiver Enable %u\n", m_device->tag(), 'A' + m_index, (data & WR3_RX_ENABLE) ? 1 : 0)); |
| 1119 | LOG(("Z80DART \"%s\" Channel %c : Auto Enables %u\n", m_device->tag(), 'A' + m_index, (data & WR3_AUTO_ENABLES) ? 1 : 0)); |
| 1080 | 1120 | LOG(("Z80DART \"%s\" Channel %c : Receiver Bits/Character %u\n", m_device->tag(), 'A' + m_index, get_rx_word_length())); |
| 1081 | 1121 | break; |
| 1082 | 1122 | |
| 1083 | 1123 | case 4: |
| 1084 | | LOG(("Z80DART \"%s\" Channel %c : Parity Enable %u\n", m_device->tag(), 'A' + m_index, (data & Z80DART_WR4_PARITY_ENABLE) ? 1 : 0)); |
| 1085 | | LOG(("Z80DART \"%s\" Channel %c : Parity %s\n", m_device->tag(), 'A' + m_index, (data & Z80DART_WR4_PARITY_EVEN) ? "Even" : "Odd")); |
| 1124 | LOG(("Z80DART \"%s\" Channel %c : Parity Enable %u\n", m_device->tag(), 'A' + m_index, (data & WR4_PARITY_ENABLE) ? 1 : 0)); |
| 1125 | LOG(("Z80DART \"%s\" Channel %c : Parity %s\n", m_device->tag(), 'A' + m_index, (data & WR4_PARITY_EVEN) ? "Even" : "Odd")); |
| 1086 | 1126 | LOG(("Z80DART \"%s\" Channel %c : Stop Bits %f\n", m_device->tag(), 'A' + m_index, get_stop_bits())); |
| 1087 | 1127 | LOG(("Z80DART \"%s\" Channel %c : Clock Mode %uX\n", m_device->tag(), 'A' + m_index, get_clock_mode())); |
| 1088 | 1128 | break; |
| 1089 | 1129 | |
| 1090 | 1130 | case 5: |
| 1091 | | LOG(("Z80DART \"%s\" Channel %c : Transmitter Enable %u\n", m_device->tag(), 'A' + m_index, (data & Z80DART_WR5_TX_ENABLE) ? 1 : 0)); |
| 1131 | LOG(("Z80DART \"%s\" Channel %c : Transmitter Enable %u\n", m_device->tag(), 'A' + m_index, (data & WR5_TX_ENABLE) ? 1 : 0)); |
| 1092 | 1132 | LOG(("Z80DART \"%s\" Channel %c : Transmitter Bits/Character %u\n", m_device->tag(), 'A' + m_index, get_tx_word_length())); |
| 1093 | | LOG(("Z80DART \"%s\" Channel %c : Send Break %u\n", m_device->tag(), 'A' + m_index, (data & Z80DART_WR5_SEND_BREAK) ? 1 : 0)); |
| 1094 | | LOG(("Z80DART \"%s\" Channel %c : Request to Send %u\n", m_device->tag(), 'A' + m_index, (data & Z80DART_WR5_RTS) ? 1 : 0)); |
| 1095 | | LOG(("Z80DART \"%s\" Channel %c : Data Terminal Ready %u\n", m_device->tag(), 'A' + m_index, (data & Z80DART_WR5_DTR) ? 1 : 0)); |
| 1133 | LOG(("Z80DART \"%s\" Channel %c : Send Break %u\n", m_device->tag(), 'A' + m_index, (data & WR5_SEND_BREAK) ? 1 : 0)); |
| 1134 | LOG(("Z80DART \"%s\" Channel %c : Request to Send %u\n", m_device->tag(), 'A' + m_index, (data & WR5_RTS) ? 1 : 0)); |
| 1135 | LOG(("Z80DART \"%s\" Channel %c : Data Terminal Ready %u\n", m_device->tag(), 'A' + m_index, (data & WR5_DTR) ? 1 : 0)); |
| 1096 | 1136 | |
| 1097 | | if (data & Z80DART_WR5_RTS) |
| 1137 | if (data & WR5_RTS) |
| 1098 | 1138 | { |
| 1099 | 1139 | // when the RTS bit is set, the _RTS output goes low |
| 1100 | 1140 | RTS(0); |
| r8854 | r8855 | |
| 1108 | 1148 | } |
| 1109 | 1149 | |
| 1110 | 1150 | // data terminal ready output follows the state programmed into the DTR bit*/ |
| 1111 | | m_dtr = (data & Z80DART_WR5_DTR) ? 0 : 1; |
| 1151 | m_dtr = (data & WR5_DTR) ? 0 : 1; |
| 1112 | 1152 | DTR(m_dtr); |
| 1113 | 1153 | break; |
| 1154 | |
| 1155 | case 6: |
| 1156 | LOG(("Z80DART \"%s\" Channel %c : Transmit Sync %02x\n", m_device->tag(), 'A' + m_index, data)); |
| 1157 | m_sync = (m_sync & 0xff00) | data; |
| 1158 | break; |
| 1159 | |
| 1160 | case 7: |
| 1161 | LOG(("Z80DART \"%s\" Channel %c : Receive Sync %02x\n", m_device->tag(), 'A' + m_index, data)); |
| 1162 | m_sync = (data << 8) | (m_sync & 0xff); |
| 1163 | break; |
| 1114 | 1164 | } |
| 1115 | 1165 | } |
| 1116 | 1166 | |
| r8854 | r8855 | |
| 1129 | 1179 | data = m_rx_data_fifo[m_rx_fifo]; |
| 1130 | 1180 | |
| 1131 | 1181 | // load error status from the FIFO, retain overrun and parity errors |
| 1132 | | m_rr[1] = (m_rr[1] & (Z80DART_RR1_RX_OVERRUN_ERROR | Z80DART_RR1_PARITY_ERROR)) | m_rx_error_fifo[m_rx_fifo]; |
| 1182 | m_rr[1] = (m_rr[1] & (RR1_RX_OVERRUN_ERROR | RR1_PARITY_ERROR)) | m_rx_error_fifo[m_rx_fifo]; |
| 1133 | 1183 | |
| 1134 | 1184 | // decrease FIFO pointer |
| 1135 | 1185 | m_rx_fifo--; |
| r8854 | r8855 | |
| 1137 | 1187 | if (m_rx_fifo < 0) |
| 1138 | 1188 | { |
| 1139 | 1189 | // no more characters available in the FIFO |
| 1140 | | m_rr[0] &= ~ Z80DART_RR0_RX_CHAR_AVAILABLE; |
| 1190 | m_rr[0] &= ~ RR0_RX_CHAR_AVAILABLE; |
| 1141 | 1191 | } |
| 1142 | 1192 | } |
| 1143 | 1193 | |
| r8854 | r8855 | |
| 1155 | 1205 | { |
| 1156 | 1206 | m_tx_data = data; |
| 1157 | 1207 | |
| 1158 | | m_rr[0] &= ~Z80DART_RR0_TX_BUFFER_EMPTY; |
| 1159 | | m_rr[1] &= ~Z80DART_RR1_ALL_SENT; |
| 1208 | m_rr[0] &= ~RR0_TX_BUFFER_EMPTY; |
| 1209 | m_rr[1] &= ~RR1_ALL_SENT; |
| 1160 | 1210 | |
| 1161 | 1211 | LOG(("Z80DART \"%s\" Channel %c : Data Register Write '%02x'\n", m_device->tag(), 'A' + m_index, data)); |
| 1162 | 1212 | } |
| r8854 | r8855 | |
| 1173 | 1223 | if (m_rx_fifo == 2) |
| 1174 | 1224 | { |
| 1175 | 1225 | // receive overrun error detected |
| 1176 | | m_rx_error |= Z80DART_RR1_RX_OVERRUN_ERROR; |
| 1226 | m_rx_error |= RR1_RX_OVERRUN_ERROR; |
| 1177 | 1227 | |
| 1178 | | switch (m_wr[1] & Z80DART_WR1_RX_INT_ENABLE_MASK) |
| 1228 | switch (m_wr[1] & WR1_RX_INT_MODE_MASK) |
| 1179 | 1229 | { |
| 1180 | | case Z80DART_WR1_RX_INT_FIRST: |
| 1230 | case WR1_RX_INT_FIRST: |
| 1181 | 1231 | if (!m_rx_first) |
| 1182 | 1232 | { |
| 1183 | 1233 | take_interrupt(INT_SPECIAL); |
| 1184 | 1234 | } |
| 1185 | 1235 | break; |
| 1186 | 1236 | |
| 1187 | | case Z80DART_WR1_RX_INT_ALL_PARITY: |
| 1188 | | case Z80DART_WR1_RX_INT_ALL: |
| 1237 | case WR1_RX_INT_ALL_PARITY: |
| 1238 | case WR1_RX_INT_ALL: |
| 1189 | 1239 | take_interrupt(INT_SPECIAL); |
| 1190 | 1240 | break; |
| 1191 | 1241 | } |
| r8854 | r8855 | |
| 1199 | 1249 | m_rx_data_fifo[m_rx_fifo] = data; |
| 1200 | 1250 | m_rx_error_fifo[m_rx_fifo] = m_rx_error; |
| 1201 | 1251 | |
| 1202 | | m_rr[0] |= Z80DART_RR0_RX_CHAR_AVAILABLE; |
| 1252 | m_rr[0] |= RR0_RX_CHAR_AVAILABLE; |
| 1203 | 1253 | |
| 1204 | 1254 | // receive interrupt |
| 1205 | | switch (m_wr[1] & Z80DART_WR1_RX_INT_ENABLE_MASK) |
| 1255 | switch (m_wr[1] & WR1_RX_INT_MODE_MASK) |
| 1206 | 1256 | { |
| 1207 | | case Z80DART_WR1_RX_INT_FIRST: |
| 1257 | case WR1_RX_INT_FIRST: |
| 1208 | 1258 | if (m_rx_first) |
| 1209 | 1259 | { |
| 1210 | 1260 | take_interrupt(INT_RECEIVE); |
| r8854 | r8855 | |
| 1213 | 1263 | } |
| 1214 | 1264 | break; |
| 1215 | 1265 | |
| 1216 | | case Z80DART_WR1_RX_INT_ALL_PARITY: |
| 1217 | | case Z80DART_WR1_RX_INT_ALL: |
| 1266 | case WR1_RX_INT_ALL_PARITY: |
| 1267 | case WR1_RX_INT_ALL: |
| 1218 | 1268 | take_interrupt(INT_RECEIVE); |
| 1219 | 1269 | break; |
| 1220 | 1270 | } |
| r8854 | r8855 | |
| 1233 | 1283 | { |
| 1234 | 1284 | // enable transmitter if in auto enables mode |
| 1235 | 1285 | if (!state) |
| 1236 | | if (m_wr[3] & Z80DART_WR3_AUTO_ENABLES) |
| 1237 | | m_wr[5] |= Z80DART_WR5_TX_ENABLE; |
| 1286 | if (m_wr[3] & WR3_AUTO_ENABLES) |
| 1287 | m_wr[5] |= WR5_TX_ENABLE; |
| 1238 | 1288 | |
| 1239 | 1289 | // set clear to send |
| 1240 | 1290 | m_cts = state; |
| r8854 | r8855 | |
| 1242 | 1292 | if (!m_rx_rr0_latch) |
| 1243 | 1293 | { |
| 1244 | 1294 | if (!m_cts) |
| 1245 | | m_rr[0] |= Z80DART_RR0_CTS; |
| 1295 | m_rr[0] |= RR0_CTS; |
| 1246 | 1296 | else |
| 1247 | | m_rr[0] &= ~Z80DART_RR0_CTS; |
| 1297 | m_rr[0] &= ~RR0_CTS; |
| 1248 | 1298 | |
| 1249 | 1299 | // trigger interrupt |
| 1250 | | if (m_wr[1] & Z80DART_WR1_EXT_INT_ENABLE) |
| 1300 | if (m_wr[1] & WR1_EXT_INT_ENABLE) |
| 1251 | 1301 | { |
| 1252 | 1302 | // trigger interrupt |
| 1253 | 1303 | take_interrupt(INT_EXTERNAL); |
| r8854 | r8855 | |
| 1272 | 1322 | { |
| 1273 | 1323 | // enable receiver if in auto enables mode |
| 1274 | 1324 | if (!state) |
| 1275 | | if (m_wr[3] & Z80DART_WR3_AUTO_ENABLES) |
| 1276 | | m_wr[3] |= Z80DART_WR3_RX_ENABLE; |
| 1325 | if (m_wr[3] & WR3_AUTO_ENABLES) |
| 1326 | m_wr[3] |= WR3_RX_ENABLE; |
| 1277 | 1327 | |
| 1278 | 1328 | // set data carrier detect |
| 1279 | 1329 | m_dcd = state; |
| r8854 | r8855 | |
| 1281 | 1331 | if (!m_rx_rr0_latch) |
| 1282 | 1332 | { |
| 1283 | 1333 | if (m_dcd) |
| 1284 | | m_rr[0] |= Z80DART_RR0_DCD; |
| 1334 | m_rr[0] |= RR0_DCD; |
| 1285 | 1335 | else |
| 1286 | | m_rr[0] &= ~Z80DART_RR0_DCD; |
| 1336 | m_rr[0] &= ~RR0_DCD; |
| 1287 | 1337 | |
| 1288 | | if (m_wr[1] & Z80DART_WR1_EXT_INT_ENABLE) |
| 1338 | if (m_wr[1] & WR1_EXT_INT_ENABLE) |
| 1289 | 1339 | { |
| 1290 | 1340 | // trigger interrupt |
| 1291 | 1341 | take_interrupt(INT_EXTERNAL); |
| r8854 | r8855 | |
| 1314 | 1364 | if (!m_rx_rr0_latch) |
| 1315 | 1365 | { |
| 1316 | 1366 | if (m_ri) |
| 1317 | | m_rr[0] |= Z80DART_RR0_RI; |
| 1367 | m_rr[0] |= RR0_RI; |
| 1318 | 1368 | else |
| 1319 | | m_rr[0] &= ~Z80DART_RR0_RI; |
| 1369 | m_rr[0] &= ~RR0_RI; |
| 1320 | 1370 | |
| 1321 | | if (m_wr[1] & Z80DART_WR1_EXT_INT_ENABLE) |
| 1371 | if (m_wr[1] & WR1_EXT_INT_ENABLE) |
| 1322 | 1372 | { |
| 1323 | 1373 | // trigger interrupt |
| 1324 | 1374 | take_interrupt(INT_EXTERNAL); |
| r8854 | r8855 | |
| 1394 | 1444 | WRITE8_DEVICE_HANDLER( z80dart_c_w ) { downcast<z80dart_device *>(device)->control_write(offset & 1, data); } |
| 1395 | 1445 | WRITE8_DEVICE_HANDLER( z80dart_d_w ) { downcast<z80dart_device *>(device)->data_write(offset & 1, data); } |
| 1396 | 1446 | |
| 1397 | | WRITE_LINE_DEVICE_HANDLER( z80dart_ctsa_w ) { downcast<z80dart_device *>(device)->cts_w(Z80DART_CH_A, state); } |
| 1398 | | WRITE_LINE_DEVICE_HANDLER( z80dart_ctsb_w ) { downcast<z80dart_device *>(device)->cts_w(Z80DART_CH_B, state); } |
| 1399 | | WRITE_LINE_DEVICE_HANDLER( z80dart_dcda_w ) { downcast<z80dart_device *>(device)->dcd_w(Z80DART_CH_A, state); } |
| 1400 | | WRITE_LINE_DEVICE_HANDLER( z80dart_dcdb_w ) { downcast<z80dart_device *>(device)->dcd_w(Z80DART_CH_B, state); } |
| 1401 | | WRITE_LINE_DEVICE_HANDLER( z80dart_ria_w ) { downcast<z80dart_device *>(device)->ri_w(Z80DART_CH_A, state); } |
| 1402 | | WRITE_LINE_DEVICE_HANDLER( z80dart_rib_w ) { downcast<z80dart_device *>(device)->ri_w(Z80DART_CH_B, state); } |
| 1403 | | WRITE_LINE_DEVICE_HANDLER( z80dart_synca_w ) { downcast<z80dart_device *>(device)->sync_w(Z80DART_CH_A, state); } |
| 1404 | | WRITE_LINE_DEVICE_HANDLER( z80dart_syncb_w ) { downcast<z80dart_device *>(device)->sync_w(Z80DART_CH_B, state); } |
| 1447 | WRITE_LINE_DEVICE_HANDLER( z80dart_ctsa_w ) { downcast<z80dart_device *>(device)->cts_w(CHANNEL_A, state); } |
| 1448 | WRITE_LINE_DEVICE_HANDLER( z80dart_ctsb_w ) { downcast<z80dart_device *>(device)->cts_w(CHANNEL_B, state); } |
| 1449 | WRITE_LINE_DEVICE_HANDLER( z80dart_dcda_w ) { downcast<z80dart_device *>(device)->dcd_w(CHANNEL_A, state); } |
| 1450 | WRITE_LINE_DEVICE_HANDLER( z80dart_dcdb_w ) { downcast<z80dart_device *>(device)->dcd_w(CHANNEL_B, state); } |
| 1451 | WRITE_LINE_DEVICE_HANDLER( z80dart_ria_w ) { downcast<z80dart_device *>(device)->ri_w(CHANNEL_A, state); } |
| 1452 | WRITE_LINE_DEVICE_HANDLER( z80dart_rib_w ) { downcast<z80dart_device *>(device)->ri_w(CHANNEL_B, state); } |
| 1453 | WRITE_LINE_DEVICE_HANDLER( z80dart_synca_w ) { downcast<z80dart_device *>(device)->sync_w(CHANNEL_A, state); } |
| 1454 | WRITE_LINE_DEVICE_HANDLER( z80dart_syncb_w ) { downcast<z80dart_device *>(device)->sync_w(CHANNEL_B, state); } |
| 1405 | 1455 | |
| 1406 | | WRITE_LINE_DEVICE_HANDLER( z80dart_rxca_w ) { downcast<z80dart_device *>(device)->rx_w(Z80DART_CH_A, state); } |
| 1407 | | WRITE_LINE_DEVICE_HANDLER( z80dart_txca_w ) { downcast<z80dart_device *>(device)->tx_w(Z80DART_CH_A, state); } |
| 1408 | | WRITE_LINE_DEVICE_HANDLER( z80dart_rxcb_w ) { downcast<z80dart_device *>(device)->rx_w(Z80DART_CH_B, state); } |
| 1409 | | WRITE_LINE_DEVICE_HANDLER( z80dart_txcb_w ) { downcast<z80dart_device *>(device)->tx_w(Z80DART_CH_B, state); } |
| 1410 | | WRITE_LINE_DEVICE_HANDLER( z80dart_rxtxcb_w ) { downcast<z80dart_device *>(device)->rx_w(Z80DART_CH_B, state); downcast<z80dart_device *>(device)->tx_w(Z80DART_CH_B, state); } |
| 1456 | WRITE_LINE_DEVICE_HANDLER( z80dart_rxca_w ) { downcast<z80dart_device *>(device)->rx_w(CHANNEL_A, state); } |
| 1457 | WRITE_LINE_DEVICE_HANDLER( z80dart_txca_w ) { downcast<z80dart_device *>(device)->tx_w(CHANNEL_A, state); } |
| 1458 | WRITE_LINE_DEVICE_HANDLER( z80dart_rxcb_w ) { downcast<z80dart_device *>(device)->rx_w(CHANNEL_B, state); } |
| 1459 | WRITE_LINE_DEVICE_HANDLER( z80dart_txcb_w ) { downcast<z80dart_device *>(device)->tx_w(CHANNEL_B, state); } |
| 1460 | WRITE_LINE_DEVICE_HANDLER( z80dart_rxtxcb_w ) { downcast<z80dart_device *>(device)->rx_w(CHANNEL_B, state); downcast<z80dart_device *>(device)->tx_w(CHANNEL_B, state); } |
| 1411 | 1461 | |
| 1412 | 1462 | READ8_DEVICE_HANDLER( z80dart_cd_ba_r ) |
| 1413 | 1463 | { |
| r8854 | r8855 | |
| 1443 | 1493 | const device_type Z80SIO0 = z80dart_device_config::static_alloc_device_config; // FIXME |
| 1444 | 1494 | const device_type Z80SIO1 = z80dart_device_config::static_alloc_device_config; // FIXME |
| 1445 | 1495 | const device_type Z80SIO2 = z80dart_device_config::static_alloc_device_config; // FIXME |
| 1496 | const device_type Z80SIO3 = z80dart_device_config::static_alloc_device_config; // FIXME |
| 1497 | const device_type Z80SIO4 = z80dart_device_config::static_alloc_device_config; // FIXME |