gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Multiplayer - almost there

#11452 - johnny_north - Tue Oct 07, 2003 6:51 pm

Everyone,

I realize that topics of this nature have come and gone without much interest. However, in this instance I do have functional multiplayer code that I?d like to share with the community once I get a couple of bugs worked out. If you can help point me in the right direction I would greatly appreciate it.

I?ve set up functional multiplayer code based on Jaap Sutter?s SGADE code. It appears to check for error conditions in the right places and is readable and robust (with one exception). My code is currently geared toward a 2 player only game.
As I understand the code it essentially does the following:

-Transmission is based on using interrupts that happen at intervals throughout the draw and blanking cycle of the GBA
-The entire packet of user defined size of 16 bit chunks should finish transfer within this cycle.
-The master GBA uses one of the timer interrupts set to divide the cycle evenly based on the number of 16 bit transfers in a user defined packet. And makes one 16 bit transfer upon this interrupt.
-Slave GBA uses the COM interrupt to deal with incoming data and begins a new transfer of its own upon interrupt.
-Once per frame (I assume that this should happen in the Vblank) each GBA will have a complete packet from the other GBAs and should process it or lose it.

My problem:
I seem to be successful transferring a packet of 3 ? 16bit chunks with out dropping any packets as far as I can tell. Right now I?m using 8 bits of the first 16 bit chunk to hold a packet counter. For sanity?s sake, I?ve been surveying and storing each packet?s number for both incoming and out going packets. I?ve been performing this survey of packet numbers right before that 16 bit portion of the packet is loaded into the outgoing register, and surveying the packet number just after that 16 bit portion it retrieved from the incoming data register.

The problem is this. Outgoing packet numbers on both the master and slave are fine and look like this ?0, 1, 2, 3, 4??. The incoming packets, though, look like this for the slave ?0,2,1,3,2,4,3,5,4?? and like this for the master ?0,0,1,1,2,2,3,3,4,4,5,5?? I can?t seem to figure out why the order of incoming packets is thus ordered. I?ve got to suspect my own code, but these packet numbers are surveyed right out of the incoming data registers.

Specifics:
-I?m using 115200 bps. Lower rates seem to cause dropped packets. I?ve changed the packed size from 1 to 4 16 bit transfers with the same results.
-REG_RCNT(134h) bit15 is 0 for multiplayer mode.
-REG_SIOCNT(128h) bit12 = 0, bit13 = 1 for multiplayer. I just realized for both master AND slave, the code sets bit14 which corresponds to a serial irq (I wonder if this should be set for the master if the master is using the Timer 3 for communication initiation?). Shouldn?t matter though.
-I?m stumped.

The only problem I can see with this code is that the slave GBA(s) won?t detect a transfer error if the master GBA is switched off during a connection. These GBA(s) only check the cable and connection status when a COM interrupt arises (which obviously won?t happen if the master quits abruptly). Additional error detection should be added outside the interrupt code to correct this.

I could have an appropriate demo and source prepared in a week or so if anyone is interested in helping me get this to fly, any hints or suggestions would also be appreciated.

#11457 - jenswa - Tue Oct 07, 2003 9:14 pm

I think multiplayer is interessthing, but i am just 'walking the basics' of the gba.

I can't really help with the ordering problem, prolly the gba master, likes it to be ordered or you're code does that for you, somewhere.

About serial irq and timer 3, i can't really tell.
Perhaps timer 3 is because of the lowest priority, just like dma 3, something like that.

For the code-around-gba-off-error i might be able to help.
But actually i don't know the registers and etc of the gba hardware,
but isn't it possible that a gba sends a interrupt over the link-cable,
when it's swicthed off? Or all gba's need to check if all gba's are active or not.

It's a shame i really know nothing about it.
_________________
It seems this wasn't lost after all.