melonDS-emu / melonDS

DS emulator, sorta
https://melonds.kuribo64.net
GNU General Public License v3.0
2.98k stars 493 forks source link

Real Time Clock is not updating using libnds time() implementation #2038

Closed IvanVeloz closed 1 month ago

IvanVeloz commented 1 month ago

When using the time() implementation of libnds, if time() is called, the time value returned stays the same.

For an example, you can use the RealTimeClock example, part of DevKitPro. The clock will stay stuck at whatever time you opened the ROM (see .nds and code). I am actually not sure if it's stuck at the time the emulation starts, at the time the ROM loads, or at the first time time() is called.

See a video of the behavior.

I tested the same binary attached on real hardware (Nintendo DS Lite) and the clock updates. The BIOS used on melonDS was dumped from the same unit.

If you don't have the time to read through libnds code, let me know. I can give it a try. I am going to do a homebrew app making extensive use of the RTC, so I am willing to volunteer time for this issue. Just let me know.

Thank you for the great emulator, the WiFi will save me so much development time!

Best regards, Ivan

Jaklyy commented 1 month ago

this is fixed in dev builds although it's worth noting that this is a result of weird implementation by devkitpro. since iirc this rom also wouldn't work on 3ds, due to the way the 3ds handles (or rather, doesn't handle) certain rtc regs i forget the exact reasoning why (i think it's something to do with alarm regs?)

IvanVeloz commented 1 month ago

Thank you for the fix. I built the main branch and yes, works perfectly.

I might raise the issue with DevKitPro after I get more familiar with their library.

IvanVeloz commented 1 month ago

OK, I thought I was going crazy for a moment.

The latest build as of today works, but only for a few seconds or minutes. After that, it stops working. I tried a lot of things: deleting the build, deleting my copy of the repo, restarting opening different NDS files. I don't know what makes it work again, but it's rare that it starts working again. I think works again when I delete the entire repo, but that makes absolutely no sense to me.

The crazier thing is I thought this was macOS somehow caching the melonDS executable... but... I switched to my Linux PC and got the same result (it did last a little longer though). The Mac is a Mac mini M1. The PC is a Ryzen 3600 running an Ubuntu toolbox container on Fedora.

Are you able to replicate this? I'm at commit c85a2103bbd41e7119e7d41daa5180dee823b591.

IvanVeloz commented 1 month ago

Okay, I found something interesting. If you disable "Boot game directly" on the Emu settings, the homebrew starts working for a while then stops. The difference is that it always starts working.

Jaklyy commented 1 month ago

i can also reproduce this on windows that's very odd needs deleting rtc.bin to fix temporarily and then it breaks again

Arisotura commented 1 month ago

huh, that's interesting to know

I'll look into it someday (when I'm not in the midst of a big refactor)

On Sun, May 12, 2024 at 3:14 AM Jakly @.***> wrote:

i can also reproduce this on windows that's very odd needs deleting rtc.bin to fix temporarily and then it breaks again

— Reply to this email directly, view it on GitHub https://github.com/melonDS-emu/melonDS/issues/2038#issuecomment-2106079623, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKAI66O3Z72X6GBWMBRKJTZB27AJAVCNFSM6AAAAABHSIUUBSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBWGA3TSNRSGM . You are receiving this because you are subscribed to this thread.Message ID: @.***>