controller auto reset

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

Moderator: BigEvilCorporation

Miquel
Very interested
Posts: 514
Joined: Sat Jul 30, 2016 12:33 am

Re: controller auto reset

Post by Miquel » Thu Jul 06, 2017 3:55 am

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.
Last edited by Miquel on Thu Jul 06, 2017 4:49 pm, edited 1 time in total.
HELP. Spanish TVs are brain washing people to be hostile to me.

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

Re: controller auto reset

Post by Chilly Willy » Thu Jul 06, 2017 3:39 pm

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.

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Re: controller auto reset

Post by KanedaFr » Thu Jul 06, 2017 5:06 pm

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 ?

Mask of Destiny
Very interested
Posts: 615
Joined: Thu Nov 30, 2006 6:30 am

Re: controller auto reset

Post by Mask of Destiny » Thu Jul 06, 2017 6:50 pm

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.

Post Reply