From 187d9a8dbc3cde9d20a6d3a4873ba5f4372e03ca Mon Sep 17 00:00:00 2001 From: p989 Date: Mon, 13 Apr 2009 06:55:29 +0000 Subject: [PATCH] simple clock for movie recording --- desmume/src/rtc.cpp | 113 ++++++++++++++++++++++++++++++++----- desmume/src/windows/main.h | 1 + 2 files changed, 99 insertions(+), 15 deletions(-) diff --git a/desmume/src/rtc.cpp b/desmume/src/rtc.cpp index 8eed6b6ec..41c1d0746 100644 --- a/desmume/src/rtc.cpp +++ b/desmume/src/rtc.cpp @@ -30,6 +30,9 @@ #include "armcpu.h" #include #include +#ifdef WIN32 +#include "windows/main.h" +#endif typedef struct { @@ -62,6 +65,55 @@ u8 cmdBitsSize[8] = {8, 8, 56, 24, 0, 24, 8, 8}; #define toBCD(x) ((x / 10) << 4) | (x % 10); +struct movietime { + + int sec; + int minute; + int hour; + int monthday; + int month; + int year; + int weekday; +}; + +struct movietime movie; + +int oldframeCounter; +u64 totalcycles=2904024960000;//noon +int totalseconds; +bool init=false; +bool moviemode=false; + +void MovieTime(void) { +#ifdef WIN32 + if(!init) { + movie.year=9; + movie.month=1; + movie.monthday=1; + movie.weekday=4; + oldframeCounter=0; + init=true; + } + + if(frameCounter > oldframeCounter) { + int difference; + difference=frameCounter-oldframeCounter; + oldframeCounter=frameCounter; + totalcycles+=((560190<<1)*difference); + } + + totalseconds=totalcycles / 67222800; //one second + + movie.sec=totalseconds % 60; + movie.minute=totalseconds/60; + movie.hour=movie.minute/60; + + //convert to sane numbers + movie.minute=movie.minute % 60; + movie.hour=movie.hour % 24; +#endif +} + static void rtcRecv() { //INFO("RTC Read command 0x%02X\n", (rtc.cmd >> 1)); @@ -86,15 +138,33 @@ static void rtcRecv() struct tm *tm_local= localtime(&tm); tm_local->tm_year %= 100; tm_local->tm_mon++; - rtc.data[0] = toBCD(tm_local->tm_year); - rtc.data[1] = toBCD(tm_local->tm_mon); - rtc.data[2] = toBCD(tm_local->tm_mday); - rtc.data[3] = (tm_local->tm_wday + 6) & 7; - if (!(rtc.regStatus1 & 0x02)) tm_local->tm_hour %= 12; - rtc.data[4] = ((tm_local->tm_hour < 12) ? 0x00 : 0x40) | toBCD(tm_local->tm_hour); - rtc.data[5] = toBCD(tm_local->tm_min); - rtc.data[6] = toBCD(tm_local->tm_sec); - break; + + if(moviemode) { + + MovieTime(); + + rtc.data[0]=toBCD(movie.year); + rtc.data[1]=toBCD(movie.month); + rtc.data[2]=toBCD(movie.monthday); + rtc.data[3]=(movie.weekday + 6) & 7; + if (!(rtc.regStatus1 & 0x02)) movie.hour %= 12; + rtc.data[4] = ((movie.hour < 12) ? 0x00 : 0x40) | toBCD(movie.hour); + rtc.data[5]=toBCD(movie.minute); + rtc.data[6]=toBCD(movie.sec); + break; + } + else { + + rtc.data[0] = toBCD(tm_local->tm_year); + rtc.data[1] = toBCD(tm_local->tm_mon); + rtc.data[2] = toBCD(tm_local->tm_mday); + rtc.data[3] = (tm_local->tm_wday + 6) & 7; + if (!(rtc.regStatus1 & 0x02)) tm_local->tm_hour %= 12; + rtc.data[4] = ((tm_local->tm_hour < 12) ? 0x00 : 0x40) | toBCD(tm_local->tm_hour); + rtc.data[5] = toBCD(tm_local->tm_min); + rtc.data[6] = toBCD(tm_local->tm_sec); + break; + } } case 3: // time { @@ -102,11 +172,24 @@ static void rtcRecv() time_t tm; time(&tm); struct tm *tm_local= localtime(&tm); - if (!(rtc.regStatus1 & 0x02)) tm_local->tm_hour %= 12; - rtc.data[0] = ((tm_local->tm_hour < 12) ? 0x00 : 0x40) | toBCD(tm_local->tm_hour); - rtc.data[1] = toBCD(tm_local->tm_min); - rtc.data[2] = toBCD(tm_local->tm_sec); - break; + + if(moviemode) { + + MovieTime(); + + if (!(rtc.regStatus1 & 0x02)) movie.hour %= 12; + rtc.data[0] = ((movie.hour < 12) ? 0x00 : 0x40) | toBCD(movie.hour); + rtc.data[1] = toBCD(movie.minute); + rtc.data[2] = toBCD(movie.sec); + } + else { + + if (!(rtc.regStatus1 & 0x02)) tm_local->tm_hour %= 12; + rtc.data[0] = ((tm_local->tm_hour < 12) ? 0x00 : 0x40) | toBCD(tm_local->tm_hour); + rtc.data[1] = toBCD(tm_local->tm_min); + rtc.data[2] = toBCD(tm_local->tm_sec); + break; + } } case 4: // freq/alarm 1 /*if (cmdBitsSize[0x04] == 8) @@ -286,4 +369,4 @@ void rtcWrite(u16 val) rtc._prevSIO = rtc._SIO; rtc._prevSCK = rtc._SCK; rtc._prevCS = rtc._CS; -} +} \ No newline at end of file diff --git a/desmume/src/windows/main.h b/desmume/src/windows/main.h index fd4727669..bcb29d147 100644 --- a/desmume/src/windows/main.h +++ b/desmume/src/windows/main.h @@ -18,6 +18,7 @@ void AviEnd(); void SetMessageToDisplay(const char *message); //For sending output to the main screen extern bool ShowInputDisplay; +extern unsigned int frameCounter; extern bool frameCounterDisplay; extern bool FpsDisplay; extern bool ShowInputDisplay;