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

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

                    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

                    wget https://raw.githubusercontent.com/grant2258/Blaster-Barcade/3d1f20d2bcc51552672119cdded187633cdfe1d7/src/drivers/foodf.c

                    ps this code works fine in default nvram when you spin the joystick round once and works every time if you calibrate

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

                      @grant2258

                      Had a compiling error that's why it was messed up.
                      Fixed now ... Testing now

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

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

                          @grant2258

                          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

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

                            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.

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

                              @grant2258 right but on first time run your direction wasn't set yet to have a last read position.

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

                                @mahoneyt944 are you having any issues ? you shouldnt be. The analog reads far too fast for button debounce you need 10 - 20 ms for the debounce. Even when you dont press a button it will read zero as center it will happen so fast you wont notice it and teh buttons will be read in less time than you could press it.

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

                                  @grant2258 if I change the code to use the counter even after calibration I get issues. He moves diagonals slowly and looks choppy. Then when exiting and re-entering the emulator he doesn't stop moving. If I don't use the counter it's fine just sometimes stops linear instead of diagonal.

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

                                    Well i would suggest you delete your foodf nvram and cfg files since the input ports where added and it was save before that. Ive only tested on a windows machine will compile on pi and test it in my barcade. And be sure to have your cheat ports on.

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

                                      @grant2258

                                      it works for me like this instead

                                      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  currentx  = 0x80;
                                        static INT16  currenty  = 0x80;
                                        static INT16  center = 0;
                                        static INT16  counter = 0;
                                        int temp;
                                        UINT16 direction;
                                      
                                        if( options.cheat_input_ports) // use cheat ports
                                        {
                                      
                                          if(whichport == 0 || whichport ==2)   direction = readinputport(6);
                                          
                                          if (counter == 8)
                                          {
                                            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);
                                            counter = 0;
                                          }
                                          else counter++;
                                      
                                          if (whichport == 0)
                                          {
                                            if (center)
                                              return currentx;
                                            return xvalue;
                                          }
                                      
                                          else if (whichport == 2)
                                          {
                                            if (center)
                                              return currenty;
                                            return yvalue;
                                          }
                                        }
                                      
                                      
                                      
                                      
                                        else // use original inputs
                                          return readinputport(whichport);
                                      }
                                      
                                      1 Reply Last reply Reply Quote 0
                                      • G
                                        grant2258 Banned
                                        last edited by grant2258

                                        ok just put the counter in if your horizontals arent sticking havent tested it on the pie yet just on a windows box will let you know how i get on. I have a few other things in tinkering with havent spent a great deal of time on this

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

                                          @grant2258 the counter is in, I just moved where it is so direction is always defined on each read but the position is not updated unless it's on the right count.

                                          We could probably initialize direction normally this way too instead of undefined and remove the if statement

                                          Like this

                                          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  currentx  = 0x80;
                                            static INT16  currenty  = 0x80;
                                            static INT16  center = 0;
                                            static INT16  counter = 0;
                                            static INT16  direction = readinputport(6);
                                            int temp;
                                          
                                            if( options.cheat_input_ports) // use cheat ports
                                            {
                                              if (counter == 8)
                                              {
                                                direction = readinputport(6);
                                                temp = direction & ~16;
                                                counter = 0;
                                          
                                                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 counter++;
                                          
                                              if (whichport == 0)
                                              {
                                                if (center)
                                                  return currentx;
                                                return xvalue;
                                              }
                                          
                                              else if (whichport == 2)
                                              {
                                                if (center)
                                                  return currenty;
                                                return yvalue;
                                              }
                                            }
                                          
                                          
                                            else // use original inputs
                                              return readinputport(whichport);
                                          }
                                          
                                          1 Reply Last reply Reply Quote 0
                                          • G
                                            grant2258 Banned
                                            last edited by

                                            strange ill checkout it out on the pi. You need to understand something about this code. This function only reads one axis at a time x then y over and over at high speeds keep that in mind if you make changes.

                                            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.