DataMuseum.dk

Presents historical artifacts from the history of:

Commodore CBM-900

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Commodore CBM-900

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦2587599b3⟧ TextFile

    Length: 4501 (0x1195)
    Types: TextFile
    Notes: UNIX file
    Names: »sclock.c«

Derivation

└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
    └─⟦926b8033d⟧ UNIX V7 Filesystem
        └─ ⟦this⟧ »u/demo/clock/sclock.c« 

TextFile

#include <stdio.h>
#include <math.h>
#include <types.h>
#include <timeb.h>
#include <time.h>
/*
 * The following definitions make C more amenable to a purist.
 */
#define	bool	int			/* boolean type */
#define	uint	unsigned int		/* short names for unsigned types */
#define	ulong	unsigned long
#define	uchar	unsigned char
#define	ushort	unsigned short int
#define	not	!			/* logical negation operator */
#define	and	&&			/* logical conjunction */
#define	or	||			/* logical disjunction */
#define	TRUE	(0 == 0)
#define	FALSE	(not TRUE)
#define	loop	while (TRUE)		/* loop until break */
#define	EOS	'\0'			/* end-of-string char */
#define XMAX 1024
#define YMAX 800

#define	RAD	32
#define	XCEN	RAD+10
#define	YCEN	RAD+10
#define	POLY	32
#define BIG 12
#define LITTLE 9
#define SECOND 13
short handfl = 0;
short lck = 0;
short intr = 0;
short sf = 0;
main(argc,argv)
char	**argv;
{

	if(argc > 1) sf++;
	drawface();
	loop
		timedisp();
	return (0);
}
drawface()
{
	register uint i,j;
	/*clear();*/

	for(i=0; i< 31; ++i) 
	    for(j = RAD; j <= RAD+1;j += 5)
		line((uint)( j * cos((2*PI*i)/31) + XCEN),
			(uint)(j * sin((2*PI*i)/31) + YCEN),
			(uint)(j * cos((2*PI*(i+1))/31) + XCEN),
			(uint)(j * sin((2*PI*(i+1))/31) + YCEN));
	
	for(i = 0; i< 360; i+= (360/12)) {
		move((uint)((15*RAD)/16 * cos((2*PI*i)/360) + XCEN),
			(uint)((15*RAD)/16 * sin((2*PI*i)/360) + YCEN));
		cont((uint)((14*RAD)/16 * cos((2*PI*(i+1))/360) + XCEN),
			(uint)((14*RAD)/16 * sin((2*PI*(i+1))/360) + YCEN));	
		cont((uint)((12*RAD)/16 * cos((2*PI*i)/360) + XCEN),
			(uint)((12*RAD)/16 * sin((2*PI*i)/360) + YCEN));
		cont((uint)((14*RAD)/16 * cos((2*PI*((i+359)%360))/360) + XCEN),
			(uint)((14*RAD)/16 * sin((2*PI*((i+359)%360))/360) + YCEN));
		cont((uint)((15*RAD)/16 * cos((2*PI*i)/360) + XCEN),
			(uint)((15*RAD)/16 * sin((2*PI*i)/360) + YCEN));
	}
	handfl = 0;
}
lx,ly;
timedisp()
{
	lck = 1;
	drawhands();
	if(intr) {
		drawface();
		drawhands();
		intr = 0;
	}
	lck = 0;
	if(sf) sleep(1) ;
	else
		sleep(60);
}
intrup()
{
	if(lck == 0)
	{
		clear();
		drawface();
		drawhands();
	}
	else	intr = 1;
}
struct	POINT {
	uint	x,y;
	};
struct HAND {
	struct POINT left;
	struct POINT center;
	struct POINT right;
};
struct HAND lastbig, lastlittle, lastsecond;
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);
	if(sf)ghand(&second,atm,SECOND);
	if(handfl) {
		if(different(&lastbig,&big))
		hand(&lastbig,BIG);
		if(different(&lastlittle, &little))
		hand(&lastlittle,LITTLE);
		if(sf)hand(&lastsecond,SECOND);
	}
	if(different(&lastbig,&big))
		hand(&big,BIG);
	if(different(&lastlittle, &little))
		hand(&little,LITTLE);
	if(sf) hand(&second, SECOND);
	lastbig = big;
	lastlittle = little;
	if (sf) 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)((RAD * r)/16 * cos((2*PI*i)/360) + XCEN);
	hs->center.y = (uint)((RAD * r)/16 * sin((2*PI*i)/360) + YCEN);
	if(r==BIG) {
	hs->left.x = (uint)((RAD * (r-2))/16 * 
		cos((2*PI*((i+358)%360))/360) + XCEN);
	hs->left.y = (uint)((RAD * (r-2))/16 * 
		sin((2*PI*((i+358)%360))/360) + YCEN);
	hs->right.x = (uint)((RAD * (r-2))/16 * 
		cos((2*PI*((i+2)%360))/360) + XCEN);
	hs->right.y = (uint)((RAD * (r-2))/16 * 
		sin((2*PI*((i+2)%360))/360) + YCEN);
	}
	else if (r == LITTLE){
	hs->left.x = (uint)((RAD * (r-2))/16 *
		cos((2*PI*((i+357)%360))/360) + XCEN);
	hs->left.y = (uint)((RAD * (r-2))/16 *
		sin((2*PI*((i+357)%360))/360) + YCEN);
	hs->right.x = (uint)((RAD * (r-2))/16 *
		cos((2*PI*((i+3)%360))/360) + XCEN);
	hs->right.y = (uint)((RAD * (r-2))/16 *
		sin((2*PI*((i+3)%360))/360) + YCEN);
	}
	return(0);
}
hand(h,hf)
struct HAND *h;
short hf;
{
		
	move(XCEN,YCEN);
	if(hf == SECOND) {
		cont(h->center.x, h->center.y);
	}
	else {
		cont(h->left.x,h->left.y);
		cont(h->center.x, h->center.y);
		cont(h->right.x, h->right.y);
		cont(XCEN,YCEN);
	}
	return(0);
}