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
This commit is contained in:
Tom Ross 2007-07-30 05:19:05 +00:00
parent 206a5d3585
commit e1147b87ab
7 changed files with 51 additions and 53 deletions

View file

@ -439,6 +439,9 @@ static const struct plugin_api rockbox_api = {
kbd_input, kbd_input,
get_time, get_time,
set_time, set_time,
#if CONFIG_RTC
mktime,
#endif
plugin_get_buffer, plugin_get_buffer,
plugin_get_audio_buffer, plugin_get_audio_buffer,
plugin_tsr, plugin_tsr,

View file

@ -112,12 +112,12 @@
#define PLUGIN_MAGIC 0x526F634B /* RocK */ #define PLUGIN_MAGIC 0x526F634B /* RocK */
/* increase this every time the api struct changes */ /* 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 /* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */ 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 */ /* plugin return codes */
enum plugin_status { enum plugin_status {
@ -549,6 +549,9 @@ struct plugin_api {
int (*kbd_input)(char* buffer, int buflen); int (*kbd_input)(char* buffer, int buflen);
struct tm* (*get_time)(void); struct tm* (*get_time)(void);
int (*set_time)(const struct tm *tm); 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_buffer)(size_t *buffer_size);
void* (*plugin_get_audio_buffer)(size_t *buffer_size); void* (*plugin_get_audio_buffer)(size_t *buffer_size);
void (*plugin_tsr)(bool (*exit_callback)(bool reenter)); void (*plugin_tsr)(bool (*exit_callback)(bool reenter));

View file

@ -19,7 +19,8 @@ endif
LINKFILE := $(OBJDIR)/link.lds LINKFILE := $(OBJDIR)/link.lds
DEPFILE = $(OBJDIR)/dep-rockboy DEPFILE = $(OBJDIR)/dep-rockboy
SRC = cpu.c emu.c events.c fastmem.c hw.c lcd.c lcdc.c loader.c main.c \ 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 #CFLAGS += -DDYNAREC
#SRC += dynarec.c #SRC += dynarec.c

View file

@ -32,7 +32,6 @@ void emu_step(void)
* make things work in the mean time. */ * make things work in the mean time. */
void emu_run(void) void emu_run(void)
{ {
/*void *timer = sys_timer();*/
int framesin=0,frames=0,timeten=*rb->current_tick, timehun=*rb->current_tick; int framesin=0,frames=0,timeten=*rb->current_tick, timehun=*rb->current_tick;
setvidmode(); setvidmode();
@ -48,20 +47,13 @@ void emu_run(void)
while (R_LY > 0 && R_LY < 144) while (R_LY > 0 && R_LY < 144)
emu_step(); emu_step();
rtc_tick(); /* RTC support not implemented */ rtc_tick();
if (options.sound || !plugbuf) if (options.sound || !plugbuf)
{ {
sound_mix(); sound_mix();
pcm_submit(); pcm_submit();
} }
else
{
/* delay = framelen - sys_elapsed(timer);
sys_sleep(delay);
sys_elapsed(timer);
*/
}
doevents(); doevents();
vid_begin(); vid_begin();

View file

@ -8,6 +8,7 @@
#include "rockmacros.h" #include "rockmacros.h"
#include "mem.h" #include "mem.h"
#include "lib/oldmenuapi.h" #include "lib/oldmenuapi.h"
#include "rtc-gb.h"
#if (CONFIG_KEYPAD == IPOD_4G_PAD) #if (CONFIG_KEYPAD == IPOD_4G_PAD)
#define MENU_BUTTON_UP BUTTON_SCROLL_BACK #define MENU_BUTTON_UP BUTTON_SCROLL_BACK
@ -84,6 +85,11 @@ int do_user_menu(void) {
bool done=false; bool done=false;
int m, ret=0; int m, ret=0;
int result; int result;
int time = 0;
#if CONFIG_RTC
time = rb->mktime(rb->get_time());
#endif
/* Clean out the button Queue */ /* Clean out the button Queue */
while (rb->button_get(false) != BUTTON_NONE) while (rb->button_get(false) != BUTTON_NONE)
@ -130,6 +136,12 @@ int do_user_menu(void) {
rb->lcd_setfont(0); /* Reset the font */ rb->lcd_setfont(0); /* Reset the font */
rb->lcd_clear_display(); /* Clear display for screen size changes */ 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; return ret;
} }

View file

@ -7,6 +7,7 @@
#include "defs.h" #include "defs.h"
#include "mem.h" #include "mem.h"
#include "rtc-gb.h" #include "rtc-gb.h"
#include "sscanf.h"
struct rtc rtc; struct rtc rtc;
@ -85,22 +86,24 @@ void rtc_tick()
void rtc_save_internal(int fd) void rtc_save_internal(int fd)
{ {
(void)fd; /* stop compiler complaining */ int rt = 0;
/* TODO */
/* fprintf(f, "%d %d %d %02d %02d %02d %02d\n%d\n", #if CONFIG_RTC
rtc.carry, rtc.stop, rtc.d, rtc.h, rtc.m, rtc.s, rtc.t, rt = rb->mktime(rb->get_time());
time(0)); */ #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) void rtc_load_internal(int fd)
{ {
/* int rt = 0; */ int rt = 0;
(void)fd; /* stop compiler complaining */ char buf[32];
/* TODO */
/* fscanf( rb->read_line(fd, buf, sizeof(buf));
f, "%d %d %d %02d %02d %02d %02d\n%d\n", sscanf(buf, "%d %d %d %d %d %d %d %d\n", &rtc.carry, &rtc.stop, &rtc.d,
&rtc.carry, &rtc.stop, &rtc.d,
&rtc.h, &rtc.m, &rtc.s, &rtc.t, &rt); &rtc.h, &rtc.m, &rtc.s, &rtc.t, &rt);
while (rtc.t >= 60) rtc.t -= 60; while (rtc.t >= 60) rtc.t -= 60;
while (rtc.s >= 60) rtc.s -= 60; while (rtc.s >= 60) rtc.s -= 60;
while (rtc.m >= 60) rtc.m -= 60; while (rtc.m >= 60) rtc.m -= 60;
@ -108,8 +111,12 @@ void rtc_load_internal(int fd)
while (rtc.d >= 365) rtc.d -= 365; while (rtc.d >= 365) rtc.d -= 365;
rtc.stop &= 1; rtc.stop &= 1;
rtc.carry &= 1; rtc.carry &= 1;
if (rt) rt = (time(0) - rt) * 60;
if (syncrtc) while (rt-- > 0) rtc_tick(); */ #if CONFIG_RTC
if (rt) rt = (rb->mktime(rb->get_time()) - rt) * 60;
#endif
while (rt-- > 0) rtc_tick();
} }

View file

@ -328,23 +328,3 @@ void vid_update(int scanline)
} }
#endif #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;
}