bray@alberta.UUCP (Brian Bray) (04/30/86)
Here is a short utility for the Atari ST that sets the time and date
on power up. It's especially useful to MAKE users. The MAKEFILE
follows the source code.
----------------------------------------------------------------------
/* SETCLOCK.C
Routine to set the clock on startup (Atari ST).
Copyright 1986, Brian Bray
This software may be freely copied and given away for
non-commercial use, but sale is prohibited.
Upgrades and comments should be sent to:
Brian Bray
#306, 10135 - Saskatchewan Drive
Edmonton, Alberta
Canada T6E 4Y9
or on UNIX.
bray@alberta.UUCP
Usage:
This program is intended to be placed in the "auto" folder of a
boot disk. On power up, it asks for the time and date and sets the
clock. It will not reset the date during a reboot,
only on power up. (Another mystery!).
86/04/30 Brian Bray Release
86/04/25 Brian Bray Called BIOS getline.
86/04/24 Brian Bray Removed scanf to make smaller
86/04/22 Brian Bray First version
*/
#include <osbind.h>
#include <define.h>
#include <stdio.h>
#define isdigit(c) (c>='0' & c<='9')
#define tonum(c) (c-'0')
char *getd(s,var)
char *s;
int *var;
{
*var = 0;
while(isdigit(*s))
*var = *var * 10 + tonum(*s++);
return(s);
}
main()
{
int time;
int year, month, day, hour, minute, seconds;
char inline[80], *ilp;
int error;
char *getd();
Cconws("Clock setting program -- Version 1.0, BDB\r\n\n");
inline[0] = 70;
error = TRUE;
while ( error ) {
Cconws("\r\nEnter date YY/MM/DD (^C to cancel): ");
Cconrs(inline);
if (inline[1] == 0) return;
ilp = &inline[2];
ilp = getd(ilp,&year);
if (*ilp++ != '/') continue;
ilp = getd(ilp,&month);
if (*ilp++ != '/') continue;
ilp = getd(ilp,&day);
if (year<80) year += 100; /*plan ahead!*/
error = year<86 || month<1 || month>12 || day<1 || day>31;
}
time = (year-80)<<9 | month<<5 | day;
Tsetdate(time);
error = TRUE;
while ( error ) {
Cconws("\r\nEnter time HH:MM:SS : ");
Cconrs(inline);
ilp = &inline[2];
ilp = getd(ilp,&hour);
if (*ilp++ != ':') continue;
ilp = getd(ilp,&minute);
if (*ilp++ == ':')
ilp = getd(ilp,&seconds);
else seconds = 0;
error = hour<0 || hour>24 || minute<0 || minute>59 ||
seconds<0 || seconds>59;
}
time = hour<<11 | minute<<5 | seconds>>1;
Tsettime(time);
Cconws("\r\nThank you.\r\n\n")
}
-----------------------end of program/start of makefile-------------------
setclock.prg : setclock.o
d:\commandp.tos copy setclock.o d:
+cd a:\clib
a:\bin\LINK68.prg [u] \
d:setclock.68k=gemstart.o,d:setclock.o,osbind.o,gemlib,libf
a:\bin\relmod.prg d:setclock
d:\commandp.tos rm d:setclock.68k
+cd a:\setclock
d:\commandp.tos copy d:setclock.prg a:
d:\commandp.tos rm d:setclock.prg
*.o : *.c
d:\commandp.tos d:\bin\c $*
setclock.o : setclock.c
--------------------------------end of makefile--------------------
-Brian