src/mess/drivers/x68k.c
| r4466 | r4467 | |
| 686 | 686 | { |
| 687 | 687 | if(port == 1) |
| 688 | 688 | { |
| 689 | | if(x68k_sys.mdctrl.mux1 & 0x01) |
| 689 | if(x68k_sys.mdctrl.mux1 & 0x10) |
| 690 | 690 | { |
| 691 | 691 | return input_port_read(device->machine,"md3b_0") | 0x90; |
| 692 | 692 | } |
| r4466 | r4467 | |
| 698 | 698 | } |
| 699 | 699 | if(port == 2) |
| 700 | 700 | { |
| 701 | | if(x68k_sys.mdctrl.mux2 & 0x01) |
| 701 | if(x68k_sys.mdctrl.mux2 & 0x20) |
| 702 | 702 | { |
| 703 | 703 | return input_port_read(device->machine,"md3b_2") | 0x90; |
| 704 | 704 | } |
| r4466 | r4467 | |
| 711 | 711 | return 0xff; |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | // Megadrive 6 button gamepad |
| 715 | // Multiplexer is controlled by bit 0 in the PPI control port |
| 716 | static TIMER_CALLBACK(md_6button_port1_timeout) |
| 717 | { |
| 718 | x68k_sys.mdctrl.seq1 = 0; |
| 719 | } |
| 714 | 720 | |
| 721 | static TIMER_CALLBACK(md_6button_port2_timeout) |
| 722 | { |
| 723 | x68k_sys.mdctrl.seq2 = 0; |
| 724 | } |
| 725 | |
| 726 | static void md_6button_init(running_machine* machine) |
| 727 | { |
| 728 | x68k_sys.mdctrl.io_timeout1 = timer_alloc(machine,md_6button_port1_timeout,NULL); |
| 729 | x68k_sys.mdctrl.io_timeout2 = timer_alloc(machine,md_6button_port2_timeout,NULL); |
| 730 | } |
| 731 | |
| 732 | static UINT8 md_6button_r(const device_config* device, int port) |
| 733 | { |
| 734 | if(port == 1) |
| 735 | { |
| 736 | switch(x68k_sys.mdctrl.seq1) |
| 737 | { |
| 738 | case 1: |
| 739 | default: |
| 740 | if(x68k_sys.mdctrl.mux1 & 0x10) |
| 741 | { |
| 742 | return input_port_read(device->machine,"md6b_0") | 0x90; |
| 743 | } |
| 744 | else |
| 745 | { |
| 746 | return (input_port_read(device->machine,"md6b_1") & 0x60) | |
| 747 | (input_port_read(device->machine,"md6b_0") & 0x03) | 0x90; |
| 748 | } |
| 749 | case 2: |
| 750 | if(x68k_sys.mdctrl.mux1 & 0x10) |
| 751 | { |
| 752 | return input_port_read(device->machine,"md6b_0") | 0x90; |
| 753 | } |
| 754 | else |
| 755 | { |
| 756 | return (input_port_read(device->machine,"md6b_1") & 0x60) | 0x90; |
| 757 | } |
| 758 | case 3: |
| 759 | if(x68k_sys.mdctrl.mux1 & 0x10) |
| 760 | { |
| 761 | return (input_port_read(device->machine,"md6b_0") & 0x60) | (input_port_read(device->machine,"md6b_4") & 0x0f) | 0x90; |
| 762 | } |
| 763 | else |
| 764 | { |
| 765 | return (input_port_read(device->machine,"md6b_1") & 0x60) | 0x9f; |
| 766 | } |
| 767 | } |
| 768 | } |
| 769 | if(port == 2) |
| 770 | { |
| 771 | switch(x68k_sys.mdctrl.seq2) |
| 772 | { |
| 773 | case 1: |
| 774 | default: |
| 775 | if(x68k_sys.mdctrl.mux2 & 0x20) |
| 776 | { |
| 777 | return input_port_read(device->machine,"md6b_2") | 0x90; |
| 778 | } |
| 779 | else |
| 780 | { |
| 781 | return (input_port_read(device->machine,"md6b_3") & 0x60) | |
| 782 | (input_port_read(device->machine,"md6b_2") & 0x03) | 0x90; |
| 783 | } |
| 784 | case 2: |
| 785 | if(x68k_sys.mdctrl.mux2 & 0x20) |
| 786 | { |
| 787 | return input_port_read(device->machine,"md6b_2") | 0x90; |
| 788 | } |
| 789 | else |
| 790 | { |
| 791 | return (input_port_read(device->machine,"md6b_3") & 0x60) | 0x90; |
| 792 | } |
| 793 | case 3: |
| 794 | if(x68k_sys.mdctrl.mux2 & 0x20) |
| 795 | { |
| 796 | return (input_port_read(device->machine,"md6b_2") & 0x60) | (input_port_read(device->machine,"md6b_5") & 0x0f) | 0x90; |
| 797 | } |
| 798 | else |
| 799 | { |
| 800 | return (input_port_read(device->machine,"md6b_3") & 0x60) | 0x9f; |
| 801 | } |
| 802 | } |
| 803 | } |
| 804 | return 0xff; |
| 805 | } |
| 806 | |
| 715 | 807 | // Judging from the XM6 source code, PPI ports A and B are joystick inputs |
| 716 | 808 | static READ8_DEVICE_HANDLER( ppi_port_a_r ) |
| 717 | 809 | { |
| r4466 | r4467 | |
| 726 | 818 | return 0xff; |
| 727 | 819 | case 0x01: // 3-button Megadrive gamepad |
| 728 | 820 | return md_3button_r(device,1); |
| 821 | case 0x02: // 6-button Megadrive gamepad |
| 822 | return md_6button_r(device,1); |
| 729 | 823 | } |
| 730 | 824 | |
| 731 | 825 | return 0xff; |
| r4466 | r4467 | |
| 744 | 838 | return 0xff; |
| 745 | 839 | case 0x10: // 3-button Megadrive gamepad |
| 746 | 840 | return md_3button_r(device,2); |
| 841 | case 0x20: // 6-button Megadrive gamepad |
| 842 | return md_6button_r(device,2); |
| 747 | 843 | } |
| 748 | 844 | |
| 749 | 845 | return 0xff; |
| r4466 | r4467 | |
| 766 | 862 | { |
| 767 | 863 | // ADPCM / Joystick control |
| 768 | 864 | const device_config *oki = devtag_get_device(device->machine, "okim6258"); |
| 865 | static UINT16 prev1; |
| 866 | static UINT16 prev2; |
| 769 | 867 | |
| 770 | 868 | ppi_port[2] = data; |
| 771 | 869 | x68k_sys.adpcm.pan = data & 0x03; |
| r4466 | r4467 | |
| 773 | 871 | x68k_set_adpcm(device->machine); |
| 774 | 872 | okim6258_set_divider(oki, (data >> 2) & 3); |
| 775 | 873 | |
| 874 | // The joystick enable bits also handle the multiplexer for various controllers |
| 776 | 875 | x68k_sys.joy.joy1_enable = data & 0x10; |
| 876 | x68k_sys.mdctrl.mux1 = data & 0x10; |
| 877 | if((prev1 & 0x10) == 0x00 && (data & 0x10) == 0x10) |
| 878 | { |
| 879 | x68k_sys.mdctrl.seq1++; |
| 880 | timer_adjust_oneshot(x68k_sys.mdctrl.io_timeout1,cpu_clocks_to_attotime(device->machine->cpu[0],8192),0); |
| 881 | } |
| 882 | prev1 = data; |
| 883 | |
| 777 | 884 | x68k_sys.joy.joy2_enable = data & 0x20; |
| 885 | x68k_sys.mdctrl.mux2 = data & 0x20; |
| 886 | if((prev2 & 0x20) == 0x00 && (data & 0x20) == 0x20) |
| 887 | { |
| 888 | x68k_sys.mdctrl.seq2++; |
| 889 | timer_adjust_oneshot(x68k_sys.mdctrl.io_timeout2,cpu_clocks_to_attotime(device->machine->cpu[0],8192),0); |
| 890 | } |
| 891 | prev2 = data; |
| 892 | |
| 778 | 893 | x68k_sys.joy.ioc6 = data & 0x40; |
| 779 | 894 | x68k_sys.joy.ioc7 = data & 0x80; |
| 895 | |
| 780 | 896 | } |
| 781 | 897 | |
| 782 | 898 | |
| r4466 | r4467 | |
| 1287 | 1403 | static WRITE16_DEVICE_HANDLER( x68k_ppi_w ) |
| 1288 | 1404 | { |
| 1289 | 1405 | ppi8255_w(device,offset & 0x03,data); |
| 1290 | | |
| 1291 | | // It appears that bit 0 of the PPI control port also controls the |
| 1292 | | // Megadrive controller multiplexer, with bit 1 determining which port. |
| 1293 | | if(offset == 0x03) |
| 1294 | | { |
| 1295 | | if(data & 0x02) // 0 = port A, 1 = port B |
| 1296 | | x68k_sys.mdctrl.mux2 = data & 0x01; |
| 1297 | | else |
| 1298 | | x68k_sys.mdctrl.mux1 = data & 0x01; |
| 1299 | | } |
| 1300 | 1406 | } |
| 1301 | 1407 | |
| 1302 | 1408 | static READ16_DEVICE_HANDLER( x68k_ppi_r ) |
| r4466 | r4467 | |
| 1762 | 1868 | PORT_CATEGORY_CLASS(0x0f,0x00,"Joystick Port 1") |
| 1763 | 1869 | PORT_CATEGORY_ITEM(0x00,"Standard 2-button MSX/FM-Towns joystick",10) |
| 1764 | 1870 | PORT_CATEGORY_ITEM(0x01,"3-button Megadrive gamepad",11) |
| 1765 | | // PORT_CATEGORY_ITEM(0x02,"6-button Megadrive gamepad",12) |
| 1871 | PORT_CATEGORY_ITEM(0x02,"6-button Megadrive gamepad",12) |
| 1766 | 1872 | PORT_CATEGORY_CLASS(0xf0,0x00,"Joystick Port 2") |
| 1767 | 1873 | PORT_CATEGORY_ITEM(0x00,"Standard 2-button MSX/FM-Towns joystick",20) |
| 1768 | 1874 | PORT_CATEGORY_ITEM(0x10,"3-button Megadrive gamepad",21) |
| 1769 | | // PORT_CATEGORY_ITEM(0x20,"6-button Megadrive gamepad",22) |
| 1875 | PORT_CATEGORY_ITEM(0x20,"6-button Megadrive gamepad",22) |
| 1770 | 1876 | // TODO: Sharp Cyber Stick (CZ-8NJ2) support |
| 1771 | 1877 | |
| 1772 | 1878 | PORT_START( "joy1" ) |
| r4466 | r4467 | |
| 1974 | 2080 | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_START ) PORT_PLAYER(2) PORT_NAME("MD Pad 2 Start Button") PORT_CATEGORY(21) |
| 1975 | 2081 | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_CATEGORY(21) |
| 1976 | 2082 | |
| 2083 | PORT_START("md6b_0") |
| 2084 | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_NAME("MD Pad 1 Up") PORT_8WAY PORT_PLAYER(1) PORT_CATEGORY(12) |
| 2085 | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_NAME("MD Pad 1 Down") PORT_8WAY PORT_PLAYER(1) PORT_CATEGORY(12) |
| 2086 | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_NAME("MD Pad 1 Left") PORT_8WAY PORT_PLAYER(1) PORT_CATEGORY(12) |
| 2087 | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_NAME("MD Pad 1 Right") PORT_8WAY PORT_PLAYER(1) PORT_CATEGORY(12) |
| 2088 | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_CATEGORY(12) |
| 2089 | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_NAME("MD Pad 1 B Button") PORT_CATEGORY(12) |
| 2090 | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_NAME("MD Pad 1 C Button") PORT_CATEGORY(12) |
| 2091 | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_CATEGORY(12) |
| 2092 | |
| 2093 | PORT_START("md6b_1") |
| 2094 | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_CATEGORY(12) |
| 2095 | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_CATEGORY(12) |
| 2096 | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_CATEGORY(12) |
| 2097 | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_CATEGORY(12) |
| 2098 | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_CATEGORY(12) |
| 2099 | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_NAME("MD Pad 1 A Button") PORT_CATEGORY(12) |
| 2100 | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_START ) PORT_PLAYER(1) PORT_NAME("MD Pad 1 Start Button") PORT_CATEGORY(12) |
| 2101 | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_CATEGORY(12) |
| 2102 | |
| 2103 | PORT_START("md6b_2") |
| 2104 | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_NAME("MD Pad 2 Up") PORT_8WAY PORT_PLAYER(2) PORT_CATEGORY(22) |
| 2105 | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_NAME("MD Pad 2 Down") PORT_8WAY PORT_PLAYER(2) PORT_CATEGORY(22) |
| 2106 | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_NAME("MD Pad 2 Left") PORT_8WAY PORT_PLAYER(2) PORT_CATEGORY(22) |
| 2107 | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_NAME("MD Pad 2 Right") PORT_8WAY PORT_PLAYER(2) PORT_CATEGORY(22) |
| 2108 | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_CATEGORY(22) |
| 2109 | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_NAME("MD Pad 2 B Button") PORT_CATEGORY(22) |
| 2110 | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_NAME("MD Pad 2 C Button") PORT_CATEGORY(22) |
| 2111 | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_CATEGORY(22) |
| 2112 | |
| 2113 | PORT_START("md6b_3") |
| 2114 | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_CATEGORY(22) |
| 2115 | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_CATEGORY(22) |
| 2116 | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_CATEGORY(22) |
| 2117 | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_CATEGORY(22) |
| 2118 | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_CATEGORY(22) |
| 2119 | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_NAME("MD Pad 2 A Button") PORT_CATEGORY(22) |
| 2120 | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_START ) PORT_PLAYER(2) PORT_NAME("MD Pad 2 Start Button") PORT_CATEGORY(22) |
| 2121 | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_CATEGORY(22) |
| 2122 | |
| 2123 | // extra inputs |
| 2124 | PORT_START("md6b_4") |
| 2125 | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(1) PORT_NAME("MD Pad 1 Z Button") PORT_CATEGORY(12) |
| 2126 | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(1) PORT_NAME("MD Pad 1 Y Button") PORT_CATEGORY(12) |
| 2127 | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) PORT_NAME("MD Pad 1 X Button") PORT_CATEGORY(12) |
| 2128 | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_PLAYER(1) PORT_NAME("MD Pad 1 Mode Button") PORT_CATEGORY(12) |
| 2129 | |
| 2130 | PORT_START("md6b_5") |
| 2131 | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(2) PORT_NAME("MD Pad 2 Z Button") PORT_CATEGORY(22) |
| 2132 | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(2) PORT_NAME("MD Pad 2 Y Button") PORT_CATEGORY(22) |
| 2133 | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) PORT_NAME("MD Pad 2 X Button") PORT_CATEGORY(22) |
| 2134 | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_PLAYER(2) PORT_NAME("MD Pad 2 Mode Button") PORT_CATEGORY(22) |
| 2135 | |
| 1977 | 2136 | INPUT_PORTS_END |
| 1978 | 2137 | |
| 1979 | 2138 | static void dimdsk_set_geometry(const device_config* image) |
| r4466 | r4467 | |
| 2242 | 2401 | x68k_vblank_irq = timer_alloc(machine, x68k_crtc_vblank_irq,NULL); |
| 2243 | 2402 | mouse_timer = timer_alloc(machine, x68k_scc_ack,NULL); |
| 2244 | 2403 | led_timer = timer_alloc(machine, x68k_led_callback,NULL); |
| 2404 | |
| 2405 | // Initialise timers for 6-button MD controllers |
| 2406 | md_6button_init(machine); |
| 2245 | 2407 | } |
| 2246 | 2408 | |
| 2247 | 2409 | static MACHINE_DRIVER_START( x68000 ) |