Previous 15994 Revisions Next

r4467 Friday 10th April, 2009 at 01:53:50 UTC by Barry Rodewald
[X68000] Corrected Megadrive gamepad interface, added 6-button Megadrive gamepad support (almost working).
[docs]messnew.txt
[src/mess/drivers]x68k.c
[src/mess/includes]x68k.h

src/mess/includes/x68k.h
r4466r4467
190190      // port A
191191      int mux1;  // multiplexer value
192192      int seq1;  // part of 6-button input sequence.
193      emu_timer* io_timeout1;
193194      // port B
194195      int mux2;  // multiplexer value
195196      int seq2;  // part of 6-button input sequence.
197      emu_timer* io_timeout2;
196198   } mdctrl;
197199};
198200
src/mess/drivers/x68k.c
r4466r4467
686686{
687687   if(port == 1)
688688   {
689      if(x68k_sys.mdctrl.mux1 & 0x01)
689      if(x68k_sys.mdctrl.mux1 & 0x10)
690690      {   
691691         return input_port_read(device->machine,"md3b_0") | 0x90;
692692      }
r4466r4467
698698   }
699699   if(port == 2)
700700   {
701      if(x68k_sys.mdctrl.mux2 & 0x01)
701      if(x68k_sys.mdctrl.mux2 & 0x20)
702702      {   
703703         return input_port_read(device->machine,"md3b_2") | 0x90;
704704      }
r4466r4467
711711   return 0xff;
712712}
713713
714// Megadrive 6 button gamepad
715// Multiplexer is controlled by bit 0 in the PPI control port
716static TIMER_CALLBACK(md_6button_port1_timeout)
717{
718   x68k_sys.mdctrl.seq1 = 0;
719}
714720
721static TIMER_CALLBACK(md_6button_port2_timeout)
722{
723   x68k_sys.mdctrl.seq2 = 0;
724}
725
726static 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
732static 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
715807// Judging from the XM6 source code, PPI ports A and B are joystick inputs
716808static READ8_DEVICE_HANDLER( ppi_port_a_r )
717809{
r4466r4467
726818            return 0xff;
727819      case 0x01:  // 3-button Megadrive gamepad
728820         return md_3button_r(device,1);
821      case 0x02:  // 6-button Megadrive gamepad
822         return md_6button_r(device,1);
729823   }
730824   
731825   return 0xff;
r4466r4467
744838            return 0xff;
745839      case 0x10:  // 3-button Megadrive gamepad
746840         return md_3button_r(device,2);
841      case 0x20:  // 6-button Megadrive gamepad
842         return md_6button_r(device,2);
747843   }
748844   
749845   return 0xff;
r4466r4467
766862{
767863   // ADPCM / Joystick control
768864   const device_config *oki = devtag_get_device(device->machine, "okim6258");
865   static UINT16 prev1;
866   static UINT16 prev2;
769867   
770868   ppi_port[2] = data;
771869   x68k_sys.adpcm.pan = data & 0x03;
r4466r4467
773871   x68k_set_adpcm(device->machine);
774872   okim6258_set_divider(oki, (data >> 2) & 3);
775873
874   // The joystick enable bits also handle the multiplexer for various controllers
776875   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
777884   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
778893   x68k_sys.joy.ioc6 = data & 0x40;
779894   x68k_sys.joy.ioc7 = data & 0x80;
895
780896}
781897
782898
r4466r4467
12871403static WRITE16_DEVICE_HANDLER( x68k_ppi_w )
12881404{
12891405   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   }
13001406}
13011407
13021408static READ16_DEVICE_HANDLER( x68k_ppi_r )
r4466r4467
17621868   PORT_CATEGORY_CLASS(0x0f,0x00,"Joystick Port 1")
17631869   PORT_CATEGORY_ITEM(0x00,"Standard 2-button MSX/FM-Towns joystick",10)
17641870   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)
17661872   PORT_CATEGORY_CLASS(0xf0,0x00,"Joystick Port 2")
17671873   PORT_CATEGORY_ITEM(0x00,"Standard 2-button MSX/FM-Towns joystick",20)
17681874   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)
17701876// TODO: Sharp Cyber Stick (CZ-8NJ2) support
17711877
17721878   PORT_START( "joy1" )
r4466r4467
19742080   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_START ) PORT_PLAYER(2) PORT_NAME("MD Pad 2 Start Button") PORT_CATEGORY(21)
19752081   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_CATEGORY(21)
19762082   
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
19772136INPUT_PORTS_END
19782137
19792138static void dimdsk_set_geometry(const device_config* image)
r4466r4467
22422401   x68k_vblank_irq = timer_alloc(machine, x68k_crtc_vblank_irq,NULL);
22432402   mouse_timer = timer_alloc(machine, x68k_scc_ack,NULL);
22442403   led_timer = timer_alloc(machine, x68k_led_callback,NULL);
2404   
2405   // Initialise timers for 6-button MD controllers
2406   md_6button_init(machine);
22452407}
22462408
22472409static MACHINE_DRIVER_START( x68000 )
docs/messnew.txt
r4466r4467
2424          - LNW-80 graphics and colour added
2525          - ht1080z and system-80 extension roms added
2626
27- [X68000] Added support for 3 and 6 button Megadrive gamepads. [Barry Rodewald]
2728
2829
30
2931User Interface Changes:
3032-----------------------
3133(none)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team