Device ID in SGDK (joy.c)

SGDK only sub forum

Moderator: Stef

Post Reply
r57shell
Very interested
Posts: 478
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Device ID in SGDK (joy.c)

Post by r57shell » Tue Dec 22, 2015 1:24 pm

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
Image

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

Re: Device ID in SGDK (joy.c)

Post by Mask of Destiny » Tue Dec 22, 2015 6:13 pm

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.

r57shell
Very interested
Posts: 478
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Re: Device ID in SGDK (joy.c)

Post by r57shell » Wed Dec 23, 2015 11:37 am

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.
Image

Dr. MefistO
Interested
Posts: 47
Joined: Wed Jan 08, 2014 3:39 pm

Re: Device ID in SGDK (joy.c)

Post by Dr. MefistO » Fri Jan 08, 2016 1:25 pm

Ok, I have the Team Player device. Give me your test ROM.

r57shell
Very interested
Posts: 478
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Re: Device ID in SGDK (joy.c)

Post by r57shell » Sun Jan 10, 2016 6:20 pm

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.
Image

r57shell
Very interested
Posts: 478
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Re: Device ID in SGDK (joy.c)

Post by r57shell » Fri Jan 15, 2016 8:04 pm

Ok, during looking into games assembly, I made this ROM for educational purposes.
https://gist.github.com/realmonster/ae8 ... 89f9b3be72
Image

Post Reply