src/emu/cpu/m6800/m6800.c
| r1137 | r1138 | |
| 112 | 112 | PAIR output_compare; /* output compare */ |
| 113 | 113 | UINT16 input_capture; /* input capture */ |
| 114 | 114 | |
| 115 | int clock; |
| 116 | UINT8 trcsr, rmcr, rdr, tdr, rsr, tsr; |
| 117 | int rxbits, txbits, txstate, trcsr_read, tx; |
| 118 | |
| 115 | 119 | PAIR timer_over; |
| 116 | 120 | } m6800_Regs; |
| 117 | 121 | |
| 118 | 122 | /* 680x registers */ |
| 119 | 123 | static m6800_Regs m6800; |
| 120 | 124 | |
| 125 | static mame_timer *m6800_rx_timer; |
| 126 | static mame_timer *m6800_tx_timer; |
| 127 | |
| 121 | 128 | #define m6801 m6800 |
| 122 | 129 | #define m6802 m6800 |
| 123 | 130 | #define m6803 m6800 |
| r1137 | r1138 | |
| 197 | 204 | SET_TIMER_EVENT; \ |
| 198 | 205 | } |
| 199 | 206 | |
| 207 | // serial I/O |
| 208 | |
| 209 | #define M6800_RMCR_SS_MASK 0x03 // Speed Select |
| 210 | #define M6800_RMCR_SS_4096 0x03 // E / 4096 |
| 211 | #define M6800_RMCR_SS_1024 0x02 // E / 1024 |
| 212 | #define M6800_RMCR_SS_128 0x01 // E / 128 |
| 213 | #define M6800_RMCR_SS_16 0x00 // E / 16 |
| 214 | #define M6800_RMCR_CC_MASK 0x0c // Clock Control/Format Select |
| 215 | |
| 216 | #define M6800_TRCSR_RDRF 0x80 // Receive Data Register Full |
| 217 | #define M6800_TRCSR_ORFE 0x40 // Over Run Framing Error |
| 218 | #define M6800_TRCSR_TDRE 0x20 // Transmit Data Register Empty |
| 219 | #define M6800_TRCSR_RIE 0x10 // Receive Interrupt Enable |
| 220 | #define M6800_TRCSR_RE 0x08 // Receive Enable |
| 221 | #define M6800_TRCSR_TIE 0x04 // Transmit Interrupt Enable |
| 222 | #define M6800_TRCSR_TE 0x02 // Transmit Enable |
| 223 | #define M6800_TRCSR_WU 0x01 // Wake Up |
| 224 | |
| 225 | #define M6800_PORT2_IO4 0x10 |
| 226 | #define M6800_PORT2_IO3 0x08 |
| 227 | |
| 228 | static const int M6800_RMCR_SS[] = { 16, 128, 1024, 4096 }; |
| 229 | |
| 230 | #define M6800_SERIAL_START 0 |
| 231 | #define M6800_SERIAL_STOP 9 |
| 232 | |
| 233 | enum |
| 234 | { |
| 235 | M6800_TX_STATE_INIT = 0, |
| 236 | M6800_TX_STATE_READY |
| 237 | }; |
| 238 | |
| 200 | 239 | /* take interrupt */ |
| 201 | 240 | #define TAKE_ICI ENTER_INTERRUPT("M6800#%d take ICI\n",0xfff6) |
| 202 | 241 | #define TAKE_OCI ENTER_INTERRUPT("M6800#%d take OCI\n",0xfff4) |
| r1137 | r1138 | |
| 204 | 243 | #define TAKE_SCI ENTER_INTERRUPT("M6800#%d take SCI\n",0xfff0) |
| 205 | 244 | #define TAKE_TRAP ENTER_INTERRUPT("M6800#%d take TRAP\n",0xffee) |
| 206 | 245 | |
| 207 | | /* check IRQ2 (internal irq) */ |
| 208 | | #define CHECK_IRQ2 { \ |
| 209 | | if(m6800.irq2&(TCSR_ICF|TCSR_OCF|TCSR_TOF)) \ |
| 210 | | { \ |
| 211 | | if(m6800.irq2&TCSR_ICF) \ |
| 212 | | { \ |
| 213 | | TAKE_ICI; \ |
| 214 | | if( m6800.irq_callback ) \ |
| 215 | | (void)(*m6800.irq_callback)(M6800_TIN_LINE); \ |
| 216 | | } \ |
| 217 | | else if(m6800.irq2&TCSR_OCF) \ |
| 218 | | { \ |
| 219 | | TAKE_OCI; \ |
| 220 | | } \ |
| 221 | | else if(m6800.irq2&TCSR_TOF) \ |
| 222 | | { \ |
| 223 | | TAKE_TOI; \ |
| 224 | | } \ |
| 225 | | } \ |
| 226 | | } |
| 227 | | |
| 228 | 246 | /* operate one instruction for */ |
| 229 | 247 | #define ONE_MORE_INSN() { \ |
| 230 | 248 | UINT8 ireg; \ |
| r1137 | r1138 | |
| 247 | 265 | (void)(*m6800.irq_callback)(M6800_IRQ_LINE); \ |
| 248 | 266 | } \ |
| 249 | 267 | else \ |
| 250 | | CHECK_IRQ2; \ |
| 268 | m6800_check_irq2(); \ |
| 251 | 269 | } \ |
| 252 | 270 | } |
| 253 | 271 | |
| r1137 | r1138 | |
| 511 | 529 | CHANGE_PC(); |
| 512 | 530 | } |
| 513 | 531 | |
| 532 | void m6800_check_irq2(void) |
| 533 | { |
| 534 | if ((m6800.tcsr & (TCSR_EICI|TCSR_ICF)) == (TCSR_EICI|TCSR_ICF)) |
| 535 | { |
| 536 | TAKE_ICI; |
| 537 | if( m6800.irq_callback ) |
| 538 | (void)(*m6800.irq_callback)(M6800_TIN_LINE); |
| 539 | } |
| 540 | else if ((m6800.tcsr & (TCSR_EOCI|TCSR_OCF)) == (TCSR_EOCI|TCSR_OCF)) |
| 541 | { |
| 542 | TAKE_OCI; |
| 543 | } |
| 544 | else if ((m6800.tcsr & (TCSR_ETOI|TCSR_TOF)) == (TCSR_ETOI|TCSR_TOF)) |
| 545 | { |
| 546 | TAKE_TOI; |
| 547 | } |
| 548 | else if (((m6800.trcsr & (M6800_TRCSR_RIE|M6800_TRCSR_RDRF)) == (M6800_TRCSR_RIE|M6800_TRCSR_RDRF)) || |
| 549 | ((m6800.trcsr & (M6800_TRCSR_RIE|M6800_TRCSR_ORFE)) == (M6800_TRCSR_RIE|M6800_TRCSR_ORFE)) || |
| 550 | ((m6800.trcsr & (M6800_TRCSR_TIE|M6800_TRCSR_TDRE)) == (M6800_TRCSR_TIE|M6800_TRCSR_TDRE))) |
| 551 | { |
| 552 | TAKE_SCI; |
| 553 | } |
| 554 | } |
| 555 | |
| 514 | 556 | /* check OCI or TOI */ |
| 515 | 557 | static void check_timer_event(void) |
| 516 | 558 | { |
| r1137 | r1138 | |
| 547 | 589 | /* include the opcode functions */ |
| 548 | 590 | #include "6800ops.c" |
| 549 | 591 | |
| 592 | static void m6800_tx(int value) |
| 593 | { |
| 594 | m6800.port2_data = (m6800.port2_data & 0xef) | (value << 4); |
| 595 | |
| 596 | if(m6800.port2_ddr == 0xff) |
| 597 | io_write_byte_8(M6803_PORT2,m6800.port2_data); |
| 598 | else |
| 599 | io_write_byte_8(M6803_PORT2,(m6800.port2_data & m6800.port2_ddr) |
| 600 | | (io_read_byte_8(M6803_PORT2) & (m6800.port2_ddr ^ 0xff))); |
| 601 | } |
| 602 | |
| 603 | static int m6800_rx(void) |
| 604 | { |
| 605 | return (io_read_byte_8(M6803_PORT2) & M6800_PORT2_IO3) >> 3; |
| 606 | } |
| 607 | |
| 608 | static TIMER_CALLBACK(m6800_tx_tick) |
| 609 | { |
| 610 | int cpunum = param; |
| 611 | |
| 612 | if (m6800.trcsr & M6800_TRCSR_TE) |
| 613 | { |
| 614 | // force Port 2 bit 4 as output |
| 615 | m6800.port2_ddr |= M6800_PORT2_IO4; |
| 616 | |
| 617 | switch (m6800.txstate) |
| 618 | { |
| 619 | case M6800_TX_STATE_INIT: |
| 620 | m6800.tx = 1; |
| 621 | m6800.txbits++; |
| 622 | |
| 623 | if (m6800.txbits == 10) |
| 624 | { |
| 625 | m6800.txstate = M6800_TX_STATE_READY; |
| 626 | m6800.txbits = M6800_SERIAL_START; |
| 627 | } |
| 628 | break; |
| 629 | |
| 630 | case M6800_TX_STATE_READY: |
| 631 | switch (m6800.txbits) |
| 632 | { |
| 633 | case M6800_SERIAL_START: |
| 634 | if (m6800.trcsr & M6800_TRCSR_TDRE) |
| 635 | { |
| 636 | // transmit buffer is empty, send consecutive '1's |
| 637 | m6800.tx = 1; |
| 638 | } |
| 639 | else |
| 640 | { |
| 641 | // transmit buffer is full, send data |
| 642 | |
| 643 | // load TDR to shift register |
| 644 | m6800.tsr = m6800.tdr; |
| 645 | |
| 646 | // transmit buffer is empty, set TDRE flag |
| 647 | m6800.trcsr |= M6800_TRCSR_TDRE; |
| 648 | |
| 649 | // send start bit '0' |
| 650 | m6800.tx = 0; |
| 651 | |
| 652 | m6800.txbits++; |
| 653 | } |
| 654 | break; |
| 655 | |
| 656 | case M6800_SERIAL_STOP: |
| 657 | // send stop bit '1' |
| 658 | m6800.tx = 1; |
| 659 | |
| 660 | cpuintrf_push_context(cpunum); |
| 661 | CHECK_IRQ_LINES(); |
| 662 | cpuintrf_pop_context(); |
| 663 | |
| 664 | m6800.txbits = M6800_SERIAL_START; |
| 665 | break; |
| 666 | |
| 667 | default: |
| 668 | // send data bit '0' or '1' |
| 669 | m6800.tx = m6800.tsr & 0x01; |
| 670 | |
| 671 | // shift transmit register |
| 672 | m6800.tsr >>= 1; |
| 673 | |
| 674 | m6800.txbits++; |
| 675 | break; |
| 676 | } |
| 677 | break; |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | m6800_tx(m6800.tx); |
| 682 | } |
| 683 | |
| 684 | static TIMER_CALLBACK(m6800_rx_tick) |
| 685 | { |
| 686 | int cpunum = param; |
| 687 | |
| 688 | if (m6800.trcsr & M6800_TRCSR_RE) |
| 689 | { |
| 690 | if (m6800.trcsr & M6800_TRCSR_WU) |
| 691 | { |
| 692 | // wait for 10 bits of '1' |
| 693 | |
| 694 | if (m6800_rx() == 1) |
| 695 | { |
| 696 | m6800.rxbits++; |
| 697 | |
| 698 | if (m6800.rxbits == 10) |
| 699 | { |
| 700 | m6800.trcsr &= ~M6800_TRCSR_WU; |
| 701 | m6800.rxbits = M6800_SERIAL_START; |
| 702 | } |
| 703 | } |
| 704 | else |
| 705 | { |
| 706 | m6800.rxbits = M6800_SERIAL_START; |
| 707 | } |
| 708 | } |
| 709 | else |
| 710 | { |
| 711 | // receive data |
| 712 | |
| 713 | switch (m6800.rxbits) |
| 714 | { |
| 715 | case M6800_SERIAL_START: |
| 716 | if (m6800_rx() == 0) |
| 717 | { |
| 718 | // start bit found |
| 719 | m6800.rxbits++; |
| 720 | } |
| 721 | break; |
| 722 | |
| 723 | case M6800_SERIAL_STOP: |
| 724 | if (m6800_rx() == 1) |
| 725 | { |
| 726 | if (m6800.trcsr & M6800_TRCSR_RDRF) |
| 727 | { |
| 728 | // overrun error |
| 729 | |
| 730 | m6800.trcsr |= M6800_TRCSR_ORFE; |
| 731 | |
| 732 | cpuintrf_push_context(cpunum); |
| 733 | CHECK_IRQ_LINES(); |
| 734 | cpuintrf_pop_context(); |
| 735 | } |
| 736 | else |
| 737 | { |
| 738 | if (!(m6800.trcsr & M6800_TRCSR_ORFE)) |
| 739 | { |
| 740 | // transfer data into receive register |
| 741 | m6800.rdr = m6800.rsr; |
| 742 | |
| 743 | // set RDRF flag |
| 744 | m6800.trcsr |= M6800_TRCSR_RDRF; |
| 745 | |
| 746 | cpuintrf_push_context(cpunum); |
| 747 | CHECK_IRQ_LINES(); |
| 748 | cpuintrf_pop_context(); |
| 749 | } |
| 750 | } |
| 751 | } |
| 752 | else |
| 753 | { |
| 754 | // framing error |
| 755 | |
| 756 | if (!(m6800.trcsr & M6800_TRCSR_ORFE)) |
| 757 | { |
| 758 | // transfer unframed data into receive register |
| 759 | m6800.rdr = m6800.rsr; |
| 760 | } |
| 761 | |
| 762 | m6800.trcsr |= M6800_TRCSR_ORFE; |
| 763 | m6800.trcsr &= ~M6800_TRCSR_RDRF; |
| 764 | |
| 765 | cpuintrf_push_context(cpunum); |
| 766 | CHECK_IRQ_LINES(); |
| 767 | cpuintrf_pop_context(); |
| 768 | } |
| 769 | |
| 770 | m6800.rxbits = M6800_SERIAL_START; |
| 771 | break; |
| 772 | |
| 773 | default: |
| 774 | // shift receive register |
| 775 | m6800.rsr >>= 1; |
| 776 | |
| 777 | // receive bit into register |
| 778 | m6800.rsr |= (m6800_rx() << 7); |
| 779 | |
| 780 | m6800.rxbits++; |
| 781 | break; |
| 782 | } |
| 783 | } |
| 784 | } |
| 785 | } |
| 786 | |
| 550 | 787 | /**************************************************************************** |
| 551 | 788 | * Reset registers to their initial values |
| 552 | 789 | ****************************************************************************/ |
| r1137 | r1138 | |
| 609 | 846 | OCD = 0xffff; |
| 610 | 847 | TOD = 0xffff; |
| 611 | 848 | m6800.ram_ctrl |= 0x40; |
| 849 | |
| 850 | #if (HAS_HD63701) |
| 851 | m6800.trcsr = M6800_TRCSR_TDRE; |
| 852 | m6800.rmcr = 0; |
| 853 | mame_timer_enable(m6800_rx_timer, 0); |
| 854 | mame_timer_enable(m6800_tx_timer, 0); |
| 855 | m6800.txstate = M6800_TX_STATE_INIT; |
| 856 | m6800.txbits = m6800.rxbits = 0; |
| 857 | m6800.trcsr_read = 0; |
| 858 | #endif |
| 612 | 859 | } |
| 613 | 860 | |
| 614 | 861 | /**************************************************************************** |
| r1137 | r1138 | |
| 676 | 923 | m6800.input_capture = CT; |
| 677 | 924 | MODIFIED_tcsr; |
| 678 | 925 | if( !(CC & 0x10) ) |
| 679 | | CHECK_IRQ2 |
| 926 | m6800_check_irq2(); |
| 680 | 927 | break; |
| 681 | 928 | default: |
| 682 | 929 | return; |
| r1137 | r1138 | |
| 1348 | 1595 | * HD63701 similiar to the M6800 |
| 1349 | 1596 | ****************************************************************************/ |
| 1350 | 1597 | #if (HAS_HD63701) |
| 1598 | |
| 1351 | 1599 | static void hd63701_init(int index, int clock, const void *config, int (*irqcallback)(int)) |
| 1352 | 1600 | { |
| 1353 | 1601 | // m6800.subtype = SUBTYPE_HD63701; |
| 1354 | 1602 | m6800.insn = hd63701_insn; |
| 1355 | 1603 | m6800.cycles = cycles_63701; |
| 1356 | 1604 | m6800.irq_callback = irqcallback; |
| 1605 | |
| 1606 | m6800.clock = clock; |
| 1607 | m6800_rx_timer = mame_timer_alloc(m6800_rx_tick); |
| 1608 | m6800_tx_timer = mame_timer_alloc(m6800_tx_tick); |
| 1609 | |
| 1357 | 1610 | state_register("hd63701", index); |
| 1358 | 1611 | } |
| 1359 | 1612 | /**************************************************************************** |
| r1137 | r1138 | |
| 2012 | 2265 | | (m6800.port4_data & m6800.port4_ddr); |
| 2013 | 2266 | case 0x08: |
| 2014 | 2267 | m6800.pending_tcsr = 0; |
| 2015 | | //logerror("CPU #%d PC %04x: warning - read TCSR register\n",cpu_getactivecpu(),activecpu_get_pc()); |
| 2016 | 2268 | return m6800.tcsr; |
| 2017 | 2269 | case 0x09: |
| 2018 | 2270 | if(!(m6800.pending_tcsr&TCSR_TOF)) |
| r1137 | r1138 | |
| 2047 | 2299 | case 0x0e: |
| 2048 | 2300 | return (m6800.input_capture >> 8) & 0xff; |
| 2049 | 2301 | case 0x0f: |
| 2302 | logerror("CPU #%d PC %04x: warning - read from unsupported register %02x\n",cpu_getactivecpu(),activecpu_get_pc(),offset); |
| 2303 | return 0; |
| 2050 | 2304 | case 0x10: |
| 2305 | return m6800.rmcr; |
| 2051 | 2306 | case 0x11: |
| 2307 | m6800.trcsr_read = 1; |
| 2308 | return m6800.trcsr; |
| 2052 | 2309 | case 0x12: |
| 2310 | if (m6800.trcsr_read) |
| 2311 | { |
| 2312 | m6800.trcsr_read = 0; |
| 2313 | m6800.trcsr = m6800.trcsr & 0x3f; |
| 2314 | } |
| 2315 | return m6800.rdr; |
| 2053 | 2316 | case 0x13: |
| 2054 | | logerror("CPU #%d PC %04x: warning - read from unsupported internal register %02x\n",cpu_getactivecpu(),activecpu_get_pc(),offset); |
| 2055 | | return 0; |
| 2317 | return m6800.tdr; |
| 2056 | 2318 | case 0x14: |
| 2057 | 2319 | logerror("CPU #%d PC %04x: read RAM control register\n",cpu_getactivecpu(),activecpu_get_pc()); |
| 2058 | 2320 | return m6800.ram_ctrl; |
| r1137 | r1138 | |
| 2113 | 2375 | | (io_read_byte_8(M6803_PORT1) & (m6800.port1_ddr ^ 0xff))); |
| 2114 | 2376 | break; |
| 2115 | 2377 | case 0x03: |
| 2116 | | m6800.port2_data = data; |
| 2117 | | m6800.port2_ddr = data; |
| 2378 | m6800.port2_data = (m6800.port2_data & 0xef) | (m6800.tx << 4); |
| 2118 | 2379 | if(m6800.port2_ddr == 0xff) |
| 2119 | 2380 | io_write_byte_8(M6803_PORT2,m6800.port2_data); |
| 2120 | 2381 | else |
| r1137 | r1138 | |
| 2164 | 2425 | m6800.pending_tcsr &= m6800.tcsr; |
| 2165 | 2426 | MODIFIED_tcsr; |
| 2166 | 2427 | if( !(CC & 0x10) ) |
| 2167 | | CHECK_IRQ2; |
| 2168 | | //logerror("CPU #%d PC %04x: TCSR = %02x\n",cpu_getactivecpu(),activecpu_get_pc(),data); |
| 2428 | m6800_check_irq2(); |
| 2169 | 2429 | break; |
| 2170 | 2430 | case 0x09: |
| 2171 | 2431 | latch09 = data & 0xff; /* 6301 only */ |
| r1137 | r1138 | |
| 2194 | 2454 | break; |
| 2195 | 2455 | case 0x0d: |
| 2196 | 2456 | case 0x0e: |
| 2457 | case 0x12: |
| 2197 | 2458 | logerror("CPU #%d PC %04x: warning - write %02x to read only internal register %02x\n",cpu_getactivecpu(),activecpu_get_pc(),data,offset); |
| 2198 | 2459 | break; |
| 2199 | 2460 | case 0x0f: |
| 2461 | logerror("CPU #%d PC %04x: warning - write %02x to unsupported internal register %02x\n",cpu_getactivecpu(),activecpu_get_pc(),data,offset); |
| 2462 | break; |
| 2200 | 2463 | case 0x10: |
| 2464 | m6800.rmcr = data & 0x0f; |
| 2465 | |
| 2466 | switch ((m6800.rmcr & M6800_RMCR_CC_MASK) >> 2) |
| 2467 | { |
| 2468 | case 0: |
| 2469 | case 3: // not implemented |
| 2470 | mame_timer_enable(m6800_rx_timer, 0); |
| 2471 | mame_timer_enable(m6800_tx_timer, 0); |
| 2472 | break; |
| 2473 | |
| 2474 | case 1: |
| 2475 | case 2: |
| 2476 | { |
| 2477 | int divisor = M6800_RMCR_SS[m6800.rmcr & M6800_RMCR_SS_MASK]; |
| 2478 | |
| 2479 | mame_timer_adjust(m6800_rx_timer, time_zero, cpu_getactivecpu(), MAME_TIME_IN_HZ(m6800.clock / divisor)); |
| 2480 | mame_timer_adjust(m6800_tx_timer, time_zero, cpu_getactivecpu(), MAME_TIME_IN_HZ(m6800.clock / divisor)); |
| 2481 | } |
| 2482 | break; |
| 2483 | } |
| 2484 | break; |
| 2201 | 2485 | case 0x11: |
| 2202 | | case 0x12: |
| 2486 | if ((data & M6800_TRCSR_TE) && !(m6800.trcsr & M6800_TRCSR_TE)) |
| 2487 | { |
| 2488 | m6800.txstate = M6800_TX_STATE_INIT; |
| 2489 | } |
| 2490 | m6800.trcsr = (m6800.trcsr & 0xe0) | (data & 0x1f); |
| 2491 | break; |
| 2203 | 2492 | case 0x13: |
| 2204 | | logerror("CPU #%d PC %04x: warning - write %02x to unsupported internal register %02x\n",cpu_getactivecpu(),activecpu_get_pc(),data,offset); |
| 2493 | if (m6800.trcsr_read) |
| 2494 | { |
| 2495 | m6800.trcsr_read = 0; |
| 2496 | m6800.trcsr &= ~M6800_TRCSR_TDRE; |
| 2497 | } |
| 2498 | m6800.tdr = data; |
| 2205 | 2499 | break; |
| 2206 | 2500 | case 0x14: |
| 2207 | 2501 | logerror("CPU #%d PC %04x: write %02x to RAM control register\n",cpu_getactivecpu(),activecpu_get_pc(),data); |
| r1137 | r1138 | |
| 2277 | 2571 | case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_DATA: info->i = 0; break; |
| 2278 | 2572 | case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_DATA: info->i = 0; break; |
| 2279 | 2573 | case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_DATA: info->i = 0; break; |
| 2280 | | case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_IO: info->i = 0; break; |
| 2574 | case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_IO: info->i = 9; break; |
| 2281 | 2575 | case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_IO: info->i = 0; break; |
| 2282 | 2576 | case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_IO: info->i = 0; break; |
| 2283 | 2577 | |
src/emu/machine/6850acia.c
| r1137 | r1138 | |
| 1 | 1 | /* |
| 2 | 2 | 6850 ACIA |
| 3 | */ |
| 3 | 4 | |
| 4 | | Preliminary and not yet tested outside of bfcobra.c! |
| 5 | | */ |
| 6 | 5 | #include "driver.h" |
| 7 | 6 | #include "timer.h" |
| 8 | 7 | #include "6850acia.h" |
| r1137 | r1138 | |
| 12 | 11 | #define CR6_5 0x60 |
| 13 | 12 | #define CR7 0x80 |
| 14 | 13 | |
| 15 | | #define STATUS_RDRF 0x01 |
| 16 | | #define STATUS_TDRE 0x02 |
| 17 | | #define STATUS_DCD 0x04 |
| 18 | | #define STATUS_CTS 0x08 |
| 19 | | #define STATUS_FE 0x10 |
| 20 | | #define STATUS_OVRN 0x20 |
| 21 | | #define STATUS_PE 0x40 |
| 22 | | #define STATUS_IRQ 0x80 |
| 23 | | |
| 24 | 14 | enum serial_state |
| 25 | 15 | { |
| 26 | 16 | START, |
| 27 | 17 | DATA, |
| 28 | 18 | PARITY, |
| 29 | 19 | STOP, |
| 30 | | COMPLETE |
| 20 | STOP2, |
| 31 | 21 | }; |
| 32 | 22 | |
| 33 | 23 | enum parity_type |
| r1137 | r1138 | |
| 37 | 27 | EVEN |
| 38 | 28 | }; |
| 39 | 29 | |
| 40 | | static const int div_type[3] = { 1, 16, 64 }; |
| 30 | static const int ACIA6850_DIVIDE[3] = { 1, 16, 64 }; |
| 41 | 31 | |
| 42 | | static const int wordtype [8][3] = |
| 32 | static const int ACIA6850_WORD[8][3] = |
| 43 | 33 | { |
| 44 | | {7, EVEN, 2}, |
| 45 | | {7, ODD, 2}, |
| 46 | | {7, EVEN, 1}, |
| 47 | | {7, ODD, 1}, |
| 48 | | {8, NONE, 2}, |
| 49 | | {8, NONE, 1}, |
| 50 | | {8, EVEN, 1}, |
| 51 | | {8, ODD, 1} |
| 34 | { 7, EVEN, 2 }, |
| 35 | { 7, ODD, 2 }, |
| 36 | { 7, EVEN, 1 }, |
| 37 | { 7, ODD, 1 }, |
| 38 | { 8, NONE, 2 }, |
| 39 | { 8, NONE, 1 }, |
| 40 | { 8, EVEN, 1 }, |
| 41 | { 8, ODD, 1 } |
| 52 | 42 | }; |
| 53 | 43 | |
| 54 | 44 | typedef struct _acia_6850_ |
| r1137 | r1138 | |
| 58 | 48 | |
| 59 | 49 | UINT8 *rx_pin; |
| 60 | 50 | UINT8 *tx_pin; |
| 51 | UINT8 *cts_pin; |
| 52 | UINT8 *rts_pin; |
| 53 | UINT8 *dcd_pin; |
| 61 | 54 | |
| 62 | 55 | UINT8 tdr; |
| 63 | 56 | UINT8 rdr; |
| r1137 | r1138 | |
| 79 | 72 | int bits; |
| 80 | 73 | enum parity_type parity; |
| 81 | 74 | int stopbits; |
| 75 | int tx_int; |
| 82 | 76 | |
| 83 | 77 | /* Signals */ |
| 84 | 78 | int overrun; |
| 85 | 79 | int reset; |
| 80 | int rts; |
| 81 | int brk; |
| 82 | int first_reset; |
| 83 | int status_read; |
| 86 | 84 | enum serial_state rx_state; |
| 87 | 85 | enum serial_state tx_state; |
| 88 | 86 | |
| r1137 | r1138 | |
| 100 | 98 | /* |
| 101 | 99 | Reset the chip |
| 102 | 100 | */ |
| 103 | | static void reset(int which) |
| 101 | static void acia6850_reset(int which) |
| 104 | 102 | { |
| 105 | 103 | acia_6850 *acia_p = &acia[which]; |
| 104 | int cts = 0, dcd = 0; |
| 106 | 105 | |
| 107 | | acia_p->status = STATUS_TDRE; |
| 106 | if (acia_p->cts_pin) |
| 107 | { |
| 108 | cts = *acia_p->cts_pin; |
| 109 | } |
| 110 | |
| 111 | if (acia_p->dcd_pin) |
| 112 | { |
| 113 | dcd = *acia_p->dcd_pin; |
| 114 | } |
| 115 | |
| 116 | acia_p->status = (cts << 3) | (dcd << 2) | ACIA6850_STATUS_TDRE; |
| 108 | 117 | acia_p->tdr = 0; |
| 109 | 118 | acia_p->rdr = 0; |
| 110 | 119 | acia_p->tx_shift = 0; |
| 111 | 120 | acia_p->rx_shift = 0; |
| 112 | 121 | *acia_p->tx_pin = 1; |
| 122 | acia_p->overrun = 0; |
| 123 | acia_p->status_read = 0; |
| 124 | acia_p->brk = 0; |
| 113 | 125 | |
| 126 | acia_p->rx_state = START; |
| 114 | 127 | acia_p->tx_state = START; |
| 115 | | acia_p->rx_state = START; |
| 128 | |
| 129 | if (acia_p->int_callback) |
| 130 | { |
| 131 | acia_p->int_callback(1); |
| 132 | } |
| 133 | |
| 134 | if (acia_p->first_reset) |
| 135 | { |
| 136 | acia_p->first_reset = 0; |
| 137 | |
| 138 | if (acia_p->rts_pin) |
| 139 | { |
| 140 | *acia_p->rts_pin = 1; |
| 141 | } |
| 142 | } |
| 143 | else |
| 144 | { |
| 145 | if (acia_p->rts_pin) |
| 146 | { |
| 147 | *acia_p->rts_pin = acia_p->rts; |
| 148 | } |
| 149 | } |
| 116 | 150 | } |
| 117 | 151 | |
| 118 | 152 | /* |
| r1137 | r1138 | |
| 131 | 165 | acia_p->tx_clock = intf->tx_clock; |
| 132 | 166 | acia_p->rx_pin = intf->rx_pin; |
| 133 | 167 | acia_p->tx_pin = intf->tx_pin; |
| 168 | acia_p->cts_pin = intf->cts_pin; |
| 169 | acia_p->rts_pin = intf->rts_pin; |
| 170 | acia_p->dcd_pin = intf->rts_pin; |
| 134 | 171 | acia_p->rx_timer = mame_timer_alloc(receive_event); |
| 135 | 172 | acia_p->tx_timer = mame_timer_alloc(transmit_event); |
| 136 | 173 | acia_p->int_callback = intf->int_callback; |
| 174 | acia_p->first_reset = 1; |
| 175 | acia_p->status_read = 0; |
| 176 | acia_p->brk = 0; |
| 137 | 177 | |
| 138 | 178 | mame_timer_reset(acia_p->rx_timer, time_never); |
| 139 | 179 | mame_timer_reset(acia_p->tx_timer, time_never); |
| 140 | 180 | |
| 141 | | // TODO |
| 142 | | *acia_p->tx_pin = 1; |
| 143 | | |
| 144 | 181 | state_save_register_item("acia6850", which, acia_p->ctrl); |
| 145 | 182 | state_save_register_item("acia6850", which, acia_p->status); |
| 146 | 183 | state_save_register_item("acia6850", which, acia_p->rx_clock); |
| r1137 | r1138 | |
| 153 | 190 | state_save_register_item("acia6850", which, acia_p->tx_bits); |
| 154 | 191 | state_save_register_item("acia6850", which, acia_p->rx_parity); |
| 155 | 192 | state_save_register_item("acia6850", which, acia_p->tx_parity); |
| 193 | state_save_register_item("acia6850", which, acia_p->tx_int); |
| 156 | 194 | |
| 157 | 195 | state_save_register_item("acia6850", which, acia_p->divide); |
| 158 | 196 | state_save_register_item("acia6850", which, acia_p->overrun); |
| 159 | 197 | state_save_register_item("acia6850", which, acia_p->reset); |
| 198 | state_save_register_item("acia6850", which, acia_p->first_reset); |
| 199 | state_save_register_item("acia6850", which, acia_p->rts); |
| 200 | state_save_register_item("acia6850", which, acia_p->brk); |
| 201 | state_save_register_item("acia6850", which, acia_p->status_read); |
| 160 | 202 | } |
| 161 | 203 | |
| 162 | 204 | /* |
| r1137 | r1138 | |
| 164 | 206 | */ |
| 165 | 207 | UINT8 acia6850_stat_r(int which) |
| 166 | 208 | { |
| 167 | | return acia[which].status; |
| 209 | acia_6850 *acia_p = &acia[which]; |
| 210 | |
| 211 | acia_p->status_read = 1; |
| 212 | |
| 213 | return acia_p->status; |
| 168 | 214 | } |
| 169 | 215 | |
| 170 | 216 | /* |
| r1137 | r1138 | |
| 172 | 218 | */ |
| 173 | 219 | void acia6850_ctrl_w(int which, UINT8 data) |
| 174 | 220 | { |
| 221 | acia_6850 *acia_p = &acia[which]; |
| 222 | |
| 175 | 223 | int wordsel; |
| 176 | 224 | int divide; |
| 177 | | acia_6850 *acia_p = &acia[which]; |
| 178 | 225 | |
| 179 | 226 | acia_p->ctrl = data; |
| 180 | 227 | |
| 181 | | /* 1. Counter divide select */ |
| 228 | // Counter Divide Select Bits |
| 229 | |
| 182 | 230 | divide = data & CR1_0; |
| 183 | 231 | |
| 184 | 232 | if (divide == 3) |
| 185 | 233 | { |
| 186 | 234 | acia_p->reset = 1; |
| 187 | | reset(which); |
| 235 | acia6850_reset(which); |
| 188 | 236 | } |
| 189 | 237 | else |
| 190 | 238 | { |
| 191 | 239 | acia_p->reset = 0; |
| 192 | | acia_p->divide = div_type[divide]; |
| 240 | acia_p->divide = ACIA6850_DIVIDE[divide]; |
| 193 | 241 | } |
| 194 | 242 | |
| 195 | | /* 2. Word type */ |
| 243 | // Word Select Bits |
| 244 | |
| 196 | 245 | wordsel = (data & CR4_2) >> 2; |
| 197 | | acia_p->bits = wordtype[wordsel][0]; |
| 198 | | acia_p->parity = wordtype[wordsel][1]; |
| 199 | | acia_p->stopbits = wordtype[wordsel][2]; |
| 200 | 246 | |
| 201 | | /* 3. TX Control (TODO) */ |
| 247 | acia_p->bits = ACIA6850_WORD[wordsel][0]; |
| 248 | acia_p->parity = ACIA6850_WORD[wordsel][1]; |
| 249 | acia_p->stopbits = ACIA6850_WORD[wordsel][2]; |
| 202 | 250 | |
| 203 | | /* After writing the word type, start receive clock */ |
| 204 | | if(!acia_p->reset) |
| 251 | // Transmitter Control Bits |
| 252 | |
| 253 | switch ((data & CR6_5) >> 5) |
| 205 | 254 | { |
| 206 | | mame_time period = scale_up_mame_time(MAME_TIME_IN_HZ(acia_p->rx_clock), acia_p->divide); |
| 207 | | /* TODO! */ |
| 208 | | mame_timer_adjust(acia_p->rx_timer, period, which, period); |
| 255 | case 0: |
| 256 | if (acia_p->rts_pin) |
| 257 | { |
| 258 | *acia_p->rts_pin = acia_p->rts = 0; |
| 259 | } |
| 260 | |
| 261 | acia_p->tx_int = 0; |
| 262 | acia_p->brk = 0; |
| 263 | break; |
| 264 | |
| 265 | case 1: |
| 266 | if (acia_p->rts_pin) |
| 267 | { |
| 268 | *acia_p->rts_pin = acia_p->rts = 0; |
| 269 | } |
| 270 | |
| 271 | acia_p->tx_int = 1; |
| 272 | acia_p->brk = 0; |
| 273 | break; |
| 274 | |
| 275 | case 2: |
| 276 | if (acia_p->rts_pin) |
| 277 | { |
| 278 | *acia_p->rts_pin = acia_p->rts = 1; |
| 279 | } |
| 280 | |
| 281 | acia_p->tx_int = 0; |
| 282 | acia_p->brk = 0; |
| 283 | break; |
| 284 | |
| 285 | case 3: |
| 286 | if (acia_p->rts_pin) |
| 287 | { |
| 288 | *acia_p->rts_pin = acia_p->rts = 0; |
| 289 | } |
| 290 | |
| 291 | acia_p->tx_int = 0; |
| 292 | acia_p->brk = 1; |
| 293 | break; |
| 209 | 294 | } |
| 295 | |
| 296 | // After writing the word type, start receive clock |
| 297 | |
| 298 | if (!acia_p->reset) |
| 299 | { |
| 300 | mame_time rx_period = scale_up_mame_time(MAME_TIME_IN_HZ(acia_p->rx_clock), acia_p->divide); |
| 301 | mame_time tx_period = scale_up_mame_time(MAME_TIME_IN_HZ(acia_p->tx_clock), acia_p->divide); |
| 302 | mame_timer_adjust(acia_p->rx_timer, rx_period, which, rx_period); |
| 303 | mame_timer_adjust(acia_p->tx_timer, tx_period, which, tx_period); |
| 304 | } |
| 210 | 305 | } |
| 211 | 306 | |
| 212 | | static TIMER_CALLBACK( tdr_to_shift ) |
| 307 | void acia6850_check_interrupts(int which) |
| 213 | 308 | { |
| 214 | | int which = param; |
| 309 | acia_6850 *acia_p = &acia[which]; |
| 215 | 310 | |
| 216 | | acia_6850 *acia_p = &acia[which]; |
| 217 | | mame_time period = scale_up_mame_time(MAME_TIME_IN_HZ(acia_p->tx_clock), acia_p->divide); |
| 311 | int irq = (acia_p->tx_int && (acia_p->status & ACIA6850_STATUS_TDRE)) || |
| 312 | ((acia_p->ctrl & 0x80) && ((acia_p->status & (ACIA6850_STATUS_RDRF|ACIA6850_STATUS_DCD)) || acia_p->overrun)); |
| 218 | 313 | |
| 219 | | acia_p->tx_shift = acia[which].tdr; |
| 220 | | acia_p->status &= ~STATUS_TDRE; |
| 314 | if (irq) |
| 315 | { |
| 316 | acia_p->status |= ACIA6850_STATUS_IRQ; |
| 221 | 317 | |
| 222 | | /* Start the transmit timer */ |
| 223 | | mame_timer_adjust(acia_p->tx_timer, period, which, period); |
| 318 | if (acia_p->int_callback) |
| 319 | { |
| 320 | acia_p->int_callback(0); |
| 321 | } |
| 322 | } |
| 323 | else |
| 324 | { |
| 325 | acia_p->status &= ~ACIA6850_STATUS_IRQ; |
| 326 | |
| 327 | if (acia_p->int_callback) |
| 328 | { |
| 329 | acia_p->int_callback(1); |
| 330 | } |
| 331 | } |
| 224 | 332 | } |
| 225 | 333 | |
| 226 | | |
| 227 | 334 | /* |
| 228 | 335 | Write transmit register |
| 229 | 336 | */ |
| 230 | 337 | void acia6850_data_w(int which, UINT8 data) |
| 231 | 338 | { |
| 232 | | if (!acia[which].reset) |
| 339 | acia_6850 *acia_p = &acia[which]; |
| 340 | |
| 341 | if (!acia_p->reset) |
| 233 | 342 | { |
| 234 | | acia[which].tdr = data; |
| 235 | | timer_call_after_resynch(which, tdr_to_shift); |
| 236 | | //printf("ACIA %d Transmit: %x (%c)\n", which, data, data); |
| 343 | acia_p->tdr = data; |
| 344 | acia_p->status &= ~ACIA6850_STATUS_TDRE; |
| 345 | acia6850_check_interrupts(which); |
| 237 | 346 | } |
| 238 | 347 | else |
| 239 | 348 | { |
| r1137 | r1138 | |
| 246 | 355 | */ |
| 247 | 356 | UINT8 acia6850_data_r(int which) |
| 248 | 357 | { |
| 249 | | acia[which].status &= ~(STATUS_RDRF | STATUS_IRQ | STATUS_PE | STATUS_OVRN); |
| 358 | acia_6850 *acia_p = &acia[which]; |
| 250 | 359 | |
| 251 | | if (acia[which].int_callback) |
| 252 | | acia[which].int_callback(0); |
| 360 | acia_p->status &= ~(ACIA6850_STATUS_RDRF | ACIA6850_STATUS_IRQ | ACIA6850_STATUS_PE); |
| 253 | 361 | |
| 254 | | return acia[which].rdr; |
| 362 | if (acia_p->status_read) |
| 363 | { |
| 364 | acia_p->status_read = 0; |
| 365 | acia_p->status &= ~(ACIA6850_STATUS_OVRN | ACIA6850_STATUS_DCD); |
| 366 | |
| 367 | if (acia_p->dcd_pin && *acia_p->dcd_pin) |
| 368 | { |
| 369 | acia_p->status |= ACIA6850_STATUS_DCD; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | if (acia_p->overrun == 1) |
| 374 | { |
| 375 | acia_p->status |= ACIA6850_STATUS_OVRN; |
| 376 | acia_p->overrun = 0; |
| 377 | } |
| 378 | |
| 379 | acia6850_check_interrupts(which); |
| 380 | |
| 381 | return acia_p->rdr; |
| 255 | 382 | } |
| 256 | 383 | |
| 257 | | |
| 258 | 384 | /* |
| 259 | 385 | Transmit a bit |
| 260 | 386 | */ |
| r1137 | r1138 | |
| 267 | 393 | { |
| 268 | 394 | case START: |
| 269 | 395 | { |
| 270 | | /* Stop bit */ |
| 271 | | *acia_p->tx_pin = 0; |
| 272 | | acia_p->tx_bits = acia_p->bits; |
| 273 | | acia_p->tx_state = DATA; |
| 396 | if (acia_p->brk) |
| 397 | { |
| 398 | // transmit break |
| 399 | |
| 400 | *acia_p->tx_pin = 0; |
| 401 | } |
| 402 | else |
| 403 | { |
| 404 | if (acia_p->status & ACIA6850_STATUS_TDRE) |
| 405 | { |
| 406 | // transmitter idle |
| 407 | |
| 408 | *acia_p->tx_pin = 1; |
| 409 | } |
| 410 | else |
| 411 | { |
| 412 | // transmit character |
| 413 | |
| 414 | //logerror("ACIA6850 #%u: TX DATA %x\n", which, acia_p->tdr); |
| 415 | //logerror("ACIA6850 #%u: TX START BIT\n", which); |
| 416 | |
| 417 | *acia_p->tx_pin = 0; |
| 418 | |
| 419 | acia_p->tx_bits = acia_p->bits; |
| 420 | acia_p->tx_shift = acia_p->tdr; |
| 421 | |
| 422 | // inhibit TDRE bit if Clear-to-Send is high |
| 423 | |
| 424 | if (!(acia_p->status & ACIA6850_STATUS_CTS)) |
| 425 | { |
| 426 | acia_p->status |= ACIA6850_STATUS_TDRE; |
| 427 | } |
| 428 | |
| 429 | acia6850_check_interrupts(which); |
| 430 | |
| 431 | acia_p->tx_state = DATA; |
| 432 | } |
| 433 | } |
| 274 | 434 | break; |
| 275 | 435 | } |
| 276 | 436 | case DATA: |
| 277 | 437 | { |
| 278 | 438 | int val = acia_p->tx_shift & 1; |
| 439 | //logerror("ACIA6850 #%u: TX DATA BIT %x\n", which, val); |
| 279 | 440 | |
| 280 | 441 | *acia_p->tx_pin = val; |
| 281 | 442 | acia_p->tx_parity ^= val; |
| r1137 | r1138 | |
| 283 | 444 | |
| 284 | 445 | if (--(acia_p->tx_bits) == 0) |
| 285 | 446 | { |
| 286 | | acia_p->tx_state = acia_p->parity == NONE ? STOP : PARITY; |
| 447 | acia_p->tx_state = (acia_p->parity == NONE) ? STOP : PARITY; |
| 287 | 448 | } |
| 288 | 449 | |
| 289 | 450 | break; |
| r1137 | r1138 | |
| 299 | 460 | *acia_p->tx_pin = (acia_p->tx_parity & 1) ? 0 : 1; |
| 300 | 461 | } |
| 301 | 462 | |
| 463 | //logerror("ACIA6850 #%u: TX PARITY BIT %x\n", which, *acia_p->tx_pin); |
| 302 | 464 | acia_p->tx_parity = 0; |
| 303 | 465 | acia_p->tx_state = STOP; |
| 304 | 466 | break; |
| 305 | 467 | } |
| 306 | 468 | case STOP: |
| 307 | 469 | { |
| 308 | | /* TODO */ |
| 470 | //logerror("ACIA6850 #%u: TX STOP BIT\n", which); |
| 309 | 471 | *acia_p->tx_pin = 1; |
| 310 | | acia_p->tx_state = COMPLETE; |
| 472 | |
| 473 | if (acia_p->stopbits == 1) |
| 474 | { |
| 475 | acia_p->tx_state = START; |
| 476 | } |
| 477 | else |
| 478 | { |
| 479 | acia_p->tx_state = STOP2; |
| 480 | } |
| 311 | 481 | break; |
| 312 | 482 | } |
| 313 | | case COMPLETE: |
| 483 | case STOP2: |
| 314 | 484 | { |
| 315 | | /* TDR is now empty */ |
| 316 | | acia_p->status |= STATUS_TDRE; |
| 317 | | |
| 318 | | /* Transmit timer no longer active */ |
| 319 | | mame_timer_enable(acia_p->tx_timer, 0); |
| 320 | | |
| 485 | //logerror("ACIA6850 #%u: TX STOP BIT\n", which); |
| 486 | *acia_p->tx_pin = 1; |
| 321 | 487 | acia_p->tx_state = START; |
| 322 | 488 | break; |
| 323 | 489 | } |
| r1137 | r1138 | |
| 330 | 496 | int which = param; |
| 331 | 497 | acia_6850 *acia_p = &acia[which]; |
| 332 | 498 | |
| 333 | | switch (acia_p->rx_state) |
| 499 | if (acia_p->dcd_pin && *acia_p->dcd_pin) |
| 334 | 500 | { |
| 335 | | case START: |
| 501 | acia_p->status |= ACIA6850_STATUS_DCD; |
| 502 | acia6850_check_interrupts(which); |
| 503 | } |
| 504 | else if ((acia_p->status & (ACIA6850_STATUS_DCD|ACIA6850_STATUS_IRQ)) == ACIA6850_STATUS_DCD) |
| 505 | { |
| 506 | acia_p->status &= ~ACIA6850_STATUS_DCD; |
| 507 | } |
| 508 | |
| 509 | if (acia_p->status & ACIA6850_STATUS_DCD) |
| 510 | { |
| 511 | acia_p->rx_state = START; |
| 512 | } |
| 513 | else |
| 514 | { |
| 515 | switch (acia_p->rx_state) |
| 336 | 516 | { |
| 337 | | /* Wait for low signal */ |
| 338 | | if (*acia_p->rx_pin == 0) |
| 517 | case START: |
| 339 | 518 | { |
| 340 | | acia_p->rx_shift = 0; |
| 341 | | acia_p->rx_bits = acia_p->bits; |
| 342 | | acia_p->rx_state = DATA; |
| 519 | if (*acia_p->rx_pin == 0) |
| 520 | { |
| 521 | //logerror("ACIA6850 #%u: RX START BIT\n", which); |
| 522 | acia_p->rx_shift = 0; |
| 523 | acia_p->rx_parity = 0; |
| 524 | acia_p->rx_bits = acia_p->bits; |
| 525 | acia_p->rx_state = DATA; |
| 526 | } |
| 527 | break; |
| 343 | 528 | } |
| 344 | | break; |
| 345 | | } |
| 346 | | case DATA: |
| 347 | | { |
| 348 | | acia_p->rx_shift |= *acia_p->rx_pin ? 0x80 : 0; |
| 349 | | acia_p->rx_parity ^= *acia_p->rx_pin; |
| 529 | case DATA: |
| 530 | { |
| 531 | //logerror("ACIA6850 #%u: RX DATA BIT %x\n", which, *acia_p->rx_pin); |
| 532 | acia_p->rx_shift |= *acia_p->rx_pin ? 0x80 : 0; |
| 533 | acia_p->rx_parity ^= *acia_p->rx_pin; |
| 350 | 534 | |
| 351 | | if (--acia_p->rx_bits == 0) |
| 352 | | { |
| 353 | | acia_p->rx_state = acia_p->parity == NONE ? STOP : PARITY; |
| 535 | if (--acia_p->rx_bits == 0) |
| 536 | { |
| 537 | if (acia_p->status & ACIA6850_STATUS_RDRF) |
| 538 | { |
| 539 | acia_p->overrun = 1; |
| 540 | acia6850_check_interrupts(which); |
| 541 | } |
| 542 | |
| 543 | acia_p->rx_state = acia_p->parity == NONE ? STOP : PARITY; |
| 544 | } |
| 545 | else |
| 546 | { |
| 547 | acia_p->rx_shift >>= 1; |
| 548 | } |
| 549 | break; |
| 354 | 550 | } |
| 355 | | else |
| 551 | case PARITY: |
| 356 | 552 | { |
| 357 | | acia_p->rx_shift >>= 1; |
| 358 | | } |
| 359 | | break; |
| 360 | | } |
| 361 | | case PARITY: |
| 362 | | { |
| 363 | | acia_p->rx_parity ^= *acia_p->rx_pin; |
| 553 | //logerror("ACIA6850 #%u: RX PARITY BIT %x\n", which, *acia_p->rx_pin); |
| 554 | acia_p->rx_parity ^= *acia_p->rx_pin; |
| 364 | 555 | |
| 365 | | if (acia_p->parity == EVEN) |
| 366 | | { |
| 367 | | if (acia_p->rx_parity) |
| 556 | if (acia_p->parity == EVEN) |
| 368 | 557 | { |
| 369 | | acia_p->status |= STATUS_PE; |
| 558 | if (acia_p->rx_parity) |
| 559 | { |
| 560 | acia_p->status |= ACIA6850_STATUS_PE; |
| 561 | } |
| 370 | 562 | } |
| 563 | else |
| 564 | { |
| 565 | if (!acia_p->rx_parity) |
| 566 | { |
| 567 | acia_p->status |= ACIA6850_STATUS_PE; |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | acia_p->rx_state = STOP; |
| 572 | break; |
| 371 | 573 | } |
| 372 | | else |
| 574 | case STOP: |
| 373 | 575 | { |
| 374 | | if (!acia_p->rx_parity) |
| 576 | if (*acia_p->rx_pin == 1) |
| 375 | 577 | { |
| 376 | | acia_p->status |= STATUS_PE; |
| 578 | //logerror("ACIA6850 #%u: RX STOP BIT\n", which); |
| 579 | if (acia_p->stopbits == 1) |
| 580 | { |
| 581 | acia_p->status &= ~ACIA6850_STATUS_FE; |
| 582 | |
| 583 | if (!(acia_p->status & ACIA6850_STATUS_RDRF)) |
| 584 | { |
| 585 | //logerror("ACIA6850 #%u: RX DATA %x\n", which, acia_p->rx_shift); |
| 586 | acia_p->rdr = acia_p->rx_shift; |
| 587 | acia_p->status |= ACIA6850_STATUS_RDRF; |
| 588 | acia6850_check_interrupts(which); |
| 589 | } |
| 590 | |
| 591 | acia_p->rx_state = START; |
| 592 | } |
| 593 | else |
| 594 | { |
| 595 | acia_p->rx_state = STOP2; |
| 596 | } |
| 377 | 597 | } |
| 598 | else |
| 599 | { |
| 600 | acia_p->status |= ACIA6850_STATUS_FE; |
| 601 | acia_p->rx_state = START; |
| 602 | } |
| 603 | break; |
| 378 | 604 | } |
| 379 | | |
| 380 | | acia_p->rx_parity = 0; |
| 381 | | acia_p->rx_state = STOP; |
| 382 | | |
| 383 | | // As long as data is in RDR |
| 384 | | break; |
| 385 | | } |
| 386 | | case STOP: |
| 387 | | { |
| 388 | | /* TODO: |
| 389 | | Multiple stop bits |
| 390 | | Overrun |
| 391 | | */ |
| 392 | | acia_p->rx_state = COMPLETE; |
| 393 | | break; |
| 394 | | } |
| 395 | | case COMPLETE: |
| 396 | | { |
| 397 | | /* |
| 398 | | TODO: Check behaviour. |
| 399 | | */ |
| 400 | | //if (!(acia_p->status & STATUS_RDRF)) |
| 605 | case STOP2: |
| 401 | 606 | { |
| 402 | | acia_p->rdr = acia_p->rx_shift; |
| 403 | | acia_p->status |= STATUS_RDRF; |
| 404 | | acia_p->status |= STATUS_IRQ; |
| 607 | if (*acia_p->rx_pin == 1) |
| 608 | { |
| 609 | //logerror("ACIA6850 #%u: RX STOP BIT\n", which); |
| 610 | acia_p->status &= ~ACIA6850_STATUS_FE; |
| 405 | 611 | |
| 406 | | // printf("ACIA %d Received full: %x\n", which, acia_p->rdr); |
| 407 | | |
| 408 | | /* TODO */ |
| 409 | | if (acia_p->ctrl & 0x80) |
| 410 | | { |
| 411 | | if (acia_p->int_callback) |
| 612 | if (!(acia_p->status & ACIA6850_STATUS_RDRF)) |
| 412 | 613 | { |
| 413 | | acia_p->int_callback(1); |
| 614 | //logerror("ACIA6850 #%u: RX DATA %x\n", which, acia_p->rx_shift); |
| 615 | acia_p->rdr = acia_p->rx_shift; |
| 616 | acia_p->status |= ACIA6850_STATUS_RDRF; |
| 617 | acia6850_check_interrupts(which); |
| 414 | 618 | } |
| 619 | |
| 620 | acia_p->rx_state = START; |
| 415 | 621 | } |
| 622 | else |
| 623 | { |
| 624 | acia_p->status |= ACIA6850_STATUS_FE; |
| 625 | acia_p->rx_state = START; |
| 626 | } |
| 627 | break; |
| 416 | 628 | } |
| 417 | | |
| 418 | | acia_p->rx_state = START; |
| 419 | | break; |
| 420 | 629 | } |
| 421 | 630 | } |
| 422 | 631 | } |