[net.sources] PCompatible HWClock

honzo@kpe.UUCP (Honzo Svasek) (08/28/86)

Following code enables PCompatible owners to read or write their
Multifunction Card Hard Ware Clock. Venix specific only because
of the in & out routines in assembler.
[VENIX is a trademark of VentureCom, Inc.]
[PCompatible is a typo]
have FUN

I_I (
I I  )	Honzo Svasek @ Kuwait Petroleum Europoort (but not for long anymore)

uucp:	..!mcvax!olnl1!kpe!honzo

- - - - - - - - - - - - dd upto and including this line - - - - - - - - - - -
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/[k]sh to create the files:
#	Makefile
#	README
#	clock.h
#	in.s
#	out.s
#	setclock.c
#	sysdate.c
# This archive created: Wed Aug 27 21:45:18 1986
# By:	honzo 
export PATH; PATH=/bin:$PATH
if test -f 'Makefile'
then
	echo shar: will not over-write existing file "'Makefile'"
else
cat > 'Makefile' << \S!H!A!R
CFLAGS=-Oiz

all:		setclock sysdate


setclock:	out.o setclock.c clock.h
		cc out.o setclock.c -o setclock

sysdate:	in.o sysdate.c clock.h
		cc in.o sysdate.c -o sysdate

in.o:		in.s
		cc -c in.s

out.o:		out.s
		cc -c out.s

install:	setclock sysdate
		/etc/install -f /etc sysdate
		/etc/install -f /etc setclock

clean:		
		rm -f sysdate setclock *.o
S!H!A!R
chmod +x 'Makefile'
fi # end of overwriting check
if test -f 'README'
then
	echo shar: will not over-write existing file "'README'"
else
cat > 'README' << \S!H!A!R
	VENIX SysVr2 Hardware Clock Routines for a Multi Function card clock
	====================================================================

				(for PCompatibles)
	
	Vanilla Venix contains a /dev/clock to set the Hard Ware Clock,
	but this device does not seem to work on a multi function card
	clock.

	Here are two commands, setclock, to set the HW clock and systime
	to read it.

	This code is hereby placed into the public domain.

	Honzo Svasek  -  Wed Aug 27 21:31:30 MET 1986

	almost forgot ...

	setclock		sets HW clock to localtime
	sysdate			prints HW date in asci format
	sysdate -		prints HW date in mmddhhmm format

	put in your /etc/startup file:

	date `sysdate -`

	(and, IF anyone is gonna write a man page, I'd like one too)
	
	===============================================================
S!H!A!R
chmod +x 'README'
fi # end of overwriting check
if test -f 'clock.h'
then
	echo shar: will not over-write existing file "'clock.h'"
else
cat > 'clock.h' << \S!H!A!R
/* clock.h - include file PC getclock, setclock programs */

/* I/O addresses MM58167AN clock/calendar chip */

#define	SEC	0x2c2
#define	MIN	0x2c3
#define	HOUR	0x2c4
#define	WDAY	0x2c5
#define	MDAY	0x2c6
#define	MON	0x2c7
#define	YEAR	0x2ca
S!H!A!R
chmod +x 'clock.h'
fi # end of overwriting check
if test -f 'in.s'
then
	echo shar: will not over-write existing file "'in.s'"
else
cat > 'in.s' << \S!H!A!R
	.data
	.text
	.globl	_in
_in:
	push	bp
	mov	bp,sp
	push	si
	push	di
	mov	dx,*4(bp)
	in
	cbw
	lea	sp,*-4(bp)
	pop	di
	pop	si
	pop	bp
	ret
	.data
S!H!A!R
chmod +x 'in.s'
fi # end of overwriting check
if test -f 'out.s'
then
	echo shar: will not over-write existing file "'out.s'"
else
cat > 'out.s' << \S!H!A!R
	.data
	.text
	.globl	_out
_out:
	push	bp
	mov	bp,sp
	push	si
	push	di
	mov	dx,*4(bp)
	movb	ax,*6(bp)
	cbw
	out
	lea	sp,*-4(bp)
	pop	di
	pop	si
	pop	bp
	ret
	.data
S!H!A!R
chmod +x 'out.s'
fi # end of overwriting check
if test -f 'setclock.c'
then
	echo shar: will not over-write existing file "'setclock.c'"
else
cat > 'setclock.c' << \S!H!A!R
#include <stdio.h>
#include <time.h>
#include "clock.h"

main (argc, argv)
int	argc;
char	*argv[];
{
	long time(), clicks;
	struct tm *localtime(), *tm;
	
	time(&clicks);
	tm = localtime(&clicks);
 	
	out(SEC, i2hwc(tm->tm_sec));
	out(MIN, i2hwc(tm->tm_min));
	out(HOUR, i2hwc(tm->tm_hour));
	out(MDAY, i2hwc(tm->tm_mday));
	out(MON, i2hwc(tm->tm_mon + 1));
	out(YEAR, i2hwc(tm->tm_year - 80));
	out(WDAY, i2hwc(tm->tm_wday));
}

i2hwc(getal)
int getal;
{
	char buf[3];
	int i;

	sprintf(buf, "%2d\0", getal);
	sscanf(buf, "%x", &i);
	return i;
}
S!H!A!R
chmod +x 'setclock.c'
fi # end of overwriting check
if test -f 'sysdate.c'
then
	echo shar: will not over-write existing file "'sysdate.c'"
else
cat > 'sysdate.c' << \S!H!A!R
#include <stdio.h>
#include <time.h>
#include "clock.h"

main (argc, argv)
int	argc;
char	*argv[];
{
	char *asctime(), c;
	struct  tm *tm;
	
	
	tm->tm_sec = hwc2i(in(SEC));
	tm->tm_min = hwc2i(in(MIN));
	tm->tm_hour = hwc2i(in(HOUR));
	tm->tm_mday = hwc2i(in(MDAY));
	tm->tm_mon = hwc2i(in(MON)) - 1;
	tm->tm_year = hwc2i(in(YEAR)) + 80;
	tm->tm_wday = hwc2i(in(WDAY));

	if (argc > 1) 
		printf("%02d%02d%02d%02d%02d\n",
		tm->tm_mon + 1, tm->tm_mday,
		tm->tm_hour, tm->tm_min, tm->tm_year);
	else	
		printf("%s", asctime(tm));
}

hwc2i(getal)
int getal;
{
	char	buf[3];
	
	sprintf(buf, "%2x\0", getal);
	return atoi(buf);
}
S!H!A!R
chmod +x 'sysdate.c'
fi # end of overwriting check
#	End of shell archive
exit 0