src/emu/cpu/m6800/m6800.c
| r10115 | r10116 | |
| 53 | 53 | |
| 54 | 54 | /* |
| 55 | 55 | |
| 56 | | Chip RAM NVRAM ROM SCI |
| 57 | | ----------------------------------------------- |
| 58 | | MC6800 - - - no |
| 59 | | MC6801 128 64 2K yes |
| 60 | | MC68701 128 64 - yes |
| 61 | | MC6803 128 64 - yes |
| 62 | | MC6802 128 32 - no |
| 63 | | MC6802NS 128 - - no |
| 64 | | MC6808 - - - no |
| 56 | Chip RAM NVRAM ROM SCI r15-f ports |
| 57 | ----------------------------------------------------------------- |
| 58 | MC6800 - - - no no 4 |
| 59 | MC6802 128 32 - no no 4 |
| 60 | MC6802NS 128 - - no no 4 |
| 61 | MC6808 - - - no no 4 |
| 62 | |
| 63 | MC6801 128 64 2K yes no 4 |
| 64 | MC68701 128 64 - yes no 4 |
| 65 | MC6803 128 64 - yes no 4 |
| 65 | 66 | |
| 66 | | HD6301 128 - 4K yes |
| 67 | | HD63701 192 - 4K yes |
| 68 | | HD6303 128 - - yes |
| 69 | | HD6801 128 64 2K yes |
| 67 | MC6801U4 192 32 4K yes yes 4 |
| 68 | MC6803U4 192 32 - yes yes 4 |
| 70 | 69 | |
| 70 | HD6801 128 64 2K yes no 4 |
| 71 | HD6301V 128 - 4K yes no 4 |
| 72 | HD63701V 192 - 4K yes no 4 |
| 73 | HD6303R 128 - - yes no 4 |
| 74 | |
| 75 | HD6301X 192 - 4K yes yes 6 |
| 76 | HD6301Y 256 - 16K yes yes 6 |
| 77 | HD6303X 192 - - yes yes 6 |
| 78 | HD6303Y 256 - - yes yes 6 |
| 79 | |
| 71 | 80 | NSC8105 |
| 72 | 81 | MS2010-A |
| 73 | 82 | |
| r10115 | r10116 | |
| 142 | 151 | |
| 143 | 152 | int clock; |
| 144 | 153 | UINT8 trcsr, rmcr, rdr, tdr, rsr, tsr; |
| 145 | | int rxbits, txbits, txstate, trcsr_read, tx; |
| 154 | int rxbits, txbits, txstate, trcsr_read_tdre, trcsr_read_orfe, trcsr_read_rdrf, tx; |
| 155 | int port2_written; |
| 146 | 156 | |
| 147 | 157 | int icount; |
| 148 | 158 | int latch09; |
| 149 | 159 | |
| 150 | 160 | PAIR timer_over; |
| 151 | | emu_timer *m6800_rx_timer; |
| 152 | | emu_timer *m6800_tx_timer; |
| 161 | emu_timer *sci_timer; |
| 153 | 162 | PAIR ea; /* effective address */ |
| 154 | 163 | |
| 155 | 164 | }; |
| r10115 | r10116 | |
| 271 | 280 | #define M6800_TRCSR_RDRF 0x80 // Receive Data Register Full |
| 272 | 281 | #define M6800_TRCSR_ORFE 0x40 // Over Run Framing Error |
| 273 | 282 | #define M6800_TRCSR_TDRE 0x20 // Transmit Data Register Empty |
| 274 | | #define M6800_TRCSR_RIE 0x10 // Receive Interrupt Enable |
| 283 | #define M6800_TRCSR_RIE 0x10 // Receive Interrupt Enable |
| 275 | 284 | #define M6800_TRCSR_RE 0x08 // Receive Enable |
| 276 | | #define M6800_TRCSR_TIE 0x04 // Transmit Interrupt Enable |
| 285 | #define M6800_TRCSR_TIE 0x04 // Transmit Interrupt Enable |
| 277 | 286 | #define M6800_TRCSR_TE 0x02 // Transmit Enable |
| 278 | 287 | #define M6800_TRCSR_WU 0x01 // Wake Up |
| 279 | 288 | |
| 280 | | #define M6800_PORT2_IO4 0x10 |
| 281 | | #define M6800_PORT2_IO3 0x08 |
| 289 | #define M6800_PORT2_IO4 0x10 |
| 290 | #define M6800_PORT2_IO3 0x08 |
| 282 | 291 | |
| 283 | 292 | static const int M6800_RMCR_SS[] = { 16, 128, 1024, 4096 }; |
| 284 | 293 | |
| r10115 | r10116 | |
| 587 | 596 | ((cpustate->trcsr & (M6800_TRCSR_RIE|M6800_TRCSR_ORFE)) == (M6800_TRCSR_RIE|M6800_TRCSR_ORFE)) || |
| 588 | 597 | ((cpustate->trcsr & (M6800_TRCSR_TIE|M6800_TRCSR_TDRE)) == (M6800_TRCSR_TIE|M6800_TRCSR_TDRE))) |
| 589 | 598 | { |
| 599 | //logerror("M6800 '%s' SCI interrupt\n", cpustate->device->tag()); |
| 590 | 600 | TAKE_SCI; |
| 591 | 601 | } |
| 592 | 602 | } |
| r10115 | r10116 | |
| 665 | 675 | check_timer_event(cpustate); |
| 666 | 676 | } |
| 667 | 677 | |
| 678 | INLINE void set_rmcr(m6800_state *cpustate, UINT8 data) |
| 679 | { |
| 680 | if (cpustate->rmcr == data) return; |
| 681 | |
| 682 | cpustate->rmcr = data; |
| 683 | |
| 684 | switch ((cpustate->rmcr & M6800_RMCR_CC_MASK) >> 2) |
| 685 | { |
| 686 | case 0: |
| 687 | case 3: // not implemented |
| 688 | timer_enable(cpustate->sci_timer, 0); |
| 689 | break; |
| 690 | |
| 691 | case 1: |
| 692 | case 2: |
| 693 | { |
| 694 | int divisor = M6800_RMCR_SS[cpustate->rmcr & M6800_RMCR_SS_MASK]; |
| 695 | |
| 696 | timer_adjust_periodic(cpustate->sci_timer, ATTOTIME_IN_HZ(cpustate->clock / divisor), 0, ATTOTIME_IN_HZ(cpustate->clock / divisor)); |
| 697 | } |
| 698 | break; |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | INLINE void write_port2(m6800_state *cpustate) |
| 703 | { |
| 704 | if (!cpustate->port2_written) return; |
| 705 | |
| 706 | UINT8 data = cpustate->port2_data; |
| 707 | UINT8 ddr = cpustate->port2_ddr & 0x1f; |
| 708 | |
| 709 | if ((ddr != 0x1f) && ddr) |
| 710 | { |
| 711 | data = (cpustate->port2_data & ddr) | (ddr ^ 0xff); |
| 712 | } |
| 713 | |
| 714 | if (cpustate->trcsr & M6800_TRCSR_TE) |
| 715 | { |
| 716 | data = (data & 0xef) | (cpustate->tx << 4); |
| 717 | } |
| 718 | |
| 719 | data &= 0x1f; |
| 720 | |
| 721 | cpustate->io->write_byte(M6803_PORT2, data); |
| 722 | } |
| 723 | |
| 668 | 724 | /* include the opcode prototypes and function pointer tables */ |
| 669 | 725 | #include "6800tbl.c" |
| 670 | 726 | |
| 671 | 727 | /* include the opcode functions */ |
| 672 | 728 | #include "6800ops.c" |
| 673 | 729 | |
| 674 | | static void m6800_tx(m6800_state *cpustate, int value) |
| 675 | | { |
| 676 | | cpustate->port2_data = (cpustate->port2_data & 0xef) | (value << 4); |
| 677 | | |
| 678 | | if(cpustate->port2_ddr == 0xff) |
| 679 | | cpustate->io->write_byte(M6803_PORT2,cpustate->port2_data); |
| 680 | | else |
| 681 | | cpustate->io->write_byte(M6803_PORT2,(cpustate->port2_data & cpustate->port2_ddr) |
| 682 | | | (cpustate->io->read_byte(M6803_PORT2) & (cpustate->port2_ddr ^ 0xff))); |
| 683 | | } |
| 684 | | |
| 685 | 730 | static int m6800_rx(m6800_state *cpustate) |
| 686 | 731 | { |
| 687 | 732 | return (cpustate->io->read_byte(M6803_PORT2) & M6800_PORT2_IO3) >> 3; |
| 688 | 733 | } |
| 689 | 734 | |
| 690 | | static TIMER_CALLBACK(m6800_tx_tick) |
| 735 | static void serial_transmit(m6800_state *cpustate) |
| 691 | 736 | { |
| 692 | | m6800_state *cpustate = (m6800_state *)ptr; |
| 737 | //logerror("M6800 '%s' Tx Tick\n", cpustate->device->tag()); |
| 693 | 738 | |
| 694 | 739 | if (cpustate->trcsr & M6800_TRCSR_TE) |
| 695 | 740 | { |
| r10115 | r10116 | |
| 732 | 777 | cpustate->tx = 0; |
| 733 | 778 | |
| 734 | 779 | cpustate->txbits++; |
| 780 | |
| 781 | //logerror("M6800 '%s' Transmit START Data %02x\n", cpustate->device->tag(), cpustate->tsr); |
| 735 | 782 | } |
| 736 | 783 | break; |
| 737 | 784 | |
| r10115 | r10116 | |
| 742 | 789 | CHECK_IRQ_LINES(cpustate); |
| 743 | 790 | |
| 744 | 791 | cpustate->txbits = M6800_SERIAL_START; |
| 792 | |
| 793 | //logerror("M6800 '%s' Transmit STOP\n", cpustate->device->tag()); |
| 745 | 794 | break; |
| 746 | 795 | |
| 747 | 796 | default: |
| r10115 | r10116 | |
| 751 | 800 | // shift transmit register |
| 752 | 801 | cpustate->tsr >>= 1; |
| 753 | 802 | |
| 803 | //logerror("M6800 '%s' Transmit Bit %u: %u\n", cpustate->device->tag(), cpustate->txbits, cpustate->tx); |
| 804 | |
| 754 | 805 | cpustate->txbits++; |
| 755 | 806 | break; |
| 756 | 807 | } |
| 757 | 808 | break; |
| 758 | 809 | } |
| 810 | |
| 811 | cpustate->port2_written = 1; |
| 812 | write_port2(cpustate); |
| 759 | 813 | } |
| 760 | | |
| 761 | | m6800_tx(cpustate, cpustate->tx); |
| 762 | 814 | } |
| 763 | 815 | |
| 764 | | static TIMER_CALLBACK(m6800_rx_tick) |
| 816 | static void serial_receive(m6800_state *cpustate) |
| 765 | 817 | { |
| 766 | | m6800_state *cpustate = (m6800_state *)ptr; |
| 767 | | |
| 818 | //logerror("M6800 '%s' Rx Tick TRCSR %02x bits %u check %02x\n", cpustate->device->tag(), cpustate->trcsr, cpustate->rxbits, cpustate->trcsr & M6800_TRCSR_RE); |
| 819 | |
| 768 | 820 | if (cpustate->trcsr & M6800_TRCSR_RE) |
| 769 | 821 | { |
| 770 | 822 | if (cpustate->trcsr & M6800_TRCSR_WU) |
| 771 | 823 | { |
| 772 | 824 | // wait for 10 bits of '1' |
| 773 | | |
| 774 | 825 | if (m6800_rx(cpustate) == 1) |
| 775 | 826 | { |
| 776 | 827 | cpustate->rxbits++; |
| 777 | 828 | |
| 829 | //logerror("M6800 '%s' Received WAKE UP bit %u\n", cpustate->device->tag(), cpustate->rxbits); |
| 830 | |
| 778 | 831 | if (cpustate->rxbits == 10) |
| 779 | 832 | { |
| 833 | //logerror("M6800 '%s' Receiver Wake Up\n", cpustate->device->tag()); |
| 834 | |
| 780 | 835 | cpustate->trcsr &= ~M6800_TRCSR_WU; |
| 781 | 836 | cpustate->rxbits = M6800_SERIAL_START; |
| 782 | 837 | } |
| 783 | 838 | } |
| 784 | 839 | else |
| 785 | 840 | { |
| 841 | //logerror("M6800 '%s' Receiver Wake Up interrupted\n", cpustate->device->tag()); |
| 842 | |
| 786 | 843 | cpustate->rxbits = M6800_SERIAL_START; |
| 787 | 844 | } |
| 788 | 845 | } |
| 789 | 846 | else |
| 790 | 847 | { |
| 791 | 848 | // receive data |
| 792 | | |
| 793 | 849 | switch (cpustate->rxbits) |
| 794 | 850 | { |
| 795 | 851 | case M6800_SERIAL_START: |
| r10115 | r10116 | |
| 797 | 853 | { |
| 798 | 854 | // start bit found |
| 799 | 855 | cpustate->rxbits++; |
| 856 | |
| 857 | //logerror("M6800 '%s' Received START bit\n", cpustate->device->tag()); |
| 800 | 858 | } |
| 801 | 859 | break; |
| 802 | 860 | |
| 803 | 861 | case M6800_SERIAL_STOP: |
| 804 | 862 | if (m6800_rx(cpustate) == 1) |
| 805 | 863 | { |
| 864 | //logerror("M6800 '%s' Received STOP bit\n", cpustate->device->tag()); |
| 865 | |
| 806 | 866 | if (cpustate->trcsr & M6800_TRCSR_RDRF) |
| 807 | 867 | { |
| 808 | 868 | // overrun error |
| 809 | | |
| 810 | 869 | cpustate->trcsr |= M6800_TRCSR_ORFE; |
| 811 | 870 | |
| 871 | //logerror("M6800 '%s' Receive Overrun Error\n", cpustate->device->tag()); |
| 872 | |
| 812 | 873 | CHECK_IRQ_LINES(cpustate); |
| 813 | 874 | } |
| 814 | 875 | else |
| r10115 | r10116 | |
| 817 | 878 | { |
| 818 | 879 | // transfer data into receive register |
| 819 | 880 | cpustate->rdr = cpustate->rsr; |
| 881 | |
| 882 | //logerror("M6800 '%s' Receive Data Register: %02x\n", cpustate->device->tag(), cpustate->rdr); |
| 820 | 883 | |
| 821 | 884 | // set RDRF flag |
| 822 | 885 | cpustate->trcsr |= M6800_TRCSR_RDRF; |
| r10115 | r10116 | |
| 828 | 891 | else |
| 829 | 892 | { |
| 830 | 893 | // framing error |
| 831 | | |
| 832 | 894 | if (!(cpustate->trcsr & M6800_TRCSR_ORFE)) |
| 833 | 895 | { |
| 834 | 896 | // transfer unframed data into receive register |
| r10115 | r10116 | |
| 838 | 900 | cpustate->trcsr |= M6800_TRCSR_ORFE; |
| 839 | 901 | cpustate->trcsr &= ~M6800_TRCSR_RDRF; |
| 840 | 902 | |
| 903 | //logerror("M6800 '%s' Receive Framing Error\n", cpustate->device->tag()); |
| 904 | |
| 841 | 905 | CHECK_IRQ_LINES(cpustate); |
| 842 | 906 | } |
| 843 | 907 | |
| r10115 | r10116 | |
| 851 | 915 | // receive bit into register |
| 852 | 916 | cpustate->rsr |= (m6800_rx(cpustate) << 7); |
| 853 | 917 | |
| 918 | //logerror("M6800 '%s' Received DATA bit %u: %u\n", cpustate->device->tag(), cpustate->rxbits, BIT(cpustate->rsr, 7)); |
| 919 | |
| 854 | 920 | cpustate->rxbits++; |
| 855 | 921 | break; |
| 856 | 922 | } |
| r10115 | r10116 | |
| 858 | 924 | } |
| 859 | 925 | } |
| 860 | 926 | |
| 927 | static TIMER_CALLBACK( sci_tick ) |
| 928 | { |
| 929 | m6800_state *cpustate = (m6800_state *)ptr; |
| 930 | |
| 931 | serial_transmit(cpustate); |
| 932 | serial_receive(cpustate); |
| 933 | } |
| 934 | |
| 861 | 935 | /**************************************************************************** |
| 862 | 936 | * Reset registers to their initial values |
| 863 | 937 | ****************************************************************************/ |
| r10115 | r10116 | |
| 883 | 957 | state_save_register_device_item(cpustate->device, 0, cpustate->port2_data); |
| 884 | 958 | state_save_register_device_item(cpustate->device, 0, cpustate->port3_data); |
| 885 | 959 | state_save_register_device_item(cpustate->device, 0, cpustate->port4_data); |
| 960 | state_save_register_device_item(cpustate->device, 0, cpustate->port2_written); |
| 886 | 961 | state_save_register_device_item(cpustate->device, 0, cpustate->tcsr); |
| 887 | 962 | state_save_register_device_item(cpustate->device, 0, cpustate->pending_tcsr); |
| 888 | 963 | state_save_register_device_item(cpustate->device, 0, cpustate->irq2); |
| r10115 | r10116 | |
| 903 | 978 | state_save_register_device_item(cpustate->device, 0, cpustate->rxbits); |
| 904 | 979 | state_save_register_device_item(cpustate->device, 0, cpustate->txbits); |
| 905 | 980 | state_save_register_device_item(cpustate->device, 0, cpustate->txstate); |
| 906 | | state_save_register_device_item(cpustate->device, 0, cpustate->trcsr_read); |
| 981 | state_save_register_device_item(cpustate->device, 0, cpustate->trcsr_read_tdre); |
| 982 | state_save_register_device_item(cpustate->device, 0, cpustate->trcsr_read_orfe); |
| 983 | state_save_register_device_item(cpustate->device, 0, cpustate->trcsr_read_rdrf); |
| 907 | 984 | state_save_register_device_item(cpustate->device, 0, cpustate->tx); |
| 908 | 985 | } |
| 909 | 986 | |
| r10115 | r10116 | |
| 940 | 1017 | |
| 941 | 1018 | cpustate->port1_ddr = 0x00; |
| 942 | 1019 | cpustate->port2_ddr = 0x00; |
| 1020 | cpustate->port2_written = 0; |
| 943 | 1021 | /* TODO: on reset port 2 should be read to determine the operating mode (bits 0-2) */ |
| 944 | 1022 | cpustate->tcsr = 0x00; |
| 945 | 1023 | cpustate->pending_tcsr = 0x00; |
| r10115 | r10116 | |
| 950 | 1028 | cpustate->ram_ctrl |= 0x40; |
| 951 | 1029 | |
| 952 | 1030 | cpustate->trcsr = M6800_TRCSR_TDRE; |
| 953 | | cpustate->rmcr = 0; |
| 954 | | if (cpustate->m6800_rx_timer) timer_enable(cpustate->m6800_rx_timer, 0); |
| 955 | | if (cpustate->m6800_tx_timer) timer_enable(cpustate->m6800_tx_timer, 0); |
| 1031 | |
| 956 | 1032 | cpustate->txstate = M6800_TX_STATE_INIT; |
| 957 | 1033 | cpustate->txbits = cpustate->rxbits = 0; |
| 958 | | cpustate->trcsr_read = 0; |
| 1034 | cpustate->tx = 1; |
| 1035 | cpustate->trcsr_read_tdre = 0; |
| 1036 | cpustate->trcsr_read_orfe = 0; |
| 1037 | cpustate->trcsr_read_rdrf = 0; |
| 959 | 1038 | |
| 1039 | set_rmcr(cpustate, 0); |
| 1040 | |
| 960 | 1041 | cpustate->cc = 0xc0; |
| 961 | 1042 | } |
| 962 | 1043 | |
| r10115 | r10116 | |
| 1046 | 1127 | cpustate->io = device->space(AS_IO); |
| 1047 | 1128 | |
| 1048 | 1129 | cpustate->clock = device->clock() / 4; |
| 1049 | | cpustate->m6800_rx_timer = timer_alloc(device->machine, m6800_rx_tick, cpustate); |
| 1050 | | cpustate->m6800_tx_timer = timer_alloc(device->machine, m6800_tx_tick, cpustate); |
| 1130 | cpustate->sci_timer = timer_alloc(device->machine, sci_tick, cpustate); |
| 1051 | 1131 | |
| 1052 | 1132 | state_register(cpustate, "m6801"); |
| 1053 | 1133 | } |
| r10115 | r10116 | |
| 1090 | 1170 | cpustate->io = device->space(AS_IO); |
| 1091 | 1171 | |
| 1092 | 1172 | cpustate->clock = device->clock() / 4; |
| 1093 | | cpustate->m6800_rx_timer = timer_alloc(device->machine, m6800_rx_tick, cpustate); |
| 1094 | | cpustate->m6800_tx_timer = timer_alloc(device->machine, m6800_tx_tick, cpustate); |
| 1173 | cpustate->sci_timer = timer_alloc(device->machine, sci_tick, cpustate); |
| 1095 | 1174 | |
| 1096 | 1175 | state_register(cpustate, "m6803"); |
| 1097 | 1176 | } |
| r10115 | r10116 | |
| 1145 | 1224 | cpustate->io = device->space(AS_IO); |
| 1146 | 1225 | |
| 1147 | 1226 | cpustate->clock = device->clock() / 4; |
| 1148 | | cpustate->m6800_rx_timer = timer_alloc(device->machine, m6800_rx_tick, cpustate); |
| 1149 | | cpustate->m6800_tx_timer = timer_alloc(device->machine, m6800_tx_tick, cpustate); |
| 1227 | cpustate->sci_timer = timer_alloc(device->machine, sci_tick, cpustate); |
| 1150 | 1228 | |
| 1151 | 1229 | state_register(cpustate, "hd63701"); |
| 1152 | 1230 | } |
| r10115 | r10116 | |
| 1209 | 1287 | case 0x01: |
| 1210 | 1288 | return cpustate->port2_ddr; |
| 1211 | 1289 | case 0x02: |
| 1212 | | return (cpustate->io->read_byte(M6803_PORT1) & (cpustate->port1_ddr ^ 0xff)) |
| 1290 | if(cpustate->port1_ddr == 0xff) |
| 1291 | return cpustate->port1_data; |
| 1292 | else |
| 1293 | return (cpustate->io->read_byte(M6803_PORT1) & (cpustate->port1_ddr ^ 0xff)) |
| 1213 | 1294 | | (cpustate->port1_data & cpustate->port1_ddr); |
| 1214 | 1295 | case 0x03: |
| 1215 | | return (cpustate->io->read_byte(M6803_PORT2) & (cpustate->port2_ddr ^ 0xff)) |
| 1296 | if(cpustate->port2_ddr == 0xff) |
| 1297 | return cpustate->port2_data; |
| 1298 | else |
| 1299 | return (cpustate->io->read_byte(M6803_PORT2) & (cpustate->port2_ddr ^ 0xff)) |
| 1216 | 1300 | | (cpustate->port2_data & cpustate->port2_ddr); |
| 1217 | 1301 | case 0x04: |
| 1218 | 1302 | return cpustate->port3_ddr; |
| 1219 | 1303 | case 0x05: |
| 1220 | 1304 | return cpustate->port4_ddr; |
| 1221 | 1305 | case 0x06: |
| 1222 | | return (cpustate->io->read_byte(M6803_PORT3) & (cpustate->port3_ddr ^ 0xff)) |
| 1306 | if(cpustate->port3_ddr == 0xff) |
| 1307 | return cpustate->port3_data; |
| 1308 | else |
| 1309 | return (cpustate->io->read_byte(M6803_PORT3) & (cpustate->port3_ddr ^ 0xff)) |
| 1223 | 1310 | | (cpustate->port3_data & cpustate->port3_ddr); |
| 1224 | 1311 | case 0x07: |
| 1225 | | return (cpustate->io->read_byte(M6803_PORT4) & (cpustate->port4_ddr ^ 0xff)) |
| 1312 | if(cpustate->port4_ddr == 0xff) |
| 1313 | return cpustate->port4_data; |
| 1314 | else |
| 1315 | return (cpustate->io->read_byte(M6803_PORT4) & (cpustate->port4_ddr ^ 0xff)) |
| 1226 | 1316 | | (cpustate->port4_data & cpustate->port4_ddr); |
| 1227 | 1317 | case 0x08: |
| 1228 | 1318 | cpustate->pending_tcsr = 0; |
| r10115 | r10116 | |
| 1265 | 1355 | case 0x10: |
| 1266 | 1356 | return cpustate->rmcr; |
| 1267 | 1357 | case 0x11: |
| 1268 | | cpustate->trcsr_read = 1; |
| 1358 | if (cpustate->trcsr & M6800_TRCSR_TDRE) |
| 1359 | { |
| 1360 | cpustate->trcsr_read_tdre = 1; |
| 1361 | } |
| 1362 | if (cpustate->trcsr & M6800_TRCSR_ORFE) |
| 1363 | { |
| 1364 | cpustate->trcsr_read_orfe = 1; |
| 1365 | } |
| 1366 | if (cpustate->trcsr & M6800_TRCSR_RDRF) |
| 1367 | { |
| 1368 | cpustate->trcsr_read_rdrf = 1; |
| 1369 | } |
| 1269 | 1370 | return cpustate->trcsr; |
| 1270 | 1371 | case 0x12: |
| 1271 | | if (cpustate->trcsr_read) |
| 1372 | if (cpustate->trcsr_read_orfe) |
| 1272 | 1373 | { |
| 1273 | | cpustate->trcsr_read = 0; |
| 1274 | | cpustate->trcsr = cpustate->trcsr & 0x3f; |
| 1374 | cpustate->trcsr_read_orfe = 0; |
| 1375 | cpustate->trcsr &= ~M6800_TRCSR_ORFE; |
| 1275 | 1376 | } |
| 1377 | if (cpustate->trcsr_read_rdrf) |
| 1378 | { |
| 1379 | //logerror("M6801 '%s' Clear RDRF\n", space->cpu->tag()); |
| 1380 | cpustate->trcsr_read_rdrf = 0; |
| 1381 | cpustate->trcsr &= ~M6800_TRCSR_RDRF; |
| 1382 | } |
| 1276 | 1383 | return cpustate->rdr; |
| 1277 | 1384 | case 0x13: |
| 1278 | 1385 | return cpustate->tdr; |
| r10115 | r10116 | |
| 1308 | 1415 | cpustate->port1_ddr = data; |
| 1309 | 1416 | if(cpustate->port1_ddr == 0xff) |
| 1310 | 1417 | cpustate->io->write_byte(M6803_PORT1,cpustate->port1_data); |
| 1311 | | else |
| 1418 | else if (cpustate->port1_ddr) |
| 1312 | 1419 | cpustate->io->write_byte(M6803_PORT1,(cpustate->port1_data & cpustate->port1_ddr) |
| 1313 | 1420 | | (cpustate->io->read_byte(M6803_PORT1) & (cpustate->port1_ddr ^ 0xff))); |
| 1314 | 1421 | } |
| r10115 | r10116 | |
| 1317 | 1424 | if (cpustate->port2_ddr != data) |
| 1318 | 1425 | { |
| 1319 | 1426 | cpustate->port2_ddr = data; |
| 1320 | | if(cpustate->port2_ddr == 0xff) |
| 1321 | | cpustate->io->write_byte(M6803_PORT2,cpustate->port2_data); |
| 1322 | | else |
| 1323 | | cpustate->io->write_byte(M6803_PORT2,(cpustate->port2_data & cpustate->port2_ddr) |
| 1324 | | | (cpustate->io->read_byte(M6803_PORT2) & (cpustate->port2_ddr ^ 0xff))); |
| 1427 | write_port2(cpustate); |
| 1325 | 1428 | |
| 1326 | 1429 | if (cpustate->port2_ddr & 2) |
| 1327 | 1430 | logerror("CPU '%s' PC %04x: warning - port 2 bit 1 set as output (OLVL) - not supported\n",space->cpu->tag(),cpu_get_pc(space->cpu)); |
| r10115 | r10116 | |
| 1331 | 1434 | cpustate->port1_data = data; |
| 1332 | 1435 | if(cpustate->port1_ddr == 0xff) |
| 1333 | 1436 | cpustate->io->write_byte(M6803_PORT1,cpustate->port1_data); |
| 1334 | | else |
| 1437 | else if (cpustate->port1_ddr) |
| 1335 | 1438 | cpustate->io->write_byte(M6803_PORT1,(cpustate->port1_data & cpustate->port1_ddr) |
| 1336 | 1439 | | (cpustate->io->read_byte(M6803_PORT1) & (cpustate->port1_ddr ^ 0xff))); |
| 1337 | 1440 | break; |
| 1338 | 1441 | case 0x03: |
| 1339 | | if (cpustate->trcsr & M6800_TRCSR_TE) |
| 1340 | | { |
| 1341 | | cpustate->port2_data = (data & 0xef) | (cpustate->tx << 4); |
| 1342 | | } |
| 1343 | | else |
| 1344 | | { |
| 1345 | | cpustate->port2_data = data; |
| 1346 | | } |
| 1347 | | if(cpustate->port2_ddr == 0xff) |
| 1348 | | cpustate->io->write_byte(M6803_PORT2,cpustate->port2_data); |
| 1349 | | else |
| 1350 | | cpustate->io->write_byte(M6803_PORT2,(cpustate->port2_data & cpustate->port2_ddr) |
| 1351 | | | (cpustate->io->read_byte(M6803_PORT2) & (cpustate->port2_ddr ^ 0xff))); |
| 1442 | cpustate->port2_data = data; |
| 1443 | cpustate->port2_written = 1; |
| 1444 | write_port2(cpustate); |
| 1352 | 1445 | break; |
| 1353 | 1446 | case 0x04: |
| 1354 | 1447 | if (cpustate->port3_ddr != data) |
| r10115 | r10116 | |
| 1356 | 1449 | cpustate->port3_ddr = data; |
| 1357 | 1450 | if(cpustate->port3_ddr == 0xff) |
| 1358 | 1451 | cpustate->io->write_byte(M6803_PORT3,cpustate->port3_data); |
| 1359 | | else |
| 1452 | else if (cpustate->port3_ddr) |
| 1360 | 1453 | cpustate->io->write_byte(M6803_PORT3,(cpustate->port3_data & cpustate->port3_ddr) |
| 1361 | 1454 | | (cpustate->io->read_byte(M6803_PORT3) & (cpustate->port3_ddr ^ 0xff))); |
| 1362 | 1455 | } |
| r10115 | r10116 | |
| 1367 | 1460 | cpustate->port4_ddr = data; |
| 1368 | 1461 | if(cpustate->port4_ddr == 0xff) |
| 1369 | 1462 | cpustate->io->write_byte(M6803_PORT4,cpustate->port4_data); |
| 1370 | | else |
| 1463 | else if (cpustate->port4_ddr) |
| 1371 | 1464 | cpustate->io->write_byte(M6803_PORT4,(cpustate->port4_data & cpustate->port4_ddr) |
| 1372 | 1465 | | (cpustate->io->read_byte(M6803_PORT4) & (cpustate->port4_ddr ^ 0xff))); |
| 1373 | 1466 | } |
| r10115 | r10116 | |
| 1376 | 1469 | cpustate->port3_data = data; |
| 1377 | 1470 | if(cpustate->port3_ddr == 0xff) |
| 1378 | 1471 | cpustate->io->write_byte(M6803_PORT3,cpustate->port3_data); |
| 1379 | | else |
| 1472 | else if (cpustate->port3_ddr) |
| 1380 | 1473 | cpustate->io->write_byte(M6803_PORT3,(cpustate->port3_data & cpustate->port3_ddr) |
| 1381 | 1474 | | (cpustate->io->read_byte(M6803_PORT3) & (cpustate->port3_ddr ^ 0xff))); |
| 1382 | 1475 | break; |
| r10115 | r10116 | |
| 1384 | 1477 | cpustate->port4_data = data; |
| 1385 | 1478 | if(cpustate->port4_ddr == 0xff) |
| 1386 | 1479 | cpustate->io->write_byte(M6803_PORT4,cpustate->port4_data); |
| 1387 | | else |
| 1480 | else if (cpustate->port4_ddr) |
| 1388 | 1481 | cpustate->io->write_byte(M6803_PORT4,(cpustate->port4_data & cpustate->port4_ddr) |
| 1389 | 1482 | | (cpustate->io->read_byte(M6803_PORT4) & (cpustate->port4_ddr ^ 0xff))); |
| 1390 | 1483 | break; |
| r10115 | r10116 | |
| 1429 | 1522 | logerror("CPU '%s' PC %04x: warning - write %02x to unsupported internal register %02x\n",space->cpu->tag(),cpu_get_pc(space->cpu),data,offset); |
| 1430 | 1523 | break; |
| 1431 | 1524 | case 0x10: |
| 1432 | | cpustate->rmcr = data & 0x0f; |
| 1433 | | |
| 1434 | | switch ((cpustate->rmcr & M6800_RMCR_CC_MASK) >> 2) |
| 1435 | | { |
| 1436 | | case 0: |
| 1437 | | case 3: // not implemented |
| 1438 | | timer_enable(cpustate->m6800_rx_timer, 0); |
| 1439 | | timer_enable(cpustate->m6800_tx_timer, 0); |
| 1440 | | break; |
| 1441 | | |
| 1442 | | case 1: |
| 1443 | | case 2: |
| 1444 | | { |
| 1445 | | int divisor = M6800_RMCR_SS[cpustate->rmcr & M6800_RMCR_SS_MASK]; |
| 1446 | | |
| 1447 | | timer_adjust_periodic(cpustate->m6800_rx_timer, attotime_zero, 0, ATTOTIME_IN_HZ(cpustate->clock / divisor)); |
| 1448 | | timer_adjust_periodic(cpustate->m6800_tx_timer, attotime_zero, 0, ATTOTIME_IN_HZ(cpustate->clock / divisor)); |
| 1449 | | } |
| 1450 | | break; |
| 1451 | | } |
| 1525 | set_rmcr(cpustate, data); |
| 1452 | 1526 | break; |
| 1453 | 1527 | case 0x11: |
| 1454 | 1528 | if ((data & M6800_TRCSR_TE) && !(cpustate->trcsr & M6800_TRCSR_TE)) |
| 1455 | 1529 | { |
| 1456 | 1530 | cpustate->txstate = M6800_TX_STATE_INIT; |
| 1531 | cpustate->txbits = 0; |
| 1532 | cpustate->tx = 1; |
| 1457 | 1533 | } |
| 1534 | |
| 1535 | if ((data & M6800_TRCSR_RE) && !(cpustate->trcsr & M6800_TRCSR_RE)) |
| 1536 | { |
| 1537 | cpustate->rxbits = 0; |
| 1538 | } |
| 1539 | |
| 1458 | 1540 | cpustate->trcsr = (cpustate->trcsr & 0xe0) | (data & 0x1f); |
| 1459 | 1541 | break; |
| 1460 | 1542 | case 0x13: |
| 1461 | | if (cpustate->trcsr_read) |
| 1543 | //logerror("M6800 '%s' Transmit Data Register: %02x\n", space->cpu->tag(), data); |
| 1544 | if (cpustate->trcsr_read_tdre) |
| 1462 | 1545 | { |
| 1463 | | cpustate->trcsr_read = 0; |
| 1546 | cpustate->trcsr_read_tdre = 0; |
| 1464 | 1547 | cpustate->trcsr &= ~M6800_TRCSR_TDRE; |
| 1465 | 1548 | } |
| 1466 | 1549 | cpustate->tdr = data; |