summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorTom Ross <midgey@rockbox.org>2007-07-30 05:19:05 +0000
committerTom Ross <midgey@rockbox.org>2007-07-30 05:19:05 +0000
commite1147b87abef7687055c9127437e6ce1353c6113 (patch)
treeab9da3b3ca7efd58cbfcecf18c7735e95df8be92 /apps
parent206a5d3585fcda50692fae2d60b2fba639c373b1 (diff)
downloadrockbox-e1147b87abef7687055c9127437e6ce1353c6113.zip
rockbox-e1147b87abef7687055c9127437e6ce1353c6113.tar.gz
rockbox-e1147b87abef7687055c9127437e6ce1353c6113.tar.bz2
rockbox-e1147b87abef7687055c9127437e6ce1353c6113.tar.xz
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')
-rw-r--r--apps/plugin.c3
-rw-r--r--apps/plugin.h7
-rw-r--r--apps/plugins/rockboy/Makefile3
-rw-r--r--apps/plugins/rockboy/emu.c10
-rw-r--r--apps/plugins/rockboy/menu.c12
-rw-r--r--apps/plugins/rockboy/rtc.c49
-rw-r--r--apps/plugins/rockboy/sys_rockbox.c20
7 files changed, 51 insertions, 53 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index dbd7d7b..fee3a51 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -439,6 +439,9 @@ static const struct plugin_api rockbox_api = {
kbd_input,
get_time,
set_time,
+#if CONFIG_RTC
+ mktime,
+#endif
plugin_get_buffer,
plugin_get_audio_buffer,
plugin_tsr,
diff --git a/apps/plugin.h b/apps/plugin.h
index 5ec0174..5146e18 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -112,12 +112,12 @@
#define PLUGIN_MAGIC 0x526F634B /* RocK */
/* increase this every time the api struct changes */
-#define PLUGIN_API_VERSION 67
+#define PLUGIN_API_VERSION 68
/* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */
-#define PLUGIN_MIN_API_VERSION 65
+#define PLUGIN_MIN_API_VERSION 68
/* plugin return codes */
enum plugin_status {
@@ -549,6 +549,9 @@ struct plugin_api {
int (*kbd_input)(char* buffer, int buflen);
struct tm* (*get_time)(void);
int (*set_time)(const struct tm *tm);
+#if CONFIG_RTC
+ time_t (*mktime)(struct tm *t);
+#endif
void* (*plugin_get_buffer)(size_t *buffer_size);
void* (*plugin_get_audio_buffer)(size_t *buffer_size);
void (*plugin_tsr)(bool (*exit_callback)(bool reenter));
diff --git a/apps/plugins/rockboy/Makefile b/apps/plugins/rockboy/Makefile
index 774be30..65170bb 100644
--- a/apps/plugins/rockboy/Makefile
+++ b/apps/plugins/rockboy/Makefile
@@ -19,7 +19,8 @@ endif
LINKFILE := $(OBJDIR)/link.lds
DEPFILE = $(OBJDIR)/dep-rockboy
SRC = cpu.c emu.c events.c fastmem.c hw.c lcd.c lcdc.c loader.c main.c \
- mem.c menu.c rbsound.c rockboy.c rtc.c save.c sound.c sys_rockbox.c
+ mem.c menu.c rbsound.c rockboy.c rtc.c save.c sound.c sys_rockbox.c \
+ ../../../firmware/common/sscanf.c
#CFLAGS += -DDYNAREC
#SRC += dynarec.c
diff --git a/apps/plugins/rockboy/emu.c b/apps/plugins/rockboy/emu.c
index 02e5fa0..d04fa9a 100644
--- a/apps/plugins/rockboy/emu.c
+++ b/apps/plugins/rockboy/emu.c
@@ -32,7 +32,6 @@ void emu_step(void)
* make things work in the mean time. */
void emu_run(void)
{
- /*void *timer = sys_timer();*/
int framesin=0,frames=0,timeten=*rb->current_tick, timehun=*rb->current_tick;
setvidmode();
@@ -48,20 +47,13 @@ void emu_run(void)
while (R_LY > 0 && R_LY < 144)
emu_step();
- rtc_tick(); /* RTC support not implemented */
+ rtc_tick();
if (options.sound || !plugbuf)
{
sound_mix();
pcm_submit();
}
- else
- {
-/* delay = framelen - sys_elapsed(timer);
- sys_sleep(delay);
- sys_elapsed(timer);
-*/
- }
doevents();
vid_begin();
diff --git a/apps/plugins/rockboy/menu.c b/apps/plugins/rockboy/menu.c
index 803310f..0c9e46b 100644
--- a/apps/plugins/rockboy/menu.c
+++ b/apps/plugins/rockboy/menu.c
@@ -8,6 +8,7 @@
#include "rockmacros.h"
#include "mem.h"
#include "lib/oldmenuapi.h"
+#include "rtc-gb.h"
#if (CONFIG_KEYPAD == IPOD_4G_PAD)
#define MENU_BUTTON_UP BUTTON_SCROLL_BACK
@@ -84,6 +85,11 @@ int do_user_menu(void) {
bool done=false;
int m, ret=0;
int result;
+ int time = 0;
+
+#if CONFIG_RTC
+ time = rb->mktime(rb->get_time());
+#endif
/* Clean out the button Queue */
while (rb->button_get(false) != BUTTON_NONE)
@@ -129,6 +135,12 @@ int do_user_menu(void) {
rb->lcd_setfont(0); /* Reset the font */
rb->lcd_clear_display(); /* Clear display for screen size changes */
+
+ /* Keep the RTC in sync */
+#if CONFIG_RTC
+ time = (rb->mktime(rb->get_time()) - time) * 60;
+#endif
+ while (time-- > 0) rtc_tick();
return ret;
}
diff --git a/apps/plugins/rockboy/rtc.c b/apps/plugins/rockboy/rtc.c
index 0b011a8..17b2853 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();
+
}
diff --git a/apps/plugins/rockboy/sys_rockbox.c b/apps/plugins/rockboy/sys_rockbox.c
index 60cac0a..fe33267 100644
--- a/apps/plugins/rockboy/sys_rockbox.c
+++ b/apps/plugins/rockboy/sys_rockbox.c
@@ -328,23 +328,3 @@ void vid_update(int scanline)
}
#endif
-long timerresult;
-
-void *sys_timer(void)
-{
- /*timerresult=*rb->current_tick;
- return &timerresult;*/
- return 0;
-}
-
-/* returns microseconds passed since sys_timer */
-int sys_elapsed(long *oldtick)
-{
- /* int elap,mytime=microtick;
-
- elap=mytime-*oldtick;
- *oldtick=mytime;
- return elap; */
- /* return ((*rb->current_tick-(*oldtick))*1000000)/HZ; */
- return *oldtick;
-}