CPCWiki forum

General Category => Programming => Topic started by: mr_lou on 15:43, 12 July 15

Title: Joystick Firebutton confusion
Post by: mr_lou on 15:43, 12 July 15
So a while back my girlfriend I were gonna play a 2-player game of PANG on my CPC+ but experienced something weird:
The firebuttons seemed to be reversed on port 2 (JOY1), so player 2 couldn't play with a joystick that only had 1 fire button.

Ok, fast forward to now. I'm experiencing the same when developing using CPCTelera by @ronaldo (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1227).

First, a BASIC program:

10 print joy(0), joy(1)
20 goto 10


This little BASIC program tells me that both JOY0 and JOY1 returns the value 16 when I press the FIRE button. That's what I expected.

Ok, now this little program in CPCTelera:


#include <cpctelera.h>
#include <stdio.h>

void main(void) {
    printf("Joystick firebutton test\n\r");
    printf("========================\n\r");
    while (1) {
    cpct_scanKeyboard();
    if (cpct_isKeyPressed(Joy0_Fire1)) printf("Joy0 fire 1\n\r");
    if (cpct_isKeyPressed(Joy0_Fire2)) printf("Joy0 fire 2\n\r");
    if (cpct_isKeyPressed(Joy0_Fire3)) printf("Joy0 fire 3\n\r");
    if (cpct_isKeyPressed(Joy1_Fire1)) printf("Joy1 fire 1\n\r");
    if (cpct_isKeyPressed(Joy1_Fire2)) printf("Joy1 fire 2\n\r");
    if (cpct_isKeyPressed(Joy1_Fire3)) printf("Joy1 fire 3\n\r");
    cpct_waitVSYNC();
   }
}


This little program tells me, that the FIRE button on JOY0 is Fire1 as I expected it to be.
But the FIRE button on JOY1 is in fact Fire2. Did not expect that.

I would think it was an error i CPCTelera, except I already experienced the same with PANG. And I know it's not a faulty wiring, because both joysticks returns 16 in BASIC.
So what is it? Some old well-known bug that everyone knows about except me?
What do other coders typically do about it?
Title: Re: Joystick Firebutton confusion
Post by: TFM on 15:47, 12 July 15
Did you use an original Joypad? Or just some random joystick, which may have a shortcut?


Fire 1 should return 16
Fire 2 should return 32
Fire 3 should return 64 (spare)

Title: Re: Joystick Firebutton confusion
Post by: mr_lou on 15:50, 12 July 15
Quote from: TFM on 15:47, 12 July 15
Did you use an original Joypad? Or just some random joystick, which may have a shortcut?

In Pang, I can plug CPC+ joypads into both ports. Then the player on JOY0 will need to press Fire1 to shoot, and the player on JOY1 will need to press Fire2 to shoot.
That makes no sense.

But now I'm seeing it's the same in CPCTelera.

No, I have tried different joysticks.
Title: Re: Joystick Firebutton confusion
Post by: mr_lou on 15:52, 12 July 15
Here is the joytest DSK.
Title: Re: Joystick Firebutton confusion
Post by: TFM on 16:01, 12 July 15
Quote from: mr_lou on 15:50, 12 July 15
In Pang, I can plug CPC+ joypads into both ports. Then the player on JOY0 will need to press Fire1 to shoot, and the player on JOY1 will need to press Fire2 to shoot.
That makes no sense.


So Fire 1 selects Player 1 and Fire 2 selects Player 2. Makes sense.
Title: Re: Joystick Firebutton confusion
Post by: TFM on 16:05, 12 July 15
Quote from: mr_lou on 15:52, 12 July 15
Here is the joytest DSK.


It works fine for Joystick1 Fire 1,2,3. Couldn't test Joy0.
Title: Re: Joystick Firebutton confusion
Post by: mr_lou on 16:11, 12 July 15
Quote from: TFM on 16:05, 12 July 15It works fine for Joystick1 Fire 1,2,3. Couldn't test Joy0.

That is just extremely weird!!!!

I have the problem both on my CPC464 and my CPC+.

On the CPC+:
The same joypad first in port 0, fire button 1 = fire 1, fire button 2 = fire 2.
Then put the same joypad into port 1, fire button 1 = fire 2 and fire button 2 = fire 1.

On the CPC:
The same happens, tried with 2 identical Wico joysticks in both ports.

This not faulty wiring as I said. This is some hardware bug thingy that I never heard about, and you apparently haven't either.

EDIT: Unless it really is a bug in both Pang and CPCTelera....
Title: Re: Joystick Firebutton confusion
Post by: TFM on 16:17, 12 July 15
Quote from: mr_lou on 16:11, 12 July 15
On the CPC+:
The same joypad first in port 0, fire button 1 = fire 1, fire button 2 = fire 2.
Then put the same joypad into port 1, fire button 1 = fire 2 and fire button 2 = fire 1.

On the CPC:
The same happens, tried with 2 identical Wico joysticks in both ports.


But the CPC only has ONE port. So I don't get it? Can somebody can do some tests please?  :)
Title: Re: Joystick Firebutton confusion
Post by: mr_lou on 16:19, 12 July 15
Quote from: TFM on 16:17, 12 July 15But the CPC only has ONE port. So I don't get it? Can somebody can do some tests please?  :)

I'm using a Y-splitter of course.
Bought 2 of these off eBay (http://www.ebay.com/itm/AMSTRAD-CPC-464-664-6128-TWO-2-X-JOYSTICK-GAME-PORT-Y-ADAPTER-CABLE-/111707890168?pt=LH_DefaultDomain_3&hash=item1a024f21f8). Seller says it has the diodes.
Title: Re: Joystick Firebutton confusion
Post by: arnoldemu on 16:56, 12 July 15
I tested Pang.
Confirmed, player 2 presses fire 2 to shoot the harpoon, player 1 presses fire 1.

However, i then used the arnold v  diagnostic cart. it showed the same as your first test in basic.

I looked at cpctelera's header file. It is incorrect.


Don't know why Pang uses fire1/fire2 like that! My only guess is that they experienced some button clash with fire1/fire2 when two players are playing. I see that fire1 and fire2 don't have diodes. But, because the directions have diodes and the fire's don't, I think you still can't cause clash if using just joysticks.

To cause clash you ordinarily need to press a direction AND fire, and the other player needs to press at least a direction or fire, then clash happens, but with diodes on the directions, the only way to cause clash is if one player presses both fires, and the other player presses 1 fire, I think.

I will need to retest, but I never saw clashes on the joysticks on plus.
Title: Re: Joystick Firebutton confusion
Post by: mr_lou on 17:35, 12 July 15
Thanks a lot Kevin!

Quote from: arnoldemu on 16:56, 12 July 15
I looked at cpctelera's header file. It is incorrect.

So you're saying I found a bug in CPCTelera?

Hereby forwarded to @ronaldo (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1227).
Title: Re: Joystick Firebutton confusion
Post by: ronaldo on 17:54, 12 July 15
Why shouldn't it be a bug in CPCtelera? Who thinks I'm so evil as to be perfect? :D

I'm pretty sure that CPCtelera is far from being bug-free. It should have at least as many bugs as I have as person, or more :D.

That's why it's so nice to be a complete community, and not just a solitary plainsman ;)

I'll have a look at it :)
Title: Re: Joystick Firebutton confusion
Post by: mr_lou on 18:06, 12 July 15
Quote from: ronaldo on 17:54, 12 July 15
Why shouldn't it be a bug in CPCtelera? Who thinks I'm so evil as to be perfect? :D

It was my Pang experience that threw me off.
Being so flawless as I am, I tend to think everyone else is too.  ;)
Title: Re: Joystick Firebutton confusion
Post by: ronaldo on 19:00, 12 July 15
I think I might have found the source from the problem. We have 2 conflicting documentations online, if I'm not mistaken. Take a look:
As you can see, CPCWiki's says that Joy1_Fire = Key G (without saying anything about Fire1/Fire2/Fire3). CPCTech says that Joy1_Fire1 = Key F, Joy1_Fire2 = Key_G.

CPCtelera follows CPCTech's and I haven't got a 2nd joystick interface to test it on a real CPC. However, I think this might be the source of the problem and CPCTech's documentation might be incorrect. Anyone can check this information? @arnoldemu (http://www.cpcwiki.eu/forum/index.php?action=profile;u=122)?
I think this is a good opportunity to check this documentation discrepancy between CPCTech's and CPCWiki's and unify both :).
Title: Re: Joystick Firebutton confusion
Post by: KaosOverride on 22:24, 12 July 15
If you look to the joystick pinout, you have fire 3, 1 and 2 in that order. If you redefine keys at north and south, Fire 1 and Fire 2 are named incorrect, both names are interchanged.

My theory is that fires where designed as Fire 3, 2, 1 and then coders found that the Atari norm used the Fire 2, so Fire 2 became the "main" fire. Then you have the Fire 3, 1, 2 we have today.
Title: Re: Joystick Firebutton confusion
Post by: Lazy Dude on 09:13, 13 July 15
Being a knowledgeable person who knows nothing about anything, I thought I'd pop up my opinion!

Firstly with the instruction manual for the 464 and 6128 it shows all the keyboard and joystick values etc.. so that's definitive, no guessing!

Joys 0 & 1 primary fire is fire 2 and fire 1 is the secondary "optional" function which on one of the joy (forget which!) is not always supported by all softwares.

Maybe open the plugs on the splitter to satisfy yourself that its all good for diodes and wiring?
Title: Re: Joystick Firebutton confusion
Post by: arnoldemu on 09:22, 13 July 15
I think you are correct the cpctech document is probably incorrect.
Title: Re: Joystick Firebutton confusion
Post by: mr_lou on 09:49, 13 July 15
That means, that bit 4 (value 16) = Fire 2 and bit 5 (value 32) = Fire 1.

Indeed, that is what the manual says too in chapter 8 page 22.

@ronaldo (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1227), that actually means that CPCTelera keyID Joy0_Fire1 and Joy0_Fire2 is wrong, while Joy1_Fire1 and Joy1_Fire2 is right.
I thought it was the other way around.

Standard fire button on joysticks that only has 1 button, is bit 4 (value 16) which should correspond to Joy0_Fire2 in CPCTelera. Currently it corresponds to Joy0_Fire1.

This should no doubt be mentioned in the Reference Manual: "Please note that the standard fire button is Fire 2!!! Yes! This is normal. Look it up. All games use Fire 2 button. Fire 1 only exists on joysticks that has 2 buttons".

Title: Re: Joystick Firebutton confusion
Post by: ronaldo on 10:09, 13 July 15
@mr_lou (http://www.cpcwiki.eu/forum/index.php?action=profile;u=96): the only real problem is messing up constants. If both Joy0_Fire1 and Joy1_Fire1 refer to the same button of the different joysticks, that would be enough. If they are really wired to Fire2, but Fire2 is used as main fire in 1-button joysticks, I think that's okay. In fact, I think that's preferably from the programmer point of view: they would prefer using Fire1 intuitively rather than finding that they should use Fire2 as that's the real fire button used in joysticks (and having to ask and read about the subject).

As long as constant names are consistent, I think it's not a problem, as CPCtelera progammers will use the appropriate constant and refer to the button they wanted. I'm going to change the Joy1_Fire1 <-> Joy1_Fire2 constants to solve this issue, as I think that's the better solution by now.
Title: Re: Joystick Firebutton confusion
Post by: Lazy Dude on 19:18, 13 July 15
As Alan Sugar would say- "You're Fired!"   :P
Title: Re: Joystick Firebutton confusion
Post by: ZbyniuR on 20:47, 13 July 15
Should be:

In old CPC
Joy0  pin8  connect with:
pin6  Fire1  key76  code(X)
pin7  Fire2  key77  code(Z)
pin5  Fire3  key78  code(255 not visible)

Joy1  pin9  connect with:
pin6  Fire1  key52  code(g)
pin7  Fire2  key53  code(f)
pin5  Fire3  key54  code(b)


In CPC Plus
Joy0 and Joy1 have separately ports, so in both GND is on pin8.
And no signal on Pins5 so Fire3 dosen't work.

No signal crush in any case. The only problem is, all "User Guides for CPC" show name Fire1 and Fire2 swap as F1 on pin7 and F2 on pin6. What is no make sens, because any Atari standard Joystick with only one fire, connect pins 8 with 6. So why Guide name it as Fire2 ??

Thats is reason why some documents quote Guide and others named Fire with X as Fire1 like in Atari standard. Thats is source of all this misunderstanding. I prefer Atari point of view. :)

Title: Re: Joystick Firebutton confusion
Post by: TFM on 21:03, 13 July 15
Because it's Amstard and not Atari. Nobody told that CPC have Atari plugs. They got Amstrad plugs, and Amstrad made Joysticks for em ;-)

Title: Re: Joystick Firebutton confusion
Post by: Lazy Dude on 21:17, 13 July 15
I must admit I always took it for granted that when the old cpc manuals state 'pin 5 spare' that it was not connected.
That's something else to tinker with when I get round to it.
Title: Re: Joystick Firebutton confusion
Post by: ZbyniuR on 22:44, 13 July 15
Yes, some documents mention about Fire3 as undocumented. But AMX mouse is using this pin5 as third button.
And all software producer treat Fire(X), as main or as only one Fire in CPC. The same like in Atari standard. But Atari standard has no second Fire because on pins 5 and 9 have analog paddle signal.

Amiga have:
pin6  F1  Button-L  <- the same like Atari and CPC
pin9  F2  Button-R  <- impossible in CPC here
pin5  F3  Button-M  <- the same like CPC and ST
Title: Re: Joystick Firebutton confusion
Post by: TFM on 23:06, 13 July 15
Few games on CPC actually use both official Fire buttons. Probably because there are only a couple of joysticks providing more then one fire signal.


Some of my joysticks have fire 1,2,3 because it's just convenient sometimes. And I liked to solder back the day ;-)


Next up: Using a Quickshot for Nintendo for a mod to run with CPC.  ;D  (In the usa you can't get a regular stick (I means sub D 9 pin plug) for a decent price).  :)
Title: Re: Joystick Firebutton confusion
Post by: KaosOverride on 00:40, 14 July 15
North and South also shows Fire 3 as "Spare"  :P

From some time ago I don't refer to Common1 and Common2 as grounds, but selects. I think is more correct.
Title: Re: Joystick Firebutton confusion
Post by: Bryce on 09:34, 14 July 15
Quote from: KaosOverride on 00:40, 14 July 15
North and South also shows Fire 3 as "Spare"  :P

From some time ago I don't refer to Common1 and Common2 as grounds, but selects. I think is more correct.

They definitely shouldn't be called grounds, as they aren't connected to ground and can't be used as ground.

Bryce.
Title: Re: Joystick Firebutton confusion
Post by: TFM on 16:38, 14 July 15
Yes, right. So let's call em by the names Common 1 and 2.  :laugh:

And of course Spare is Fire 3 since the AMX mouse is using it.  ;)


Nice way to waste time - just to think how to name things - remembers me about the computing section of the German Telekom in the early 90ies. I worked for them for a while... CPUs with 256 cores. And no Windows like shit!!! Huhu!  :) 
Powered by SMFPacks Menu Editor Mod