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 > packet format

#10670 - johnny_north - Fri Sep 12, 2003 12:00 am

Hello everyone,

I?m looking for some opinions on the GBA multiplayer communications use. Right now I?m pondering how to approach parsing the information contained within a transferred packet of information. It appears as though the GBA system was meant to be used such that information transfers should happen regularly, most likely once per frame. On the contrary, it doesn?t seem as though the system is set up for arbitrarily timed transfers (i.e. whenever any of the connected GBAs has info to transfer), as all of the data arrives as a unit in the incoming data registers, and must be dealt with immediately (Let me know if I?ve got the wrong impression).

Anyway, if I?m transferring four sets of packets ? each 64 bits wide - per frame, how do I keep all of the info straight? I?m concerned that if I continue to transfer the same data until some change happens, I?ll have to deal with discarding duplicate packet info. Otherwise, If I make a transfer only once, I?m concerned that I?ll loose critical data at some point and I?ll have to build special case error catching code to recover. From my first experiments, the system seems to miss syncing up occasionally and I think I?m losing data when it happens.

At the very least, I?m guessing that the first 8 or 16 bits of each 64 bit packet should contain basic header information to tell the unit what the rest of the data in the packet is. Maybe the next chunk should contain a random key to compare against previous data, to prevent duplicate data processing. Maybe this calls for some sort of confirmation packet being sent to notify the sender of receipt of the information?

This is my first foray into the world of comms, so I?d welcome your opinions, advice and any helpful information on the subject.

#10673 - sajiimori - Fri Sep 12, 2003 12:50 am

Warning: speculation follows, as I've never linked gba's before

Couldn't you set up an interrupt for incoming serial data, and have the ISR queue up the data to be processed at some point in the main loop? Then each gba could essentially send data whenever it feels like it, and the others will be sure to process it (once) within one frame's time.

My usual style for packet organization (for networked PC games) is to put some bits at the beginning that specify what kind of packet it is, and send data that is as specific and absolute as I can afford. For instance, I would much rather send x and y coordinates of an object than send the distance that it's moved since the last frame (and definitely not information about what keys the other players are pressing). After all, getting duplicate packets that all say "I'm at x=8212, y=1073" won't do any harm.

I usually skip doing checksums and explicit acknowledgements, and instead just try to make it so invalid data or lost packets will cause as little disruption as possible. This keeps the code nice and simple (and usually very fast too).