blocksds / sdk

Main BlocksDS SDK repository
https://blocksds.github.io/docs/
130 stars 5 forks source link

Understand how RTC change detection works #148

Closed AntonioND closed 3 weeks ago

AntonioND commented 1 month ago

Some games can detect when the RTC has changed. They seem to use a flag that is most likely stored in the firmware user settings:

https://problemkaputt.de/gbatek.htm#dsfirmwareusersettings

  066h  1   Year (2000..2255) (when having entered date in the boot menu)
  067h  1   Unknown (usually 00h...08h or 78h..7Fh or so)
  068h  4   RTC Offset (difference in seconds when RTC time/date was changed)
  06Ch  4   Not used (FFh-filled, sometimes 00h-filled) (=MSBs of above?)

The RTC Offset is probably the flag that is checked by games. It could be interesting to verify if this is the case and maybe add helpers to clear and set that value.

libnds never sets the value of that offset currently.

We should also document the behavior of the flag in the RTC changing functions.

asiekierka commented 1 month ago

The RTC offset works as follows: Every time the date/time is changed on the DS from A to B, the RTC offset has (epoch(B) - epoch(A)) added to it.

AntonioND commented 3 weeks ago

This should be enough: https://github.com/blocksds/libnds/commit/5d7d57023a88782f2139d87e2798ec58fafc3570