The local multiplayer saga, ep 8
Remember the issue I mentioned in the last post? I fixed that since then. Turns out Nintendo's wifi code does quite a few weird things during a multiplayer connection, and we need to deal with these to keep a stable connection.

In this case, it was related to the power-down registers. The game code may regularly decide to stop and restart the wifi hardware to reset some of its state, and I found out that sometimes that would happen while a frame was being received, which caused a bunch of problems in melonDS.

The code uses register W_POWERFORCE to turn off the wifi transceiver. But, that's the thing, we thought that operation was instant. However, the game had a loop waiting on some status registers after writing to W_POWERFORCE, which implied that the shutdown operation might not always be instant. Hmm...

A couple hardware tests later, this theory is confirmed: if the transceiver is turned off while transmitting or receiving a frame, it will first finish that operation before actually turning off. There we go.

Implementing that into melonDS didn't fix the issue with NSMB minigames, but it helped make local-multiplayer connections more stable overall, for example the slowdowns I had observed in MvsL seem to be gone now. Then I also fixed the issue with the minigames, which happened to be caused by some leftover code that was bad and no longer needed.

As it seems that I have gotten local multiplayer pretty stable and resilient now, folks from our community have been stress-testing it. For example:

All in all, certainly not bad. Consider that there is no way this would ever work reliably on the current melonDS release.

However, we're not done yet. While we can claim victory on the horseman of wifi, there's still a bunch of things to do for a better user experience.

First of all, I need to clean up my code. Then, as far as wifi emulation is concerned, I want to add some features to make it more resilient all around, and rewrite it to use a proper event scheduler instead of running every microsecond, which should hopefully improve performance.

I also need to handle disconnects more gracefully. Right now, there's a chance that they will just leave the other instances hanging or slowing to a crawl, and I need to deal with that. The current system is cool and all but it certainly doesn't fail gracefully. I think most of it is the egregious receive-wait timeout, but I might still have some work to do in the error handling department. The timeout will also be lowered, and maybe made user-configurable.

Something I'm considering is bringing back the old BSD-socket comm layer, in complement to the current shared-memory one. It atleast deserves a fair performance comparison, as it appears that its original slowness was due to the initial, overengineered sync mechanism -- according to a quick test, BSD sockets aren't slower than shared memory, atleast when all instances are running on the same computer. It is also theoretically possible to play multiplayer games over LAN, but it needs an enterprise-grade network to be somewhat usable, so I'm not yet sure whether it's worth making this possible.

And of course, there are many improvements to be done to the UX side of things, to make local multiplayer comfortable. Reworking input handling, sound output, how things like melonDS.ini, savefiles, etc should be dealt with, etc...

And, once all that is taken care of, then can begin season 2: netplay support.

NSMB MvsL over the internet, anyone?
PeeJay Bonobo says:
Aug 26th 2022
I honestly can't wait to see netplay being a thing as well, but as far as this is concerned, it's working perfectly fine thus far. I don't mind using the Audio Settings to turn down the volume for the last seven instances, however. It should be an option as opposed to a "hardcoded" thing.
HeroMayCry says:
Aug 26th 2022
Would a VPN service Such as RADMINVPN or Hamachi be able to connect people as if it was a LAN based connection?
Minessota Klei says:
Aug 26th 2022
Amazing, this is actually possible!

I have a question, using the emulator on a computer with Linux and someone else using the emulator on another computer with Windows, with both computers connected to the same wi-fi network, will it work too!?
Jay says:
Aug 26th 2022
The speed things are developing is amazing, truly amazing. Well done.
AsPika says:
Aug 27th 2022
Wow.... Multiplayer mode!!! 🤩
Isaac says:
Aug 27th 2022
Wow, you are steam rolling through this. You should honestly record and make a documentary style video for YouTube because this is seriously awesome to follow.
Also imagine this getting ported to Android
bu says:
Aug 27th 2022
good work
Puppet12004 says:
Aug 28th 2022
When will the MelonDS Project officially come out for android? It's a bit sad that it's not officially on Android
Puppet12004 says:
Aug 28th 2022
Hopefully MelonDS is very soon Officially on Android by PlayStore or APK
Coolguy says:
Aug 28th 2022
Wow dude, you're amazing, this project is progressing real fast. One suggestion, you guys should fix the Ubuntu (22.04) snap version, you can download it from the store but it will close once you open a ROM, I had to download the appimage and also install some packages before it could run correctly.

Anyway, amazing job.
Guest says:
Aug 28th 2022
Enterprise-grade networking should not be an issue, at least for some of the community (not just a few), since I believe that quite a few people may also be entering the homelab scene.
HeroMayCry says:
Aug 28th 2022
Does the version on GitHub have the multiplayer components and stuff? I really wanna try it rn and actually play Kh Days with friends. If I need networking can I just use a service like RADMIN or Hamachi? Please I just need an answer on this.
Post a comment