RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Food Fight - joystick troubles, solved

    Scheduled Pinned Locked Moved Help and Support
    ad stick
    125 Posts 5 Posters 10.2k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mahoneyt944 @grant2258
      last edited by mahoneyt944

      This post is deleted!
      1 Reply Last reply Reply Quote 0
      • M
        mahoneyt944
        last edited by mahoneyt944

        @grant2258

        This is just additional option to your current fix which doesn't apply to analog.

        First you would turn on your fix for centering digital joysticks. Then you'd have the option(options.default_center) to use 0x7f as your center position as it does now or the variables set by each direction. This only applies to digital controls.

        if (delta == 0 && options.digital_analog )
        {
             If (options.default_center == 0)
             {
                  Current_Horizontal = horizontal_value;
        	  Current_vertical = vertical_value;
             }
             Else 
             {
                  Current_Horizontal = default_value;
                  Current_Vertical = default_value;
             }
        }
        else if ((delta == 0) && (in->type & IPF_CENTER) )
        {
        	if (current > default_value)
        	delta = -100 / sensitivity;
        	if (current < default_value)
        	delta = 100 / sensitivity;
        }
        

        The reason to do it here is for compatibility with any other game in the future that may have used the 49-way control with similar issues.

        These variables will be set after every direction pressed(if your fix is turned off, they just wouldn't do anything):

        Some direction press
        
        normal code thats here now.
        horizontal_value = 0x??
        vertical_value = 0x??
        
                        HORZ    VERT
        UP               7F      80
        DOWN             7F      7E
        LEFT             80      7F
        RIGHT            7E      7F
        UP/LEFT          80      80
        UP/RIGHT         7E      80
        DOWN/LEFT        80      7E
        DOWN/RIGHT       7E      7E
        
        1 Reply Last reply Reply Quote 0
        • G
          grant2258 Banned
          last edited by

          dont get what your doing here this just reads one port at a time the variable you need to set is current for the value of the port your reading from the mame driver.

          You have no way of knowing its vertical or horizontal or what that port is for its just reading it at os level. your logic need to go here https://github.com/libretro/mame2003-plus-libretro/blob/0134c428b75882aa474f78dbbf2c6ecde49b97b7/src/drivers/foodf.c#L175-L178

          this is the return value from the code your trying to change.

          M 1 Reply Last reply Reply Quote 0
          • M
            mahoneyt944 @grant2258
            last edited by mahoneyt944

            @grant2258

            I want to make it so that each of the 8 way digital presses set a horz and vert position variable that can be used later for centering.

            I understand "current" sets them together, so it needs a way to be set individually.

            So the last direction pressed will be the position he stops facing.

            This is for digital only,

            1 Reply Last reply Reply Quote 0
            • G
              grant2258 Banned
              last edited by grant2258

              This will need done at driver level to be honest the self centering code option was added for analog games that dont have this flag set and it snap there right away. The other issues with this game need dealt with at driver level as far as digital control hacks go.

              M 1 Reply Last reply Reply Quote 0
              • M
                mahoneyt944 @grant2258
                last edited by mahoneyt944

                @grant2258

                Ok. So hacking the games driver (foodf.c?),

                It needs set so that the last direction pressed on our joystick sets the facing direction when you are centered

                Also, was your digital centering fixed submitted to the mame2003-plus official page as an update yet?

                1 Reply Last reply Reply Quote 0
                • M
                  mahoneyt944
                  last edited by mahoneyt944

                  This post is deleted!
                  1 Reply Last reply Reply Quote 0
                  • G
                    grant2258 Banned
                    last edited by

                    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.

                    1 Reply Last reply Reply Quote 0
                    • G
                      grant2258 Banned
                      last edited by grant2258

                      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;
                        }
                      
                      
                      }
                      
                      M 1 Reply Last reply Reply Quote 0
                      • M
                        mahoneyt944 @grant2258
                        last edited by mahoneyt944

                        @grant2258

                        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;
                        }
                        
                        1 Reply Last reply Reply Quote 0
                        • G
                          grant2258 Banned
                          last edited by

                          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.

                          M 1 Reply Last reply Reply Quote 0
                          • M
                            mahoneyt944 @grant2258
                            last edited by mahoneyt944

                            @grant2258

                            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;
                            }
                            
                            1 Reply Last reply Reply Quote 0
                            • G
                              grant2258 Banned
                              last edited by grant2258

                              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 )
                              
                              M 1 Reply Last reply Reply Quote 0
                              • M
                                mahoneyt944 @grant2258
                                last edited by

                                @grant2258 center is 127. Not 128. Did you test this code yet?

                                1 Reply Last reply Reply Quote 0
                                • G
                                  grant2258 Banned
                                  last edited by grant2258

                                  actually its 128 for out purposes wen want it dead on center

                                  M 1 Reply Last reply Reply Quote 0
                                  • M
                                    mahoneyt944 @grant2258
                                    last edited by

                                    @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...?

                                    1 Reply Last reply Reply Quote 0
                                    • G
                                      grant2258 Banned
                                      last edited by

                                      The game auto calibrates as well so dont worry about it too muchthe value is fine.

                                      M 1 Reply Last reply Reply Quote 0
                                      • M
                                        mahoneyt944 @grant2258
                                        last edited by

                                        @grant2258 did you test it?

                                        1 Reply Last reply Reply Quote 0
                                        • G
                                          grant2258 Banned
                                          last edited by grant2258

                                          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.

                                          M 1 Reply Last reply Reply Quote 0
                                          • M
                                            mahoneyt944 @grant2258
                                            last edited by

                                            @grant2258 tested, can't move left or right and diagonals are stoping off target most times. Sometimes diagonals stop in linear directions too.

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            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.