![]() |
Home | Downloads | Screenshots | Forums | Source code | RSS | Donate |
Register | Log in |
< melonDS RC bugsTechnical issues > |
Small DLDI fix, and maybe more May 26th 2025, by Arisotura |
Mental health still complicated. Getting somewhat better... I made a more personal blog, to post about other fun projects of mine (including the WiiU gamepad stuff) and other fun shit. If you're interested, it's here: https://arisotura.dreamwidth.org/ Anyway, I committed a fix to melonDS. May not seem like a lot, but after months of not touching the code at all, it's something. Just today, I heard about a DLDI test program failing on melonDS, which piqued my interest. I'd have thought DLDI was a solved problem, so this was interesting. What's going on there? DLDI is a standard interface that was developed to allow clean support for different DS linkers. Since they all have different hardware interfaces and different ways to access their storage medium (CF or SD card), homebrew apps would need to embed drivers for each linker they intended to support, which would be quite a mess. Instead, the homebrew itself only includes a DLDI stub, with a simple header and dummy functions. The linker's loader then patches the homebrew with its own DLDI driver when loading it: the DLDI stub is replaced with the linker's driver, which contains the adequate code for accessing the linker's storage medium. The driver contains some simple functions, like "initialize", "is the card inserted", "read sectors", "write sectors", etc. melonDS implements DLDI in a similar way. Basically, melonDS has a few different NDSCart classes for the different supported cart types. In most cases, CartRetail will be used, which emulates a generic retail game cart. There are a few variants of it, like CartRetailIR for some Pokémon games. But when melonDS recognizes a homebrew ROM, it uses the CartHomebrew class instead. This class implements a couple extra commands for accessing a SD card image (0xC0 for reading a sector, and 0xC1 for writing a sector). (note: there is also a CartR4 class, which emulates a real R4 flashcart; this will be used if you attempt to load a R4 firmware ROM into melonDS, but for most homebrew, the simpler CartHomebrew will be used) melonDS also patches the homebrew ROM with its own DLDI driver, which just translates reads/writes to the aforementioned commands that CartHomebrew understands. It's a pretty simple driver, nothing fancy there. Said driver required buffer addresses to be aligned to a 4-byte boundary. I had no real idea what to expect when coding the driver. Due to the way the cart hardware works, cart data transfers are done in 32-bit units, and the DS's ARM CPUs don't support unaligned memory accesses, so I took the easy way out. However, the DLDI testing tool above also tests unaligned buffer addresses, and those work on hardware, so, yeah. Some DLDI drivers might not support it, but the possibility exists. Long story short, I added some support for unaligned buffer addresses in melonDS's DLDI driver. They will be slower, due to accessing memory in 8-bit units, but atleast it works. This was also the occasion to dig out the code for that DLDI driver and add it to the repo. I also checked GBAtek and: buf should be usually 4-byte aligned, however, some drivers do also support unaligned buffers using slower transfer code (better implement that when making .dldi drivers, but better don't rely on it being supported when making .nds files).
This makes it a bit of a conundrum. Obviously, from an end user perspective, it's ideal for melonDS to have better compatibility, and for its DLDI driver to support unaligned buffers. But from a homebrew developer perspective, it's not ideal, because if one relies on this, there's no guarantee it will work on every linker (although up-to-date DLDI drivers should support it). So, not ideal. Anyway, I hope you liked this little post. It was an occasion for me to go a bit in detail about how a part of melonDS works :) |
9 comments have been posted. |
< melonDS RC bugsTechnical issues > |
kaos says: May 27th 2025 |
Great to hear from you again, and hopefully things stabilize for you soon. Going to go read your personal blog now, thanks for the link! |
Trunks says: May 28th 2025 |
Interesting stuff for sure! |
Zyute says: May 28th 2025 |
Always cool to get a peek behind the curtain of melonDS and its inner workings. One's health especially the mental side is a very difficult thing to get under grasps with so hearing you are getting better and finding focus is a positive thing Arisotura. Definitely going to head over to investigate what other ideas you have in the blog :). Good luck with what you have going on and take care 😎. |
mrjflippo says: May 28th 2025 |
Always enjoy any updates you push here. Take care of you yourself; it's a marathon, not a sprint. |
Variant9 says: May 28th 2025 |
Makes me wonder if a "strict mode" for homebrew developers would be useful, where MelonDS is less forgiving with out-of-spec behavior that may differ depending on console/platform. |
Houston says: May 28th 2025 |
Always neat to read about the technical aspects of emulation, even if I'm too foolish to understand it fully lol Hope your health improves :) |
LEGO_Vince says: May 29th 2025 |
Hey quick question, I haven't seen any Windows updates for a while. Any reason why that is? |
kaos says: May 30th 2025 |
LEGO_Vince: Looks like nightly builds (specifically for Windows) have been broken for about 3 weeks. Arisotura doesn't use Windows (see the last blog post), so they're waiting for someone from the community to fix it most likely. |
Arisotura says: May 30th 2025 |
Nadia has been banging her head against stupid CI/build shit for a while now... she certainly has more patience than me with this kind of stuff. |