src/mess/drivers/fmtowns.c
| r7617 | r7618 | |
| 127 | 127 | #define TOWNS_CD_IRQ_MPU 1 |
| 128 | 128 | #define TOWNS_CD_IRQ_DMA 2 |
| 129 | 129 | |
| 130 | enum |
| 131 | { |
| 132 | MOUSE_START, |
| 133 | MOUSE_SYNC, |
| 134 | MOUSE_X_HIGH, |
| 135 | MOUSE_X_LOW, |
| 136 | MOUSE_Y_HIGH, |
| 137 | MOUSE_Y_LOW |
| 138 | }; |
| 139 | |
| 130 | 140 | static UINT8 ftimer; |
| 131 | 141 | static UINT8 nmi_mask; |
| 132 | 142 | static UINT8 compat_mode; |
| r7617 | r7618 | |
| 156 | 166 | static UINT8 towns_kb_output; // key output |
| 157 | 167 | static UINT8 towns_kb_extend; // extended key output |
| 158 | 168 | static emu_timer* towns_kb_timer; |
| 169 | static emu_timer* towns_mouse_timer; |
| 159 | 170 | static UINT8 towns_fm_irq_flag; |
| 160 | 171 | static UINT8 towns_pcm_irq_flag; |
| 161 | 172 | static UINT8 towns_pcm_channel_flag; |
| 162 | 173 | static UINT8 towns_pcm_channel_mask; |
| 163 | 174 | static UINT8 towns_pad_mask; |
| 175 | static UINT8 towns_mouse_output; |
| 176 | static UINT8 towns_mouse_x; |
| 177 | static UINT8 towns_mouse_y; |
| 164 | 178 | |
| 165 | 179 | static struct towns_cdrom_controller |
| 166 | 180 | { |
| r7617 | r7618 | |
| 748 | 762 | |
| 749 | 763 | // Controller ports |
| 750 | 764 | // Joysticks are multiplexed, with fire buttons available when bits 0 and 1 of port 0x4d6 are high. (bits 2 and 3 for second port?) |
| 765 | static TIMER_CALLBACK(towns_mouse_timeout) |
| 766 | { |
| 767 | towns_mouse_output = MOUSE_START; // reset mouse data |
| 768 | } |
| 769 | |
| 751 | 770 | static READ32_HANDLER(towns_padport_r) |
| 752 | 771 | { |
| 753 | 772 | UINT32 ret = 0; |
| 754 | | UINT8 extra1 = input_port_read(space->machine,"joy1_ex"); |
| 755 | | UINT8 extra2 = input_port_read(space->machine,"joy2_ex"); |
| 773 | UINT32 porttype = input_port_read(space->machine,"ctrltype"); |
| 774 | UINT8 extra1; |
| 775 | UINT8 extra2; |
| 776 | UINT32 state; |
| 756 | 777 | |
| 757 | | if(towns_pad_mask & 0x10) |
| 758 | | ret |= (input_port_read(space->machine,"joy1") & 0x3f) | 0x00000040; |
| 759 | | else |
| 760 | | ret |= (input_port_read(space->machine,"joy1") & 0x0f) | 0x00000030; |
| 778 | if((porttype & 0x0f) == 0x00) |
| 779 | ret |= 0x000000ff; |
| 780 | if((porttype & 0xf0) == 0x00) |
| 781 | ret |= 0x00ff0000; |
| 782 | if((porttype & 0x0f) == 0x01) |
| 783 | { |
| 784 | extra1 = input_port_read(space->machine,"joy1_ex"); |
| 785 | |
| 786 | if(towns_pad_mask & 0x10) |
| 787 | ret |= (input_port_read(space->machine,"joy1") & 0x3f) | 0x00000040; |
| 788 | else |
| 789 | ret |= (input_port_read(space->machine,"joy1") & 0x0f) | 0x00000030; |
| 790 | |
| 791 | if(extra1 & 0x01) // Run button = left+right |
| 792 | ret &= ~0x0000000c; |
| 793 | if(extra1 & 0x02) // Select button = up+down |
| 794 | ret &= ~0x00000003; |
| 795 | |
| 796 | if((extra1 & 0x10) && (towns_pad_mask & 0x01)) |
| 797 | ret &= ~0x00000010; |
| 798 | if((extra1 & 0x20) && (towns_pad_mask & 0x02)) |
| 799 | ret &= ~0x00000020; |
| 800 | } |
| 801 | if((porttype & 0xf0) == 0x10) |
| 802 | { |
| 803 | extra2 = input_port_read(space->machine,"joy2_ex"); |
| 761 | 804 | |
| 762 | | if(towns_pad_mask & 0x20) |
| 763 | | ret |= ((input_port_read(space->machine,"joy2") & 0x3f) << 16) | 0x00400000; |
| 764 | | else |
| 765 | | ret |= ((input_port_read(space->machine,"joy2") & 0x0f) << 16) | 0x00300000; |
| 805 | if(towns_pad_mask & 0x20) |
| 806 | ret |= ((input_port_read(space->machine,"joy2") & 0x3f) << 16) | 0x00400000; |
| 807 | else |
| 808 | ret |= ((input_port_read(space->machine,"joy2") & 0x0f) << 16) | 0x00300000; |
| 809 | |
| 810 | if(extra2 & 0x01) |
| 811 | ret &= ~0x000c0000; |
| 812 | if(extra2 & 0x02) |
| 813 | ret &= ~0x00030000; |
| 766 | 814 | |
| 767 | | if(extra1 & 0x01) // Run button = left+right |
| 768 | | ret &= ~0x0000000c; |
| 769 | | if(extra2 & 0x01) |
| 770 | | ret &= ~0x000c0000; |
| 771 | | if(extra1 & 0x02) // Select button = up+down |
| 772 | | ret &= ~0x00000003; |
| 773 | | if(extra2 & 0x02) |
| 774 | | ret &= ~0x00030000; |
| 775 | | |
| 776 | | if((extra1 & 0x10) && (towns_pad_mask & 0x01)) |
| 777 | | ret &= ~0x00000010; |
| 778 | | if((extra1 & 0x20) && (towns_pad_mask & 0x02)) |
| 779 | | ret &= ~0x00000020; |
| 780 | | if((extra2 & 0x10) && (towns_pad_mask & 0x04)) |
| 781 | | ret &= ~0x00100000; |
| 782 | | if((extra2 & 0x20) && (towns_pad_mask & 0x08)) |
| 783 | | ret &= ~0x00200000; |
| 784 | | |
| 815 | if((extra2 & 0x10) && (towns_pad_mask & 0x04)) |
| 816 | ret &= ~0x00100000; |
| 817 | if((extra2 & 0x20) && (towns_pad_mask & 0x08)) |
| 818 | ret &= ~0x00200000; |
| 819 | } |
| 820 | if((porttype & 0x0f) == 0x02) // mouse |
| 821 | { |
| 822 | switch(towns_mouse_output) |
| 823 | { |
| 824 | case MOUSE_X_HIGH: |
| 825 | ret |= ((towns_mouse_x & 0xf0) >> 4); |
| 826 | break; |
| 827 | case MOUSE_X_LOW: |
| 828 | ret |= (towns_mouse_x & 0x0f); |
| 829 | break; |
| 830 | case MOUSE_Y_HIGH: |
| 831 | ret |= ((towns_mouse_y & 0xf0) >> 4); |
| 832 | break; |
| 833 | case MOUSE_Y_LOW: |
| 834 | ret |= (towns_mouse_y & 0x0f); |
| 835 | break; |
| 836 | case MOUSE_START: |
| 837 | case MOUSE_SYNC: |
| 838 | default: |
| 839 | if(towns_mouse_output < MOUSE_Y_LOW) |
| 840 | ret |= 0x0000000f; |
| 841 | } |
| 842 | |
| 843 | //logerror("Mouse: X=%02x Y=%02x state=%i\n",towns_mouse_x,towns_mouse_y,towns_mouse_output); |
| 844 | // button states are always visible |
| 845 | state = input_port_read(space->machine,"mouse1"); |
| 846 | if(!(state & 0x01)) |
| 847 | ret |= 0x00000010; |
| 848 | if(!(state & 0x02)) |
| 849 | ret |= 0x00000020; |
| 850 | if(towns_pad_mask & 0x10) |
| 851 | ret |= 0x00000040; |
| 852 | } |
| 853 | |
| 785 | 854 | return ret; |
| 786 | 855 | } |
| 787 | 856 | |
| 788 | 857 | static WRITE32_HANDLER(towns_pad_mask_w) |
| 789 | 858 | { |
| 859 | static UINT8 prev; |
| 860 | static UINT8 prev_x,prev_y; |
| 861 | UINT8 current_x,current_y; |
| 862 | |
| 790 | 863 | if(ACCESSING_BITS_16_23) |
| 864 | { |
| 791 | 865 | towns_pad_mask = (data & 0x00ff0000) >> 16; |
| 866 | if((input_port_read(space->machine,"ctrltype") & 0x0f) == 0x02) // mouse |
| 867 | { |
| 868 | if((towns_pad_mask & 0x10) != 0 && (prev & 0x10) == 0) |
| 869 | { |
| 870 | if(towns_mouse_output == MOUSE_START) |
| 871 | { |
| 872 | towns_mouse_output = MOUSE_X_HIGH; |
| 873 | current_x = input_port_read(space->machine,"mouse2"); |
| 874 | current_y = input_port_read(space->machine,"mouse3"); |
| 875 | towns_mouse_x = prev_x - current_x; |
| 876 | towns_mouse_y = prev_y - current_y; |
| 877 | prev_x = current_x; |
| 878 | prev_y = current_y; |
| 879 | } |
| 880 | else |
| 881 | towns_mouse_output++; |
| 882 | timer_adjust_periodic(towns_mouse_timer,ATTOTIME_IN_USEC(600),0,attotime_zero); |
| 883 | } |
| 884 | if((towns_pad_mask & 0x10) == 0 && (prev & 0x10) != 0) |
| 885 | { |
| 886 | if(towns_mouse_output == MOUSE_START) |
| 887 | { |
| 888 | towns_mouse_output = MOUSE_SYNC; |
| 889 | current_x = input_port_read(space->machine,"mouse2"); |
| 890 | current_y = input_port_read(space->machine,"mouse3"); |
| 891 | towns_mouse_x = prev_x - current_x; |
| 892 | towns_mouse_y = prev_y - current_y; |
| 893 | prev_x = current_x; |
| 894 | prev_y = current_y; |
| 895 | } |
| 896 | else |
| 897 | towns_mouse_output++; |
| 898 | timer_adjust_periodic(towns_mouse_timer,ATTOTIME_IN_USEC(600),0,attotime_zero); |
| 899 | } |
| 900 | prev = towns_pad_mask; |
| 901 | } |
| 902 | } |
| 792 | 903 | } |
| 793 | 904 | |
| 794 | 905 | static READ8_HANDLER( towns_cmos8_r ) |
| r7617 | r7618 | |
| 1747 | 1858 | |
| 1748 | 1859 | /* Input ports */ |
| 1749 | 1860 | static INPUT_PORTS_START( towns ) |
| 1861 | PORT_START("ctrltype") |
| 1862 | PORT_CATEGORY_CLASS(0x0f,0x01,"Joystick port 1") |
| 1863 | PORT_CATEGORY_ITEM(0x00,"Nothing",10) |
| 1864 | PORT_CATEGORY_ITEM(0x01,"Standard 2-button joystick",11) |
| 1865 | PORT_CATEGORY_ITEM(0x02,"Mouse",12) |
| 1866 | PORT_CATEGORY_CLASS(0xf0,0x10,"Joystick port 2") |
| 1867 | PORT_CATEGORY_ITEM(0x00,"Nothing",20) |
| 1868 | PORT_CATEGORY_ITEM(0x10,"Standard 2-button joystick",21) |
| 1869 | |
| 1750 | 1870 | // Keyboard |
| 1751 | 1871 | PORT_START( "key1" ) // scancodes 0x00-0x1f |
| 1752 | 1872 | PORT_BIT(0x00000001,IP_ACTIVE_HIGH,IPT_UNUSED) |
| r7617 | r7618 | |
| 1883 | 2003 | PORT_BIT(0x20000000,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_NAME("COPY") |
| 1884 | 2004 | |
| 1885 | 2005 | PORT_START("joy1") |
| 1886 | | PORT_BIT(0x00000001,IP_ACTIVE_LOW, IPT_JOYSTICK_UP) PORT_PLAYER(1) |
| 1887 | | PORT_BIT(0x00000002,IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN) PORT_PLAYER(1) |
| 1888 | | PORT_BIT(0x00000004,IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT) PORT_PLAYER(1) |
| 1889 | | PORT_BIT(0x00000008,IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT) PORT_PLAYER(1) |
| 1890 | | PORT_BIT(0x00000010,IP_ACTIVE_LOW, IPT_UNUSED) |
| 1891 | | PORT_BIT(0x00000020,IP_ACTIVE_LOW, IPT_UNUSED) |
| 1892 | | PORT_BIT(0x00000040,IP_ACTIVE_HIGH, IPT_UNUSED) |
| 1893 | | PORT_BIT(0x00000080,IP_ACTIVE_HIGH, IPT_UNUSED) |
| 2006 | PORT_BIT(0x00000001,IP_ACTIVE_LOW, IPT_JOYSTICK_UP) PORT_PLAYER(1) PORT_CATEGORY(11) |
| 2007 | PORT_BIT(0x00000002,IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN) PORT_PLAYER(1) PORT_CATEGORY(11) |
| 2008 | PORT_BIT(0x00000004,IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT) PORT_PLAYER(1) PORT_CATEGORY(11) |
| 2009 | PORT_BIT(0x00000008,IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT) PORT_PLAYER(1) PORT_CATEGORY(11) |
| 2010 | PORT_BIT(0x00000010,IP_ACTIVE_LOW, IPT_UNUSED) PORT_CATEGORY(11) |
| 2011 | PORT_BIT(0x00000020,IP_ACTIVE_LOW, IPT_UNUSED) PORT_CATEGORY(11) |
| 2012 | PORT_BIT(0x00000040,IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CATEGORY(11) |
| 2013 | PORT_BIT(0x00000080,IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CATEGORY(11) |
| 1894 | 2014 | |
| 1895 | 2015 | PORT_START("joy1_ex") |
| 1896 | | PORT_BIT(0x00000001,IP_ACTIVE_HIGH, IPT_START) PORT_NAME("1P Run") PORT_PLAYER(1) |
| 1897 | | PORT_BIT(0x00000002,IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("1P Select") PORT_PLAYER(1) |
| 1898 | | PORT_BIT(0x00000004,IP_ACTIVE_LOW, IPT_UNUSED) |
| 1899 | | PORT_BIT(0x00000008,IP_ACTIVE_LOW, IPT_UNUSED) |
| 1900 | | PORT_BIT(0x00000010,IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_PLAYER(1) |
| 1901 | | PORT_BIT(0x00000020,IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_PLAYER(1) |
| 1902 | | PORT_BIT(0x00000040,IP_ACTIVE_HIGH, IPT_UNUSED) |
| 1903 | | PORT_BIT(0x00000080,IP_ACTIVE_HIGH, IPT_UNUSED) |
| 2016 | PORT_BIT(0x00000001,IP_ACTIVE_HIGH, IPT_START) PORT_NAME("1P Run") PORT_PLAYER(1) PORT_CATEGORY(11) |
| 2017 | PORT_BIT(0x00000002,IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("1P Select") PORT_PLAYER(1) PORT_CATEGORY(11) |
| 2018 | PORT_BIT(0x00000004,IP_ACTIVE_LOW, IPT_UNUSED) PORT_CATEGORY(11) |
| 2019 | PORT_BIT(0x00000008,IP_ACTIVE_LOW, IPT_UNUSED) PORT_CATEGORY(11) |
| 2020 | PORT_BIT(0x00000010,IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_PLAYER(1) PORT_CATEGORY(11) |
| 2021 | PORT_BIT(0x00000020,IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_PLAYER(1) PORT_CATEGORY(11) |
| 2022 | PORT_BIT(0x00000040,IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CATEGORY(11) |
| 2023 | PORT_BIT(0x00000080,IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CATEGORY(11) |
| 1904 | 2024 | |
| 1905 | 2025 | PORT_START("joy2") |
| 1906 | | PORT_BIT(0x00000001,IP_ACTIVE_LOW, IPT_JOYSTICK_UP) PORT_PLAYER(2) |
| 1907 | | PORT_BIT(0x00000002,IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN) PORT_PLAYER(2) |
| 1908 | | PORT_BIT(0x00000004,IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT) PORT_PLAYER(2) |
| 1909 | | PORT_BIT(0x00000008,IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT) PORT_PLAYER(2) |
| 1910 | | PORT_BIT(0x00000010,IP_ACTIVE_LOW, IPT_UNUSED) |
| 1911 | | PORT_BIT(0x00000020,IP_ACTIVE_LOW, IPT_UNUSED) |
| 1912 | | PORT_BIT(0x00000040,IP_ACTIVE_HIGH, IPT_UNUSED) |
| 1913 | | PORT_BIT(0x00000080,IP_ACTIVE_HIGH, IPT_UNUSED) |
| 2026 | PORT_BIT(0x00000001,IP_ACTIVE_LOW, IPT_JOYSTICK_UP) PORT_PLAYER(2) PORT_CATEGORY(21) |
| 2027 | PORT_BIT(0x00000002,IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN) PORT_PLAYER(2) PORT_CATEGORY(21) |
| 2028 | PORT_BIT(0x00000004,IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT) PORT_PLAYER(2) PORT_CATEGORY(21) |
| 2029 | PORT_BIT(0x00000008,IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT) PORT_PLAYER(2) PORT_CATEGORY(21) |
| 2030 | PORT_BIT(0x00000010,IP_ACTIVE_LOW, IPT_UNUSED) PORT_CATEGORY(21) |
| 2031 | PORT_BIT(0x00000020,IP_ACTIVE_LOW, IPT_UNUSED) PORT_CATEGORY(21) |
| 2032 | PORT_BIT(0x00000040,IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CATEGORY(21) |
| 2033 | PORT_BIT(0x00000080,IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CATEGORY(21) |
| 1914 | 2034 | |
| 1915 | 2035 | PORT_START("joy2_ex") |
| 1916 | | PORT_BIT(0x00000001,IP_ACTIVE_HIGH, IPT_START) PORT_NAME("2P Run") PORT_PLAYER(2) |
| 1917 | | PORT_BIT(0x00000002,IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("2P Select") PORT_PLAYER(2) |
| 1918 | | PORT_BIT(0x00000004,IP_ACTIVE_LOW, IPT_UNUSED) |
| 1919 | | PORT_BIT(0x00000008,IP_ACTIVE_LOW, IPT_UNUSED) |
| 1920 | | PORT_BIT(0x00000010,IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_PLAYER(2) |
| 1921 | | PORT_BIT(0x00000020,IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_PLAYER(2) |
| 1922 | | PORT_BIT(0x00000040,IP_ACTIVE_HIGH, IPT_UNUSED) |
| 1923 | | PORT_BIT(0x00000080,IP_ACTIVE_HIGH, IPT_UNUSED) |
| 2036 | PORT_BIT(0x00000001,IP_ACTIVE_HIGH, IPT_START) PORT_NAME("2P Run") PORT_PLAYER(2) PORT_CATEGORY(21) |
| 2037 | PORT_BIT(0x00000002,IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("2P Select") PORT_PLAYER(2) PORT_CATEGORY(21) |
| 2038 | PORT_BIT(0x00000004,IP_ACTIVE_LOW, IPT_UNUSED) PORT_CATEGORY(21) |
| 2039 | PORT_BIT(0x00000008,IP_ACTIVE_LOW, IPT_UNUSED) PORT_CATEGORY(21) |
| 2040 | PORT_BIT(0x00000010,IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_PLAYER(2) PORT_CATEGORY(21) |
| 2041 | PORT_BIT(0x00000020,IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_PLAYER(2) PORT_CATEGORY(21) |
| 2042 | PORT_BIT(0x00000040,IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CATEGORY(21) |
| 2043 | PORT_BIT(0x00000080,IP_ACTIVE_HIGH, IPT_UNUSED) PORT_CATEGORY(21) |
| 2044 | |
| 2045 | PORT_START("mouse1") // buttons |
| 2046 | PORT_BIT( 0x00000001, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Left mouse button") PORT_CODE(MOUSECODE_BUTTON1) PORT_CATEGORY(12) |
| 2047 | PORT_BIT( 0x00000002, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("Right mouse button") PORT_CODE(MOUSECODE_BUTTON2) PORT_CATEGORY(12) |
| 2048 | |
| 2049 | PORT_START("mouse2") // X-axis |
| 2050 | PORT_BIT( 0xff, 0x00, IPT_MOUSE_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1) PORT_CATEGORY(12) |
| 2051 | |
| 2052 | PORT_START("mouse3") // Y-axis |
| 2053 | PORT_BIT( 0xff, 0x00, IPT_MOUSE_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(1) PORT_CATEGORY(12) |
| 2054 | |
| 1924 | 2055 | INPUT_PORTS_END |
| 1925 | 2056 | |
| 1926 | 2057 | static INPUT_PORTS_START( marty ) |
| r7617 | r7618 | |
| 1948 | 2079 | towns_init_rtc(); |
| 1949 | 2080 | towns_rtc_timer = timer_alloc(machine,rtc_second,NULL); |
| 1950 | 2081 | towns_kb_timer = timer_alloc(machine,poll_keyboard,NULL); |
| 2082 | towns_mouse_timer = timer_alloc(machine,towns_mouse_timeout,NULL); |
| 1951 | 2083 | |
| 1952 | 2084 | // CD-ROM init |
| 1953 | 2085 | towns_cd.read_timer = timer_alloc(machine,towns_cdrom_read_byte,(void*)devtag_get_device(machine,"dma_1")); |
| r7617 | r7618 | |
| 1973 | 2105 | towns_kb_status = 0x18; |
| 1974 | 2106 | towns_kb_irq1_enable = 0; |
| 1975 | 2107 | towns_pad_mask = 0x7f; |
| 2108 | towns_mouse_output = MOUSE_START; |
| 1976 | 2109 | towns_cd.status = 0x01; // CDROM controller ready |
| 1977 | 2110 | towns_cd.buffer_ptr = -1; |
| 1978 | 2111 | timer_adjust_periodic(towns_rtc_timer,attotime_zero,0,ATTOTIME_IN_HZ(1)); |