gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > libfat, no file date?

#122594 - ttabbal - Tue Mar 20, 2007 4:31 pm

I have read working fine in libfat, but when I write a new file it doesn't have a date. It's valid, and I can copy it off the card just fine. I'm testing on an M3 Simply w/ devkitpro r20. The code is nothing special, just an fopen() with "wb", an fwrite() and an fclose().

Is there any way to tell libfat what the time is?

#122601 - Diddl - Tue Mar 20, 2007 5:18 pm

does you set the system time? in libfat is code for reading RTC and setting into fileinfo.

#122602 - ttabbal - Tue Mar 20, 2007 5:23 pm

Diddl wrote:
does you set the system time? in libfat is code for reading RTC and setting into fileinfo.


The DS system clock (the one they show in the boot menu) is set. It was set out of the box, it was wrong, but it did have a value. Where does libfat get the time from? I could print it to the screen to see what it sees.

#122606 - Diddl - Tue Mar 20, 2007 5:31 pm

libfat does read this RTC data, I know this cause I had problems to compile libfat sources with old r19 kit. with devkitpro r19 you get error messages concerning RTC cause this struct has changed at r20.

#122610 - ttabbal - Tue Mar 20, 2007 6:02 pm

Which struct? I'm not sure where this is stored.

#122633 - Diddl - Tue Mar 20, 2007 9:54 pm

ttabbal wrote:
Which struct? I'm not sure where this is stored.


file filetime.c:
Code:

u16 _FAT_filetime_getTimeFromRTC (void) {
#ifdef NDS
   int hour, minute, second;

   hour = (IPC->time.rtc.hours >= HOUR_PM_INDICATOR ? IPC->time.rtc.hours - HOUR_PM_INDICATOR : IPC->time.rtc.hours);
   minute = IPC->time.rtc.minutes;
   second = IPC->time.rtc.seconds;

#122665 - ttabbal - Wed Mar 21, 2007 3:49 am

Okay, I get all zeros for those vars (I just copied the code into my project and did a printf to see what the values are). The firmware menu knows what time it is, why doesn't homebrew?

#122673 - HyperHacker - Wed Mar 21, 2007 4:58 am

The ARM7 has to read them from the real-time clock and fill them in. You must be using a custom ARM7 binary that doesn't do that (or it's broken or not being loaded properly). A word of advice though, from what I've heard, reading the clock too often causes touch screen inaccuracy. Really you need only read it once per frame, or if you can spare a timer, once at startup and then keep track of time manually.
_________________
I'm a PSP hacker now, but I still <3 DS.

#122685 - ttabbal - Wed Mar 21, 2007 5:52 am

I am using the template ARM7 from the combined template project. Do I just use IPC->time = gp_getRTC(); in the vblank handler?

#124603 - tepples - Sat Apr 07, 2007 4:25 am

I got accurate date from recent libfat by just doing this in ARM7 main() (based on code extracted from this post):
Code:
   rtcReset();
   rtcGetTimeAndDate((uint8 *)&(IPC->time.rtc.year));

If you also care about an accurate time of day, and you expect your program to run for more than a couple minutes, then I'd suggest having ARM7 vblank handler update the seconds and minutes values itself until the time reaches a new hour, at which point it should call rtcGetTimeAndDate() again to resync. Don't resync too often, as it appears to cause noise in the touch screen readout. Also, remember that the LCD timing is set for roughly 599 (not 600) vblanks in 10 seconds, so tune your Bresenham algorithm accordingly.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.