Page 2 of 2

Re: controller auto reset

Posted: Thu Jul 06, 2017 3:55 am
by Miquel
Aside that you can unplug & plug controllers at any moment...

You said some 3rd party 6 buttons controllers only fetch data at 1st and 4th cycle, but on SGDK the 6 button routine gets data at 3rd and 4th cycles.

Code: Select all

static u16 read6Btn(u16 port)
{
    vu8 *pb;
    u16 val, v1, v2;

    pb = (vu8 *)0xa10003 + port*2;

    v1 = TH_CONTROL_PHASE(pb);                    /* - 0 s a 0 0 d u - 1 c b r l d u */
    val = TH_CONTROL_PHASE(pb);                   /* - 0 s a 0 0 d u - 1 c b r l d u */
    v2 = TH_CONTROL_PHASE(pb);                    /* - 0 s a 0 0 0 0 - 1 c b m x y z */
    val = TH_CONTROL_PHASE(pb);                   /* - 0 s a 1 1 1 1 - 1 c b r l d u */

    if ((val & 0x0F00) != 0x0F00) v2 = (JOY_TYPE_PAD3 << JOY_TYPE_SHIFT) | 0x0F00; /* three button pad */
    else v2 = (JOY_TYPE_PAD6 << JOY_TYPE_SHIFT) | ((v2 & 0x000F) << 8); /* six button pad */

    val = ((v1 & 0x3000) >> 6) | (v1 & 0x003F);   /* 0 0 0 0 0 0 0 0 s a c b r l d u  */
    val |= v2;                                    /* 0 0 0 1 m x y z s a c b r l d u  or  0 0 0 0 1 1 1 1 s a c b r l d u */
    val ^= 0x0FFF;                                /* 0 0 0 1 M X Y Z S A C B R L D U  or  0 0 0 0 0 0 0 0 S A C B R L D U */

    return val;
}
Or I'm missing some thing or v1 is completely ignored.

And you don't need to do it at vblank... a MD game works like:

game loop
v interruption
game loop
v interruption
game loop
v interruption
...

So it's more resource wise to do it in the game loop.

Re: controller auto reset

Posted: Thu Jul 06, 2017 3:39 pm
by Chilly Willy
No, I said some third-party controllers only WORK if you do one or four cycles. They return data at the proper cycles the same as all controllers.
So it's more resource wise to do it in the game loop.
ONLY if you can guarantee the loop will not run any faster than once per vblank, and that the place in the loop you do the pad reading is the same each loop. Otherwise you won't be able to guarantee the timeout and you may wind up reading a pad too soon and it'll go bananas on you. That 1/60th second delay is critical to some pads. Now going longer is fine - for example, if your code loops once every other vblank, you know you have about 1/30th sec, which is way more than needed. Then it's not so critical.

Re: controller auto reset

Posted: Thu Jul 06, 2017 5:06 pm
by KanedaFr
Chilly Willy wrote:. That 1/60th second delay is critical to some pads. Now going longer is fine - for example, if your code loops once every other vblank, you know you have about 1/30th sec, which is way more than needed. Then it's not so critical.
Which get back to my initial question ;)
Some pads (third party?) auto reset within the 1/60 (1/50) frame ?

Re: controller auto reset

Posted: Thu Jul 06, 2017 6:50 pm
by Mask of Destiny
All six-button controllers will reset after a certain amount of time when read properly. There is no way to get a six-button controller back to the initial state without that reset.