simple clock for movie recording

This commit is contained in:
p989 2009-04-13 06:55:29 +00:00
parent 97789af476
commit 187d9a8dbc
2 changed files with 99 additions and 15 deletions

View File

@ -30,6 +30,9 @@
#include "armcpu.h" #include "armcpu.h"
#include <time.h> #include <time.h>
#include <string.h> #include <string.h>
#ifdef WIN32
#include "windows/main.h"
#endif
typedef struct 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); #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() static void rtcRecv()
{ {
//INFO("RTC Read command 0x%02X\n", (rtc.cmd >> 1)); //INFO("RTC Read command 0x%02X\n", (rtc.cmd >> 1));
@ -86,6 +138,23 @@ static void rtcRecv()
struct tm *tm_local= localtime(&tm); struct tm *tm_local= localtime(&tm);
tm_local->tm_year %= 100; tm_local->tm_year %= 100;
tm_local->tm_mon++; tm_local->tm_mon++;
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[0] = toBCD(tm_local->tm_year);
rtc.data[1] = toBCD(tm_local->tm_mon); rtc.data[1] = toBCD(tm_local->tm_mon);
rtc.data[2] = toBCD(tm_local->tm_mday); rtc.data[2] = toBCD(tm_local->tm_mday);
@ -96,18 +165,32 @@ static void rtcRecv()
rtc.data[6] = toBCD(tm_local->tm_sec); rtc.data[6] = toBCD(tm_local->tm_sec);
break; break;
} }
}
case 3: // time case 3: // time
{ {
//INFO("RTC: read time\n"); //INFO("RTC: read time\n");
time_t tm; time_t tm;
time(&tm); time(&tm);
struct tm *tm_local= localtime(&tm); struct tm *tm_local= localtime(&tm);
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; 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[0] = ((tm_local->tm_hour < 12) ? 0x00 : 0x40) | toBCD(tm_local->tm_hour);
rtc.data[1] = toBCD(tm_local->tm_min); rtc.data[1] = toBCD(tm_local->tm_min);
rtc.data[2] = toBCD(tm_local->tm_sec); rtc.data[2] = toBCD(tm_local->tm_sec);
break; break;
} }
}
case 4: // freq/alarm 1 case 4: // freq/alarm 1
/*if (cmdBitsSize[0x04] == 8) /*if (cmdBitsSize[0x04] == 8)
INFO("RTC: read INT1 freq\n"); INFO("RTC: read INT1 freq\n");

View File

@ -18,6 +18,7 @@ void AviEnd();
void SetMessageToDisplay(const char *message); //For sending output to the main screen void SetMessageToDisplay(const char *message); //For sending output to the main screen
extern bool ShowInputDisplay; extern bool ShowInputDisplay;
extern unsigned int frameCounter;
extern bool frameCounterDisplay; extern bool frameCounterDisplay;
extern bool FpsDisplay; extern bool FpsDisplay;
extern bool ShowInputDisplay; extern bool ShowInputDisplay;