Re: controller auto reset
Posted: 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.
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.
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;
}
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.