Puck's Usb Joystick Lib Fix!


YuanHao

Member
Joined
Jul 30, 2006
Messages
215
Age
38
Website
www.yuanworks.com
This is specially important for emus and anyone using Puck's USB Joystick lib!!

(Note: I'm sorry if this problem has already been issued and fixed, but I can't seem to find too much about it in the forum)

PROBLEM:

We just got the USB cradle, and we used the NES emu to test it. The USB joystick libs sets both LEFT and RIGHT (or UP and DOWN, but let's stick to LEFT and RIGHT) if you press them at the "same" (or quickly enough) time.

For example: Suppose you are running on megaman 3 to the left, and suddenly decide to go right. Both left and right will be registered, which will freeze megaman. It gets worse for example on Ninja Gaiden, where Ryu starts to ice-skate through the stage (similar to mario 1 glitch with the pipe).

SOLUTION (untested but probably works):

In the joy_update() method:

Change:
CODE
if (events.number == 1) {
if (events.value == 0) joy->stateaxes[JOYLEFT] = joy->stateaxes[JOYRIGHT] = 0;
else if (events.value < 0) joy->stateaxes[JOYLEFT] = 1;
else joy->stateaxes[JOYRIGHT] = 1;
joy->axevals[1] = events.value; }


To:

CODE
if (events.number == 0) {

// Reset both directions...
joy->stateaxes[JOYLEFT] = joy->stateaxes[JOYRIGHT] = 0;

if (events.value < 0)
joy->stateaxes[JOYLEFT] = 1;

else if (events.value > 0)
joy->stateaxes[JOYRIGHT] = 1;

joy->axevals[0] = events.value;
}


The same must be done with UP and DOWN. What will happen? LEFT and RIGHT will never be pressed simultaneously (which I don't feel is needed in any game that has been made as of now).

I'm busy at the moment and not familiar to modifying emulators or such, so I hope someone else can do it :D. I know it's no great discovery, but it's a real pain when you're trying to play with usb controllers. This little code will save many cradles and a lot of frustration :)

BTW thanks Puck for this great library, and woogal who suggested the solution :) Too much entertainment for today, back to Wind and Water! (I'll be testing this tomorrow and see if I can get USB controller support for Wind and Water :))
 
A r k said:
We just got the USB cradle, and we used the NES emu to test it.
Was that NES emu gpfce?

Nice discovery though. I was trying to reproduce that problem but failed, probably I suck at changing gamepad directions quickly (or my gamepad doesn't let me that). Will patch gpfce and PD this evening, as they are definitely affected.
 
Last edited by a moderator:
Don't get too excited just yet. As Ark says, this is untested and just my guess at what could be causing the problem (based on me making the same mistake with sdl a few weeks ago). It was 4am and I'd had no sleep, so the chances of me misreading something could have been quite high ;).

Also, thinking about this a bit more, if event.value is anything like the sdl values then this code could do with a little more modification to reduce the sensitivity of analog sticks. Joystick axis values normally go from -32k to +32k (or something like that), so with this code the slightest movement on an analog controller will register a direction. Usually when reading an analog controller and converting it like this a few thousand values are ignored so there is a bit of a dead area (I ignore between -8000 and +8000).
 
Could a lack of a dead area be the cause of the original problem? In that only when the joystick is dead-centered does it not register a direction.
 
ste_167 said:
Could a lack of a dead area be the cause of the original problem? In that only when the joystick is dead-centered does it not register a direction.
I think you're thinking of analog controls. As far as I know digital input devices don't have a dead zone like an analog joystick, a direction switch is either on or off.
 
Last edited by a moderator:
Hi again everyone.

woogal: I could bet that this would solve the problem, since there is NO way for both directions to be on for the 0 values.

Notaz: Yep, I tested GPFCE, btw excellent work :D

It is possible to never do this with some controllers, though it's easy with my PlayStation controller.

And, I'm not sure what will happen with analogs. I tested my PS analogs and they also got stuck (same issue). However, I would say they work since there's a value for left/right, and another value for up/down. The problem that woogal states should be solved by each software or condition, not by the general lib itself. Something such as:

if direction == LEFT && .value >= 8000 then //do action

I don't think this issue should be solved through the lib. Besides, analog controllers are not the best to play non-analog games (which make up the most part of GP2X entertainment, I guess we could point out PSX).

I'll be testing this today and I'll let you all know.
 
A r k said:
[...]
The problem that woogal states should be solved by each software or condition, not by the general lib itself. Something such as:

if direction == LEFT && .value >= 8000 then //do action
But still your and woogal's solution should be good for most cases.

I was able to reproduce the problem after I temporarily reduced update rate to < 10Hz, and the fix seemed to work. The latest build of gpfce now has the fix, can you try it out?
 
Last edited by a moderator:
notaz said:
A r k said:
[...]
The problem that woogal states should be solved by each software or condition, not by the general lib itself. Something such as:

if direction == LEFT && .value >= 8000 then //do action
But still your and woogal's solution should be good for most cases.

I was able to reproduce the problem after I temporarily reduced update rate to < 10Hz, and the fix seemed to work. The latest build of gpfce now has the fix, can you try it out?


Slowing it down makes it easier since you won't get the 0 value on the axis I think.

Just tried GPFCE, works like a charm :D thanks notaz! I hope everyone who thought twice about buying a cradle makes their final decision of BUYING it, it makes such a difference to play with controllers.

I also finished adding 1 player support for Wind and Water and works great too (with the fix), so I guess two players will come by later today.
 
Last edited by a moderator:
DDR:

I believe this game (and/or the many clones baised on it) DO need to register LEFT+RIGHT at the same time.

However, I don't think may GP2X owners will use their DDR pad with this....(although it could very well work...!)

G.J.!
 
Great work!

Just one thought, pretty much every game in an emulator for a console that only supports joysticks with 1 fire button (phew!) will need to have diagonals pressed simultaneously. Simply because up on the joystick is jump in most (all?) platformers, like Turrican on UAE4all. Some of the original games on Amiga even go out of their way not to jump right or left _unless_ diagonals are pressed pretty much at the same time. I'd think the same applies to fighting games like IK+.
 
Do you mean if one can press Up and right (for diagonal) at the same time?

That's ok, this fix only prevents both LEFT+RIGHT to be pressed simultaneously, or UP+DOWN simultaneously. LEFT+UP is ok, or any other combination :)
 
Back
Top