Food Fight - joystick troubles, solved
-
This post is deleted! -
That fix was for yourself me and libretto have parted ways a while back. I would advise to post an issue there if you would like it added to there port one of the maintainers will add it if they want i added.
-
here is some code that will remember the up down left right positions. Its up to you if you want to add diagonals remember analog is radial when doing your logic. This is how your read the joystick directly you can apply any extra logic you want to this should be enough to get you where you want to go.
static READ16_HANDLER( analog_r ) { static up=0; static down=0; static left=0; static right=0; int xvalue = 128; int yvalue = 128; if (whichport == 0) { if (code_pressed(JOYCODE_1_LEFT)) { xvalue = 255; left =1; right =0; up=0; down =0;} else if (code_pressed(JOYCODE_1_RIGHT)) { xvalue = 0; right =1; left =0; up=0; down =0;} log_cb(RETRO_LOG_INFO, LOGPRE "X == %d \n",xvalue); if (xvalue == 128 && right) return 122; else if (xvalue == 128 && left) return 134; else return xvalue; } // return readinputport(whichport); else if (whichport == 2) { if (code_pressed(JOYCODE_1_UP)) { yvalue = 255; up =1; down =0; right =0; left =0;} if (code_pressed(JOYCODE_1_DOWN)) { yvalue = 0; down =1; up=0; right =0; left =0;} if (yvalue == 128 && down) return 122; else if (yvalue == 128 && up) return 134; else return yvalue; } }
-
Thank you, made some updates, see below. Just need to add the diagonals and maybe tighten up the stopping values.
You said diagonals are radial. Does that mean we check under a different port for diagonals or something? or can I just update my "if/else if" press checks under port 0 and 2 to check for diagonals first? So diagonals takes precedence over linear moves.
static READ16_HANDLER( analog_r ) { static int up = 0; static int down = 0; static int left = 0; static int right = 0; int center = 127; int xvalue = center; int yvalue = center; if (whichport == 0) { if (code_pressed(JOYCODE_1_LEFT)) { xvalue = 255; left=1; right=0; up=0; down=0; } else if (code_pressed(JOYCODE_1_RIGHT)) { xvalue = 0; left=0; right=1; up=0; down=0;} if (xvalue == center && right) return 122; else if (xvalue == center && left) return 134; else return xvalue; } else if (whichport == 2) { if (code_pressed(JOYCODE_1_UP)) { yvalue = 255; left=0; right=0; up=1; down=0; } else if (code_pressed(JOYCODE_1_DOWN)) { yvalue = 0; left=0; right=0; up=0; down=1; } if (yvalue == center && down) return 122; else if (yvalue == center && up) return 134; else return yvalue; } return center; }
-
well whichport 0 is the axsis and whichport2 is the yaxis it only reads one at a time.
you need to keep track of the x and y changes you never know what port is going to read so you need to keep track of x and y settings. Ill try knock something up for you to use thats a little easier to work with.
-
This is what I tried(see main code below), it works ok, but glitchy. Mostly because when pressing diagonals it's easy to press one direction earlier than the other. Which results in false stops being set linearly.
Probably just need to add a center check for the linear directions so they only set at exact positions and are harder to hit... like this:
else if (code_pressed(JOYCODE_1_LEFT && yvalue == center)) { xvalue = 255; left=1; right=0; up=0; down=0; }
static READ16_HANDLER( analog_r ) { //return readinputport(whichport); static int up = 0; static int down = 0; static int left = 0; static int right = 0; int center = 127; int xvalue = center; int yvalue = center; if (whichport == 0) { // check for diagonal presses first if (code_pressed(JOYCODE_1_LEFT) && code_pressed(JOYCODE_1_UP)) { xvalue = 255; left=1; right=0; up=1; down=0; } else if (code_pressed(JOYCODE_1_LEFT) && code_pressed(JOYCODE_1_DOWN)) { xvalue = 255; left=1; right=0; up=0; down=1; } else if (code_pressed(JOYCODE_1_RIGHT) && code_pressed(JOYCODE_1_UP)) { xvalue = 0; left=0; right=1; up=1; down=0; } else if (code_pressed(JOYCODE_1_RIGHT) && code_pressed(JOYCODE_1_DOWN)) { xvalue = 0; left=0; right=1; up=0; down=1; } // check linear presses else if (code_pressed(JOYCODE_1_LEFT)) { xvalue = 255; left=1; right=0; up=0; down=0; } else if (code_pressed(JOYCODE_1_RIGHT)) { xvalue = 0; left=0; right=1; up=0; down=0;} if (xvalue == center && right) return 122; else if (xvalue == center && left) return 132; else return xvalue; } else if (whichport == 2) { // check for diagonal presses first if (code_pressed(JOYCODE_1_UP) && code_pressed(JOYCODE_1_LEFT)) { yvalue = 255; left=1; right=0; up=1; down=0; } else if (code_pressed(JOYCODE_1_UP) && code_pressed(JOYCODE_1_RIGHT)) { yvalue = 255; left=0; right=1; up=1; down=0; } else if (code_pressed(JOYCODE_1_DOWN) && code_pressed(JOYCODE_1_LEFT)) { yvalue = 0; left=1; right=0; up=0; down=1; } else if (code_pressed(JOYCODE_1_DOWN) && code_pressed(JOYCODE_1_RIGHT)) { yvalue = 0; left=0; right=1; up=0; down=1; } // check linear presses else if (code_pressed(JOYCODE_1_UP)) { yvalue = 255; left=0; right=0; up=1; down=0; } else if (code_pressed(JOYCODE_1_DOWN)) { yvalue = 0; left=0; right=0; up=0; down=1; } if (yvalue == center && down) return 122; else if (yvalue == center && up) return 132; else return yvalue; } return center; }
-
here is the new simplified code this uses the cheat input ports as well cocktail mode isint added atm if you need it just let me know.
static READ16_HANDLER( analog_r ) { #define max 255 #define cent 128 #define bump 51; #define up 1 #define down 2 #define left 4 #define right 8 static INT16 xvalue = 0x80; static INT16 yvalue = 0x80; static INT16 lastx = 0x80; static INT16 lasty = 0x80; static INT16 currentx = 0x80; static INT16 currenty = 0x80; static INT16 center = 0; int flag; int temp; UINT16 direction; if( options.cheat_input_ports) // use cheat ports { if(whichport == 0 || whichport ==2) direction = readinputport(6); temp = direction & ~16; if ( temp == 0 ) center =1; else if ( temp == up ) { center=0; xvalue = cent; yvalue = max; currentx=cent; currenty= cent+bump; } else if ( temp == down ) { center=0; xvalue = cent; yvalue = 0; currentx=cent; currenty= cent-bump; } else if ( temp == left ) { center=0; xvalue = max; yvalue = cent; currentx=cent+bump; currenty= cent; } else if ( temp == right ) { center=0; xvalue = 0; yvalue = cent; currentx=cent-bump; currenty= cent; } else if ( temp == right+up ) { center=0 ;xvalue = 0; yvalue = max; currentx=cent-bump; currenty= cent+bump; } else if ( temp == right+down ) { center=0; xvalue = 0; yvalue = 0; currentx=cent-bump; currenty= cent-bump; } else if ( temp == left+up ) { center=0; xvalue = max; yvalue = max; currentx=cent+bump; currenty= cent+bump; } else if ( temp == left+down ) { center=0; xvalue = max; yvalue = 0; currentx=cent+bump; currenty= cent-bump; } else log_cb(RETRO_LOG_INFO, LOGPRE "unhandled condition %d\n",temp); // log_cb(RETRO_LOG_INFO, LOGPRE "flag:%d center:%d xval:%d yval:%d\n", temp, center, xvalue, yvalue); if (whichport == 0) { if (center) return currentx; return xvalue; } else if (whichport == 2) { if (center) return currenty; return yvalue; } else log_cb(RETRO_LOG_INFO, LOGPRE "unhandled condition1 %d\n",temp); } else // use original inputs return readinputport(whichport); }
add new cheat ports here just before INPUT_PORTS_END https://github.com/libretro/mame2003-plus-libretro/blob/0134c428b75882aa474f78dbbf2c6ecde49b97b7/src/drivers/foodf.c#L291
PORT_START /* fake port for digital joystick control */ PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP | IPF_8WAY | IPF_CHEAT ) PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN | IPF_8WAY | IPF_CHEAT ) PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT | IPF_8WAY | IPF_CHEAT ) PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_CHEAT )
-
@grant2258 center is 127. Not 128. Did you test this code yet?
-
actually its 128 for out purposes wen want it dead on center
-
@grant2258 I was testing 128 yesterday and it made it slightly to one side. Thats why I changed it to 127 to get a true center...?
-
The game auto calibrates as well so dont worry about it too muchthe value is fine.
-
@grant2258 did you test it?
-
just a basic test is working fine as be sure to enable cheat ports or youll be using the old original analog code.
If you have issues after testing it let me know. The input ports on the horizontal seem to be reading a bit fast slow it down till you dont get button bounce on the device your using.
if(whichport == 0 || whichport ==2) direction = readinputport(6);
too
if (whichport ==2) direction = readinputport(6);if that doesnt dampen it enough for you read it every second time with whichport ==2 condition.
-
@grant2258 tested, can't move left or right and diagonals are stoping off target most times. Sometimes diagonals stop in linear directions too.
-
works fine here make sure your using cheat ports the re-calibrate your your joystick in the service menu. When you mess about with this code you change the calibration during my testing i had to repeatedly delete the nvram to undo teh games calibration.
Thats why care needs to be done when testing. The horizontal could be reading too fast for you i explained this before its button debounce delay the read time.
the code is here
ps this code works fine in default nvram when you spin the joystick round once and works every time if you calibrate
-
Had a compiling error that's why it was messed up.
Fixed now ... Testing now -
this code here https://github.com/grant2258/Blaster-Barcade/blob/3d1f20d2bcc51552672119cdded187633cdfe1d7/src/drivers/foodf.c#L199
change it too
if( counter == 8) { direction = readinputport(6); counter =0; } else counter ++;
and add somewhere at the top where the other variables are this should take care of the debounce works fine on a keyboard (horizontal centering )
static INT16 counter = 0;
-
if the counter isn't 8 direction wont be set to be used with temp. is that an issue? Or should this be a while loop
-
it intentional it uses the last read. The problem is it reads so fast you get button debounce you need to slow the reads down unti you get horizontals without issues.
-
@grant2258 right but on first time run your direction wasn't set yet to have a last read position.
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.