|
|
DataMuseum.dkPresents historical artifacts from the history of: Commodore CBM-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Commodore CBM-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 4398 (0x112e)
Types: TextFile
Notes: UNIX file
Names: »clock.c«
└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
└─⟦2d53db1df⟧ UNIX Filesystem
└─⟦this⟧ »hr/src/clock/clock.c«
#include <math.h>
#include <types.h>
#include <timeb.h>
#include <time.h>
#include <smgr.h>
#define POLY 32
#define BIG 12
#define LITTLE 9
#define SECOND 13
#define CWINDOW (WINDOW+8)
extern uint CXMAX,
CYMAX,
CXRAD,
CYRAD,
CXCEN,
CYCEN;
short handfl;
struct HAND
{
POINT left;
POINT center;
POINT right;
};
struct HAND lastbig,
lastlittle,
lastsecond;
POINT cframe[2][32], /* points on the frame */
cdig[12][4]; /* points on the numerals */
setpoints()
{
register uint i,j;
double _dsin, _dcos, _dsin2, _dcos2;
for(i=0; i< 32; ++i)
{
_dsin = sin((2*PI*i)/31);
_dcos = cos((2*PI*i)/31);
for( j = 0; j <= 1; j ++ )
{
cframe[j][i].x = (uint)((CXRAD + 5*j) * _dcos + CXCEN);
cframe[j][i].y = (uint)((CYRAD + 5*j) * _dsin + CYCEN);
}
}
j = 0;
for(i = 0; i< 360; i+= (360/12) )
{
_dsin = sin((2*PI*i)/360);
_dcos = cos((2*PI*i)/360);
_dsin2 = sin((2*PI*(i+1))/360);
_dcos2 = cos((2*PI*(i+1))/360);
cdig[j][0].x = (uint)((15*CXRAD)/16 * _dcos + CXCEN);
cdig[j][0].y = (uint)((15*CYRAD)/16 * _dsin + CYCEN);
cdig[j][1].x = (uint)((14*CXRAD)/16 * _dcos2 + CXCEN);
cdig[j][1].y = (uint)((14*CYRAD)/16 * _dsin2 + CYCEN);
cdig[j][2].x = (uint)((12*CXRAD)/16 * _dcos + CXCEN);
cdig[j][2].y = (uint)((12*CYRAD)/16 * _dsin + CYCEN);
cdig[j][3].x = (uint)((14*CXRAD)/16 * cos((2*PI*((i+359)%360))/360) +CXCEN);
cdig[j][3].y = (uint)((14*CYRAD)/16 * sin((2*PI*((i+359)%360))/360) + CYCEN);
j++;
}
}
drawface()
{
GRAPH g;
register uint i,j;
S_ClrClip(CWINDOW);
g.wn_Logop = L_FALSE;
G_SetGraph( CWINDOW, &g, GCLOG );
for(i=0; i< 31; ++i)
{
for( j = 0; j <= 1; j ++ )
cwline(cframe[j][i], cframe[j][i+1]);
}
for( i = 0; i< 12; i++ )
{
cwmove(cdig[i][0]);
cwtoline(cdig[i][1]);
cwtoline(cdig[i][2]);
cwtoline(cdig[i][3]);
cwtoline(cdig[i][0]);
}
clrhand(&lastbig);
clrhand(&lastlittle);
handfl = 0;
g.wn_Logop = L_NDST;
G_SetGraph( CWINDOW, &g, GCLOG );
}
drawhands()
{
struct HAND big,little,second;
struct tm *atm;
struct timeb tb;
ftime(&tb);
atm = localtime(&tb.time);
ghand(&big,atm,BIG);
ghand(&little,atm,LITTLE);
ghand(&second,atm,SECOND);
if(handfl) {
if(different(&lastbig,&big))
hand(&lastbig,BIG);
if(different(&lastlittle, &little))
hand(&lastlittle,LITTLE);
hand(&lastsecond,SECOND);
}
if(different(&lastbig,&big))
hand(&big,BIG);
if(different(&lastlittle, &little))
hand(&little,LITTLE);
hand(&second, SECOND);
lastbig = big;
lastlittle = little;
lastsecond = second;
handfl = 1;
return(0);
}
different(a,b)
struct HAND *a,*b;
{
if(( a->right.x != b->right.x) ||
(a->right.y != b->right.y) ||
(a->center.x != b->center.x) ||
(a->center.y != b->center.y) ||
(a->left.x != b->left.x) ||
(a->left.y != b->left.y))
return (1);
else
return(0);
}
/*
** get points for hand
*/
ghand(hs,atm,r)
struct HAND *hs;
struct tm *atm;
int r;
{
uint i;
if(r == BIG)
i = (atm->tm_min * 360)/60;
else if(r == LITTLE)
{
i = ((atm->tm_hour % 12) * 360)/12;
i += (atm->tm_min * 30)/60;
}
else i = (atm->tm_sec * 360)/60;
i = (i+270)%360;
hs->center.x = (uint)((CXRAD * r)/16 * cos((2*PI*i)/360) + CXCEN);
hs->center.y = (uint)((CYRAD * r)/16 * sin((2*PI*i)/360) + CYCEN);
if (r==BIG)
{
hs->left.x = (uint)((CXRAD * (r-2))/16 *
cos((2*PI*((i+358)%360))/360) + CXCEN);
hs->left.y = (uint)((CYRAD * (r-2))/16 *
sin((2*PI*((i+358)%360))/360) + CYCEN);
hs->right.x = (uint)((CXRAD * (r-2))/16 *
cos((2*PI*((i+2)%360))/360) + CXCEN);
hs->right.y = (uint)((CYRAD * (r-2))/16 *
sin((2*PI*((i+2)%360))/360) + CYCEN);
}
else if (r == LITTLE)
{
hs->left.x = (uint)((CXRAD * (r-2))/16 *
cos((2*PI*((i+357)%360))/360) + CXCEN);
hs->left.y = (uint)((CYRAD * (r-2))/16 *
sin((2*PI*((i+357)%360))/360) + CYCEN);
hs->right.x = (uint)((CXRAD * (r-2))/16 *
cos((2*PI*((i+3)%360))/360) + CXCEN);
hs->right.y = (uint)((CYRAD * (r-2))/16 *
sin((2*PI*((i+3)%360))/360) + CYCEN);
}
}
hand(h,hf)
struct HAND *h;
short hf;
{
cwmove(CXCEN, CYCEN);
if (hf == SECOND)
{
cwtoline(h->center.x, h->center.y);
}
else
{
cwtoline(h->left.x,h->left.y);
cwtoline(h->center.x, h->center.y);
cwtoline(h->right.x, h->right.y);
cwtoline(CXCEN, CYCEN);
}
}
clrhand(hp)
struct HAND *hp;
{
hp->left.x = 0;
hp->left.y = 0;
hp->center.x = 0;
hp->center.y = 0;
hp->right.x = 0;
hp->right.y = 0;
}