From 146d4d1e941e38f3da59173bdcd84ba7c8eadba8 Mon Sep 17 00:00:00 2001 From: Jonathan Gevaryahu Date: Thu, 18 Mar 2010 00:01:29 +0000 Subject: [PATCH] Imported the same implementation of moon war proto's spinner to moon war 2; works much more smoothly now. [Lord Nightmare] --- src/mame/drivers/galaxian.c | 29 +++++++++++++++++++++-------- src/mame/drivers/galdrvr.c | 8 ++++---- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/mame/drivers/galaxian.c b/src/mame/drivers/galaxian.c index 6fe44814107..24775e2bb8b 100644 --- a/src/mame/drivers/galaxian.c +++ b/src/mame/drivers/galaxian.c @@ -1093,15 +1093,28 @@ static WRITE8_DEVICE_HANDLER( moonwar_port_select_w ) static READ8_DEVICE_HANDLER( moonwar_input_port_0_r ) { - UINT8 sign; - UINT8 delta; + // see http://www.cityofberwyn.com/schematics/stern/MoonWar_opto.tiff for schematic + // I.e. a 74ls161 counts from 0 to 15 which is the absolute number of bars passed on the quadrature + // one difference is it lacks the strobe input (does it?), which if not active causes + // the dial input to go open bus. This is used in moon war 2 to switch between player 1 + // and player 2 dials, which is emulated here. + static int lastdialread = -1; + int dialread = (moonwar_port_select ? input_port_read(device->machine, "IN3") : input_port_read(device->machine, "IN4")); + static int dialoutput = 0; + static int direction = 0; + UINT8 ret; + UINT8 buttons = (input_port_read(device->machine,"IN0")&0xe0); + if ((lastdialread - dialread) < 0) direction = 1; + else if ((lastdialread - dialread) > 0) direction = 0; + // note when lastdialread and dialread are the same direction is left alone. + dialoutput += abs(dialread - lastdialread); + dialoutput &= 0xf; + + ret= dialoutput | ((direction==1)?0x10:0) | buttons; - delta = (moonwar_port_select ? input_port_read(device->machine, "IN3") : input_port_read(device->machine, "IN4")); - - sign = (delta & 0x80) >> 3; - delta &= 0x0f; - - return ((input_port_read(device->machine, "IN0") & 0xe0) | delta | sign ); + //fprintf(stderr, "dialread: %02x, lastdialread: %02x, dialoutput: %02x, spinner ret is %02x\n", dialread, lastdialread, dialoutput, ret); + lastdialread = dialread; + return ret; } diff --git a/src/mame/drivers/galdrvr.c b/src/mame/drivers/galdrvr.c index 8d0624f2ebd..d770aa144ad 100644 --- a/src/mame/drivers/galdrvr.c +++ b/src/mame/drivers/galdrvr.c @@ -2645,10 +2645,10 @@ static INPUT_PORTS_START( moonwar ) PORT_BIT( 0xf0, IP_ACTIVE_LOW, IPT_UNUSED ) /* output bits */ PORT_START("IN3") /* IN3/4 - dummy ports for the dial */ - PORT_BIT( 0xff, 0x00, IPT_DIAL ) PORT_SENSITIVITY(25) PORT_KEYDELTA(10) PORT_RESET + PORT_BIT( 0xff, 0x00, IPT_DIAL ) PORT_SENSITIVITY(25) PORT_KEYDELTA(10) PORT_START("IN4") - PORT_BIT( 0xff, 0x00, IPT_DIAL ) PORT_SENSITIVITY(25) PORT_KEYDELTA(10) PORT_RESET PORT_COCKTAIL + PORT_BIT( 0xff, 0x00, IPT_DIAL ) PORT_SENSITIVITY(25) PORT_KEYDELTA(10) PORT_COCKTAIL INPUT_PORTS_END /* same as above, but coinage is different */ @@ -2668,10 +2668,10 @@ static INPUT_PORTS_START( moonwara ) PORT_BIT( 0xf0, IP_ACTIVE_LOW, IPT_UNUSED ) /* output bits */ PORT_START("IN3") /* IN3/4 - dummy ports for the dial */ - PORT_BIT( 0xff, 0x00, IPT_DIAL ) PORT_SENSITIVITY(25) PORT_KEYDELTA(10) PORT_RESET + PORT_BIT( 0xff, 0x00, IPT_DIAL ) PORT_SENSITIVITY(25) PORT_KEYDELTA(10) PORT_START("IN4") /* doesn't actually work due to bug in game code */ - PORT_BIT( 0xff, 0x00, IPT_DIAL ) PORT_SENSITIVITY(25) PORT_KEYDELTA(10) PORT_RESET PORT_COCKTAIL + PORT_BIT( 0xff, 0x00, IPT_DIAL ) PORT_SENSITIVITY(25) PORT_KEYDELTA(10) PORT_COCKTAIL INPUT_PORTS_END static INPUT_PORTS_START( tdpgal )