Opening your eyes to the world
I haven't been very active these days, mostly real life getting in the way, as usual. Anyway, I have been thinking of cool things I could work on for melonDS. I have some ideas in mind regarding input, like supporting multi-touch and other fun touchscreen-related features, but lately I felt like working on some actual emulation, especially in the DSi field. It's well known that DSi emulation in melonDS needs more love.

I was thinking of implementing things like SoundEx and microphone support, but Generic said he was going to implement that, so I'm letting him having fun there. Instead, I went for improving camera emulation. After all, cameras are the main thing DSi-exclusive games make use of, so DSi emulation with no camera support just feels incomplete.

melonDS 0.9.4 already has some very basic camera emulation, but it basically just does the bare minimum to pass the camera init sequence, and then returns a fixed stripe pattern (which is basically just the picture data register returning a fixed value). Nothing exciting.

For example, you can open the DSi camera app and get to the actual camera part of it, but trying to take a picture will result in a system error. Reason for this is that the camera can be set to output at multiple resolutions. It has two modes of operation, named 'preview' and 'capture', which makes sense in applications like digital cameras: preview mode would provide a low-res preview of what the camera sees, that can be displayed on a built-in screen, while capture mode would provide a full-res picture that can be saved. The DSi camera lets you configure two contexts, each with their output resolution, image format, and various other options (for example, flipping the picture...).

So I first had to add support for these modes of operation. I first implemented the registers necessary to handle the camera mode/context switch. But, of course this wasn't enough. The stub in place for picture transfer assumed a resolution of 256x192, but in this case, the resolution is changed to 640x480. This also means that the DSi camera app expects more picture data to come, and it will softlock if there isn't enough data incoming.

This is where my camera test homebrew came in handy. I modified it so that I could do things like switching between the front and back cameras, switch between preview and capture modes, and even use the picture cropping feature to view different areas of the picture in 640x480 mode (as obviously it wouldn't fit onscreen). Doing this let me get a good grasp on how these features were supposed to work.

Then I felt confident implementing all that into melonDS.

This is a preexisting still picture, not actual camera input. But regardless, we have working camera emulation now, and this is half the battle. The other half would be reading picture data from sources like an actual camera, feeding it into the emulator, and integrating all that into the UI.

Taking a picture in the DSi camera app also works, and thanks to the SD folder-sync system, I can easily retrieve the resulting picture. For example, the original file, and the resulting DSi picture.

There is also still a bunch of tidbits to take care of, as far as camera emulation goes. For example, all details and edge cases pertaining to the picture transfer hardware. It's tricky to work with, because from my understanding, picture data is transferred from the camera on a per-scanline basis, but the transfer hardware holds it in a buffer which is limited to 512 words, and it has no idea what resolution the picture is. It just knows to trigger a DMA transfer every N scanlines (N being configured in CAM_CNT), but if these N scanlines amount to more data than the buffer can hold, you're going to get blank lines in your picture.

The DSi cameras themselves also have a looooot of low-level details, many of which don't matter in the case of melonDS. It's like for the DS wifi hardware: we have to deal with these things to some extent because we're doing low-level emulation, and the games/apps we emulate run on the bare metal, but a lot of it isn't useful to our emulator, and in most/all cases a lot of it is initialized to some generic settings and never touched again.

But hey, this looks like a pretty good start. If you're interested, you can check it out in the camera_betterer branch, atleast until we merge it.
Arisotura says:
May 6th 2022
nah, that will require fixing the DSP core (and that's not really something I look forward to)
bisaalz says:
May 7th 2022
QCameraInfo file not found #include <QCameraInfo> when trying to build in macos
Newt Best says:
May 9th 2022
If you yalk with the creators of Citra 3DS Emulator to have good camera they can help you?
poudink says:
May 9th 2022
I don't think Citra's camera implementation would be compatible at all with melonDS. The 3DS is a completely different system, plus Citra focuses on HLE.
AceAttorneyFanDL6 says:
May 13th 2022
This is a really specific bug, but I came across it now. Melonds has the ability to play compressed ds games, and I compressed the Ace Attorney Trilogy in the .7z format with 7zip on windows( Settings: Compression method:LZMA2,Ultra, word size 273, solid block size, 1536mb dictionary size, compress shared files). The first file, Phoenix Wright:Ace Attorney, works perfectly fine. However, when I try to load any of the other games via the drop down menu offered by melonds, it fails to load the rom. This is very consistent behaviour. I downloaded the windows release from this website, version 0.9.4. The uncompressed version of the file, in .nds format, works fine. I doubt most people have come across this bug, so I hope you found some value in my rambling. I can provide my .ini files or specify my exact configuration if that's necessary.
Arisotura says:
May 23rd 2022
That's interesting. Would you mind sending me the problematic archive, so I might look at it?
Peduls says:
May 25th 2022
Very impressive how far this emulator has come. Can't wait to see what's next! Personally I can't wait for Hi-Res Software Rendering or OpenGL improvements since OpenGL is pretty glitchy right now.
AceAttorneyFanDL6 says:
May 25th 2022
@Arisotura: I'd be more than willing to share the archive! I don't know exactly what file hosting site to put it on, but for now I've put it on one of the alternative Firefox Send websites : link expires after 30 days, and I hope I don't put the website in hot soup by linking to copyrighted content). The file is a little over 48Mb, which I'm pretty proud of. I've also included my save file and my config file, though I doubt that will be of much use.
AceAttorneyFanDL6 says:
May 25th 2022

This is the link. Sorry if it was obfuscated by my comments.
Arisotura says:
May 28th 2022
Thank you! I'll check it out whenever I find some time and motivation.

As far as legal shito is concerned, this should be fine.
Siyar16 says:
Jul 13th 2022
Post a comment