The local multiplayer saga, ep 6
For melonDS, there are three horsemen of apocalypse. Over the years, we have been able to deal with nearly everything the DS has thrown at us, but there are three main categories of long-standing issues: timing issues, precision errors in the OpenGL renderer, and local multiplayer.

And I certainly did deal a blow to that horseman back in 2017 when a working local multiplayer connection was emulated for the first time, but of course it wasn't going to be all. While the connection worked, it was always finicky, and getting it to work was a bit like voodoo magic. After melonDS 0.4 was released, melonDS changed from being a mere curiosity to being 'the wifi emulator', and many people came in for that feature. And we just kept telling them to disable their framerate limiter, pray, sacrifice a goat or two to the wifi deities, and hope things will work.

It was certainly substandard for melonDS. One of the main reasons why it stayed that way for long was, besides having to work on other fronts, that it was a precarious position of equilibrium. Any attempts at improving wifi emulation resulted in a more unstable connection. I thought it would take an overhaul of how the connection is emulated to make it work reliably, but I always had that fear of putting much time and effort into it only to get terrible results, so the status quo was maintained. But you know how it is: when making your emulation more accurate gives worse results, it means you're missing something else. After 5 years of business, we're no stranger to this.

So what does it take to beat the horseman of wifi? Two things: a stable, reliable medium of communication, and reverse-engineering of the DS wifi hardware, which is full of fun little details that sometimes matter a lot.

But, of course, it's not going to go down without resistance. It's a horseman of apocalypse. It will put up a fight at every stage.

Lately, we got to a point where local multiplayer connections are pretty stable, and it's possible to reach decent speeds on good hardware. For reference, my 2014 laptop Crepe can run New Super Mario Bros. MvsL multiplayer at near-fullspeed with the JIT on. I'm confident that any decent computer will be up to the task when we're done.

But, of course, that's with well-behaving games, where everybody sends their packets as they should and everything is good. While we were testing other games, it appeared to us that there are... cursed games. Tetris DS and Mario Kart DS, for example, have exhibited intense lag while trying to get a multiplayer game going.

I looked at what was going on in Tetris DS. The lag is caused by the host hitting the timeout when waiting for incoming client replies, because sometimes the client isn't sending any reply at all. It was egregious because I set the timeout to a ridiculous value (500 milliseconds) to make sure everything would get through reliably. A lower timeout reduces the lag in this situation, but also increases the chance of missing incoming packets when we need them, so this is essentially a compromise (we might end up making the timeout user-configurable).

But, why are we not receiving replies from the client to begin with? In a previous post, I have mentioned that the DS, when it acts as a multiplayer client, always replies to CMD frames, even when no reply frame is configured, and melonDS emulates this behavior too.

But how does the DS know when it's acting as a multiplayer client? When the AID_LOW register is set to a non-zero value. That register is essentially the client number in a multiplayer setting. If it's set to zero, the DS will not reply to CMD frames.

This is what is happening in Tetris DS. When the game receives a CMD frame, it sets up a callback that will run after the end of the entire CMD exchange and reset AID_LOW to zero. Then, whenever it wants to send a reply frame, it will set AID_LOW to the correct value. Why it's doing that, I don't know. But there's a small chance that AID_LOW will still be zero by the time a CMD frame is received, which means no reply will be sent.

I don't know if this is an issue with melonDS or if this also happens on hardware. All I know is that I had trouble falling asleep last night because I was thinking about ways to deal with this without hitting timeouts and lagging.

Oh well. I refuse to give up. You're going down, horseman of wifi.
Just Thank you says:
Aug 22nd 2022
The hero we don't deserve, good job.
Sweaty Socks says:
Aug 22nd 2022
I see development goes strong and steady here.
Thank you for the latest Rev of 0.9.4, swapping screens in "top/bottom only" was an improvement I've been waiting for.
-vania maps are both readable and well out the way now.
Minessota Klei says:
Aug 22nd 2022
Thank you very much Arisotura, I really like MelonDS, it's the only emulator that runs perfectly on my weak laptop on which I use Linux on it!

I'm now playing "Monster Tale" very cool (^o^)//
Zyute says:
Aug 22nd 2022
The horseman doesnt stand a chance. MelonDS is the only DS emulator that i use. You are doing a fantastic job so keep it up.😎
Anonymous says:
Aug 23rd 2022
Loving all this WiFi progress and definitely cheering you on!
Jay says:
Aug 24th 2022
The climax is coming.
Masky says:
Aug 24th 2022
you and the others working on this emulator is the reason I get to relieve a huge part of my childhood and I thank y'all for that
Sam says:
Aug 24th 2022
Great stuff as always! MelonDS delivers amazing performance on my low-end laptop! Thank you all for the genius craft!

PS: Could we expect LCD grid shader support in the 1.0 release?
HeroMayCry says:
Aug 24th 2022
I can't wait to finally be able to play kingdom hearts 358/2 days as it was intended: with friends. You've given me so much hope. PLEASE DON'T GIVE UP NOW!
keisui says:
Aug 25th 2022
@HeroMayCry thats exactly what im waiting to do too ! especially with high internal res and widescreen , im so excited for the day local multiplayer is finished
DuelingPotato says:
Aug 25th 2022
If you are looking for mores games that might behave badly, you can try the Naruto Ninja Destiny series, made very quickly and probably very cheaply considering their abundant asset reuse.
Post a comment
Name:
DO NOT TOUCH