summaryrefslogtreecommitdiff
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
parent206a5d3585fcda50692fae2d60b2fba639c373b1 (diff)
downloadrockbox-e1147b87abef7687055c9127437e6ce1353c6113.tar.gz
rockbox-e1147b87abef7687055c9127437e6ce1353c6113.zip
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
-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 dbd7d7b4fb..fee3a51851 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -439,6 +439,9 @@ static const struct plugin_api rockbox_api = {
439 kbd_input, 439 kbd_input,
440 get_time, 440 get_time,
441 set_time, 441 set_time,
442#if CONFIG_RTC
443 mktime,
444#endif
442 plugin_get_buffer, 445 plugin_get_buffer,
443 plugin_get_audio_buffer, 446 plugin_get_audio_buffer,
444 plugin_tsr, 447 plugin_tsr,
diff --git a/apps/plugin.h b/apps/plugin.h
index 5ec0174c52..5146e18139 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -112,12 +112,12 @@
112#define PLUGIN_MAGIC 0x526F634B /* RocK */ 112#define PLUGIN_MAGIC 0x526F634B /* RocK */
113 113
114/* increase this every time the api struct changes */ 114/* increase this every time the api struct changes */
115#define PLUGIN_API_VERSION 67 115#define PLUGIN_API_VERSION 68
116 116
117/* update this to latest version if a change to the api struct breaks 117/* update this to latest version if a change to the api struct breaks
118 backwards compatibility (and please take the opportunity to sort in any 118 backwards compatibility (and please take the opportunity to sort in any
119 new function which are "waiting" at the end of the function table) */ 119 new function which are "waiting" at the end of the function table) */
120#define PLUGIN_MIN_API_VERSION 65 120#define PLUGIN_MIN_API_VERSION 68
121 121
122/* plugin return codes */ 122/* plugin return codes */
123enum plugin_status { 123enum plugin_status {
@@ -549,6 +549,9 @@ struct plugin_api {
549 int (*kbd_input)(char* buffer, int buflen); 549 int (*kbd_input)(char* buffer, int buflen);
550 struct tm* (*get_time)(void); 550 struct tm* (*get_time)(void);
551 int (*set_time)(const struct tm *tm); 551 int (*set_time)(const struct tm *tm);
552#if CONFIG_RTC
553 time_t (*mktime)(struct tm *t);
554#endif
552 void* (*plugin_get_buffer)(size_t *buffer_size); 555 void* (*plugin_get_buffer)(size_t *buffer_size);
553 void* (*plugin_get_audio_buffer)(size_t *buffer_size); 556 void* (*plugin_get_audio_buffer)(size_t *buffer_size);
554 void (*plugin_tsr)(bool (*exit_callback)(bool reenter)); 557 void (*plugin_tsr)(bool (*exit_callback)(bool reenter));
diff --git a/apps/plugins/rockboy/Makefile b/apps/plugins/rockboy/Makefile
index 774be303fd..65170bb6fd 100644
--- a/apps/plugins/rockboy/Makefile
+++ b/apps/plugins/rockboy/Makefile
@@ -19,7 +19,8 @@ endif
19LINKFILE := $(OBJDIR)/link.lds 19LINKFILE := $(OBJDIR)/link.lds
20DEPFILE = $(OBJDIR)/dep-rockboy 20DEPFILE = $(OBJDIR)/dep-rockboy
21SRC = cpu.c emu.c events.c fastmem.c hw.c lcd.c lcdc.c loader.c main.c \ 21SRC = cpu.c emu.c events.c fastmem.c hw.c lcd.c lcdc.c loader.c main.c \
22 mem.c menu.c rbsound.c rockboy.c rtc.c save.c sound.c sys_rockbox.c 22 mem.c menu.c rbsound.c rockboy.c rtc.c save.c sound.c sys_rockbox.c \
23 ../../../firmware/common/sscanf.c
23 24
24#CFLAGS += -DDYNAREC 25#CFLAGS += -DDYNAREC
25#SRC += dynarec.c 26#SRC += dynarec.c
diff --git a/apps/plugins/rockboy/emu.c b/apps/plugins/rockboy/emu.c
index 02e5fa0b1c..d04fa9a0fb 100644
--- a/apps/plugins/rockboy/emu.c
+++ b/apps/plugins/rockboy/emu.c
@@ -32,7 +32,6 @@ void emu_step(void)
32 * make things work in the mean time. */ 32 * make things work in the mean time. */
33void emu_run(void) 33void emu_run(void)
34{ 34{
35 /*void *timer = sys_timer();*/
36 int framesin=0,frames=0,timeten=*rb->current_tick, timehun=*rb->current_tick; 35 int framesin=0,frames=0,timeten=*rb->current_tick, timehun=*rb->current_tick;
37 36
38 setvidmode(); 37 setvidmode();
@@ -48,20 +47,13 @@ void emu_run(void)
48 while (R_LY > 0 && R_LY < 144) 47 while (R_LY > 0 && R_LY < 144)
49 emu_step(); 48 emu_step();
50 49
51 rtc_tick(); /* RTC support not implemented */ 50 rtc_tick();
52 51
53 if (options.sound || !plugbuf) 52 if (options.sound || !plugbuf)
54 { 53 {
55 sound_mix(); 54 sound_mix();
56 pcm_submit(); 55 pcm_submit();
57 } 56 }
58 else
59 {
60/* delay = framelen - sys_elapsed(timer);
61 sys_sleep(delay);
62 sys_elapsed(timer);
63*/
64 }
65 57
66 doevents(); 58 doevents();
67 vid_begin(); 59 vid_begin();
diff --git a/apps/plugins/rockboy/menu.c b/apps/plugins/rockboy/menu.c
index 803310f70c..0c9e46bbdf 100644
--- a/apps/plugins/rockboy/menu.c
+++ b/apps/plugins/rockboy/menu.c
@@ -8,6 +8,7 @@
8#include "rockmacros.h" 8#include "rockmacros.h"
9#include "mem.h" 9#include "mem.h"
10#include "lib/oldmenuapi.h" 10#include "lib/oldmenuapi.h"
11#include "rtc-gb.h"
11 12
12#if (CONFIG_KEYPAD == IPOD_4G_PAD) 13#if (CONFIG_KEYPAD == IPOD_4G_PAD)
13#define MENU_BUTTON_UP BUTTON_SCROLL_BACK 14#define MENU_BUTTON_UP BUTTON_SCROLL_BACK
@@ -84,6 +85,11 @@ int do_user_menu(void) {
84 bool done=false; 85 bool done=false;
85 int m, ret=0; 86 int m, ret=0;
86 int result; 87 int result;
88 int time = 0;
89
90#if CONFIG_RTC
91 time = rb->mktime(rb->get_time());
92#endif
87 93
88 /* Clean out the button Queue */ 94 /* Clean out the button Queue */
89 while (rb->button_get(false) != BUTTON_NONE) 95 while (rb->button_get(false) != BUTTON_NONE)
@@ -129,6 +135,12 @@ int do_user_menu(void) {
129 135
130 rb->lcd_setfont(0); /* Reset the font */ 136 rb->lcd_setfont(0); /* Reset the font */
131 rb->lcd_clear_display(); /* Clear display for screen size changes */ 137 rb->lcd_clear_display(); /* Clear display for screen size changes */
138
139 /* Keep the RTC in sync */
140#if CONFIG_RTC
141 time = (rb->mktime(rb->get_time()) - time) * 60;
142#endif
143 while (time-- > 0) rtc_tick();
132 144
133 return ret; 145 return ret;
134} 146}
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 @@
7#include "defs.h" 7#include "defs.h"
8#include "mem.h" 8#include "mem.h"
9#include "rtc-gb.h" 9#include "rtc-gb.h"
10#include "sscanf.h"
10 11
11struct rtc rtc; 12struct rtc rtc;
12 13
@@ -85,31 +86,37 @@ void rtc_tick()
85 86
86void rtc_save_internal(int fd) 87void rtc_save_internal(int fd)
87{ 88{
88 (void)fd; /* stop compiler complaining */ 89 int rt = 0;
89 /* TODO */ 90
90 /* fprintf(f, "%d %d %d %02d %02d %02d %02d\n%d\n", 91#if CONFIG_RTC
91 rtc.carry, rtc.stop, rtc.d, rtc.h, rtc.m, rtc.s, rtc.t, 92 rt = rb->mktime(rb->get_time());
92 time(0)); */ 93#endif
94 fdprintf(fd, "%d %d %d %d %d %d %d %d\n", rtc.carry, rtc.stop, rtc.d, rtc.h,
95 rtc.m, rtc.s, rtc.t, rt);
93} 96}
94 97
95void rtc_load_internal(int fd) 98void rtc_load_internal(int fd)
96{ 99{
97 /* int rt = 0; */ 100 int rt = 0;
98 (void)fd; /* stop compiler complaining */ 101 char buf[32];
99 /* TODO */ 102
100 /* fscanf( 103 rb->read_line(fd, buf, sizeof(buf));
101 f, "%d %d %d %02d %02d %02d %02d\n%d\n", 104 sscanf(buf, "%d %d %d %d %d %d %d %d\n", &rtc.carry, &rtc.stop, &rtc.d,
102 &rtc.carry, &rtc.stop, &rtc.d, 105 &rtc.h, &rtc.m, &rtc.s, &rtc.t, &rt);
103 &rtc.h, &rtc.m, &rtc.s, &rtc.t, &rt); 106
104 while (rtc.t >= 60) rtc.t -= 60; 107 while (rtc.t >= 60) rtc.t -= 60;
105 while (rtc.s >= 60) rtc.s -= 60; 108 while (rtc.s >= 60) rtc.s -= 60;
106 while (rtc.m >= 60) rtc.m -= 60; 109 while (rtc.m >= 60) rtc.m -= 60;
107 while (rtc.h >= 24) rtc.h -= 24; 110 while (rtc.h >= 24) rtc.h -= 24;
108 while (rtc.d >= 365) rtc.d -= 365; 111 while (rtc.d >= 365) rtc.d -= 365;
109 rtc.stop &= 1; 112 rtc.stop &= 1;
110 rtc.carry &= 1; 113 rtc.carry &= 1;
111 if (rt) rt = (time(0) - rt) * 60; 114
112 if (syncrtc) while (rt-- > 0) rtc_tick(); */ 115#if CONFIG_RTC
116 if (rt) rt = (rb->mktime(rb->get_time()) - rt) * 60;
117#endif
118 while (rt-- > 0) rtc_tick();
119
113} 120}
114 121
115 122
diff --git a/apps/plugins/rockboy/sys_rockbox.c b/apps/plugins/rockboy/sys_rockbox.c
index 60cac0a88d..fe3326737d 100644
--- a/apps/plugins/rockboy/sys_rockbox.c
+++ b/apps/plugins/rockboy/sys_rockbox.c
@@ -328,23 +328,3 @@ void vid_update(int scanline)
328} 328}
329#endif 329#endif
330 330
331long timerresult;
332
333void *sys_timer(void)
334{
335 /*timerresult=*rb->current_tick;
336 return &timerresult;*/
337 return 0;
338}
339
340/* returns microseconds passed since sys_timer */
341int sys_elapsed(long *oldtick)
342{
343 /* int elap,mytime=microtick;
344
345 elap=mytime-*oldtick;
346 *oldtick=mytime;
347 return elap; */
348 /* return ((*rb->current_tick-(*oldtick))*1000000)/HZ; */
349 return *oldtick;
350}