6 button

For anything related to IO (joypad, serial, XE...)

Moderator: BigEvilCorporation

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

Post by Chilly Willy » Wed Dec 08, 2010 7:42 pm

Code: Select all

extern unsigned short int get_pad(int pad);

#define SEGA_CTRL_BUTTONS   0x0FFF
#define SEGA_CTRL_UP        0x0001
#define SEGA_CTRL_DOWN      0x0002
#define SEGA_CTRL_LEFT      0x0004
#define SEGA_CTRL_RIGHT     0x0008
#define SEGA_CTRL_B         0x0010
#define SEGA_CTRL_C         0x0020
#define SEGA_CTRL_A         0x0040
#define SEGA_CTRL_START     0x0080
#define SEGA_CTRL_Z         0x0100
#define SEGA_CTRL_Y         0x0200
#define SEGA_CTRL_X         0x0400
#define SEGA_CTRL_MODE      0x0800

#define SEGA_CTRL_TYPE      0xF000
#define SEGA_CTRL_THREE     0x0000
#define SEGA_CTRL_SIX       0x1000
#define SEGA_CTRL_NONE      0xF000

int main(void)
{
    while(1)
    {
        unsigned short int buttons;


        buttons = get_pad(0);
        if ((buttons & SEGA_CTRL_TYPE) == SEGA_CTRL_NONE)
        {
            buttons = get_pad(1);
            if ((buttons & SEGA_CTRL_TYPE) == SEGA_CTRL_NONE)
            {
                // no controllers, loop until one plugged in
                continue;
            }
        }
        // buttons now has current value of either pad0 or pad1

        if ((buttons & SEGA_CTRL_A))
        {
            // A pressed

        }


    }
}
That looks for pad0 first, and if there isn't a pad in control port 0, checks for pad1. If neither are plugged in, it waits for a controller to be plugged in. It has one example of checking if a button is pressed, but does nothing. You'll need your own code for that.

Mixail
Very interested
Posts: 133
Joined: Thu Nov 18, 2010 4:47 pm

Post by Mixail » Thu Dec 09, 2010 9:30 pm

Problem all in the same. The screen flickers.
Such impressions that function
buttons = get_pad(0);
break.

Image

powerofrecall
Very interested
Posts: 237
Joined: Fri Apr 17, 2009 7:35 pm
Location: USA

Post by powerofrecall » Thu Dec 09, 2010 9:47 pm

It's because you're drawing to the A plane without waiting for vsync. Try either putting in a VDP_waitVSync(); in there or flipping between APLAN and BPLAN.

Also try inserting get_pad() into the vblank callback and read the pad into a global variable.

edit: also if you're just wanting to show the state of a button or something, just update the text when the button state changes instead of constantly in a while loop

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

Post by Stef » Fri Dec 10, 2010 9:42 am

edit: also if you're just wanting to show the state of a button or something, just update the text when the button state changes instead of constantly in a while loop
And to handle that easily you can use the following method to set your joystick state change event handler :

Code: Select all

JOY_setEventHandler(_joyEventCallback *CB);
where the event handler should be defined as :

Code: Select all

void joyEventCallback(u16 joy, u16 changed, u16 state) {...}
You can see how use it in partic example.

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

Post by Chilly Willy » Fri Dec 10, 2010 7:12 pm

That would only read 3 button controllers, but either method works fine. The person just doesn't have enough foundation in programming a console like the Genesis to do what he wants.

Mixail
Very interested
Posts: 133
Joined: Thu Nov 18, 2010 4:47 pm

Post by Mixail » Fri Dec 10, 2010 8:52 pm

Simply I not so do something.

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

Post by Chilly Willy » Fri Dec 10, 2010 9:05 pm

Look over the examples that come with Stef's mini devkit. Look at the source for the routine in the devkit. Get an understanding of how they work, how to do things on the Genesis, THEN you should be ready to start making simple programs of your own. The examples are there for a reason... the source for the devkit is available for people to study for a reason. The reason is to help others learn.

Post Reply