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

SGDK only sub forum

Moderator: Stef

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

Post by Chilly Willy » Thu Aug 09, 2012 4:52 pm

You aren't looking at the value of JOY_readJoypad() correctly... look at one thing you do

Code: Select all

 && !previousvalue
On a 6-button pad, that will ALWAYS be 0. Why? Because previousValue is (1<<12 | (buttons)). So no matter what the buttons are, it's always still got a value. If you want ONLY the buttons, you must use (val & BUTTON_ALL), which strips the controller type. Also, store the value in a local var rather than read it multiple times. It's faster and cleaner.

Code: Select all

while (1)
    {
        u16 buttons = JOY_readJoypad(JOY_1);

        VDP_drawText("->", 3, choix);

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

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

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

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

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

        previousvalue = buttons & BUTTONS_ALL;
    }

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

Post by oofwill » Thu Aug 09, 2012 5:49 pm

Many thanks for this. It should work now.

I thought !JOY_readJoypad() would return 1 if no buttons pressed.

I always use this and this worked with 3 buttons pad but i didn't know this difference with 6 buttons pad.

Thanks again, i'm testing it :D

And i'll store the read in u16 value if so (i'm not good at C, i'm at beginning :oops: )

EDIT : it's perfectly working now, many thanks ;)

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

Post by Chilly Willy » Thu Aug 09, 2012 6:44 pm

It works with 3 button pads because the JOY type for a 3 button pad is 0. The type field (the upper four bits of the value read) varies by the controller. There's a complete list in joy.h. You get the type using (readval & JOY_TYPE_MASK) or (readval >> JOY_TYPE_SHIFT), and you get the buttons using (readval & BUTTONS_ALL).

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

Post by oofwill » Thu Aug 09, 2012 10:07 pm

Your explaination is great, i now have a better understanding of how it works.

I can do some thing i didn't even think before :)

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

Post by Chilly Willy » Thu Aug 09, 2012 10:41 pm

oofwill wrote:Your explaination is great, i now have a better understanding of how it works.

I can do some thing i didn't even think before :)
Good. The idea was that in one function, you'd have both the type of controller and it's status (button state). All controllers return the buttons compatible with pads - as far as they can; for example, the mouse translates the left/middle/right buttons into A/B/C, and sets the direction based on which way the mouse is moving. So using (val & BUTTONS_ALL), both the mouse and pad look exactly the same to your program. If you needed to know if it were really a pad or a mouse, then you look at (val & JOY_TYPE_MASK).

Post Reply