Page 1 of 1
Device ID in SGDK (joy.c)
Posted: Tue Dec 22, 2015 1:24 pm
by r57shell
can someone confirm correctness of this code (taken from SGDK)
Code: Select all
/* get ID port 1 */
pb = (vu8 *)0xa10003;
a = *pb;
*pb = 0x00;
id = (a & 8) | (a & 4) ? 8 : 0;
id |= (a & 2) | (a & 1) ? 4 : 0;
a = *pb;
*pb = 0x40;
id |= (a & 8) | (a & 4) ? 2 : 0;
id |= (a & 2) | (a & 1) ? 1 : 0;
portType[PORT_1] = id;
I'm asking because it does not work in any known by me emulator of genesis. I don't have teamplay or other things except normal joypads to test it, and I don't have flashcart too, that's why I'm asking
Re: Device ID in SGDK (joy.c)
Posted: Tue Dec 22, 2015 6:13 pm
by Mask of Destiny
The algorithm looks generally correct, but the bits appear to be arranged differently than in the official algorithm. In the official version, the values from TH=0 form bits 0 and 1 while the values from TH=1 form bits 2 and 3. In the version you posted from SGDK, they're flipped around. This isn't necessarily a problem as long as you adjust the constants you're checking for accordingly. With this version a controller will be 0x7 instead of 0xD for instance.
Re: Device ID in SGDK (joy.c)
Posted: Wed Dec 23, 2015 11:37 am
by r57shell
but normal joypad (6 or 3 buttons) defined as 0xD here.
also, take a look in write/read order. It does first read, then write.
Re: Device ID in SGDK (joy.c)
Posted: Fri Jan 08, 2016 1:25 pm
by Dr. MefistO
Ok, I have the Team Player device. Give me your test ROM.
Re: Device ID in SGDK (joy.c)
Posted: Sun Jan 10, 2016 6:20 pm
by r57shell
With help of
Dr. MefistO, figured out that SGDK code is working on hardware.
Also, it works fine in Retroarch with libgenplus-gx.
What is interesting, that Fusion works if add following line, which does not make any sense.
Code: Select all
/* get ID port 1 */
pb = (vu8 *)0xa10003;
*pb = 0x70; /* Fusion support */
a = *pb;
*pb = 0x00;
id = (a & 8) | (a & 4) ? 8 : 0;
id |= (a & 2) | (a & 1) ? 4 : 0;
a = *pb;
*pb = 0x40;
id |= (a & 8) | (a & 4) ? 2 : 0;
id |= (a & 2) | (a & 1) ? 1 : 0;
portType[PORT_1] = id;
0x70 - works, 0x40 - don't. Looks like there is some hardcode. Does someone have clues why?
I'll look into code of reading joypads in games that have teamplayer support later.
Re: Device ID in SGDK (joy.c)
Posted: Fri Jan 15, 2016 8:04 pm
by r57shell
Ok, during looking into games assembly, I made this ROM for educational purposes.
https://gist.github.com/realmonster/ae8 ... 89f9b3be72