src/emu/machine/z8536.c
| r12911 | r12912 | |
| 8 | 8 | **********************************************************************/ |
| 9 | 9 | |
| 10 | 10 | /* |
| 11 | | |
| 12 | | TODO: |
| 13 | | |
| 14 | | - interrupts |
| 15 | | - vector |
| 16 | | - status affects vector |
| 17 | | - IE/IP/IUS |
| 18 | | - acknowledge |
| 19 | | - daisy chain |
| 20 | | - port I/O |
| 21 | | - counters/timers |
| 22 | 11 | |
| 12 | TODO: |
| 13 | |
| 14 | - interrupts |
| 15 | - vector |
| 16 | - status affects vector |
| 17 | - IE/IP/IUS |
| 18 | - acknowledge |
| 19 | - daisy chain |
| 20 | - port I/O |
| 21 | - counters/timers |
| 22 | |
| 23 | 23 | */ |
| 24 | 24 | |
| 25 | 25 | #include "emu.h" |
| r12911 | r12912 | |
| 287 | 287 | { |
| 288 | 288 | int state = ASSERT_LINE; |
| 289 | 289 | UINT8 vector = 0xff; |
| 290 | | |
| 290 | |
| 291 | 291 | if (m_register[MASTER_INTERRUPT_CONTROL] & MICR_MIE) |
| 292 | 292 | { |
| 293 | 293 | if ((m_register[COUNTER_TIMER_3_COMMAND_AND_STATUS] & (CTCS_IP | CTCS_IE)) == (CTCS_IP | CTCS_IE)) |
| r12911 | r12912 | |
| 359 | 359 | else |
| 360 | 360 | { |
| 361 | 361 | state = CLEAR_LINE; |
| 362 | | } |
| 362 | } |
| 363 | 363 | |
| 364 | 364 | if (m_int != state) |
| 365 | 365 | { |
| r12911 | r12912 | |
| 391 | 391 | case PORT_C_DATA: |
| 392 | 392 | data = 0xf0 | (m_in_pc_func(0) & 0x0f); |
| 393 | 393 | break; |
| 394 | | |
| 394 | |
| 395 | 395 | case COUNTER_TIMER_1_CURRENT_COUNT_MS_BYTE: |
| 396 | 396 | case COUNTER_TIMER_2_CURRENT_COUNT_MS_BYTE: |
| 397 | 397 | case COUNTER_TIMER_3_CURRENT_COUNT_MS_BYTE: |
| 398 | 398 | { |
| 399 | 399 | int timer = (offset - COUNTER_TIMER_1_CURRENT_COUNT_MS_BYTE) >> 1; |
| 400 | | |
| 400 | |
| 401 | 401 | if (m_register[COUNTER_TIMER_1_COMMAND_AND_STATUS + timer] & CTCS_RCC) |
| 402 | 402 | { |
| 403 | 403 | // read frozen value |
| r12911 | r12912 | |
| 416 | 416 | case COUNTER_TIMER_3_CURRENT_COUNT_LS_BYTE: |
| 417 | 417 | { |
| 418 | 418 | int timer = (offset - COUNTER_TIMER_1_CURRENT_COUNT_MS_BYTE) >> 1; |
| 419 | | |
| 419 | |
| 420 | 420 | if (m_register[COUNTER_TIMER_1_COMMAND_AND_STATUS + timer] & CTCS_RCC) |
| 421 | 421 | { |
| 422 | 422 | // read frozen value |
| r12911 | r12912 | |
| 427 | 427 | // read current count |
| 428 | 428 | data = m_counter[timer] & 0xff; |
| 429 | 429 | } |
| 430 | | |
| 430 | |
| 431 | 431 | // clear RCC bit |
| 432 | 432 | m_register[COUNTER_TIMER_1_COMMAND_AND_STATUS + timer] &= ~CTCS_RCC; |
| 433 | 433 | } |
| r12911 | r12912 | |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | m_register[offset] = data; |
| 488 | | |
| 488 | |
| 489 | 489 | check_interrupt(); |
| 490 | 490 | } |
| 491 | 491 | break; |
| r12911 | r12912 | |
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | m_register[offset] = data; |
| 506 | | |
| 506 | |
| 507 | 507 | for (int counter = 0; counter < 3; counter++) |
| 508 | 508 | { |
| 509 | 509 | // clear RCC bit if counter disabled |
| r12911 | r12912 | |
| 525 | 525 | if (LOG) logerror("%s Z8536 '%s' Counter/Timer Interrupt Vector: %02x\n", machine().describe_context(), tag(), data); |
| 526 | 526 | m_register[offset] = data; |
| 527 | 527 | break; |
| 528 | | |
| 528 | |
| 529 | 529 | case PORT_C_DATA_PATH_POLARITY: |
| 530 | 530 | if (LOG) logerror("%s Z8536 '%s' Port C Data Path Polarity: %02x\n", machine().describe_context(), tag(), data); |
| 531 | 531 | m_register[offset] = data; |
| r12911 | r12912 | |
| 535 | 535 | if (LOG) logerror("%s Z8536 '%s' Port C Data Direction: %02x\n", machine().describe_context(), tag(), data); |
| 536 | 536 | m_register[offset] = data; |
| 537 | 537 | break; |
| 538 | | |
| 538 | |
| 539 | 539 | case PORT_C_SPECIAL_IO_CONTROL: |
| 540 | 540 | if (LOG) logerror("%s Z8536 '%s' Port C Special I/O Control: %02x\n", machine().describe_context(), tag(), data); |
| 541 | 541 | m_register[offset] = data; |
| r12911 | r12912 | |
| 564 | 564 | check_interrupt(); |
| 565 | 565 | } |
| 566 | 566 | break; |
| 567 | | |
| 567 | |
| 568 | 568 | case COUNTER_TIMER_1_COMMAND_AND_STATUS: |
| 569 | 569 | case COUNTER_TIMER_2_COMMAND_AND_STATUS: |
| 570 | 570 | case COUNTER_TIMER_3_COMMAND_AND_STATUS: |
| r12911 | r12912 | |
| 577 | 577 | if (LOG) logerror("%s Z8536 '%s' Counter/Timer %u Gate Command Bit: %u\n", machine().describe_context(), tag(), counter + 1, (data & CTCS_GCB) ? 1 : 0); |
| 578 | 578 | if (LOG) logerror("%s Z8536 '%s' Counter/Timer %u Read Counter Control: %u\n", machine().describe_context(), tag(), counter + 1, (data & CTCS_RCC) ? 1 : 0); |
| 579 | 579 | } |
| 580 | | |
| 580 | |
| 581 | 581 | switch (data >> 5) |
| 582 | 582 | { |
| 583 | 583 | case IC_CLEAR_IP_IUS: m_register[offset] &= ~(CTCS_IP | CTCS_IUS);if (LOG) logerror("%s Z8536 '%s' Counter/Timer %u Clear IP/IUS\n", machine().describe_context(), tag(), counter + 1); break; |
| r12911 | r12912 | |
| 591 | 591 | |
| 592 | 592 | // gate command bit |
| 593 | 593 | m_register[offset] = (m_register[offset] & ~CTCS_GCB) | (data & CTCS_GCB); |
| 594 | | |
| 594 | |
| 595 | 595 | // trigger command bit |
| 596 | 596 | if (data & CTCS_TCB) |
| 597 | 597 | { |
| 598 | 598 | trigger(counter); |
| 599 | 599 | } |
| 600 | | |
| 600 | |
| 601 | 601 | // read counter control |
| 602 | 602 | if (counter_enabled(counter) && (data & CTCS_RCC)) |
| 603 | 603 | { |
| r12911 | r12912 | |
| 606 | 606 | m_register[COUNTER_TIMER_1_CURRENT_COUNT_MS_BYTE + (counter << 1)] = m_counter[counter] >> 8; |
| 607 | 607 | m_register[COUNTER_TIMER_1_CURRENT_COUNT_LS_BYTE + (counter << 1)] = m_counter[counter] & 0xff; |
| 608 | 608 | } |
| 609 | | |
| 609 | |
| 610 | 610 | check_interrupt(); |
| 611 | 611 | } |
| 612 | 612 | break; |
| r12911 | r12912 | |
| 628 | 628 | m_out_pc_func(0, m_output[PORT_C]); |
| 629 | 629 | } |
| 630 | 630 | break; |
| 631 | | |
| 631 | |
| 632 | 632 | case COUNTER_TIMER_1_TIME_CONSTANT_MS_BYTE: |
| 633 | 633 | case COUNTER_TIMER_2_TIME_CONSTANT_MS_BYTE: |
| 634 | 634 | case COUNTER_TIMER_3_TIME_CONSTANT_MS_BYTE: |
| r12911 | r12912 | |
| 637 | 637 | int counter = (offset - COUNTER_TIMER_1_TIME_CONSTANT_MS_BYTE) >> 1; |
| 638 | 638 | if (LOG) logerror("%s Z8536 '%s' Counter/Timer %u Time Constant MSB: %02x\n", machine().describe_context(), tag(), counter + 1, data); |
| 639 | 639 | } |
| 640 | | |
| 640 | |
| 641 | 641 | m_register[offset] = data; |
| 642 | 642 | break; |
| 643 | 643 | |
| r12911 | r12912 | |
| 649 | 649 | int counter = (offset - COUNTER_TIMER_1_TIME_CONSTANT_LS_BYTE) >> 1; |
| 650 | 650 | if (LOG) logerror("%s Z8536 '%s' Counter/Timer %u Time Constant LSB: %02x\n", machine().describe_context(), tag(), counter + 1, data); |
| 651 | 651 | } |
| 652 | | |
| 652 | |
| 653 | 653 | m_register[offset] = data; |
| 654 | 654 | break; |
| 655 | 655 | |
| r12911 | r12912 | |
| 680 | 680 | char port = BIT(offset, 3) ? 'B' : 'A'; |
| 681 | 681 | int pts = (data & PMS_PTS_MASK) >> 6; |
| 682 | 682 | int pms = (data & PMS_PMS_MASK) >> 1; |
| 683 | | |
| 683 | |
| 684 | 684 | logerror("%s Z8536 '%s' Port %c Port Type: %s\n", machine().describe_context(), tag(), port, PMS_PTS[pts]); |
| 685 | 685 | logerror("%s Z8536 '%s' Port %c Interrupt on 2 Bytes: %u\n", machine().describe_context(), tag(), port, (data & PMS_ITB) ? 1 : 0); |
| 686 | 686 | logerror("%s Z8536 '%s' Port %c Single Buffer: %u\n", machine().describe_context(), tag(), port, (data & PMS_SB) ? 1 : 0); |
| 687 | 687 | logerror("%s Z8536 '%s' Port %c Interrupt on Match Only: %u\n", machine().describe_context(), tag(), port, (data & PMS_IMO) ? 1 : 0); |
| 688 | 688 | logerror("%s Z8536 '%s' Port %c Pattern Mode: %s\n", machine().describe_context(), tag(), port, PMS_PMS[pms]); |
| 689 | | |
| 689 | |
| 690 | 690 | if (pts == PTS_BIT) |
| 691 | 691 | logerror("%s Z8536 '%s' Port %c Latch on Pattern Match: %u\n", machine().describe_context(), tag(), port, (data & PMS_LPM) ? 1 : 0); |
| 692 | 692 | else |
| 693 | 693 | logerror("%s Z8536 '%s' Port %c Deskew Timer Enable: %u\n", machine().describe_context(), tag(), port, (data & PMS_DTE) ? 1 : 0); |
| 694 | 694 | } |
| 695 | | |
| 695 | |
| 696 | 696 | m_register[offset] = data; |
| 697 | 697 | break; |
| 698 | | |
| 698 | |
| 699 | 699 | case PORT_A_HANDSHAKE_SPECIFICATION: |
| 700 | 700 | case PORT_B_HANDSHAKE_SPECIFICATION: |
| 701 | 701 | // TODO |
| 702 | 702 | break; |
| 703 | | |
| 703 | |
| 704 | 704 | case PORT_A_DATA_PATH_POLARITY: |
| 705 | 705 | case PORT_B_DATA_PATH_POLARITY: |
| 706 | 706 | if (LOG) logerror("%s Z8536 '%s' Port %c Data Path Polarity: %02x\n", machine().describe_context(), tag(), BIT(offset, 3) ? 'B' : 'A', data); |
| r12911 | r12912 | |
| 712 | 712 | if (LOG) logerror("%s Z8536 '%s' Port %c Data Direction: %02x\n", machine().describe_context(), tag(), BIT(offset, 3) ? 'B' : 'A', data); |
| 713 | 713 | m_register[offset] = data; |
| 714 | 714 | break; |
| 715 | | |
| 715 | |
| 716 | 716 | case PORT_A_SPECIAL_IO_CONTROL: |
| 717 | 717 | case PORT_B_SPECIAL_IO_CONTROL: |
| 718 | 718 | if (LOG) logerror("%s Z8536 '%s' Port %c Special I/O Control: %02x\n", machine().describe_context(), tag(), BIT(offset, 3) ? 'B' : 'A', data); |
| r12911 | r12912 | |
| 724 | 724 | if (LOG) logerror("%s Z8536 '%s' Port %c Pattern Polarity: %02x\n", machine().describe_context(), tag(), BIT(offset, 3) ? 'B' : 'A', data); |
| 725 | 725 | m_register[offset] = data; |
| 726 | 726 | break; |
| 727 | | |
| 727 | |
| 728 | 728 | case PORT_A_PATTERN_TRANSITION: |
| 729 | 729 | case PORT_B_PATTERN_TRANSITION: |
| 730 | 730 | if (LOG) logerror("%s Z8536 '%s' Port %c Pattern Transition: %02x\n", machine().describe_context(), tag(), BIT(offset, 3) ? 'B' : 'A', data); |
| 731 | 731 | m_register[offset] = data; |
| 732 | 732 | break; |
| 733 | | |
| 733 | |
| 734 | 734 | case PORT_A_PATTERN_MASK: |
| 735 | 735 | case PORT_B_PATTERN_MASK: |
| 736 | 736 | if (LOG) logerror("%s Z8536 '%s' Port %c Pattern Mask: %02x\n", machine().describe_context(), tag(), BIT(offset, 3) ? 'B' : 'A', data); |
| 737 | 737 | m_register[offset] = data; |
| 738 | 738 | break; |
| 739 | | |
| 739 | |
| 740 | 740 | default: |
| 741 | 741 | logerror("%s: Z8536 '%s' Unimplemented write %02x to register %u\n", machine().describe_context(), tag(), data, offset); |
| 742 | 742 | m_register[offset] = data; |
| r12911 | r12912 | |
| 763 | 763 | inline bool z8536_device::counter_enabled(device_timer_id id) |
| 764 | 764 | { |
| 765 | 765 | bool enabled = false; |
| 766 | | |
| 766 | |
| 767 | 767 | switch (id) |
| 768 | 768 | { |
| 769 | 769 | case TIMER_1: |
| 770 | 770 | enabled = (m_register[MASTER_CONFIGURATION_CONTROL] & MCCR_CT1E) ? true : false; |
| 771 | 771 | break; |
| 772 | | |
| 772 | |
| 773 | 773 | case TIMER_2: |
| 774 | 774 | enabled = (m_register[MASTER_CONFIGURATION_CONTROL] & MCCR_CT2E) ? true : false; |
| 775 | 775 | break; |
| 776 | | |
| 776 | |
| 777 | 777 | case TIMER_3: |
| 778 | 778 | enabled = (m_register[MASTER_CONFIGURATION_CONTROL] & MCCR_PCE_CT3E) ? true : false; |
| 779 | 779 | break; |
| 780 | 780 | } |
| 781 | | |
| 781 | |
| 782 | 782 | return enabled; |
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | |
| 786 | 786 | //------------------------------------------------- |
| 787 | | // counter_external_output - |
| 787 | // counter_external_output - |
| 788 | 788 | //------------------------------------------------- |
| 789 | 789 | |
| 790 | 790 | inline bool z8536_device::counter_external_output(device_timer_id id) |
| r12911 | r12912 | |
| 794 | 794 | |
| 795 | 795 | |
| 796 | 796 | //------------------------------------------------- |
| 797 | | // counter_external_count - |
| 797 | // counter_external_count - |
| 798 | 798 | //------------------------------------------------- |
| 799 | 799 | |
| 800 | 800 | inline bool z8536_device::counter_external_count(device_timer_id id) |
| r12911 | r12912 | |
| 804 | 804 | |
| 805 | 805 | |
| 806 | 806 | //------------------------------------------------- |
| 807 | | // counter_external_trigger - |
| 807 | // counter_external_trigger - |
| 808 | 808 | //------------------------------------------------- |
| 809 | 809 | |
| 810 | 810 | inline bool z8536_device::counter_external_trigger(device_timer_id id) |
| r12911 | r12912 | |
| 814 | 814 | |
| 815 | 815 | |
| 816 | 816 | //------------------------------------------------- |
| 817 | | // counter_external_gate - |
| 817 | // counter_external_gate - |
| 818 | 818 | //------------------------------------------------- |
| 819 | 819 | |
| 820 | 820 | inline bool z8536_device::counter_external_gate(device_timer_id id) |
| r12911 | r12912 | |
| 824 | 824 | |
| 825 | 825 | |
| 826 | 826 | //------------------------------------------------- |
| 827 | | // counter_gated - |
| 827 | // counter_gated - |
| 828 | 828 | //------------------------------------------------- |
| 829 | 829 | |
| 830 | 830 | inline bool z8536_device::counter_gated(device_timer_id id) |
| r12911 | r12912 | |
| 841 | 841 | { |
| 842 | 842 | if (!counter_gated(id)) return; |
| 843 | 843 | if (!m_register[COUNTER_TIMER_1_COMMAND_AND_STATUS + id] & CTCS_CIP) return; |
| 844 | | |
| 844 | |
| 845 | 845 | // count down |
| 846 | 846 | m_counter[id]--; |
| 847 | 847 | |
| r12911 | r12912 | |
| 857 | 857 | // set interrupt pending bit |
| 858 | 858 | m_register[COUNTER_TIMER_1_COMMAND_AND_STATUS + id] |= CTCS_IP; |
| 859 | 859 | } |
| 860 | | |
| 860 | |
| 861 | 861 | if (m_register[COUNTER_TIMER_1_MODE_SPECIFICATION + id] & CTMS_CSC) |
| 862 | 862 | { |
| 863 | 863 | // reload counter with time constant |
| r12911 | r12912 | |
| 866 | 866 | else |
| 867 | 867 | { |
| 868 | 868 | if (LOG) logerror("%s Z8536 '%s' Counter/Timer %u Terminal Count\n", machine().describe_context(), tag(), id + 1); |
| 869 | | |
| 869 | |
| 870 | 870 | // clear count in progress bit |
| 871 | 871 | m_register[COUNTER_TIMER_1_COMMAND_AND_STATUS + id] &= ~CTCS_CIP; |
| 872 | 872 | } |
| 873 | | |
| 873 | |
| 874 | 874 | check_interrupt(); |
| 875 | 875 | } |
| 876 | 876 | } |
| r12911 | r12912 | |
| 884 | 884 | { |
| 885 | 885 | // ignore triggers during countdown if retrigger is disabled |
| 886 | 886 | if (!(m_register[COUNTER_TIMER_1_MODE_SPECIFICATION + id] & CTMS_REB) && (m_register[COUNTER_TIMER_1_COMMAND_AND_STATUS + id] & CTCS_CIP)) return; |
| 887 | | |
| 887 | |
| 888 | 888 | if (LOG) logerror("%s Z8536 '%s' Counter/Timer %u Trigger\n", machine().describe_context(), tag(), id + 1); |
| 889 | | |
| 889 | |
| 890 | 890 | // load counter with time constant |
| 891 | 891 | m_counter[id] = (m_register[COUNTER_TIMER_1_TIME_CONSTANT_MS_BYTE + (id << 1)] << 8) | m_register[COUNTER_TIMER_1_TIME_CONSTANT_LS_BYTE + (id << 1)]; |
| 892 | 892 | |
| r12911 | r12912 | |
| 1182 | 1182 | { |
| 1183 | 1183 | m_register[COUNTER_TIMER_1_COMMAND_AND_STATUS] |= CTCS_IUS; |
| 1184 | 1184 | } |
| 1185 | | |
| 1185 | |
| 1186 | 1186 | if (m_register[MASTER_INTERRUPT_CONTROL] & MICR_NV) |
| 1187 | 1187 | { |
| 1188 | 1188 | // no vector |