Stewmath / GameYob

[Super] Gameboy [Color] emulator for the Nintendo [3]DS
MIT License
270 stars 59 forks source link

implement DSi camera for pocket camera mapper #197

Closed Lana-chan closed 1 year ago

Lana-chan commented 1 year ago

originally PR #195, github closed that one because i moved my branches downstream

see also #196 for same functionality on the stable v0.5.2 branch

"it works, mostly!"™

image

very dirty hack, mostly based off: https://gbdev.io/pandocs/Gameboy_Camera.html https://github.com/Epicpkmn11/dsi-camera/ https://github.com/mgba-emu/mgba/blob/master/src/gb/mbc/pocket-cam.c

Stewmath commented 1 year ago

Better late than never I guess? I noticed that the framerate tanks when the camera is on. Maybe something could be done about that later. Still, it more than gets the job done. Thanks!

I'll refrain from merging the v0.5-hotfix version, as that's supposed to be, well, stable. If I make any new releases it would probably be based on the master branch anyway.

Lana-chan commented 1 year ago

the slowness may be because of a delay i had to introduce while the camera is being polled:

https://github.com/Stewmath/GameYob/blob/45599fbb2f08b2f8042e7f9f47578ef078f2e889/platform/ds/arm9/source/inputhelper.cpp#L230

i tried doing it other ways such as keeping the buffer and not polling the camera while i couldn't instead, so that the rest of the code could run, but in doing so it introduced a lot more instability and crashes. there might be ways to mitigate both the need for the delay and keep it stable, but i haven't found it.

i don't know much about the DSi hardware, i just know how to plug different pieces of code together :)

Stewmath commented 1 year ago

I see. Perhaps the camera could be configured to capture at a lower resolution so the DMA copy won't take so long. But there's very little documentation on how the hardware actually works so :shrug:

Stewmath commented 1 year ago

Ah, here we go: https://problemkaputt.de/gbatek.htm#dsicameras

And in arm7/source/aptina.c, tweaking MODE_OUTPUT_WIDTH_A and MODE_OUTPUT_HEIGHT_A might be the way to limit the size of the picture so that the DMA transfer can be done quickly.

I'm not going to actually do that right now, just noting it down for future reference. =)