You have to switch them an even times.
What would happen if, by mistake, I switch them an odd times?
has the controller somekind of reset-to-defaut-after-X-ns feature ? or will my read be bugged for the rest of the game ?

Moderator: BigEvilCorporation
Code: Select all
asking ABC
wait vlank
asking XYZ
Code: Select all
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 */
Code: Select all
static u16 TH_CONTROL_PHASE(vu8 *pb)
{
u16 val;
*pb = 0x00; /* TH (select) low */
asm volatile ("nop");
asm volatile ("nop");
val = *pb;
*pb = 0x40; /* TH (select) high */
val <<= 8;
val |= *pb;
return val;
}
Yeah, sorry, misspoke on that... been a while (years) since I wrote that code. But you should still fetch it. His pseudo-code isn't doing that. Notice how they do four high-to-low-to-high transitions? His only does three. My point was that doesn't get the entire data packet, and a few odd-ball controllers won't work because of that.TmEE co.(TM) wrote:Technically you're not supposed to use the "1111" as ID, only the "0000"
From my memories (not always right), I had a third party six-button pad (with no mode button) that would work if you did ONE cycle per vblank (normal 3-button read), or if you did FOUR cycles per vblank (6-button read), and return garbage for anything else. My thought at the time was that whatever internal state machine (be it hardware or software) they used only checked for timeout at one cycle, or four cycles, but not two or three. Probably saved themselves two or three logic terms by skimping like that.Sik wrote:But wouldn't such controllers also break with games that only support 3 button controllers? (the whole point of automatic reset is to make that stuff work)
EDIT: I do recall some controllers break if you try to read too much though, and when the controller is just initialized it may be in an undefined state, so it's in your best interests to avoid using the controller as soon as you initialize the ports. Yeah, this problem has actually happened before.
Chilly Willy wrote:Note, the code is from SGDK... which I helped with a few things, notably the controller code.
????Chilly Willy wrote: From my memories (not always right), I had a third party six-button pad (with no mode button) that would work if you did ONE cycle per vblank (normal 3-button read), or if you did FOUR cycles per vblank (6-button read), and return garbage for anything else. My thought at the time was that whatever internal state machine (be it hardware or software) they used only checked for timeout at one cycle, or four cycles, but not two or three. Probably saved themselves two or three logic terms by skimping like that.![]()
Code: Select all
static u16 read3Btn(u16 port)
{
vu8 *pb;
u16 val;
pb = (vu8 *)0xa10003 + port*2;
val = TH_CONTROL_PHASE(pb); /* - 0 s a 0 0 d u - 1 c b r l d u */
val = ((val & 0x3000) >> 6) | (val & 0x003F); /* 0 0 0 0 0 0 0 0 s a c b r l d u */
val ^= 0x00FF; /* 0 0 0 0 0 0 0 0 S A C B R L D U */
return val | (JOY_TYPE_PAD3 << JOY_TYPE_SHIFT);
}
Code: Select all
JOY_setSupport(PORT_1, JOY_SUPPORT_3BTN);