-buttons pad : X, Y, Z aren't working

SGDK only sub forum

Moderator: Stef

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

-buttons pad : X, Y, Z aren't working

Post by oofwill » Wed Aug 08, 2012 2:27 pm

Hi,

I've tested KanedaFR's soft for testing various joypads and it work with gens.

Now i'm writing a small code to test 6 buttons pads, and testing it with gens.
When i press D-pad or A; B, C & Start buttons, it's working.

However, it doesn't work with X, Y, Z & mode buttons.

Code: Select all

JOY_setEventHandler( &joypad );
.
.
.

Code: Select all

if (state & BUTTON_START)
        {
            VDP_drawText("START", 8, 8);
        }

    else if (changed & BUTTON_START)
        {
            VDP_drawText("     ", 8, 8);
        }

    if (state & BUTTON_A)
        {
            VDP_drawText("A", 8, 5);
        }

    else if (changed & BUTTON_A)
        {
            VDP_drawText(" ", 8, 5);
        }
this code is working, but if i replace "A" by "X" for example, it doesn't work anymore...

Any clue?

sega16
Very interested
Posts: 251
Joined: Sat Jan 29, 2011 3:16 pm
Location: U.S.A.

Post by sega16 » Wed Aug 08, 2012 2:35 pm

You are using sgdk 0.92 right? If so in joy.h you will notice the function

Code: Select all

/**
 * \brief
 *      Set peripheral support for the specified port.<br>
 *<br>
 *      By default ports are configured to only enable support for joypads, unless<br>
 *      a pad is not detected. In that case, a multitap or mouse is enabled if<br>
 *      present.<br>
 *<br>
 * \param port
 *      Port we want to set support.<br>
 *      <b>PORT_1</b>   = port 1<br>
 *      <b>PORT_2</b>   = port 2<br>
 * \param support
 *      Peripheral support.<br>
 *      <b>JOY_SUPPORT_3BTN</b>           = 3 button joypad<br>
 *      <b>JOY_SUPPORT_6BTN</b>           = 6 button joypad<br>
 *      <b>JOY_SUPPORT_TRACKBALL</b>      = Sega Sports Pad (SMS trackball)<br>
 *      <b>JOY_SUPPORT_MOUSE</b>          = Sega MegaMouse<br>
 *      <b>JOY_SUPPORT_TEAMPLAYER</b>     = Sega TeamPlayer<br>
 *      <b>JOY_SUPPORT_EA4WAYPLAY</b>     = EA 4-Way Play<br>
 *      <b>JOY_SUPPORT_MENACER</b>        = Sega Menacer<br>
 *      <b>JOY_SUPPORT_JUSTIFIER_BLUE</b> = Konami Justifier (blue gun only)<br>
 *      <b>JOY_SUPPORT_JUSTIFIER_BOTH</b> = Konami Justifier (both guns)<br>
 *      <b>JOY_SUPPORT_ANALOGJOY</b>      = Sega analog joypad (not yet supported)<br>
 *      <b>JOY_SUPPORT_KEYBOARD</b>       = Sega keyboard (not yet supported)<br>
 *<br>
 *      Ex : enable support for MegaMouse on second port :<br>
 *      JOY_setSupport(PORT_2, JOY_SUPPORT_MOUSE);<br>
 *<br>
 */
void JOY_setSupport(u16 port, u16 support);
Call that function JOY_setSupport() and set the port to what you want to support.

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Wed Aug 08, 2012 2:59 pm

I've already test it with

Code: Select all

JOY_setSupport(PORT_1, JOY_SUPPORT_6BTN);
It doesn't work :|

How do i know what version of SGDK i'm using?

sega16
Very interested
Posts: 251
Joined: Sat Jan 29, 2011 3:16 pm
Location: U.S.A.

Post by sega16 » Wed Aug 08, 2012 3:07 pm

The version is in the folder name you should have a folder called sgdk092 if the number is smaller than 092 that you have a older version.

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Wed Aug 08, 2012 3:09 pm

:lol: mine is just "SGDK"

sega16
Very interested
Posts: 251
Joined: Sat Jan 29, 2011 3:16 pm
Location: U.S.A.

Post by sega16 » Wed Aug 08, 2012 4:56 pm

I got a readme.txt file in sgdk 0.92 there was no readme in older versions.

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Wed Aug 08, 2012 6:02 pm

I have no readme...

Seems i'll had to upgrade to 0.92...

Thanks for help ;)

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Wed Aug 08, 2012 7:17 pm

The SDK auto-detects controllers when it can. If you get the port type, you'll see what has been detected.

Code: Select all

/**
 * \brief
 *      Get peripheral type for the specified port.<br>
 *<br>
 *      The peripheral type for each port is automatically detected during JOY_init().<br>
 *      This function returns that type to help decide how the port support should be set.<br>
 *      Types greater than 15 are not derived via Sega's controller ID method.<br>
 *<br>
 * \param port
 *      Port we want to get the peripheral type.<br>
 *      <b>PORT_1</b>   = port 1<br>
 *      <b>PORT_2</b>   = port 2<br>
 * \return type
 *      Peripheral type.<br>
 *      <b>PORT_TYPE_MENACER</b>        = Sega Menacer<br>
 *      <b>PORT_TYPE_JUSTIFIER</b>      = Konami Justifier<br>
 *      <b>PORT_TYPE_MOUSE</b>          = Sega MegaMouse<br>
 *      <b>PORT_TYPE_TEAMPLAYER</b>     = Sega TeamPlayer<br>
 *      <b>PORT_TYPE_PAD</b>            = Sega joypad<br>
 *      <b>PORT_TYPE_UNKNOWN</b>        = unidentified or no peripheral<br>
 *      <b>PORT_TYPE_EA4WAYPLAY</b>     = EA 4-Way Play<br>
 *<br>
 *      Ex : get peripheral type in port 1 :<br>
 *      type = JOY_getPortType(PORT_1);<br>
 *<br>
 */
u8 JOY_getPortType(u16 port);
The type of pad is also auto-detected, and the way to figure out which you have is to read the joy pad, then check the type field (the top four bits of the buttons value returned by JOY_readJoypad).

Code: Select all

#define JOY_TYPE_PAD3           0x00
#define JOY_TYPE_PAD6           0x01
#define JOY_TYPE_MOUSE          0x02
#define JOY_TYPE_TRACKBALL      0x03
#define JOY_TYPE_MENACER        0x04
#define JOY_TYPE_JUSTIFIER      0x05
#define JOY_TYPE_UNKNOWN        0x0F
#define JOY_TYPE_SHIFT          12
#define JOY_TYPE_MASK           0xF000
You only set the support explicitly under certain conditions:

1 - Set 3 button support when you have a 6 button pad, but don't need all 6 buttons. Setting 3 button support makes the pad read a little faster.

2 - Certain controllers take a long time to read, so they default to OFF unless they are the only controller found. The mouse is a good example. The mouse is not enabled unless there's no pad plugged in. Set support to mouse when you need it and get port shows it's available.

3 - Certain controllers take more system resources and/or aren't often used, so they default to off. A light gun is a good example. Set support for the gun if get port shows it's available and you want to use it.

4 - Certain controllers cannot be detected, like the trackball. Set the support for the trackball when you require it or the user selects on option (onscreen) saying it's available and they want to use it.

So you don't need to set the support for 6 button controllers - it's automatically set if you have one plugged in. The current SDK has an example for the controllers showing how to get the port type, how to determine what is being read, how to set the support, etc.

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Wed Aug 08, 2012 7:36 pm

Ok, i understand.

This program used to work normally until i made some changes, but i don't know wich changes causes my problems...

No i've got another problem :lol:

I replace all old files by new files of SGDK 0.92 version.
Now, when i'm compiling my program, all seems to be ok, but in emulator, there is no reaction when i press au button (all buttons!)

The code don't change so i try to compile librairies... i'm stopped by this step :

Add the "bin" directory of devkit (%GDK_WIN%\bin) to your PATH variable. Be careful, if you have another GCC installation you can have some conflicts when cc1 command will be called...

I don't understand what i'm suppose to do... :|

Sorry for those noob questions :|

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Wed Aug 08, 2012 9:06 pm

oofwill wrote:Ok, i understand.

This program used to work normally until i made some changes, but i don't know wich changes causes my problems...

No i've got another problem :lol:

I replace all old files by new files of SGDK 0.92 version.
Now, when i'm compiling my program, all seems to be ok, but in emulator, there is no reaction when i press au button (all buttons!)

The code don't change so i try to compile librairies... i'm stopped by this step :

Add the "bin" directory of devkit (%GDK_WIN%\bin) to your PATH variable. Be careful, if you have another GCC installation you can have some conflicts when cc1 command will be called...

I don't understand what i'm suppose to do... :|

Sorry for those noob questions :|
If your old SGDK installation worked you don't have to repeat the install process... replacing old SGDK files by new ones should be enough, then you only need to rebuild your rom.

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Wed Aug 08, 2012 10:12 pm

So, it's ok for this 0.92...

I always have problem with X, Y & Z buttons, but i don't stop searching ...

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Wed Aug 08, 2012 10:34 pm

How about showing the code? It's probably something you're thinking you wrote one way, but is actually written another way. That's REAL common: reading the code the way you THINK you wrote it rather than the way you ACTUALLY wrote it. That's why it's good to have someone else look over your code - they read it the way you actually wrote since they have no idea what you MEANT to write.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Thu Aug 09, 2012 8:24 am

Chilly Willy wrote:How about showing the code? It's probably something you're thinking you wrote one way, but is actually written another way. That's REAL common: reading the code the way you THINK you wrote it rather than the way you ACTUALLY wrote it. That's why it's good to have someone else look over your code - they read it the way you actually wrote since they have no idea what you MEANT to write.
So true ;)

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Thu Aug 09, 2012 3:26 pm

You're so right! how many times i'm searching why it doesn't work and it's just because i put "*" in place of "/" or something else :lol:

example (tested with Regen)

Code: Select all

while (1)
    {        
        VDP_drawText("->", 3, choix);

        if ((JOY_readJoypad(JOY_1) & BUTTON_START) && choix==8 && !previousvalue) {conf_detect();}

        if ((JOY_readJoypad(JOY_1) & BUTTON_START) && choix==10 && !previousvalue) {joy_test();}

        if ((JOY_readJoypad(JOY_1) & BUTTON_START) && choix==12 && !previousvalue) {color_test();}

        if ((JOY_readJoypad(JOY_1) & BUTTON_UP) && choix==8 && !previousvalue) {VDP_drawText("  ", 3, choix); choix=12;}
        else if ((JOY_readJoypad(JOY_1) & BUTTON_UP) && !previousvalue) {VDP_drawText("  ", 3, choix); choix=choix-2;}

        if ((JOY_readJoypad(JOY_1) & BUTTON_DOWN) && choix==12 && !previousvalue) {VDP_drawText("  ", 3, choix); choix=8;}
        else if ((JOY_readJoypad(JOY_1) & BUTTON_DOWN) && !previousvalue) {VDP_drawText("  ", 3, choix); choix=choix+2;}

        previousvalue=JOY_readJoypad(JOY_1);
    }
When i'm running this with Regen : two case :

- a 6 button pad is configured in Regen : my arrow (->) doesn't move neither START button
- a 3 button pad is configured in Regen : my arrow is moving up and down when i press up & down, start button is active too.

Edit : tested with Gens, same result

Edit 2: after another test, it seems to work with PORT2... but not PORT1 :shock:

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Thu Aug 09, 2012 4:28 pm

I don't understand :|

this code works

Code: Select all

if (JOY_readJoypad(JOY_2) & BUTTON_X) {VDP_drawText("X", 27, 14);}
        else if (!(JOY_readJoypad(JOY_2) & BUTTON_X)) {VDP_drawText(" ", 27, 14);}

        if (JOY_readJoypad(JOY_2) & BUTTON_Y) {VDP_drawText("Y", 27, 15);}
        else if (!(JOY_readJoypad(JOY_2) & BUTTON_Y)) {VDP_drawText(" ", 27, 15);}

        if (JOY_readJoypad(JOY_2) & BUTTON_Z) {VDP_drawText("Z", 27, 16);}
        else if (!(JOY_readJoypad(JOY_2) & BUTTON_Z)) {VDP_drawText(" ", 27, 16);}
and this one not!

Code: Select all

if (JOY_readJoypad(JOY_1) & BUTTON_X) {VDP_drawText("X", 8, 13);}
        else if (!(JOY_readJoypad(JOY_1) & BUTTON_X)) {VDP_drawText(" ", 8, 13);}
This is the first thing i don't understand.

The second thing is : when i press A, B & C at the same time, pad 1 or 2, A, B & C are on the screen. ok. normal.
But on pad 1, while X, Y & Z buttons aren't working, they are working on pad 2 but i can't press more than two at the same time.
If i press X & Y then Z, Z won't appear.

Very strange :|

Post Reply