diff options
author | Tom Ross <midgey@rockbox.org> | 2007-07-30 05:19:05 +0000 |
---|---|---|
committer | Tom Ross <midgey@rockbox.org> | 2007-07-30 05:19:05 +0000 |
commit | e1147b87abef7687055c9127437e6ce1353c6113 (patch) | |
tree | ab9da3b3ca7efd58cbfcecf18c7735e95df8be92 /apps/plugins/rockboy/rtc.c | |
parent | 206a5d3585fcda50692fae2d60b2fba639c373b1 (diff) |
RTC (real time clock) support for Rockboy. The time in games like Pokemon Gold/Silver should now stay synced on RTC-capable targets. Other targets will lose track of time when the player is turned off. User's can edit the .rtc file in an attempt to resync the RTC. The clock should stay synced when entering and leaving the menu. I've tested this over the past two weeks and it seems to work well.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14071 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/rockboy/rtc.c')
-rw-r--r-- | apps/plugins/rockboy/rtc.c | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/apps/plugins/rockboy/rtc.c b/apps/plugins/rockboy/rtc.c index 0b011a828c..17b2853fce 100644 --- a/apps/plugins/rockboy/rtc.c +++ b/apps/plugins/rockboy/rtc.c @@ -7,6 +7,7 @@ #include "defs.h" #include "mem.h" #include "rtc-gb.h" +#include "sscanf.h" struct rtc rtc; @@ -85,31 +86,37 @@ void rtc_tick() void rtc_save_internal(int fd) { - (void)fd; /* stop compiler complaining */ - /* TODO */ - /* fprintf(f, "%d %d %d %02d %02d %02d %02d\n%d\n", - rtc.carry, rtc.stop, rtc.d, rtc.h, rtc.m, rtc.s, rtc.t, - time(0)); */ + int rt = 0; + +#if CONFIG_RTC + rt = rb->mktime(rb->get_time()); +#endif + fdprintf(fd, "%d %d %d %d %d %d %d %d\n", rtc.carry, rtc.stop, rtc.d, rtc.h, + rtc.m, rtc.s, rtc.t, rt); } void rtc_load_internal(int fd) { - /* int rt = 0; */ - (void)fd; /* stop compiler complaining */ - /* TODO */ - /* fscanf( - f, "%d %d %d %02d %02d %02d %02d\n%d\n", - &rtc.carry, &rtc.stop, &rtc.d, - &rtc.h, &rtc.m, &rtc.s, &rtc.t, &rt); - while (rtc.t >= 60) rtc.t -= 60; - while (rtc.s >= 60) rtc.s -= 60; - while (rtc.m >= 60) rtc.m -= 60; - while (rtc.h >= 24) rtc.h -= 24; - while (rtc.d >= 365) rtc.d -= 365; - rtc.stop &= 1; - rtc.carry &= 1; - if (rt) rt = (time(0) - rt) * 60; - if (syncrtc) while (rt-- > 0) rtc_tick(); */ + int rt = 0; + char buf[32]; + + rb->read_line(fd, buf, sizeof(buf)); + sscanf(buf, "%d %d %d %d %d %d %d %d\n", &rtc.carry, &rtc.stop, &rtc.d, + &rtc.h, &rtc.m, &rtc.s, &rtc.t, &rt); + + while (rtc.t >= 60) rtc.t -= 60; + while (rtc.s >= 60) rtc.s -= 60; + while (rtc.m >= 60) rtc.m -= 60; + while (rtc.h >= 24) rtc.h -= 24; + while (rtc.d >= 365) rtc.d -= 365; + rtc.stop &= 1; + rtc.carry &= 1; + +#if CONFIG_RTC + if (rt) rt = (rb->mktime(rb->get_time()) - rt) * 60; +#endif + while (rt-- > 0) rtc_tick(); + } |