/*
	SC1RTC.C

	CM71xx/Z1 and CM72xx/Z2

	Display the time/date information of the RTC to the stdio of Dynamic C.
*/

void showtime( struct tm this );
void loadtime( struct tm *this, int hour, int min, int sec,
					int mon, int mday,int year, int wday );
main(){
	struct tm this;
	struct tm that;
	int oldsec;

	oldsec = 0;

	tm_rd( &this );
	showtime( this );
	if( (this.tm_year < 95) || (this.tm_year >99) ){
		printf("Real-time clock may not have been set.\n");
		printf("Loading new time of 8 a.m. on 7-21-95.\n");
		loadtime( &this, 8, 0, 0, 7, 21, 95, 5 );
		tm_wr( &this );
	}
	for(;;){
		hitwd();	runwatch();
		tm_rd( &this );
		if( oldsec != this.tm_sec ){		// show new time every 1 sec
			showtime( this );
			oldsec = this.tm_sec;
		}
	}
}

// Show the time/date information to stdio.
void showtime( struct tm this ){
	printf("%02d:%02d:%02d  %02d-%02d-%02d-%1d\n",
	this.tm_hour,this.tm_min,this.tm_sec,
	this.tm_mon,this.tm_mday,this.tm_year,this.tm_wday);
}

// load discrete time/date information to the time structurr this.
void loadtime( struct tm *this, int hour, int min, int sec,
					int mon, int mday,int year, int wday){
	this->tm_hour = hour;
	this->tm_min  = min;
	this->tm_sec  = sec;
	this->tm_mon  = mon;
	this->tm_mday = mday;
	this->tm_year = year;
	this->tm_wday = wday;
}
/**/