[comp.sources.atari.st] v02i040: atime89 -- Set GEMDOS time from keyboard clock

koreth@ssyx.ucsc.edu (Steven Grimm) (05/19/89)

Submitted-by: radoslav@kuling.docs.uu.se (Radoslav Bogdanovic)
Posting-number: Volume 2, Issue 40
Archive-name: atime89

This is the sources for the AUTO - TIMESET program which was posted to
the comp.binaries.atari.st.

---------------------- CUT HERE ------------------------------------------

: This is a shar archive.  Extract with sh, not csh.
: This archive ends with exit, so do not worry about trailing junk.
echo 'Extracting a_time89.doc'
sed 's/^X//' > a_time89.doc << '+ END-OF-FILE a_time89.doc'
X
X                    AUTO - TIMESET Version 1.0 
X                 (c) by Radoslav Bogdanovic / RadoSoft 
X                            17 may, 1989
X
X                For Microdeal/Michtron Internal Clock Card        
X                                 and
X                Other Clock Cards working on the keyboard
X                processor for time & date maintenance.
X
X    This program works from your AUTO folder of your floppydisk or harddisk
X    and also takes over the function of the supplied AUTOTIME.PRG supplied 
X    with the Microdeal/Michtron Clock Card.
X
X    The need for this program arose after I had installed the Clock Card
X    and then suddenly noticed that the clock was zeroed by some other program
X    and that I suddenly had a lot of files with wrong time and date stamp.
X    To prevent this I realised that the only way was to write a program that
X    would check if the date was somehow wrong. This is performed by checking
X    if the IKBD setting of the year is different of the xx year in the file
X    name of A_TIMExx.PRG. This mean that you only need to rename the program
X    once every year to get it to work properly.
X    
X    This program was compiled with Sozobon C compiler and the complete 
X    source code is supplied.
X    
X    This program may freely be distributed. 
X    
X    I can be reached at the following address for bug reports and others: 
X    
X            RadoSoft
X            Radoslav Bogdanovic
X            Sernaders Vag 1-332
X            S-752 61 Uppsala
X            SWEDEN
X            
X            Telephone: +46-18-463897
X            
X            E-mail address: radoslav@kuling.uu.se
X
X    
+ END-OF-FILE a_time89.doc
chmod 'u=rw,g=rw,o=r' 'a_time89.doc'
echo '	-rw-rw-r--  1 radoslav     1636 May 17 17:09 a_time89.doc        (as sent)'
echo -n '	'
/bin/ls -l a_time89.doc
echo 'Extracting a_time89.c'
sed 's/^X//' > a_time89.c << '+ END-OF-FILE a_time89.c'
X/*  
X    AUTO - TIMESET Version 1.0 by Radoslav Bogdanovic / RadoSoft 
X            Compiled with Sozobon C -- 17 may, 1989
X            
X    For Microdeal Internal Clock Card and other clock cards working
X    on the keyboard processor for time & date maintaince.
X    
X    This program also takes over the function of the AUTOTIME.PRG which
X    is supplied with Microdeal Clock Card.
X    
X    For more details see the supplied documentation file.
X    
X*/
X
X#include <stdio.h>
X#include <ctype.h>
X#include <osbind.h>
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X    register unsigned long IKBDtimedate;
X    register unsigned int GEMtime, GEMdate;
X    int seconds, minutes, hours, day, month, year, fyear;
X    char *ptr, ans;
X
X    printf("\n      AUTO - TIMESET Version 1.0\n"); 
X    printf("   by Radoslav Bogdanovic / RadoSoft\n");
X    printf("Compiled with Sozobon C -- 12 May, 1989\n");
X
X
X    /* Following works only with Sozobon C, because other C compilers does
X       NOT inserts program name (command) in ARGV[0] when program started 
X       from GEM-DESKTOP or program autostarted from AUTO-folder.          */    
X    ptr = argv[0];
X    while (*ptr) ++ptr;     /* Find the end of the program name */
X    ptr -= 6;               /* Back up to xx.prg                */
X    if ( isdigit(*ptr) ) 
X        fyear = atoi(ptr);
X    else {
X        printf("\n This is %s ...\n",argv[0]);
X        printf(" This program should be renamed to\n"); 
X        printf(" A_TIMExx.PRG, where xx is 80 to 99,\n");
X        printf(" two digits indicating which year\n");
X        printf(" you want to check against. \n");
X        printf("\n Press any key to exit\n");
X        Bconin(2);
X        exit(0);
X    }
X
X    IKBDtimedate = Gettime();
X    GEMtime = Tgettime();
X    GEMdate = Tgetdate();
X    
X    /* Check if year from filename is same as current IKBD year  */
X    /* If year from filename differs from current IKBD year then */
X    /* it's assumed that the IKBD time is wrong or zeroed.       */
X    
X    if (fyear != (((IKBDtimedate >> 25) & 0x7F) + 80)) {
X
X        IKBDtimeprint("\nThe current IKBD time and date is",IKBDtimedate);
X        timeprintGEM("The current GEM time is",GEMtime);
X        dateprintGEM("The current GEM date is",GEMdate);
X
X        printf("\nDo you want to change time and date (Y/N): ");
X        ans = Bconin(2);
X        if ((ans == 'Y')||(ans == 'y'))
X        {
X            printf("\nEnter the new date and time (YY/MM/DD HH:MM): ");
X            scanf("%d/%d/%d %d:%d",&year,&month,&day,&hours,&minutes);
X            seconds = 0;
X            if (year < 100) year += 1900;
X    
X            IKBDtimedate =  ((unsigned long)(year-1980)<<25)
X                            |((unsigned long)month<<21)
X                            |((unsigned long)day<<16)
X                            |((unsigned long)hours<<11)
X                            |((unsigned long)minutes<<5)
X                            |((unsigned long)seconds<<1);
X    
X            GEMdate = ((unsigned)(year - 1980)<<9)
X                     |((unsigned)month<<5)
X                     |(unsigned)day;        
X                     
X            GEMtime = ((unsigned)hours<<11)
X                     |((unsigned)minutes<<5)
X                     |((unsigned)seconds>>1); 
X          
X            Settime(IKBDtimedate);
X            Tsettime(GEMtime);
X            Tsetdate(GEMdate);
X        }
X        else 
X           setsystemtime(Gettime());
X        putchar('\n');    
X    }
X    else
X       setsystemtime(Gettime());        
X}
X
X/*-----------------------------------------------------*/
X/* fixdigit insert a '0' before number if number < 10  */
X/*-----------------------------------------------------*/
Xfixdigit(buf, number)
Xchar *buf; int number;
X{
X    if (number < 10) {
X        buf[0] = '0';
X        sprintf(&buf[1],"%d",number);
X    }    
X    else
X        sprintf(buf,"%d",number);        
X}                    
X
X/*---------------------------------------------------------------*/
X/* IKBDtimeprint decodes IKBD time & date  and prints a string   */
X/*---------------------------------------------------------------*/
XIKBDtimeprint(string,time)
Xchar *string; register unsigned long time;
X{
X    int seconds, minutes, hours, day, month, year;
X    char mins[3], secs[3], days[3], monts[3];
X    
X    seconds = (time & 0x001F) << 1;
X    minutes = (time >> 5) & 0x3F;
X    hours   = (time >> 11) & 0x1F;
X    
X    day     = (time >> 16) & 0x1F;
X    month   = (time >> 21) & 0x0F;
X    year    = ((time >> 25) & 0x7F) + 1980;
X    
X    fixdigit(mins, minutes);
X    fixdigit(secs, seconds);
X    fixdigit(days, day);
X    fixdigit(monts, month);
X    printf("%s %d:%s:%s on %d/%s/%s\n",string,hours,mins,
X            secs, year,monts,days);
X}                       
X
X/*-----------------------------------------------------*/
X/* timeprintGEM decodes GEM time and prints a string   */
X/*-----------------------------------------------------*/
XtimeprintGEM(string,time)
Xchar *string; register unsigned int time;
X{
X    int seconds, minutes, hours;
X    char mins[3], secs[3];
X    
X    seconds = (time & 0x001F) << 1;
X    minutes = (time >> 5) & 0x3F;
X    hours   = (time >> 11) & 0x1F;
X    
X    fixdigit(mins, minutes);
X    fixdigit(secs, seconds);
X    printf("%s %d:%s:%s\n",string,hours,mins,secs);
X}
X
X/*-----------------------------------------------------*/
X/* dateprintGEM decodes GEM date and prints a string   */
X/*-----------------------------------------------------*/
XdateprintGEM(string,date)
Xchar *string; register unsigned int date;
X{
X    int day, month, year;
X    char days[3], monts[3];
X    
X    day     = date & 0x1F;
X    month   = (date >> 5) & 0x0F;
X    year    = ((date >> 9) & 0x7F) + 1980;
X    
X    fixdigit(days, day);
X    fixdigit(monts, month);
X    printf("%s %d/%s/%s\n",string,year,monts,days);
X}                       
X
X/*---------------------------------------------------------------------*/
X/* setsystemtime sets the GEM system time & date from IKBD time & date */
X/*---------------------------------------------------------------------*/
Xsetsystemtime(time)
Xregister unsigned long time;
X{
X    int seconds, minutes, hours, day, month, year;
X    unsigned int GEMtime, GEMdate;    
X    
X    seconds = (time & 0x001F) << 1;
X    minutes = (time >> 5) & 0x3F;
X    hours   = (time >> 11) & 0x1F;
X    
X    day     = (time >> 16) & 0x1F;
X    month   = (time >> 21) & 0x0F;
X    year    = (time >> 25) & 0x7F;
X    
X    GEMdate = ((unsigned)year<<9)
X              |((unsigned)month<<5)
X              |(unsigned)day;        
X                     
X    GEMtime = ((unsigned)hours<<11)
X              |((unsigned)minutes<<5)
X              |((unsigned)seconds>>1); 
X
X    Tsettime(GEMtime);
X    Tsetdate(GEMdate);
X}                       
X
+ END-OF-FILE a_time89.c
chmod 'u=rw,g=rw,o=r' 'a_time89.c'
echo '	-rw-rw-r--  1 radoslav     6693 May 17 17:00 a_time89.c        (as sent)'
echo -n '	'
/bin/ls -l a_time89.c
exit 0