pm@cwruecmp.UUCP (07/19/86)
Here is a simple program to set date and time on the ST. As you will see, the reset button does NOT cause the keyboard timer to lose its time. However, TOS does; so you need to do Tsettime() and Tsetdate() after reset. -------cut here-------cut here-------cut here-------cut here-------cut here-- /* td.c -- a simple program to set the time and date on Atari ST pm @ Case */ #include <osbind.h> long td; /* time and date, in internal form */ char tds[] = "00mm/dd/yy hh:mm:ss"; /* 00 are wasted space */ char new[20]; /* input buffer, fmt as above */ twodigits(a, p) /* the last two decimal digits of a */ register int a; /* are stuffed into p[0], p[1] */ register char *p; { *p++ = (a%100)/10 + '0'; *p++ = a%10 + '0'; } timestr(t) register int t; { register int sec, min, hr; sec = (t & 0x001F) << 1; min = (t >> 5) & 0x003F; hr = (t >> 11) & 0x001F; twodigits(hr, &tds[11]); twodigits(min, &tds[14]); twodigits(sec, &tds[17]); } datestr(d) register int d; { register int day, mon, yr; day = (d & 0x001F); mon = (d >> 5) & 0x000F; yr = ((d >> 9) & 0x01FF) + 1980; twodigits(mon, &tds[2]); twodigits(day, &tds[5]); twodigits(yr, &tds[8]); } set(p, m, i) /* Assign bit field <i:j> of td with a */ register int p; /* computed value from new[p], new[p+1] */ register long m; /* if they are decimal digits. */ register int i; /* j == i - 1 + #1's in mask m */ { register int a, b; register long ll; a = new[p++]; b = new[p]; if ( (a == 0) || (b == 0) || (a > '9')|| (a < '0') || (b > '9')|| (b < '0') ) return; ll = (long) ((a - '0') *10 + b - '0'); if (i == 0) ll >>= 1; /* couple of kludges! for 2*sec and yr */ if (i == 25) ll -= 80; ll = (ll << i) & m; td = (td & ~m) | ll; } main() { register int *p; p = (int *) &td; /* \033e (enable cursor) if this prg is invoked from desktop */ Cconws("\033e\r\nikbd current date and time: "); td = Gettime(); datestr(p[0]); timestr(p[1]); Cconws(&tds[2]); Cconws("\r\n\n\ to change the time and date, type in the new values in exactly\r\n\ the same format; to leave it alone, just type return.\r\n\ \nmm/dd/yy hh:mm:ss\r\n"); new[0] = (char) 18; Cconrs(new); Cconout('\n'); /* set hours; min; sec; mon; date; year; */ set(2, (long) (0x0000000F << 21), 21); /* month */ set(5, (long) (0x0000001F << 16), 16); /* day */ set(8, (long) (0x0000003F << 25), 25); /* yr, 20th century */ set(11, (long) (0x0000001F << 11), 11); /* hr */ set(14, (long) (0x0000003F << 5), 5); /* min */ set(17, (long) (0x0000001F), 0); /* sec */ Settime(td); /* set ikbd clock */ Tsettime(p[1]); Tsetdate(p[0]); } /* -eof- */ -- prabhaker mateti decvax!cwruecmp!pm department of computer engineering & science pm@Case case western reserve university (pm%Case@csnet-relay) cleveland, oh 44106 (216) 368-2816