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.
    • G
      grant2258 Banned
      last edited by grant2258

      thats probably ok for digital wont help analog controls it probably wants a certain range. I have messed about with it. I really think this driver would work properly and a analog controller with a bigger throw for more precise movement. Ie slight circles would let you shoot round without moving.

      I dont have any type of gimbal analog devices to test it though. A u360 would be handy to test this stuff on but i dont have one.

      I better explain this a little better imagine you added a 30cm shaft to a xbox360 controller you could get more fine movements on it and easily move the just the eyes doing a small circle

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

        @grant2258

        I've read that someone increased the sensativity to 125% and had some luck.

        Couldn't we shorten the range from changing "FF" in the driver?

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

          @mahoneyt944 this does appear to work properly in analog would need a decent precision joystick to test it properly though like the original joystick the machine had itself or make a big jig with pots at the side this would help with games like star wars and such. Its like the steering wheels you have much better control because of the diameter of the wheel you can turn a little at a time(If you had a cap on the pot like a guitar does it would be pretty rubbish).

          If you look at this game and compare a gamepad thumbstick throw to the monster of a throw the cab had its really the same kind of thing. It is all guess work but im thinking you just do little circles on the cab to throw food everywhere.

          . Digital has no real solution for this just more games can be made bearable with auto center.

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

            @grant2258

            So 125% did better with true anolog?

            There's got to be a way to cheat this control on digital. At least there's some progress

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

              ye could always to this with a thumb stick sometimes with tiny careful movements(not practical when playing the game) or setting the key delta low to me it looks like how the game works again i havent played the original. 125% doesnt make much of a difference ro be honest.

              I think a gimbal like this one would make the game work properly https://www.robotshop.com/en/hitec-2-axis-joystick-gim-01.html of course this is aimed at robotics.

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

                @grant2258

                Analog is a going to be the right way to play this game, but I think a mod should be made for digital if it can't be mapped properly. Most people building home retropie arcade cabinets are going to be using sanwa or similar joysticks which makes food fight less compatible. It's a shame because it's a fun yet simple game.

                I'm probably not the best candidate to write a fix because I'm not familiar with the different file locations and how they link but I'm willing to try. And have some coding experience.

                What I propose is that each of the 8 way control directions, when pressed, sets a specific horizontal_value and vertical_value variable corresponding to that direction. These variables will be set/changed every time you press a direction. This means that the direction last pressed will be the values used for centering if options.default_center is turned off and the digital center fix is on.

                Then when centering is active for digital controls and options.default_center is off, if press right he will stop facing right. If you press left he will stop facing left etc for all 8 direction.

                The first thing I need to know is the location of the file where each button press is made so horizontal_value and vertical_value can be defined/ set for each direction.

                So:
                horizontal_value = 0x??
                vertical_value = 0x??

                Will be at the end of each direction press (8 directions).

                Next "current" needs to be able to be set independently so you can set horizontal and vertical positions instead of setting them both to default_value. This might look something like this, replacing "current = default_value" in your fix:

                If (default_center is off) {
                Current_Horizontal = horizontal_value
                Current_vertical = vertical_value
                }
                Else {
                Current_Horizontal = default_value
                Current_Vertical = default_value
                }

                Finally, an additional retroarch option will be added to "use default center value on/off".
                options.default_center

                This means you can use the centering fix with or without the default center location.

                If you're willing to help, I'll get all the location values

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

                  thats not really a good solution the default center is ok for 99% of the games. You need to do this in the driver level. So you can just put in digital input drivers instead of analog ones. The logic in this game is pretty easy as far as the input goes.

                  this is where mame sets the analog ports

                  https://github.com/libretro/mame2003-plus-libretro/blob/0134c428b75882aa474f78dbbf2c6ecde49b97b7/src/drivers/foodf.c#L250-L260

                  this is where the variable is set of which axis to read
                  https://github.com/libretro/mame2003-plus-libretro/blob/0134c428b75882aa474f78dbbf2c6ecde49b97b7/src/drivers/foodf.c#L181-L184

                  and finally mame reads the input port set in the code from that variable here.

                  https://github.com/libretro/mame2003-plus-libretro/blob/0134c428b75882aa474f78dbbf2c6ecde49b97b7/src/drivers/foodf.c#L175-L178

                  now you can do this a few ways like add digital controls and read them its up to you how you want to do it you could work round the analog code as is but that would break real analog controls.

                  M 1 Reply Last reply Reply Quote 0
                  • 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
                                            • 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.