Page 4 of 4

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

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.

Posted: Thu Dec 09, 2010 9:30 pm
by Mixail
Problem all in the same. The screen flickers.
Such impressions that function
buttons = get_pad(0);
break.

Image

Posted: Thu Dec 09, 2010 9:47 pm
by powerofrecall
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

Posted: Fri Dec 10, 2010 9:42 am
by Stef
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.

Posted: Fri Dec 10, 2010 7:12 pm
by Chilly Willy
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.

Posted: Fri Dec 10, 2010 8:52 pm
by Mixail
Simply I not so do something.

Posted: Fri Dec 10, 2010 9:05 pm
by Chilly Willy
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.