/*	XWPCLK	- Executive Workbench Clock
**
*/

#include "a:stdio.h"
#include "b:oxege.h"

#define	CLOCK_LINE	20
#define CLOCK_COLUMN	32

extern int hour, minute, second, year, month, day, jdate;
extern char scratch[], GLname[];

int oldsec;
char FLclock, FLbclock;

initclk()
	{
	FLbclock = 1;
	cpoke( CLOCK_LINE,   CLOCK_COLUMN,    62 | ATTINV, ATTDIM | ATTALT );
	cpoke( CLOCK_LINE+1, CLOCK_COLUMN,    62 | ATTINV, ATTDIM | ATTALT );
	cpoke( CLOCK_LINE,   CLOCK_COLUMN+15, 63 | ATTINV, ATTDIM | ATTALT );
	cpoke( CLOCK_LINE+1, CLOCK_COLUMN+15, 63 | ATTINV, ATTDIM | ATTALT );
	cpoke( CLOCK_LINE,   CLOCK_COLUMN+5,  20 | ATTINV, ATTDIM | ATTALT );
	cpoke( CLOCK_LINE+1, CLOCK_COLUMN+5,  84 | ATTINV, ATTDIM | ATTALT );
	cpoke( CLOCK_LINE,   CLOCK_COLUMN+10, 20 | ATTINV, ATTDIM | ATTALT );
	cpoke( CLOCK_LINE+1, CLOCK_COLUMN+10, 84 | ATTINV, ATTDIM | ATTALT );
	oldsec = 61;
	bclock();
	}

bclock()
	{
	if (FLbclock == NULL)
		{
		return;
		}

	gettime();
	if ( second != oldsec )
		{
		bigdigit( hour/10,   CLOCK_LINE, CLOCK_COLUMN+1 );
		bigdigit( hour%10,   CLOCK_LINE, CLOCK_COLUMN+3 );
		bigdigit( minute/10, CLOCK_LINE, CLOCK_COLUMN+6 );
		bigdigit( minute%10, CLOCK_LINE, CLOCK_COLUMN+8 );
		bigdigit( second/10, CLOCK_LINE, CLOCK_COLUMN+11 );
		bigdigit( second%10, CLOCK_LINE, CLOCK_COLUMN+13 );
		}
	oldsec = second;
	}

clrclk()
	{
	FLbclock = NULL;
	fill( CLOCK_LINE, CLOCK_COLUMN, CLOCK_LINE+1, 
		CLOCK_COLUMN+15, FILL1, ATTDIM | ATTALT );
	}

char pm[] = "GOOD MORNING";
char pa[] = "GOOD AFTERNOON";
char pe[] = "GOOD EVENING";

greeting()
	{
	gettime();
	if ( hour < 12 )
		{ 
		strcpy( scratch, pm );
		}
	if ( ( hour > 11 ) && ( hour < 18 ) )
		{ 
		strcpy( scratch, pa );
		}
	if ( hour > 17 )
		{ 
		strcpy( scratch, pe ); 
		}
	strcat( scratch, ", " );
	strcat( scratch, GLname );
	return scratch;
	}

reset()
	{
	int line;
	outline( 5, 40, 15, 60, OUTDIM | ATTINV, ATTDIM | ATTALT );
	spoke(  6, 41, " SET DATE AND TIME ", ATTDIM | ATTUND );
	fill( 7, 41, 7, 59, FILL3, ATTDIM | ATTALT );
	spoke(  8, 41, "   YEAR: ", ATTDIM | ATTUND);
	spoke(  9, 41, "  MONTH: ", ATTDIM | ATTUND);
	spoke( 10, 41, "    DAY: ", ATTDIM | ATTUND);
	spoke( 12, 41, "   HOUR: ", ATTDIM | ATTUND );
	spoke( 13, 41, " MINUTE: ", ATTDIM | ATTUND );
	spoke( 14, 41, " SECOND: ", ATTDIM | ATTUND );
	line = 8;
	while ( line < 15 )
		{
		spoke( line, 50, "          ", ATTBRT | INVATT );
		++line;
		}
	fill( 11, 41, 11, 59, FILL3, ATTDIM | ATTALT );
	defcursor( 3 );
	adr(  8, 51);
	scanf("%d", &year );
	adr(  9, 51);
	scanf("%d", &month );
	adr( 10, 51);
	scanf("%d", &day );
	adr( 12, 51 );
	scanf("%d", &hour );
	adr( 13, 51 );
	scanf("%d", &minute );
	adr( 14, 51 );
	scanf("%d", &second );
	defcursor( 0 );
	ctoj();
	hour = binbcd( hour );
	minute = binbcd( minute );
	second = binbcd( second );
	*( DATELOC ) = jdate;
	*( HOURLOC ) = hour;
	*( MINUTELOC ) = minute;
	*( SECONDLOC ) = second;
	fill( 5, 40, 15, 65, FILL1, ATTDIM | ATTALT );
	}

exclock()
	{
	doclock();
	FLclock = !FLclock;
	spoke( 23, 71, "         ", ATTDIM );
	}

LL1, ATTDIM | ATTALT );
	}
